mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-02 01:01:18 +03:00
Display deactivated status on pledges
This commit is contained in:
parent
f7f7ab4989
commit
012a6b76a0
|
@ -17,6 +17,7 @@ defined( 'WPINC' ) || die();
|
||||||
const SLUG = 'pledge';
|
const SLUG = 'pledge';
|
||||||
const SLUG_PL = 'pledges';
|
const SLUG_PL = 'pledges';
|
||||||
const CPT_ID = FiveForTheFuture\PREFIX . '_' . SLUG;
|
const CPT_ID = FiveForTheFuture\PREFIX . '_' . SLUG;
|
||||||
|
const DEACTIVE_STATUS = FiveForTheFuture\PREFIX . '-deactivated';
|
||||||
|
|
||||||
// Admin hooks.
|
// Admin hooks.
|
||||||
add_action( 'init', __NAMESPACE__ . '\register', 0 );
|
add_action( 'init', __NAMESPACE__ . '\register', 0 );
|
||||||
|
@ -30,6 +31,8 @@ add_filter( 'post_row_actions', __NAMESPACE__ . '\add_row_action', 10, 2 )
|
||||||
add_action( 'post_action_deactivate', __NAMESPACE__ . '\handle_activation_action', 10, 3 );
|
add_action( 'post_action_deactivate', __NAMESPACE__ . '\handle_activation_action', 10, 3 );
|
||||||
add_action( 'post_action_reactivate', __NAMESPACE__ . '\handle_activation_action', 10, 3 );
|
add_action( 'post_action_reactivate', __NAMESPACE__ . '\handle_activation_action', 10, 3 );
|
||||||
add_action( 'admin_notices', __NAMESPACE__ . '\action_success_message' );
|
add_action( 'admin_notices', __NAMESPACE__ . '\action_success_message' );
|
||||||
|
add_filter( 'display_post_states', __NAMESPACE__ . '\add_status_to_display', 10, 2 );
|
||||||
|
add_action( 'post_submitbox_misc_actions', __NAMESPACE__ . '\inject_status_label' );
|
||||||
|
|
||||||
// Front end hooks.
|
// Front end hooks.
|
||||||
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' );
|
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' );
|
||||||
|
@ -122,15 +125,20 @@ function register_custom_post_type() {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function register_custom_post_status() {
|
function register_custom_post_status() {
|
||||||
|
$label_count = _n_noop(
|
||||||
|
'Deactivated <span class="count">(%s)</span>',
|
||||||
|
'Deactivated <span class="count">(%s)</span>',
|
||||||
|
'wporg-5ftf'
|
||||||
|
);
|
||||||
register_post_status(
|
register_post_status(
|
||||||
FiveForTheFuture\PREFIX . '-deactivated',
|
DEACTIVE_STATUS,
|
||||||
array(
|
array(
|
||||||
'label' => __( 'Deactivated', 'wporg-5ftf' ),
|
'label' => __( 'Deactivated', 'wporg-5ftf' ),
|
||||||
'label_count' => _n_noop( 'Deactivated <span class="count">(%s)</span>', 'Deactivated <span class="count">(%s)</span>', 'wporg-5ftf' ),
|
'label_count' => $label_count,
|
||||||
'public' => false,
|
'public' => false,
|
||||||
'internal' => false,
|
'internal' => false,
|
||||||
'protected' => true,
|
'protected' => true,
|
||||||
CPT_ID => true, // Custom parameter to streamline its use with the Pledge CPT.
|
'show_in_admin_all_list' => false,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -146,9 +154,9 @@ function add_row_action( $actions, $post ) {
|
||||||
return $actions;
|
return $actions;
|
||||||
}
|
}
|
||||||
$post_type_object = get_post_type_object( $post->post_type );
|
$post_type_object = get_post_type_object( $post->post_type );
|
||||||
if ( FiveForTheFuture\PREFIX . '-deactivated' === $post->post_status ) {
|
if ( DEACTIVE_STATUS === $post->post_status ) {
|
||||||
$actions['reactivate'] = sprintf(
|
$actions['reactivate'] = sprintf(
|
||||||
'<a href="%s" aria-label="%s">%s</a>',
|
'<a href="%s" style="color:#297531;" aria-label="%s">%s</a>',
|
||||||
wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=reactivate', $post->ID ) ), 'reactivate-post_' . $post->ID ),
|
wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=reactivate', $post->ID ) ), 'reactivate-post_' . $post->ID ),
|
||||||
/* translators: %s: Post title. */
|
/* translators: %s: Post title. */
|
||||||
esc_attr( sprintf( __( 'Reactivate pledge “%s”', 'wporg-5ftf' ), $post->post_title ) ),
|
esc_attr( sprintf( __( 'Reactivate pledge “%s”', 'wporg-5ftf' ), $post->post_title ) ),
|
||||||
|
@ -157,7 +165,7 @@ function add_row_action( $actions, $post ) {
|
||||||
} else {
|
} else {
|
||||||
unset( $actions['trash'] );
|
unset( $actions['trash'] );
|
||||||
$actions['deactivate'] = sprintf(
|
$actions['deactivate'] = sprintf(
|
||||||
'<a href="%s" aria-label="%s">%s</a>',
|
'<a href="%s" style="color:#dc3232;" aria-label="%s">%s</a>',
|
||||||
wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=deactivate', $post->ID ) ), 'deactivate-post_' . $post->ID ),
|
wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=deactivate', $post->ID ) ), 'deactivate-post_' . $post->ID ),
|
||||||
/* translators: %s: Post title. */
|
/* translators: %s: Post title. */
|
||||||
esc_attr( sprintf( __( 'Deactivate pledge “%s”', 'wporg-5ftf' ), $post->post_title ) ),
|
esc_attr( sprintf( __( 'Deactivate pledge “%s”', 'wporg-5ftf' ), $post->post_title ) ),
|
||||||
|
@ -193,7 +201,7 @@ function handle_activation_action( $post_id ) {
|
||||||
if ( 'deactivate' === $action ) {
|
if ( 'deactivate' === $action ) {
|
||||||
wp_update_post( array(
|
wp_update_post( array(
|
||||||
'ID' => $post_id,
|
'ID' => $post_id,
|
||||||
'post_status' => FiveForTheFuture\PREFIX . '-deactivated',
|
'post_status' => DEACTIVE_STATUS,
|
||||||
) );
|
) );
|
||||||
wp_redirect( add_query_arg( 'deactivated', 1, $sendback ) );
|
wp_redirect( add_query_arg( 'deactivated', 1, $sendback ) );
|
||||||
exit();
|
exit();
|
||||||
|
@ -224,6 +232,51 @@ function action_success_message() {
|
||||||
<?php endif;
|
<?php endif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add "Deactivated" to the list of post states (displayed on each post in the list table).
|
||||||
|
*
|
||||||
|
* @param string[] $post_states An array of post display states.
|
||||||
|
* @param WP_Post $post The current post object.
|
||||||
|
*
|
||||||
|
* @return array The filtered list of post display states.
|
||||||
|
*/
|
||||||
|
function add_status_to_display( $post_states, $post ) {
|
||||||
|
if ( isset( $_REQUEST['post_status'] ) ) {
|
||||||
|
$showing_status = $_REQUEST['post_status'];
|
||||||
|
} else {
|
||||||
|
$showing_status = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$status = DEACTIVE_STATUS;
|
||||||
|
if ( $showing_status !== $status && $status === $post->post_status ) {
|
||||||
|
$post_states[ $status ] = _x( 'Deactivated', 'pledge label', 'wporg-5ftf' );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $post_states;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use JS to replace the empty status label on deactivated pledges.
|
||||||
|
*
|
||||||
|
* @param WP_Post $post The current post object.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function inject_status_label( $post ) {
|
||||||
|
if ( CPT_ID === $post->post_type && DEACTIVE_STATUS === $post->post_status ) : ?>
|
||||||
|
<script type="text/javascript">
|
||||||
|
jQuery( document ).ready( function( $ ) {
|
||||||
|
$("#post-status-display").text("Deactivated");
|
||||||
|
$("#save-action").remove();
|
||||||
|
$("#publishing-action").remove();
|
||||||
|
} );
|
||||||
|
</script>
|
||||||
|
<div class="misc-pub-section misc-pub-visibility">
|
||||||
|
<p><?php esc_html_e( 'This pledge is deactivated, it cannot be edited.', 'wporg-5ftf' ); ?></p>
|
||||||
|
</div>
|
||||||
|
<?php endif;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add columns to the Pledges list table.
|
* Add columns to the Pledges list table.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue