Skip to content

Getting started

The following guide will help you install Metapress inside your WordPress plugin and start using it. The guide assumes you have a basic understanding of PHP and WordPress plugin development and have Composer installed on your system.

Installation

To install Metapress, you need to add it as a dependency to your plugin. Open a terminal window and navigate to your plugin directory. Run the following command to add Metapress as a dependency:

bash
composer require sematico/metapress --prefer-dist --dev

TIP

The --dev flag is used because we assume you are scoping your plugin via PHP Scoper.

Auto-loading

Metapress uses Composer's autoloader to load classes. To autoload Metapress classes, add the following lines to your plugin's main file after the header comments:

php
if ( file_exists( dirname( __FILE__ ) . '/vendor/autoload.php' ) ) {
    require dirname( __FILE__ ) . '/vendor/autoload.php';
}

Initialize your plugin

Use the PluginFactory class to create an instance of your plugin. The class accepts 3 arguments:

  1. A class that implements the PluginInterface interface. You may use the Plugin class provided by Metapress.
  2. The plugin's slug. This should be a unique identifier for your plugin.
  3. The full path and filename of the file with symlinks resolved. Use the __FILE__ magic constant.
php
use Sematico\Metapress\Plugin;
use Sematico\Metapress\PluginFactory;

$plugin = PluginFactory::create( new Plugin(), 'plugin-slug', __FILE__);

Congratulations! You have successfully installed Metapress in your plugin. You can now start using the framework to build your plugin.

Configuration

The framework uses a configuration file to set up certain aspects of your plugin. You must create a configuration file in your plugin's root directory and call it config.php.

The configuration file must have the following properties:

  • requirements
  • services
  • api_routes

There are more configuration options available, but these are the minimum required to get started. See the example file below for a full example:

php
<?php

use Sematico\Metapress\Services\Options;

use function DI\autowire;

return [

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

    'settings_link' => [
        'url'   => admin_url('admin.php?page=sematico-tester'),
        'label' => 'Settings',
    ],

    'review_link' => [
        'url'   => '#',
        'label' => 'Review',
    ],

    'support_link' => [
        'url'   => '#',
        'label' => 'Support',
    ],

    'documentation_link' => [
        'url'   => '#',
        'label' => 'Documentation',
    ],

    'footer_links' => [
        'kb' => [
            'url'   => '#',
            'title' => 'Knowledge Base',
            'rel'   => 'noopener noreferrer',
        ],
        'docs' => [
            'url'   => '#',
            'title' => 'Documentation',
            'rel'   => 'noopener noreferrer',
        ],
        'support' => [
            'url'   => '#',
            'title' => 'Support',
            'rel'   => 'noopener noreferrer',
        ],
    ],

    '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'   => '#',
                'label' => 'Get Support',
            ],
        ],
    ],

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

    'services' => [
        Options::class => autowire(),
    ],
];

Additional properties can be added to the configuration file to extend the functionality of your plugin as you see fit.

For an in-depth look at the configuration options, see the Configuration guide.