Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap a minimal sync package #52681

Merged
merged 9 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,12 @@
"markdown_source": "../packages/stylelint-config/README.md",
"parent": "packages"
},
{
"title": "@wordpress/sync",
"slug": "packages-sync",
"markdown_source": "../packages/sync/README.md",
"parent": "packages"
},
{
"title": "@wordpress/token-list",
"slug": "packages-token-list",
Expand Down
3 changes: 3 additions & 0 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ function gutenberg_initialize_editor( $editor_name, $editor_script_handle, $sett
*/
function gutenberg_enable_experiments() {
$gutenberg_experiments = get_option( 'gutenberg-experiments' );
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-sync-collaboration', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableSync = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-zoomed-out-view', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableZoomedOutView = true', 'before' );
}
Expand Down
24 changes: 24 additions & 0 deletions lib/experimental/synchronization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Bootstraps synchrnoization (collborative editing).
*
* @package gutenberg
*/

/**
* Initializes the collaborative editing secret.
*/
function gutenberg_rest_api_init_collaborative_editing() {
$gutenberg_experiments = get_option( 'gutenberg-experiments' );
if ( ! $gutenberg_experiments || ! array_key_exists( 'gutenberg-sync-collaboration', $gutenberg_experiments ) ) {
return;
}
$collaborative_editing_secret = get_site_option( 'collaborative_editing_secret' );
if ( ! $collaborative_editing_secret ) {
$collaborative_editing_secret = wp_generate_password( 64, false );
}
add_site_option( 'collaborative_editing_secret', $collaborative_editing_secret );

wp_add_inline_script( 'wp-sync', 'window.__experimentalCollaborativeEditingSecret = "' . $collaborative_editing_secret . '";', 'before' );
}
add_action( 'admin_init', 'gutenberg_rest_api_init_collaborative_editing' );
12 changes: 12 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ function gutenberg_initialize_experiments_settings() {
'gutenberg-experiments'
);

add_settings_field(
'gutenberg-sync-collaboration',
__( 'Live Collaboration and offline persistence ', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enable the live collaboration and offline persistence between peers', 'gutenberg' ),
'id' => 'gutenberg-sync-collaboration',
)
);

add_settings_field(
'gutenberg-zoomed-out-view',
__( 'Zoomed out view ', 'gutenberg' ),
Expand Down
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/experimental/navigation-theme-opt-in.php';
require __DIR__ . '/experimental/kses.php';
require __DIR__ . '/experimental/l10n.php';
require __DIR__ . '/experimental/synchronization.php';

if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) {
require __DIR__ . '/experimental/disable-tinymce.php';
Expand Down
Loading