Skip to content

Commit

Permalink
Show Ads tab for Odyssey
Browse files Browse the repository at this point in the history
  • Loading branch information
kangzj committed Jan 16, 2023
1 parent 9818b18 commit 8dd5bd6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
3 changes: 2 additions & 1 deletion projects/packages/stats-admin/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"require": {
"automattic/jetpack-constants": "@dev",
"automattic/jetpack-options": "@dev",
"automattic/jetpack-stats": "@dev"
"automattic/jetpack-stats": "@dev",
"automattic/jetpack-status": "@dev"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.0.4",
Expand Down
45 changes: 36 additions & 9 deletions projects/packages/stats-admin/src/class-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Automattic\Jetpack\Admin_UI\Admin_Menu;
use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Modules;
use Jetpack_Options;

/**
Expand Down Expand Up @@ -229,10 +230,7 @@ protected function config_data() {
'username' => 'no-user',
),
'capabilities' => array(
"$blog_id" => array(
'manage_options' => true,
'activate_wordads' => true,
),
"$blog_id" => self::get_current_user_capatibilites(),
),
),
'sites' => array(
Expand All @@ -243,17 +241,15 @@ protected function config_data() {
'jetpack' => true,
'visible' => true,
'capabilities' => $empty_object,
'options' => array(
'admin_url' => admin_url(),
),
'products' => array(),
'plan' => $empty_object, // we need this empty object, otherwise the front end would crash on insight page.
'options' => array(
'wordads' => true,
'wordads' => ( new Modules() )->is_active( 'wordads' ),
'admin_url' => admin_url(),
),
),
),
'features' => array( "$blog_id" => array( 'data' => array( 'active' => array( 'wordads' ) ) ) ),
'features' => array( "$blog_id" => array( 'data' => self::get_plan_features() ) ),
),
),
);
Expand Down Expand Up @@ -294,4 +290,35 @@ protected static function get_site_locale() {
return $locale;
}

/**
* Get the features of the current plan.
*/
protected function get_plan_features() {
if ( ! class_exists( 'Jetpack_Plan' ) ) {
return array();
}
$plan = \Jetpack_Plan::get();
if ( empty( $plan['features'] ) ) {
return array();
}
return $plan['features'];
}

/**
* Get the capabilities of the current user.
*
* @return array An array of capabilities.
*/
protected function get_current_user_capatibilites() {
// TODO: `1.0.0` is just a placeholder. Add required API and then replace with the actual version.
if ( version_compare( Main::VERSION, '1.0.0', '<=' ) ) {
return array();
}
$user = wp_get_current_user();
if ( ! $user || is_wp_error( $user ) ) {
return array();
}
return $user->allcaps;
}

}

0 comments on commit 8dd5bd6

Please sign in to comment.