Full Site Editing - Version 3.5358

Version Description

Download this release

Release Info

Developer fullofcaffeine
Plugin Icon wp plugin Full Site Editing
Version 3.5358
Comparing to
See all releases

Code changes from version 3.5313 to 3.5358

error-reporting/dist/error-reporting.asset.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php return array('dependencies' => array('wp-api-fetch', 'wp-polyfill'), 'version' => '3a70bc7ec9e6671562069d308d13e351');
error-reporting/dist/error-reporting.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(){"use strict";var r={606:function(r){r.exports=window.wp.apiFetch}},e={};function t(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return r[n](i,i.exports,t),i.exports}t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,{a:e}),e},t.d=function(r,e){for(var n in e)t.o(e,n)&&!t.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:e[n]})},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})};var n={};!function(){t.r(n);var r=t(606),e=t.n(r),o=window._jsErr||[],i=window._headJsErrorHandler,a=function(r){var t=r.error,n={message:t.message,trace:t.stack,url:document.location.href,feature:"wp-admin"};return e()({global:!0,path:"/rest/v1.1/js-error",method:"POST",data:{error:JSON.stringify(n)}}).catch((function(){return console.error("Error: Unable to record the error in Logstash.")}))};window.addEventListener("error",a),window.removeEventListener("error",i),delete window._headJsErrorHandler,Promise.allSettled(o.map(a)).then((function(){return delete window._jsErr}))}(),window.EditingToolkit=n}();
error-reporting/index.js ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import apiFetch from '@wordpress/api-fetch';
5
+
6
+ /**
7
+ * Errors that happened before this script had a chance to load
8
+ * are captured in a global array. See `./index.php`.
9
+ */
10
+ const headErrors = window._jsErr || [];
11
+ const headErrorHandler = window._headJsErrorHandler;
12
+
13
+ const reportError = ( { error } ) => {
14
+ const data = {
15
+ message: error.message,
16
+ trace: error.stack,
17
+ url: document.location.href,
18
+ feature: 'wp-admin',
19
+ };
20
+
21
+ return (
22
+ apiFetch( {
23
+ global: true,
24
+ path: '/rest/v1.1/js-error',
25
+ method: 'POST',
26
+ data: { error: JSON.stringify( data ) },
27
+ } )
28
+ // eslint-disable-next-line no-console
29
+ .catch( () => console.error( 'Error: Unable to record the error in Logstash.' ) )
30
+ );
31
+ };
32
+
33
+ window.addEventListener( 'error', reportError );
34
+
35
+ // Remove the head handler as it's not needed anymore after we set the main one above
36
+ window.removeEventListener( 'error', headErrorHandler );
37
+ delete window._headJsErrorHandler;
38
+
39
+ // We still need to report the head errors, if any.
40
+ Promise.allSettled( headErrors.map( reportError ) ).then( () => delete window._jsErr );
error-reporting/index.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Error reporting from wp-admin / Gutenberg context for simple sites and Atomic.
4
+ *
5
+ * @package A8C\FSE
6
+ */
7
+
8
+ namespace A8C\FSE\ErrorReporting;
9
+
10
+ /**
11
+ * Inline error handler that will capture errors before
12
+ * the main handler has a chance to. Errors are pushed
13
+ * to a global array called `_jsErr` which is then verified
14
+ * in the main handler. See `./index.js`.
15
+ */
16
+ function head_error_handler() {
17
+ ?><script type="text/javascript">
18
+ window._headJsErrorHandler = function( errEvent ) {
19
+ console.log(errEvent);
20
+ window._jsErr = window._jsErr || [];
21
+ window._jsErr.push(errEvent);
22
+ }
23
+ window.addEventListener( 'error', window._headJsErrorHandler );
24
+ </script>
25
+ <?php
26
+ }
27
+
28
+ /**
29
+ * Limit the attribute to script els that point to scripts served from s0.wp.com.
30
+ * We might want to add stats.wp.com and widgets.wp.com here, too. See: https://wp.me/pMz3w-cCq#comment-86959.
31
+ * "Staticized" (aka minified or concatenaded) scripts don't go through this pipeline, so they are not processed
32
+ * by this filter. The attribute is added to those directly in jsconcat, see D57238-code.
33
+ *
34
+ * @param {string} $tag string containing the def of a script tag.
35
+ */
36
+ function add_crossorigin_to_script_els( $tag ) {
37
+ // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
38
+ if ( preg_match( '/<script\s.*src=.*s0\.wp\.com.*>/', $tag ) ) {
39
+ return str_replace( ' src', " crossorigin='anonymous' src", $tag );
40
+ };
41
+ return $tag;
42
+ }
43
+
44
+ /**
45
+ * Enqueue assets
46
+ */
47
+ function enqueue_script() {
48
+ $asset_file = include plugin_dir_path( __FILE__ ) . 'dist/error-reporting.asset.php';
49
+ $script_dependencies = isset( $asset_file['dependencies'] ) ? $asset_file['dependencies'] : array();
50
+ $script_version = isset( $asset_file['version'] ) ? $asset_file['version'] : filemtime( plugin_dir_path( __FILE__ ) . 'dist/error-reporting.js' );
51
+
52
+ wp_enqueue_script(
53
+ 'a8c-fse-error-reporting-script',
54
+ plugins_url( 'dist/error-reporting.js', __FILE__ ),
55
+ $script_dependencies,
56
+ $script_version,
57
+ true
58
+ );
59
+ }
60
+
61
+ /**
62
+ * Effectivelly activates the error reporting module by setting the necessary hooks.
63
+ */
64
+ function activate_error_reporting() {
65
+ add_action( 'admin_print_scripts', __NAMESPACE__ . '\head_error_handler' );
66
+ add_filter( 'script_loader_tag', __NAMESPACE__ . '\add_crossorigin_to_script_els', 99, 2 );
67
+ // We load as last as possible for perf reasons. The head handler will
68
+ // capture errors until the main handler is loaded.
69
+ add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\enqueue_script', 99 );
70
+ }
71
+
72
+ /**
73
+ * Temporary function to feature flag by segment. We'll be gradually testing
74
+ * it on production simple sites, observing how it works and and gradually
75
+ * increase the segment until we reach 100 and eventually just remove this logic.
76
+ *
77
+ * It's important to note that we'll only gradually roll-out for simple sites.
78
+ * Once we're confident enough it works well on simple-sites, we'll work on
79
+ * addressing issues that are preventing this module from working on WoA, test
80
+ * on real AT sites and finally deploy the plugin to WoA while removing the
81
+ * guard above that prevents it from loading on WoA. The reason for that in WoA
82
+ * it's actually trivial to test a custom build in production without affecting
83
+ * other customers, and on simple sites, it's not, hence the need for a gradual
84
+ * roll-out as an additional safety measure.
85
+ *
86
+ * @todo Remove once the roll-out is complete.
87
+ *
88
+ * @param int $user_id the user id.
89
+ * @return bool
90
+ */
91
+ function user_in_test_segment( $user_id ) {
92
+ $current_segment = 10; // segment of existing users that will get this feature.
93
+ $user_segment = $user_id % 100;
94
+
95
+ // We get the last two digits of the user id and that will be used to decide in what
96
+ // segment the user is. i.e if current_segment is 10, then only ids that end in < 10
97
+ // will be considered part of the segment.
98
+ return $user_segment < $current_segment;
99
+ }
100
+
101
+ /**
102
+ * Returns whether or not the user is an automattician, but first verifies
103
+ * if the function `is_automattician` exists in the current context. If not,
104
+ * then we consider the user to not be an automattician. This guard is needed
105
+ * because this function is not present in some envs, namely the testing env.
106
+ *
107
+ * @todo Remove once roll-out is complete
108
+ *
109
+ * @param int $user_id the user id.
110
+ * @return bool
111
+ */
112
+ function user_is_automattician( $user_id ) {
113
+ return function_exists( 'is_automattician' ) && is_automattician( $user_id );
114
+ }
115
+
116
+ /**
117
+ * Returns whether or not the site loading ETK is in the WoA env.
118
+ *
119
+ * @return bool
120
+ */
121
+ function is_atomic() {
122
+ return defined( 'IS_ATOMIC' ) && IS_ATOMIC;
123
+ }
124
+
125
+ // We don't want to activate this module in AT just yet. See https://wp.me/p4TIVU-9DI#comment-10922.
126
+ // @todo Remove once we have a version that works for WPCOM simple sites and WoA.
127
+ if ( ! is_atomic() ) {
128
+ // @todo Remove once the roll-out is complete.
129
+ $user_id = get_current_user_id();
130
+ if ( user_is_automattician( $user_id ) || user_in_test_segment( $user_id ) ) {
131
+ activate_error_reporting();
132
+ }
133
+ }
full-site-editing-plugin.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: WordPress.com Editing Toolkit
4
  * Description: Enhances your page creation workflow within the Block Editor.
