Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,349 @@
<?php
/**
* The Beta Opt-in functionality.
*
* @package RankMath
* @subpackage RankMath\Version_Control
*/
namespace RankMath;
use RankMath\Traits\Hooker;
use RankMath\Helpers\Str;
use RankMath\Helpers\Param;
defined( 'ABSPATH' ) || exit;
/**
* Beta_Optin class.
*/
class Beta_Optin {
use Hooker;
/**
* Beta changelog URL.
*
* @var string
*/
const BETA_CHANGELOG_URL = 'https://rankmath.com/changelog/beta/';
/**
* Placeholder for opening tag inserted with JS.
*
* @var string
*/
const NOTICE_START_MARKER = '&#x25B7;';
/**
* Placeholder for closing tag inserted with JS.
*
* @var string
*/
const NOTICE_END_MARKER = '&#x25C1;';
/**
* Holds the fetched trunk version in memory to avoid fetching multiple times.
*
* @var mixed
*/
public $trunk_version = false;
/**
* Actions and filters.
*
* @return void
*/
public function hooks() {
$this->filter( 'site_transient_update_plugins', 'transient_update_plugins' );
$this->action( 'in_plugin_update_message-seo-by-rank-math/rank-math.php', 'plugin_update_message' );
$this->action( 'install_plugins_pre_plugin-information', 'beta_plugin_information' );
$this->action( 'admin_footer', 'beta_changelog_link_js' );
}
/**
* Replace plugin info popup for beta versions.
*/
public function beta_plugin_information() {
if ( 'seo-by-rank-math' !== Param::request( 'plugin' ) ) {
return;
}
$transient = get_site_transient( 'update_plugins' );
if ( self::has_beta_update( $transient ) ) {
// No-js fallback.
echo '<html><head></head><body style="margin: 0;"><iframe src="' . esc_attr( self::BETA_CHANGELOG_URL ) . '" style="width: 100%; height: 100%;"></body></html>';
exit;
}
}
/**
* Check if Rank Math update is a beta update in the transient.
*
* @param mixed $transient Transient value.
* @return boolean If it is a beta update or not.
*/
public static function has_beta_update( $transient ) {
return (
is_object( $transient )
&& ! empty( $transient->response )
&& ! empty( $transient->response['seo-by-rank-math/rank-math.php'] )
&& ! empty( $transient->response['seo-by-rank-math/rank-math.php']->is_beta )
);
}
/**
* Get all available versions of Rank Math.
*
* @param boolean $beta Include beta versions.
*
* @return array List of versions and download URLs.
*/
public static function get_available_versions( $beta = false ) {
$versions = [];
$plugin_info = Version_Control::get_plugin_info();
if ( empty( $plugin_info['versions'] ) ) {
return $versions;
}
foreach ( (array) $plugin_info['versions'] as $version => $url ) {
if ( ! self::is_eligible_version( $version, $beta ) ) {
continue;
}
$versions[ $version ] = $url;
}
uksort( $versions, 'version_compare' );
return $versions;
}
/**
* Check if version should be in the dropdown.
*
* @param string $version Version number.
* @param boolean $beta If beta versions should be included or not.
*
* @return boolean If version should be in the dropdown.
*/
public static function is_eligible_version( $version, $beta ) {
if ( 'trunk' === $version ) {
return false;
}
if ( ! $beta && Str::contains( 'beta', $version ) ) {
return false;
}
return true;
}
/**
* Get latest version available.
*
* @return string Latest version number.
*/
public static function get_latest_version() {
$plugin_info = Version_Control::get_plugin_info();
return $plugin_info['version'];
}
/**
* Get latest beta version available.
*
* @return string Latest beta version number.
*/
public function get_latest_beta_version() {
$version = get_transient( 'rank_math_trunk_version' );
if ( ! $version || $this->is_check_requested() ) {
$version = $this->fetch_trunk_version();
}
$beta = 0;
if ( Str::contains( 'beta', $version ) ) {
$beta = $version;
}
return $beta;
}
/**
* Fetch latest plugin file from public SVN and get version number.
*
* @return string
*/
public function fetch_trunk_version() {
if ( false !== $this->trunk_version ) {
return $this->trunk_version;
}
$this->trunk_version = 0;
$response = wp_remote_get( 'https://plugins.svn.wordpress.org/seo-by-rank-math/trunk/rank-math.php' );
if ( is_wp_error( $response ) || ! is_array( $response ) ) {
return $this->trunk_version;
}
$plugin_file = wp_remote_retrieve_body( $response );
preg_match( '/Version:\s+([0-9a-zA-Z.-]+)\s*$/m', $plugin_file, $matches );
if ( empty( $matches[1] ) ) {
return $this->trunk_version;
}
$this->trunk_version = $matches[1];
set_transient( 'rank_math_trunk_version', $this->trunk_version, ( 12 * HOUR_IN_SECONDS ) );
return $this->trunk_version;
}
/**
* Inject beta in the `update_plugins` transient to be able to update to it.
*
* @param mixed $value Original value.
*
* @return mixed New value.
*/
public function transient_update_plugins( $value ) {
$beta_version = $this->get_latest_beta_version();
$new_version = isset( $value->response['seo-by-rank-math/rank-math.php'] ) && ! empty( $value->response['seo-by-rank-math/rank-math.php']->new_version ) ? $value->response['seo-by-rank-math/rank-math.php']->new_version : 0;
if ( ! $beta_version ) {
return $value;
}
if ( version_compare( $beta_version, rank_math()->version, '>' ) && version_compare( $beta_version, $new_version, '>' ) ) {
$value = $this->inject_beta( $value, $beta_version );
}
return $value;
}
/**
* Inject beta update in the transient value.
*
* @param mixed $value Transient value.
* @param string $beta_version Beta version number.
*
* @return mixed New transient value.
*/
public function inject_beta( $value, $beta_version ) {
if ( empty( $value ) ) {
$value = new \stdClass();
}
if ( empty( $value->response ) ) {
$value->response = [];
}
$value->response['seo-by-rank-math/rank-math.php'] = new \stdClass();
$plugin_data = Version_Control::get_plugin_data( $beta_version, 'https://downloads.wordpress.org/plugin/seo-by-rank-math.zip' );
foreach ( $plugin_data as $prop_key => $prop_value ) {
$value->response['seo-by-rank-math/rank-math.php']->{$prop_key} = $prop_value;
}
$value->response['seo-by-rank-math/rank-math.php']->is_beta = true;
$value->response['seo-by-rank-math/rank-math.php']->upgrade_notice = self::NOTICE_START_MARKER . ' ' . __( 'This update will install a beta version of Rank Math.', 'rank-math' ) . ' ' . self::NOTICE_END_MARKER;
if ( empty( $value->no_update ) ) {
$value->no_update = [];
}
unset( $value->no_update['seo-by-rank-math/rank-math.php'] );
return $value;
}
/**
* Add warning about beta version in the update notice.
*
* @param array $plugin_data An array of plugin metadata.
* @return void
*/
public function plugin_update_message( $plugin_data ) {
if ( empty( $plugin_data['is_beta'] ) ) {
return;
}
printf(
'</p><p class="rank-math-beta-update-notice">%s',
esc_html__( 'This update will install a beta version of Rank Math.', 'rank-math' )
);
}
/**
* Add Javascript to open beta changelog link in a new tab instead of the modal.
*
* @return void
*/
public function beta_changelog_link_js() {
$screen = get_current_screen();
$applicable_screens = [
'update-core',
'plugins',
'update-core-network',
'plugins-network',
];
if ( empty( $screen->base ) || ! in_array( $screen->base, $applicable_screens, true ) ) {
return;
}
$transient = get_site_transient( 'update_plugins' );
if ( ! self::has_beta_update( $transient ) ) {
return;
}
?>
<script type="text/javascript">
jQuery( document ).ready( function( $ ) {
// Change our link.
$('.open-plugin-details-modal').each( function( index, element ) {
if ( element.href.indexOf( 'plugin=seo-by-rank-math&section=changelog' ) !== -1 ) {
// Found our link.
$( element )
.removeClass( 'open-plugin-details-modal thickbox' )
.attr( 'href', '<?php echo esc_js( self::BETA_CHANGELOG_URL ); ?>' )
.attr( 'target', '_blank' );
return false;
}
} );
// Change our notice.
<?php if ( 'update-core' === $screen->base || 'update-core-network' === $screen->base ) { ?>
$('td.plugin-title').each( function( index, element ) {
var contents = $( element ).html();
if ( contents.indexOf( '<?php echo esc_js( html_entity_decode( self::NOTICE_START_MARKER ) ); ?>' ) !== -1 && contents.indexOf( '<?php echo esc_js( html_entity_decode( self::NOTICE_END_MARKER ) ); ?>' ) !== -1 ) {
contents = contents
.replace( '<?php echo esc_js( html_entity_decode( self::NOTICE_START_MARKER ) ); ?>', '</p><div class="update-message notice inline notice-warning notice-alt rank-math-beta-update-notice"><p>' )
.replace( '<?php echo esc_js( html_entity_decode( self::NOTICE_END_MARKER ) ); ?>', '</p></div><p style="display: none;">' );
$( element ).html( contents );
return false;
}
} );
<?php } ?>
} );
</script>
<style>
.update-message.rank-math-beta-update-notice {
font-weight: bold;
margin-top: 20px;
}
.update-message.rank-math-beta-update-notice > p:before {
content: "\f534";
}
</style>
<?php
}
/**
* If user requested check with force-check parameter.
*
* @return bool
*/
public function is_check_requested() {
return (bool) Param::get( 'force-check' );
}
}

View File

@@ -0,0 +1,146 @@
<?php
/**
* The Version Rollback Class.
*
* @package RankMath
* @subpackage RankMath\Version_Control
*/
namespace RankMath;
use RankMath\Traits\Hooker;
use RankMath\Helpers\Param;
defined( 'ABSPATH' ) || exit;
/**
* Rollback_Version class.
*/
class Rollback_Version {
use Hooker;
/**
* Rollback version option key.
*
* @var string
*/
const ROLLBACK_VERSION_OPTION = 'rank_math_rollback_version';
/**
* Check if currently installed version is a rollback version.
*
* @return boolean Whether it is rollback or not.
*/
public static function is_rollback_version() {
$is_rollback = boolval( get_option( self::ROLLBACK_VERSION_OPTION, false ) );
if ( ! $is_rollback ) {
return false;
}
$current_version = rank_math()->version;
$latest_version = Beta_Optin::get_latest_version();
if ( $current_version === $latest_version ) {
delete_option( self::ROLLBACK_VERSION_OPTION );
return false;
}
return true;
}
/**
* Check if we should roll back in this request or not.
*/
public static function should_rollback() {
if ( ! Param::post( 'rm_rollback_version' ) ) {
return false;
}
if ( ! current_user_can( 'update_plugins' ) ) {
return false;
}
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'rank-math-rollback' ) ) {
return false;
}
return true;
}
/**
* Reinstall previous version.
*
* @return boolean Whether the installation was successful.
*/
public function rollback() {
$title = __( 'Rollback Plugin', 'rank-math' );
$parent_file = 'plugins.php';
$submenu_file = 'plugins.php';
$new_version = Param::post( 'rm_rollback_version' );
wp_enqueue_script( 'updates' );
$plugin = 'seo-by-rank-math/rank-math.php';
$nonce = 'upgrade-plugin_' . $plugin;
$url = 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $plugin );
if ( ! class_exists( '\Plugin_Upgrader' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // @phpstan-ignore-line
}
update_option( self::ROLLBACK_VERSION_OPTION, $new_version );
// Downgrade version number if necessary.
if ( version_compare( rank_math()->version, $new_version, '>' ) ) {
update_option( 'rank_math_version', $new_version );
}
add_filter( 'pre_site_transient_update_plugins', [ $this, 'pre_transient_update_plugins' ], 20 );
add_filter( 'gettext', [ $this, 'change_updater_strings' ], 20, 2 );
$upgrader = new \Plugin_Upgrader( new \Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) ) );
echo '<div class="rank-math-rollback-status">';
$upgrader->upgrade( $plugin );
echo '</div>';
remove_filter( 'pre_site_transient_update_plugins', [ $this, 'pre_transient_update_plugins' ], 20 );
remove_filter( 'gettext', [ $this, 'change_updater_strings' ], 20, 2 );
return true;
}
/**
* Inject old version in the `update_plugins` transient for downgrading.
*
* @return object New `update_plugins` data object.
*/
public function pre_transient_update_plugins() {
$versions = Beta_Optin::get_available_versions( true );
$selected = Param::post( 'rm_rollback_version' );
$package = $versions[ $selected ];
$data = new \stdClass();
$data->response = [];
$data->response['seo-by-rank-math/rank-math.php'] = new \stdClass();
$plugin_data = Version_Control::get_plugin_data( $selected, $package );
foreach ( $plugin_data as $prop_key => $prop_value ) {
$data->response['seo-by-rank-math/rank-math.php']->{$prop_key} = $prop_value;
}
return $data;
}
/**
* Hooked to gettext filter to change strings in the Updater for the rollback process.
*
* @param string $translation Translated text.
* @param string $text Original text.
*
* @return string New translated text.
*/
public function change_updater_strings( $translation, $text ) {
if ( 'Plugin updated successfully.' === $text ) {
return __( 'Plugin rollback successful.', 'rank-math' );
}
if ( 'Installing the latest version&#8230;' === $text ) {
return __( 'Installing the rollback version&#8230;', 'rank-math' );
}
return $translation;
}
}

View File

@@ -0,0 +1,154 @@
<?php
/**
* The Version Control internal module.
*
* @package RankMath
* @subpackage RankMath\Version_Control
*/
namespace RankMath;
use RankMath\Helper;
use RankMath\Helpers\Param;
use RankMath\Traits\Hooker;
defined( 'ABSPATH' ) || exit;
/**
* Version_Control class.
*/
class Version_Control {
use Hooker;
/**
* Module ID.
*
* @var string
*/
public $id = '';
/**
* Module directory.
*
* @var string
*/
public $directory = '';
/**
* Plugin info transient key.
*
* @var string
*/
const TRANSIENT = 'rank_math_wporg_plugin_info';
/**
* WordPress.org plugins API URL.
*
* @var string
*/
const API_URL = 'https://api.wordpress.org/plugins/info/1.0/seo-by-rank-math.json';
/**
* Constructor.
*/
public function __construct() {
if ( Helper::is_heartbeat() ) {
return;
}
if ( Helper::is_rest() ) {
return;
}
$this->config(
[
'id' => 'status',
'directory' => __DIR__,
]
);
$this->hooks();
}
/**
* Register version control hooks.
*/
public function hooks() {
if ( Helper::get_settings( 'general.beta_optin' ) ) {
$beta_optin = new Beta_Optin();
$beta_optin->hooks();
}
}
/**
* Get localized JSON data based on the Page view.
*/
public static function get_json_data() {
$versions = array_reverse( array_keys( Beta_Optin::get_available_versions( Helper::get_settings( 'general.beta_optin' ) ) ) );
array_splice( $versions, 10 );
return [
'latestVersion' => Beta_Optin::get_latest_version(),
'isRollbackVersion' => Rollback_Version::is_rollback_version(),
'isPluginUpdateDisabled' => Helper::is_plugin_update_disabled(),
'availableVersions' => $versions,
'updateCoreUrl' => self_admin_url( 'update-core.php' ),
'rollbackVersion' => get_option( 'rank_math_rollback_version', false ),
'rollbackNonce' => wp_create_nonce( 'rank-math-rollback' ),
'betaOptin' => boolval( Helper::get_settings( 'general.beta_optin' ) ),
'autoUpdate' => boolval( Helper::get_auto_update_setting() ),
'updateNotificationEmail' => boolval( Helper::get_settings( 'general.update_notification_email' ) ),
];
}
/**
* Get Rank Math plugin information.
*
* @return mixed Plugin information array or false on fail.
*/
public static function get_plugin_info() {
$cache = get_transient( self::TRANSIENT );
if ( $cache ) {
return $cache;
}
$request = wp_remote_get( self::API_URL, [ 'timeout' => 20 ] );
if ( ! is_wp_error( $request ) && is_array( $request ) ) {
$response = json_decode( $request['body'], true );
set_transient( self::TRANSIENT, $response, ( 12 * HOUR_IN_SECONDS ) );
return $response;
}
return false;
}
/**
* Get plugin data to use in the `update_plugins` transient.
*
* @param string $version New version.
* @param string $package New version download URL.
* @return array An array of plugin metadata.
*/
public static function get_plugin_data( $version, $package ) {
return [
'id' => 'w.org/plugins/seo-by-rank-math',
'slug' => 'seo-by-rank-math',
'plugin' => 'seo-by-rank-math/rank-math.php',
'new_version' => $version,
'url' => 'https://wordpress.org/plugins/seo-by-rank-math/',
'package' => $package,
'icons' =>
[
'2x' => 'https://ps.w.org/seo-by-rank-math/assets/icon-256x256.png?rev=2034417',
'1x' => 'https://ps.w.org/seo-by-rank-math/assets/icon.svg?rev=2034417',
'svg' => 'https://ps.w.org/seo-by-rank-math/assets/icon.svg?rev=2034417',
],
'banners' =>
[
'2x' => 'https://ps.w.org/seo-by-rank-math/assets/banner-1544x500.png?rev=2034417',
'1x' => 'https://ps.w.org/seo-by-rank-math/assets/banner-772x250.png?rev=2034417',
],
'banners_rtl' => [],
];
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* The Version Control View to be used on Network Admin.
*
* @package RankMath
* @subpackage RankMath\Version_Control
*/
namespace RankMath;
use RankMath\Helper;
defined( 'ABSPATH' ) || exit;
if ( Rollback_Version::should_rollback() ) {
$rollback = new Rollback_Version();
$rollback->rollback();
return;
}
echo '<div id="rank-math-version-control-wrapper"></div>';

View File

@@ -0,0 +1 @@
<?php // Silence is golden.