Skip to content

Commit

Permalink
Save the wpcom_admin_interface option
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur791004 committed May 8, 2024
1 parent 810652c commit 0c735ae
Showing 1 changed file with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
* The setting is displayed only if the has the wp-admin interface selected.
*/
function wpcomsh_wpcom_admin_interface_settings_field() {
if ( get_option( 'wpcom_admin_interface' ) !== 'wp-admin' ) {
return;
}

add_settings_field( 'wpcom_admin_interface', null, 'wpcom_admin_interface_display', 'general', 'default' );

Check failure on line 15 in projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php

View workflow job for this annotation

GitHub Actions / Static analysis

TypeError PhanTypeMismatchArgumentProbablyReal Argument 2 ($title) is null of type null but \add_settings_field() takes string (no real type) defined at /home/runner/work/jetpack/jetpack/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php:90292 (the inferred real argument type has nothing in common with the parameter's phpdoc type)

register_setting( 'general', 'wpcom_admin_interface', 'esc_attr' );

Check failure on line 17 in projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php

View workflow job for this annotation

GitHub Actions / Static analysis

TypeError PhanTypeMismatchArgumentProbablyReal Argument 3 ($args) is 'esc_attr' of type 'esc_attr' but \register_setting() takes array (no real type) defined at /home/runner/work/jetpack/jetpack/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php:127428 (the inferred real argument type has nothing in common with the parameter's phpdoc type)
Expand All @@ -34,6 +30,41 @@ function wpcom_admin_interface_display() {
echo '</fieldset>';
}

if ( function_exists( 'wpcom_is_nav_redesign_enabled' ) && wpcom_is_nav_redesign_enabled() ) {
if ( ! empty( get_option( 'wpcom_classic_early_release' ) ) ) {
add_action( 'admin_init', 'wpcomsh_wpcom_admin_interface_settings_field' );
}

/**
* Update the wpcom_admin_interface option on wpcom as it's the persistent data.
*
* @access private
* @since 4.20.0
*
* @param array $new_value The new settings value.
* @param array $old_value The old settings value.
* @return array The value to update.
*/
function wpcom_admin_interface_pre_update_option( $new_value, $old_value ) {
if ( $new_value === $old_value ) {
return $new_value;
}

if ( ! class_exists( 'Jetpack_Options' ) || ! class_exists( 'Automattic\Jetpack\Connection\Client' ) || ! class_exists( 'Automattic\Jetpack\Status\Host' ) ) {
return $new_value;
}

if ( ( new Host() )->is_wpcom_simple() ) {

Check failure on line 56 in projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php

View workflow job for this annotation

GitHub Actions / Static analysis

UndefError PhanUndeclaredClassMethod Call to method __construct from undeclared class \Host

Check failure on line 56 in projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php

View workflow job for this annotation

GitHub Actions / Static analysis

UndefError PhanUndeclaredClassMethod Call to method is_wpcom_simple from undeclared class \Host
return $new_value;
}

$blog_id = Jetpack_Options::get_option( 'id' );
Automattic\Jetpack\Connection\Client::wpcom_json_api_request_as_user(
"/sites/$blog_id/hosting/admin-interface",
'v2',
array( 'method' => 'POST' ),
array( 'interface' => $new_value )
);

return $new_value;
}
add_filter( 'pre_update_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_update_option', 10, 2 );

0 comments on commit 0c735ae

Please sign in to comment.