| 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( 'MywpControllerModuleAdminComments' ) ) : |
| 12 |
|
| 13 |
final class MywpControllerModuleAdminComments extends MywpControllerAbstractModule { |
| 14 |
|
| 15 |
static protected $id = 'admin_comments'; |
| 16 |
|
| 17 |
public static function mywp_controller_initial_data( $initial_data ) { |
| 18 |
|
| 19 |
$initial_data['list_columns'] = array(); |
| 20 |
|
| 21 |
$initial_data['per_page_num'] = ''; |
| 22 |
$initial_data['hide_search_box'] = ''; |
| 23 |
|
| 24 |
return $initial_data; |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
public static function mywp_controller_default_data( $default_data ) { |
| 29 |
|
| 30 |
$default_data['list_columns'] = array(); |
| 31 |
|
| 32 |
$default_data['per_page_num'] = 20; |
| 33 |
$default_data['hide_search_box'] = false; |
| 34 |
|
| 35 |
return $default_data; |
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
public static function mywp_wp_loaded() { |
| 40 |
|
| 41 |
if( ! is_admin() ) { |
| 42 |
|
| 43 |
return false; |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
if( is_network_admin() ) { |
| 48 |
|
| 49 |
return false; |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
if( ! self::is_do_controller() ) { |
| 54 |
|
| 55 |
return false; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
add_action( 'mywp_ajax' , array( __CLASS__ , 'mywp_ajax' ) , 1000 ); |
| 60 |
|
| 61 |
add_action( 'load-edit-comments.php' , array( __CLASS__ , 'load_comments' ) , 1000 ); |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
public static function mywp_ajax() { |
| 66 |
|
| 67 |
if( empty( $_POST['action'] ) ) { |
| 68 |
|
| 69 |
return false; |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
$action = strip_tags( $_POST['action'] ); |
| 74 |
|
| 75 |
if( ! in_array( $action , array( 'edit-comment' , 'replyto-comment' ) ) ) { |
| 76 |
|
| 77 |
return false; |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
add_filter( 'manage_edit-comments_columns' , array( __CLASS__ , 'manage_columns' ) ); |
| 82 |
|
| 83 |
add_filter( 'manage_comments_custom_column' , array( __CLASS__ , 'manage_column_body' ) , 10 , 2 ); |
| 84 |
|
| 85 |
add_filter( 'manage_edit-comments_sortable_columns', array( __CLASS__ , 'manage_columns_sortable' ) ); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
public static function load_comments() { |
| 91 |
|
| 92 |
add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_search_box' ) ); |
| 93 |
|
| 94 |
add_action( 'admin_print_styles' , array( __CLASS__ , 'change_column_width' ) ); |
| 95 |
|
| 96 |
add_filter( 'comments_per_page' , array( __CLASS__ , 'comments_per_page' ) ); |
| 97 |
|
| 98 |
add_filter( 'manage_edit-comments_columns' , array( __CLASS__ , 'manage_columns' ) ); |
| 99 |
|
| 100 |
add_filter( 'manage_comments_custom_column' , array( __CLASS__ , 'manage_column_body' ) , 10 , 2 ); |
| 101 |
|
| 102 |
add_filter( 'manage_edit-comments_sortable_columns', array( __CLASS__ , 'manage_columns_sortable' ) ); |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
public static function hide_search_box() { |
| 107 |
|
| 108 |
if( ! self::is_do_function( __FUNCTION__ ) ) { |
| 109 |
|
| 110 |
return false; |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
$setting_data = self::get_setting_data(); |
| 115 |
|
| 116 |
if( empty( $setting_data['hide_search_box'] ) ) { |
| 117 |
|
| 118 |
return false; |
| 119 |
|
| 120 |
} |
| 121 |
|
| 122 |
echo '<style>'; |
| 123 |
|
| 124 |
echo 'body.wp-admin #comments-form .search-box { display: none; }'; |
| 125 |
|
| 126 |
echo '</style>'; |
| 127 |
|
| 128 |
self::after_do_function( __FUNCTION__ ); |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
public static function change_column_width() { |
| 133 |
|
| 134 |
if( ! self::is_do_function( __FUNCTION__ ) ) { |
| 135 |
|
| 136 |
return false; |
| 137 |
|
| 138 |
} |
| 139 |
|
| 140 |
$setting_data = self::get_setting_data(); |
| 141 |
|
| 142 |
if( empty( $setting_data['list_columns'] ) ) { |
| 143 |
|
| 144 |
return false; |
| 145 |
|
| 146 |
} |
| 147 |
|
| 148 |
$columns = array(); |
| 149 |
|
| 150 |
foreach( $setting_data['list_columns'] as $column_id => $column_setting ) { |
| 151 |
|
| 152 |
if( empty( $column_setting['width'] ) ) { |
| 153 |
|
| 154 |
continue; |
| 155 |
|
| 156 |
} |
| 157 |
|
| 158 |
$columns[ $column_id ] = $column_setting['width']; |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
if( empty( $columns ) ) { |
| 163 |
|
| 164 |
return false; |
| 165 |
|
| 166 |
} |
| 167 |
|
| 168 |
echo '<style>'; |
| 169 |
|
| 170 |
foreach( $columns as $column_id => $width ) { |
| 171 |
|
| 172 |
echo 'body.wp-admin .wp-list-table.widefat thead th.column-' . esc_attr( $column_id ) . ' { width: ' . esc_attr( $width ) . '; display: table-cell; }'; |
| 173 |
echo 'body.wp-admin .wp-list-table.widefat thead td.column-' . esc_attr( $column_id ) . ' { width: ' . esc_attr( $width ) . '; display: table-cell; }'; |
| 174 |
|
| 175 |
echo 'body.wp-admin .wp-list-table.widefat thead th#' . esc_attr( $column_id ) . ' { width: ' . esc_attr( $width ) . '; display: table-cell; }'; |
| 176 |
echo 'body.wp-admin .wp-list-table.widefat thead td#' . esc_attr( $column_id ) . ' { width: ' . esc_attr( $width ) . '; display: table-cell; }'; |
| 177 |
|
| 178 |
} |
| 179 |
|
| 180 |
echo '</style>'; |
| 181 |
|
| 182 |
self::after_do_function( __FUNCTION__ ); |
| 183 |
|
| 184 |
} |
| 185 |
|
| 186 |
public static function comments_per_page( $per_page ) { |
| 187 |
|
| 188 |
if( ! self::is_do_function( __FUNCTION__ ) ) { |
| 189 |
|
| 190 |
return $per_page; |
| 191 |
|
| 192 |
} |
| 193 |
|
| 194 |
$setting_data = self::get_setting_data(); |
| 195 |
|
| 196 |
if( empty( $setting_data['per_page_num'] ) ) { |
| 197 |
|
| 198 |
return $per_page; |
| 199 |
|
| 200 |
} |
| 201 |
|
| 202 |
$per_page = $setting_data['per_page_num']; |
| 203 |
|
| 204 |
self::after_do_function( __FUNCTION__ ); |
| 205 |
|
| 206 |
return $per_page; |
| 207 |
|
| 208 |
} |
| 209 |
|
| 210 |
public static function manage_columns( $columns ) { |
| 211 |
|
| 212 |
if( ! self::is_do_function( __FUNCTION__ ) ) { |
| 213 |
|
| 214 |
return $columns; |
| 215 |
|
| 216 |
} |
| 217 |
|
| 218 |
$setting_data = self::get_setting_data(); |
| 219 |
|
| 220 |
if( empty( $setting_data['list_columns'] ) ) { |
| 221 |
|
| 222 |
return $columns; |
| 223 |
|
| 224 |
} |
| 225 |
|
| 226 |
$columns = array(); |
| 227 |
|
| 228 |
foreach( $setting_data['list_columns'] as $column_id => $column_setting ) { |
| 229 |
|
| 230 |
$columns[ $column_id ] = $column_setting['title']; |
| 231 |
|
| 232 |
} |
| 233 |
|
| 234 |
self::after_do_function( __FUNCTION__ ); |
| 235 |
|
| 236 |
return $columns; |
| 237 |
|
| 238 |
} |
| 239 |
|
| 240 |
public static function manage_column_body( $column_id , $comment_id ) { |
| 241 |
|
| 242 |
if( ! self::is_do_function( __FUNCTION__ ) ) { |
| 243 |
|
| 244 |
return false; |
| 245 |
|
| 246 |
} |
| 247 |
|
| 248 |
$comment = get_comment( $comment_id ); |
| 249 |
|
| 250 |
if( $column_id === 'id' ) { |
| 251 |
|
| 252 |
echo $comment_id; |
| 253 |
|
| 254 |
} elseif( $column_id === 'comment_author' ) { |
| 255 |
|
| 256 |
echo $comment->comment_author; |
| 257 |
|
| 258 |
} elseif( $column_id === 'comment_author_email' ) { |
| 259 |
|
| 260 |
echo $comment->comment_author_email; |
| 261 |
|
| 262 |
} elseif( $column_id === 'comment_author_url' ) { |
| 263 |
|
| 264 |
echo $comment->comment_author_url; |
| 265 |
|
| 266 |
} |
| 267 |
|
| 268 |
self::after_do_function( __FUNCTION__ ); |
| 269 |
|
| 270 |
} |
| 271 |
|
| 272 |
public static function manage_columns_sortable( $sortables ) { |
| 273 |
|
| 274 |
if( ! self::is_do_function( __FUNCTION__ ) ) { |
| 275 |
|
| 276 |
return $sortables; |
| 277 |
|
| 278 |
} |
| 279 |
|
| 280 |
$setting_data = self::get_setting_data(); |
| 281 |
|
| 282 |
if( empty( $setting_data['list_columns'] ) ) { |
| 283 |
|
| 284 |
return $sortables; |
| 285 |
|
| 286 |
} |
| 287 |
|
| 288 |
$sortables = array(); |
| 289 |
|
| 290 |
foreach( $setting_data['list_columns'] as $column_id => $column_setting ) { |
| 291 |
|
| 292 |
if( ! empty( $column_setting['sort'] ) ) { |
| 293 |
|
| 294 |
$sortables[ $column_id ] = $column_setting['orderby']; |
| 295 |
|
| 296 |
} |
| 297 |
|
| 298 |
} |
| 299 |
|
| 300 |
self::after_do_function( __FUNCTION__ ); |
| 301 |
|
| 302 |
return $sortables; |
| 303 |
|
| 304 |
} |
| 305 |
|
| 306 |
} |
| 307 |
|
| 308 |
MywpControllerModuleAdminComments::init(); |
| 309 |
|
| 310 |
endif; |
| 311 |
|