Skip to content

Instantly share code, notes, and snippets.

@sajidzaman
Created September 11, 2013 12:59
Show Gist options
  • Save sajidzaman/6523229 to your computer and use it in GitHub Desktop.
Save sajidzaman/6523229 to your computer and use it in GitHub Desktop.
Add a Custom message with the post insertion redirect in wordpress.
add_filter('wp_insert_post_data', 'ccl', 99);
function ccl($data) {
if ($data['post_type'] !== 'revision' && $data['post_status'] == 'publish') {
$data['post_status'] = 'draft';
add_filter('redirect_post_location', 'my_redirect_post_location_filter', 99);
}
return $data;
}
Then add a message variable in the redirect filter function.
function my_redirect_post_location_filter($location) {
remove_filter('redirect_post_location', __FUNCTION__, 99);
$location = add_query_arg('message', 99, $location);
return $location;
}
Finally hook into the post_updated_messages filter and add your message so Wordpress knows what to print.
add_filter('post_updated_messages', 'my_post_updated_messages_filter');
function my_post_updated_messages_filter($messages) {
$messages['post'][99] = 'Publish not allowed';
return $messages;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment