Prep Plugin for release on WordPress.org (#23)

* Update translation text domain
* 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.
* Add Proper Build script
* Use emojii flags
* Fix i18n deprecation  notice for translating too early
* Put all scripts in footer and load async
This commit is contained in:
David Stone
2025-04-14 11:36:46 -06:00
committed by GitHub
parent a31cfcb565
commit d88e50df38
1087 changed files with 12586 additions and 18535 deletions

View File

@ -47,8 +47,7 @@ class Arr {
* @param integer $flag The flag determining the return type.
*
* @return mixed
*@since 2.0.11
*
* @since 2.0.11
*/
public static function filter_by_property($array_to_filter, $property, $expected_value, $flag = 0) {
@ -74,8 +73,7 @@ class Arr {
* @param callable $closure The closure function to call.
*
* @return array
*@since 2.0.11
*
* @since 2.0.11
*/
public static function filter($array_to_search, $closure) {
@ -99,13 +97,12 @@ class Arr {
*
* @param array $array_target The array to get the value from.
* @param string $key The array key to get. Supports dot notation.
* @param mixed $default The value to return ibn the case the key does not exist.
* @param mixed $default_value The value to return ibn the case the key does not exist.
*
* @return mixed
*@since 2.0.11
*
* @since 2.0.11
*/
public static function get($array_target, $key, $default = null) {
public static function get($array_target, $key, $default_value = null) {
if (is_null($key)) {
return $array_target;
@ -117,7 +114,7 @@ class Arr {
foreach (explode('.', $key) as $segment) {
if ( ! is_array($array_target) || ! array_key_exists($segment, $array_target)) {
return $default;
return $default_value;
}
$array_target = $array_target[ $segment ];
@ -134,8 +131,7 @@ class Arr {
* @param mixed $value The value to set.
*
* @return array
*@since 2.0.11
*
* @since 2.0.11
*/
public static function set(&$array_to_modify, $key, $value) {

View File

@ -83,7 +83,7 @@ class Screenshot {
* Check if the results contain a PNG header.
*/
if (! str_starts_with($response['body'], "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a")) {
wu_log_add('screenshot-generator', $log_prefix . __('Result is not a PNG file.', 'wp-ultimo'), LogLevel::ERROR);
wu_log_add('screenshot-generator', $log_prefix . __('Result is not a PNG file.', 'wp-multisite-waas'), LogLevel::ERROR);
return false;
}
@ -91,7 +91,7 @@ class Screenshot {
$upload = wp_upload_bits('screenshot-' . gmdate('Y-m-d-H-i-s') . '.png', null, $response['body']);
if ( ! empty($upload['error'])) {
wu_log_add('screenshot-generator', $log_prefix . json_encode($upload['error']), LogLevel::ERROR);
wu_log_add('screenshot-generator', $log_prefix . wp_json_encode($upload['error']), LogLevel::ERROR);
return false;
}
@ -122,7 +122,7 @@ class Screenshot {
// Assign metadata to attachment
wp_update_attachment_metadata($attach_id, $attach_data);
wu_log_add('screenshot-generator', $log_prefix . __('Success!', 'wp-ultimo'));
wu_log_add('screenshot-generator', $log_prefix . __('Success!', 'wp-multisite-waas'));
return $attach_id;
}

View File

@ -56,7 +56,7 @@ class Site_Duplicator {
if (is_wp_error($duplicate_site)) {
// translators: %s id the template site id and %s is the error message returned.
$message = sprintf(__('Attempt to duplicate site %1$d failed: %2$s', 'wp-ultimo'), $from_site_id, $duplicate_site->get_error_message());
$message = sprintf(__('Attempt to duplicate site %1$d failed: %2$s', 'wp-multisite-waas'), $from_site_id, $duplicate_site->get_error_message());
wu_log_add('site-duplication', $message, LogLevel::ERROR);
@ -64,7 +64,7 @@ class Site_Duplicator {
}
// translators: %1$d is the ID of the site template used, and %2$d is the id of the new site.
$message = sprintf(__('Attempt to duplicate site %1$d successful - New site id: %2$d', 'wp-ultimo'), $from_site_id, $duplicate_site);
$message = sprintf(__('Attempt to duplicate site %1$d successful - New site id: %2$d', 'wp-multisite-waas'), $from_site_id, $duplicate_site);
wu_log_add('site-duplication', $message);
@ -108,7 +108,7 @@ class Site_Duplicator {
if (is_wp_error($duplicate_site_id)) {
// translators: %s id the template site id and %s is the error message returned.
$message = sprintf(__('Attempt to override site %1$d with data from site %2$d failed: %3$s', 'wp-ultimo'), $from_site_id, $to_site_id, $duplicate_site_id->get_error_message());
$message = sprintf(__('Attempt to override site %1$d with data from site %2$d failed: %3$s', 'wp-multisite-waas'), $from_site_id, $to_site_id, $duplicate_site_id->get_error_message());
wu_log_add('site-duplication', $message, LogLevel::ERROR);
@ -132,7 +132,7 @@ class Site_Duplicator {
if ($saved) {
// translators: %1$d is the ID of the site template used, and %2$d is the ID of the overriden site.
$message = sprintf(__('Attempt to override site %1$d with data from site %2$d successful.', 'wp-ultimo'), $from_site_id, $duplicate_site_id);
$message = sprintf(__('Attempt to override site %1$d with data from site %2$d successful.', 'wp-multisite-waas'), $from_site_id, $duplicate_site_id);
wu_log_add('site-duplication', $message);
@ -188,7 +188,7 @@ class Site_Duplicator {
$wpdb->hide_errors();
if ( ! $args->from_site_id) {
return new \WP_Error('from_site_id_required', __('You need to provide a valid site to duplicate.', 'wp-ultimo'));
return new \WP_Error('from_site_id_required', __('You need to provide a valid site to duplicate.', 'wp-multisite-waas'));
}
$user_id = ! empty($args->user_id) ? $args->user_id : self::create_admin($args->email, $site_domain);
@ -210,7 +210,7 @@ class Site_Duplicator {
}
if ( ! is_numeric($args->to_site_id)) {
return new \WP_Error('site_creation_failed', __('An attempt to create a new site failed.', 'wp-ultimo'));
return new \WP_Error('site_creation_failed', __('An attempt to create a new site failed.', 'wp-multisite-waas'));
}
if ( ! is_super_admin($user_id) && ! get_user_option('primary_blog', $user_id)) {
@ -274,7 +274,7 @@ class Site_Duplicator {
$user_id = wpmu_create_user($domain, $password, $email);
if (false === $user_id) {
return new \WP_Error('user_creation_error', __('We were not able to create a new admin user for the site being duplicated.', 'wp-ultimo'));
return new \WP_Error('user_creation_error', __('We were not able to create a new admin user for the site being duplicated.', 'wp-multisite-waas'));
} else {
wp_new_user_notification($user_id);
}

View File

@ -64,7 +64,7 @@ class Validator {
public function __construct() {
// translators: %s is the field name.
$field_required_message = sprintf(__('The %s field is required', 'wp-ultimo'), ':attribute');
$field_required_message = sprintf(__('The %s field is required', 'wp-multisite-waas'), ':attribute');
$validation_error_messages = apply_filters(
'wu_validator_error_messages',
@ -73,17 +73,17 @@ class Validator {
'required_without' => $field_required_message,
'required_with' => $field_required_message,
// translators: %s is the email field identifier
'email' => sprintf(__('The %s is not valid email', 'wp-ultimo'), ':attribute'),
'email' => sprintf(__('The %s is not valid email', 'wp-multisite-waas'), ':attribute'),
// translators: 1st %s is the field name; 2nd is the allowed value
'min' => sprintf(__('The %1$s minimum is %2$s', 'wp-ultimo'), ':attribute', ':min'),
'min' => sprintf(__('The %1$s minimum is %2$s', 'wp-multisite-waas'), ':attribute', ':min'),
// translators: 1st %s is the field name; 2nd is the allowed value
'max' => sprintf(__('The %1$s maximum is %2$s', 'wp-ultimo'), ':attribute', ':max'),
'max' => sprintf(__('The %1$s maximum is %2$s', 'wp-multisite-waas'), ':attribute', ':max'),
// translators: %s is the field identifier
'alpha_dash' => sprintf(__('The %s only allows a-z, 0-9, _ and -', 'wp-ultimo'), ':attribute'),
'alpha_dash' => sprintf(__('The %s only allows a-z, 0-9, _ and -', 'wp-multisite-waas'), ':attribute'),
// translators: %s is the field identifier
'lowercase' => sprintf(__('The %s must be lowercase', 'wp-ultimo'), ':attribute'),
'lowercase' => sprintf(__('The %s must be lowercase', 'wp-multisite-waas'), ':attribute'),
// translators: %s is the field identifier
'integer' => sprintf(__('The %s must be integer', 'wp-ultimo'), ':attribute'),
'integer' => sprintf(__('The %s must be integer', 'wp-multisite-waas'), ':attribute'),
],
$this
);
@ -92,8 +92,8 @@ class Validator {
$this->validator->setTranslations(
[
'and' => __('and', 'wp-ultimo'),
'or' => __('or', 'wp-ultimo'),
'and' => __('and', 'wp-multisite-waas'),
'or' => __('or', 'wp-multisite-waas'),
]
);

View File

@ -37,7 +37,7 @@ class WP_Config {
if ( ! is_writable($config_path)) {
// translators: %s is the file name.
return new \WP_Error('not-writeable', sprintf(__('The file %s is not writable', 'wp-ultimo'), $config_path));
return new \WP_Error('not-writeable', sprintf(__('The file %s is not writable', 'wp-multisite-waas'), $config_path));
}
$config = file($config_path);
@ -52,7 +52,7 @@ class WP_Config {
$hook_line = $this->find_reference_hook_line($config);
if (false === $hook_line) {
return new \WP_Error('unknown-wpconfig', __("WP Multisite WaaS can't recognize your wp-config.php, please revert it to original state for further process.", 'wp-ultimo'));
return new \WP_Error('unknown-wpconfig', __("WP Multisite WaaS can't recognize your wp-config.php, please revert it to original state for further process.", 'wp-multisite-waas'));
}
$config = $this->inject_contents($config, $hook_line + 1, PHP_EOL . $content . PHP_EOL);
@ -180,7 +180,7 @@ class WP_Config {
if ( ! is_writable($config_path)) {
// translators: %s is the file name.
return new \WP_Error('not-writeable', sprintf(__('The file %s is not writable', 'wp-ultimo'), $config_path));
return new \WP_Error('not-writeable', sprintf(__('The file %s is not writable', 'wp-multisite-waas'), $config_path));
}
$config = file($config_path);

View File

@ -75,7 +75,7 @@ class Checkout_Steps extends Rule {
foreach ($required_fields_list as $field_slug) {
if (! in_array($field_slug, $all_fields_list, true)) {
$this->message = sprintf(__('The %s field must be present in at least one of the checkout form steps.', 'wp-ultimo'), wu_slug_to_name($field_slug));
$this->message = sprintf(__('The %s field must be present in at least one of the checkout form steps.', 'wp-multisite-waas'), wu_slug_to_name($field_slug));
return false;
}
@ -111,7 +111,7 @@ class Checkout_Steps extends Rule {
);
if (empty($found_submittable_field_types)) {
$this->message = sprintf(__('The %s step is missing a submit field', 'wp-ultimo'), $step['name']);
$this->message = sprintf(__('The %s step is missing a submit field', 'wp-multisite-waas'), $step['name']);
return false;
}

View File

@ -55,7 +55,7 @@ class Products extends Rule {
return true;
}
$this->message = __('A plan is required.', 'wp-ultimo');
$this->message = __('A plan is required.', 'wp-multisite-waas');
return false;
}

View File

@ -56,14 +56,14 @@ class Site_Template extends Rule {
$site = wu_get_site($template_id);
if (! $site || ($site->get_type() !== Site_Type::SITE_TEMPLATE && $site->get_type() !== Site_Type::CUSTOMER_OWNED)) {
$this->message = __('The Template ID does not correspond to a valid Template', 'wp-ultimo');
$this->message = __('The Template ID does not correspond to a valid Template', 'wp-multisite-waas');
return false;
}
if ($site->get_type() === Site_Type::CUSTOMER_OWNED) {
if (! wu_get_setting('allow_own_site_as_template')) {
$this->message = __('You can not use your sites as template', 'wp-ultimo');
$this->message = __('You can not use your sites as template', 'wp-multisite-waas');
return false;
}
@ -71,7 +71,7 @@ class Site_Template extends Rule {
$customer = wu_get_current_customer();
if (! $customer || $site->get_customer_id() !== $customer->get_id()) {
$this->message = __('The selected template is not available.', 'wp-ultimo');
$this->message = __('The selected template is not available.', 'wp-multisite-waas');
return false;
}
@ -103,7 +103,7 @@ class Site_Template extends Rule {
if (is_array($allowed_templates) && !in_array($template_id, $allowed_templates)) { // phpcs:ignore
$this->message = __('The selected template is not available for this product.', 'wp-ultimo');
$this->message = __('The selected template is not available for this product.', 'wp-multisite-waas');
return false;
}

View File

@ -46,6 +46,9 @@ class Unique extends Rule {
*/
public function check($value): bool {
if (empty($value)) {
return true;
}
$this->requireParameters(
[
'model',
@ -78,7 +81,7 @@ class Unique extends Rule {
* Customize the error message for the customer.
*/
if (in_array($model, $user_models, true)) {
$this->message = __('A customer with the same email address or username already exists.', 'wp-ultimo');
$this->message = __('A customer with the same email address or username already exists.', 'wp-multisite-waas');
}
if ( ! $existing) {