Created
July 19, 2016 22:35
-
-
Save stephenscaff/178ea2f00dc50056a958e3e4110ec9be to your computer and use it in GitHub Desktop.
Revisions
-
stephenscaff created this gist
Jul 19, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ /** * CPT ACF * * Adds a Menu Item for custom post types to add options page fields. * */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly function ctp_acf_options_pages() { if( function_exists('acf_add_options_page') ) { //Check if installed acf $ctpacf_post_types = get_post_types( array( '_builtin' => false, 'has_archive' => true ) ); //get post types foreach ( $ctpacf_post_types as $cpt ) { if( post_type_exists( $cpt ) ) { $cptname = get_post_type_object( $cpt )->labels->name; $cpt_acf_page = array( 'page_title' => ucfirst( $cptname ) . ' Fields', 'menu_title' => ucfirst( $cptname ) . ' Fields', 'menu_slug' => 'cpt-acf-' . $cpt, 'capability' => 'edit_posts', 'position' => false, 'parent_slug' => 'edit.php?post_type=' . $cpt, 'icon_url' => false, 'redirect' => false, 'post_id' => 'cpt_' . $cpt, 'autoload' => false ); acf_add_options_page( $cpt_acf_page ); } // end if } } else { //activation warning add_action( 'admin_notices', 'ctpacf_admin_error_notice' ); } } add_action( 'init', 'ctp_acf_options_pages', 99 );