Skip to content

Plugin Functions

If you are interested in plugin development, check out the Plugin guide.

plugin_basename()

/**
 * Extracts the file name of a specific plugin.
 *
 * @param string $filename Plugin's file name.
 */
function plugin_basename(string $filename): string

register_activation_hook()

/**
 * When a plugin is activated, the action `activate_name` hook is called.
 * `name` is replaced by the actual file name of the plugin being activated.
 * So if the plugin is located at 'public/plugins/SamplePlugin.php', then the hook will
 * call 'activate_Sample'.
 *
 * @param string $filename Plugin's filename.
 * @param mixed $function The function that should be triggered by the hook.
 * @throws ReflectionException
 */
function register_activation_hook(string $filename, mixed $function): void

register_deactivation_hook()

/**
 * When a plugin is deactivated, the action `deactivate_name` hook is called.
 * `name` is replaced by the actual file name of the plugin being deactivated.
 * So if the plugin is located at 'public/plugins/SamplePlugin.php', then the hook will
 * call 'deactivate_Sample'.
 *
 * @param string $filename Plugin's filename.
 * @param mixed $function The function that should be triggered by the hook.
 * @throws ReflectionException
 */
function register_deactivation_hook(string $filename, mixed $function): void

plugin_dir_path()

/**
 * Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in.
 *
 * @param string $filename The filename of the plugin (__FILE__).
 * @return string The filesystem path of the directory that contains the plugin.
 */
function plugin_dir_path(string $filename): string

active_plugins()

/**
 * Returns a list of all plugins that have been activated.
 *
 * @return array|false
 * @throws ReflectionException
 * @throws ContainerExceptionInterface
 * @throws NotFoundExceptionInterface
 */
function active_plugins(): array|false

activate_plugin()

/**
 * Activates a specific plugin that is called by $_GET['id'] variable.
 *
 * @param string $plugin ID of the plugin to activate
 * @throws ContainerExceptionInterface
 * @throws NotFoundExceptionInterface
 * @throws ReflectionException
 */
function activate_plugin(string $plugin): void

deactivate_plugin()

/**
 * Deactivates a plugin.
 *
 * @param string $plugin
 * @return void
 * @throws ContainerExceptionInterface
 * @throws NotFoundExceptionInterface
 * @throws ReflectionException
 */
function deactivate_plugin(string $plugin): void

is_plugin_activated()

/**
 * Checks if a particular plugin has been activated.
 *
 * @param string $plugin
 * @return bool
 * @throws ContainerExceptionInterface
 * @throws NotFoundExceptionInterface
 * @throws ReflectionException
 * @throws \Qubus\Exception\Exception
 */
function is_plugin_activated(string $plugin): bool

load_active_plugins()

/**
 * @throws ContainerExceptionInterface
 * @throws NotFoundExceptionInterface
 * @throws ReflectionException
 * @throws TypeException
 * @throws \Qubus\Exception\Exception
 */
function load_active_plugins(): void

plugin_url()

/**
 * Retrieves a URL within the plugins or mu-plugins directory.
 *
 * Defaults to the plugins directory URL if no arguments are supplied.
 *
 * @param string $path  Optional. Extra path appended to the end of the URL, including
 *                      the relative directory if $plugin is supplied. Default empty.
 * @param string $plugin Optional. A full path to a file inside a plugin or mu-plugin.
 *                       The URL will be relative to its directory. Default empty.
 *                       Typically, this is done by passing `__FILE__` as the argument.
 * @return string Plugins URL link with optional paths appended.
 * @throws ReflectionException
 * @throws \Qubus\Exception\Exception
 */
function plugin_url(string $path = '', string $plugin = ''): string

plugin_dir_url()

/**
 * Get the URL directory path (with trailing slash) for the plugin __FILE__ passed in.
 *
 * @param string $file The filename of the plugin (__FILE__).
 * @return string the URL path of the directory that contains the plugin.
 * @throws ReflectionException
 * @throws \Qubus\Exception\Exception
 */
function plugin_dir_url(string $file): string

plugin_info()

/**
 * Retrieves meta data about a plugin.
 *
 * @access private
 * @param string $pluginsDir
 * @return array
 * @throws TypeException
 */
function plugin_info(string $pluginsDir = ''): array