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,61 @@
<?php
/**
* Class Google\Site_Kit\Core\User\Audience_Segmentation
*
* @package Google\Site_Kit\Core\User
* @copyright 2024 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Storage\User_Options;
/**
* Class for handling audience settings rest routes.
*
* @since 1.134.0
* @access private
* @ignore
*/
class Audience_Segmentation {
/**
* Audience_Settings instance.
*
* @since 1.134.0
* @var Audience_Settings
*/
private $audience_settings;
/**
* REST_Audience_Settings_Controller instance.
*
* @since 1.134.0
* @var REST_Audience_Settings_Controller
*/
private $rest_controller;
/**
* Constructor.
*
* @since 1.134.0
*
* @param User_Options $user_options User_Options instance.
*/
public function __construct( User_Options $user_options ) {
$this->audience_settings = new Audience_Settings( $user_options );
$this->rest_controller = new REST_Audience_Settings_Controller( $this->audience_settings );
}
/**
* Registers functionality through WordPress hooks.
*
* @since 1.134.0
*/
public function register() {
$this->audience_settings->register();
$this->rest_controller->register();
}
}

View File

@@ -0,0 +1,130 @@
<?php
/**
* Class Google\Site_Kit\Core\User\Audience_Settings
*
* @package Google\Site_Kit\Core\User
* @copyright 2024 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Storage\User_Setting;
use Google\Site_Kit\Core\Util\Sanitize;
/**
* Class for audience settings.
*
* @since 1.134.0
* @access private
* @ignore
*/
class Audience_Settings extends User_Setting {
/**
* The user option name for audience setting.
*/
const OPTION = 'googlesitekit_audience_settings';
/**
* Gets the expected value type.
*
* @since 1.124.0
*
* @return string The type name.
*/
protected function get_type() {
return 'object';
}
/**
* Gets the default value.
*
* @since 1.124.0
* @since 1.136.0 Added `didSetAudiences` default value.
*
* @return array The default value.
*/
protected function get_default() {
return array(
'configuredAudiences' => null,
'isAudienceSegmentationWidgetHidden' => false,
'didSetAudiences' => false,
);
}
/**
* Merges an array of settings to update.
*
* @since 1.124.0
* @since 1.138.0 Allow setting `null` for `configuredAudiences`.
*
* @param array $partial Partial settings array to save.
* @return bool True on success, false on failure.
*/
public function merge( array $partial ) {
$settings = $this->get();
$partial = array_filter(
$partial,
function ( $value, $key ) {
// Allow setting `null` for `configuredAudiences`.
return 'configuredAudiences' === $key ? true : null !== $value;
},
ARRAY_FILTER_USE_BOTH
);
$allowed_settings = array(
'configuredAudiences' => true,
'isAudienceSegmentationWidgetHidden' => true,
'didSetAudiences' => true,
);
$updated = array_intersect_key( $partial, $allowed_settings );
if ( empty( $settings['didSetAudiences'] )
&& isset( $updated['configuredAudiences'] )
&& is_array( $updated['configuredAudiences'] )
&& ! empty( $updated['configuredAudiences'] )
) {
$updated['didSetAudiences'] = true;
}
return $this->set( array_merge( $settings, $updated ) );
}
/**
* Gets the callback for sanitizing the setting's value before saving.
*
* @since 1.124.0
* @since 1.138.0 Allow setting `null` for `configuredAudiences`.
*
* @return callable Sanitize callback.
*/
protected function get_sanitize_callback() {
return function ( $settings ) {
if ( ! is_array( $settings ) ) {
return array();
}
$sanitized_settings = array();
// Allow setting `null` for `configuredAudiences`.
if ( array_key_exists( 'configuredAudiences', $settings ) ) {
$sanitized_settings['configuredAudiences'] = is_null( $settings['configuredAudiences'] )
? null
: Sanitize::sanitize_string_list( $settings['configuredAudiences'] );
}
if ( isset( $settings['isAudienceSegmentationWidgetHidden'] ) ) {
$sanitized_settings['isAudienceSegmentationWidgetHidden'] = false !== $settings['isAudienceSegmentationWidgetHidden'];
}
if ( isset( $settings['didSetAudiences'] ) ) {
$sanitized_settings['didSetAudiences'] = false !== $settings['didSetAudiences'];
}
return $sanitized_settings;
};
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* Class Google\Site_Kit\Core\User\Conversion_Reporting
*
* @package Google\Site_Kit\Core\User
* @copyright 2024 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Storage\User_Options;
/**
* Class for handling conversion reporting settings rest routes.
*
* @since 1.144.0
* @access private
* @ignore
*/
class Conversion_Reporting {
/**
* Conversion_Reporting_Settings instance.
*
* @since 1.144.0
* @var Conversion_Reporting_Settings
*/
private $conversion_reporting_settings;
/**
* REST_Conversion_Reporting_Controller instance.
*
* @since 1.144.0
* @var REST_Conversion_Reporting_Controller
*/
private $rest_controller;
/**
* Constructor.
*
* @since 1.144.0
*
* @param User_Options $user_options User_Options instance.
*/
public function __construct( User_Options $user_options ) {
$this->conversion_reporting_settings = new Conversion_Reporting_Settings( $user_options );
$this->rest_controller = new REST_Conversion_Reporting_Controller( $this->conversion_reporting_settings );
}
/**
* Registers functionality through WordPress hooks.
*
* @since 1.144.0
*/
public function register() {
$this->conversion_reporting_settings->register();
$this->rest_controller->register();
}
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* Class Google\Site_Kit\Core\User\Conversion_Reporting_Settings
*
* @package Google\Site_Kit\Core\Conversion_Reporting
* @copyright 2024 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Storage\User_Setting;
/**
* Class for handling conversion reporting settings rest routes.
*
* @since 1.144.0
* @access private
* @ignore
*/
class Conversion_Reporting_Settings extends User_Setting {
/**
* The user option name for this setting.
*/
const OPTION = 'googlesitekit_conversion_reporting_settings';
/**
* Gets the expected value type.
*
* @since 1.144.0
*
* @return string The type name.
*/
protected function get_type() {
return 'object';
}
/**
* Gets the default value.
*
* @since 1.144.0
*
* @return array The default value.
*/
protected function get_default() {
return array(
'newEventsCalloutDismissedAt' => 0,
'lostEventsCalloutDismissedAt' => 0,
);
}
/**
* Merges an array of settings to update.
*
* @since 1.144.0
*
* @param array $partial Partial settings array to save.
* @return bool True on success, false on failure.
*/
public function merge( array $partial ) {
$settings = $this->get();
$partial = array_filter(
$partial,
function ( $value ) {
return null !== $value;
}
);
$allowed_settings = array(
'newEventsCalloutDismissedAt' => true,
'lostEventsCalloutDismissedAt' => true,
);
$updated = array_intersect_key( $partial, $allowed_settings );
return $this->set( array_merge( $settings, $updated ) );
}
/**
* Gets the callback for sanitizing the setting's value before saving.
*
* @since 1.144.0
*
* @return callable Sanitize callback.
*/
protected function get_sanitize_callback() {
return function ( $settings ) {
if ( ! is_array( $settings ) ) {
return array();
}
if ( isset( $settings['newEventsCalloutDismissedAt'] ) ) {
if ( ! is_int( $settings['newEventsCalloutDismissedAt'] ) ) {
$settings['newEventsCalloutDismissedAt'] = 0;
}
}
if ( isset( $settings['lostEventsCalloutDismissedAt'] ) ) {
if ( ! is_int( $settings['lostEventsCalloutDismissedAt'] ) ) {
$settings['lostEventsCalloutDismissedAt'] = 0;
}
}
return $settings;
};
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* Class Google\Site_Kit\Core\User\Email_Reporting
*
* @package Google\Site_Kit\Core\User
* @copyright 2025 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Storage\User_Options;
/**
* Class for handling email reporting settings rest routes.
*
* @since 1.162.0
* @access private
* @ignore
*/
class Email_Reporting {
/**
* Email_Reporting_Settings instance.
*
* @since 1.162.0
* @var Email_Reporting_Settings
*/
private $email_reporting_settings;
/**
* REST_Email_Reporting_Controller instance.
*
* @since 1.162.0
* @var REST_Email_Reporting_Controller
*/
private $rest_controller;
/**
* Constructor.
*
* @since 1.162.0
*
* @param User_Options $user_options User_Options instance.
*/
public function __construct( User_Options $user_options ) {
$this->email_reporting_settings = new Email_Reporting_Settings( $user_options );
$this->rest_controller = new REST_Email_Reporting_Controller( $this->email_reporting_settings );
}
/**
* Registers functionality through WordPress hooks.
*
* @since 1.162.0
*/
public function register() {
$this->email_reporting_settings->register();
$this->rest_controller->register();
}
}

View File

@@ -0,0 +1,126 @@
<?php
/**
* Class Google\Site_Kit\Core\User\Email_Reporting_Settings
*
* @package Google\Site_Kit\Core\User
* @copyright 2025 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Storage\User_Setting;
/**
* Class for email reporting settings.
*
* @since 1.161.0
* @access private
* @ignore
*/
class Email_Reporting_Settings extends User_Setting {
/**
* The user option name for email reporting setting.
*/
const OPTION = 'googlesitekit_email_reporting_settings';
/**
* Gets the expected value type.
*
* @since 1.161.0
*
* @return string The type name.
*/
protected function get_type() {
return 'object';
}
/**
* Gets the default value.
*
* @since 1.161.0
*
* @return array The default value.
*/
protected function get_default() {
return array(
'subscribed' => false,
'frequency' => 'weekly',
);
}
/**
* Merges an array of settings to update.
*
* @since 1.161.0
*
* @param array $partial Partial settings array to save.
* @return bool True on success, false on failure.
*/
public function merge( array $partial ) {
$settings = $this->get();
$partial = array_filter(
$partial,
function ( $value ) {
return null !== $value;
}
);
$allowed_settings = array(
'subscribed' => true,
'frequency' => true,
);
$updated = array_intersect_key( $partial, $allowed_settings );
return $this->set( array_merge( $settings, $updated ) );
}
/**
* Gets the callback for sanitizing the setting's value before saving.
*
* @since 1.161.0
*
* @return callable Sanitize callback.
*/
protected function get_sanitize_callback() {
return function ( $settings ) {
if ( ! is_array( $settings ) ) {
return array();
}
$sanitized_settings = array();
if ( isset( $settings['subscribed'] ) ) {
$sanitized_settings['subscribed'] = (bool) $settings['subscribed'];
}
if ( array_key_exists( 'frequency', $settings ) ) {
if ( is_string( $settings['frequency'] ) ) {
$sanitized_settings['frequency'] = $settings['frequency'];
} else {
$sanitized_settings['frequency'] = 'weekly';
}
if ( ! in_array( $sanitized_settings['frequency'], array( 'weekly', 'monthly', 'quarterly' ), true ) ) {
$sanitized_settings['frequency'] = 'weekly';
}
}
return $sanitized_settings;
};
}
/**
* Accessor for the `subscribed` setting.
*
* @since 1.161.0
*
* @return bool TRUE if user is subscribed, otherwise FALSE.
*/
public function is_user_subscribed() {
return $this->get()['subscribed'];
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* Class Google\Site_Kit\Core\User\Initial_Setup
*
* @package Google\Site_Kit\Core\User
* @copyright 2025 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Storage\User_Options;
/**
* Class for handling initial setup rest routes.
*
* @since 1.164.0
* @access private
* @ignore
*/
class Initial_Setup {
/**
* Initial_Setup_Settings instance.
*
* @since 1.164.0
* @var Initial_Setup_Settings
*/
private $initial_setup_settings;
/**
* REST_Initial_Setup_Controller instance.
*
* @since 1.164.0
* @var REST_Initial_Setup_Controller
*/
private $rest_controller;
/**
* Constructor.
*
* @since 1.164.0
*
* @param User_Options $user_options User_Options instance.
*/
public function __construct( User_Options $user_options ) {
$this->initial_setup_settings = new Initial_Setup_Settings( $user_options );
$this->rest_controller = new REST_Initial_Setup_Controller( $this->initial_setup_settings );
}
/**
* Registers functionality through WordPress hooks.
*
* @since 1.164.0
*/
public function register() {
$this->initial_setup_settings->register();
$this->rest_controller->register();
}
}

View File

@@ -0,0 +1,99 @@
<?php
/**
* Class Google\Site_Kit\Core\User\Initial_Setup_Settings
*
* @package Google\Site_Kit\Core\User
* @copyright 2025 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Storage\User_Setting;
/**
* Class for initial setup settings.
*
* @since 1.164.0
* @access private
* @ignore
*/
class Initial_Setup_Settings extends User_Setting {
/**
* The user option name for the initial setup setting.
*/
const OPTION = 'googlesitekit_initial_setup';
/**
* Gets the expected value type.
*
* @since 1.164.0
*
* @return string The type name.
*/
protected function get_type() {
return 'object';
}
/**
* Gets the default value.
*
* @since 1.164.0
*
* @return array The default value.
*/
protected function get_default() {
return array(
'isAnalyticsSetupComplete' => null,
);
}
/**
* Merges an array of settings to update.
*
* @since 1.164.0
*
* @param array $partial Partial settings array to save.
* @return bool True on success, false on failure.
*/
public function merge( array $partial ) {
$settings = $this->get();
$partial = array_filter(
$partial,
function ( $value ) {
return null !== $value;
}
);
$allowed_settings = array(
'isAnalyticsSetupComplete' => true,
);
$updated = array_intersect_key( $partial, $allowed_settings );
return $this->set( array_merge( $settings, $updated ) );
}
/**
* Gets the callback for sanitizing the setting's value before saving.
*
* @since 1.164.0
*
* @return callable Sanitize callback.
*/
protected function get_sanitize_callback() {
return function ( $settings ) {
if ( ! is_array( $settings ) ) {
return array();
}
if ( isset( $settings['isAnalyticsSetupComplete'] ) ) {
$settings['isAnalyticsSetupComplete'] = (bool) $settings['isAnalyticsSetupComplete'];
}
return $settings;
};
}
}

View File

@@ -0,0 +1,141 @@
<?php
/**
* Class Google\Site_Kit\Core\User\REST_Audience_Settings_Controller
*
* @package Google\Site_Kit\Core\User
* @copyright 2024 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Permissions\Permissions;
use Google\Site_Kit\Core\REST_API\REST_Route;
use Google\Site_Kit\Core\REST_API\REST_Routes;
use Google\Site_Kit\Core\Util\Feature_Flags;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;
/**
* Class for handling audience settings rest routes.
*
* @since 1.134.0
* @access private
* @ignore
*/
class REST_Audience_Settings_Controller {
/**
* Audience_Settings instance.
*
* @since 1.134.0
* @var Audience_Settings
*/
private $audience_settings;
/**
* Constructor.
*
* @since 1.134.0
*
* @param Audience_Settings $audience_settings Audience_Settings instance.
*/
public function __construct( Audience_Settings $audience_settings ) {
$this->audience_settings = $audience_settings;
}
/**
* Registers functionality through WordPress hooks.
*
* @since 1.134.0
*/
public function register() {
add_filter(
'googlesitekit_rest_routes',
function ( $routes ) {
return array_merge( $routes, $this->get_rest_routes() );
}
);
add_filter(
'googlesitekit_apifetch_preload_paths',
function ( $paths ) {
return array_merge(
$paths,
array(
'/' . REST_Routes::REST_ROOT . '/core/user/data/audience-settings',
)
);
}
);
}
/**
* Gets REST route instances.
*
* @since 1.134.0
*
* @return REST_Route[] List of REST_Route objects.
*/
protected function get_rest_routes() {
$can_view_dashboard = function () {
return current_user_can( Permissions::VIEW_DASHBOARD );
};
return array(
new REST_Route(
'core/user/data/audience-settings',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => function () {
return new WP_REST_Response( $this->audience_settings->get() );
},
'permission_callback' => $can_view_dashboard,
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => function ( WP_REST_Request $request ) {
$settings = $request['data']['settings'];
$this->audience_settings->merge( $settings );
return new WP_REST_Response( $this->audience_settings->get() );
},
'permission_callback' => $can_view_dashboard,
'args' => array(
'data' => array(
'type' => 'object',
'required' => true,
'properties' => array(
'settings' => array(
'type' => 'object',
'required' => true,
'minProperties' => 1,
'additionalProperties' => false,
'properties' => array(
'configuredAudiences' => array(
'type' => 'array',
'items' => array(
'type' => 'string',
),
),
'isAudienceSegmentationWidgetHidden' => array(
'type' => 'boolean',
),
'didSetAudiences' => array(
'type' => 'boolean',
),
),
),
),
),
),
),
)
),
);
}
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* Class Google\Site_Kit\Core\User\REST_Conversion_Reporting_Controller
*
* @package Google\Site_Kit\Core\User
* @copyright 2024 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Permissions\Permissions;
use Google\Site_Kit\Core\REST_API\REST_Route;
use Google\Site_Kit\Core\REST_API\REST_Routes;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;
/**
* Class for handling conversion reporting settings rest routes.
*
* @since 1.144.0
* @access private
* @ignore
*/
class REST_Conversion_Reporting_Controller {
/**
* Conversion_Reporting_Settings instance.
*
* @since 1.144.0
* @var Conversion_Reporting_Settings
*/
private $conversion_reporting_settings;
/**
* Constructor.
*
* @since 1.144.0
*
* @param Conversion_Reporting_Settings $conversion_reporting_settings Conversion_Reporting_Settings instance.
*/
public function __construct( Conversion_Reporting_Settings $conversion_reporting_settings ) {
$this->conversion_reporting_settings = $conversion_reporting_settings;
}
/**
* Registers functionality through WordPress hooks.
*
* @since 1.144.0
*/
public function register() {
add_filter(
'googlesitekit_rest_routes',
function ( $routes ) {
return array_merge( $routes, $this->get_rest_routes() );
}
);
add_filter(
'googlesitekit_apifetch_preload_paths',
function ( $paths ) {
return array_merge(
$paths,
array(
'/' . REST_Routes::REST_ROOT . '/core/user/data/conversion-reporting-settings',
)
);
}
);
}
/**
* Gets REST route instances.
*
* @since 1.144.0
*
* @return REST_Route[] List of REST_Route objects.
*/
protected function get_rest_routes() {
$can_view_dashboard = function () {
return current_user_can( Permissions::VIEW_DASHBOARD );
};
return array(
new REST_Route(
'core/user/data/conversion-reporting-settings',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => function () {
return new WP_REST_Response( $this->conversion_reporting_settings->get() );
},
'permission_callback' => $can_view_dashboard,
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => function ( WP_REST_Request $request ) {
$settings = $request['data']['settings'];
$this->conversion_reporting_settings->merge( $settings );
return new WP_REST_Response( $this->conversion_reporting_settings->get() );
},
'permission_callback' => $can_view_dashboard,
'args' => array(
'data' => array(
'type' => 'object',
'required' => true,
'properties' => array(
'settings' => array(
'type' => 'object',
'required' => true,
'minProperties' => 1,
'additionalProperties' => false,
'properties' => array(
'newEventsCalloutDismissedAt' => array(
'type' => 'integer',
),
'lostEventsCalloutDismissedAt' => array(
'type' => 'integer',
),
),
),
),
),
),
),
)
),
);
}
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* Class Google\Site_Kit\Core\User\REST_Email_Reporting_Controller
*
* @package Google\Site_Kit\Core\User
* @copyright 2025 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Permissions\Permissions;
use Google\Site_Kit\Core\REST_API\REST_Route;
use Google\Site_Kit\Core\REST_API\REST_Routes;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;
/**
* Class for handling email reporting user settings via REST API.
*
* @since 1.162.0
* @access private
* @ignore
*/
class REST_Email_Reporting_Controller {
/**
* Email_Reporting_Settings instance.
*
* @since 1.162.0
* @var Email_Reporting_Settings
*/
private $settings;
/**
* Constructor.
*
* @since 1.162.0
*
* @param Email_Reporting_Settings $settings Email_Reporting_Settings instance.
*/
public function __construct( Email_Reporting_Settings $settings ) {
$this->settings = $settings;
}
/**
* Registers functionality through WordPress hooks.
*
* @since 1.162.0
*/
public function register() {
add_filter(
'googlesitekit_rest_routes',
function ( $routes ) {
return array_merge( $routes, $this->get_rest_routes() );
}
);
add_filter(
'googlesitekit_apifetch_preload_paths',
function ( $paths ) {
return array_merge(
$paths,
array(
'/' . REST_Routes::REST_ROOT . '/core/user/data/email-reporting-settings',
)
);
}
);
}
/**
* Gets REST route instances.
*
* @since 1.162.0
*
* @return REST_Route[] List of REST_Route objects.
*/
protected function get_rest_routes() {
$can_view_dashboard = function () {
return current_user_can( Permissions::VIEW_DASHBOARD );
};
return array(
new REST_Route(
'core/user/data/email-reporting-settings',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => function () {
return new WP_REST_Response( $this->settings->get() );
},
'permission_callback' => $can_view_dashboard,
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => function ( WP_REST_Request $request ) {
$settings = $request['data']['settings'];
$this->settings->merge( $settings );
return new WP_REST_Response( $this->settings->get() );
},
'permission_callback' => $can_view_dashboard,
'args' => array(
'data' => array(
'type' => 'object',
'required' => true,
'properties' => array(
'settings' => array(
'type' => 'object',
'required' => true,
'minProperties' => 1,
'additionalProperties' => false,
'properties' => array(
'frequency' => array(
'type' => 'string',
'enum' => array( 'weekly', 'monthly', 'quarterly' ),
),
'subscribed' => array(
'type' => 'boolean',
),
),
),
),
),
),
),
)
),
);
}
}

View File

@@ -0,0 +1,131 @@
<?php
/**
* Class Google\Site_Kit\Core\User\REST_Initial_Setup_Controller
*
* @package Google\Site_Kit\Core\User
* @copyright 2025 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Permissions\Permissions;
use Google\Site_Kit\Core\REST_API\REST_Route;
use Google\Site_Kit\Core\REST_API\REST_Routes;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;
/**
* Class for handling audience settings rest routes.
*
* @since 1.164.0
* @access private
* @ignore
*/
class REST_Initial_Setup_Controller {
/**
* Initial_Setup_Settings instance.
*
* @since 1.164.0
* @var Initial_Setup_Settings
*/
private $initial_setup_settings;
/**
* Constructor.
*
* @since 1.164.0
*
* @param Initial_Setup_Settings $initial_setup_settings Initial_Setup_Settings instance.
*/
public function __construct( Initial_Setup_Settings $initial_setup_settings ) {
$this->initial_setup_settings = $initial_setup_settings;
}
/**
* Registers functionality through WordPress hooks.
*
* @since 1.164.0
*/
public function register() {
add_filter(
'googlesitekit_rest_routes',
function ( $routes ) {
return array_merge( $routes, $this->get_rest_routes() );
}
);
add_filter(
'googlesitekit_apifetch_preload_paths',
function ( $paths ) {
return array_merge(
$paths,
array(
'/' . REST_Routes::REST_ROOT . '/core/user/data/initial-setup-settings',
)
);
}
);
}
/**
* Gets REST route instances.
*
* @since 1.164.0
*
* @return REST_Route[] List of REST_Route objects.
*/
protected function get_rest_routes() {
$can_setup = function () {
return current_user_can( Permissions::SETUP );
};
return array(
new REST_Route(
'core/user/data/initial-setup-settings',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => function () {
return new WP_REST_Response( $this->initial_setup_settings->get() );
},
'permission_callback' => $can_setup,
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => function ( WP_REST_Request $request ) {
$settings = $request['data']['settings'];
$this->initial_setup_settings->merge( $settings );
return new WP_REST_Response( $this->initial_setup_settings->get() );
},
'permission_callback' => $can_setup,
'args' => array(
'data' => array(
'type' => 'object',
'required' => true,
'properties' => array(
'settings' => array(
'type' => 'object',
'required' => true,
'minProperties' => 1,
'additionalProperties' => false,
'properties' => array(
'isAnalyticsSetupComplete' => array(
'type' => 'boolean',
),
),
),
),
),
),
),
)
),
);
}
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* Class Google\Site_Kit\Core\User\User
*
* @package Google\Site_Kit\Core\User
* @copyright 2024 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\User;
use Google\Site_Kit\Core\Storage\User_Options;
use Google\Site_Kit\Core\Util\Feature_Flags;
/**
* Class for handling user settings rest routes.
*
* @since 1.134.0
* @access private
* @ignore
*/
class User {
/**
* Audience_Segmentation instance.
*
* @since 1.134.0
* @var Audience_Segmentation
*/
private $audience_segmentation;
/**
* Conversion_Reporting instance.
*
* @since 1.144.0
* @var Conversion_Reporting
*/
private $conversion_reporting;
/**
* Email_Reporting instance.
*
* @since 1.162.0
* @var Email_Reporting
*/
private $email_reporting;
/**
* Initial_Setup instance.
*
* @since 1.164.0
* @var Initial_Setup
*/
private $initial_setup;
/**
* Constructor.
*
* @since 1.134.0
* @since 1.162.0 Added Email Reporting.
* @since 1.164.0 Added Initial Setup.
*
* @param User_Options $user_options User_Options instance.
*/
public function __construct( User_Options $user_options ) {
$this->audience_segmentation = new Audience_Segmentation( $user_options );
$this->conversion_reporting = new Conversion_Reporting( $user_options );
if ( Feature_Flags::enabled( 'proactiveUserEngagement' ) ) {
$this->email_reporting = new Email_Reporting( $user_options );
}
if ( Feature_Flags::enabled( 'setupFlowRefresh' ) ) {
$this->initial_setup = new Initial_Setup( $user_options );
}
}
/**
* Registers functionality through WordPress hooks.
*
* @since 1.134.0
* @since 1.162.0 Added Email Reporting.
* @since 1.164.0 Added Initial Setup.
*/
public function register() {
$this->audience_segmentation->register();
$this->conversion_reporting->register();
if ( Feature_Flags::enabled( 'proactiveUserEngagement' ) && $this->email_reporting ) {
$this->email_reporting->register();
}
if ( Feature_Flags::enabled( 'setupFlowRefresh' ) ) {
$this->initial_setup->register();
}
}
}