mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-04-21 10:33:44 +03:00
Pledges: Add columns to pledge list table
It's useful to have some at-a-glance info about pledges when scrolling the list table.
This commit is contained in:
parent
83125dd8b2
commit
14109a1b3e
|
@ -7,7 +7,7 @@
|
||||||
namespace WordPressDotOrg\FiveForTheFuture\Pledge;
|
namespace WordPressDotOrg\FiveForTheFuture\Pledge;
|
||||||
|
|
||||||
use WordPressDotOrg\FiveForTheFuture;
|
use WordPressDotOrg\FiveForTheFuture;
|
||||||
use WordPressDotOrg\FiveForTheFuture\Email;
|
use WordPressDotOrg\FiveForTheFuture\{ Contributor, Email };
|
||||||
use WP_Error, WP_Query;
|
use WP_Error, WP_Query;
|
||||||
|
|
||||||
use const WordPressDotOrg\FiveForTheFuture\PledgeMeta\META_PREFIX;
|
use const WordPressDotOrg\FiveForTheFuture\PledgeMeta\META_PREFIX;
|
||||||
|
@ -21,6 +21,8 @@ const CPT_ID = FiveForTheFuture\PREFIX . '_' . SLUG;
|
||||||
add_action( 'init', __NAMESPACE__ . '\register', 0 );
|
add_action( 'init', __NAMESPACE__ . '\register', 0 );
|
||||||
add_action( 'admin_menu', __NAMESPACE__ . '\admin_menu' );
|
add_action( 'admin_menu', __NAMESPACE__ . '\admin_menu' );
|
||||||
add_action( 'pre_get_posts', __NAMESPACE__ . '\filter_query' );
|
add_action( 'pre_get_posts', __NAMESPACE__ . '\filter_query' );
|
||||||
|
add_filter( 'manage_edit-' . CPT_ID . '_columns', __NAMESPACE__ . '\add_list_table_columns' );
|
||||||
|
add_action( 'manage_' . CPT_ID . '_posts_custom_column', __NAMESPACE__ . '\populate_list_table_columns', 10, 2 );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register all the things.
|
* Register all the things.
|
||||||
|
@ -117,6 +119,50 @@ function register_custom_post_status() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add columns to the Pledges list table.
|
||||||
|
*
|
||||||
|
* @param array $columns
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function add_list_table_columns( $columns ) {
|
||||||
|
$first = array_slice( $columns, 0, 2, true );
|
||||||
|
$last = array_slice( $columns, 2, null, true );
|
||||||
|
|
||||||
|
$new_columns = array(
|
||||||
|
'contributor_counts' => __( 'Contributors', 'wporg' ),
|
||||||
|
'domain' => __( 'Domain', 'wporg' ),
|
||||||
|
);
|
||||||
|
|
||||||
|
return array_merge( $first, $new_columns, $last );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render content in the custom columns added to the Pledges list table.
|
||||||
|
*
|
||||||
|
* @param string $column
|
||||||
|
* @param int $post_id
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function populate_list_table_columns( $column, $post_id ) {
|
||||||
|
switch ( $column ) {
|
||||||
|
case 'contributor_counts':
|
||||||
|
$contribs = Contributor\get_pledge_contributors( $post_id, 'all' );
|
||||||
|
printf(
|
||||||
|
wpautop( '%1$d confirmed' . "\n" . '%2$d unconfirmed' ),
|
||||||
|
count( $contribs['publish'] ),
|
||||||
|
count( $contribs['pending'] )
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'domain':
|
||||||
|
$domain = get_post_meta( $post_id, META_PREFIX . 'org-domain', true );
|
||||||
|
echo esc_html( $domain );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new pledge post.
|
* Create a new pledge post.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue