Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

c_cav on "Modifying post type - using the registered_post_type hook"

$
0
0

Actually this turned out to be a lot easier than I thought it would be, but since I could find NO documentation on this hook anywhere, figured I'd add something here.

In my case, there is a post type from another plugin that I simply do not want to display as it only confuses the end user...

Accomplishing this cleanly was rather easy using 2 action hooks. Code sample follows:

We'll call the target post_type "foo"

add_action('registered_post_type', 'my_registered_post_type_handler', 10, 2);
function my_registered_post_type_handler($post_type, $args) {
  do_action("my_registered_{$post_type}_post_type", $post_type, $args);
}

add_action('my_registered_foo_post_type', 'my_registered_foo_post_type_handler', 10, 2);
function my_registered_foo_post_type_handler($post_type, $args) {
  remove_action(current_filter(), __FUNCTION__, 10, 2);  // only run once
  // change your args here
  $args['show_ui'] = false;
  // re-register
  register_post_type($post_type, $args); // will call this hook again if it exists, so we removed it above.
}

And we are done.


Viewing all articles
Browse latest Browse all 8245

Trending Articles