This commit is contained in:
2026-07-02 15:54:39 -06:00
commit 9883323161
17470 changed files with 4470592 additions and 0 deletions
@@ -0,0 +1,75 @@
<?php
namespace Automattic\Jetpack_Boost\Data_Sync;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Get;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Set;
use Automattic\Jetpack_Boost\Lib\Environment_Change_Detector;
class Cornerstone_Pages_Entry implements Entry_Can_Get, Entry_Can_Set {
private $option_key;
public function __construct( $option_key ) {
$this->option_key = 'jetpack_boost_ds_' . $option_key;
}
public function get( $fallback_value = array() ) {
$urls = get_option( $this->option_key, array() );
if ( empty( $urls ) && ! empty( $fallback_value ) ) {
$urls = $fallback_value;
$this->set( $urls );
}
/**
* Filters the list of cornerstone pages. This list only includes the custom pages.
* If you want the full list, use `jetpack_boost_cornerstone_pages_list_complete` instead.
*
* @since 3.7.0
*
* @param array $urls An array of absolute URLs.
*/
return apply_filters( 'jetpack_boost_cornerstone_pages_list', array_map( array( $this, 'transform_to_absolute' ), $urls ) );
}
public function set( $value ) {
$value = $this->sanitize_value( $value );
$updated = update_option( $this->option_key, $value );
if ( $updated ) {
( new Environment_Change_Detector() )->handle_cornerstone_pages_list_update();
}
}
private function sanitize_value( $value ) {
if ( is_array( $value ) ) {
$value = array_values( array_unique( array_map( 'untrailingslashit', array_map( array( $this, 'transform_to_relative' ), $value ) ) ) );
} else {
$value = array();
}
return $value;
}
private function transform_to_relative( $url ) {
$url = trim( $url );
// Remove the home_url from the beginning of the URL if it exists.
if ( strpos( $url, home_url() ) === 0 ) {
$url = substr( $url, strlen( home_url() ) );
}
// Ensure the URL starts with a slash.
if ( $url !== '' ) {
$url = ltrim( $url, '/' );
$url = '/' . $url;
}
return $url;
}
private function transform_to_absolute( $url ) {
return home_url( $url );
}
}
@@ -0,0 +1,12 @@
<?php
namespace Automattic\Jetpack_Boost\Data_Sync;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Get;
use Automattic\Jetpack_Boost\Lib\Critical_CSS\Generator;
class Critical_CSS_Meta_Entry implements Entry_Can_Get {
public function get( $_fallback = false ) {
$generator = new Generator();
return $generator->get_generation_metadata();
}
}
@@ -0,0 +1,52 @@
<?php
namespace Automattic\Jetpack_Boost\Data_Sync;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Get;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Set;
use Automattic\Jetpack_Boost\Lib\Connection;
use Automattic\Jetpack_Boost\Lib\Premium_Features;
class Getting_Started_Entry implements Entry_Can_Get, Entry_Can_Set {
private $option_key = 'jb_get_started';
/**
* Determines if the user should be shown the Getting Started page.
*/
public function get( $fallback = false ) {
// No point in showing the page if the site is offline, it's probably localhost.
if ( ( new Status() )->is_offline_mode() ) {
return false;
}
// No need to show the page if the site is private.
if ( ( new Status() )->is_private_site() ) {
return false;
}
// If there is no connection, the page must be shown to give them a chance to connect by choosing a plan.
if ( ! ( new Connection() )->is_connected() ) {
return true;
}
// If the site already has premium plan, there is no need to show the page.
if ( Premium_Features::has_any() ) {
return false;
}
// For all other cases, the page should be shown only if the flag is set. It indicates that it's a new site.
if ( $fallback !== false ) {
return \get_option( $this->option_key, $fallback );
}
return \get_option( $this->option_key );
}
public function set( $value ) {
if ( $value === true ) {
update_option( $this->option_key, $value, false );
} else {
delete_option( $this->option_key );
}
}
}
@@ -0,0 +1,31 @@
<?php
namespace Automattic\Jetpack_Boost\Data_Sync;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Get;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Merge;
class Mergeable_Array_Entry implements Entry_Can_Get, Entry_Can_Merge {
private $option_key;
public function __construct( $option_key ) {
$this->option_key = $option_key;
}
public function get( $fallback_value = false ) {
// WordPress looks at argument count to figure out if a fallback value was used.
// Only provide the fallback value if it's not the default ( false ).
if ( $fallback_value !== false ) {
return get_option( $this->option_key, $fallback_value );
}
return get_option( $this->option_key );
}
public function set( $value ) {
update_option( $this->option_key, $value, false );
}
public function merge( $value, $partial_value ) {
return array_merge( $value, $partial_value );
}
}
@@ -0,0 +1,78 @@
<?php
namespace Automattic\Jetpack_Boost\Data_Sync;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Get;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Set;
/**
* The Minify_Excludes_State_Entry class represents a single state entry for Jetpack Boost Data Sync.
*
* This class implements the Entry_Can_Get and Entry_Can_Set interfaces, allowing it to retrieve and set
* the current state of the Minify Excludes option.
*
* @package Automattic\Jetpack_Boost\Data_Sync
*/
class Minify_Excludes_State_Entry implements Entry_Can_Get, Entry_Can_Set {
/**
* The option key used to store the Minify Excludes option.
*
* @var string
*/
private $option_key;
/**
* Constructs a new instance of the Minify_Excludes_State_Entry class.
*
* @param string $option_key The option key used to store the Minify Excludes option.
*/
public function __construct( $option_key ) {
$this->option_key = 'jetpack_boost_ds_' . $option_key;
}
/**
* Retrieves the value of the specified option.
*
* If the option does not exist, it returns the provided fallback value
* or null if no fallback value is provided.
*
* @param mixed $fallback_value Optional. The value to return if the option does not exist.
* Default is false.
* @return mixed The value of the option, or the fallback value if the option does not exist.
*/
public function get( $fallback_value = false ) {
if ( $fallback_value !== false ) {
return get_option( $this->option_key, $fallback_value );
}
return get_option( $this->option_key );
}
/**
* Sets the value of the Minify Excludes option.
*
* @param mixed $value The new value of the Minify Excludes option.
*/
public function set( $value ) {
$value = $this->sanitize_value( $value );
update_option( $this->option_key, $value );
}
/**
* Sanitizes the given value, ensuring that it is a comma-separated list of unique, trimmed strings.
*
* @param mixed $value The value to sanitize.
*
* @return string The sanitized value, as a comma-separated list of unique, trimmed strings.
*/
private function sanitize_value( $value ) {
if ( is_array( $value ) ) {
$value = array_values( array_unique( array_filter( array_map( 'trim', $value ) ) ) );
} else {
$value = array();
}
return $value;
}
}
@@ -0,0 +1,60 @@
<?php
namespace Automattic\Jetpack_Boost\Data_Sync;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Get;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Merge;
use Automattic\Jetpack_Boost\Modules\Module;
class Modules_State_Entry implements Entry_Can_Get, Entry_Can_Merge {
protected $modules = array();
public function __construct( $features ) {
foreach ( $features as $feature ) {
$instance = new Module( new $feature() );
$this->modules[ $instance->get_slug() ] = $instance;
}
}
public function get( $_fallback = false ) {
$state = array();
/*
* Module states are stored in their individual wp_options records.
* We're combining the states of all modules into a single record and attaching the availability of the module.
*/
foreach ( $this->modules as $module ) {
$state[ $module->get_slug() ] = array(
'active' => $module->is_available() && $module->is_enabled(),
'available' => $module->is_available(),
);
}
return $state;
}
public function set( $value ) {
foreach ( $value as $module_slug => $module_state ) {
if ( ! isset( $this->modules[ $module_slug ] ) ) {
continue;
}
$updated = $this->modules[ $module_slug ]->update( $module_state['active'] );
if ( $updated ) {
/**
* Fires when a module is enabled or disabled.
*
* @param string $module The module slug.
* @param bool $status The new status.
* @since 1.5.2
*/
do_action( 'jetpack_boost_module_status_updated', $module_slug, $module_state['active'] );
}
}
}
public function merge( $value, $partial_value ) {
return array_merge( $value, $partial_value );
}
}
@@ -0,0 +1,53 @@
<?php
namespace Automattic\Jetpack_Boost\Data_Sync;
use Automattic\Jetpack\Boost_Speed_Score\Speed_Score_Graph_History_Request;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Get;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Entry_Can_Set;
use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Lazy_Entry;
class Performance_History_Entry implements Lazy_Entry, Entry_Can_Get, Entry_Can_Set {
private $start_date;
private $end_date;
public function __construct() {
// Default to the last 30 days
$this->start_date = ( time() - 60 * 60 * 24 * 30 ) * 1000;
$this->end_date = time() * 1000;
}
public function get( $_fallback = false ) {
$request = new Speed_Score_Graph_History_Request( $this->start_date, $this->end_date, array() );
$result = $request->execute();
if ( is_wp_error( $result ) || empty( $result['data'] ) ) {
return array(
'startDate' => $this->start_date,
'endDate' => $this->end_date,
'periods' => array(),
'annotations' => array(),
);
}
$annotations = $result['data']['annotations'] ?? array();
// Sanitize the annotations
foreach ( $annotations as $key => $annotation ) {
$annotations[ $key ] = array(
'timestamp' => $annotation['timestamp'],
'text' => wp_kses_post( $annotation['text'] ),
);
}
return array(
'startDate' => $result['data']['_meta']['start'],
'endDate' => $result['data']['_meta']['end'],
'periods' => $result['data']['periods'],
'annotations' => $annotations,
);
}
public function set( $value ) {
$this->start_date = $value['startDate'];
$this->end_date = $value['endDate'];
}
}