method_options_before_fields

 
 
 
 

do_action( 'method_options_before_fields', CMB2 $cmb_options )

Fires before Method’s default fields are registered on the Method Settings options page, allowing child themes to inject custom CMB2 fields at the top of the panel.


Description

This action fires inside method_register_theme_options_metabox() immediately after the CMB2 options box is created but before any of Method’s built‑in fields (social links, breadcrumb configuration, etc.) are added. This gives child themes a clean insertion point at the top of the settings page.


Parameters

$cmb_options (CMB2) :
The CMB2 box object for the Method Settings page. Use $cmb_options->add_field() to register additional fields.


Source

PHP
do_action( 'method_options_before_fields', $cmb_options );

File: lib/theme-options.php, function method_register_theme_options_metabox()


Usage

PHP
add_action( 'method_options_before_fields', 'mytheme_add_custom_settings' );

function mytheme_add_custom_settings( $cmb_options ) {
    $cmb_options->add_field( array(
        'name' => __( 'Site‑Wide Settings', 'mytheme' ),
        'id'   => 'custom_settings_title',
        'type' => 'title',
    ));

    $cmb_options->add_field( array(
        'name'    => __( 'Phone Number', 'mytheme' ),
        'desc'    => __( 'Enter the primary contact phone number.', 'mytheme' ),
        'id'      => 'contact_phone',
        'type'    => 'text',
    ));

    $cmb_options->add_field( array(
        'name'    => __( 'Email Address', 'mytheme' ),
        'desc'    => __( 'Enter the primary contact email address.', 'mytheme' ),
        'id'      => 'contact_email',
        'type'    => 'text_email',
    ));
}

Notes

  • Fields added via this action are stored in the same method_options option as Method’s built‑in fields. Retrieve them with get_option('method_options')['your_field_id'] or via Method_Utility::get_option('your_field_id').
  • This action fires during cmb2_admin_init, so CMB2 must be active. CMB2 is a required plugin configured via TGM Plugin Activation.
  • Fields appear at the top of the page, before the “Social Media Links” section. To add fields at the bottom or between existing sections, you would need to hook into cmb2_admin_init directly and target the method_theme_options_metabox box by ID.
  • The CMB2 box uses 'option_key' => 'method_options' and is positioned at menu position 2 with a custom Method logo icon.

Related

  • method_register_theme_options_metabox() — The function that fires this action
  • Method_Utility::get_option() — Retrieve option values programmatically
  • CMB2 Field Types Reference — Available field types for add_field()

Changelog

VersionDescription
2.0.0Introduced.