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

Add dashboard wincher connect patch #20307

Merged
merged 20 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
02ebf18
Display wincher performance report if user not logged in
KaisZaoualiWincher Apr 3, 2023
44667d2
Replace wincher connect explanation by connect button
KaisZaoualiWincher Apr 3, 2023
82c22e5
Change wincher table explanation in dashboard
KaisZaoualiWincher Apr 3, 2023
4514836
Disable wincher view link for not logged in users
KaisZaoualiWincher Apr 3, 2023
eb8fd55
Add wincher connect success alerts in dashboard
KaisZaoualiWincher Apr 13, 2023
087b7de
Use a shortlink for wincher login
KaisZaoualiWincher Apr 24, 2023
7f8bfa9
Use a new shortlink for dashboard-about-wincher link
KaisZaoualiWincher Apr 24, 2023
11ae6e6
Merge branch 'feature/add-dashboard-wincher-connect' of https://githu…
pls78 Apr 27, 2023
bdf4a2a
Merge branch 'trunk' into add-dashboard-wincher-connect-patch
pls78 Apr 27, 2023
da00efc
Use a shortcode for the about link
pls78 Apr 27, 2023
5361f37
Move Wincher SEO performance report to its own widget on dashboard
KaisZaoualiWincher May 1, 2023
e7e4e14
Merge branch 'feature/add-dashboard-wincher-connect' of https://githu…
pls78 May 2, 2023
2c9ba39
Add network error handling on Wincher connect
KaisZaoualiWincher May 5, 2023
178c028
Fix Wincher performance alerts' margin bottom
KaisZaoualiWincher May 9, 2023
62eb89f
Merge branch 'feature/add-dashboard-wincher-connect' of https://githu…
pls78 May 10, 2023
a0c555b
Merge branch 'trunk' into add-dashboard-wincher-connect-patch
pls78 May 10, 2023
d325f9c
Fix shortlinks
pls78 May 10, 2023
f8fe16c
Avoid an uncaught error when there's no network connection and the us…
pls78 May 10, 2023
2b266db
Fix WincherPerformanceReport warnings
KaisZaoualiWincher May 17, 2023
ac2f096
Merge branch 'feature/add-dashboard-wincher-connect' of https://githu…
pls78 May 17, 2023
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
1 change: 1 addition & 0 deletions admin/class-admin-asset-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ protected function scripts_to_be_registered() {
'api-client' => [ 'wp-api' ],
'crawl-settings' => [ 'jquery' ],
'dashboard-widget' => [ self::PREFIX . 'api-client' ],
'wincher-dashboard-widget' => [ self::PREFIX . 'api-client' ],
'editor-modules' => [ 'jquery' ],
'elementor' => [
self::PREFIX . 'api-client',
Expand Down
3 changes: 2 additions & 1 deletion admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public function __construct() {
}

$this->admin_features = [
'dashboard_widget' => new Yoast_Dashboard_Widget(),
'dashboard_widget' => new Yoast_Dashboard_Widget(),
'wincher_dashboard_widget' => new Wincher_Dashboard_Widget(),
];

if ( WPSEO_Metabox::is_post_overview( $pagenow ) || WPSEO_Metabox::is_post_edit( $pagenow ) ) {
Expand Down
128 changes: 128 additions & 0 deletions admin/class-wincher-dashboard-widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Admin
*/

/**
* Wincher dashboard widget.
*/
class Wincher_Dashboard_Widget implements WPSEO_WordPress_Integration {

/**
* Holds an instance of the admin asset manager.
*
* @var WPSEO_Admin_Asset_Manager
*/
protected $asset_manager;

/**
* Wincher_Dashboard_Widget constructor.
*/
public function __construct() {
$this->asset_manager = new WPSEO_Admin_Asset_Manager();
}

/**
* Register WordPress hooks.
*/
public function register_hooks() {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_wincher_dashboard_assets' ] );
add_action( 'admin_init', [ $this, 'queue_wincher_dashboard_widget' ] );
}

/**
* Adds the Wincher dashboard widget if it should be shown.
*
* @return void
*/
public function queue_wincher_dashboard_widget() {
if ( $this->show_widget() ) {
add_action( 'wp_dashboard_setup', [ $this, 'add_wincher_dashboard_widget' ] );
}
}

/**
* Adds the Wincher dashboard widget to WordPress.
*/
public function add_wincher_dashboard_widget() {
add_filter( 'postbox_classes_dashboard_wpseo-wincher-dashboard-overview', [ $this, 'wpseo_wincher_dashboard_overview_class' ] );
wp_add_dashboard_widget(
'wpseo-wincher-dashboard-overview',
/* translators: %1$s expands to Yoast SEO, %2$s to Wincher */
sprintf( __( '%1$s / %2$s: Top Keyphrases', 'wordpress-seo' ), 'Yoast SEO', 'Wincher' ),
[ $this, 'display_wincher_dashboard_widget' ]
);
}

/**
* Adds CSS classes to the dashboard widget.
*
* @param array $classes An array of postbox CSS classes.
*
* @return array
*/
public function wpseo_wincher_dashboard_overview_class( $classes ) {
$classes[] = 'yoast wpseo-wincherdashboard-overview';
return $classes;
}

/**
* Displays the Wincher dashboard widget.
*/
public function display_wincher_dashboard_widget() {
echo '<div id="yoast-seo-wincher-dashboard-widget"></div>';
}

/**
* Enqueues assets for the dashboard if the current page is the dashboard.
*/
public function enqueue_wincher_dashboard_assets() {
if ( ! $this->is_dashboard_screen() ) {
return;
}

$this->asset_manager->localize_script( 'wincher-dashboard-widget', 'wpseoWincherDashboardWidgetL10n', $this->localize_wincher_dashboard_script() );
$this->asset_manager->enqueue_script( 'wincher-dashboard-widget' );
$this->asset_manager->enqueue_style( 'wp-dashboard' );
$this->asset_manager->enqueue_style( 'monorepo' );
}

/**
* Translates strings used in the Wincher dashboard widget.
*
* @return array The translated strings.
*/
public function localize_wincher_dashboard_script() {

return [
'wincher_is_logged_in' => YoastSEO()->helpers->wincher->login_status(),
'wincher_website_id' => WPSEO_Options::get( 'wincher_website_id', '' ),
];
}

/**
* Checks if the current screen is the dashboard screen.
*
* @return bool Whether or not this is the dashboard screen.
*/
private function is_dashboard_screen() {
$current_screen = get_current_screen();

return ( $current_screen instanceof WP_Screen && $current_screen->id === 'dashboard' );
}

/**
* Returns true when the Wincher dashboard widget should be shown.
*
* @return bool
*/
private function show_widget() {
$analysis_seo = new WPSEO_Metabox_Analysis_SEO();
$user_can_edit = $analysis_seo->is_enabled() && current_user_can( 'edit_posts' );
$is_wincher_active = YoastSEO()->helpers->wincher->is_active();

return $user_can_edit && $is_wincher_active;
}
}
5 changes: 0 additions & 5 deletions admin/class-yoast-dashboard-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ public function enqueue_dashboard_assets() {
* @return array The translated strings.
*/
public function localize_dashboard_script() {
$is_wincher_active = YoastSEO()->helpers->wincher->is_active();

return [
'feed_header' => sprintf(
/* translators: %1$s resolves to Yoast.com */
Expand All @@ -127,9 +125,6 @@ public function localize_dashboard_script() {
'feed_footer' => __( 'Read more like this on our SEO blog', 'wordpress-seo' ),
'wp_version' => substr( $GLOBALS['wp_version'], 0, 3 ) . '-' . ( is_plugin_active( 'classic-editor/classic-editor.php' ) ? '1' : '0' ),
'php_version' => PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION,
'is_wincher_active' => ( $is_wincher_active ) ? 1 : 0,
'wincher_is_logged_in' => ( $is_wincher_active ) ? YoastSEO()->helpers->wincher->login_status() : false,
'wincher_website_id' => WPSEO_Options::get( 'wincher_website_id', '' ),
];
}

Expand Down
1 change: 1 addition & 0 deletions config/webpack/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const getEntries = ( sourceDirectory = "./packages/js/src" ) => ( {
"classic-editor": `${ sourceDirectory }/classic-editor.js`,
"crawl-settings": `${ sourceDirectory }/crawl-settings.js`,
"dashboard-widget": `${ sourceDirectory }/dashboard-widget.js`,
"wincher-dashboard-widget": `${ sourceDirectory }/wincher-dashboard-widget.js`,
"dynamic-blocks": `${ sourceDirectory }/dynamic-blocks.js`,
"edit-page": `${ sourceDirectory }/edit-page.js`,
"editor-modules": `${ sourceDirectory }/editor-modules.js`,
Expand Down
4 changes: 2 additions & 2 deletions css/src/dashboard.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading