-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatch-ids.php
More file actions
370 lines (306 loc) · 12 KB
/
Copy pathcatch-ids.php
File metadata and controls
370 lines (306 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link catchplugins.com
* @since 1.0.0
* @package Catch_IDs
*
* @wordpress-plugin
* Plugin Name: Catch IDs
* Plugin URI: https://catchplugins.com/plugins/catch-ids/
* 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.
* Version: 1.7
* Author: Catch Plugins
* Author URI: catchplugins.com
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Text Domain: catch-ids
* Tags: catch-ids, simple, admin, wp-admin, show, ids, post, page, category, media, links, tag, user, id, post id, page id, category id
* Domain Path: /languages
*/
/*
Copyright (C) 2018 Catch Plugins, (info@catchplugins.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Make plugin available for translation
* Translations can be filed in the /languages/ directory
*/
if ( !defined( 'ABSPATH' ) ) exit;
// Define Version
define( 'CATCH_IDS_VERSION', '1.7' );
// The URL of the directory that contains the plugin
if ( !defined( 'CATCH_IDS_URL' ) ) {
define( 'CATCH_IDS_URL', plugin_dir_url( __FILE__ ) );
}
// The absolute path of the directory that contains the file
if ( !defined( 'CATCH_IDS_PATH' ) ) {
define( 'CATCH_IDS_PATH', plugin_dir_path( __FILE__ ) );
}
// Gets the path to a plugin file or directory, relative to the plugins directory, without the leading and trailing slashes.
if ( !defined( 'CATCH_IDS_BASENAME' ) ) {
define( 'CATCH_IDS_BASENAME', plugin_basename( __FILE__ ) );
}
function catchids_load_textdomain() {
load_plugin_textdomain( 'catch-ids', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
}
add_action( 'plugins_loaded', 'catchids_load_textdomain' );
/**
* @package Catch Plugins
* @subpackage Catch IDs
* @since Catch IDs 1.0
*/
if ( ! function_exists( 'catchids_column' ) ):
/**
* Prepend the new column to the columns array
*/
function catchids_column( $cols ) {
$column_id = array( 'catchids' => __( 'ID', 'catch-ids' ) );
$cols = array_slice( $cols, 0, 1, true ) + $column_id + array_slice( $cols, 1, NULL, true );
return $cols;
}
endif; // catchids_column
if ( ! function_exists( 'catchids_value' ) ) :
/**
* Echo the ID for the new column
*/
function catchids_value( $column_name, $id ) {
if ( 'catchids' == $column_name ) {
echo $id;
}
}
endif; // catchids_value
if ( ! function_exists( 'catchids_return_value' ) ) :
function catchids_return_value( $value, $column_name, $id ) {
if ( 'catchids' == $column_name ) {
$value .= $id;
}
return $value;
}
endif; // catchids_return_value
if ( ! function_exists( 'catchids_css' ) ) :
/**
* Output CSS for width of new column
*/
function catchids_css() {
?>
<style type="text/css">
#catchids { width: 80px; }
@media screen and (max-width: 782px) {
.wp-list-table #catchids, .wp-list-table #the-list .catchids { display: none; }
.wp-list-table #the-list .is-expanded .catchids {
padding-left: 30px;
}
}
</style>
<?php
}
endif; // catchids_css
add_action( 'admin_head', 'catchids_css');
if ( ! function_exists( 'catchids_add' ) ) :
/**
* Actions/Filters for various tables and the css output
*/
function catchids_add() {
$options = catchids_get_options();
// For Media Management
if( is_array( $options ) && array_key_exists( 'media', $options ) && ( 1 == $options['media'] ) ) {
add_action( "manage_media_columns" , 'catchids_column' );
add_filter( "manage_media_custom_column" , 'catchids_value' , 10 , 3 );
}
// For Link Management
add_action( 'manage_link_custom_column', 'catchids_value', 10, 2 );
add_filter( 'manage_link-manager_columns', 'catchids_column' );
// For Category Management
add_action( 'manage_edit-link-categories_columns', 'catchids_column' );
add_filter( 'manage_link_categories_custom_column', 'catchids_return_value', 10, 3 );
// For Category, Tags and other custom taxonomies Management
foreach( get_taxonomies() as $taxonomy ) {
if( is_array( $options ) && array_key_exists ( 'category', $options ) && ( 1 == $options['category'] ) ) {
add_action( "manage_edit-${taxonomy}_columns" , 'catchids_column' );
add_filter( "manage_${taxonomy}_custom_column" , 'catchids_return_value' , 10 , 3 );
if( version_compare($GLOBALS['wp_version'], '3.0.999', '>') ) {
add_filter( "manage_edit-${taxonomy}_sortable_columns" , 'catchids_column' );
}
}
}
foreach( get_post_types() as $ptype ) {
if( is_array( $options ) && array_key_exists ( $ptype, $options ) && ( 1 == $options[$ptype] ) ){
add_action( "manage_edit-${ptype}_columns" , 'catchids_column' );
add_filter( "manage_${ptype}_posts_custom_column" , 'catchids_value' , 10 , 3 );
if( version_compare($GLOBALS['wp_version'], '3.0.999', '>') ) {
add_filter( "manage_edit-${ptype}_sortable_columns" , 'catchids_column' );
}
}
}
// For User Management
if( is_array( $options ) && array_key_exists ( 'user', $options ) && ( 1 == $options['user'] ) ){
add_action( 'manage_users_columns', 'catchids_column' );
add_filter( 'manage_users_custom_column', 'catchids_return_value', 10, 3 );
if( version_compare($GLOBALS['wp_version'], '3.0.999', '>') ) {
add_filter( "manage_users_sortable_columns" , 'catchids_column' );
}
}
// For Comment Management
if( is_array( $options ) && array_key_exists ( 'comment', $options ) && ( 1 == $options['comment'] ) ){
add_action( 'manage_edit-comments_columns', 'catchids_column' );
add_action( 'manage_comments_custom_column', 'catchids_value', 10, 2 );
if( version_compare($GLOBALS['wp_version'], '3.0.999', '>') ) {
add_filter( "manage_edit-comments_sortable_columns" , 'catchids_column' );
}
}
}
endif; // catchids_add
add_action( 'admin_init', 'catchids_add' );
if ( ! function_exists( 'catchids_get_all_post_types' ) ) :
function catchids_get_all_post_types() {
$post_types = get_post_types( array( 'public' => true ) );
$post_type_list = array();
foreach ( $post_types as $key => $value ) {
if( 'attachment' != $key ) {
$data = str_replace('-', ' ', $value);
$data = str_replace('_', ' ', $data);
$post_type_list[$key] = ucwords( $data );
}
}
return $post_type_list;
}
endif; // catchids_get_all_post_types
if ( ! function_exists( 'catchids_get_options' ) ) :
function catchids_get_options() {
$defaults = catchids_default_options();
$options = get_option( 'catchids_options', $defaults );
return wp_parse_args( $options, $defaults ) ;
}
endif; // catchids_get_options
if ( ! function_exists( 'catchids_default_options' ) ) :
/**
* Return array of default options
*
* @since 1.0
* @return array default options.
*/
function catchids_default_options( $option = null ) {
$types = catchids_get_all_post_types();
foreach( $types as $key => $value ) {
$default_options[$key] = 1;
}
$default_options['category'] = 1;
$default_options['media'] = 1;
$default_options['user'] = 1;
$default_options['comment'] = 1;
if ( null == $option ) {
return apply_filters( 'catchids_options', $default_options );
}
else {
return $default_options[ $option ];
}
}
endif; // catchids_default_options
if ( ! function_exists( 'catchids_add_plugin_settings_menu' ) ) :
function catchids_add_plugin_settings_menu() {
add_menu_page(
esc_html__( 'Catch IDs', 'catch-ids' ), //page title
esc_html__( 'Catch IDs', 'catch-ids' ), //menu title
'edit_posts', //capability needed
'catch-ids', //menu slug (and page query url)
'catchids_settings',
'dashicons-editor-ol',
'99.01564'
);
}
endif; // catchids_add_plugin_settings_menu
add_action( 'admin_menu', 'catchids_add_plugin_settings_menu' );
if ( ! function_exists( 'catchids_settings' ) ) :
function catchids_settings() {
$child_theme = false;
if ( ! current_user_can( 'edit_posts' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'catch-ids' ) );
}
require_once plugin_dir_path( __FILE__ ) . 'partials/catch-ids-display.php';
}
endif; // catchids_settings
if ( ! function_exists( 'catchids_register_settings' ) ) :
/**
* Catch IDs: register_settings
* Catch IDs Register Settings
*/
function catchids_register_settings() {
register_setting(
'catchids-group',
'catchids_options',
'catchids_sanitize_callback'
);
}
endif; // catchids_register_settings
add_action( 'admin_init', 'catchids_register_settings' );
if ( ! function_exists( 'catchids_action_links' ) ) :
/**
* Catch_IDs: catchids_action_links
* Catch_IDs Settings Link function callback
*
* @param arrray $links Link url.
*
* @param arrray $file File name.
*/
function catchids_action_links( $links, $file ) {
if ( $file === 'catch-ids/catch-ids.php' ) {
$settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=catch-ids' ) ) . '">' . esc_html__( 'Settings', 'catch-ids' ) . '</a>';
array_unshift( $links, $settings_link );
}
return $links;
}
endif; // catchids_action_links
add_filter( 'plugin_action_links', 'catchids_action_links', 10, 2 );
if ( ! function_exists( 'catchids_enqueue_styles' ) ) :
function catchids_enqueue_styles() {
if( isset( $_GET['page'] ) && 'catch-ids' == $_GET['page'] ) {
wp_enqueue_style( 'catchids-styles', plugin_dir_url( __FILE__ ) . 'css/catch-ids.css', array(), '1.0', 'all' );
wp_enqueue_style( 'catch-ids-dashboard-tabs', plugin_dir_url( __FILE__ ) . 'css/admin-dashboard.css', array(), '1.0', 'all' );
}
}
endif; // catchids_enqueue_styles
add_action( 'admin_enqueue_scripts', 'catchids_enqueue_styles' );
if ( ! function_exists( 'catchids_enqueue_scripts' ) ) :
function catchids_enqueue_scripts() {
if( isset( $_GET['page'] ) && 'catch-ids' == $_GET['page'] ) {
wp_enqueue_script( 'catch-ids-match-height', plugin_dir_url( __FILE__ ) . 'js/jquery.matchHeight.min.js', array( 'jquery' ), '1.0', false );
wp_enqueue_script( 'catchids-scripts', plugin_dir_url( __FILE__ ) . 'js/catch-ids.js', array( 'jquery', 'catch-ids-match-height' ), '1.0', false );
}
}
endif; // catchids_enqueue_scripts
add_action( 'admin_enqueue_scripts', 'catchids_enqueue_scripts' );
add_action( 'wp_ajax_catchids_switch', 'catchids_switch' );
if ( ! function_exists( 'catchids_switch' ) ) :
function catchids_switch() {
$value = ( 'true' == $_POST['value'] ) ? 1 : 0;
$option_name = $_POST['option_name'];
$option_value = catchids_get_options( 'catchids_options' );
$option_value[$option_name] = $value;
if( update_option( 'catchids_options', $option_value ) ) {
echo $value;
} else {
esc_html_e( 'Connection Error. Please try again.', 'catch-ids' );
}
wp_die(); // this is required to terminate immediately and return a proper response
}
endif; // catchids_switch
/* Adds Catch Themes tab in Add theme page and Themes by Catch Themes in Customizer's change theme option. */
require plugin_dir_path( __FILE__ ) . 'includes/our-themes.php';
/* Adds Catch Plugins tab in Add theme page. */
require plugin_dir_path( __FILE__ ) . 'includes/our-plugins.php';