Use PHP 7.4 featers and PHP 8 polyfills
This commit is contained in:
@ -28,13 +28,13 @@ class Customer_User_Role_Limits {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
public function init(): void {
|
||||
|
||||
add_action('in_admin_header', array($this, 'block_new_user_page'));
|
||||
add_action('in_admin_header', [$this, 'block_new_user_page']);
|
||||
|
||||
add_action('wu_async_after_membership_update_products', array($this, 'update_site_user_roles'));
|
||||
add_action('wu_async_after_membership_update_products', [$this, 'update_site_user_roles']);
|
||||
|
||||
add_filter('editable_roles', array($this, 'filter_editable_roles'));
|
||||
add_filter('editable_roles', [$this, 'filter_editable_roles']);
|
||||
|
||||
if ( ! wu_get_current_site()->has_module_limitation('customer_user_role')) {
|
||||
return;
|
||||
@ -46,7 +46,7 @@ class Customer_User_Role_Limits {
|
||||
*
|
||||
* @since 2.0.20
|
||||
*/
|
||||
public function block_new_user_page() {
|
||||
public function block_new_user_page(): void {
|
||||
|
||||
if (is_super_admin()) {
|
||||
return;
|
||||
@ -71,7 +71,7 @@ class Customer_User_Role_Limits {
|
||||
*/
|
||||
$message = apply_filters('wu_users_membership_limit_message', $message);
|
||||
|
||||
wp_die($message, __('Limit Reached', 'wp-ultimo'), array('back_link' => true));
|
||||
wp_die($message, __('Limit Reached', 'wp-ultimo'), ['back_link' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +94,7 @@ class Customer_User_Role_Limits {
|
||||
$limit = $users_limitation->{$role};
|
||||
|
||||
if (property_exists($limit, 'enabled') && $limit->enabled) {
|
||||
$user_list = get_users(array('role' => $role));
|
||||
$user_list = get_users(['role' => $role]);
|
||||
|
||||
$count = (int) count($user_list);
|
||||
|
||||
@ -119,7 +119,7 @@ class Customer_User_Role_Limits {
|
||||
* @param int $membership_id The membership upgraded or downgraded.
|
||||
* @return void
|
||||
*/
|
||||
public function update_site_user_roles($membership_id) {
|
||||
public function update_site_user_roles($membership_id): void {
|
||||
|
||||
$membership = wu_get_membership($membership_id);
|
||||
|
||||
|
@ -45,11 +45,11 @@ class Disk_Space_Limits {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
public function init(): void {
|
||||
|
||||
add_filter('site_option_upload_space_check_disabled', array($this, 'upload_space_check_disabled'));
|
||||
add_filter('site_option_upload_space_check_disabled', [$this, 'upload_space_check_disabled']);
|
||||
|
||||
add_filter('get_space_allowed', array($this, 'apply_disk_space_limitations'));
|
||||
add_filter('get_space_allowed', [$this, 'apply_disk_space_limitations']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,9 +43,9 @@ class Plugin_Limits {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
public function init(): void {
|
||||
|
||||
add_action('wu_sunrise_loaded', array($this, 'load_limitations'));
|
||||
add_action('wu_sunrise_loaded', [$this, 'load_limitations']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,27 +54,27 @@ class Plugin_Limits {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function load_limitations() {
|
||||
public function load_limitations(): void {
|
||||
|
||||
if (wu_get_current_site()->has_limitations()) {
|
||||
add_filter('site_option_active_sitewide_plugins', array($this, 'deactivate_network_plugins'));
|
||||
add_filter('site_option_active_sitewide_plugins', [$this, 'deactivate_network_plugins']);
|
||||
|
||||
add_filter('option_active_plugins', array($this, 'deactivate_plugins'));
|
||||
add_filter('option_active_plugins', [$this, 'deactivate_plugins']);
|
||||
|
||||
add_filter('all_plugins', array($this, 'clear_plugin_list'));
|
||||
add_filter('all_plugins', [$this, 'clear_plugin_list']);
|
||||
|
||||
add_filter('the_content', array($this, 'clean_unused_shortcodes'), 9999);
|
||||
add_filter('the_content', [$this, 'clean_unused_shortcodes'], 9999);
|
||||
|
||||
add_filter('plugin_action_links', array($this, 'clear_actions'), -2000, 2);
|
||||
add_filter('plugin_action_links', [$this, 'clear_actions'], -2000, 2);
|
||||
|
||||
add_filter('show_network_active_plugins', '__return_true');
|
||||
|
||||
add_action('load-plugins.php', array($this, 'admin_page_hooks'));
|
||||
add_action('load-plugins.php', [$this, 'admin_page_hooks']);
|
||||
}
|
||||
|
||||
add_action('wu_site_post_save', array($this, 'activate_and_inactive_plugins'), 10, 3);
|
||||
add_action('wu_site_post_save', [$this, 'activate_and_inactive_plugins'], 10, 3);
|
||||
|
||||
add_action('wu_checkout_done', array($this, 'maybe_activate_and_inactive_plugins'), 10, 5);
|
||||
add_action('wu_checkout_done', [$this, 'maybe_activate_and_inactive_plugins'], 10, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,7 +83,7 @@ class Plugin_Limits {
|
||||
* @since 2.0.5
|
||||
* @return void
|
||||
*/
|
||||
public function admin_page_hooks() {
|
||||
public function admin_page_hooks(): void {
|
||||
add_action('admin_enqueue_scripts', 'add_wubox');
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ class Plugin_Limits {
|
||||
* @param bool $new_site If this site is a new one.
|
||||
* @return void
|
||||
*/
|
||||
public function activate_and_inactive_plugins($data, $site_object, $new_site) {
|
||||
public function activate_and_inactive_plugins($data, $site_object, $new_site): void {
|
||||
if ($site_object && $new_site) {
|
||||
$site_object->sync_plugins();
|
||||
}
|
||||
@ -115,7 +115,7 @@ class Plugin_Limits {
|
||||
* @param string $type The cart type.
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_activate_and_inactive_plugins($payment, $membership, $customer, $cart, $type) {
|
||||
public function maybe_activate_and_inactive_plugins($payment, $membership, $customer, $cart, $type): void {
|
||||
if ('new' !== $type && $membership) {
|
||||
$membership->sync_plugins();
|
||||
}
|
||||
@ -155,10 +155,10 @@ class Plugin_Limits {
|
||||
$upgrade = sprintf(
|
||||
'<a href="%s" class="wu-styling" title="%s"><span class="dashicons-wu-lock1 wu-mr-1"></span>%s</a>',
|
||||
wu_generate_upgrade_to_unlock_url(
|
||||
array(
|
||||
[
|
||||
'module' => 'plugins',
|
||||
'type' => $plugin_file,
|
||||
)
|
||||
]
|
||||
),
|
||||
__('Upgrade to unlock', 'wp-ultimo'),
|
||||
__('Upgrade to unlock', 'wp-ultimo')
|
||||
@ -196,7 +196,7 @@ class Plugin_Limits {
|
||||
unset($plugins[ $plugin_slug ]);
|
||||
}
|
||||
|
||||
if (strncmp($plugin_slug, 'wp-ultimo', strlen('wp-ultimo')) === 0) {
|
||||
if (str_starts_with($plugin_slug, 'wp-ultimo')) {
|
||||
unset($plugins[ $plugin_slug ]);
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ class Plugin_Limits {
|
||||
$plugin_limits = wu_get_current_site()->get_limitations()->plugins;
|
||||
|
||||
foreach ($plugins as $plugin_slug => $timestamp) {
|
||||
if (strpos($plugin_slug, 'wp-ultimo') !== false) {
|
||||
if (str_contains($plugin_slug, 'wp-ultimo')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -289,7 +289,7 @@ class Plugin_Limits {
|
||||
$plugin_limits = wu_get_current_site()->get_limitations()->plugins;
|
||||
|
||||
foreach ($plugins as $plugin_slug) {
|
||||
if (strpos((string) $plugin_slug, 'wp-ultimo') !== false) {
|
||||
if (str_contains((string) $plugin_slug, 'wp-ultimo')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class Post_Type_Limits {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
public function init(): void {
|
||||
|
||||
/**
|
||||
* Emulated post types.
|
||||
@ -36,7 +36,7 @@ class Post_Type_Limits {
|
||||
* @since 2.0.6
|
||||
*/
|
||||
if (is_main_site() && is_network_admin()) {
|
||||
add_action('init', array($this, 'register_emulated_post_types'), 999);
|
||||
add_action('init', [$this, 'register_emulated_post_types'], 999);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,15 +57,15 @@ class Post_Type_Limits {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action('load-post-new.php', array($this, 'limit_posts'));
|
||||
add_action('load-post-new.php', [$this, 'limit_posts']);
|
||||
|
||||
add_filter('wp_handle_upload', array($this, 'limit_media'));
|
||||
add_filter('wp_handle_upload', [$this, 'limit_media']);
|
||||
|
||||
add_filter('media_upload_tabs', array($this, 'limit_tabs'));
|
||||
add_filter('media_upload_tabs', [$this, 'limit_tabs']);
|
||||
|
||||
add_action('current_screen', array($this, 'limit_restoring'), 10);
|
||||
add_action('current_screen', [$this, 'limit_restoring'], 10);
|
||||
|
||||
add_filter('wp_insert_post_data', array($this, 'limit_draft_publishing'), 10, 2);
|
||||
add_filter('wp_insert_post_data', [$this, 'limit_draft_publishing'], 10, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,9 +74,9 @@ class Post_Type_Limits {
|
||||
* @since 2.0.6
|
||||
* @return void
|
||||
*/
|
||||
public function register_emulated_post_types() {
|
||||
public function register_emulated_post_types(): void {
|
||||
|
||||
$emulated_post_types = wu_get_setting('emulated_post_types', array());
|
||||
$emulated_post_types = wu_get_setting('emulated_post_types', []);
|
||||
|
||||
if (is_array($emulated_post_types) && ! empty($emulated_post_types)) {
|
||||
foreach ($emulated_post_types as $pt) {
|
||||
@ -90,7 +90,7 @@ class Post_Type_Limits {
|
||||
|
||||
register_post_type(
|
||||
$pt->post_type,
|
||||
array(
|
||||
[
|
||||
'label' => $pt->label,
|
||||
'exclude_from_search' => true,
|
||||
'public' => true,
|
||||
@ -98,7 +98,7 @@ class Post_Type_Limits {
|
||||
'has_archive' => false,
|
||||
'can_export' => false,
|
||||
'delete_with_user' => false,
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -110,7 +110,7 @@ class Post_Type_Limits {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function limit_restoring() {
|
||||
public function limit_restoring(): void {
|
||||
|
||||
if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'untrash') {
|
||||
$this->limit_posts();
|
||||
@ -123,7 +123,7 @@ class Post_Type_Limits {
|
||||
* @since 1.0.0
|
||||
* @since 1.5.4 Checks for blocked post types
|
||||
*/
|
||||
public function limit_posts() {
|
||||
public function limit_posts(): void {
|
||||
|
||||
if (is_main_site()) {
|
||||
return;
|
||||
@ -135,7 +135,7 @@ class Post_Type_Limits {
|
||||
$upgrade_message = __('Your plan does not support this post type.', 'wp-ultimo');
|
||||
|
||||
// translators: %s is the URL.
|
||||
wp_die($upgrade_message, __('Limit Reached', 'wp-ultimo'), array('back_link' => true));
|
||||
wp_die($upgrade_message, __('Limit Reached', 'wp-ultimo'), ['back_link' => true]);
|
||||
}
|
||||
|
||||
// Check if that is more than our limit
|
||||
@ -143,7 +143,7 @@ class Post_Type_Limits {
|
||||
$upgrade_message = __('You reached your plan\'s post limit.', 'wp-ultimo');
|
||||
|
||||
// translators: %s is the URL
|
||||
wp_die($upgrade_message, __('Limit Reached', 'wp-ultimo'), array('back_link' => true));
|
||||
wp_die($upgrade_message, __('Limit Reached', 'wp-ultimo'), ['back_link' => true]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ class Post_Type_Limits {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$post_type = isset($data['post_type']) ? $data['post_type'] : 'post';
|
||||
$post_type = $data['post_type'] ?? 'post';
|
||||
|
||||
$post_type_limits = wu_get_current_site()->get_limitations()->post_types;
|
||||
|
||||
|
@ -30,9 +30,9 @@ class Site_Template_Limits {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
public function init(): void {
|
||||
|
||||
add_action('plugins_loaded', array($this, 'setup'));
|
||||
add_action('plugins_loaded', [$this, 'setup']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,13 +41,13 @@ class Site_Template_Limits {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function setup() {
|
||||
public function setup(): void {
|
||||
|
||||
add_filter('wu_template_selection_render_attributes', array($this, 'maybe_filter_template_selection_options'));
|
||||
add_filter('wu_template_selection_render_attributes', [$this, 'maybe_filter_template_selection_options']);
|
||||
|
||||
add_filter('wu_checkout_template_id', array($this, 'maybe_force_template_selection'), 10, 2);
|
||||
add_filter('wu_checkout_template_id', [$this, 'maybe_force_template_selection'], 10, 2);
|
||||
|
||||
add_filter('wu_cart_get_extra_params', array($this, 'maybe_force_template_selection_on_cart'), 10, 2);
|
||||
add_filter('wu_cart_get_extra_params', [$this, 'maybe_force_template_selection_on_cart'], 10, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,16 +62,16 @@ class Site_Template_Limits {
|
||||
|
||||
$attributes['should_display'] = true;
|
||||
|
||||
$products = array_map('wu_get_product', wu_get_isset($attributes, 'products', array()));
|
||||
$products = array_map('wu_get_product', wu_get_isset($attributes, 'products', []));
|
||||
|
||||
$products = array_filter($products);
|
||||
|
||||
if ( ! empty($products)) {
|
||||
$limits = new \WP_Ultimo\Objects\Limitations();
|
||||
|
||||
list($plan, $additional_products) = wu_segregate_products($products);
|
||||
[$plan, $additional_products] = wu_segregate_products($products);
|
||||
|
||||
$products = array_merge(array($plan), $additional_products);
|
||||
$products = array_merge([$plan], $additional_products);
|
||||
|
||||
foreach ($products as $product) {
|
||||
$limits = $limits->merge($product->get_limitations());
|
||||
@ -127,9 +127,9 @@ class Site_Template_Limits {
|
||||
|
||||
$products = $cart->get_all_products();
|
||||
|
||||
list($plan, $additional_products) = wu_segregate_products($products);
|
||||
[$plan, $additional_products] = wu_segregate_products($products);
|
||||
|
||||
$products = array_merge(array($plan), $additional_products);
|
||||
$products = array_merge([$plan], $additional_products);
|
||||
|
||||
$products = array_filter($products);
|
||||
|
||||
@ -162,9 +162,9 @@ class Site_Template_Limits {
|
||||
if ( ! empty($products)) {
|
||||
$limits = new \WP_Ultimo\Objects\Limitations();
|
||||
|
||||
list($plan, $additional_products) = wu_segregate_products($products);
|
||||
[$plan, $additional_products] = wu_segregate_products($products);
|
||||
|
||||
$products = array_merge(array($plan), $additional_products);
|
||||
$products = array_merge([$plan], $additional_products);
|
||||
|
||||
foreach ($products as $product) {
|
||||
$limits = $limits->merge($product->get_limitations());
|
||||
|
@ -27,7 +27,7 @@ class Theme_Limits {
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $themes_not_available = array();
|
||||
protected $themes_not_available = [];
|
||||
|
||||
/**
|
||||
* Keep a cache of the results as the check is costly.
|
||||
@ -51,7 +51,7 @@ class Theme_Limits {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
public function init(): void {
|
||||
|
||||
/**
|
||||
* We need to bail if we're inside the WP CLI context and the
|
||||
@ -68,7 +68,7 @@ class Theme_Limits {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action('wu_sunrise_loaded', array($this, 'load_limitations'));
|
||||
add_action('wu_sunrise_loaded', [$this, 'load_limitations']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,24 +77,24 @@ class Theme_Limits {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function load_limitations() {
|
||||
public function load_limitations(): void {
|
||||
|
||||
if (wu_get_current_site()->has_limitations()) {
|
||||
add_filter('stylesheet', array($this, 'force_active_theme_stylesheet'));
|
||||
add_filter('stylesheet', [$this, 'force_active_theme_stylesheet']);
|
||||
|
||||
add_filter('template', array($this, 'force_active_theme_template'));
|
||||
add_filter('template', [$this, 'force_active_theme_template']);
|
||||
|
||||
add_filter('allowed_themes', array($this, 'add_extra_available_themes'));
|
||||
add_filter('allowed_themes', [$this, 'add_extra_available_themes']);
|
||||
|
||||
add_filter('site_allowed_themes', array($this, 'add_extra_available_themes'));
|
||||
add_filter('site_allowed_themes', [$this, 'add_extra_available_themes']);
|
||||
|
||||
add_filter('wp_prepare_themes_for_js', array($this, 'maybe_remove_activate_button'));
|
||||
add_filter('wp_prepare_themes_for_js', [$this, 'maybe_remove_activate_button']);
|
||||
|
||||
add_action('admin_enqueue_scripts', array($this, 'hacky_remove_activate_button'));
|
||||
add_action('admin_enqueue_scripts', [$this, 'hacky_remove_activate_button']);
|
||||
|
||||
add_action('admin_footer-themes.php', array($this, 'modify_backbone_template'));
|
||||
add_action('admin_footer-themes.php', [$this, 'modify_backbone_template']);
|
||||
|
||||
add_action('customize_changeset_save_data', array($this, 'prevent_theme_activation_on_customizer'), 99, 2);
|
||||
add_action('customize_changeset_save_data', [$this, 'prevent_theme_activation_on_customizer'], 99, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,10 +124,10 @@ class Theme_Limits {
|
||||
$theme_limitations = wu_get_current_site()->get_limitations()->themes;
|
||||
|
||||
if ($theme_limitations->allowed($new_theme, 'not_available')) {
|
||||
$response = array(
|
||||
$response = [
|
||||
'code' => 'not-available',
|
||||
'message' => __('This theme is not available on your current plan.', 'wp-ultimo'),
|
||||
);
|
||||
];
|
||||
|
||||
wp_send_json($response, 'not-available');
|
||||
|
||||
@ -149,7 +149,7 @@ class Theme_Limits {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function hacky_remove_activate_button() {
|
||||
public function hacky_remove_activate_button(): void {
|
||||
|
||||
global $pagenow;
|
||||
|
||||
@ -169,20 +169,20 @@ class Theme_Limits {
|
||||
|
||||
$upgrade_button = wu_generate_upgrade_to_unlock_button(
|
||||
__('Upgrade to unlock', 'wp-ultimo'),
|
||||
array(
|
||||
[
|
||||
'module' => 'themes',
|
||||
'type' => 'EXTENSION',
|
||||
'classes' => 'button',
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'theme',
|
||||
'wu_theme_settings',
|
||||
array(
|
||||
[
|
||||
'themes_not_available' => $this->themes_not_available,
|
||||
'replacement_message' => $upgrade_button,
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ class Theme_Limits {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function modify_backbone_template() { // phpcs:disable ?>
|
||||
public function modify_backbone_template(): void { // phpcs:disable ?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
@ -266,7 +266,7 @@ class Theme_Limits {
|
||||
|
||||
$forced_stylesheet = $this->get_forced_theme_stylesheet();
|
||||
|
||||
return $forced_stylesheet ? $forced_stylesheet : $stylesheet;
|
||||
return $forced_stylesheet ?: $stylesheet;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -285,7 +285,7 @@ class Theme_Limits {
|
||||
|
||||
$forced_template = $this->get_forced_theme_template();
|
||||
|
||||
return $forced_template ? $forced_template : $template;
|
||||
return $forced_template ?: $template;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user