Prep Plugin for release on WordPress.org
Escape everything that should be escaped. Add nonce checks where needed. Sanitize all inputs. Apply Code style changes across the codebase. Correct many deprecation notices. Optimize load order of many filters.
This commit is contained in:
35
inc/functions/compatiblity.php
Normal file
35
inc/functions/compatiblity.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Backport of WordPress 6.7.0 current_user_can_for_site() function.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
*/
|
||||
|
||||
if ( ! function_exists('current_user_can_for_site')) {
|
||||
|
||||
/**
|
||||
* Returns whether the current user has the specified capability for a given site.
|
||||
*
|
||||
* This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
|
||||
* capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
|
||||
* map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
|
||||
*
|
||||
* This function replaces the current_user_can_for_blog() function.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* current_user_can_for_site( $site_id, 'edit_posts' );
|
||||
* current_user_can_for_site( $site_id, 'edit_post', $post->ID );
|
||||
* current_user_can_for_site( $site_id, 'edit_post_meta', $post->ID, $meta_key );
|
||||
*
|
||||
* @since 6.7.0
|
||||
*
|
||||
* @param int $site_id Site ID.
|
||||
* @param string $capability Capability name.
|
||||
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
|
||||
* @return bool Whether the user has the given capability.
|
||||
*/
|
||||
function current_user_can_for_site($site_id, $capability, ...$args) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
|
||||
return current_user_can_for_blog($site_id, $capability, ...$args);
|
||||
}
|
||||
}
|
@ -74,9 +74,9 @@ function wu_get_days_ago($date_1, $date_2 = false) {
|
||||
|
||||
$datetime_2 = wu_date($date_2);
|
||||
|
||||
$dateIntervar = $datetime_1->diff($datetime_2, false);
|
||||
$date_intervar = $datetime_1->diff($datetime_2, false);
|
||||
|
||||
return - $dateIntervar->days;
|
||||
return - $date_intervar->days;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +90,7 @@ function wu_get_current_time($type = 'mysql', $gmt = false) {
|
||||
|
||||
switch_to_blog(wu_get_main_site_id());
|
||||
|
||||
$time = current_time($type, $gmt); // phpcs:ignore
|
||||
$time = current_time($type, $gmt); // phpcs:ignore
|
||||
|
||||
restore_current_blog();
|
||||
|
||||
@ -121,7 +121,6 @@ function wu_filter_duration_unit($unit, $length) {
|
||||
$new_unit = $length > 1 ? __('Years', 'wp-multisite-waas') : __('Year', 'wp-multisite-waas');
|
||||
break;
|
||||
default:
|
||||
$new_unit = $new_unit;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -181,10 +180,10 @@ function wu_convert_php_date_format_to_moment_js_format($php_date_format): strin
|
||||
'g' => 'h',
|
||||
'H' => 'HH',
|
||||
'h' => 'hh',
|
||||
'I' => '', // Daylight Saving Time? => moment().isDST();
|
||||
'I' => '', // Daylight Saving Time?: moment().isDST().
|
||||
'i' => 'mm',
|
||||
'j' => 'D',
|
||||
'L' => '', // Leap year? => moment().isLeapYear();
|
||||
'L' => '', // Is Leap year?: moment().isLeapYear().
|
||||
'l' => 'dddd',
|
||||
'M' => 'MMM',
|
||||
'm' => 'MM',
|
||||
|
@ -358,7 +358,7 @@ function wu_calculate_taxes_by_day($start_date = false, $end_date = false, $incl
|
||||
|
||||
foreach ($line_items_groups as $line_items_group) {
|
||||
foreach ($line_items_group as $line_item) {
|
||||
$date = gmdate('Y-m-d', strtotime((string) $line_item->date_created));
|
||||
$date = gmdate('Y-m-d', strtotime($line_item->get_date_created()));
|
||||
|
||||
if ( ! wu_get_isset($data, $date)) {
|
||||
$data[ $date ] = [
|
||||
|
@ -149,7 +149,7 @@ function wu_print_signup_field($field_slug, $field, $results) {
|
||||
|
||||
<script type="text/javascript">
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var requires = <?php echo json_encode($field['requires']); ?>,
|
||||
var requires = <?php echo wp_json_encode($field['requires']); ?>,
|
||||
target_field = document.getElementById('<?php echo $field_slug; ?>-field');
|
||||
|
||||
var display_field = function(target_field, requires, velocity) {
|
||||
|
@ -21,7 +21,7 @@ function wu_convert_to_state($state_array = []) {
|
||||
|
||||
$object = (object) $state_array; // Force object to prevent issues with Vue.
|
||||
|
||||
return json_encode($object);
|
||||
return wp_json_encode($object);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,16 +12,16 @@ defined('ABSPATH') || exit;
|
||||
/**
|
||||
* Get the value of a slugfied network option
|
||||
*
|
||||
* @since 1.9.6
|
||||
* @param string $option_name Option name.
|
||||
* @param mixed $default The default value.
|
||||
* @param mixed $default_value The default value.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function wu_get_option($option_name = 'settings', $default = []) {
|
||||
function wu_get_option($option_name = 'settings', $default_value = []) {
|
||||
|
||||
$option_value = get_network_option(null, wu_slugify($option_name), $default);
|
||||
$option_value = get_network_option(null, wu_slugify($option_name), $default_value);
|
||||
|
||||
return apply_filters('wu_get_option', $option_value, $option_name, $default);
|
||||
return apply_filters('wu_get_option', $option_value, $option_name, $default_value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,15 +45,15 @@ function wu_sort_by_order($a, $b) {
|
||||
*
|
||||
* @since 2.0.7
|
||||
*
|
||||
* @param array $list The list of sortable elements.
|
||||
* @param array $items The list of sortable elements.
|
||||
* @param string $order_key The order key.
|
||||
* @return array
|
||||
*/
|
||||
function wu_set_order_from_index($list, $order_key = 'order') {
|
||||
function wu_set_order_from_index($items, $order_key = 'order') {
|
||||
|
||||
$index = 1;
|
||||
|
||||
foreach ($list as &$item) {
|
||||
foreach ($items as &$item) {
|
||||
if (isset($item[ $order_key ]) === false) {
|
||||
$index = $index ?: 1; // phpcs:ignore
|
||||
|
||||
@ -63,5 +63,5 @@ function wu_set_order_from_index($list, $order_key = 'order') {
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
return $items;
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ defined('ABSPATH') || exit;
|
||||
/**
|
||||
* Converts a string (e.g. 'yes' or 'no' or '1' or '0') to a bool.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @param string $input_string The string to convert.
|
||||
*
|
||||
* @param string $string The string to convert.
|
||||
* @return bool
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function wu_string_to_bool($string) {
|
||||
function wu_string_to_bool($input_string) {
|
||||
|
||||
return is_bool($string) ? $string : ('on' === strtolower($string) || 'yes' === strtolower($string) || 1 === $string || 'true' === strtolower($string) || '1' === $string);
|
||||
return is_bool($input_string) ? $input_string : ('on' === strtolower($input_string) || 'yes' === strtolower($input_string) || 1 === $input_string || 'true' === strtolower($input_string) || '1' === $input_string);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,13 +59,13 @@ function wu_replace_dashes($str) {
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $string String to process.
|
||||
* @param string $str String to process.
|
||||
* @param integer $max_size Number of initials to return.
|
||||
* @return string
|
||||
*/
|
||||
function wu_get_initials($string, $max_size = 2) {
|
||||
function wu_get_initials($str, $max_size = 2) {
|
||||
|
||||
$words = explode(' ', $string);
|
||||
$words = explode(' ', $str);
|
||||
|
||||
$initials = '';
|
||||
|
||||
|
@ -30,20 +30,20 @@ function wu_should_load_sunrise() {
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $setting Setting to get.
|
||||
* @param mixed $default Default value.
|
||||
* @param mixed $default_value Default value.
|
||||
* @return mixed
|
||||
*/
|
||||
function wu_get_setting_early($setting, $default = false) {
|
||||
function wu_get_setting_early($setting, $default_value = false) {
|
||||
|
||||
if (did_action('wp_ultimo_load')) {
|
||||
_doing_it_wrong('wu_get_setting_early', __('Regular setting APIs are already available. You should use wu_get_setting() instead.', 'wp-multisite-waas'), '2.0.0');
|
||||
_doing_it_wrong('wu_get_setting_early', esc_html__('Regular setting APIs are already available. You should use wu_get_setting() instead.', 'wp-multisite-waas'), '2.0.0');
|
||||
}
|
||||
|
||||
$settings_key = \WP_Ultimo\Settings::KEY;
|
||||
|
||||
$settings = get_network_option(null, 'wp-ultimo_' . $settings_key);
|
||||
|
||||
return wu_get_isset($settings, $setting, $default);
|
||||
return wu_get_isset($settings, $setting, $default_value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +59,7 @@ function wu_get_setting_early($setting, $default = false) {
|
||||
function wu_save_setting_early($key, $value) {
|
||||
|
||||
if (did_action('wp_ultimo_load')) {
|
||||
_doing_it_wrong('wu_save_setting_early', __('Regular setting APIs are already available. You should use wu_save_setting() instead.', 'wp-multisite-waas'), '2.0.20');
|
||||
_doing_it_wrong('wu_save_setting_early', esc_html__('Regular setting APIs are already available. You should use wu_save_setting() instead.', 'wp-multisite-waas'), '2.0.20');
|
||||
}
|
||||
|
||||
$settings_key = \WP_Ultimo\Settings::KEY;
|
||||
|
@ -21,10 +21,10 @@ function wu_get_current_url() {
|
||||
* the initiator URL.
|
||||
*/
|
||||
if (wp_doing_ajax() && isset($_SERVER['HTTP_REFERER'])) {
|
||||
return $_SERVER['HTTP_REFERER'];
|
||||
return wp_unslash($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||
return (is_ssl() ? 'https://' : 'http://') . strtolower(wp_unslash($_SERVER['HTTP_HOST'])) . $_SERVER['REQUEST_URI'];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,7 +86,7 @@ function wu_ajax_url($when = null, $query_args = [], $site_id = false, $scheme =
|
||||
$query_args['r'] = wp_create_nonce('wu-ajax-nonce');
|
||||
|
||||
if ($when) {
|
||||
$query_args['wu-when'] = base64_encode($when);
|
||||
$query_args['wu-when'] = base64_encode($when); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
||||
}
|
||||
|
||||
$url = add_query_arg($query_args, $base_url);
|
||||
|
Reference in New Issue
Block a user