mirror of
https://gh.wpcy.net/https://github.com/djav1985/v-wordpress-plugin-updater.git
synced 2026-04-24 04:03:01 +08:00
- Bug #5: Validate REMOTE_ADDR with filter_var before blacklist lookup Prevents invalid/malformed IPs from poisoning blacklist table - Bug #1: Extend blacklist unlock duration from 3 to 7 days Aligns code implementation with documented security policy - Bug #4: Update plugin default API URLs from /plugins/api.php to /api Fixes endpoint mismatch between client and server; applies to both plugin and theme update URLs in Options.php and settings.php defaults - Bug #6: Correct README setup documentation with proper option names Changes vontmnt_api_key to vwpu_update_key; removes non-existent VONTMNT_API_URL constant; adds dashboard widget setup instructions
109 lines
3 KiB
PHP
109 lines
3 KiB
PHP
<?php // phpcs:disable WordPress.Files.FileName.NotHyphenatedLowercase phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
|
/**
|
|
* Project: UpdateAPI
|
|
* Author: Vontainment <services@vontainment.com>
|
|
* License: https://opensource.org/licenses/MIT MIT License
|
|
* Link: https://vontainment.com
|
|
* Version: 2.0.0
|
|
*
|
|
* File: Options.php
|
|
* Description: V WordPress Plugin Updater
|
|
*/
|
|
|
|
namespace VWPU\Helpers;
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Class Options
|
|
*
|
|
* Centralized option management with automatic prefixing and validation.
|
|
*
|
|
* @since 2.0.0
|
|
*/
|
|
class Options {
|
|
|
|
/**
|
|
* Option prefix for all plugin options.
|
|
*
|
|
* @since 2.0.0
|
|
* @var string
|
|
*/
|
|
private const PREFIX = 'vwpu_';
|
|
|
|
/**
|
|
* Get an option value with automatic prefixing.
|
|
*
|
|
* @since 2.0.0
|
|
* @param string $option_key The option key without the prefix.
|
|
* @param mixed $default_value Optional. Default value to return if the option does not exist.
|
|
* @return mixed The option value or default.
|
|
*/
|
|
public static function get( string $option_key, $default_value = '' ) {
|
|
return get_option( self::PREFIX . $option_key, $default_value );
|
|
}
|
|
|
|
/**
|
|
* Set an option value with automatic prefixing.
|
|
*
|
|
* @since 2.0.0
|
|
* @param string $option_key The option key without the prefix.
|
|
* @param mixed $value The value to set.
|
|
* @param bool $autoload Optional. Whether to autoload the option. Default false.
|
|
* @return bool True if option was updated, false otherwise.
|
|
*/
|
|
public static function set( string $option_key, $value, bool $autoload = false ): bool {
|
|
return update_option( self::PREFIX . $option_key, $value, $autoload ? 'yes' : 'no' );
|
|
}
|
|
|
|
/**
|
|
* Delete an option with automatic prefixing.
|
|
*
|
|
* @since 2.0.0
|
|
* @param string $option_key The option key without the prefix.
|
|
* @return bool True if option was deleted, false otherwise.
|
|
*/
|
|
public static function delete( string $option_key ): bool {
|
|
return delete_option( self::PREFIX . $option_key );
|
|
}
|
|
|
|
/**
|
|
* Check if a plugin option is true (with automatic prefixing).
|
|
*
|
|
* @since 2.0.0
|
|
* @param string $option_key Option key without prefix.
|
|
* @return bool True if option is set and truthy.
|
|
*/
|
|
public static function is_true( string $option_key ): bool {
|
|
$value = self::get( $option_key, 'false' );
|
|
if ( is_bool( $value ) ) {
|
|
return $value;
|
|
}
|
|
return filter_var( $value, FILTER_VALIDATE_BOOLEAN );
|
|
}
|
|
|
|
/**
|
|
* Initialize default plugin options.
|
|
*
|
|
* @since 2.0.0
|
|
* @return void
|
|
*/
|
|
public static function initialize_defaults(): void {
|
|
$defaults = array(
|
|
'update_plugins' => 'false',
|
|
'update_themes' => 'false',
|
|
'update_key' => '',
|
|
'update_plugin_url' => 'https://wp-updates.servicesbyv.com/api',
|
|
'update_theme_url' => 'https://wp-updates.servicesbyv.com/api',
|
|
);
|
|
|
|
foreach ( $defaults as $option_name => $default_value ) {
|
|
// Only add if option doesn't exist yet.
|
|
if ( false === get_option( self::PREFIX . $option_name, false ) ) {
|
|
add_option( self::PREFIX . $option_name, $default_value, '', 'no' );
|
|
}
|
|
}
|
|
}
|
|
}
|