Contexts / Submenu Context

Read More: Fieldmanager_Context_Submenu

Adds a new screen to the WordPress admin, and saves data to options.

The Submenu Context is a very powerful feature of Fieldmanager. The registered field’s name becomes the option_name stored in the database. If your settings page has many fields, you need to use a Group as your top-level field. You cannot have one settings page which saves to multiple options.

In order for the submenu action to fire, it must first be registered using fm_register_submenu_page(). Assuming I have a field "my_fields", here’s an example of registering a submenu page, then hooking into the action:

if ( function_exists( 'fm_register_submenu_page' ) ) {
    fm_register_submenu_page( 'my_fields', 'tools.php', 'Meta Fields' );
}
add_action( 'fm_submenu_my_fields', function() {
    $fm = new Fieldmanager_TextField( array(
        'name' => 'my_fields',
    ) );
    $fm->activate_submenu_page();
} );

In the above code, pay special attention to the three locations that “my_fields” appears, as it needs to be identical in all of them:

  1. The first argument passed to fm_register_submenu_page()
  2. The action used to register the field, fm_submenu_my_fields
  3. The field’s name

Action

fm_submenu_{page} [specifically: sanitize_text_field( $_GET['page'] )]

Additional References

  1. Example 1: Basic Settings Page

    if ( function_exists( 'fm_register_submenu_page' ) ) {
    	fm_register_submenu_page( 'option_fields', 'options-general.php', 'My Settings Page' );
    	add_action( 'fm_submenu_option_fields', function() {
    		$fm = new Fieldmanager_Group( array(
    			'name'     => 'option_fields',
    			'children' => array(
    				'text'         => new Fieldmanager_Textfield( 'Text Field' ),
    				'media'        => new Fieldmanager_Media( 'Media File' ),
    				'richtextarea' => new Fieldmanager_RichTextArea( 'Rich Text Area' ),
    			)
    		) );
    		$fm->activate_submenu_page();
    	} );
    }