• Theo Platica

    (@platcatheo)


    Thank you for your contribution, but in order to expand the correct menu item, I had to make some edits to your plugin:

     /**
         * Load the ACF Assets only on archive options page
         * @param string $hook_suffix
         * @return void
         */
        public function admin_enqueue_scripts( $hook_suffix ) {
            $screen = get_current_screen();
    
            if ( strpos($_GET['page'], 'archive-options') !==  FALSE ) {
                acf_enqueue_scripts();
            }
        }
    
        /**
         * Add ACF menu page for each custom post type
         *
         * @param string $label
         * @param string $menu
         */
        private function add_menu( $label, $menu, $post_type ) {
            $page_name = sprintf( __( '%s Archive', 'acf-archive' ), $label);
    
            $options = [
                'parent_slug' => $menu,
                'page_title'  => $page_name,
                'menu_title'  => $page_name,
                'capability'  => 'edit_posts',
                'menu_slug'   => 'archive-options-'.$post_type,
            ];
    
            add_submenu_page(
                $options['parent_slug'],
                $options['page_title'],
                $options['menu_title'],
                $options['capability'],
                $options['menu_slug'],
                [ $this, 'render_menu' ]
            );
        }
    
        /**
         * Check if we are in the current post type for showing the fields.
         *
         * @param $match
         * @param $rule
         * @param $options
         * @return bool
         */
        public function location_rules_match_archive( $match, $rule, $options ) {
            if ( ! isset( $_GET['post_type'] ) || ! isset( $_GET['page'] ) ) {
                return $match;
            }
    
            return $_GET['post_type'] == $rule['value'] && strpos($_GET['page'], 'archive-options') !==  FALSE;
        }
  • The topic ‘Nice work’ is closed to new replies.