Changeset 14426
- Timestamp:
- 04/16/2025 08:50:08 PM (7 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/admin.php
r14387 r14426 10 10 class Admin { 11 11 12 const COL_NAME_AUTHOR = 'wporg-photo-author'; 12 13 const COL_NAME_FLAG = 'wporg-flags'; 13 14 const COL_NAME_PHOTO = 'wporg-photo'; … … 27 28 add_action( 'load-edit.php', [ __CLASS__, 'add_admin_css' ] ); 28 29 add_action( 'load-post.php', [ __CLASS__, 'add_admin_css' ] ); 30 add_filter( "manage_{$post_type}_posts_columns", [ __CLASS__, 'add_author_column' ] ); 31 add_action( "manage_{$post_type}_posts_custom_column", [ __CLASS__, 'handle_author_column_data' ], 10, 2 ); 29 32 add_filter( "manage_{$post_type}_posts_columns", [ __CLASS__, 'add_photo_column' ] ); 30 33 add_action( "manage_{$post_type}_posts_custom_column", [ __CLASS__, 'handle_photo_column_data' ], 10, 2 ); … … 33 36 add_filter( "manage_edit-{$post_type}_columns", [ __CLASS__, 'remove_columns_from_pending_photos' ] ); 34 37 add_filter( 'post_row_actions', [ __CLASS__, 'add_post_action_photo_links' ], 10, 2 ); 35 add_filter( 'the_author', [ __CLASS__, 'add_published_photos_count_to_author' ] );36 38 add_filter( 'use_block_editor_for_post_type', [ __CLASS__, 'disable_block_editor' ], 10, 2 ); 37 39 add_action( 'admin_notices', [ __CLASS__, 'add_notice_to_photo_media_if_pending' ] ); … … 325 327 ( empty( $_GET['post_status'] ) || in_array( $_GET['post_status'], $post_statuses ) ) 326 328 ); 329 } 330 331 /** 332 * Replaces default 'Author' column with a custom 'Author' column that shows 333 * typical author column data as well as additional data. 334 * 335 * As of WP 6.8, it no longer easy to modify the existing 'Author' column to 336 * add more data, so this adds a custom column to replace the 'Author' column. 337 * 338 * @param array $posts_columns Array of post column titles. 339 * @return array The $posts_columns array with the photo author column added. 340 */ 341 public static function add_author_column( $posts_columns ) { 342 if ( ! self::should_include_photo_column() ) { 343 return $posts_columns; 344 } 345 346 // Position after existing 'Author' column. 347 $pos = array_search( 'author', array_keys( $posts_columns ) ); 348 349 if ( ! $pos ) { 350 // Else, position the column after the 'Title' column (where 'Author' is normally located). 351 $pos = array_search( 'title', array_keys( $posts_columns ) ); 352 } 353 354 if ( $pos ) { 355 $pos++; 356 $posts_columns = array_slice( $posts_columns, 0, $pos, true ) 357 + [ self::COL_NAME_AUTHOR => __( 'Author', 'wporg-photos' ) ] 358 + array_slice( $posts_columns, $pos, count( $posts_columns ) - 1, true ); 359 } else { 360 $posts_columns[ self::COL_NAME_AUTHOR ] = __( 'Author', 'wporg-photos' ); 361 } 362 363 // Remove the existing 'Author' column. 364 unset( $posts_columns['author'] ); 365 366 return $posts_columns; 367 } 368 369 /** 370 * Outputs the photo author column content for the post. 371 * 372 * @param string $column_name The name of the column. 373 * @param int $post_id The id of the post being displayed. 374 */ 375 public static function handle_author_column_data( $column_name, $post_id ) { 376 if ( self::COL_NAME_AUTHOR !== $column_name ) { 377 return; 378 } 379 380 $post = get_post( $post_id ); 381 382 // Get the same 'Author' column content as generated by core. 383 $list_table = _get_list_table( 'WP_Posts_List_Table' ); 384 $core_html = $list_table->column_author( $post ); 385 386 /** 387 * Fires before any photo author column content is output. 388 * 389 * @param WP_Post The post object. 390 */ 391 do_action( 'photo_author_column_data_start', $post ); 392 393 // Output core's default author column data for this post. 394 echo $core_html; 395 396 /** 397 * Fires after the default author column content is output. 398 * 399 * @param WP_Post The post object. 400 */ 401 do_action( 'photo_author_column_data_after_author', $post ); 402 403 // Output author submission counts. 404 echo self::get_author_submission_stats( (int) get_post_field( 'post_author', $post_id ) ); 405 406 /** 407 * Fires at the end of the photo author column content. 408 * 409 * @param WP_Post The post object. 410 */ 411 do_action( 'photo_author_column_data_end', $post ); 327 412 } 328 413 … … 808 893 809 894 /** 810 * Appends the count of the published photos to author names in photo post811 * listings.812 * 813 * @param string $display_name The author's display name.895 * Returns hyperlinked statistics on the author's submission counts (published, 896 * pending, rejected, etc) intended to be shown to moderators. 897 * 898 * @param int $author_id Author ID. 814 899 * @return string 815 900 */ 816 public static function add_published_photos_count_to_author( $display_name ) { 817 global $authordata; 818 819 if ( ! is_admin() || ! self::should_include_photo_column( true ) ) { 820 return $display_name; 821 } 822 823 // Close link to contributor's listing of photos. 824 $display_name .= '</a>'; 825 901 public static function get_author_submission_stats( $author_id ) { 826 902 $post_type = Registrations::get_post_type(); 827 903 $reject_status = Rejection::get_post_status(); 904 $stats_display = ''; 828 905 829 906 // Show number of approved photos. … … 831 908 'post_type' => $post_type, 832 909 'post_status' => 'publish', 833 'author' => $author data->ID,910 'author' => $author_id, 834 911 ], 'edit.php' ); 835 $ display_name.= '<div class="user-approved-count">'912 $stats_display .= '<div class="user-approved-count">' 836 913 . sprintf( 837 914 __( 'Approved: <strong>%s</strong>', 'wporg-photos' ), … … 846 923 'post_type' => $post_type, 847 924 'post_status' => 'publish', 848 'author' => $author data->ID,925 'author' => $author_id, 849 926 ], 'edit.php' ); 850 $ display_name.= '<div class="user-approved-today-count">'927 $stats_display .= '<div class="user-approved-today-count">' 851 928 . sprintf( 852 929 __( '↪ (today): %s', 'wporg-photos' ), … … 862 939 'post_type' => $post_type, 863 940 'post_status' => 'pending', 864 'author' => $author data->ID,941 'author' => $author_id, 865 942 ], 'edit.php' ); 866 943 867 $ display_name.= '<div class="user-pending-count">'944 $stats_display .= '<div class="user-pending-count">' 868 945 . sprintf( 869 946 __( 'Pending: <strong>%s</strong>', 'wporg-photos' ), … … 874 951 875 952 // Show number of rejected photos. 876 $rejection_count = User::count_rejected_photos( $author data->ID);953 $rejection_count = User::count_rejected_photos( $author_id ); 877 954 if ( $rejection_count ) { 878 955 $rejected_link = add_query_arg( [ 879 956 'post_type' => $post_type, 880 957 'post_status' => $reject_status, 881 'author' => $author data->ID,958 'author' => $author_id, 882 959 ], 'edit.php' ); 883 $ display_name.= '<div class="user-rejected-count">'960 $stats_display .= '<div class="user-rejected-count">' 884 961 . sprintf( 885 962 /* translators: %s: Count of user rejections linked to listing of their rejections. */ … … 896 973 'post_type' => $post_type, 897 974 'post_status' => $reject_status, 898 'author' => $author data->ID,975 'author' => $author_id, 899 976 ], 'edit.php' ); 900 $ display_name.= '<div class="user-rejected-today-count">'977 $stats_display .= '<div class="user-rejected-today-count">' 901 978 . sprintf( 902 979 __( '↪ (today): %s', 'wporg-photos' ), … … 906 983 } 907 984 908 // Prevent unbalanced tag. 909 $display_name .= '<a>'; 910 911 return $display_name; 985 return $stats_display; 912 986 } 913 987 … … 1316 1390 */ 1317 1391 public static function add_contributor_ip_column( $posts_columns ) { 1318 $pos = array_search( 'author', array_keys( $posts_columns ) );1392 $pos = array_search( self::COL_NAME_AUTHOR, array_keys( $posts_columns ) ); 1319 1393 1320 1394 if ( $pos ) { … … 1322 1396 $posts_columns = array_slice( $posts_columns, 0, $pos, true ) 1323 1397 + [ self::COL_NAME_CONTRIBUTOR_IP => __( 'Contributor IP', 'wporg-photos' ) ] 1324 + array_slice( $posts_columns, 3, count( $posts_columns ) - 1, true );1398 + array_slice( $posts_columns, $pos, count( $posts_columns ) - 1, true ); 1325 1399 } else { 1326 1400 $posts_columns[ self::COL_NAME_CONTRIBUTOR_IP ] = __( 'Contributor IP', 'wporg-photos' );
Note: See TracChangeset
for help on using the changeset viewer.