5
- * Version: 3.5313
6
  * Author: Automattic
7
  * Author URI: https://automattic.com/wordpress-plugins/
8
  * License: GPLv2 or later
@@ -42,7 +42,7 @@ namespace A8C\FSE;
42
  *
43
  * @var string
44
  */
45
- define( 'A8C_ETK_PLUGIN_VERSION', '3.5313' );
46
 
47
  // Always include these helper files for dotcom FSE.
48
  require_once __DIR__ . '/dotcom-fse/helpers.php';
@@ -334,3 +334,11 @@ function load_whats_new() {
334
  require_once __DIR__ . '/whats-new/class-whats-new.php';
335
  }
336
  add_action( 'plugins_loaded', __NAMESPACE__ . '\load_whats_new' );
 
 
 
 
 
 
 
 
2
  /**
3
  * Plugin Name: WordPress.com Editing Toolkit
4
  * Description: Enhances your page creation workflow within the Block Editor.
5
+ * Version: 3.5358
6
  * Author: Automattic
7
  * Author URI: https://automattic.com/wordpress-plugins/
8
  * License: GPLv2 or later
42
  *
43
  * @var string
44
  */
45
+ define( 'A8C_ETK_PLUGIN_VERSION', '3.5358' );
46
 
47
  // Always include these helper files for dotcom FSE.
48
  require_once __DIR__ . '/dotcom-fse/helpers.php';
334
  require_once __DIR__ . '/whats-new/class-whats-new.php';
335
  }
336
  add_action( 'plugins_loaded', __NAMESPACE__ . '\load_whats_new' );
337
+
338
+ /**
339
+ * Error reporting for wp-admin / Gutenberg
340
+ */
341
+ function load_error_reporting() {
342
+ require_once __DIR__ . '/error-reporting/index.php';
343
+ }
344
+ add_action( 'plugins_loaded', __NAMESPACE__ . '\load_error_reporting' );
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: automattic
3
  Tags: block, blocks, editor, gutenberg, page
4
  Requires at least: 5.5
5
  Tested up to: 5.6
6
- Stable tag: 3.5313
7
  Requires PHP: 5.6.20
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
3
  Tags: block, blocks, editor, gutenberg, page
4
  Requires at least: 5.5
5
  Tested up to: 5.6
6
+ Stable tag: 3.5358
7
  Requires PHP: 5.6.20
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html