web-dev-qa-db-fra.com

Comment personnaliser les avis post-édition

Comment personnaliser le message de notification ('Publiée' ou 'Publiée' ') affiché lorsque j'ajoute ou modifie un type de publication personnalisé enregistré avec la fonction register_post_type()?

1
maxime schoeni

Vous pouvez utiliser le filtre post_updated_messages.

add_filter( 'post_updated_messages', 'rw_post_updated_messages' );


function rw_post_updated_messages( $messages ) {

$post             = get_post();
$post_type        = get_post_type( $post );
$post_type_object = get_post_type_object( $post_type );

$messages['my-post-type'] = array(
    0  => '', // Unused. Messages start at index 1.
    1  => __( 'My Post Type updated.' ),
    2  => __( 'Custom field updated.' ),
    3  => __( 'Custom field deleted.'),
    4  => __( 'My Post Type updated.' ),
    /* translators: %s: date and time of the revision */
    5  => isset( $_GET['revision'] ) ? sprintf( __( 'My Post Type restored to revision from %s' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
    6  => __( 'My Post Type published.' ),
    7  => __( 'My Post Type saved.' ),
    8  => __( 'My Post Type submitted.' ),
    9  => sprintf(
        __( 'My Post Type scheduled for: <strong>%1$s</strong>.' ),
        // translators: Publish box date format, see http://php.net/date
        date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) )
    ),
    10 => __( 'My Post Type draft updated.' )
);

    //you can also access items this way
    // $messages['post'][1] = "I just totally changed the Updated messages for standards posts";

    //return the new messaging 
return $messages;
}
3
Welcher