Skip to content

Commit

Permalink
Updated Postname if it's not available at the Created Post time
Browse files Browse the repository at this point in the history
  • Loading branch information
samiahmedsiddiqui committed Oct 15, 2017
1 parent a90157a commit 06a63f9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static function update_taxonomy_terms() {
update_option( 'permalinks_customizer_table', $taxonomy_table );
} elseif ( isset( $taxonomy_table ) && empty( $taxonomy_table ) ) {
delete_option( 'permalinks_customizer_table' );
update_option( 'permalinks_customizer_plugin_version', '1.3.7' );
update_option( 'permalinks_customizer_plugin_version', '1.3.8' );
}
}
}
86 changes: 49 additions & 37 deletions frontend/class-permalinks-customizer-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,14 @@ private function permalinks_customizer_replace_tags( $post_id, $post, $replace_t
// Replace %postname% with the respective post name
if ( false !== strpos( $replace_tag, "%postname%" ) ) {
if ( ! empty( $post->post_name ) ) {
$replace_tag = str_replace( '%postname%', $post->post_name, $replace_tag );
$replace_tag = str_replace( '%postname%', $post->post_name, $replace_tag );
} else {
$title = sanitize_title( $post->post_title );
$replace_tag = str_replace( '%postname%', $title, $replace_tag );
$title = sanitize_title( $post->post_title );
$replace_tag = str_replace( '%postname%', $title, $replace_tag );
wp_update_post( array(
'ID' => $post_id,
'post_name' => $title
));
}
}

Expand All @@ -324,10 +328,14 @@ private function permalinks_customizer_replace_tags( $post_id, $post, $replace_t
}

if ( ! empty( $post->post_name ) ) {
$postnames .= $post->post_name;
$postnames .= $post->post_name;
} else {
$title = sanitize_title( $post->post_title );
$postnames .= $title;
$title = sanitize_title( $post->post_title );
$postnames .= $title;
wp_update_post( array(
'ID' => $post_id,
'post_name' => $title
));
}

$replace_tag = str_replace( '%parent_postname%', $postnames, $replace_tag );
Expand All @@ -347,10 +355,14 @@ private function permalinks_customizer_replace_tags( $post_id, $post, $replace_t
}

if ( !empty( $post->post_name ) ) {
$postnames .= $post->post_name;
$postnames .= $post->post_name;
} else {
$title = sanitize_title( $post->post_title );
$postnames .= $title;
$title = sanitize_title( $post->post_title );
$postnames .= $title;
wp_update_post( array(
'ID' => $post_id,
'post_name' => $title
));
}

$replace_tag = str_replace( '%all_parents_postname%', $postnames, $replace_tag );
Expand All @@ -362,22 +374,22 @@ private function permalinks_customizer_replace_tags( $post_id, $post, $replace_t
$total_cat = count( $categories );
$tid = 1;
if ( $total_cat > 0 && is_array( $categories ) ) {
$tid = '';
foreach ( $categories as $cat ) {
if ( $cat->term_id < $tid || empty( $tid ) ) {
$tid = $cat->term_id;
$pid = '';
if ( ! empty( $cat->parent ) ) {
$pid = $cat->parent;
}
$tid = '';
foreach ( $categories as $cat ) {
if ( $cat->term_id < $tid || empty( $tid ) ) {
$tid = $cat->term_id;
$pid = '';
if ( ! empty( $cat->parent ) ) {
$pid = $cat->parent;
}
}
}
}
}
$term_category = get_term( $tid );
$category = is_object( $term_category ) ? $term_category->slug : '';
if ( ! empty( $pid ) ) {
$parent_category = get_term( $pid );
$category = is_object( $parent_category ) ? $parent_category->slug . '/' . $category : '';
$parent_category = get_term( $pid );
$category = is_object( $parent_category ) ? $parent_category->slug . '/' . $category : '';
}
$replace_tag = str_replace( '%category%', $category, $replace_tag );
}
Expand All @@ -388,12 +400,12 @@ private function permalinks_customizer_replace_tags( $post_id, $post, $replace_t
$total_cat = count( $categories );
$tid = 1;
if ( $total_cat > 0 && is_array( $categories ) ) {
$tid = '';
foreach( $categories as $cat ) {
if ( $cat->term_id < $tid || empty( $tid ) ) {
$tid = $cat->term_id;
}
}
$tid = '';
foreach( $categories as $cat ) {
if ( $cat->term_id < $tid || empty( $tid ) ) {
$tid = $cat->term_id;
}
}
}
$term_category = get_term( $tid );
$category = is_object( $term_category ) ? $term_category->slug : '';
Expand All @@ -406,22 +418,22 @@ private function permalinks_customizer_replace_tags( $post_id, $post, $replace_t
$total_cat = count( $categories );
$tid = 1;
if ( $total_cat > 0 && is_array( $categories ) ) {
$tid = '';
foreach ( $categories as $cat ) {
if ( $cat->term_id < $tid || empty( $tid ) ) {
$tid = $cat->term_id;
$pid = '';
if ( ! empty( $cat->parent ) ) {
$pid = $cat->parent;
}
$tid = '';
foreach ( $categories as $cat ) {
if ( $cat->term_id < $tid || empty( $tid ) ) {
$tid = $cat->term_id;
$pid = '';
if ( ! empty( $cat->parent ) ) {
$pid = $cat->parent;
}
}
}
}
}
$term_category = get_term( $tid );
$category = is_object( $term_category ) ? $term_category->slug : '';
if ( ! empty( $pid ) ) {
$parent_category = get_term( $pid );
$category = is_object( $parent_category ) ? $parent_category->slug . '/' . $category : $category;
$parent_category = get_term( $pid );
$category = is_object( $parent_category ) ? $parent_category->slug . '/' . $category : $category;
}
$replace_tag = str_replace( '%product_cat%', $category, $replace_tag );
}
Expand Down
2 changes: 1 addition & 1 deletion permalinks-customizer-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
exit();
}

define( 'PERMALINKS_CUSTOMIZER_PLUGIN_VERSION', '1.3.6' );
define( 'PERMALINKS_CUSTOMIZER_PLUGIN_VERSION', '1.3.8' );

if ( ! defined( 'PERMALINKS_CUSTOMIZER_PATH' ) ) {
define( 'PERMALINKS_CUSTOMIZER_PATH', plugin_dir_path( __FILE__ ) );
Expand Down
2 changes: 1 addition & 1 deletion permalinks-customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: Permalinks Customizer
* Plugin URI: https://wordpress.org/plugins/permalinks-customizer/
* Description: Set permalinks for default post-type and custom post-type which can be changed from the single post edit page.
* Version: 1.3.7
* Version: 1.3.8
* Author: YAS Global Team
* Author URI: https://www.yasglobal.com/web-design-development/wordpress/permalinks-customizer/
* Donate link: https://www.paypal.me/yasglobal
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ License URI: http://www.gnu.org/licenses/gpl.html
Tags: address, category, custom, custom permalink, custom post permalinks, link, permalink, rewrite slug, redirects, slug, tags, url, custom taxonomy
Requires at least: 3.5
Tested up to: 4.8
Stable tag: 1.3.7
Stable tag: 1.3.8

Set permalinks for default PostTypes, custom PostTypes, default Taxonomies (Category/Tags) and custom Taxonomies which can be changed from the edit page.

Expand Down Expand Up @@ -119,6 +119,10 @@ A. No, This plugin does not work with [custom permalinks](https://wordpress.org/

== Changelog ==

= 1.3.8 =

* Updated Postname if it's not available at the Created Post time

= 1.3.7 =

* Resolved the Yoast SEO Slug Issue
Expand Down

0 comments on commit 06a63f9

Please sign in to comment.