| 1 |
<?php |
| 2 |
/** |
| 3 |
* Bootstraps synchrnoization (collborative editing). |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Initializes the collaborative editing secret. |
| 10 |
*/ |
| 11 |
function gutenberg_rest_api_init_collaborative_editing() { |
| 12 |
$gutenberg_experiments = get_option( 'gutenberg-experiments' ); |
| 13 |
if ( ! $gutenberg_experiments || ! array_key_exists( 'gutenberg-sync-collaboration', $gutenberg_experiments ) ) { |
| 14 |
return; |
| 15 |
} |
| 16 |
$collaborative_editing_secret = get_site_option( 'collaborative_editing_secret' ); |
| 17 |
if ( ! $collaborative_editing_secret ) { |
| 18 |
$collaborative_editing_secret = wp_generate_password( 64, false ); |
| 19 |
} |
| 20 |
add_site_option( 'collaborative_editing_secret', $collaborative_editing_secret ); |
| 21 |
|
| 22 |
wp_add_inline_script( 'wp-sync', 'window.__experimentalCollaborativeEditingSecret = "' . $collaborative_editing_secret . '";', 'before' ); |
| 23 |
} |
| 24 |
add_action( 'admin_init', 'gutenberg_rest_api_init_collaborative_editing' ); |
| 25 |
|