Skip to content

Configuration file

Metapress uses a configuration file to define certain aspects of your plugin. This file must be named config.php and placed in the root directory of your plugin. The configuration file is a PHP array that is loaded by the plugin's main class and values can be accessed using the config method.

Requirements

The requirements key is an array of classes that extend the AbstractCheck class and implement the CheckInterface interface. These classes are used to check if the plugin's requirements are met. If a requirement is not met, the plugin will be disabled and an error message will be displayed to the user.

php
return [
    'requirements' => [
       new \Sematico\Metapress\Requirements\Checks\PHPVersion('8.0'),
    ],
];

The above example checks if the PHP version is 8.0 or higher. If the requirement is not met, the plugin will be disabled. For more information on the available checks and how to create your own, see the requirements checks documentation.

API Routes

The api_routes key is an array of routes classes that will be registered with the WordPress REST API. These classes must implement the ApiControllerInterface and the PluginAwareInterface interfaces.

You may use the PluginAwareTrait to automatically inject the plugin instance into the route class. The class must implement the register_routes method, which will be called when the plugin is loaded.

The framework comes with a pre-built route that handles the settings page for your plugin. If you're going to use the settings page, you must include the OptionsRoute class in the api_routes array.

php
return [
    'api_routes' => [
        \Sematico\Metapress\Api\OptionsRoute::class,
    ],
];

For more information on how to create your own API routes, see the API routes documentation.

Services

Metapress uses a service container to manage dependencies. The services key is an array of services that will be registered with the container. Internally, the container is powered by PHP-DI.

The framework comes with a series of pre-built services that are automatically registered with the container. An optional service that can be used as a base for your own services is the Options class.

This class provides a simple way to store and retrieve options of your plugin. You can use the Options class by injecting it into your services configuration.

php
return [
    'services' => [
        \Sematico\Metapress\Services\Options::class => autowire(),
    ],
];

For more information on how to create your own services, see the dependency injection documentation.

The framework accepts a series of helpful links that will be displayed in the plugin's settings page and other areas of the plugin. The following keys are available:

  • settings_link: The URL to the plugin's settings page.
  • review_link: The URL to the plugin's review page.
  • support_link: The URL to the plugin's support page.
  • documentation_link: The URL to the plugin's documentation page.

Each of these keys is an array with the following keys:

  • url: The URL to the page.
  • label: The label that will be displayed to the user.
php
return [
    'settings_link' => [
        'url' => 'https://example.com/settings',
        'label' => 'Settings',
    ],
    'review_link' => [
        'url' => 'https://example.com/review',
        'label' => 'Review',
    ],
    'support_link' => [
        'url' => 'https://example.com/support',
        'label' => 'Support',
    ],
    'documentation_link' => [
        'url' => 'https://example.com/docs',
        'label' => 'Documentation',
    ],
];

TIP

The settings link is displayed in the plugin's row on the plugins page in the WordPress admin area. The review, support, and documentation links are displayed in the plugin's settings page.

The footer links are displayed at the bottom of the plugin's settings page. You may add any number of links to the footer. Each link is an array with the following keys:

  • url: The URL to the page.
  • title: The title of the link.
php
return [
    'footer_links' => [
        'kb' => [
            'url' => 'https://example.com/kb',
            'label' => 'Knowledge Base',
        ],
        'docs' => [
            'url' => 'https://example.com/docs',
            'label' => 'Documentation',
        ],
        'support' => [
            'url' => 'https://example.com/support',
            'label' => 'Support',
        ],
    ],
];

Admin sidebar

The admin sidebar is displayed on the left side of the plugin's settings page. The sidebar supports blocks of content that can be added using the admin_sidebar key. Each block is an array with the following keys:

  • title: The title of the block.
  • content: The content of the block.
  • button: An array with the following keys:
    • url: The URL to the page.
    • label: The label of the button.
php
return [
    'admin_sidebar' => [
        [
            'title' => 'Need Support?',
            'content' => 'Whether you need help or have a new feature request, please create a topic in the support forum on WordPress.org.',
            'button' => [
                'url' => 'https://example.com/support',
                'label' => 'Get Support',
            ],
        ],
    ],
];

NOTE

We recommend using the admin sidebar to provide users with helpful information and links to support resources and to limit the use of the sidebar to one or two blocks.

Custom properties

Additional properties can be added to the configuration file to extend the functionality of your plugin as you see fit. You can access these properties using the config method in your plugin's main class.

php
return [
    'custom_property' => 'value',
];

You can access the custom property in your plugin's main class like this:

php
$custom_property = $this->config()->get('custom_property');