Created
August 15, 2012 07:25
-
-
Save thenbrent/3357350 to your computer and use it in GitHub Desktop.
Set correct admin messages for all custom post type in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Customise the messsages for all custom post types in a WordPress install. | |
* | |
* @author Brent Shepherd <brent@findingsimple.com> | |
* @package eg | |
* @subpackage CPT | |
* @since 1.0 | |
*/ | |
function eg_cpt_update_messages( $messages ) { | |
global $post, $post_ID; | |
$post_types = get_post_types( array( 'show_ui' => true, '_builtin' => false ), 'objects' ); | |
foreach( $post_types as $post_type => $post_object ) { | |
$messages[$post_type] = array( | |
0 => '', // Unused. Messages start at index 1. | |
1 => sprintf( __( '%s updated. <a href="%s">View %s</a>' ), $post_object->labels->singular_name, esc_url( get_permalink( $post_ID ) ), $post_object->labels->singular_name ), | |
2 => __( 'Custom field updated.' ), | |
3 => __( 'Custom field deleted.' ), | |
4 => sprintf( __( '%s updated.' ), $post_object->labels->singular_name ), | |
5 => isset( $_GET['revision']) ? sprintf( __( '%s restored to revision from %s' ), $post_object->labels->singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, | |
6 => sprintf( __( '%s published. <a href="%s">View %s</a>' ), $post_object->labels->singular_name, esc_url( get_permalink( $post_ID ) ), $post_object->labels->singular_name ), | |
7 => sprintf( __( '%s saved.' ), $post_object->labels->singular_name ), | |
8 => sprintf( __( '%s submitted. <a target="_blank" href="%s">Preview %s</a>' ), $post_object->labels->singular_name, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), $post_object->labels->singular_name ), | |
9 => sprintf( __( '%s scheduled for: <strong>%s</strong>. <a target="_blank" href="%s">Preview %s</a>' ), $post_object->labels->singular_name, date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ), $post_object->labels->singular_name ), | |
10 => sprintf( __( '%s draft updated. <a target="_blank" href="%s">Preview %s</a>' ), $post_object->labels->singular_name, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), $post_object->labels->singular_name ), | |
); | |
} | |
return $messages; | |
} | |
add_filter( 'post_updated_messages', 'eg_cpt_update_messages' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know why it took me so long to find this (8 year old) solution but +1. This should be a feature in the core project ( that could be disabled during post-registration ) .