[ 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');

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
return: void

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');

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).
return: void

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);

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

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.

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
return: mixed

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

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

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

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

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

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
return: void
since: 1.8.1

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.

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).
return: bool Whether the function was registered as a filter before it was removed.

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

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).
return: bool                        Whether the function was registered as an action before it was removed.
since: 1.7.1

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

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

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

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

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.

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

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

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

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

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.
return: int|bool Optionally returns the priority on that hook for the specified function.
since: 1.5

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

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

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

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

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>
* /

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

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

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

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.

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

yourls_activate_plugin( $plugin )   X-Ref
Activate a plugin

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

yourls_deactivate_plugin( $plugin )   X-Ref
Deactivate a plugin

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

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

param: string $file
return: string
since: 1.5

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

param: string $file
return: string
since: 1.5

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

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

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

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

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

param: string $plugin_page
return: void
since: 1.5

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

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

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

return: void
since: 1.5.1

yourls_return_true()   X-Ref
Returns true.

Useful for returning true to filters easily.

return: bool True.
since: 1.7.1

yourls_return_false()   X-Ref
Returns false.

Useful for returning false to filters easily.

return: bool False.
since: 1.7.1

yourls_return_zero()   X-Ref
Returns 0.

Useful for returning 0 to filters easily.

return: int 0.
since: 1.7.1

yourls_return_empty_array()   X-Ref
Returns an empty array.

Useful for returning an empty array to filters easily.

return: array Empty array.
since: 1.7.1

yourls_return_null()   X-Ref
Returns null.

Useful for returning null to filters easily.

return: null Null value.
since: 1.7.1

yourls_return_empty_string()   X-Ref
Returns an empty string.

Useful for returning an empty string to filters easily.

return: string Empty string.
since: 1.7.1



Generated: Fri Mar 28 05:10:25 2025 Cross-referenced by PHPXref 0.7.1