plugins - Generate Advanced Custom Fields box in custom admin menu page

I have created an custom admin menu page called FCC Youtube with add_menu_page function which has some custom fields I

I have created an custom admin menu page called FCC Youtube with add_menu_page function which has some custom fields I manually generated via HTML and PHP:

code ( just the part how I created this custom admin menu page )

// creat admin menu page 
add_action("admin_menu","youtube_menu");
function youtube_menu() {
        add_menu_page('Youtube Channel Settings', 'FCC Youtube', 'edit_pages', 'youtube_channel_settings', 'youtube_channel_render_page','.png');
        add_action('admin_init','youtube_regsettings');
    }

I want to create many admin menu pages like the FCC Youtube page I've created. ( FCC Vimeo, FCC Buttons etc.)

I wish these pages have ACF field groups. , means I can create ACF field groups and assign the group to my custom admin menu pages It will work exactly like ACF Option-addon page.

ACF Option-addon doesn't allow me to create multiple top level Options page. I understand I can create multiple second-level option page but I wish to have many TOP Level ones, but I still can't figure out how to do this!

I have purchased the Option add-on but it doesn't allow me to create multiple "top level" Option page, I only have a parent page called "Options" then lots of sub pages under it, I wish to have other "Top Level" pages have other names than "Options" , but it seems very difficult to do : s,

see this

I have all these bunch of options page under the Parent 'Options', I can't move them outside of the parent

I have created an custom admin menu page called FCC Youtube with add_menu_page function which has some custom fields I manually generated via HTML and PHP:

code ( just the part how I created this custom admin menu page )

// creat admin menu page 
add_action("admin_menu","youtube_menu");
function youtube_menu() {
        add_menu_page('Youtube Channel Settings', 'FCC Youtube', 'edit_pages', 'youtube_channel_settings', 'youtube_channel_render_page','http://fcc.sportingpulse/wp-content/uploads/2013/04/youtube_icon16x16.png');
        add_action('admin_init','youtube_regsettings');
    }

I want to create many admin menu pages like the FCC Youtube page I've created. ( FCC Vimeo, FCC Buttons etc.)

I wish these pages have ACF field groups. , means I can create ACF field groups and assign the group to my custom admin menu pages It will work exactly like ACF Option-addon page.

ACF Option-addon doesn't allow me to create multiple top level Options page. I understand I can create multiple second-level option page but I wish to have many TOP Level ones, but I still can't figure out how to do this!

I have purchased the Option add-on but it doesn't allow me to create multiple "top level" Option page, I only have a parent page called "Options" then lots of sub pages under it, I wish to have other "Top Level" pages have other names than "Options" , but it seems very difficult to do : s,

see this

I have all these bunch of options page under the Parent 'Options', I can't move them outside of the parent

Share Improve this question edited Apr 17, 2013 at 4:56 Ray Tsai asked Apr 16, 2013 at 6:14 Ray TsaiRay Tsai 311 silver badge4 bronze badges 9
  • Why not use the Settings API? codex.wordpress/Settings_API – Andrew Bartel Commented Apr 16, 2013 at 6:17
  • I just wished I can have a page that can go into editing content straight away, like this:ray-tsai/fcc_custom_bt.png, instead of seeing this page first :ray-tsai/fcc_custom_bt2.png, and then going into the editing page, I don't need my clients to see the multiple posts page. – Ray Tsai Commented Apr 16, 2013 at 6:30
  • hi man I've put in more details hopefully it is now more clear ! – Ray Tsai Commented Apr 17, 2013 at 4:35
  • So, you want an ACF Options Page premium add-on without premium? – brasofilo Commented Apr 17, 2013 at 4:41
  • I have purchased the Option add-on but it doesn't allow me to create multiple "top level" Option page, I only have a parent page called "Options" then lots of sub pages under it, I wish to have other "Top Level" pages have other names than "Options" , but it seems very difficult to do : s, see this ray-tsai/fcc_options_sub.png, I have all these bunch of options page under the Parent 'Options', I can't move them outside of the parent – Ray Tsai Commented Apr 17, 2013 at 4:48
 |  Show 4 more comments

1 Answer 1

Reset to default 3

Interesting exercise, a one page plugin that believes it deserves a first level menu page is wrong, IMO. I use the same technique with Jetpack.

To create sub-pages in the Options Page add-on, read the documentation.

The logic of this menu/sub-menu swapping is:

  1. Add multiple ACF Options Pages
  2. Create our menu first level page
  3. Remove (hide) our plugin page
  4. Add (move) our plugin page into ACF's

Steps 1 and 2 are to make this example generic.
To use it with any other plugin, only steps 3 and 4 are necessary, adjusting the slugs.
To move it into a default WP menu, for example, use add_theme_page (Appearance) or add_options_page (Settings).

<?php
/**
 * Plugin Name: Swap Menus and Sub-menus
 * Plugin URI: http://wordpress.stackexchange/q/95981/12615
 * Author: brasofilo
 * Author URI: http://wordpress.stackexchange/users/12615/brasofilo
 * Licence: GPLv2 or later
 */

class Swap_Menus_WPSE_95981 {

    function __construct()
    {
        add_action( 'plugins_loaded', array( $this, 'modify_menus' ) );
    }

    function modify_menus() 
    {
        // 1) Add ACF Options pages
        if( function_exists( "register_options_page" ) )
        {
            register_options_page( 'Header' );
            register_options_page( 'Footer' );
        }

        // 2) Create this plugin page
        add_action( 'admin_menu', array( $this, 'add_aux_menu' ) );

        // 3) Remove (hide) this plugin page
        add_action( 'admin_init', array( $this, 'remove_aux_menu' ) );

        // 4) Move this plugin page into ACF Options page
        // Priority here (9999) is to put the submenu at last postition
        // If the priority is removed, the submenu is put at first position
        add_action( 'admin_menu', array( $this, 'add_aux_menu_again'), 9999 );
    }

    function add_aux_menu() 
    {
        add_menu_page(
            'Dummy Page First Level', 
            'Dummy Title', 
            'edit_posts', 
            'dummy-page-slug', 
            array( $this, 'menu_page_content' )
        );
    }

    function menu_page_content() 
    {
        ?>
            <div id="icon-post" class="icon32"></div>
            <h2>Dummy Page</h2>
            <p> Lorem ipsum</p>
        <?php
    }

    function remove_aux_menu() 
    {
        remove_menu_page( 'dummy-page-slug' ); 
    }


    function add_aux_menu_again() 
    {
        // To move into default pages, f.ex., use add_theme_page or add_options_page
        add_submenu_page(
            'acf-options-header', // <---- Destination menu slug
            'Dummy Page Second Level', 
            'Dummy Page Second Level', 
            'edit_posts', 
            'dummy-page-slug', 
            array( $this, 'menu_page_content' )
        );
    }
}

new Swap_Menus_WPSE_95981();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745348333a4623671.html

相关推荐

  • plugins - Generate Advanced Custom Fields box in custom admin menu page

    I have created an custom admin menu page called FCC Youtube with add_menu_page function which has some custom fields I

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信