如何修复cmb2面板选项

时间:2019-06-02 08:53:36

标签: wordpress cmb2

我在下面编写了一段代码,但在羽毛发热中选择多媒体文件时遇到了麻烦;当我单击它时,将不会执行任何操作。

<?php
/**
 * This snippet has been updated to reflect the official supporting of options pages by CMB2
 * in version 2.2.5.
 *
 * If you are using the old version of the options-page registration,
 * it is recommended you swtich to this method.
 */
add_action( 'cmb2_admin_init', 'm_register_theme_options_metabox' );
/**
 * Hook in and register a metabox to handle a theme options page and adds a menu item.
 */
function m_register_theme_options_metabox() {
    /**
     * Registers options page menu item and form.
     */
    $args = array(
        'id'           => 'm_option_metabox',
        'title'        => esc_html__( 'تنظیمات قالب', 'm' ),
        'object_types' => array( 'options-page' ),
        /*
         * The following parameters are specific to the options-page box
         * Several of these parameters are passed along to add_menu_page()/add_submenu_page().
         */
        'option_key'      => 'm_options', // The option key and admin menu page slug.
        'tab_group'    => 'm_options',
        'tab_title'    => 'سربرگ',
        // 'icon_url'        => 'dashicons-palmtree', // Menu icon. Only applicable if 'parent_slug' is left empty.
        // 'menu_title'      => esc_html__( 'Options', 'm' ), // Falls back to 'title' (above).
        // 'parent_slug'     => 'themes.php', // Make options page a submenu item of the themes menu.
        // 'capability'      => 'manage_options', // Cap required to view options-page.
        // 'position'        => 1, // Menu position. Only applicable if 'parent_slug' is left empty.
        // 'admin_menu_hook' => 'network_admin_menu', // 'network_admin_menu' to add network-level options page.
        // 'display_cb'      => false, // Override the options-page form output (CMB2_Hookup::options_page_output()).
        // 'save_button'     => esc_html__( 'Save Theme Options', 'm' ), // The text for the options-page save button. Defaults to 'Save'.
    ) ;
    $header_options = new_cmb2_box( $args );
    /*
     * Options fields ids only need
     * to be unique within this box.
     * Prefix is not needed.
     */
    $header_options->add_field( array(
    'name' => 'شخصی سازی لوگو سایت',
    'type' => 'title',
    'id'   => 'custom_header_title'
) );
    $group_header = $header_options->add_field( array(
    'id'          => 'custom_header',
    'type'        => 'group',
    'description' => __( 'شما می توانید از این قسمت لوگویی برای سایت خود انتخاب نمایید', 'cmb2' ),
    'repeatable'  => false, // use false if you want non-repeatable group
    'options'     => array(
        'group_title'   => __( 'شخصی سازی لوگوی', 'cmb2' )
        ),
) );
    $header_options->add_group_field( $group_header, array(
    'name'    => 'پیام خوش امد گویی ',
    'default' => 'به هانزا خوش امدید',
    'id'      => 'm_welcome_text',
    'type'    => 'text',
    ) );
    $header_options->add_group_field( $group_header, array(
    'name'    => 'متن سبد خرید',
    'default' => 'سبد خرید',
    'id'      => 'm_basket_text',
    'type'    => 'text',
    ) );
    $header_options->add_group_field( $group_header, array(
    'name'    => 'لینک سبد خرید',
    'id'      => 'm_basket_link',
    'type'    => 'text',
    ) );
    $header_options->add_group_field( $group_header, array(
    'name'    => 'شماره تلفن',
    'default' => '+989388386156',
    'id'      => 'phone_number_text',
    'type'    => 'text',
) );
    $header_options->add_group_field( $group_header, array(
    'name'    => 'لوگو سایت',
    'desc'    => 'لطفا یک لوگو برای سایت خود انتخاب نمایید',
    'id'      => 'm_logo',
    'type'    => 'file',
    // Optional:
    'options' => array(
        'url' => true, // Hide the text input for the url
    ),
    'text'    => array(
        'add_upload_file_text' => 'انتخاب فایل' // Change upload button text. Default: "Add or Upload File"
    ),
    // query_args are passed to wp.media's library query.
    'query_args' => array(
         'type' => array(
            'image/gif',
            'image/jpeg',
            'image/png',
         ),
    ),
    'preview_size' => 'thumbnail', // Image size to use when previewing in the admin.
) );
    $header_options->add_group_field( $group_header, array(
    'name'    => 'تخفیف ویژه سبد خرید',
    'id'      => 'm_basket_offer_img',
    'type'    => 'file',
    // Optional:
    'options' => array(
        'url' => true, // Hide the text input for the url
    ),
    'text'    => array(
        'add_upload_file_text' => 'انتخاب فایل' // Change upload button text. Default: "Add or Upload File"
    ),
    // query_args are passed to wp.media's library query.
    'query_args' => array(
         'type' => array(
            'image/gif',
            'image/jpeg',
            'image/png',
         ),
    ),
    'preview_size' => 'thumbnail', // Image size to use when previewing in the admin.
) );
    $header_options->add_group_field( $group_header, array(
    'name'    => 'لینک تخفیف ویژه',
    'id'      => 'm_basket_offer_link',
    'type'    => 'text',
    ) );
    $args = array(
        'id'           => 'm_sidebar_option_metabox',
        'menu_title'   => 'سایدبار', // Use menu title, & not title to hide main h2.
        'object_types' => array( 'options-page' ),
        'option_key'   => 'm_sidebar_option_metabox',
        'parent_slug'  => 'm_options',
        'tab_group'    => 'm_options',
        'tab_title'    => 'سایدبار',
    );
$m_sidebar_options = new_cmb2_box( $args );

    $m_sidebar_options->add_field( array(
    'name' => 'شخصی سازی سایدبار سایت',
    'type' => 'title',
    'id'   => 'custom_social_slider'
) );
    $group_social_slider = $m_sidebar_options->add_field( array(
    'id'          => 'm_social_slider',
    'type'        => 'group',
    'repeatable'  => true, // use false if you want non-repeatable group
    'options'     => array(
        'group_title'   => __( 'انتخاب عکس {#} اسلایدر', 'cmb2' ),
        'add_button'    => __( 'Add Another Entry', 'cmb2' ),
        'remove_button' => __( 'Remove Entry', 'cmb2' ),
        'sortable'      => true, // beta
        ),
) );
    $m_sidebar_options->add_group_field( $group_social_slider, array(
    'name'    => 'عکس شبکه مجازی سایدبار',
    'desc'    => 'انتخاب عکس شبکه مجازی',
    'id'      => 'sidebar_social_img',
    'type'    => 'file',
    // Optional:
    'options' => array(
        'url' => true, // Hide the text input for the url
    ),
    'text'    => array(
        'add_upload_file_text' => 'انتخاب فایل' // Change upload button text. Default: "Add or Upload File"
    ),
    // query_args are passed to wp.media's library query.
    'query_args' => array(
         'type' => array(
            'image/gif',
            'image/jpeg',
            'image/png',
         ),
    ),
    'preview_size' => 'thumbnail', // Image size to use when previewing in the admin.
) );
    $m_sidebar_options->add_group_field( $group_social_slider, array(
    'name'    => 'متن جایگزین عکس',
    'id'      => 'sidebar_social_img_alt',
    'type'    => 'text',
) );
    $m_sidebar_options->add_group_field( $group_social_slider, array(
    'name'    => 'ادرس شبکه اجتماعی',
    'id'      => 'sidebar_social_img_link',
    'type'    => 'text_url',
) );
    $args = array(
        'id'           => 'm_f_slider_option_metabox',
        'menu_title'   => 'اسلایدر بالا', // Use menu title, & not title to hide main h2.
        'object_types' => array( 'options-page' ),
        'option_key'   => 'm_f_slider_option_metabox',
        'parent_slug'  => 'm_options',
        'tab_group'    => 'm_options',
        'tab_title'    => 'اسلایدر بالا',
    );
$m_f_slider_options = new_cmb2_box( $args );
    $m_f_slider_options->add_field( array(
    'name' => 'شخصی سازی اسلایدر بالا',
    'type' => 'title',
    'id'   => 'customize_first_slider'
) );
    $group_slider = $m_f_slider_options->add_field( array(
    'id'          => 'm_slider',
    'type'        => 'group',
    'description' => __( 'شما می توانید از این قسمت اسلایدر سایت خود را مدیریت کنید.', 'cmb2' ),
    'repeatable'  => true, // use false if you want non-repeatable group
    'options'     => array(
        'group_title'   => __( 'انتخاب عکس {#} اسلایدر', 'cmb2' ),
        'add_button'    => __( 'Add Another Entry', 'cmb2' ),
        'remove_button' => __( 'Remove Entry', 'cmb2' ),
        'sortable'      => true, // beta
        ),
) );
    $m_f_slider_options->add_group_field( $group_slider, array(
    'name'    => 'عکس اسلایدر',
    'desc'    => 'انتخاب عکس اسلایدر',
    'id'      => 'slider_img',
    'type'    => 'file',
    // Optional:
    'options' => array(
        'url' => true, // Hide the text input for the url
    ),
    'text'    => array(
        'add_upload_file_text' => 'انتخاب فایل' // Change upload button text. Default: "Add or Upload File"
    ),
    // query_args are passed to wp.media's library query.
    'query_args' => array(
         'type' => array(
            'image/gif',
            'image/jpeg',
            'image/png',
         ),
    ),
    'preview_size' => 'thumbnail', // Image size to use when previewing in the admin.
) );
    $m_f_slider_options->add_group_field( $group_slider, array(
    'name'    => 'متن مورد نظر برای اسلایدر',
    'id'      => 'slider_title',
    'type'    => 'text',
) );
    $m_f_slider_options->add_group_field( $group_slider, array(
    'name' => __( 'لینک اسلایدر', 'cmb2' ),
    'id'   => 'slider_url',
    'type' => 'text_url',
    // 'protocols' => array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet' ), // Array of allowed protocols
) );
$args = array(
        'id'           => 'm_content_option_metabox',
        'menu_title'   => 'مطالب سایت', // Use menu title, & not title to hide main h2.
        'object_types' => array( 'options-page' ),
        'option_key'   => 'm_content_option_metabox',
        'parent_slug'  => 'm_options',
        'tab_group'    => 'm_options',
        'tab_title'    => 'مطالب سایت',
    );
$m_content_options = new_cmb2_box( $args );
    $m_content_options->add_field( array(
    'name' => 'شخصی سازی مطالب هانزا',
    'type' => 'title',
    'id'   => 'customize_content'
) );
    $group_customize_m_content = $m_content_options->add_field( array(
    'id'          => 'm_content',
    'type'        => 'group',
    'description' => __( 'شما می توانید از این قسمت مطالب سایت خود را مدیریت کنید.', 'cmb2' ),
    'repeatable'  => true, // use false if you want non-repeatable group
    'options'     => array(
        'group_title'   => __( 'مطلب شماره {#}', 'cmb2' ),
        'add_button'    => __( 'اضافه کردن', 'cmb2' ),
        'remove_button' => __( 'حذف کردن', 'cmb2' ),
        'sortable'      => true, // beta
        ),
) );
    $m_content_options->add_group_field( $group_customize_m_content, array(
    'name'    => 'متن مورد نظر برای مطلب',
    'id'      => 'content-title',
    'type'    => 'text',
) );
    $m_content_options->add_group_field( $group_customize_m_content, array(
    'name'    => 'تنظیمات سربرگ',
    'id'      => 'content_make_',
    'type'    => 'wysiwyg',
    'options' => array(),
    ) );
    $m_content_options->add_group_field( $group_customize_m_content, array(
    'name'             => 'انتخاب اندازه',
    'id'               => 'content-size',
    'type'             => 'select',
    'show_option_none' => true,
    'default'          => 'col-md-3',
    'options'          => array(
        'col-md-1' => __( 'col-md-1', 'cmb2' ),
        'col-md-2' => __( 'col-md-2', 'cmb2' ),
        'col-md-3' => __( 'col-md-3', 'cmb2' ),
        'col-md-4' => __( 'col-md-4', 'cmb2' ),
        'col-md-5' => __( 'col-md-5', 'cmb2' ),
        'col-md-6' => __( 'col-md-6', 'cmb2' ),
        'col-md-7' => __( 'col-md-7', 'cmb2' ),
        'col-md-8' => __( 'col-md-8', 'cmb2' ),
        'col-md-9' => __( 'col-md-9', 'cmb2' ),
        'col-md-10' => __( 'col-md-10', 'cmb2' ),
        'col-md-11' => __( 'col-md-11', 'cmb2' ),
        'col-md-12' => __( 'col-md-12', 'cmb2' ),
    ),
) );
    $args = array(
        'id'           => 'm_s_slider_option_metabox',
        'menu_title'   => 'اسلایدر پایین', // Use menu title, & not title to hide main h2.
        'object_types' => array( 'options-page' ),
        'option_key'   => 'm_s_slider_option_metabox',
        'parent_slug'  => 'm_options',
        'tab_group'    => 'm_options',
        'tab_title'    => 'اسلایدر پایین',
    );
$m_s_slider_options = new_cmb2_box( $args );
    $m_s_slider_options->add_field( array(
    'name' => 'شخصی سازی اسلایدر سایت',
    'type' => 'title',
    'id'   => 'm_sidebat_title_2'
) );
    $group_slider_2 = $m_s_slider_options->add_field( array(
    'id'          => 'm_slider_2',
    'type'        => 'group',
    'description' => __( 'شما می توانید از این قسمت اسلایدر سایت خود را مدیریت کنید.', 'cmb2' ),
    'repeatable'  => true, // use false if you want non-repeatable group
    'options'     => array(
        'group_title'   => __( 'انتخاب عکس {#} اسلایدر', 'cmb2' ),
        'add_button'    => __( 'Add Another Entry', 'cmb2' ),
        'remove_button' => __( 'Remove Entry', 'cmb2' ),
        'sortable'      => true, // beta
        ),
) );
    $m_s_slider_options->add_group_field( $group_slider_2, array(
    'name'    => 'عکس اسلایدر',
    'desc'    => 'انتخاب عکس اسلایدر',
    'id'      => 'slider_img_2',
    'type'    => 'file',
    // Optional:
    'options' => array(
        'url' => true, // Hide the text input for the url
    ),
    'text'    => array(
        'add_upload_file_text' => 'انتخاب فایل' // Change upload button text. Default: "Add or Upload File"
    ),
    // query_args are passed to wp.media's library query.
    'query_args' => array(
         'type' => array(
            'image/gif',
            'image/jpeg',
            'image/png',
         ),
    ),
    'preview_size' => 'thumbnail', // Image size to use when previewing in the admin.
) );
    $m_s_slider_options->add_group_field( $group_slider_2, array(
    'name'    => 'متن مورد نظر برای اسلایدر',
    'id'      => 'slider_title_2',
    'type'    => 'text',
) );
    $m_s_slider_options->add_group_field( $group_slider_2, array(
    'name' => __( 'لینک اسلایدر', 'cmb2' ),
    'id'   => 'slider_url_2',
    'type' => 'text_url',
    // 'protocols' => array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet' ), // Array of allowed protocols
) );
    $args = array(
        'id'           => 'm_footer_option_metabox',
        'menu_title'   => 'فوتر', // Use menu title, & not title to hide main h2.
        'object_types' => array( 'options-page' ),
        'option_key'   => 'm_footer_option_metabox',
        'parent_slug'  => 'm_options',
        'tab_group'    => 'm_options',
        'tab_title'    => 'فوتر',
    );
$m_footer_options = new_cmb2_box( $args );
    $m_footer_options->add_field( array(
    'name' => 'شخصی سازی فوتر سایت',
    'type' => 'title',
    'id'   => 'm_sfooter_title'
) );
    $group_sfooter = $m_footer_options->add_field( array(
    'id'          => 'm_sfooter',
    'type'        => 'group',
    'description' => __( 'شما می توانید از این قسمت فوتر سایت خود را مدیریت کنید.', 'cmb2' ),
    'repeatable'  => false, // use false if you want non-repeatable group
) );
    $m_footer_options->add_group_field( $group_sfooter, array(
    'name'    => 'فوتر',
    'id'      => 'sfooter-content',
    'type'    => 'wysiwyg',
    'options' => array(),
) );
    $m_footer_options->add_group_field( $group_sfooter, array(
    'name'    => 'نماد اعتماد',
    'id'      => 'sfooter-namad',
    'type'    => 'wysiwyg',
    'options' => array(),
) );
    $group_footer = $m_footer_options->add_field( array(
    'id'          => 'm_footer',
    'type'        => 'group',
    'description' => __( 'شما می توانید از این قسمت فوتر سایت خود را مدیریت کنید.', 'cmb2' ),
    'repeatable'  => false, // use false if you want non-repeatable group
    'options'     => array(
        'group_title'   => __( 'شخصی سازی فوتر', 'cmb2' ),
        ),
) );
    $m_footer_options->add_group_field( $group_footer, array(
    'name' => 'متن کپی رایت فوتر',
    'default' => 'تمامی حقوق مادی و معنوی مطالب و طراحی های این سایت برای سایت کدپز محفوظ می باشد.',
    'id' => 'copyright',
    'type' => 'textarea_small'
) );
    $m_footer_options->add_group_field( $group_footer, array(
    'name' => __( 'تلگرام', 'cmb2' ),
    'id'   => 'social-telegram',
    'type' => 'text_url',
) );
    $m_footer_options->add_group_field( $group_footer, array(
    'name' => __( 'فیس بوک', 'cmb2' ),
    'id'   => 'social-facebook',
    'type' => 'text_url',
) );
    $m_footer_options->add_group_field( $group_footer, array(
    'name' => __( 'تویتر', 'cmb2' ),
    'id'   => 'social-twitter',
    'type' => 'text_url',
) );
    $m_footer_options->add_group_field( $group_footer, array(
    'name' => __( 'گوگل پلاس', 'cmb2' ),
    'id'   => 'social-google-plus',
    'type' => 'text_url',
) );
    $m_footer_options->add_group_field( $group_footer, array(
    'name' => __( 'اینستاگرام', 'cmb2' ),
    'id'   => 'social-instagram',
    'type' => 'text_url',
) );
    $args = array(
        'id'           => 'm_color_bg_option_metabox',
        'menu_title'   => 'پس زمینه و رنگ ها', // Use menu title, & not title to hide main h2.
        'object_types' => array( 'options-page' ),
        'option_key'   => 'm_color_bg_option_metabox',
        'parent_slug'  => 'm_options',
        'tab_group'    => 'm_options',
        'tab_title'    => 'پس زمینه و رنگ ها',
    );
$m_bg_color_options = new_cmb2_box( $args );
    $m_bg_color_options->add_field( array(
    'name' => 'شخصی سازی پس زمینه سایت',
    'type' => 'title',
    'id'   => 'customize_colors'
) );
    $group_customize = $m_bg_color_options->add_field( array(
    'id'          => 'background',
    'type'        => 'group',
    'description' => __( 'شما می توانید از این قسمت پس زمینه ای برای سایت خود انتخاب نمایید', 'cmb2' ),
    'repeatable'  => false, // use false if you want non-repeatable group
    'options'     => array(
        'group_title'   => __( 'شخصی سازی پس زمینه ی سایت', 'cmb2' )
        ),
) );
    $m_bg_color_options->add_group_field( $group_customize, array(
    'name'    => 'عکس پس زمینه',
    'desc'    => 'لطفا یک عکس برای پس زمینه سایت خود انتخاب نمایید',
    'id'      => 'bg-header',
    'type'    => 'file',
    // Optional:
    'options' => array(
        'url' => true, // Hide the text input for the url
    ),
    'text'    => array(
        'add_upload_file_text' => 'انتخاب فایل' // Change upload button text. Default: "Add or Upload File"
    ),
    // query_args are passed to wp.media's library query.
    'query_args' => array(
         'type' => array(
            'image/gif',
            'image/jpeg',
            'image/png',
         ),
    ),
    'preview_size' => 'thumbnail', // Image size to use when previewing in the admin.
) );
    $m_bg_color_options->add_group_field( $group_customize, array(
    'name'    => 'رنگ پس زمینه',
    'id'      => 'bg-color',
    'type'    => 'colorpicker',
    'default' => '#e2e3e4',
     'options' => array(
        'alpha' => true, // Make this a rgba color picker.
     ),
) );
    $m_bg_color_options->add_group_field( $group_customize, array(
    'name'    => 'پس زمینه هدر',
    'id'      => 'header_bg_color',
    'type'    => 'colorpicker',
    'default' => '#322c22',
     'options' => array(
        'alpha' => true, // Make this a rgba color picker.
     ),
) );
    $m_bg_color_options->add_group_field( $group_customize, array(
    'name'    => 'پس زمینه منو',
    'id'      => 'nav-bg-color',
    'type'    => 'colorpicker',
    'default' => '#322c22',
     'options' => array(
        'alpha' => true, // Make this a rgba color picker.
     ),
) );
    $m_bg_color_options->add_group_field( $group_customize, array(
    'name'    => 'پس زمینه رنگ دکمه ها',
    'id'      => 'btn-bg-color',
    'type'    => 'colorpicker',
    'default' => '#ffe430',
     'options' => array(
        'alpha' => true, // Make this a rgba color picker.
     ),
) );
    $m_bg_color_options->add_group_field( $group_customize, array(
    'name'    => 'پس زمینه رنگ دکمه ها',
    'id'      => 'btn-bgg-color',
    'type'    => 'colorpicker',
    'default' => '#231f20',

     'options' => array(
        'alpha' => true, // Make this a rgba color picker.
     ),
) );
    $m_bg_color_options->add_group_field( $group_customize, array(
    'name'    => 'سربرگ مطالب',
    'id'      => 'content-bg-color',
    'type'    => 'colorpicker',
    'default' => '#0ea6b6',
     'options' => array(
        'alpha' => true, // Make this a rgba color picker.
     ),
) );
    $m_bg_color_options->add_group_field( $group_customize, array(
    'name'    => 'رنگ نوشته سربرگ مطالب',
    'id'      => 'content-text-color',
    'type'    => 'colorpicker',
    'default' => '#ffffff',
     'options' => array(
        'alpha' => true, // Make this a rgba color picker.
     ),
) );
}
/**
 * Wrapper function around cmb2_get_option
 * @since  0.1.0
 * @param  string $key     Options array key
 * @param  mixed  $default Optional default value
 * @return mixed           Option value
 */
function m_get_option( $key = '',$id_name, $default = false ) {
    if ( function_exists( 'cmb2_get_option' ) ) {
        // Use cmb2_get_option as it passes through some key filters.
        return cmb2_get_option( $id_name, $key, $default );
    }
    // Fallback to get_option if CMB2 is not loaded yet.
    $opts = get_option( $id_name, $default );
    $val = $default;
    if ( 'all' == $key ) {
        $val = $opts;
    } elseif ( is_array( $opts ) && array_key_exists( $key, $opts ) && false !== $opts[ $key ] ) {
        $val = $opts[ $key ];
    }
    return $val;
}

在上面的代码中,我进行了设置并将它们放在不同的部分中,首先,所有代码都被划分为一个页面,效果并不理想。

反汇编后,我首先遇到了以主要格式加载代码的问题,该问题已解决。然后,我遇到了不在主选项卡以外的选项卡中不加载多媒体文件的问题。

0 个答案:

没有答案
相关问题