Last active
October 27, 2018 19:12
-
-
Save lukecav/b82ae8d6efdedfe7c6e256e1abfa7b89 to your computer and use it in GitHub Desktop.
Re-slug - Updated (works in WP 4.7.3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$(function() { | |
$("#re-slug").live("click", function(e) { | |
e.preventDefault(); | |
var the_new_slug = $("#title").val(); | |
$.post( | |
ajaxurl, | |
{ | |
action: "sample-permalink", | |
post_id: $("#post_ID").val(), | |
new_slug: the_new_slug, | |
new_title: the_new_slug, | |
samplepermalinknonce:$("#samplepermalinknonce").val() | |
}, | |
function(val){ | |
$("#edit-slug-box").html(val); | |
$("#post_name").val(the_new_slug); | |
$("#view-post-btn").show(); | |
$("#re-slug").hide(); | |
}); | |
}); | |
$("#title").on("input", function() { | |
$('#re-slug').show(); | |
}); | |
}); | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Re-slug | |
Plugin URI: http://exygy.com/re-slug-wordpress-plugin/ | |
Description: Regenerate the post permalink after changing the title | |
Author: Exygy | |
Author URI: http://exygy.com | |
Version: 1.1 | |
*/ | |
function add_reslug_button ($return) { | |
// Add Re-slug button after Edit buton | |
$return = str_replace('Edit</button>', 'Edit</button> <button type="button" id="re-slug" class="edit-slug button button-small hide-if-no-js" style="display:inherit;"><a href="#re-slug">Re-slug</a></button>', $return); | |
return $return; | |
} | |
add_filter( 'get_sample_permalink_html', 'add_reslug_button', 10, 1 ); | |
function enqueue_reslug_script($hook) { | |
if( 'post.php' != $hook && 'post-new.php' != $hook ) | |
return; | |
wp_enqueue_script( 'reslug', plugin_dir_url( __FILE__ ) . '/re-slug.js' ); | |
} | |
add_action( 'admin_enqueue_scripts', 'enqueue_reslug_script' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment