Skip to content

Instantly share code, notes, and snippets.

@sutandang
Created June 6, 2017 15:44
Show Gist options
  • Save sutandang/cfd2f7c8393786f2615465a0379f487a to your computer and use it in GitHub Desktop.
Save sutandang/cfd2f7c8393786f2615465a0379f487a to your computer and use it in GitHub Desktop.
How to update message alert in custome post type wordpress
add_filter( 'post_updated_messages', 'update_new_messages' ,100);
function update_new_messages( $messages ) {
$post = get_post();
$post_type = get_post_type( $post );
$post_type_object = get_post_type_object( $post_type );
if($post_type != 'product')
return;
/*Edit with your custome, in this case i update product in woocommerce to solutions*/
$messages['product'] = array(
0 => '',
1 => __( 'Solution updated.', 'textdomain' ),
2 => __( 'Custom field updated.', 'textdomain' ),
3 => __( 'Custom field deleted.', 'textdomain' ),
4 => __( 'Solution updated.', 'textdomain' ),
5 => isset( $_GET['revision'] ) ? sprintf( __( 'Solution restored to revision from %s', 'textdomain' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => __( 'Solution published.', 'textdomain' ),
7 => __( 'Solution saved.', 'textdomain' ),
8 => __( 'Solution submitted.', 'textdomain' ),
9 => sprintf(
__( 'Solution scheduled for: <strong>%1$s</strong>.', 'textdomain' ),
date_i18n( __( 'M j, Y @ G:i', 'textdomain' ), strtotime( $post->post_date ) )
),
10 => __( 'Solution draft updated.', 'textdomain' )
);
if ( $post_type_object->publicly_queryable ) {
$permalink = get_permalink( $post->ID );
$view_link = sprintf( ' <a href="%s">%s</a>', esc_url( $permalink ), __( 'View solution', 'textdomain' ) );
$messages[ $post_type ][1] .= $view_link;
$messages[ $post_type ][6] .= $view_link;
$messages[ $post_type ][9] .= $view_link;
$preview_permalink = add_query_arg( 'preview', 'true', $permalink );
$preview_link = sprintf( ' <a target="_blank" href="%s">%s</a>', esc_url( $preview_permalink ), __( 'Preview solution', 'textdomain' ) );
$messages[ $post_type ][8] .= $preview_link;
$messages[ $post_type ][10] .= $preview_link;
}
return $messages;
}
/*overide post type label in wordpress*/
add_filter( 'woocommerce_register_post_type_product', 'custom_post_type' );
function custom_post_type( $args ){
$labels = array(
'name' => __( 'Solutions', 'woocommerce' ),
'singular_name' => __( 'Solution', 'woocommerce' ),
'menu_name' => _x( 'Solutions', 'Admin menu name', 'woocommerce' ),
'add_new' => __( 'Add Solution', 'woocommerce' ),
'add_new_item' => __( 'Add New Solution', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit Solution', 'woocommerce' ),
'new_item' => __( 'New Solution', 'woocommerce' ),
'view' => __( 'View Solution', 'woocommerce' ),
'view_item' => __( 'View Solution', 'woocommerce' ),
'search_items' => __( 'Search Solutions', 'woocommerce' ),
'not_found' => __( 'No Solutions found', 'woocommerce' ),
'not_found_in_trash' => __( 'No Solutions found in trash', 'woocommerce' ),
'parent' => __( 'Parent Solution', 'woocommerce' ),
'featured_image' => __( 'Company Logo', 'woocommerce' ),
'set_featured_image' => __( 'Set solutions image', 'woocommerce' ),
'remove_featured_image' => __( 'Remove solutions image', 'woocommerce' ),
'use_featured_image' => __( 'Use as solutions image', 'woocommerce' ),
'insert_into_item' => __( 'Insert into solutions', 'woocommerce' ),
'uploaded_to_this_item' => __( 'Uploaded to this solutions', 'woocommerce' ),
'filter_items_list' => __( 'Filter Solutions', 'woocommerce' ),
'use_featured_image' => __( 'Use as solutions image', 'woocommerce' ),
'remove_featured_image' => __( 'Remove solutions image', 'woocommerce' ),
'set_featured_image' => __( 'Set solutions image', 'woocommerce' ),
'insert_into_item' => __( 'Insert into solutions', 'woocommerce' ),
'items_list_navigation' => __( 'Solutions navigation', 'woocommerce' ),
'uploaded_to_this_item' => __( 'Uploaded to this solutions', 'woocommerce' ),
'items_list' => __( 'Solutions list', 'woocommerce' ),
);
$args['labels'] = $labels;
$args['description'] = __( 'This is where you can add new tours to your store.', 'your-custom-plugin' );
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment