Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page covers a live example on how to build external plugins to communicate with the main release. In this example, we intend to use a newer library the EComPHP, which no longer requires SOAP as a component. However, since the plugin has wider compatibility with PHP 7.x and the new library do not offer anything older than PHP 8.1 - we can not really import such feature in the current module. Doing so, will force all merchants up to the latest PHP version and as of today, this is not possible.

This is why we are building an extension to the main plugin, that is compatible with the new library.

First step - Creating the loader and configuration

  • To get pre-configured data from the main plugin, you can use the built in quick-method rbwc_get_option that is supposed to be used instead of an insecure filter.
  • If you tend to build an implementation that injects itself into the primary plugin configuration, you will first need to handle the current configuration templates. This can be done with the filter rbwc_get_configuration_fields (see below). 

Getting configuration fields

In the newly built extension we use the filter rbwc_get_configuration_fields to make sure that we can keep track on the original configuration array that resides in the main plugin.

Code Block
    /**
     * @return array
     */
    public static function getFormFields(): array
    {
        return apply_filters('rbwc_get_configuration_fields', null, 'all');
    }

It is also good to know that the extension will not function properly without its parent features. This is done by using the plugins_loaded action like this:

Code Block
    add_action('plugins_loaded', 'ResursMapi\Mapi::activate');

    // In the Mapi class, we add this checker:

    /**
     * Activate plugin features for Resurs MAPI if parent plugin is available.
     * @return void
     * @noinspection PhpExpressionResultUnusedInspection
     */
    public static function activate(): void
    {
        // Initialize options from basic plugin, if all requirements is present.
        if (self::isAvailable()) {
            // Initialize plugin function and filters by silently instantiate the Plugin class.
            new Plugin();
            self::init();
        }
    }

    /**
     * Makes sure the parent plugin is available.
     * @return bool
     */
    private static function isAvailable(): bool
    {
        return apply_filters('rbwc_is_available', false);
    }