DocumentationServices ProviderServices

Services Provider

Overview

WP Bones implements and provides several WordPress services such as Ajax, Shortcodes, Custom Post Types, and so on. Most of these services are handled by the config/plugin.php file.

The config/plugin.php file is the main configuration file of the plugin. It is the place where you can define the plugin name, version, and other settings.

Available Services

Write your own Service

Create a new Service Provider

You may create your own service by following the steps below:

php bones make:provider MyProvider

By default, the new provider will be created in the plugins/Providers directory. Of course, you may create your Service Provider manually and in any directory you prefer. You have to change the namespace accordingly.

Edit the Service Provider bootstrap

<?php
 
namespace WPKirk\Providers;
 
if (! defined('ABSPATH')) {
    exit;
}
 
use WPKirk\WPBones\Support\ServiceProvider;
 
class MyProvider extends ServiceProvider
{
 
  public function register()
  {
    // TODO
  }
}

In the register method, you can define the actions, filters, and other services you require.

Load the Service Provider

The ServiceProvider gets loaded through the config/plugin.php file.

  /*
  |--------------------------------------------------------------------------
  | Autoload Service Providers
  |--------------------------------------------------------------------------
  |
  | The service providers listed here will be automatically loaded on the
  | initialization of your plugin. Feel free to add your own services to
  | this array to provide expanded functionality to your applications.
  |
  */
 
  "providers" => [
    "WPKirk\Providers\MyProvider",
  ],