Upload files to 'includes'

This commit is contained in:
2022-10-30 14:11:56 -07:00
parent 5e82f002b9
commit bd403ce047
19 changed files with 532 additions and 245 deletions

View File

@ -55,7 +55,7 @@
* )
* )
*
* @var array
* @var array $yourls_filters
*/
if ( !isset( $yourls_filters ) ) {
$yourls_filters = [];
@ -65,7 +65,7 @@ if ( !isset( $yourls_filters ) ) {
* This global var will collect 'done' actions with the following structure:
* $yourls_actions['hook'] => number of time this action was done
*
* @var array
* @var array $yourls_actions
*/
if ( !isset( $yourls_actions ) ) {
$yourls_actions = [];
@ -79,7 +79,7 @@ if ( !isset( $yourls_actions ) ) {
*
* @link https://docs.yourls.org/development/plugins.html
* @param string $hook the name of the YOURLS element to be filtered or YOURLS action to be triggered
* @param callback $function_name the name of the function that is to be called.
* @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
* particular action are executed (default=10, lower=earlier execution, and functions
* with the same priority are executed in the order in which they were added to the
@ -88,11 +88,12 @@ if ( !isset( $yourls_actions ) ) {
* provided).
* @param string $type
* @global array $yourls_filters Storage for all of the filters
* @return void
*/
function yourls_add_filter( $hook, $function_name, $priority = 10, $accepted_args = NULL, $type = 'filter' ) {
global $yourls_filters;
// At this point, we cannot check if the function exists, as it may well be defined later (which is OK)
$id = yourls_filter_unique_id( $hook, $function_name, $priority );
$id = yourls_filter_unique_id($function_name);
$yourls_filters[ $hook ][ $priority ][ $id ] = [
'function' => $function_name,
@ -114,11 +115,12 @@ function yourls_add_filter( $hook, $function_name, $priority = 10, $accepted_arg
*
* @link https://docs.yourls.org/development/plugins.html
* @param string $hook The name of the action to which the $function_to_add is hooked.
* @param callback $function_name The name of the function you wish to be called.
* @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
* are executed (default: 10). Lower numbers correspond with earlier execution, and functions
* with the same priority are executed in the order in which they were added to the action.
* @param int $accepted_args Optional. The number of arguments the function accept (default 1).
* @return void
*/
function yourls_add_action( $hook, $function_name, $priority = 10, $accepted_args = 1 ) {
yourls_add_filter( $hook, $function_name, $priority, $accepted_args, 'action' );
@ -142,14 +144,11 @@ function yourls_add_action( $hook, $function_name, $priority = 10, $accepted_arg
* yourls_add_filter('my_hook_test', $my_callback_function);
*
* @link https://docs.yourls.org/development/hooks.html
* @param string $hook Hook to which the function is attached
* @param string|array $function Used for creating unique id
* @param int|bool $priority Used in counting how many hooks were applied. If === false and $function is an object reference,
* we return the unique id only if it already has one, false otherwise.
* @param string|array|object $function The callable used in a filter or action.
* @return string unique ID for usage as array key
*/
function yourls_filter_unique_id( $hook, $function, $priority ) {
// If function then just skip all of the tests and not overwrite the following.
function yourls_filter_unique_id($function) {
// If given a string (function name)
if ( is_string( $function ) ) {
return $function;
}
@ -167,20 +166,12 @@ function yourls_filter_unique_id( $hook, $function, $priority ) {
return spl_object_hash( $function[0] ).$function[1];
}
// Static Calling
if ( is_string( $function[0] ) ) {
return $function[0].'::'.$function[1];
}
/**
* There is no other possible case as of PHP 7.2-8.0 callables. Still, we're leaving the final
* `if` block (which could be remove to simply `return $function[0].'::'.$function[1]`) for readability
* and understanding the logic.
*/
// Last case, static Calling : $function[0] is a string (Class Name) and $function[1] is a string (Method Name)
return $function[0].'::'.$function[1];
}
/**
* Performs a filtering operation on a YOURLS element or event.
* Performs a filtering operation on a value or an event.
*
* Typical use:
*
@ -192,12 +183,12 @@ function yourls_filter_unique_id( $hook, $function, $priority ) {
* yourls_apply_filter( 'yourls_event' );
* (see yourls_do_action() )
*
* Returns an element which may have been filtered by a filter.
* Returns a value which may have been modified by a filter.
*
* @global array $yourls_filters storage for all of the filters
* @param string $hook the name of the YOURLS element or action
* @param mixed $value the value of the element before filtering
* @param bool $is_action true if the function is called by yourls_do_action()
* @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
*/
function yourls_apply_filter( $hook, $value = '', $is_action = false ) {
@ -222,6 +213,7 @@ function yourls_apply_filter( $hook, $value = '', $is_action = false ) {
reset( $yourls_filters[ $hook ] );
do {
foreach ( (array)current( $yourls_filters[ $hook ] ) as $the_ ) {
$_value = '';
if ( !is_null($the_[ 'function' ]) ) {
$args[ 1 ] = $value;
$count = $the_[ 'accepted_args' ];
@ -247,6 +239,7 @@ function yourls_apply_filter( $hook, $value = '', $is_action = false ) {
*
* @param string $hook the name of the YOURLS action
* @param mixed $arg action arguments
* @return void
*/
function yourls_do_action( $hook, $arg = '' ) {
global $yourls_actions, $yourls_filters;
@ -306,6 +299,7 @@ function yourls_did_action( $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
*/
function yourls_call_all_hooks($type, $hook, ...$args) {
global $yourls_filters;
@ -340,14 +334,14 @@ function yourls_call_all_hooks($type, $hook, ...$args) {
*
* @global array $yourls_filters storage for all of the filters
* @param string $hook The filter hook to which the function to be removed is hooked.
* @param callback $function_to_remove The name of the function which should be removed.
* @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.
*/
function yourls_remove_filter( $hook, $function_to_remove, $priority = 10 ) {
global $yourls_filters;
$function_to_remove = yourls_filter_unique_id( $hook, $function_to_remove, $priority );
$function_to_remove = yourls_filter_unique_id($function_to_remove);
$remove = isset( $yourls_filters[ $hook ][ $priority ][ $function_to_remove ] );
@ -435,15 +429,14 @@ function yourls_get_filters($hook) {
function yourls_get_actions($hook) {
return yourls_get_filters($hook);
}
/**
* Check if any filter has been registered for a hook.
*
* @since 1.5
* @global array $yourls_filters storage for all of the filters
* @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.
* @global array $yourls_filters storage for all of the filters
*/
function yourls_has_filter( $hook, $function_to_check = false ) {
global $yourls_filters;
@ -453,7 +446,7 @@ function yourls_has_filter( $hook, $function_to_check = false ) {
return $has;
}
if ( !$idx = yourls_filter_unique_id( $hook, $function_to_check, false ) ) {
if ( !$idx = yourls_filter_unique_id($function_to_check) ) {
return false;
}
@ -465,6 +458,7 @@ function yourls_has_filter( $hook, $function_to_check = false ) {
return false;
}
/**
* Check if any action has been registered for a hook.
*
@ -786,6 +780,7 @@ function yourls_list_plugin_admin_pages() {
* @param string $slug
* @param string $title
* @param callable $function
* @return void
*/
function yourls_register_plugin_page( $slug, $title, $function ) {
yourls_get_db()->add_plugin_page( $slug, $title, $function );
@ -796,6 +791,7 @@ function yourls_register_plugin_page( $slug, $title, $function ) {
*
* @since 1.5
* @param string $plugin_page
* @return void
*/
function yourls_plugin_admin_page( $plugin_page ) {
// Check the plugin page is actually registered
@ -866,6 +862,7 @@ function yourls_plugins_sort_callback( $plugin_a, $plugin_b ) {
*
* @codeCoverageIgnore
* @since 1.5.1
* @return void
*/
function yourls_shutdown() {
yourls_do_action( 'shutdown' );