updated plugin Simple Local Avatars version 2.8.3

This commit is contained in:
2025-04-29 21:20:02 +00:00
committed by Gitium
parent fd76ba0cbe
commit c950632407
122 changed files with 5001 additions and 115 deletions

View File

@ -0,0 +1,22 @@
#!/bin/bash
# Script directory and filename
SCRIPT_DIR="$(dirname "$0")"
SCRIPT_NAME="$(basename "$0")"
# Check for the required argument
if [ "$#" -ne 1 ]; then
echo "Usage: $0 New_Namespace"
exit 1
fi
NEW_NAMESPACE="$1"
# Use find to get all files recursively from the script's directory, excluding the script itself
find "$SCRIPT_DIR" -type f \( -name "*.php" -o -name "*.json" \) ! -name "$SCRIPT_NAME" | while read -r file; do
echo $file
# Use perl for the replacement in each file
perl -pi -e "s/WP_Compat_Validation_Tool/$NEW_NAMESPACE/g" "$file"
done
cd 10up-lib/wp-compat-validation-tool && rm -rf .git .github .gitignore composer.json composer.lock CHANGELOG.md CONTRIBUTING.md README.md LICENSE.md CODE_OF_CONDUCT.md CREDITS.md

View File

@ -0,0 +1,169 @@
<?php
namespace SimpleLocalAvatarsValidator;
class Validator {
/**
* Array of checks.
*
* @var array
*/
private $checklist = array();
/**
* Array of error messages
*
* @var string[]
*/
private $messages = array();
/**
* Constructor function.
*/
public function __construct() {
$this->checklist = array(
'plugin_name' => array(
'value' => '',
'required' => true,
),
'php_min_required_version' => array(
'value' => '',
'required' => false,
),
'php_max_required_version' => array(
'value' => '',
'required' => false,
),
'wp_min_required_version' => array(
'value' => '',
'required' => false,
),
'wp_max_required_version' => array(
'value' => '',
'required' => false,
),
);
}
/**
* Sets the plugin name.
*
* @param string $value Plugin name.
* @return Validator
*/
public function set_plugin_name( $value = '' ) {
$this->checklist['plugin_name']['value'] = $value;
return $this;
}
/**
* Sets the minimum PHP version supported by a plugin.
*
* @param string $value Minimum PHP version.
* @return Validator
*/
public function set_php_min_required_version( $value = '' ) {
$this->checklist['php_min_required_version']['value'] = $value;
return $this;
}
/**
* Sets the maximum PHP version supported by a plugin.
*
* @param string $value Maximum PHP version.
* @return Validator
*/
public function set_php_max_required_version( $value = '' ) {
$this->checklist['php_max_required_version']['value'] = $value;
return $this;
}
/**
* Sets the minimum WordPress version supported by a plugin.
*
* @param string $value Minimum WordPress version.
* @return Validator
*/
public function set_wordpress_min_required_version( $value = '' ) {
$this->checklist['wp_min_required_version']['value'] = $value;
return $this;
}
/**
* Sets the maximum WordPress version supported by a plugin.
*
* @param string $value Maximum WordPress version.
* @return Validator
*/
public function set_wordpress_max_required_version( $value = '' ) {
$this->checklist['wp_max_required_version']['value'] = $value;
return $this;
}
/**
* Returns true if the plugin meets all compatibility checks, false otherwise.
*
* @return boolean
*/
public function is_plugin_compatible() {
foreach ( $this->checklist as $item_name => $item_details ) {
if ( $item_details['required'] && empty( $item_details['value'] ) ) {
return false;
}
switch ( $item_name ) {
case 'php_min_required_version':
if ( ! empty( $item_details['value'] ) && version_compare( phpversion(), $item_details['value'], '<' ) ) {
$this->messages[] = sprintf( esc_html__( 'The minimum PHP version required is %s' ), $item_details['value'] );
}
break;
case 'php_max_required_version':
if ( ! empty( $item_details['value'] ) && version_compare( phpversion(), $item_details['value'], '>' ) ) {
$this->messages[] = sprintf( esc_html__( 'The maximum PHP version supported is %s' ), $item_details['value'] );
}
break;
default:
break;
}
}
if ( ! empty( $this->messages ) ) {
add_action( 'admin_notices', array( $this, 'render_php_compat_error' ) );
return false;
}
return true;
}
/**
* Renders the error messages as notice.
*/
public function render_php_compat_error() {
?>
<div class="notice notice-error">
<p>
<strong>
<?php printf( esc_html__( '%s error:' ), $this->checklist['plugin_name']['value'] ); ?>
</strong>
</p>
<?php if ( count( $this->messages ) > 1 ) : ?>
<ul>
<?php foreach ( $this->messages as $message ) : ?>
<li><?php echo esc_html( $message ); ?></li>
<?php endforeach; ?>
</ul>
<?php elseif ( 1 === count( $this->messages ) ): ?>
<p>
<?php echo esc_html( $this->messages[0] ); ?>
</p>
<?php endif; ?>
</div>
<?php
}
}