Skip to content

Instantly share code, notes, and snippets.

@ScottDeLuzio
Created October 24, 2016 22:48
Show Gist options
  • Save ScottDeLuzio/3f60d8c362996f0fe9fb726d631f1f99 to your computer and use it in GitHub Desktop.
Save ScottDeLuzio/3f60d8c362996f0fe9fb726d631f1f99 to your computer and use it in GitHub Desktop.
// Replace this
function wp_jv_prg_add_rg_meta_box_head() {
add_meta_box('wp_jv_prg_sectionid','WP JV Reading Groups','wp_jv_prg_add_rg_meta_box', 'post','side','high');
add_meta_box('wp_jv_prg_sectionid','WP JV Reading Groups','wp_jv_prg_add_rg_meta_box', 'page','side','high');
}
// With this
function wp_jv_prg_add_rg_meta_box_head() {
$post_types = wp_jv_prg_get_post_types();
foreach( $post_types as $post_type ) {
add_meta_box('wp_jv_prg_sectionid','WP JV Reading Groups','wp_jv_prg_add_rg_meta_box', $post_type,'side','high');
}
}
//Also add this to get all post type names (including page and post) and allow others to hook into $post_types
function wp_jv_prg_get_post_types() {
$args = array(
'public' => true,
'_builtin' => false
);
$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
$post_types = get_post_types( $args, $output, $operator );
$post_types = array_merge( $post_types, array( 'post' => 'post' ) );
if ( has_filter( 'wp_jv_prg_post_types' ) ){
$post_types = apply_filters( 'wp_jv_prg_post_types', $post_types );
}
return $post_types;
}
function wp_jv_prg_modify_post_types( $post_types ) {
return $post_types;
}
add_filter( 'wp_jv_prg_post_types', 'wp_jv_prg_modify_post_types' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment