YM Fast Options WordPress plugin documentation – <yanmet.com>

YM Fast Options WordPress plugin documentation

Getting Started

First of all you need to install YM Fast Options.

Then open your functions.php theme file. You can found it in:

../wp-content/themes/your-theme/functions.php

Add callback function to admin_menu action hook

if ( class_exists( 'YMFO_Page' ) ) {
    /** Registers YMFO custom options */
    add_action( 'admin_menu', function () {
        // Next code here
    });
}

Create options page

For example it will be a contacts page.

$contacts_page = new YMFO_Page( 'Contacts', 'contacts' );

The first function argument is the section title, and the second is the section slug.

Create options section

For example it will be a section with social media links.

$contacts_page->add_section( 'Social media', 'social_media' );

The first function argument is the section title, and the second is the section slug.

Add options fields to section

$contacts_page->add_field( 'YouTube', 'youtube_link', 'url', 'social_media' );
$contacts_page->add_field( 'Facebook', 'facebook_link', 'url', 'social_media' );

The first function argument is the field title, the second is the field slug, the third is the field type (you can find allowed types below) and the fourth is the field section slug.

It’s done!

You can locate the new options page in the WordPress admin area on the sidebar.

Our result code is:

if ( class_exists( 'YMFO_Page' ) ) {
    /** Registers YMFO custom options */
    add_action( 'admin_menu', function () {
        // Create page
        $contacts_page = new YMFO_Page( 'Contacts', 'contacts' );

        // Create section
        $contacts_page->add_section( 'Social media', 'social_media' );

        // Create fields
        $contacts_page->add_field( 'YouTube', 'youtube_link', 'url', 'social_media' );
        $contacts_page->add_field( 'Facebook', 'facebook_link', 'url', 'social_media' );
    });
}

How to get new options values

To get your options values use ymfo_get_option( $page_slug, $field_slug ).

For example let’s print a link to your YouTube channel:

<a href="<?php echo esc_attr( ymfo_get_option( 'contacts', 'youtube_link' ) ); ?>">YouTube</a>

Allowed field types

  • text
  • textarea
  • number
  • tel
  • email
  • url
  • date
  • datetime-local
  • month
  • week
  • time
  • color

Examples

How to create page with subpages

To create a page with subpages you can use callback and parent_page arguments.

For top page you need to set page slug the same as the first subpage’s slug and callback argument as null to disable page print callback.

For subpages you need to set top page variable as the parent_page argument.

if ( class_exists( 'YMFO_Page' ) ) {
    /** Registers YMFO custom options */
    add_action( 'admin_menu', function () {
        // Top page
        $top_page = new YMFO_Page( 'My Company', 'contacts', [
            'callback' => null,
        ]);

        // Subpage
        $contacts = new YMFO_Page( 'Contacts', 'contacts', [
            'parent_page' => $top_page,
        ]);
        // Subpage
        $settings = new YMFO_Page( 'Settings', 'settings', [
            'parent_page' => $top_page,
        ]);
    });
}