'; } /** @psalm-suppress ParamNameMismatch -- params match with \Walker_Page::start_el */ public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) { $css_classes = 'page-item page-item-' . $page->ID; $has_children = isset( $args['pages_with_children'][ $page->ID ] ); if ( $has_children ) { $css_classes .= ' page-item-has-children'; } if ( '' === $page->post_title ) { /* translators: %d: ID of a post. */ $page->post_title = sprintf( __( '#%d (no title)', 'p2020' ), $page->ID ); } // Add opening
  • ; closing
  • is in \Walker_page::end_el $is_draggable = current_user_can( 'publish_pages' ) ? 'true' : 'false'; $output .= sprintf( '
  • ', esc_attr( $css_classes ), $is_draggable, $page->ID ); // Add item details wrapper. $output .= '
    '; // Add page title, with drag handle and expand/collapse button. $drag_handle = '
    '; $toggle_button = sprintf( '', ( $has_children ? '' : 'disabled' ) ); $title_link = sprintf( '%s', esc_url( (string) get_permalink( $page->ID ) ), apply_filters( 'the_title', $page->post_title, $page->ID ) ); $output .= sprintf( '%s%s%s', current_user_can( 'publish_pages' ) ? $drag_handle : '', $toggle_button, $title_link ); // Add contributor info. $contributors = $this->get_contributor_info( $page->ID ); $output .= sprintf( '%s', $contributors ); // Add date modified. $date_format = get_option( 'date_format' ); if ( empty( $date_format ) ) { $date_format = 'M j, Y'; } $post_modified = (string) mysql2date( $date_format, $page->post_modified ) . ''; $output .= sprintf( '%s', $post_modified ); // Add post actions. $wrapper_class = 'p2020-pages-index__post-actions o2-dropdown-actions'; $output .= self::get_post_actions_menu( $page->ID, $wrapper_class ); // Close item details wrapper. $output .= '
    '; } private function get_post_actions_menu( int $page_id, string $wrapper_class ): string { $editor_page_url = Navigation\Urls::get_editor_page_url(); $new_page_link = $editor_page_url . ( wp_parse_url( $editor_page_url, PHP_URL_QUERY ) ? '&' : '?' ) . 'parent_post=' . $page_id; $new_page_label = __( 'Add subpage', 'p2020' ); $permalink = \get_permalink( $page_id ); $permalink_label = __( 'Copy link', 'p2020' ); /* Translators: verb, synonym of "delete" */ $trash_link = admin_url( 'post.php?action=trash&post=' . $page_id ); $trash_label = __( 'Trash', 'p2020' ); $menu_items = "
  • "; if ( current_user_can( 'publish_pages' ) ) { $menu_items .= "
  • $new_page_label
  • "; } if ( current_user_can( 'delete_others_pages' ) ) { $menu_items .= "
  • $trash_label
  • "; } return ""; } private function get_contributor_info( int $page_id ): string { $page = get_post( $page_id ); if ( ! is_object( $page ) ) { return ''; } $revisions = wp_get_post_revisions( $page_id ); $author = $page->post_author; $contributors_by_revision = [ $author => 1 ]; foreach ( $revisions as $revision ) { if ( wp_is_post_autosave( $revision ) ) { continue; } if ( isset( $contributors_by_revision[ $revision->post_author ] ) ) { $contributors_by_revision[ $revision->post_author ]++; } else { $contributors_by_revision[ $revision->post_author ] = 1; } } arsort( $contributors_by_revision, SORT_NUMERIC ); $top_contributors = array_slice( $contributors_by_revision, 0, self::LIMIT_CONTRIBUTORS_LIST, true ); $contributor_info = ''; foreach ( array_keys( $top_contributors ) as $contributor_id ) { $contributor_info .= (string) get_avatar( $contributor_id, 64, '', '', [ 'force_display' => true, 'height' => 32, 'width' => 32 ] ); } $hidden_contributors = count( $contributors_by_revision ) - count( $top_contributors ); if ( $hidden_contributors > 1 ) { $contributor_info .= '+' . $hidden_contributors . ''; } return $contributor_info; } }