Skip to content

ACF Option Page

Loïc Antignac edited this page May 24, 2022 · 7 revisions

Once the the plugin is created, the declaration(s) can be added:

<?php
/**
 * Plugin Name:       Example ACF Option Page
 * Author:            My Name
 * Text Domain:       wax-custom-content
 * Domain Path:       /languages
 */
defined( 'ABSPATH' ) || exit;

// If you already have an autoload (for example if you are on Bedrock) you can remove these 3 lines, otherwise leave them.
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
	require __DIR__ . '/vendor/autoload.php';
}

use Webaxones\Core\Entities\Entities;

Webaxones\Core\Library::init( 'webaxones-content' );

/**
 * Custom ACF option page: Projects archive
 */
$declarations[] = [
	'entity'   => 'Webaxones\Core\Option\AcfOptionsPage',
	'labels'   => [
		'page_title' => _x( 'Projects archive', 'Option page title', 'webaxones-content' ),
		'menu_title' => _x( 'Projects page', 'Option page menu title', 'webaxones-content' ),
	],
	'settings' => [
		'slug'        => 'wax-projects-settings',
		'location'    => 'custom', /*'custom', 'dashboard', 'posts', 'pages', 'comments', 'theme', 'plugins', 'users', 'management', 'options'*/
		'parent_slug' => 'edit.php?post_type=project', /* if location is "custom" */
		'capability'  => 'manage_options',
		'icon_url'    => '',
		'position'    => 99,
	],
];

Entities::process( $declarations );

Settings

As for all entities, settings starts with the slug key which identifies the entity and must be unique.
settings are based on the arguments of the acf_add_options_page function, to which is added the location key which allows to define the place where the menu will be displayed.
If location key equals custom, the menu will be placed as a submenu of the menu defined by parent_slug key.
All other values correspond to the native WordPress menus.