| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if( ! class_exists( 'MywpControllerAbstractModule' ) ) { |
| 8 |
return false; |
| 9 |
} |
| 10 |
|
| 11 |
if ( ! class_exists( 'MywpControllerModuleDebugGeneral' ) ) : |
| 12 |
|
| 13 |
final class MywpControllerModuleDebugGeneral extends MywpControllerAbstractModule { |
| 14 |
|
| 15 |
static protected $id = 'debug_general'; |
| 16 |
|
| 17 |
static protected $model_use_filter = false; |
| 18 |
|
| 19 |
static protected $is_do_controller = true; |
| 20 |
|
| 21 |
public static function mywp_controller_initial_data( $initial_data ) { |
| 22 |
|
| 23 |
$initial_data['users'] = array(); |
| 24 |
|
| 25 |
return $initial_data; |
| 26 |
|
| 27 |
} |
| 28 |
|
| 29 |
public static function mywp_controller_default_data( $default_data ) { |
| 30 |
|
| 31 |
$default_data['users'] = array(); |
| 32 |
|
| 33 |
return $default_data; |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
protected static function after_init() { |
| 38 |
|
| 39 |
add_filter( 'mywp_is_debug' , array( __CLASS__ , 'mywp_is_debug' ) , 9 ); |
| 40 |
|
| 41 |
add_action( 'after_setup_theme' , array( __CLASS__ , 'after_setup_theme' ) , 49 ); |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
public static function mywp_wp_loaded() { |
| 46 |
|
| 47 |
add_action( 'mywp_request_admin' , array( __CLASS__ , 'mywp_request_admin' ) , 49 ); |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
public static function mywp_is_debug( $is_debug ) { |
| 52 |
|
| 53 |
if( ! self::is_do_function( __FUNCTION__ ) ) { |
| 54 |
|
| 55 |
return false; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
$setting_data = self::get_setting_data(); |
| 60 |
|
| 61 |
if( empty( $setting_data['users'] ) ) { |
| 62 |
|
| 63 |
return false; |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
$user_id = get_current_user_id(); |
| 68 |
|
| 69 |
if( empty( $user_id ) ) { |
| 70 |
|
| 71 |
return false; |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
if( in_array( $user_id , $setting_data['users'] ) ) { |
| 76 |
|
| 77 |
return true; |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
self::after_do_function( __FUNCTION__ ); |
| 82 |
|
| 83 |
return false; |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
public static function after_setup_theme() { |
| 88 |
|
| 89 |
if( ! MywpDeveloper::is_debug() ) { |
| 90 |
|
| 91 |
return false; |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
add_filter( 'mywp_post_types' , array( __CLASS__ , 'mywp_post_types' ) , 49 ); |
| 96 |
|
| 97 |
} |
| 98 |
|
| 99 |
public static function mywp_post_types( $post_types ) { |
| 100 |
|
| 101 |
foreach( $post_types as $post_type_name => $post_type_setting ) { |
| 102 |
|
| 103 |
$post_types[ $post_type_name ]['show_ui'] = true; |
| 104 |
$post_types[ $post_type_name ]['delete_with_user'] = true; |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
return $post_types; |
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
public static function mywp_request_admin() { |
| 113 |
|
| 114 |
if( ! MywpDeveloper::is_debug() ) { |
| 115 |
|
| 116 |
return false; |
| 117 |
|
| 118 |
} |
| 119 |
|
| 120 |
add_filter( 'current_edit_per_page' , array( __CLASS__ , 'current_edit_per_page' ) ); |
| 121 |
add_filter( 'mywp_setting_admin_sidebar_print_item_header_pre_add_title' , array( __CLASS__ , 'mywp_setting_admin_sidebar_print_item_header_pre_add_title' ) , 10 , 2 ); |
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
public static function current_edit_per_page( $per_page ) { |
| 126 |
|
| 127 |
$per_page = 200; |
| 128 |
|
| 129 |
return $per_page; |
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
public static function mywp_setting_admin_sidebar_print_item_header_pre_add_title( $pre_add_title , $item ) { |
| 134 |
|
| 135 |
$pre_add_title .= sprintf( '[%d]' , $item->ID ); |
| 136 |
|
| 137 |
return $pre_add_title; |
| 138 |
|
| 139 |
} |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
MywpControllerModuleDebugGeneral::init(); |
| 144 |
|
| 145 |
endif; |
| 146 |
|