updated plugin Jetpack Protect
version 3.0.2
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
extends: [ require.resolve( 'jetpack-js-tools/eslintrc/react' ) ],
|
||||
};
|
@ -5,6 +5,53 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [2.3.7] - 2024-09-05
|
||||
### Changed
|
||||
- Internal updates.
|
||||
|
||||
## [2.3.6] - 2024-09-05
|
||||
### Changed
|
||||
- Updated package dependencies. [#39176]
|
||||
|
||||
### Fixed
|
||||
- Fixed script data not available in block editor iframe [#39221]
|
||||
|
||||
## [2.3.5] - 2024-08-29
|
||||
### Changed
|
||||
- Updated package dependencies. [#39111]
|
||||
|
||||
## [2.3.4] - 2024-08-23
|
||||
### Changed
|
||||
- Updated package dependencies. [#39004]
|
||||
|
||||
## [2.3.3] - 2024-08-21
|
||||
### Changed
|
||||
- i18n loader script & React JSX runtime: load scripts in the footer. [#38929]
|
||||
|
||||
## [2.3.2] - 2024-08-15
|
||||
### Changed
|
||||
- Updated package dependencies. [#38662]
|
||||
|
||||
## [2.3.1] - 2024-08-12
|
||||
### Fixed
|
||||
- Fixed variable names. [#38606]
|
||||
|
||||
## [2.3.0] - 2024-08-08
|
||||
### Added
|
||||
- Added jetpack-initial-state package to consolidate the logic for Initial state. [#38430]
|
||||
|
||||
## [2.2.0] - 2024-07-23
|
||||
### Added
|
||||
- Assets: Add JSX runtime polyfill `react-jsx-runtime` for WordPress < 6.6. [#38428]
|
||||
|
||||
## [2.1.13] - 2024-07-03
|
||||
### Changed
|
||||
- Updated package dependencies. [#38132]
|
||||
|
||||
## [2.1.12] - 2024-06-05
|
||||
### Changed
|
||||
- Updated package dependencies. [#37669]
|
||||
|
||||
## [2.1.11] - 2024-05-20
|
||||
### Changed
|
||||
- Internal updates.
|
||||
@ -450,6 +497,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
- Statically access asset tools
|
||||
|
||||
[2.3.7]: https://github.com/Automattic/jetpack-assets/compare/v2.3.6...v2.3.7
|
||||
[2.3.6]: https://github.com/Automattic/jetpack-assets/compare/v2.3.5...v2.3.6
|
||||
[2.3.5]: https://github.com/Automattic/jetpack-assets/compare/v2.3.4...v2.3.5
|
||||
[2.3.4]: https://github.com/Automattic/jetpack-assets/compare/v2.3.3...v2.3.4
|
||||
[2.3.3]: https://github.com/Automattic/jetpack-assets/compare/v2.3.2...v2.3.3
|
||||
[2.3.2]: https://github.com/Automattic/jetpack-assets/compare/v2.3.1...v2.3.2
|
||||
[2.3.1]: https://github.com/Automattic/jetpack-assets/compare/v2.3.0...v2.3.1
|
||||
[2.3.0]: https://github.com/Automattic/jetpack-assets/compare/v2.2.0...v2.3.0
|
||||
[2.2.0]: https://github.com/Automattic/jetpack-assets/compare/v2.1.13...v2.2.0
|
||||
[2.1.13]: https://github.com/Automattic/jetpack-assets/compare/v2.1.12...v2.1.13
|
||||
[2.1.12]: https://github.com/Automattic/jetpack-assets/compare/v2.1.11...v2.1.12
|
||||
[2.1.11]: https://github.com/Automattic/jetpack-assets/compare/v2.1.10...v2.1.11
|
||||
[2.1.10]: https://github.com/Automattic/jetpack-assets/compare/v2.1.9...v2.1.10
|
||||
[2.1.9]: https://github.com/Automattic/jetpack-assets/compare/v2.1.8...v2.1.9
|
||||
|
@ -9,6 +9,7 @@
|
||||
// drop data into `$wp_filter` for `WP_Hook::build_preinitialized_hooks()`.
|
||||
if ( function_exists( 'add_action' ) ) {
|
||||
add_action( 'wp_default_scripts', array( Automattic\Jetpack\Assets::class, 'wp_default_scripts_hook' ) );
|
||||
add_action( 'plugins_loaded', array( Automattic\Jetpack\Assets\Script_Data::class, 'configure' ), 1 );
|
||||
} else {
|
||||
global $wp_filter;
|
||||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
@ -16,4 +17,9 @@ if ( function_exists( 'add_action' ) ) {
|
||||
'accepted_args' => 1,
|
||||
'function' => array( Automattic\Jetpack\Assets::class, 'wp_default_scripts_hook' ),
|
||||
);
|
||||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
$wp_filter['plugins_loaded'][1][] = array(
|
||||
'accepted_args' => 0,
|
||||
'function' => array( Automattic\Jetpack\Assets\Script_Data::class, 'configure' ),
|
||||
);
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
<?php return array('dependencies' => array('wp-i18n'), 'version' => 'b5d2a25bb8ad1698db1c');
|
||||
<?php return array('dependencies' => array('wp-i18n'), 'version' => 'becd7d9884bc1b331e45');
|
||||
|
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array(), 'version' => '0274966690f87adbeccb');
|
@ -0,0 +1 @@
|
||||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.JetpackScriptDataModule=t():e.JetpackScriptDataModule=t()}(self,(()=>(()=>{var e={729:(e,t,r)=>{"use strict";r.r(t),r.d(t,{getActiveFeatures:()=>a.mH,getAdminUrl:()=>a.hT,getJetpackAdminPageUrl:()=>a.oQ,getMyJetpackUrl:()=>a.e5,getScriptData:()=>a.au,getSiteData:()=>a.sV});var o=r(428),n={};for(const e in o)"default"!==e&&(n[e]=()=>o[e]);r.d(t,n);var a=r(336)},428:()=>{},336:(e,t,r)=>{"use strict";function o(){return window.JetpackScriptData}function n(){return o().site}function a(e=""){return`${o().site.admin_url}${e}`}function i(e=""){return a(`admin.php?page=jetpack${e}`)}function u(e=""){return a(`admin.php?page=my-jetpack${e}`)}function p(){return o().site.plan?.features?.active??[]}r.d(t,{au:()=>o,e5:()=>u,hT:()=>a,mH:()=>p,oQ:()=>i,sV:()=>n})}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,r),a.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{"use strict";r.r(o);var e=r(729),t={};for(const r in e)"default"!==r&&(t[r]=()=>e[r]);r.d(o,t)})(),o})()));
|
@ -0,0 +1,2 @@
|
||||
/*! For license information please see react-jsx-runtime.js.LICENSE.txt */
|
||||
(()=>{"use strict";var r={572:(r,e,t)=>{var o=t(609),n=Symbol.for("react.element"),s=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,f=o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function _(r,e,t){var o,s={},_=null,i=null;for(o in void 0!==t&&(_=""+t),void 0!==e.key&&(_=""+e.key),void 0!==e.ref&&(i=e.ref),e)a.call(e,o)&&!p.hasOwnProperty(o)&&(s[o]=e[o]);if(r&&r.defaultProps)for(o in e=r.defaultProps)void 0===s[o]&&(s[o]=e[o]);return{$$typeof:n,type:r,key:_,ref:i,props:s,_owner:f.current}}e.Fragment=s,e.jsx=_,e.jsxs=_},48:(r,e,t)=>{r.exports=t(572)},609:r=>{r.exports=window.React}},e={},t=function t(o){var n=e[o];if(void 0!==n)return n.exports;var s=e[o]={exports:{}};return r[o](s,s.exports,t),s.exports}(48);window.ReactJSXRuntime=t})();
|
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @license React
|
||||
* react-jsx-runtime.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
@ -5,12 +5,12 @@
|
||||
"license": "GPL-2.0-or-later",
|
||||
"require": {
|
||||
"php": ">=7.0",
|
||||
"automattic/jetpack-constants": "^2.0.2"
|
||||
"automattic/jetpack-constants": "^2.0.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"brain/monkey": "2.6.1",
|
||||
"yoast/phpunit-polyfills": "1.1.0",
|
||||
"automattic/jetpack-changelogger": "^4.2.4",
|
||||
"yoast/phpunit-polyfills": "^1.1.1",
|
||||
"automattic/jetpack-changelogger": "^4.2.6",
|
||||
"wikimedia/testing-access-wrapper": "^1.0 || ^2.0 || ^3.0"
|
||||
},
|
||||
"suggest": {
|
||||
@ -51,7 +51,7 @@
|
||||
"link-template": "https://github.com/Automattic/jetpack-assets/compare/v${old}...v${new}"
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-trunk": "2.1.x-dev"
|
||||
"dev-trunk": "2.3.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,9 +109,8 @@ class Assets {
|
||||
*/
|
||||
public static function enqueue_async_script( $handle, $min_path, $non_min_path, $deps = array(), $ver = false, $in_footer = true ) {
|
||||
_deprecated_function( __METHOD__, '2.1.0' );
|
||||
$assets_instance = self::instance();
|
||||
$assets_instance->add_async_script( $handle );
|
||||
wp_enqueue_script( $handle, self::get_file_url_for_environment( $min_path, $non_min_path ), $deps, $ver, $in_footer );
|
||||
wp_script_add_data( $handle, 'strategy', 'defer' );
|
||||
}
|
||||
|
||||
// endregion .
|
||||
@ -258,11 +257,11 @@ class Assets {
|
||||
$ret = '';
|
||||
$ret .= isset( $parts['scheme'] ) ? $parts['scheme'] . '://' : '';
|
||||
if ( isset( $parts['user'] ) || isset( $parts['pass'] ) ) {
|
||||
$ret .= isset( $parts['user'] ) ? $parts['user'] : '';
|
||||
$ret .= $parts['user'] ?? '';
|
||||
$ret .= isset( $parts['pass'] ) ? ':' . $parts['pass'] : '';
|
||||
$ret .= '@';
|
||||
}
|
||||
$ret .= isset( $parts['host'] ) ? $parts['host'] : '';
|
||||
$ret .= $parts['host'] ?? '';
|
||||
$ret .= isset( $parts['port'] ) ? ':' . $parts['port'] : '';
|
||||
|
||||
$pp = explode( '/', $parts['path'] );
|
||||
@ -323,6 +322,7 @@ class Assets {
|
||||
* - `strategy`: (string) Specify a script strategy to use, eg. `defer` or `async`. Default is `""`.
|
||||
* - `textdomain`: (string) Text domain for the script. Required if the script depends on wp-i18n.
|
||||
* - `version`: (string) Override the version from the `asset_path` file.
|
||||
* @phan-param array{asset_path?:?string,async?:bool,css_dependencies?:string[],css_path?:?string,dependencies?:string[],enqueue?:bool,in_footer?:bool,media?:string,minify?:?bool,nonmin_path?:string,strategy?:string,textdomain?:string,version?:string} $options
|
||||
* @throws \InvalidArgumentException If arguments are invalid.
|
||||
*/
|
||||
public static function register_script( $handle, $path, $relative_to, array $options = array() ) {
|
||||
@ -349,8 +349,9 @@ class Assets {
|
||||
'strategy' => '',
|
||||
'textdomain' => null,
|
||||
);
|
||||
'@phan-var array{asset_path:?string,async:bool,css_dependencies:string[],css_path:?string,dependencies:string[],enqueue:bool,in_footer:bool,media:string,minify:?bool,nonmin_path?:string,strategy:string,textdomain:string,version?:string} $options'; // Phan gets confused by the array addition.
|
||||
|
||||
if ( $options['css_path'] && substr( $options['css_path'], -4 ) !== '.css' ) {
|
||||
if ( is_string( $options['css_path'] ) && $options['css_path'] !== '' && substr( $options['css_path'], -4 ) !== '.css' ) {
|
||||
throw new \InvalidArgumentException( '$options[\'css_path\'] must end in ".css"' );
|
||||
}
|
||||
|
||||
@ -376,9 +377,10 @@ class Assets {
|
||||
),
|
||||
$options['css_dependencies']
|
||||
);
|
||||
$ver = isset( $options['version'] ) ? $options['version'] : $asset['version'];
|
||||
$ver = $options['version'] ?? $asset['version'];
|
||||
} else {
|
||||
$ver = isset( $options['version'] ) ? $options['version'] : filemtime( "$dir/$path" );
|
||||
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
||||
$ver = $options['version'] ?? @filemtime( "$dir/$path" );
|
||||
}
|
||||
|
||||
if ( $options['async'] && '' === $options['strategy'] ) { // Handle the deprecated `async` option
|
||||
@ -407,7 +409,7 @@ class Assets {
|
||||
);
|
||||
}
|
||||
|
||||
if ( $options['css_path'] && file_exists( "$dir/{$options['css_path']}" ) ) {
|
||||
if ( is_string( $options['css_path'] ) && $options['css_path'] !== '' && file_exists( "$dir/{$options['css_path']}" ) ) {
|
||||
$csspath = $options['css_path'];
|
||||
if ( is_rtl() ) {
|
||||
$rtlcsspath = substr( $csspath, 0, -4 ) . '.rtl.css';
|
||||
@ -508,26 +510,39 @@ class Assets {
|
||||
}
|
||||
$url = self::normalize_path( plugins_url( $path, __FILE__ ) );
|
||||
$url = add_query_arg( 'minify', 'true', $url );
|
||||
$wp_scripts->add( 'wp-jp-i18n-loader', $url, $asset['dependencies'], $asset['version'] );
|
||||
|
||||
$handle = 'wp-jp-i18n-loader';
|
||||
|
||||
$wp_scripts->add( $handle, $url, $asset['dependencies'], $asset['version'] );
|
||||
|
||||
// Ensure the script is loaded in the footer and deferred.
|
||||
$wp_scripts->add_data( $handle, 'group', 1 );
|
||||
|
||||
if ( ! is_array( $data ) ||
|
||||
! isset( $data['baseUrl'] ) || ! ( is_string( $data['baseUrl'] ) || false === $data['baseUrl'] ) ||
|
||||
! isset( $data['locale'] ) || ! is_string( $data['locale'] ) ||
|
||||
! isset( $data['domainMap'] ) || ! is_array( $data['domainMap'] ) ||
|
||||
! isset( $data['domainPaths'] ) || ! is_array( $data['domainPaths'] )
|
||||
) {
|
||||
$wp_scripts->add_inline_script( 'wp-jp-i18n-loader', 'console.warn( "I18n state deleted by jetpack_i18n_state hook" );' );
|
||||
$wp_scripts->add_inline_script( $handle, 'console.warn( "I18n state deleted by jetpack_i18n_state hook" );' );
|
||||
} elseif ( ! $data['baseUrl'] ) {
|
||||
$wp_scripts->add_inline_script( 'wp-jp-i18n-loader', 'console.warn( "Failed to determine languages base URL. Is WP_LANG_DIR in the WordPress root?" );' );
|
||||
$wp_scripts->add_inline_script( $handle, 'console.warn( "Failed to determine languages base URL. Is WP_LANG_DIR in the WordPress root?" );' );
|
||||
} else {
|
||||
$data['domainMap'] = (object) $data['domainMap']; // Ensure it becomes a json object.
|
||||
$data['domainPaths'] = (object) $data['domainPaths']; // Ensure it becomes a json object.
|
||||
$wp_scripts->add_inline_script( 'wp-jp-i18n-loader', 'wp.jpI18nLoader.state = ' . wp_json_encode( $data, JSON_UNESCAPED_SLASHES ) . ';' );
|
||||
$wp_scripts->add_inline_script( $handle, 'wp.jpI18nLoader.state = ' . wp_json_encode( $data, JSON_UNESCAPED_SLASHES ) . ';' );
|
||||
}
|
||||
|
||||
// Deprecated state module: Depend on wp-i18n to ensure global `wp` exists and because anything needing this will need that too.
|
||||
$wp_scripts->add( 'wp-jp-i18n-state', false, array( 'wp-deprecated', 'wp-jp-i18n-loader' ) );
|
||||
$wp_scripts->add( 'wp-jp-i18n-state', false, array( 'wp-deprecated', $handle ) );
|
||||
$wp_scripts->add_inline_script( 'wp-jp-i18n-state', 'wp.deprecated( "wp-jp-i18n-state", { alternative: "wp-jp-i18n-loader" } );' );
|
||||
$wp_scripts->add_inline_script( 'wp-jp-i18n-state', 'wp.jpI18nState = wp.jpI18nLoader.state;' );
|
||||
|
||||
// Register the React JSX runtime script - used as a polyfill until we can update JSX transforms. See https://github.com/Automattic/jetpack/issues/38424.
|
||||
// @todo Remove this when we drop support for WordPress 6.5, as well as the script inclusion in test_wp_default_scripts_hook.
|
||||
$jsx_url = self::normalize_path( plugins_url( '../build/react-jsx-runtime.js', __FILE__ ) );
|
||||
$wp_scripts->add( 'react-jsx-runtime', $jsx_url, array( 'react' ), '18.3.1', true );
|
||||
$wp_scripts->add_data( 'react-jsx-runtime', 'group', 1 );
|
||||
}
|
||||
|
||||
// endregion .
|
||||
@ -667,7 +682,7 @@ class Assets {
|
||||
* @param string $translation Translated text.
|
||||
* @param string $single The text to be used if the number is singular.
|
||||
* @param string $plural The text to be used if the number is plural.
|
||||
* @param string $number The number to compare against to use either the singular or plural form.
|
||||
* @param int $number The number to compare against to use either the singular or plural form.
|
||||
* @param string $domain Text domain.
|
||||
* @return string Translated text.
|
||||
*/
|
||||
@ -704,7 +719,7 @@ class Assets {
|
||||
* @param string $translation Translated text.
|
||||
* @param string $single The text to be used if the number is singular.
|
||||
* @param string $plural The text to be used if the number is plural.
|
||||
* @param string $number The number to compare against to use either the singular or plural form.
|
||||
* @param int $number The number to compare against to use either the singular or plural form.
|
||||
* @param string $context Context information for the translators.
|
||||
* @param string $domain Text domain.
|
||||
* @return string Translated text.
|
||||
|
@ -0,0 +1,220 @@
|
||||
<?php
|
||||
/**
|
||||
* Jetpack script data.
|
||||
*
|
||||
* @package automattic/jetpack-assets
|
||||
*/
|
||||
|
||||
namespace Automattic\Jetpack\Assets;
|
||||
|
||||
use Automattic\Jetpack\Assets;
|
||||
|
||||
/**
|
||||
* Class script data
|
||||
*/
|
||||
class Script_Data {
|
||||
|
||||
const SCRIPT_HANDLE = 'jetpack-script-data';
|
||||
|
||||
/**
|
||||
* Whether the script data has been rendered.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private static $did_render_script_data = false;
|
||||
|
||||
/**
|
||||
* Configure.
|
||||
*/
|
||||
public static function configure() {
|
||||
/**
|
||||
* Ensure that assets are registered on wp_loaded,
|
||||
* which is fired before *_enqueue_scripts actions.
|
||||
* It means that when the dependent scripts are registered,
|
||||
* the scripts here are already registered.
|
||||
*/
|
||||
add_action( 'wp_loaded', array( self::class, 'register_assets' ) );
|
||||
|
||||
/**
|
||||
* Notes:
|
||||
* 1. wp_print_scripts action is fired on both admin and public pages.
|
||||
* On admin pages, it's fired before admin_enqueue_scripts action,
|
||||
* which can be a problem if the consumer package uses admin_enqueue_scripts
|
||||
* to hook into the script data. Thus, we prefer to use admin_print_scripts on admin pages.
|
||||
* 2. We want to render the script data on print, instead of init or enqueue actions,
|
||||
* so that the hook callbacks have enough time and information
|
||||
* to decide whether to update the script data or not.
|
||||
*/
|
||||
$hook = is_admin() ? 'admin_print_scripts' : 'wp_print_scripts';
|
||||
add_action( $hook, array( self::class, 'render_script_data' ), 1 );
|
||||
add_action( 'enqueue_block_editor_assets', array( self::class, 'render_script_data' ), 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register assets.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
public static function register_assets() {
|
||||
|
||||
Assets::register_script(
|
||||
self::SCRIPT_HANDLE,
|
||||
'../build/jetpack-script-data.js',
|
||||
__FILE__,
|
||||
array(
|
||||
'in_footer' => true,
|
||||
'textdomain' => 'jetpack-assets',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the script data using an inline script.
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function render_script_data() {
|
||||
// In case of 'enqueue_block_editor_assets' action, this can be called multiple times.
|
||||
if ( self::$did_render_script_data ) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::$did_render_script_data = true;
|
||||
|
||||
$script_data = is_admin() ? self::get_admin_script_data() : self::get_public_script_data();
|
||||
|
||||
$script_data = wp_json_encode(
|
||||
$script_data,
|
||||
JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE
|
||||
);
|
||||
|
||||
wp_add_inline_script(
|
||||
self::SCRIPT_HANDLE,
|
||||
sprintf( 'window.JetpackScriptData = %s;', $script_data ),
|
||||
'before'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the admin script data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function get_admin_script_data() {
|
||||
|
||||
global $wp_version;
|
||||
|
||||
$data = array(
|
||||
'site' => array(
|
||||
'admin_url' => esc_url_raw( admin_url() ),
|
||||
'date_format' => get_option( 'date_format' ),
|
||||
'icon' => self::get_site_icon(),
|
||||
'is_multisite' => is_multisite(),
|
||||
'plan' => array(
|
||||
// The properties here should be updated by the consumer package/plugin.
|
||||
// It includes properties like 'product_slug', 'features', etc.
|
||||
'product_slug' => '',
|
||||
),
|
||||
'rest_nonce' => wp_create_nonce( 'wp_rest' ),
|
||||
'rest_root' => esc_url_raw( rest_url() ),
|
||||
'title' => self::get_site_title(),
|
||||
'wp_version' => $wp_version,
|
||||
'wpcom' => array(
|
||||
// This should contain the connected site details like blog_id, is_atomic etc.
|
||||
'blog_id' => 0,
|
||||
),
|
||||
),
|
||||
'user' => array(
|
||||
'current_user' => self::get_current_user_data(),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter the admin script data.
|
||||
*
|
||||
* When using this filter, ensure that the data is added only if it is used by some script.
|
||||
* This filter may be called on almost every admin page load. So, one should check if the data is needed/used on that page.
|
||||
* For example, the social (publicize) data is used only on Social admin page, Jetpack settings page and the post editor.
|
||||
* So, the social data should be added only on those pages.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*
|
||||
* @param array $data The script data.
|
||||
*/
|
||||
return apply_filters( 'jetpack_admin_js_script_data', $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the admin script data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function get_public_script_data() {
|
||||
|
||||
$data = array(
|
||||
'site' => array(
|
||||
'icon' => self::get_site_icon(),
|
||||
'title' => self::get_site_title(),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Filter the public script data.
|
||||
*
|
||||
* See the docs for `jetpack_admin_js_script_data` filter for more information.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*
|
||||
* @param array $data The script data.
|
||||
*/
|
||||
return apply_filters( 'jetpack_public_js_script_data', $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the site title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function get_site_title() {
|
||||
$title = get_bloginfo( 'name' );
|
||||
|
||||
return $title ? $title : esc_url_raw( ( get_site_url() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the site icon.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function get_site_icon() {
|
||||
if ( ! has_site_icon() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the site icon using Photon.
|
||||
*
|
||||
* @see https://developer.wordpress.com/docs/photon/
|
||||
*
|
||||
* @param string $url The URL of the site icon.
|
||||
* @param array|string $args An array of arguments, e.g. array( 'w' => '300', 'resize' => array( 123, 456 ) ), or in string form (w=123&h=456).
|
||||
*/
|
||||
return apply_filters( 'jetpack_photon_url', get_site_icon_url(), array( 'w' => 64 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current user data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function get_current_user_data() {
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
return array(
|
||||
'display_name' => $current_user->display_name,
|
||||
'id' => $current_user->ID,
|
||||
);
|
||||
}
|
||||
}
|
@ -102,7 +102,7 @@ class Semver {
|
||||
if ( ctype_digit( $a ) ) {
|
||||
if ( ctype_digit( $b ) ) {
|
||||
if ( (int) $a !== (int) $b ) {
|
||||
return $a - $b;
|
||||
return (int) $a - (int) $b;
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
|
@ -20,10 +20,10 @@ module.exports = {
|
||||
/**
|
||||
* Download and register translations for a bundle.
|
||||
*
|
||||
* @param {string} path - Bundle path being fetched. May have a query part.
|
||||
* @param {string} domain - Text domain to register into.
|
||||
* @param {string} path - Bundle path being fetched. May have a query part.
|
||||
* @param {string} domain - Text domain to register into.
|
||||
* @param {string} location - Location for the translation: 'plugin', 'theme', or 'core'.
|
||||
* @returns {Promise} Resolved when the translations are registered, or rejected with an `Error`.
|
||||
* @return {Promise} Resolved when the translations are registered, or rejected with an `Error`.
|
||||
*/
|
||||
async downloadI18n( path, domain, location ) {
|
||||
const state = this.state;
|
||||
|
@ -0,0 +1 @@
|
||||
export * from '@automattic/jetpack-script-data';
|
Reference in New Issue
Block a user