PluginProbe
Catch IDs / trunk
Catch IDs vtrunk
2.7.3 2.8 2.8.1 3.0 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 All 39 releases
catch-ids / catch-ids.php

catch-ids.php in Catch IDs trunk, at catch-ids.php

515 lines 15.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The plugin bootstrap file
5 *
6 * This file is read by WordPress to generate the plugin information in the plugin
7 * admin area. This file also includes all of the dependencies used by the plugin,
8 * registers the activation and deactivation functions, and defines a function
9 * that starts the plugin.
10 *
11 * @link catchplugins.com
12 * @since 1.0.0
13 * @package Catch_IDs
14 *
15 * @wordpress-plugin
16 * Plugin Name: Catch IDs
17 * Plugin URI: https://catchplugins.com/plugins/catch-ids/
18 * Description: Catch IDs is a simple and light weight plugin to show the Post ID, Page ID, Media ID, Links ID, Category ID, Tag ID and User ID in the Admin Section Table. This plugin was initially develop to support our themes features slider. Then we thought that this will be helpful to all the WordPress Admin Users. Just activate and catch IDs in your page, post, category, tag and media pages.
19 * Version: 3.0
20 * Author: Catch Plugins
21 * Author URI: https://catchplugins.com
22 * License: GPL-3.0+
23 * License URI: http://www.gnu.org/licenses/gpl-3.0.txt
24 * Text Domain: catch-ids
25 * Tags: catch-ids, simple, admin, wp-admin, show, ids, post, page, category, media, links, tag, user, id, post id, page id, category id
26 * Domain Path: /languages
27 */
28
29 /*
30 Copyright (C) 2018 Catch Plugins, (info@catchplugins.com)
31
32 This program is free software; you can redistribute it and/or modify
33 it under the terms of the GNU General Public License as published by
34 the Free Software Foundation; either version 3 of the License, or
35 (at your option) any later version.
36
37 This program is distributed in the hope that it will be useful,
38 but WITHOUT ANY WARRANTY; without even the implied warranty of
39 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 GNU General Public License for more details.
41
42 You should have received a copy of the GNU General Public License
43 along with this program. If not, see <http://www.gnu.org/licenses/>.
44 */
45
46 /**
47 * Make plugin available for translation
48 * Translations can be filed in the /languages/ directory
49 */
50
51 if (! defined('ABSPATH')) {
52 exit;
53 }
54
55 // Define Version
56 if (! defined('CATCH_IDS_VERSION')) {
57 define('CATCH_IDS_VERSION', '3.0');
58 }
59
60 // The URL of the directory that contains the plugin
61 if (! defined('CATCH_IDS_URL')) {
62 define('CATCH_IDS_URL', plugin_dir_url(__FILE__));
63 }
64
65
66 // The absolute path of the directory that contains the file
67 if (! defined('CATCH_IDS_PATH')) {
68 define('CATCH_IDS_PATH', plugin_dir_path(__FILE__));
69 }
70
71
72 // Gets the path to a plugin file or directory, relative to the plugins directory, without the leading and trailing slashes.
73 if (! defined('CATCH_IDS_BASENAME')) {
74 define('CATCH_IDS_BASENAME', plugin_basename(__FILE__));
75 }
76
77 function catchids_load_textdomain()
78 {
79 load_plugin_textdomain('catch-ids', false, plugin_basename(dirname(__FILE__)) . '/languages');
80 }
81 add_action('plugins_loaded', 'catchids_load_textdomain');
82
83
84 /**
85 * @package Catch Plugins
86 * @subpackage Catch IDs
87 * @since Catch IDs 1.0
88 */
89
90 if (! function_exists('catchids_column')) :
91 /**
92 * Prepend the new column to the columns array
93 */
94 function catchids_column($cols)
95 {
96 $column_id = array('catchids' => esc_html__('ID', 'catch-ids'));
97 $cols = array_slice($cols, 0, 1, true) + $column_id + array_slice($cols, 1, null, true);
98 return $cols;
99 }
100
101 endif; // catchids_column
102
103 if (! function_exists('catchids_value')) :
104 /**
105 * Echo the ID for the new column
106 */
107 function catchids_value($column_name, $id)
108 {
109 if ('catchids' == $column_name) {
110 echo esc_html($id);
111 }
112 }
113 endif; // catchids_value
114
115
116 if (! function_exists('catchids_return_value')) :
117 function catchids_return_value($value, $column_name, $id)
118 {
119 if ('catchids' == $column_name) {
120 $value .= absint($id);
121 }
122 return $value;
123 }
124 endif; // catchids_return_value
125
126
127 if (! function_exists('catchids_css')) :
128 /**
129 * Output CSS for width of new column
130 */
131 function catchids_css()
132 {
133 ?>
134 <style type="text/css">
135 #catchids {
136 width: 80px;
137 }
138
139 @media screen and (max-width: 782px) {
140
141 .wp-list-table #catchids,
142 .wp-list-table #the-list .catchids {
143 display: none;
144 }
145
146 .wp-list-table #the-list .is-expanded .catchids {
147 padding-left: 30px;
148 }
149 }
150 </style>
151 <?php
152 }
153 endif; // catchids_css
154 add_action('admin_head', 'catchids_css');
155
156
157 if (! function_exists('catchids_add')) :
158 /**
159 * Actions/Filters for various tables and the css output
160 */
161 function catchids_add()
162 {
163 $options = catchids_get_options();
164 // For Media Management
165 if (is_array($options) && array_key_exists('media', $options) && (1 == $options['media'])) {
166 add_action('manage_media_columns', 'catchids_column');
167 add_filter('manage_media_custom_column', 'catchids_value', 10, 3);
168 }
169
170 // For Link Management
171 add_action('manage_link_custom_column', 'catchids_value', 10, 2);
172 add_filter('manage_link-manager_columns', 'catchids_column');
173
174 // For Category Management
175 add_action('manage_edit-link-categories_columns', 'catchids_column');
176 add_filter('manage_link_categories_custom_column', 'catchids_return_value', 10, 3);
177
178 // For Category, Tags and other custom taxonomies Management
179 foreach (get_taxonomies() as $taxonomy) {
180 if (is_array($options) && array_key_exists('category', $options) && (1 == $options['category'])) {
181 add_action("manage_edit-{$taxonomy}_columns", 'catchids_column');
182 add_filter("manage_{$taxonomy}_custom_column", 'catchids_return_value', 10, 3);
183 add_filter("manage_edit-{$taxonomy}_sortable_columns", 'catchids_column');
184 }
185 }
186
187 foreach (get_post_types() as $ptype) {
188 if (is_array($options) && array_key_exists($ptype, $options) && (1 == $options[$ptype])) {
189 add_action("manage_edit-{$ptype}_columns", 'catchids_column');
190 add_filter("manage_{$ptype}_posts_custom_column", 'catchids_value', 10, 3);
191 add_filter("manage_edit-{$ptype}_sortable_columns", 'catchids_column');
192 }
193 }
194
195 // For User Management
196 if (is_array($options) && array_key_exists('user', $options) && (1 == $options['user'])) {
197 add_action('manage_users_columns', 'catchids_column');
198 add_filter('manage_users_custom_column', 'catchids_return_value', 10, 3);
199 add_filter('manage_users_sortable_columns', 'catchids_column');
200 }
201
202 // For Comment Management
203 if (is_array($options) && array_key_exists('comment', $options) && (1 == $options['comment'])) {
204 add_action('manage_edit-comments_columns', 'catchids_column');
205 add_action('manage_comments_custom_column', 'catchids_value', 10, 2);
206 add_filter('manage_edit-comments_sortable_columns', 'catchids_column');
207 }
208 }
209 endif; // catchids_add
210 add_action('admin_init', 'catchids_add');
211
212
213 if (! function_exists('catchids_get_all_post_types')) :
214 function catchids_get_all_post_types()
215 {
216 $post_types = get_post_types(array('public' => true));
217 $post_type_list = array();
218 foreach ($post_types as $key => $value) {
219 if ('attachment' != $key) {
220 $data = str_replace('-', ' ', $value);
221 $data = str_replace('_', ' ', $data);
222 $post_type_list[$key] = ucwords($data);
223 }
224 }
225 return $post_type_list;
226 }
227 endif; // catchids_get_all_post_types
228
229
230 if (! function_exists('catchids_get_options')) :
231 function catchids_get_options()
232 {
233 $defaults = catchids_default_options();
234 $options = get_option('catchids_options', $defaults);
235
236 return wp_parse_args($options, $defaults);
237 }
238 endif; // catchids_get_options
239
240
241 if (! function_exists('catchids_default_options')) :
242 /**
243 * Return array of default options
244 *
245 * @since 1.0
246 * @return array default options.
247 */
248 function catchids_default_options($option = null)
249 {
250 $types = catchids_get_all_post_types();
251 foreach ($types as $key => $value) {
252 $default_options[$key] = 1;
253 }
254 $default_options['category'] = 1;
255 $default_options['media'] = 1;
256 $default_options['user'] = 1;
257 $default_options['comment'] = 1;
258 $default_options['theme_plugin_tabs'] = 1;
259
260 if (null === $option) {
261 return apply_filters('catchids_options', $default_options);
262 } else {
263 return $default_options[$option];
264 }
265 }
266 endif; // catchids_default_options
267
268
269 if (! function_exists('catchids_add_plugin_settings_menu')) :
270 function catchids_add_plugin_settings_menu()
271 {
272 add_menu_page(
273 esc_html__('Catch IDs', 'catch-ids'), //page title
274 esc_html__('Catch IDs', 'catch-ids'), //menu title
275 'manage_options', //capability needed
276 'catch-ids', //menu slug (and page query url)
277 'catchids_settings',
278 'dashicons-editor-ol',
279 '99.01564'
280 );
281 }
282 endif; // catchids_add_plugin_settings_menu
283 add_action('admin_menu', 'catchids_add_plugin_settings_menu');
284
285
286 if (! function_exists('catchids_settings')) :
287 function catchids_settings()
288 {
289 $child_theme = false;
290 if (! current_user_can('manage_options')) {
291 wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'catch-ids'));
292 }
293
294 require_once plugin_dir_path(__FILE__) . 'partials/catch-ids-display.php';
295 }
296 endif; // catchids_settings
297
298
299 if (! function_exists('catchids_sanitize_callback')) :
300 /**
301 * Sanitize callback for catchids_options.
302 *
303 * @param array $input Raw input array.
304 * @return array Sanitized options.
305 */
306 function catchids_sanitize_callback($input)
307 {
308 $defaults = catchids_default_options();
309 $output = array();
310
311 foreach ($defaults as $key => $default) {
312 $output[$key] = isset($input[$key]) ? (int) $input[$key] : 0;
313 }
314
315 return $output;
316 }
317 endif; // catchids_sanitize_callback
318
319 if (! function_exists('catchids_register_settings')) :
320 /**
321 * Catch IDs: register_settings
322 * Catch IDs Register Settings
323 */
324 function catchids_register_settings()
325 {
326 register_setting(
327 'catchids-group',
328 'catchids_options',
329 'catchids_sanitize_callback'
330 );
331 }
332 endif; // catchids_register_settings
333 add_action('admin_init', 'catchids_register_settings');
334
335
336 if (! function_exists('catchids_action_links')) :
337 /**
338 * Catch_IDs: catchids_action_links
339 * Catch_IDs Settings Link function callback
340 *
341 * @param arrray $links Link url.
342 *
343 * @param arrray $file File name.
344 */
345 function catchids_action_links($links, $file)
346 {
347 if ($file === 'catch-ids/catch-ids.php') {
348 $settings_link = '<a href="' . esc_url(admin_url('admin.php?page=catch-ids')) . '">' . esc_html__('Settings', 'catch-ids') . '</a>';
349
350 array_unshift($links, $settings_link);
351 }
352 return $links;
353 }
354 endif; // catchids_action_links
355 add_filter('plugin_action_links', 'catchids_action_links', 10, 2);
356
357
358 if (! function_exists('catchids_enqueue_styles')) :
359 function catchids_enqueue_styles($hook_suffix)
360 {
361
362 if ('toplevel_page_catch-ids' === $hook_suffix) {
363
364 wp_enqueue_style('catchids-styles', plugin_dir_url(__FILE__) . 'css/catch-ids.css', array(), CATCH_IDS_VERSION, 'all');
365 wp_enqueue_style('catch-ids-dashboard-tabs', plugin_dir_url(__FILE__) . 'css/admin-dashboard.css', array(), CATCH_IDS_VERSION, 'all');
366 }
367 }
368 endif; // catchids_enqueue_styles
369 add_action('admin_enqueue_scripts', 'catchids_enqueue_styles');
370
371
372 if (! function_exists('catchids_enqueue_scripts')) :
373 function catchids_enqueue_scripts($hook_suffix)
374 {
375 if ('toplevel_page_catch-ids' === $hook_suffix) {
376
377 wp_enqueue_script('catch-ids-match-height', plugin_dir_url(__FILE__) . 'js/jquery.matchHeight.min.js', array('jquery'), CATCH_IDS_VERSION, true);
378 wp_enqueue_script('catchids-scripts', plugin_dir_url(__FILE__) . 'js/catch-ids.js', array('jquery', 'catch-ids-match-height'), CATCH_IDS_VERSION, true);
379 }
380 }
381 endif; // catchids_enqueue_scripts
382 add_action('admin_enqueue_scripts', 'catchids_enqueue_scripts');
383
384
385 if (! function_exists('catchids_handle_ajax_switch')) :
386 /**
387 * Shared handler for toggle-switch AJAX requests.
388 *
389 * @param string $nonce_action The nonce action string to verify against.
390 */
391 function catchids_handle_ajax_switch($nonce_action)
392 {
393 if (! isset($_POST['security'], $_POST['value'], $_POST['option_name'])) {
394 wp_die(esc_html__('Invalid request.', 'catch-ids'));
395 }
396
397 // Verify nonce.
398 $nonce = sanitize_text_field(wp_unslash($_POST['security']));
399 if (! wp_verify_nonce($nonce, $nonce_action)) {
400 wp_die(esc_html__('Unauthorized access!', 'catch-ids'));
401 }
402
403 // Capability check.
404 if (! current_user_can('manage_options')) {
405 wp_die(esc_html__('Permission denied!', 'catch-ids'));
406 }
407
408 // Sanitize inputs.
409 $raw_value = sanitize_text_field(wp_unslash($_POST['value']));
410 $value = ('true' === $raw_value) ? 1 : 0;
411 $option_name = sanitize_key(wp_unslash($_POST['option_name']));
412
413 // Update option.
414 $option_value = catchids_get_options();
415 $option_value[$option_name] = $value;
416
417 if (update_option('catchids_options', $option_value)) {
418 echo esc_html($value);
419 } else {
420 esc_html_e('Connection Error. Please try again.', 'catch-ids');
421 }
422
423 wp_die();
424 }
425 endif; // catchids_handle_ajax_switch
426
427 if (! function_exists('catchids_switch')) :
428 function catchids_switch()
429 {
430 catchids_handle_ajax_switch('catch_ids_nonce');
431 }
432 endif; // catchids_switch
433 add_action('wp_ajax_catchids_switch', 'catchids_switch');
434
435 if (! function_exists('ctp_switch')) :
436 function ctp_switch()
437 {
438 catchids_handle_ajax_switch('catch_ids_tabs_nonce');
439 }
440 endif; // ctp_switch
441 add_action('wp_ajax_ctp_switch', 'ctp_switch');
442
443 add_action('plugins_loaded', 'catchids_load_theme_plugin_tabs');
444
445 if (! function_exists('catchids_load_theme_plugin_tabs')) :
446 function catchids_load_theme_plugin_tabs()
447 {
448 $options = catchids_get_options();
449 if (1 == $options['theme_plugin_tabs']) {
450 /* Adds Catch Themes tab in Add theme page and Themes by Catch Themes in Customizer's change theme option. */
451 if (! class_exists('CatchThemesThemePlugin') && ! function_exists('add_our_plugins_tab')) {
452 require plugin_dir_path(__FILE__) . 'includes/CatchThemesThemePlugin.php';
453 }
454 }
455 }
456 endif; // catchids_load_theme_plugin_tabs
457
458 /* Adds support link and review link in plugin page */
459 add_filter('plugin_row_meta', 'catchids_add_plugin_meta_links', 10, 2);
460
461 if (! function_exists('catchids_add_plugin_meta_links')) :
462 function catchids_add_plugin_meta_links($meta_fields, $file)
463 {
464 if ($file === plugin_basename(__FILE__)) {
465
466 $allowed_html = array(
467 'a' => array(
468 'href' => array(),
469 'target' => array(),
470 'title' => array(),
471 ),
472 'i' => array('class' => array()),
473 'svg' => array(
474 'xmlns' => array(),
475 'width' => array(),
476 'height' => array(),
477 'viewbox' => array(),
478 'fill' => array(),
479 'stroke' => array(),
480 'stroke-width' => array(),
481 'stroke-linecap' => array(),
482 'stroke-linejoin' => array(),
483 'class' => array(),
484 ),
485 'polygon' => array('points' => array()),
486 );
487
488 $star_svg = "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>";
489
490 $meta_fields[] = wp_kses(
491 "<a href='https://catchplugins.com/support-forum/forum/catch-ids/' target='_blank'>Support Forum</a>",
492 $allowed_html
493 );
494 $meta_fields[] = wp_kses(
495 "<a href='https://wordpress.org/support/plugin/catch-ids/reviews#new-post' target='_blank' title='Rate'>"
496 . "<i class='ct-rate-stars'>"
497 . str_repeat($star_svg, 5)
498 . '</i></a>',
499 $allowed_html
500 );
501
502 $stars_color = '#ffb900';
503
504 echo '<style>'
505 . '.ct-rate-stars{display:inline-block;color:' . esc_attr($stars_color) . ';position:relative;top:3px;}'
506 . '.ct-rate-stars svg{fill:' . esc_attr($stars_color) . ';}'
507 . '.ct-rate-stars svg:hover{fill:' . esc_attr($stars_color) . '}'
508 . '.ct-rate-stars svg:hover ~ svg{fill:none;}'
509 . '</style>';
510 }
511
512 return $meta_fields;
513 }
514 endif; // catchids_add_plugin_meta_links
515