Plugin Directory

Changeset 3341948


Ignore:
Timestamp:
08/09/2025 09:56:21 AM (8 months ago)
Author:
tsinf
Message:

v1.0.5 Add Post States List to Page Overview, Add Post ID (Search and Sort) Functionality, Add German Translation

Location:
ts-search-slug
Files:
20 added
2 edited

Legend:

Unmodified
Added
Removed
  • ts-search-slug/trunk/plugin.php

    r3185072 r3341948  
    77 Author: Tobias Spiess
    88 Author URI: https://www.spiess-informatik.de
    9  Version: 1.0.4
     9 Version: 1.0.5
    1010 Text-Domain: ts-search-slug
    1111 Domain Path: /languages
     
    1313
    1414/**
    15  * Load Plugin Translations
     15 * Deprecated: Load Plugin Translations
    1616 */
    17 function tsinf_search_slug_load_plugin_textdomain() {
    18     load_plugin_textdomain( 'ts-search-slug', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
     17// function tsinf_search_slug_load_plugin_textdomain() {
     18//  load_plugin_textdomain( 'ts-search-slug', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
     19// }
     20// add_action( 'plugins_loaded', 'tsinf_search_slug_load_plugin_textdomain' );
     21
     22if(!defined('TS_Search_Slug_Version'))
     23{
     24    define('TS_Search_Slug_Version', '1.0.5');
    1925}
    20 add_action( 'plugins_loaded', 'tsinf_search_slug_load_plugin_textdomain' );
    2126
    2227if(!defined('TS_Search_Slug'))
     
    2833            add_action('admin_menu', array('TS_Search_Slug', 'add_options_page'));
    2934            add_action('admin_init', array('TS_Search_Slug', 'establish_options_page'));
    30            
     35
     36            add_action('admin_enqueue_scripts', array('TS_Search_Slug', 'load_scripts_and_styles'));
     37
    3138            add_filter('manage_post_posts_columns', array('TS_Search_Slug', 'append_admin_columns'));
    32             add_action('manage_post_posts_custom_column',  array('TS_Search_Slug', 'append_admin_columns_data'), 10, 2);
    33             add_filter('manage_edit-post_sortable_columns', array('TS_Search_Slug', 'make_custom_columns_sortable'));
    34            
    35             add_filter('manage_page_posts_columns', array('TS_Search_Slug', 'append_admin_columns'));
    36             add_action('manage_page_posts_custom_column',  array('TS_Search_Slug', 'append_admin_columns_data'), 10, 2);
    37             add_filter('manage_edit-page_sortable_columns', array('TS_Search_Slug', 'make_custom_columns_sortable'));
     39            add_action('manage_post_posts_custom_column',  array('TS_Search_Slug', 'append_admin_columns_data'), 10, 2);
     40            add_filter('manage_edit-post_sortable_columns', array('TS_Search_Slug', 'make_custom_columns_sortable'));
     41
     42            add_filter('manage_page_posts_columns', array('TS_Search_Slug', 'append_admin_columns'));
     43            add_action('manage_page_posts_custom_column',  array('TS_Search_Slug', 'append_admin_columns_data'), 10, 2);
     44            add_filter('manage_edit-page_sortable_columns', array('TS_Search_Slug', 'make_custom_columns_sortable'));
    3845           
    3946            $all_options = get_option('ts_search_slug_settings');
     
    5562           
    5663            add_filter('posts_where' , array('TS_Search_Slug', 'posts_where'), 10, 2);
    57         }
    58        
    59         public static function add_options_page() {
     64
     65            $settings = get_option('ts_search_slug_settings');
     66            $post_states_list = isset($settings['post_states_list']) ? $settings['post_states_list'] : '';
     67            if((int) $post_states_list === 1) {
     68                add_action('manage_posts_extra_tablenav', array('TS_Search_Slug', 'add_page_states_list_to_backend'), 1, 999);
     69                add_action('admin_footer', array('TS_Search_Slug', 'add_page_states_list_markup_to_backend'));
     70            }
     71
     72            add_action('wp_ajax_tsinf_get_state_list', array('TS_Search_Slug', 'ajax_get_state_list'));
     73            add_action('wp_ajax_nopriv_tsinf_get_state_list', array('TS_Search_Slug', 'ajax_get_state_list'));
     74
     75
     76            add_filter('manage_edit-post_sortable_columns', function ($columns) {
     77                $columns['author'] = 'author';
     78                return $columns;
     79            });
     80
     81        }
     82
     83        public static function load_scripts_and_styles() {
     84            wp_enqueue_style('ts-search-slug-style', plugins_url('css/backend.css', __FILE__), array(), TS_Search_Slug_Version);
     85            wp_enqueue_script('ts-search-slug-script', plugins_url('js/backend.js', __FILE__), array('jquery'), TS_Search_Slug_Version, array('in_footer' => true));
     86
     87            wp_localize_script('ts-search-slug-script', 'TS_Search_Slug_JS_Obj', array(
     88                'ajax_url' => admin_url('admin-ajax.php'),
     89                'nonce' => wp_create_nonce('6PPBo?7cKN8f4=evtaRE%rPN;L{5dg5')
     90            ));
     91        }
     92
     93        public static function add_options_page() {
    6094            add_submenu_page(
    6195                'options-general.php',
     
    83117            ?>
    84118            </form>
     119            <style type="text/css">
     120                .settings_page_ts_search_slug .activate_features_for_cpt_wrap {
     121                    padding: 5px 0;
     122                }
     123
     124                .settings_page_ts_search_slug .tsinf_search_slug_line {
     125                    margin: 5px 0 10px 0;
     126                }
     127            </style>
    85128            <?php
    86129        }
     
    97140            add_settings_field(
    98141                    'ts_search_slug_post_types',
    99                     __('Enable Post Slug Functionality for Custom Post Types', 'ts-search-slug'),
     142                    __('Enable Post Slug Functionality for additional Custom Post Types', 'ts-search-slug'),
    100143                    array('TS_Search_Slug', 'render_options_page_field_post_types'),
    101144                    'ts_search_slug',
    102145                    'ts_search_slug_plugin_main_section'
    103                 );
     146            );
     147
     148            add_settings_field(
     149                'ts_search_slug_post_types_id',
     150                __('Enable Post ID Functionality for Post Types', 'ts-search-slug'),
     151                array('TS_Search_Slug', 'render_options_page_field_post_types_id'),
     152                'ts_search_slug',
     153                'ts_search_slug_plugin_main_section'
     154            );
     155
     156            add_settings_field(
     157                'ts_search_slug_post_states_list',
     158                __('Enable Post States List in Page Overview', 'ts-search-slug'),
     159                array('TS_Search_Slug', 'render_options_page_field_post_states_list'),
     160                'ts_search_slug',
     161                'ts_search_slug_plugin_main_section'
     162            );
    104163           
    105164            register_setting('ts_search_slug', 'ts_search_slug_settings', 'post_types');
     165            register_setting('ts_search_slug', 'ts_search_slug_settings', 'post_types_id');
     166            register_setting('ts_search_slug', 'ts_search_slug_settings', 'post_states_list');
    106167        }
    107168       
     
    115176            $args = array(
    116177                'public'   => true,
    117                 '_builtin' => false,
     178                '_builtin' => false,
    118179                'show_ui' => true
    119180            );
    120181            $post_types = get_post_types($args, 'object');
     182
    121183            if(is_array($post_types) && count($post_types) > 0)
    122184            {
     
    133195                foreach($post_types as $post_type)
    134196                {
    135                     $checked = "";
    136                     if(in_array($post_type->name, $activated_cpts))
    137                     {
    138                         $checked = " checked='checked' ";
    139                     }
    140             ?>
    141                 <div class="tsinf_search_slug_line">
    142                     <input type="checkbox" name="ts_search_slug_settings[post_types][]" <?php echo esc_attr($checked); ?> value="<?php echo esc_attr($post_type->name); ?>" />
    143                     <span class="label"><?php echo esc_html($post_type->label); ?> (<?php echo esc_attr($post_type->name); ?>)</span>
    144                 </div>
    145             <?php
     197                    ?>
     198                        <div class="tsinf_search_slug_line">
     199                            <input type="checkbox" name="ts_search_slug_settings[post_types][]" <?php checked(in_array($post_type->name, $activated_cpts), true); ?> value="<?php echo esc_attr($post_type->name); ?>" />
     200                            <span class="label"><?php echo esc_html($post_type->label); ?> (<?php echo esc_attr($post_type->name); ?>)</span>
     201                        </div>
     202                    <?php
    146203                }
    147204                ?>
     205                    <strong><small><?php esc_html_e('For compatibility with previous versions, the built-in post types (Post, Page) are always enabled for the slug functionality. Therefore, they do not appear in the settings here.', 'ts-search-slug'); ?></small></strong>
    148206                </div>
    149207                <?php
    150208            }
    151209        }
     210
     211        public static function render_options_page_field_post_types_id() {
     212            $args = array(
     213                'public'   => true,
     214                'show_ui' => true
     215            );
     216            $post_types = get_post_types($args, 'object');
     217            if(is_array($post_types) && count($post_types) > 0)
     218            {
     219                ?>
     220                <div class="activate_features_for_cpt_wrap">
     221                    <?php
     222                    $all_options = get_option('ts_search_slug_settings');
     223                    $activated_cpts = array();
     224                    if(is_array($all_options) && isset($all_options['post_types_id']))
     225                    {
     226                        $activated_cpts = $all_options['post_types_id'];
     227                    }
     228
     229                    foreach($post_types as $post_type)
     230                    {
     231                        ?>
     232                        <div class="tsinf_search_slug_line">
     233                            <input type="checkbox" name="ts_search_slug_settings[post_types_id][]" <?php checked(in_array($post_type->name, $activated_cpts), true); ?> value="<?php echo esc_attr($post_type->name); ?>" />
     234                            <span class="label"><?php echo esc_html($post_type->label); ?> (<?php echo esc_attr($post_type->name); ?>)</span>
     235                        </div>
     236                        <?php
     237                    }
     238                    ?>
     239                </div>
     240                <?php
     241            }
     242        }
     243
     244        public static function render_options_page_field_post_states_list() {
     245            $settings = get_option('ts_search_slug_settings');
     246            $post_states_list = isset($settings['post_states_list']) ? $settings['post_states_list'] : '';
     247            ?>
     248            <div class="tsinf_search_slug_line">
     249                <input type="checkbox" name="ts_search_slug_settings[post_states_list]" <?php checked($post_states_list, 1); ?> value="1" />
     250            </div>
     251            <?php
     252        }
    152253       
    153254        /**
     
    158259        public static function append_admin_columns($columns) {
    159260            $columns['ts_search_slug_post_name'] = __('Postname/Slug', 'ts-search-slug');
     261            $columns['ts_search_slug_post_id'] = __('ID', 'ts-search-slug');
    160262       
    161263            return $columns;
     
    174276                    echo esc_attr(basename(get_permalink()));
    175277                    break;
    176        
    177                
    178        
     278
     279                case 'ts_search_slug_post_id':
     280                    echo (int) get_the_ID();
     281                    break;
     282
    179283            }
    180284        }
     
    187291        public static function make_custom_columns_sortable($columns) {
    188292            $columns['ts_search_slug_post_name'] = 'post_name';
     293            $columns['ts_search_slug_post_id'] = 'ID';
    189294       
    190295            return $columns;
     
    198303        public static function posts_where($where, $wp_query) {
    199304            global $pagenow;
    200            
     305
    201306            $post_type = '';
    202307            if(isset($_GET['post_type']))
     
    204309                $post_type = wp_strip_all_tags(wp_unslash($_GET['post_type']));
    205310            }
    206            
    207             $all_options = get_option('ts_search_slug_settings');
    208             $activated_cpts = array();
    209             if(is_array($all_options) && isset($all_options['post_types']))
    210             {
    211                 $activated_cpts = $all_options['post_types'];
    212             }
    213            
    214             $search = (isset($_GET['s'])) ? sanitize_text_field(wp_unslash($_GET['s'])) : '';
    215             if(is_admin() && 'edit.php' === $pagenow && is_string($search) && strlen($search) > 0 && ($post_type === 'post' || $post_type === 'page' || in_array($post_type, $activated_cpts)))
    216             {
    217                 global $wpdb;
    218                
    219                 $like = '%' . $wpdb->esc_like($search) . '%';
    220                 $like_term = $wpdb->prepare("({$wpdb->posts}.post_name LIKE %s)", $like);
    221                
    222                 $like_search_pattern = $wpdb->prepare("({$wpdb->posts}.post_title LIKE %s)", $like);
    223                 $like_search_replace = " " . $like_search_pattern . " OR " . $like_term . " ";
    224                
    225                 $where = str_replace($like_search_pattern, $like_search_replace, $where);
    226             }
     311
     312            if(!is_string($post_type) || (is_string($post_type) && strlen($post_type) < 1)) {
     313                $post_type = $wp_query->query['post_type'];
     314            }
     315
     316            $search = "";
     317            if(isset($_GET['s']) && is_string($_GET['s']) && strlen($_GET['s']) > 1) {
     318                $search = sanitize_text_field(wp_unslash($_GET['s']));
     319            } else if(isset($wp_query->query['s']) && is_string($wp_query->query['s']) && strlen($wp_query->query['s']) > 1) {
     320                $search = sanitize_text_field(wp_unslash($wp_query->query['s']));
     321            };
     322
     323
     324            if(is_admin() && 'edit.php' === $pagenow && is_string($search) && strlen($search) > 0) {
     325
     326                $all_options = get_option('ts_search_slug_settings');
     327                $activated_cpts = array();
     328                $activated_cpts_id = array();
     329                $all_options_is_array = is_array($all_options);
     330                if($all_options_is_array && isset($all_options['post_types']))
     331                {
     332                    $activated_cpts = $all_options['post_types'];
     333                }
     334
     335                if($all_options_is_array && isset($all_options['post_types_id']))
     336                {
     337                    $activated_cpts_id = $all_options['post_types_id'];
     338                }
     339
     340                global $wpdb;
     341                if ((is_array($activated_cpts) && in_array($post_type, $activated_cpts)) || ($post_type === 'post') || ($post_type === 'page')) {
     342                    $like = '%' . $wpdb->esc_like($search) . '%';
     343                    $like_term = $wpdb->prepare("({$wpdb->posts}.post_name LIKE %s)", $like);
     344
     345                    $like_search_pattern = $wpdb->prepare("({$wpdb->posts}.post_title LIKE %s)", $like);
     346                    $like_search_replace = " " . $like_search_pattern . " OR " . $like_term . " ";
     347
     348                    $where = str_replace($like_search_pattern, $like_search_replace, $where);
     349                }
     350
     351
     352                if (is_array($activated_cpts_id) && in_array($post_type, $activated_cpts_id)) {
     353
     354                    // WordPress trennt komma-separierte Suchbergiffe schon in OR Teile
     355                    $search_ids = array();
     356                    if (preg_match('/^(\d+)(,\d+)*$/', $search, $matches)) {
     357                        $search_ids = explode(',', $search);
     358                        $search_ids = array_map('intval', $search_ids);
     359                    }
     360
     361                    if (!empty($search_ids)) {
     362                        $id_where = " OR {$wpdb->posts}.ID IN (" . implode(',', $search_ids) . ")";
     363                        $where .= $id_where;
     364                    }
     365
     366                }
     367
     368            }
     369
     370
    227371           
    228372            return $where;
    229373        }
    230     }
     374
     375        /**
     376         *
     377         * @return void
     378         */
     379        public static function add_page_states_list_to_backend() {
     380            global $typenow;
     381            if ( $typenow == 'page' ) {
     382                echo '<input type="button" class="button button-primary" id="ts-search-slug-open-state-list" value="' . esc_attr('Open "Pages with States" List', 'ts-search-slug') . '" style="margin-left:10px;" />';
     383            }
     384        }
     385
     386        /**
     387         *
     388         * @return void
     389         */
     390        public static function add_page_states_list_markup_to_backend() {
     391            global $typenow;
     392            if ( $typenow == 'page' ) {
     393                echo '<div id="ts-search-slug-page-state-menu" class="list-empty" style="display: none;">
     394                        <button id="ts-search-slug-page-state-menu-close-button" class="button button-secondary" type="button">' . esc_html__('Close', 'ts-search-slug') . '</button>
     395                        <div class="ts-search-slug-page-state-menu-inner">' .
     396                            esc_html__('Loading ...', 'ts-search-slug') .
     397                        '</div>
     398                </div>';
     399            }
     400        }
     401
     402        public static function ajax_get_state_list() {
     403            check_ajax_referer('6PPBo?7cKN8f4=evtaRE%rPN;L{5dg5', 'security');
     404
     405            $pages_with_states = array();
     406
     407            $pages = get_pages(
     408                    array(
     409                        'sort_order' => 'ASC',
     410                        'sort_column' => 'post_title',
     411                        'hierarchical' => 0
     412                    )
     413            );
     414            foreach ( $pages as $page ) {
     415                $states = apply_filters( 'display_post_states', [], $page );
     416
     417                if ( !empty( $states ) ) {
     418                    $pages_with_states[$page->ID] = array(
     419                            'states' => array_map('esc_html', $states),
     420                            'title' => $page->post_title,
     421                            'link' => get_permalink($page->ID),
     422                            'backend_link' => admin_url(sprintf('/post.php?post=%d&action=edit', (int) $page->ID)),
     423                    );
     424                }
     425            }
     426
     427            $response = array(
     428                'pages_with_states' => $pages_with_states,
     429            );
     430
     431            wp_send_json($response);
     432        }
     433
     434
     435
     436
     437    }
    231438   
    232439   
  • ts-search-slug/trunk/readme.txt

    r3185072 r3341948  
    22Contributors: tsinf
    33Tags: post, slug
    4 Requires at least: 4.8
    5 Tested up to: 6.6
    6 Stable Tag: 1.0.4
     4Requires at least: 6.4
     5Tested up to: 6.8
     6Stable Tag: 1.0.5
    77License: GPLv3
    88Creation time: 01.05.2018
    9 Last updated time: 10.11.2024
     9Last updated time: 09.08.2025
    1010
    1111Search for Slug in Admin Post/Page Overview and add Slug Column to Post/Page Overview.
    1212
    1313== Description ==
    14 With this plugin you can search posts and for their slug, see the slug in admin post overview in an additional column and sort by it
     14With this plugin you can search posts for their slug and their post id, see the slug and post id in admin post overview in an additional column and sort by them.
     15
     16For searching multiple Post IDs in the search field, you can separate them with ",", in example "36723,298525,3732".
     17
     18And you can see an overview of all pages which are tagged with post states, and quick switch to them.
     19For that, you must switch to the page overview and klick the button to open the list.
     20
     21Please keep in mind, this is a hobby project and I need some time to respond.
     22I'm always open to suggestions for improvement.
     23
     24Please contact me over the support forum on the plugin page on issues.
    1525
    1626== Installation ==
     
    2131
    2232== Changelog ==
     33* 1.0.5
     34- Add Post States List to Page Overview (must be activated in the settings)
     35- Add Post ID (Search and Sort) Functionality (must be activated in the settings)
     36- Add German Translation
     37
    2338* 1.0.4
    24 WP Plugin Check related fixes
     39- WP Plugin Check related fixes
    2540
    2641* 1.0.3
    27 Fix PHP Warning "Parameter 2 to posts_where() expected to be a reference, value given"
     42- Fix PHP Warning "Parameter 2 to posts_where() expected to be a reference, value given"
    2843
    2944* 1.0.2
    30 Fix bug, that other search parameters in admin area are ignored when slug search is activated
     45- Fix bug, that other search parameters in admin area are ignored when slug search is activated
    3146
    3247* 1.0.1
    33 Add custom post type support
     48- Add custom post type support
    3449
    3550
Note: See TracChangeset for help on using the changeset viewer.