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

Masterbar: Add My Home submenu to all Atomic sites #14590

Merged
merged 1 commit into from
Mar 5, 2020
Merged
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
58 changes: 11 additions & 47 deletions modules/masterbar/masterbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -1330,40 +1330,6 @@ public function add_my_sites_submenu( $wp_admin_bar ) {
}
}

/**
* Calls the wpcom API to get the creation date of the site
* and determine if it's eligible for the 'My Home' page.
*
* @return bool Whether the site has 'My Home' enabled.
*/
private function is_my_home_enabled() {
$my_home_enabled = get_transient( 'jetpack_my_home_enabled' );

if ( false === $my_home_enabled ) {
$site_id = Jetpack_Options::get_option( 'id' );
$site_response = Client::wpcom_json_api_request_as_blog(
sprintf( '/sites/%d', $site_id ) . '?force=wpcom&options=created_at',
'1.1'
);

if ( is_wp_error( $site_response ) ) {
return false;
}

$site_data = json_decode( wp_remote_retrieve_body( $site_response ) );

$my_home_enabled = $site_data &&
isset( $site_data->options->created_at ) &&
( new Datetime( '2019-08-06 00:00:00.000' ) ) <= ( new Datetime( $site_data->options->created_at ) )
? 1
: 0;

set_transient( 'jetpack_my_home_enabled', $my_home_enabled );
}

return (bool) $my_home_enabled;
}

/**
* Adds "My Home" submenu item to sites that are eligible.
*
Expand All @@ -1375,18 +1341,16 @@ private function add_my_home_submenu_item( &$wp_admin_bar ) {
return;
}

if ( $this->is_my_home_enabled() ) {
$wp_admin_bar->add_menu(
array(
'parent' => 'blog',
'id' => 'my-home',
'title' => __( 'My Home', 'jetpack' ),
'href' => 'https://wordpress.com/home/' . esc_attr( $this->primary_site_slug ),
'meta' => array(
'class' => 'mb-icon',
),
)
);
}
$wp_admin_bar->add_menu(
array(
'parent' => 'blog',
'id' => 'my-home',
'title' => __( 'My Home', 'jetpack' ),
'href' => 'https://wordpress.com/home/' . esc_attr( $this->primary_site_slug ),
mmtr marked this conversation as resolved.
Show resolved Hide resolved
'meta' => array(
'class' => 'mb-icon',
),
)
);
}
}