Version Description
Download this release
Release Info
Developer | wojtekn |
Plugin | Full Site Editing |
Version | 3.49470 |
Comparing to | |
See all releases |
Code changes from version 3.49426 to 3.49470
- build_meta.txt +3 -3
- coming-soon/coming-soon.php +77 -0
- coming-soon/test/class-coming-soon-test.php +107 -0
- full-site-editing-plugin.php +2 -2
- readme.txt +1 -1
build_meta.txt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
commit_hash=
|
2 |
-
commit_url=https://github.com/Automattic/wp-calypso/commit/
|
3 |
-
build_number=3.
|
1 |
+
commit_hash=335d233bff622602d808116430d7ad4807736b79
|
2 |
+
commit_url=https://github.com/Automattic/wp-calypso/commit/335d233bff622602d808116430d7ad4807736b79
|
3 |
+
build_number=3.49470
|
coming-soon/coming-soon.php
CHANGED
@@ -17,6 +17,13 @@ function should_show_coming_soon_page() {
|
|
17 |
return false;
|
18 |
}
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
$should_show = ( (int) get_option( 'wpcom_public_coming_soon' ) === 1 );
|
21 |
|
22 |
// Everyone from Administrator to Subscriber will be able to see the site.
|
@@ -31,6 +38,76 @@ function should_show_coming_soon_page() {
|
|
31 |
return apply_filters( 'a8c_show_coming_soon_page', $should_show );
|
32 |
}
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
/**
|
35 |
* Renders a fallback coming soon page
|
36 |
*/
|
17 |
return false;
|
18 |
}
|
19 |
|
20 |
+
$share_code = get_share_code();
|
21 |
+
if ( is_accessed_by_valid_share_link( $share_code ) ) {
|
22 |
+
track_preview_link_event();
|
23 |
+
setcookie( 'wp_share_code', $share_code, time() + 3600, '/', false, is_ssl() );
|
24 |
+
return false;
|
25 |
+
}
|
26 |
+
|
27 |
$should_show = ( (int) get_option( 'wpcom_public_coming_soon' ) === 1 );
|
28 |
|
29 |
// Everyone from Administrator to Subscriber will be able to see the site.
|
38 |
return apply_filters( 'a8c_show_coming_soon_page', $should_show );
|
39 |
}
|
40 |
|
41 |
+
/**
|
42 |
+
* Gets share code from URL or Cookie.
|
43 |
+
*
|
44 |
+
* @return string
|
45 |
+
*/
|
46 |
+
function get_share_code() {
|
47 |
+
if ( isset( $_GET['share'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
48 |
+
return $_GET['share']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
49 |
+
} elseif ( isset( $_COOKIE['wp_share_code'] ) ) {
|
50 |
+
return $_COOKIE['wp_share_code'];
|
51 |
+
}
|
52 |
+
return '';
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Determines whether the coming soon page should be bypassed.
|
57 |
+
*
|
58 |
+
* It checks if share code is provided as GET parameter, or as a cookie.
|
59 |
+
* Then it validates the code against blog option, and if sharing code is valid,
|
60 |
+
* it allows bypassing the Coming Soon page.
|
61 |
+
*
|
62 |
+
* Finally, it sets a code in cookie and sets header that prevents robots from indexing.
|
63 |
+
*
|
64 |
+
* @param string $share_code Share code to check against blog option value.
|
65 |
+
*
|
66 |
+
* @return bool
|
67 |
+
*/
|
68 |
+
function is_accessed_by_valid_share_link( $share_code ) {
|
69 |
+
$preview_links_option = get_option( 'wpcom_public_preview_links' );
|
70 |
+
|
71 |
+
if ( ! is_array( $preview_links_option ) || ! count( $preview_links_option ) || ! $share_code ) {
|
72 |
+
return false;
|
73 |
+
}
|
74 |
+
|
75 |
+
if ( ! in_array( $share_code, array_column( $preview_links_option, 'code' ), true ) ) {
|
76 |
+
return false;
|
77 |
+
}
|
78 |
+
|
79 |
+
return true;
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Add X-Robots-Tag header to prevent from indexing page that includes share code.
|
84 |
+
*
|
85 |
+
* @param array $headers Headers.
|
86 |
+
* @return array Headers.
|
87 |
+
*/
|
88 |
+
function maybe_add_x_robots_headers( $headers ) {
|
89 |
+
if ( get_share_code() ) {
|
90 |
+
$headers['X-Robots-Tag'] = 'noindex, nofollow';
|
91 |
+
}
|
92 |
+
return $headers;
|
93 |
+
}
|
94 |
+
add_filter( 'wp_headers', __NAMESPACE__ . '\maybe_add_x_robots_headers' );
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Track site preview event.
|
98 |
+
*
|
99 |
+
* @return void
|
100 |
+
*/
|
101 |
+
function track_preview_link_event() {
|
102 |
+
$event_name = 'wpcom_site_previewed';
|
103 |
+
if ( function_exists( 'wpcomsh_record_tracks_event' ) ) {
|
104 |
+
wpcomsh_record_tracks_event( $event_name, array() );
|
105 |
+
} else {
|
106 |
+
require_lib( 'tracks/client' );
|
107 |
+
tracks_record_event( get_current_user_id(), $event_name, array() );
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
/**
|
112 |
* Renders a fallback coming soon page
|
113 |
*/
|
coming-soon/test/class-coming-soon-test.php
CHANGED
@@ -15,6 +15,18 @@ require_once __DIR__ . '/../coming-soon.php';
|
|
15 |
* Class Coming_Soon_Test
|
16 |
*/
|
17 |
class Coming_Soon_Test extends TestCase {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
/**
|
19 |
* Post-test suite actions.
|
20 |
*/
|
@@ -23,6 +35,14 @@ class Coming_Soon_Test extends TestCase {
|
|
23 |
parent::tearDownAfterClass();
|
24 |
}
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
/**
|
27 |
* Add coming soon options.
|
28 |
*/
|
@@ -40,6 +60,28 @@ class Coming_Soon_Test extends TestCase {
|
|
40 |
delete_option( 'wpcom_public_coming_soon' );
|
41 |
}
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
/**
|
44 |
* Tests that we update the coming soon option when the public option moves
|
45 |
* from public not indexed to anything.
|
@@ -154,4 +196,69 @@ class Coming_Soon_Test extends TestCase {
|
|
154 |
do_action( 'wpmu_new_blog', get_current_blog_id(), null, null, null, null, $meta );
|
155 |
$this->assertFalse( get_option( 'wpcom_public_coming_soon' ) );
|
156 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
}
|
15 |
* Class Coming_Soon_Test
|
16 |
*/
|
17 |
class Coming_Soon_Test extends TestCase {
|
18 |
+
/**
|
19 |
+
* Preview links used to test bypassing Coming Soon using the URL with share code provided as GET parameter.
|
20 |
+
*
|
21 |
+
* @var \string[][]
|
22 |
+
*/
|
23 |
+
private static $preview_links = array(
|
24 |
+
array(
|
25 |
+
'code' => 'sharing-code',
|
26 |
+
'created_at' => '2022-11-23',
|
27 |
+
),
|
28 |
+
);
|
29 |
+
|
30 |
/**
|
31 |
* Post-test suite actions.
|
32 |
*/
|
35 |
parent::tearDownAfterClass();
|
36 |
}
|
37 |
|
38 |
+
/**
|
39 |
+
* Post-test actions.
|
40 |
+
*/
|
41 |
+
public function tearDown() {
|
42 |
+
self::delete_preview_links_parameters();
|
43 |
+
parent::tearDown();
|
44 |
+
}
|
45 |
+
|
46 |
/**
|
47 |
* Add coming soon options.
|
48 |
*/
|
60 |
delete_option( 'wpcom_public_coming_soon' );
|
61 |
}
|
62 |
|
63 |
+
/**
|
64 |
+
* Mock valid share code GET request
|
65 |
+
*/
|
66 |
+
private static function set_valid_share_code_get_parameter() {
|
67 |
+
$_GET['share'] = self::$preview_links[0]['code'];
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Mock valid share code COOKIE request
|
72 |
+
*/
|
73 |
+
private static function set_valid_share_code_cookie_parameter() {
|
74 |
+
$_COOKIE['wp_share_code'] = self::$preview_links[0]['code'];
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Remove share code from GET and COOKIE.
|
79 |
+
*/
|
80 |
+
private static function delete_preview_links_parameters() {
|
81 |
+
unset( $_GET['share'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
82 |
+
unset( $_COOKIE['wp_share_code'] );
|
83 |
+
}
|
84 |
+
|
85 |
/**
|
86 |
* Tests that we update the coming soon option when the public option moves
|
87 |
* from public not indexed to anything.
|
196 |
do_action( 'wpmu_new_blog', get_current_blog_id(), null, null, null, null, $meta );
|
197 |
$this->assertFalse( get_option( 'wpcom_public_coming_soon' ) );
|
198 |
}
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Tests that is_accessed_by_valid_share_link() returns true for requests
|
202 |
+
* that include valid preview link.
|
203 |
+
*
|
204 |
+
* @return void
|
205 |
+
*/
|
206 |
+
public function test_is_accessed_by_valid_share_link_success() {
|
207 |
+
update_option( 'wpcom_public_preview_links', self::$preview_links );
|
208 |
+
|
209 |
+
$result = is_accessed_by_valid_share_link( self::$preview_links[0]['code'] );
|
210 |
+
|
211 |
+
$this->assertTrue( $result );
|
212 |
+
}
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Tests that is_accessed_by_valid_share_link() returns false for requests
|
216 |
+
* that include invalid preview link.
|
217 |
+
*
|
218 |
+
* @return void
|
219 |
+
*/
|
220 |
+
public function test_is_accessed_by_valid_share_link_failure() {
|
221 |
+
update_option( 'wpcom_public_preview_links', self::$preview_links );
|
222 |
+
|
223 |
+
$result = is_accessed_by_valid_share_link( 'foo-bar' );
|
224 |
+
|
225 |
+
$this->assertFalse( $result );
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* Tests if get_share_code() return share code from GET param.
|
230 |
+
*
|
231 |
+
* @return void
|
232 |
+
*/
|
233 |
+
public function test_get_share_code_gets_code_from_get() {
|
234 |
+
self::set_valid_share_code_get_parameter();
|
235 |
+
|
236 |
+
$share_code = get_share_code();
|
237 |
+
|
238 |
+
$this->assertEquals( 'sharing-code', $share_code );
|
239 |
+
}
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Tests if get_share_code() return share code from COOKIE param.
|
243 |
+
*
|
244 |
+
* @return void
|
245 |
+
*/
|
246 |
+
public function test_get_share_code_gets_code_from_cookie() {
|
247 |
+
self::set_valid_share_code_cookie_parameter();
|
248 |
+
|
249 |
+
$share_code = get_share_code();
|
250 |
+
|
251 |
+
$this->assertEquals( 'sharing-code', $share_code );
|
252 |
+
}
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Tests if get_share_code() return empty share code if it's not set as GET or COOKIE parameter.
|
256 |
+
*
|
257 |
+
* @return void
|
258 |
+
*/
|
259 |
+
public function test_get_share_code_gets_empty_code_if_not_set() {
|
260 |
+
$share_code = get_share_code();
|
261 |
+
|
262 |
+
$this->assertSame( '', $share_code );
|
263 |
+
}
|
264 |
}
|
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.
|
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.
|
46 |
|
47 |
// Always include these helper files for dotcom FSE.
|
48 |
require_once __DIR__ . '/dotcom-fse/helpers.php';
|
2 |
/**
|
3 |
* Plugin Name: WordPress.com Editing Toolkit
|
4 |
* Description: Enhances your page creation workflow within the Block Editor.
|
5 |
+
* Version: 3.49470
|
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.49470' );
|
46 |
|
47 |
// Always include these helper files for dotcom FSE.
|
48 |
require_once __DIR__ . '/dotcom-fse/helpers.php';
|
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: 6.0
|
6 |
-
Stable tag: 3.
|
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: 6.0
|
6 |
+
Stable tag: 3.49470
|
7 |
Requires PHP: 5.6.20
|
8 |
License: GPLv2 or later
|
9 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|