I'm following a tutorial about custom post types and I am unable to understand how some functions work.
Allow me to explain a little more.
function my_updated_messages( $messages ) {
global $post, $post_ID;
$messages['product'] = array(
0 => '',
1 => sprintf( __('Product updated. <a href="%s">View product</a>'), esc_url( get_permalink($post_ID) ) ),
2 => __('Custom field updated.'),
3 => __('Custom field deleted.'),
4 => __('Product updated.'),
5 => isset($_GET['revision']) ? sprintf( __('Product restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('Product published. <a href="%s">View product</a>'), esc_url( get_permalink($post_ID) ) ),
7 => __('Product saved.'),
8 => sprintf( __('Product submitted. <a target="_blank" href="%s">Preview product</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __('Product scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview product</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('Product draft updated. <a target="_blank" href="%s">Preview product</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;
}
add_filter( 'post_updated_messages', 'my_updated_messages' );
I have copied part of the tutorial code snippet above. In this example, I do know that $messages contains and array which has certain post types. To allow custom messages to a custom post type, a new array is made and then returned. The function my_updated_message() is then filtered (I know what add_filter does).
Okay, the questions:
- When a new function has a parameter, the parameter has to be passed when the function is called right? In the case above, how does WP know that $messages is in fact, $messages from WP?
- Sorry for being totally unrelated to the context above, but why does var_dump($post_updated_messages); return null to me. I want to see what's inside.
A detailed explanation or a link to any tutorial would be greatly appreciated.
global $post, $post_ID;
are missing. Is it a mistake? (In factvar_dump($post_ID);
seems to returnNULL
).