Skip to content

Commit

Permalink
Convert custom permalink to permalink customizer
Browse files Browse the repository at this point in the history
  • Loading branch information
samiahmedsiddiqui committed Jul 16, 2017
1 parent 8675a5d commit cfea5a9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 5 deletions.
64 changes: 63 additions & 1 deletion permalinks-customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Plugin Name: Permalinks Customizer
* Version: 0.3.1
* Version: 0.3.2
* 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.
* Author: Sami Ahmed Siddiqui
Expand Down Expand Up @@ -55,6 +55,7 @@ function permalinks_customizer_menu() {
add_menu_page('Set Your Permalinks', 'Permalinks Customizer', 'administrator', 'permalinks-customizer-settings', 'permalinks_customizer_options_page');
add_submenu_page( 'permalinks-customizer-settings', 'Set Your Permalinks', 'Set Permanlinks', 'administrator', 'permalinks-customizer-settings', 'permalinks_customizer_options_page' );
add_submenu_page( 'permalinks-customizer-settings', 'Structure Tags', 'Structure Tags', 'administrator', 'permalinks-customizer-tags', 'permalinks_customizer_tags_page' );
add_submenu_page( 'permalinks-customizer-settings', 'Convert Custom Permalink', 'Convert Custom Permalink', 'administrator', 'permalinks-customizer-convert-url', 'permalinks_customizer_convert_url' );
add_action( 'admin_init', 'register_permalinks_customizer_settings' );
}

Expand Down Expand Up @@ -632,6 +633,67 @@ function permalinks_customizer_original_page_link($post_id) {
return $originalPermalink;
}

function permalinks_customizer_convert_url() {
global $wpdb;
$plugin_slug = 'permalinks-customizer-convert-url';
$step = isset( $_GET['processing'] ) ? absint( $_GET['processing'] ) : 1;
$steps = isset( $_GET['limit'] ) ? $_GET['limit'] : 0;
$data = $wpdb->get_row( 'SELECT meta_id from wp_postmeta where meta_key = "custom_permalink" LIMIT 1');
echo '<div class="wrap"><h2>'.esc_html( get_admin_page_title() ).'</h2>';
if ( isset( $_GET['processing'] ) ) :
if ( isset($data) && !empty($data) ) {
$wpdb->query( $wpdb->prepare( 'UPDATE wp_postmeta SET meta_key = "permalink_customizer" where meta_id = %d ', $data->meta_id) );
echo '<p>The batch update routine has started. Please be patient as this may take some time to complete <img class="conversion-in-process" src="'.includes_url( 'images/spinner-2x.gif' ).'" alt="Loading..." ) width="20px" height="20px" style="vertical-align:bottom" /></p>';
echo '<p class="processing"><strong>Converting '.(int) $step.' out of '.(int) $steps.' custom permalinks</strong></p>';
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$.post( ajaxurl, { action: 'permalinks-customizer-convert-url', processing: '<?php echo $step; ?>', limit: '<?php echo absint( $_GET["limit"] ); ?>'}, function(res){
var step = '<?php echo $step; ?>';
var total = '<?php echo $steps; ?>';
if ( step == total ) {
$('.conversion-in-process').remove();
window.location = window.location.pathname="?page=permalinks-customizer-convert-url&processed="+total;
return;
} else {
document.location.href = '<?php echo add_query_arg( array( "page" => $plugin_slug, "processing" => (int) $step + 1, "limit" => absint( $_GET["limit"] ) ) ); ?>';
}
}, 'json');
});
</script>
<?php }else{ ?>
<script type="text/javascript">
jQuery(document).ready(function($){
window.location = window.location.pathname="?page=permalinks-customizer-convert-url&processed=<?php echo $step; ?>&no-permalink=1";
});
</script>
<?php }
else :
if( $_GET["no-permalink"] == 1 ) {
$completed = $_GET["processed"] - 1;
$cat_data = $wpdb->get_row( 'SELECT option_id from wp_options where option_name LIKE "%custom_permalink_table%" ' );
if( isset($cat_data) && !empty($cat_data)) {
$wpdb->query( $wpdb->prepare( 'UPDATE wp_options SET option_name = "permalinks_customizer_table" where option_id = %d ', $cat_data->option_id) );
}
echo '<div class="updated"><p>'. $completed .' <strong>Custom Permalink</strong> have been converted to <strong>Permalink Customizer</strong> successfully.</p></div>';
} elseif( $_GET["processed"] > 0 ) {
$cat_data = $wpdb->get_row( 'SELECT option_id from wp_options where option_name LIKE "%custom_permalink_table%" ' );
if( isset($cat_data) && !empty($cat_data)) {
$wpdb->query( $wpdb->prepare( 'UPDATE wp_options SET option_name = "permalinks_customizer_table" where option_id = %d ', $cat_data->option_id) );
}
echo '<div class="updated"><p>'. $_GET["processed"] .' <strong>Custom Permalink</strong> have been converted to <strong>Permalink Customizer</strong> successfully.</p></div>';
}
echo '<p>Click on the "Convert Permalink" button to convert custom permalink to Permalink Customizer. By doing this, all of your previous permalink which was created by custom permalink plugin would be converted to Permalink Customizer.</p>';
echo '<form id="permalinks-customizer-convert-url" method="get" action="'.add_query_arg( 'page', 'permalinks-customizer-convert-url' ).'">';
echo '<input type="hidden" name="page" value="'.$plugin_slug.'" />';
echo '<input type="hidden" name="processing" value="1" />';
echo '<input type="number" name="limit" value="100" />';
echo '<p><input class="button button-primary" type="submit" name="submit" value="Convert Permalink" /></p>';
echo '</form>';
endif;
echo '</div>';
}

if (function_exists("add_action") && function_exists("add_filter")) {
add_action( 'template_redirect', 'permalinks_customizer_redirect', 5 );
add_filter( 'post_link', 'permalinks_customizer_post_link', 'edit_files', 2 );
Expand Down
16 changes: 12 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
=== Permalinks Customizer ===
Contributors: sasiddiqui, michaeltyson
Contributors: sasiddiqui, yasglobal, michaeltyson
License: GPLv3
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
Requires at least: 3.5
Tested up to: 4.4
Stable tag: 0.3.1
Tested up to: 4.5
Stable tag: 0.3.2

Set permalinks for default post-type and custom post-type which can be changed from the single post edit page.

Expand Down Expand Up @@ -57,7 +57,7 @@ If you leave the some post-type fields empty. So, <strong>Permalinks Customizer<

= Tags =

address, permalink, permalinks, custom permalink, custom post permalink, url, tag, category, redirects, slug, set permalink, change permalink, rewrite slug
address, permalink, permalinks, custom permalink, custom post permalink, url, tag, category, redirects, slug, set permalink, change permalink, rewrite slug, convert permalink, convert custom permalink, batch processing

== Installation ==

Expand All @@ -73,6 +73,10 @@ address, permalink, permalinks, custom permalink, custom post permalink, url, ta

* Permalinks can easily be changed for the single post from its post edit page.

* You can easily convert the custom permalink to permalink customizer by going on [permalinks settings page](http://www.example.com/wp-admin/admin.php?page=permalinks-customizer-convert-url)

* Permalink conversion varies from servr to server. So, make sure to convert the url at a time on depending on your server capability.

== Frequently Asked Questions ==

= Q. How to define slug of the post type? =
Expand All @@ -86,6 +90,10 @@ A. No, This plugin does not work with [custom permalinks](https://wordpress.org/

== Changelog ==

= 0.3.2 =

* Convert custom permalink to permalink customizer

= 0.3.1 =

* Add product_cat tag which is specially used for WooCommerce Products
Expand Down

0 comments on commit cfea5a9

Please sign in to comment.