Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function disallow_posts_with_same_name($messages) {
- global $post;
- global $wpdb;
- $name = $post->post_name;
- $post_id = $post->ID;
- $wtquery_post = "SELECT post_name FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND post_name = '{$name}' AND ID != {$post_id}";
- $wtquery_page = "SELECT post_name FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' AND post_name = '{$name}' AND ID != {$post_id}";
- $wresults_post = $wpdb->get_results($wtquery_post);
- $wresults_page = $wpdb->get_results($wtquery_page);
- if ( $wresults_post || $wresults_page ) {
- $error_message = 'Bezpośredni odnośnik o tej samej nazwie już istnieje. Zmień go aby uniknąć problemów z duplikowaniem się adresów.';
- add_settings_error('post_has_links', '', $error_message, 'error');
- settings_errors( 'post_has_links' );
- $post->post_status = 'draft';
- wp_update_post($post);
- return;
- }
- return $messages;
- }
- add_action('post_updated_messages', 'disallow_posts_with_same_name');
- function disallow_posts_with_same_name_js() {
- echo '"<script>
- (function($) {
- $(document).ready(function(){
- if ( $( "#setting-error-sname" ).length ) {
- $( "#setting-error-sname, #editable-post-name" ).animate({backgroundColor:"#dc3232",color:"#fff",padding:"2px 4px"},\'slow\');
- }
- });
- })( jQuery );
- </script>"';
- }
- add_action('admin_footer', 'disallow_posts_with_same_name_js');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement