Use new code style
This commit is contained in:
@ -9,8 +9,8 @@
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Exception\Runtime_Exception;
|
||||
use \Psr\Log\LogLevel;
|
||||
use WP_Ultimo\Exception\Runtime_Exception;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
/**
|
||||
* Returns the WP Multisite WaaS version.
|
||||
@ -21,8 +21,7 @@ use \Psr\Log\LogLevel;
|
||||
function wu_get_version() {
|
||||
|
||||
return class_exists(\WP_Ultimo::class) ? \WP_Ultimo::VERSION : '';
|
||||
|
||||
} // end wu_get_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the debug status.
|
||||
@ -33,8 +32,7 @@ function wu_get_version() {
|
||||
function wu_is_debug() {
|
||||
|
||||
return defined('WP_ULTIMO_DEBUG') && WP_ULTIMO_DEBUG;
|
||||
|
||||
} // end wu_is_debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if WP Multisite WaaS is being loaded as a must-use plugin.
|
||||
@ -45,8 +43,7 @@ function wu_is_debug() {
|
||||
function wu_is_must_use() {
|
||||
|
||||
return defined('WP_ULTIMO_IS_MUST_USE') && WP_ULTIMO_IS_MUST_USE;
|
||||
|
||||
} // end wu_is_must_use;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an array key value is set and returns it.
|
||||
@ -68,15 +65,12 @@ function wu_is_must_use() {
|
||||
*/
|
||||
function wu_get_isset($array, $key, $default = false) {
|
||||
|
||||
if (!is_array($array)) {
|
||||
|
||||
if ( ! is_array($array)) {
|
||||
$array = (array) $array;
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
return isset($array[$key]) ? $array[$key] : $default;
|
||||
|
||||
} // end wu_get_isset;
|
||||
return isset($array[ $key ]) ? $array[ $key ] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the main site id for the network.
|
||||
@ -91,8 +85,7 @@ function wu_get_main_site_id() {
|
||||
global $current_site;
|
||||
|
||||
return $current_site->blog_id;
|
||||
|
||||
} // end wu_get_main_site_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function return 'slugfied' options terms to be used as options ids.
|
||||
@ -104,8 +97,7 @@ function wu_get_main_site_id() {
|
||||
function wu_slugify($term) {
|
||||
|
||||
return "wp-ultimo_$term";
|
||||
|
||||
} // end wu_slugify;
|
||||
}
|
||||
/**
|
||||
* Returns the full path to the plugin folder.
|
||||
*
|
||||
@ -115,8 +107,7 @@ function wu_slugify($term) {
|
||||
function wu_path($dir): string {
|
||||
|
||||
return WP_ULTIMO_PLUGIN_DIR . $dir; // @phpstan-ignore-line
|
||||
|
||||
} // end wu_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL to the plugin folder.
|
||||
@ -128,8 +119,7 @@ function wu_path($dir): string {
|
||||
function wu_url($dir) {
|
||||
|
||||
return apply_filters('wp_ultimo_url', WP_ULTIMO_PLUGIN_URL . $dir); // @phpstan-ignore-line
|
||||
|
||||
} // end wu_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand to retrieving variables from $_GET, $_POST and $_REQUEST;
|
||||
@ -142,11 +132,10 @@ function wu_url($dir) {
|
||||
*/
|
||||
function wu_request($key, $default = false) {
|
||||
|
||||
$value = isset($_REQUEST[$key]) ? stripslashes_deep($_REQUEST[$key]) : $default;
|
||||
$value = isset($_REQUEST[ $key ]) ? stripslashes_deep($_REQUEST[ $key ]) : $default;
|
||||
|
||||
return apply_filters('wu_request', $value, $key, $default);
|
||||
|
||||
} // end wu_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an exception if a given hook was not yet run.
|
||||
@ -159,15 +148,12 @@ function wu_request($key, $default = false) {
|
||||
*/
|
||||
function _wu_require_hook($hook = 'ms_loaded') { // phpcs:ignore
|
||||
|
||||
if (!did_action($hook)) {
|
||||
|
||||
if ( ! did_action($hook)) {
|
||||
$message = "This function can not yet be run as it relies on processing that happens on hook {$hook}.";
|
||||
|
||||
throw new Runtime_Exception($message);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end _wu_require_hook;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if reflection is available.
|
||||
@ -183,14 +169,11 @@ function wu_are_code_comments_available() {
|
||||
static $res;
|
||||
|
||||
if ($res === null) {
|
||||
|
||||
$res = (bool) (new \ReflectionFunction(__FUNCTION__))->getDocComment();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
||||
} // end wu_are_code_comments_available;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join string into a single path string.
|
||||
@ -202,18 +185,15 @@ function wu_are_code_comments_available() {
|
||||
function wu_path_join(...$parts): string {
|
||||
|
||||
if (sizeof($parts) === 0) {
|
||||
|
||||
return '';
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$prefix = ($parts[0] === DIRECTORY_SEPARATOR) ? DIRECTORY_SEPARATOR : '';
|
||||
|
||||
$processed = array_filter(array_map(fn($part) => rtrim((string) $part, DIRECTORY_SEPARATOR), $parts), fn($part) => !empty($part));
|
||||
$processed = array_filter(array_map(fn($part) => rtrim((string) $part, DIRECTORY_SEPARATOR), $parts), fn($part) => ! empty($part));
|
||||
|
||||
return $prefix . implode(DIRECTORY_SEPARATOR, $processed);
|
||||
|
||||
} // end wu_path_join;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -229,8 +209,7 @@ function wu_path_join(...$parts): string {
|
||||
function wu_log_add($handle, $message, $log_level = LogLevel::INFO) {
|
||||
|
||||
\WP_Ultimo\Logger::add($handle, $message, $log_level);
|
||||
|
||||
} // end wu_log_add;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear entries from chosen file.
|
||||
@ -243,8 +222,7 @@ function wu_log_add($handle, $message, $log_level = LogLevel::INFO) {
|
||||
function wu_log_clear($handle) {
|
||||
|
||||
\WP_Ultimo\Logger::clear($handle);
|
||||
|
||||
} // end wu_log_clear;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe log errors to the file.
|
||||
@ -257,12 +235,9 @@ function wu_log_clear($handle) {
|
||||
function wu_maybe_log_error($e) {
|
||||
|
||||
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||
|
||||
error_log($e);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end wu_maybe_log_error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the function caller.
|
||||
@ -276,11 +251,10 @@ function wu_get_function_caller($depth = 1) {
|
||||
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $depth + 1);
|
||||
|
||||
$caller = isset($backtrace[$depth]['function']) ? $backtrace[$depth]['function'] : null;
|
||||
$caller = isset($backtrace[ $depth ]['function']) ? $backtrace[ $depth ]['function'] : null;
|
||||
|
||||
return $caller;
|
||||
|
||||
} // end wu_get_function_caller;
|
||||
}
|
||||
/**
|
||||
* Checks if a particular plugin is skipped in a CLI context.
|
||||
*
|
||||
@ -290,25 +264,20 @@ function wu_get_function_caller($depth = 1) {
|
||||
*/
|
||||
function wu_cli_is_plugin_skipped($plugin = null): bool {
|
||||
|
||||
if (!class_exists(\WP_CLI::class)) {
|
||||
|
||||
if ( ! class_exists(\WP_CLI::class)) {
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$skipped_plugins = \WP_CLI::get_config('skip-plugins');
|
||||
|
||||
if (is_bool($skipped_plugins)) {
|
||||
|
||||
return true;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$skipped_plugins = array_map(fn($plugin_slug) => trim((string) $plugin_slug), explode(',', (string) $skipped_plugins));
|
||||
|
||||
return in_array($plugin, $skipped_plugins, true);
|
||||
|
||||
} // end wu_cli_is_plugin_skipped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture errors and exceptions thrown inside the callback to prevent breakage.
|
||||
@ -324,13 +293,9 @@ function wu_cli_is_plugin_skipped($plugin = null): bool {
|
||||
function wu_ignore_errors($fn, $log = false) {
|
||||
|
||||
try {
|
||||
|
||||
call_user_func($fn);
|
||||
|
||||
} catch (\Throwable $exception) {
|
||||
|
||||
// Ignore it or log it.
|
||||
|
||||
} // end try;
|
||||
|
||||
} // end wu_ignore_errors;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user