| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if( ! class_exists( 'MywpDeveloperAbstractModule' ) ) { |
| 8 |
return false; |
| 9 |
} |
| 10 |
|
| 11 |
if ( ! class_exists( 'MywpDeveloperModuleDevAdmin' ) ) : |
| 12 |
|
| 13 |
final class MywpDeveloperModuleDevAdmin extends MywpDeveloperAbstractModule { |
| 14 |
|
| 15 |
static protected $id = 'dev_admin'; |
| 16 |
|
| 17 |
static protected $priority = 20; |
| 18 |
|
| 19 |
static private $post_updated_messages = array(); |
| 20 |
|
| 21 |
static private $bulk_post_updated_messages = array(); |
| 22 |
|
| 23 |
protected static function after_init() { |
| 24 |
|
| 25 |
add_filter( 'post_updated_messages' , array( __CLASS__ , 'post_updated_messages' ) , 1000 ); |
| 26 |
|
| 27 |
add_filter( 'bulk_post_updated_messages' , array( __CLASS__ , 'bulk_post_updated_messages' ) , 1000 ); |
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
public static function post_updated_messages( $messages ) { |
| 32 |
|
| 33 |
global $typenow; |
| 34 |
|
| 35 |
if( empty( $typenow ) ) { |
| 36 |
|
| 37 |
return $messages; |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
if( isset( $messages[ $typenow ] ) ) { |
| 42 |
|
| 43 |
self::$post_updated_messages = $messages[ $typenow ]; |
| 44 |
|
| 45 |
} elseif( isset( $messages['post'] ) ) { |
| 46 |
|
| 47 |
self::$post_updated_messages = $messages[ 'post' ]; |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
return $messages; |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
public static function bulk_post_updated_messages( $bulk_messages ) { |
| 56 |
|
| 57 |
global $typenow; |
| 58 |
|
| 59 |
if( empty( $typenow ) ) { |
| 60 |
|
| 61 |
return $bulk_messages; |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
if( isset( $bulk_messages[ $typenow ] ) ) { |
| 66 |
|
| 67 |
self::$bulk_post_updated_messages = $bulk_messages[ $typenow ]; |
| 68 |
|
| 69 |
} elseif( isset( $bulk_messages['post'] ) ) { |
| 70 |
|
| 71 |
self::$bulk_post_updated_messages = $bulk_messages[ 'post' ]; |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
return $bulk_messages; |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
public static function mywp_debug_renders( $debug_renders ) { |
| 80 |
|
| 81 |
if( ! is_admin() ) { |
| 82 |
|
| 83 |
return $debug_renders; |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
$debug_renders[ self::$id ] = array( |
| 88 |
'debug_type' => 'dev', |
| 89 |
'title' => __( 'Current Admin Information' , 'my-wp' ), |
| 90 |
); |
| 91 |
|
| 92 |
return $debug_renders; |
| 93 |
|
| 94 |
} |
| 95 |
|
| 96 |
protected static function get_debug_lists() { |
| 97 |
|
| 98 |
global $wpdb; |
| 99 |
global $pagenow, $hook_suffix, $plugin_page, $page_hook, $typenow, $taxnow; |
| 100 |
global $post; |
| 101 |
global $user_id; |
| 102 |
|
| 103 |
$current_screen = false; |
| 104 |
|
| 105 |
$current_screen_id = false; |
| 106 |
|
| 107 |
if( function_exists( 'get_current_screen' ) ) { |
| 108 |
|
| 109 |
$current_screen = get_current_screen(); |
| 110 |
|
| 111 |
if( ! empty( $current_screen->id ) ) { |
| 112 |
|
| 113 |
$current_screen_id = $current_screen->id; |
| 114 |
|
| 115 |
} |
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
$debug_lists = array( |
| 120 |
'$pagenow' => $pagenow, |
| 121 |
'$hook_suffix' => $hook_suffix, |
| 122 |
'$plugin_page' => $plugin_page, |
| 123 |
'$page_hook' => $page_hook, |
| 124 |
'$typenow' => $typenow, |
| 125 |
'$taxnow' => $taxnow, |
| 126 |
'$current_screen' => $current_screen, |
| 127 |
); |
| 128 |
|
| 129 |
if( in_array( $pagenow , array( 'post.php' , 'post-new.php' ) ) ) { |
| 130 |
|
| 131 |
$post_id = (int) $post->ID; |
| 132 |
|
| 133 |
$debug_lists['post_id'] = $post_id; |
| 134 |
$debug_lists['post'] = $post; |
| 135 |
$debug_lists['custom_fields'] = get_post_meta( $post_id ); |
| 136 |
|
| 137 |
$debug_lists['taxonomies'] = array(); |
| 138 |
$debug_lists['terms'] = array(); |
| 139 |
|
| 140 |
$post_taxonomies = get_post_taxonomies( $post_id ); |
| 141 |
|
| 142 |
if( ! empty( $post_taxonomies ) ) { |
| 143 |
|
| 144 |
foreach( $post_taxonomies as $taxonomy_name ) { |
| 145 |
|
| 146 |
$debug_lists['taxonomies'][ $taxonomy_name ] = false; |
| 147 |
$debug_lists['terms'][ $taxonomy_name ] = false; |
| 148 |
|
| 149 |
$taxonomy = get_taxonomy( $taxonomy_name ); |
| 150 |
|
| 151 |
$terms = wp_get_post_terms( $post_id , $taxonomy_name ); |
| 152 |
|
| 153 |
if( empty( $taxonomy ) ) { |
| 154 |
|
| 155 |
continue; |
| 156 |
|
| 157 |
} |
| 158 |
|
| 159 |
$debug_lists['taxonomies'][ $taxonomy_name ] = $taxonomy; |
| 160 |
|
| 161 |
if( ! empty( $terms ) ) { |
| 162 |
|
| 163 |
$debug_lists['terms'][ $taxonomy_name ] = $terms; |
| 164 |
|
| 165 |
} |
| 166 |
|
| 167 |
} |
| 168 |
|
| 169 |
} |
| 170 |
|
| 171 |
$debug_lists['post_updated_messages'] = self::$post_updated_messages; |
| 172 |
|
| 173 |
$debug_lists['get_post( ' . $post_id . ' )'] = get_post( $post_id ); |
| 174 |
$debug_lists['MywpPostType::get_post( ' . $post_id . ' )'] = MywpPostType::get_post( $post_id ); |
| 175 |
$debug_lists['SELECT * FROM $wpdb->posts WHERE ID = ' . $post_id] = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id ) ); |
| 176 |
|
| 177 |
} elseif( in_array( $pagenow , array( 'edit.php' ) ) ) { |
| 178 |
|
| 179 |
$debug_lists['post_type'] = $typenow; |
| 180 |
$debug_lists['counts'] = wp_count_posts( $typenow ); |
| 181 |
|
| 182 |
$debug_lists['taxonomies'] = array(); |
| 183 |
|
| 184 |
$post_type_taxonomies = get_object_taxonomies( $typenow ); |
| 185 |
|
| 186 |
if( ! empty( $post_type_taxonomies ) ) { |
| 187 |
|
| 188 |
foreach( $post_type_taxonomies as $taxonomy_name ) { |
| 189 |
|
| 190 |
$debug_lists['taxonomies'][ $taxonomy_name ] = false; |
| 191 |
|
| 192 |
$taxonomy = get_taxonomy( $taxonomy_name ); |
| 193 |
|
| 194 |
if( empty( $taxonomy ) ) { |
| 195 |
|
| 196 |
continue; |
| 197 |
|
| 198 |
} |
| 199 |
|
| 200 |
$debug_lists['taxonomies'][ $taxonomy_name ] = $taxonomy; |
| 201 |
|
| 202 |
} |
| 203 |
|
| 204 |
} |
| 205 |
|
| 206 |
if( $typenow === 'page' ) { |
| 207 |
|
| 208 |
$debug_lists['column_filters'][] = 'manage_pages_columns'; |
| 209 |
|
| 210 |
} else { |
| 211 |
|
| 212 |
$debug_lists['column_filters'][] = 'manage_posts_columns'; |
| 213 |
|
| 214 |
} |
| 215 |
|
| 216 |
$debug_lists['column_filters'][] = sprintf( 'manage_%s_posts_columns (manage_{$typenow}_posts_columns)' , $typenow ); |
| 217 |
|
| 218 |
$debug_lists['sortable_column_filter'] = sprintf( 'manage_%s_sortable_columns (manage_{$this->screen->id}_sortable_columns)' , $current_screen_id ); |
| 219 |
|
| 220 |
if( $typenow === 'page' ) { |
| 221 |
|
| 222 |
$debug_lists['column_content_actions'][] = 'manage_pages_custom_column'; |
| 223 |
|
| 224 |
} else { |
| 225 |
|
| 226 |
$debug_lists['column_content_actions'][] = 'manage_posts_custom_column'; |
| 227 |
|
| 228 |
} |
| 229 |
|
| 230 |
$debug_lists['column_content_actions'][] = sprintf( 'manage_%s_posts_custom_column (manage_{$post->post_type}_posts_custom_column)' , $typenow ); |
| 231 |
|
| 232 |
$debug_lists['bulk_action_filter'] = sprintf( 'bulk_actions-%s (bulk_actions-{$this->screen->id})' , $current_screen_id ); |
| 233 |
|
| 234 |
$debug_lists['bulk_post_updated_messages'] = self::$bulk_post_updated_messages; |
| 235 |
|
| 236 |
} elseif( in_array( $pagenow , array( 'edit-tags.php' ) ) ) { |
| 237 |
|
| 238 |
$debug_lists['taxonomy'] = $taxnow; |
| 239 |
$debug_lists['count'] = wp_count_terms( $taxnow ); |
| 240 |
|
| 241 |
$debug_lists['column_filters'] = sprintf( 'manage_edit-%s_columns (manage_edit-{$taxnow}_columns)' , $taxnow ); |
| 242 |
|
| 243 |
$debug_lists['sortable_column_filter'] = sprintf( 'manage_%s_sortable_columns (manage_{$this->screen->id}_sortable_columns)' , $current_screen_id ); |
| 244 |
|
| 245 |
$debug_lists['column_content_actions'] = sprintf( 'manage_%s_custom_column' , $taxnow ); |
| 246 |
|
| 247 |
$debug_lists['bulk_action_filter'] = sprintf( 'bulk_actions-%s (bulk_actions-{$this->screen->id})' , $current_screen_id ); |
| 248 |
|
| 249 |
|
| 250 |
} elseif( in_array( $pagenow , array( 'term.php' ) ) ) { |
| 251 |
|
| 252 |
$debug_lists['taxonomy'] = $taxnow; |
| 253 |
$debug_lists['post_type'] = $typenow; |
| 254 |
|
| 255 |
$term_id = absint( $_REQUEST['tag_ID'] ); |
| 256 |
$deaub_lists['term_id'] = $term_id; |
| 257 |
$debug_lists['term'] = get_term( $term_id ); |
| 258 |
$debug_lists['custom_meta'] = get_term_meta( $term_id ); |
| 259 |
|
| 260 |
} elseif( in_array( $pagenow , array( 'users.php' ) ) ) { |
| 261 |
|
| 262 |
$debug_lists['count'] = count_users(); |
| 263 |
|
| 264 |
} elseif( in_array( $pagenow , array( 'user-edit.php' , 'profile.php' ) ) ) { |
| 265 |
|
| 266 |
$debug_lists['user_id'] = $user_id; |
| 267 |
$debug_lists['get_userdata()'] = get_userdata( $user_id ); |
| 268 |
$debug_lists['get_user_meta()'] = get_user_meta( $user_id ); |
| 269 |
|
| 270 |
} |
| 271 |
|
| 272 |
return $debug_lists; |
| 273 |
|
| 274 |
} |
| 275 |
|
| 276 |
protected static function mywp_developer_debug() { |
| 277 |
|
| 278 |
if( ! is_admin() ) { |
| 279 |
|
| 280 |
return false; |
| 281 |
|
| 282 |
} |
| 283 |
|
| 284 |
parent::mywp_developer_debug(); |
| 285 |
|
| 286 |
} |
| 287 |
|
| 288 |
protected static function mywp_debug_render() { |
| 289 |
|
| 290 |
if( ! is_admin() ) { |
| 291 |
|
| 292 |
return false; |
| 293 |
|
| 294 |
} |
| 295 |
|
| 296 |
parent::mywp_debug_render(); |
| 297 |
|
| 298 |
} |
| 299 |
|
| 300 |
} |
| 301 |
|
| 302 |
MywpDeveloperModuleDevAdmin::init(); |
| 303 |
|
| 304 |
endif; |
| 305 |
|