[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/includes/ -> functions-plugins.php (summary)

The filter/plugin API is located in this file, which allows for creating filters and hooking functions, and methods. The functions or methods will be run when the filter is called. Any of the syntaxes explained in the PHP documentation for the {@link https://www.php.net/manual/en/language.types.callable.php 'callback'} type are valid.

Author: Ozh
File Size: 929 lines (30 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 36 functions

  yourls_add_filter()
  yourls_add_action()
  yourls_filter_unique_id()
  yourls_apply_filter()
  yourls_do_action()
  yourls_did_action()
  yourls_call_all_hooks()
  yourls_remove_filter()
  yourls_remove_action()
  yourls_remove_all_actions()
  yourls_remove_all_filters()
  yourls_get_filters()
  yourls_get_actions()
  yourls_has_filter()
  yourls_has_action()
  yourls_has_active_plugins()
  yourls_get_plugins()
  yourls_is_active_plugin()
  yourls_get_plugin_data()
  yourls_load_plugins()
  yourls_is_a_plugin_file()
  yourls_activate_plugin()
  yourls_deactivate_plugin()
  yourls_plugin_basename()
  yourls_plugin_url()
  yourls_list_plugin_admin_pages()
  yourls_register_plugin_page()
  yourls_plugin_admin_page()
  yourls_plugins_sort_callback()
  yourls_shutdown()
  yourls_return_true()
  yourls_return_false()
  yourls_return_zero()
  yourls_return_empty_array()
  yourls_return_null()
  yourls_return_empty_string()

Functions
Functions that are not part of a class:

yourls_add_filter( $hook, $function_name, $priority = 10, $accepted_args = NULL, $type = 'filter' )   X-Ref
Registers a filtering function

Typical use:
yourls_add_filter('some_hook', 'function_handler_for_hook');

return: void
param: string   $hook           the name of the YOURLS element to be filtered or YOURLS action to be triggered
param: callable $function_name  the name of the function that is to be called.
param: int      $priority       optional. Used to specify the order in which the functions associated with a
param: int      $accepted_args  optional. The number of arguments the function accept (default is the number
param: string   $type

yourls_add_action( $hook, $function_name, $priority = 10, $accepted_args = 1 )   X-Ref
Hooks a function on to a specific action.

Actions are the hooks that YOURLS launches at specific points
during execution, or when specific events occur. Plugins can specify that
one or more of its PHP functions are executed at these points, using the
Action API.

Typical use:
yourls_add_action('some_hook', 'function_handler_for_hook');

return: void
param: string   $hook           The name of the action to which the $function_to_add is hooked.
param: callable $function_name  The name of the function you wish to be called.
param: int      $priority       Optional. Used to specify the order in which the functions associated with a particular action
param: int      $accepted_args  Optional. The number of arguments the function accept (default 1).

yourls_filter_unique_id($function)   X-Ref
Build Unique ID for storage and retrieval.

Simply using a function name is not enough, as several functions can have the same name when they are enclosed in classes.
Possible ways to attach a function to a hook (filter or action):
- strings:
yourls_add_filter('my_hook_test', 'my_callback_function');
yourls_add_filter('my_hook_test', 'My_Class::my_callback_function');

- arrays:
yourls_add_filter('my_hook_test', array('My_Class','my_callback_function'));
yourls_add_filter('my_hook_test', array($class_instance, 'my_callback_function'));

- objects:
yourls_add_filter('my_hook_test', $class_instance_with_invoke_method);
yourls_add_filter('my_hook_test', $my_callback_function);

return: string  unique ID for usage as array key
param: string|array|object $function  The callable used in a filter or action.

yourls_apply_filter( $hook, $value = '', $is_action = false )   X-Ref
Performs a filtering operation on a value or an event.

Typical use:

1) Modify a variable if a function is attached to hook 'yourls_hook'
$yourls_var = "default value";
$yourls_var = yourls_apply_filter( 'yourls_hook', $yourls_var );

2) Trigger functions is attached to event 'yourls_event'
yourls_apply_filter( 'yourls_event' );
(see yourls_do_action() )

Returns a value which may have been modified by a filter.

return: mixed
param: string $hook the name of the YOURLS element or action
param: mixed $value the value of the element before filtering
param: true|mixed $is_action true if the function is called by yourls_do_action() - otherwise may be the second parameter of an arbitrary number of parameters

yourls_do_action( $hook, $arg = '' )   X-Ref
Performs an action triggered by a YOURLS event.

return: void
param: string $hook the name of the YOURLS action
param: mixed $arg action arguments

yourls_did_action( $hook )   X-Ref
Retrieve the number times an action is fired.

return: int The number of times action hook <tt>$hook</tt> is fired
param: string $hook Name of the action hook.

yourls_call_all_hooks($type, $hook, ...$args)   X-Ref
Execute the 'all' hook, with all of the arguments or parameters that were used for the hook

Internal function used by yourls_do_action() and yourls_apply_filter() - not meant to be used from
outside these functions.
This is mostly a debugging function to understand the flow of events.
See https://docs.yourls.org/development/debugging.html to learn how to use the 'all' hook

since: 1.8.1
return: void
param: string $type Either 'action' or 'filter'
param: string $hook The hook name, eg 'plugins_loaded'
param: mixed  $args Variable-length argument lists that were passed to the action or filter

yourls_remove_filter( $hook, $function_to_remove, $priority = 10 )   X-Ref
Removes a function from a specified filter hook.

This function removes a function attached to a specified filter hook. This
method can be used to remove default functions attached to a specific filter
hook and possibly replace them with a substitute.

To remove a hook, the $function_to_remove and $priority arguments must match
when the hook was added.

return: bool Whether the function was registered as a filter before it was removed.
param: string $hook The filter hook to which the function to be removed is hooked.
param: callable $function_to_remove The name of the function which should be removed.
param: int $priority optional. The priority of the function (default: 10).

yourls_remove_action( $hook, $function_to_remove, $priority = 10 )   X-Ref
Removes a function from a specified action hook.

since: 1.7.1
return: bool                        Whether the function was registered as an action before it was removed.
param: string   $hook               The action hook to which the function to be removed is hooked.
param: callable $function_to_remove The name of the function which should be removed.
param: int      $priority           optional. The priority of the function (default: 10).

yourls_remove_all_actions( $hook, $priority = false )   X-Ref
Removes all functions from a specified action hook.

since: 1.7.1
return: bool true when it's finished
param: string    $hook     The action to remove hooks from
param: int|false $priority optional. The priority of the functions to remove

yourls_remove_all_filters( $hook, $priority = false )   X-Ref
Removes all functions from a specified filter hook.

since: 1.7.1
return: bool true when it's finished
param: string    $hook     The filter to remove hooks from
param: int|false $priority optional. The priority of the functions to remove

yourls_get_filters($hook)   X-Ref
Return filters for a specific hook.

If hook has filters (or actions, see yourls_has_action()), this will return an array priorities => callbacks.
See the structure of yourls_filters on top of this file for details.

since: 1.8.3
return: array
param: string $hook The hook to retrieve filters for

yourls_get_actions($hook)   X-Ref
Return actions for a specific hook.

since: 1.8.3
return: array
param: string $hook The hook to retrieve actions for

yourls_has_filter( $hook, $function_to_check = false )   X-Ref
Check if any filter has been registered for a hook.

since: 1.5
return: int|bool Optionally returns the priority on that hook for the specified function.
param: string         $hook              The name of the filter hook.
param: callable|false $function_to_check optional. If specified, return the priority of that function on this hook or false if not attached.

yourls_has_action( $hook, $function_to_check = false )   X-Ref
Check if any action has been registered for a hook.

since: 1.5
return: bool|int
param: string         $hook
param: callable|false $function_to_check

yourls_has_active_plugins()   X-Ref
Return number of active plugins

return: int Number of activated plugins

yourls_get_plugins()   X-Ref
List plugins in /user/plugins

return: array Array of [/plugindir/plugin.php]=>array('Name'=>'Ozh', 'Title'=>'Hello', )

yourls_is_active_plugin( $plugin )   X-Ref
Check if a plugin is active

return: bool
param: string $plugin Physical path to plugin file

yourls_get_plugin_data( $file )   X-Ref
Parse a plugin header

The plugin header has the following form:
/*
Plugin Name: <plugin name>
Plugin URI: <plugin home page>
Description: <plugin description>
Version: <plugin version number>
Author: <author name>
Author URI: <author home page>
* /

Or in the form of a phpdoc block
/**
* Plugin Name: <plugin name>
* Plugin URI: <plugin home page>
* Description: <plugin description>
* Version: <plugin version number>
* Author: <author name>
* Author URI: <author home page>
* /

since: 1.5
return: array Array of 'Field'=>'Value' from plugin comment header lines of the form "Field: Value"
param: string $file Physical path to plugin file

yourls_load_plugins()   X-Ref
Include active plugins

This function includes every 'YOURLS_PLUGINDIR/plugin_name/plugin.php' found in option 'active_plugins'
It will return a diagnosis array with the following keys:
(bool)'loaded' : true if plugin(s) loaded, false otherwise
(string)'info' : extra information

since: 1.5
return: array    Array('loaded' => bool, 'info' => string)

yourls_is_a_plugin_file($file)   X-Ref
Check if a file is a plugin file

This doesn't check if the file is a valid PHP file, only that it's correctly named.

since: 1.5
return: bool
param: string $file Full pathname to a file

yourls_activate_plugin( $plugin )   X-Ref
Activate a plugin

since: 1.5
return: string|true  string if error or true if success
param: string $plugin Plugin filename (full or relative to plugins directory)

yourls_deactivate_plugin( $plugin )   X-Ref
Deactivate a plugin

since: 1.5
return: string|true  string if error or true if success
param: string $plugin Plugin filename (full relative to plugins directory)

yourls_plugin_basename( $file )   X-Ref
Return the path of a plugin file, relative to the plugins directory

since: 1.5
return: string
param: string $file

yourls_plugin_url( $file )   X-Ref
Return the URL of the directory a plugin

since: 1.5
return: string
param: string $file

yourls_list_plugin_admin_pages()   X-Ref
Build list of links to plugin admin pages, if any

since: 1.5
return: array  Array of arrays of URL and anchor of plugin admin pages, or empty array if no plugin page

yourls_register_plugin_page( $slug, $title, $function )   X-Ref
Register a plugin administration page

since: 1.5
return: void
param: string   $slug
param: string   $title
param: callable $function

yourls_plugin_admin_page( $plugin_page )   X-Ref
Handle plugin administration page

since: 1.5
return: void
param: string $plugin_page

yourls_plugins_sort_callback( $plugin_a, $plugin_b )   X-Ref
Callback function: Sort plugins

since: 1.5
return: int 0, 1 or -1, see uasort()
param: array $plugin_a
param: array $plugin_b

yourls_shutdown()   X-Ref
Shutdown function, runs just before PHP shuts down execution. Stolen from WP

This function is automatically tied to the script execution end at startup time, see
var $actions->register_shutdown in includes/Config/Init.php

You can use this function to fire one or several actions when the PHP execution ends.
Example of use:
yourls_add_action('shutdown', 'my_plugin_action_this');
yourls_add_action('shutdown', 'my_plugin_action_that');
// functions my_plugin_action_this() and my_plugin_action_that() will be triggered
// after YOURLS is completely executed

since: 1.5.1
return: void

yourls_return_true()   X-Ref
Returns true.

Useful for returning true to filters easily.

since: 1.7.1
return: bool True.

yourls_return_false()   X-Ref
Returns false.

Useful for returning false to filters easily.

since: 1.7.1
return: bool False.

yourls_return_zero()   X-Ref
Returns 0.

Useful for returning 0 to filters easily.

since: 1.7.1
return: int 0.

yourls_return_empty_array()   X-Ref
Returns an empty array.

Useful for returning an empty array to filters easily.

since: 1.7.1
return: array Empty array.

yourls_return_null()   X-Ref
Returns null.

Useful for returning null to filters easily.

since: 1.7.1
return: null Null value.

yourls_return_empty_string()   X-Ref
Returns an empty string.

Useful for returning an empty string to filters easily.

since: 1.7.1
return: string Empty string.



Generated: Tue Jan 21 05:10:11 2025 Cross-referenced by PHPXref 0.7.1