Changeset 3341948
- Timestamp:
- 08/09/2025 09:56:21 AM (8 months ago)
- Location:
- ts-search-slug
- Files:
-
- 20 added
- 2 edited
-
tags/1.0.5 (added)
-
tags/1.0.5/css (added)
-
tags/1.0.5/css/backend.css (added)
-
tags/1.0.5/index.php (added)
-
tags/1.0.5/js (added)
-
tags/1.0.5/js/backend.js (added)
-
tags/1.0.5/languages (added)
-
tags/1.0.5/languages/ts-search-slug-de_DE.l10n.php (added)
-
tags/1.0.5/languages/ts-search-slug-de_DE.mo (added)
-
tags/1.0.5/languages/ts-search-slug-de_DE.po (added)
-
tags/1.0.5/license.txt (added)
-
tags/1.0.5/plugin.php (added)
-
tags/1.0.5/readme.txt (added)
-
trunk/css (added)
-
trunk/css/backend.css (added)
-
trunk/js (added)
-
trunk/js/backend.js (added)
-
trunk/languages/ts-search-slug-de_DE.l10n.php (added)
-
trunk/languages/ts-search-slug-de_DE.mo (added)
-
trunk/languages/ts-search-slug-de_DE.po (added)
-
trunk/plugin.php (modified) (13 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ts-search-slug/trunk/plugin.php
r3185072 r3341948 7 7 Author: Tobias Spiess 8 8 Author URI: https://www.spiess-informatik.de 9 Version: 1.0. 49 Version: 1.0.5 10 10 Text-Domain: ts-search-slug 11 11 Domain Path: /languages … … 13 13 14 14 /** 15 * Load Plugin Translations15 * Deprecated: Load Plugin Translations 16 16 */ 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 22 if(!defined('TS_Search_Slug_Version')) 23 { 24 define('TS_Search_Slug_Version', '1.0.5'); 19 25 } 20 add_action( 'plugins_loaded', 'tsinf_search_slug_load_plugin_textdomain' );21 26 22 27 if(!defined('TS_Search_Slug')) … … 28 33 add_action('admin_menu', array('TS_Search_Slug', 'add_options_page')); 29 34 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 31 38 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')); 38 45 39 46 $all_options = get_option('ts_search_slug_settings'); … … 55 62 56 63 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() { 60 94 add_submenu_page( 61 95 'options-general.php', … … 83 117 ?> 84 118 </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> 85 128 <?php 86 129 } … … 97 140 add_settings_field( 98 141 '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'), 100 143 array('TS_Search_Slug', 'render_options_page_field_post_types'), 101 144 'ts_search_slug', 102 145 '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 ); 104 163 105 164 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'); 106 167 } 107 168 … … 115 176 $args = array( 116 177 'public' => true, 117 '_builtin' => false,178 '_builtin' => false, 118 179 'show_ui' => true 119 180 ); 120 181 $post_types = get_post_types($args, 'object'); 182 121 183 if(is_array($post_types) && count($post_types) > 0) 122 184 { … … 133 195 foreach($post_types as $post_type) 134 196 { 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 146 203 } 147 204 ?> 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> 148 206 </div> 149 207 <?php 150 208 } 151 209 } 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 } 152 253 153 254 /** … … 158 259 public static function append_admin_columns($columns) { 159 260 $columns['ts_search_slug_post_name'] = __('Postname/Slug', 'ts-search-slug'); 261 $columns['ts_search_slug_post_id'] = __('ID', 'ts-search-slug'); 160 262 161 263 return $columns; … … 174 276 echo esc_attr(basename(get_permalink())); 175 277 break; 176 177 178 278 279 case 'ts_search_slug_post_id': 280 echo (int) get_the_ID(); 281 break; 282 179 283 } 180 284 } … … 187 291 public static function make_custom_columns_sortable($columns) { 188 292 $columns['ts_search_slug_post_name'] = 'post_name'; 293 $columns['ts_search_slug_post_id'] = 'ID'; 189 294 190 295 return $columns; … … 198 303 public static function posts_where($where, $wp_query) { 199 304 global $pagenow; 200 305 201 306 $post_type = ''; 202 307 if(isset($_GET['post_type'])) … … 204 309 $post_type = wp_strip_all_tags(wp_unslash($_GET['post_type'])); 205 310 } 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 227 371 228 372 return $where; 229 373 } 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 } 231 438 232 439 -
ts-search-slug/trunk/readme.txt
r3185072 r3341948 2 2 Contributors: tsinf 3 3 Tags: post, slug 4 Requires at least: 4.85 Tested up to: 6. 66 Stable Tag: 1.0. 44 Requires at least: 6.4 5 Tested up to: 6.8 6 Stable Tag: 1.0.5 7 7 License: GPLv3 8 8 Creation time: 01.05.2018 9 Last updated time: 10.11.20249 Last updated time: 09.08.2025 10 10 11 11 Search for Slug in Admin Post/Page Overview and add Slug Column to Post/Page Overview. 12 12 13 13 == 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 14 With 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 16 For searching multiple Post IDs in the search field, you can separate them with ",", in example "36723,298525,3732". 17 18 And you can see an overview of all pages which are tagged with post states, and quick switch to them. 19 For that, you must switch to the page overview and klick the button to open the list. 20 21 Please keep in mind, this is a hobby project and I need some time to respond. 22 I'm always open to suggestions for improvement. 23 24 Please contact me over the support forum on the plugin page on issues. 15 25 16 26 == Installation == … … 21 31 22 32 == 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 23 38 * 1.0.4 24 WP Plugin Check related fixes39 - WP Plugin Check related fixes 25 40 26 41 * 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" 28 43 29 44 * 1.0.2 30 Fix bug, that other search parameters in admin area are ignored when slug search is activated45 - Fix bug, that other search parameters in admin area are ignored when slug search is activated 31 46 32 47 * 1.0.1 33 Add custom post type support48 - Add custom post type support 34 49 35 50
Note: See TracChangeset
for help on using the changeset viewer.