@@ -81,6 +81,15 @@ class Admin {
81
81
*/
82
82
public $ connect = null ;
83
83
84
+ /**
85
+ * Whether we're editing a post or term.
86
+ *
87
+ * @since 4.7.7
88
+ *
89
+ * @var bool
90
+ */
91
+ private $ isEditor = false ;
92
+
84
93
/**
85
94
* Construct method.
86
95
*
@@ -135,7 +144,7 @@ public function deactivationSurvey() {
135
144
* @return string The possibly modified HTML language attribute.
136
145
*/
137
146
public function alwaysAddHtmlDirAttribute ( $ output ) {
138
- if ( is_rtl () || preg_match ( '/dir=[ \'"](ltr|rtl|auto)[ \'"]/i ' , $ output ) ) {
147
+ if ( is_rtl () || preg_match ( '/dir=[ \'"](ltr|rtl|auto)[ \'"]/i ' , ( string ) $ output ) ) {
139
148
return $ output ;
140
149
}
141
150
@@ -276,8 +285,8 @@ private function registerLinkFormatHooks() {
276
285
277
286
add_action ( 'wp_enqueue_editor ' , [ $ this , 'addClassicLinkFormatScript ' ], 999999 );
278
287
279
- global $ wp_version ;
280
- if ( version_compare ( $ wp_version , '5.3 ' , '>= ' ) || is_plugin_active ( 'gutenberg/gutenberg.php ' ) ) {
288
+ global $ wp_version ; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
289
+ if ( version_compare ( $ wp_version , '5.3 ' , '>= ' ) || is_plugin_active ( 'gutenberg/gutenberg.php ' ) ) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName
281
290
add_action ( 'current_screen ' , [ $ this , 'addGutenbergLinkFormatScript ' ] );
282
291
add_action ( 'enqueue_block_editor_assets ' , [ $ this , 'enqueueBlockEditorLinkFormat ' ] );
283
292
}
@@ -418,7 +427,6 @@ public function addGutenbergLinkFormatScript() {
418
427
*/
419
428
public function adminBarMenu () {
420
429
if ( false === apply_filters ( 'aioseo_show_in_admin_bar ' , true ) ) {
421
- // API filter hook to disable showing SEO in admin bar.
422
430
return ;
423
431
}
424
432
@@ -427,21 +435,21 @@ public function adminBarMenu() {
427
435
return ;
428
436
}
429
437
430
- $ classes = is_admin ()
438
+ $ classes = is_admin ()
431
439
? 'wp-core-ui wp-ui-notification aioseo-menu-notification-counter '
432
440
: 'aioseo-menu-notification-counter aioseo-menu-notification-counter-frontend ' ;
433
- $ count = count ( Models \Notification::getAllActiveNotifications () );
434
- $ htmlCount = 10 > $ count ? $ count : '! ' ;
435
- $ htmlCount = $ htmlCount ? "<div class= \"{$ classes }\"> " . $ htmlCount . '</div> ' : '' ;
436
- $ htmlCount .= '<div id="aioseo-menu-new-notifications"></div> ' ;
441
+ $ notificationCount = count ( Models \Notification::getAllActiveNotifications () );
442
+ $ htmlCount = 10 > $ notificationCount ? $ notificationCount : '! ' ;
443
+ $ htmlCount = $ htmlCount ? "<div class= \"{$ classes }\"> " . $ htmlCount . '</div> ' : '' ;
444
+ $ htmlCount .= '<div id="aioseo-menu-new-notifications"></div> ' ;
437
445
438
446
$ this ->adminBarMenuItems [] = [
439
447
'id ' => 'aioseo-main ' ,
440
448
'title ' => '<div class="ab-item aioseo-logo svg"></div><span class="text"> ' . esc_html__ ( 'SEO ' , 'all-in-one-seo-pack ' ) . '</span> ' . wp_kses_post ( $ htmlCount ),
441
449
'href ' => esc_url ( admin_url ( 'admin.php?page= ' . $ firstPageSlug ) )
442
450
];
443
451
444
- if ( $ count ) {
452
+ if ( $ notificationCount ) {
445
453
$ this ->adminBarMenuItems [] = [
446
454
'parent ' => 'aioseo-main ' ,
447
455
'id ' => 'aioseo-notifications ' ,
@@ -452,14 +460,22 @@ public function adminBarMenu() {
452
460
453
461
$ this ->adminBarMenuItems [] = aioseo ()->standalone ->seoPreview ->getAdminBarMenuItemNode ();
454
462
463
+ $ currentScreen = aioseo ()->helpers ->getCurrentScreen ();
464
+ if (
465
+ is_admin () &&
466
+ ( 'post ' === $ currentScreen ->base || 'term ' === $ currentScreen ->base )
467
+ ) {
468
+ $ this ->isEditor = true ;
469
+ }
470
+
455
471
$ htmlSitemapRequested = aioseo ()->htmlSitemap ->isDedicatedPage ;
456
- if ( ! is_admin () && ! $ htmlSitemapRequested ) {
472
+ if ( $ htmlSitemapRequested || ! is_admin () || $ this -> isEditor ) {
457
473
$ this ->addPageAnalyzerMenuItems ();
458
474
}
459
475
460
476
if ( $ htmlSitemapRequested ) {
461
- global $ wp_admin_bar ;
462
- $ wp_admin_bar ->remove_node ( 'edit ' );
477
+ global $ wp_admin_bar ; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
478
+ $ wp_admin_bar ->remove_node ( 'edit ' ); // phpcs:ignore Squiz.NamingConventions.ValidVariableName
463
479
}
464
480
465
481
$ this ->addSettingsMenuItems ();
@@ -477,9 +493,9 @@ public function adminBarMenu() {
477
493
* @return void
478
494
*/
479
495
protected function addAdminBarMenuItems () {
480
- global $ wp_admin_bar ;
496
+ global $ wp_admin_bar ; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
481
497
foreach ( $ this ->adminBarMenuItems as $ item ) {
482
- $ wp_admin_bar ->add_menu ( $ item );
498
+ $ wp_admin_bar ->add_menu ( $ item ); // phpcs:ignore Squiz.NamingConventions.ValidVariableName
483
499
}
484
500
}
485
501
@@ -491,9 +507,31 @@ protected function addAdminBarMenuItems() {
491
507
* @return void
492
508
*/
493
509
public function addPageAnalyzerMenuItems () {
494
- global $ wp ;
495
- // Make sure the trailing slash matches the site configuration.
496
- $ url = user_trailingslashit ( home_url ( $ wp ->request ) );
510
+ $ url = '' ;
511
+ $ currentScreen = aioseo ()->helpers ->getCurrentScreen ();
512
+ if (
513
+ is_singular () ||
514
+ ( is_admin () && 'post ' === $ currentScreen ->base )
515
+ ) {
516
+ $ post = aioseo ()->helpers ->getPost ();
517
+ if ( is_a ( $ post , 'WP_Post ' ) && 'publish ' === $ post ->post_status && '' !== $ post ->post_name ) {
518
+ $ url = get_permalink ( $ post ->ID );
519
+ }
520
+ }
521
+
522
+ if (
523
+ is_category () ||
524
+ is_tag () ||
525
+ is_tax () ||
526
+ ( is_admin () && 'term ' === $ currentScreen ->base )
527
+ ) {
528
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended, HM.Security.NonceVerification.Recommended
529
+ $ termId = ! empty ( $ _REQUEST ['tag_ID ' ] ) ? intval ( $ _REQUEST ['tag_ID ' ] ) : 0 ;
530
+ $ term = is_admin () && $ termId ? get_term ( $ termId ) : get_queried_object ();
531
+ if ( is_a ( $ term , 'WP_Term ' ) ) {
532
+ $ url = get_term_link ( $ term );
533
+ }
534
+ }
497
535
498
536
if ( ! $ url ) {
499
537
return ;
@@ -502,61 +540,51 @@ public function addPageAnalyzerMenuItems() {
502
540
$ this ->adminBarMenuItems [] = [
503
541
'id ' => 'aioseo-analyze-page ' ,
504
542
'parent ' => 'aioseo-main ' ,
505
- 'title ' => esc_html__ ( 'Analyze this page ' , 'all-in-one-seo-pack ' ),
543
+ 'title ' => esc_html__ ( 'Analyze this page ' , 'all-in-one-seo-pack ' )
506
544
];
507
545
508
546
$ url = urlencode ( $ url );
509
547
510
548
$ submenuItems = [
511
549
[
512
- 'id ' => 'aioseo-analyze-page-inlinks ' ,
513
- 'title ' => esc_html__ ( 'Check links to this URL ' , 'all-in-one-seo-pack ' ),
514
- 'href ' => 'https://search.google.com/search-console/links/drilldown?resource_id = ' . urlencode ( get_option ( ' siteurl ' ) ) . ' &type=EXTERNAL&target= ' . $ url . ' &domain= ' ,
550
+ 'id ' => 'aioseo-analyze-page-pagespeed ' ,
551
+ 'title ' => esc_html__ ( 'Google Page Speed Test ' , 'all-in-one-seo-pack ' ),
552
+ 'href ' => 'https://pagespeed.web.dev/report?url = ' . $ url
515
553
],
516
554
[
517
- 'id ' => 'aioseo-analyze-page-cache ' ,
518
- 'title ' => esc_html__ ( 'Check Google Cache ' , 'all-in-one-seo-pack ' ),
519
- 'href ' => '//webcache.googleusercontent .com/search?strip=1&q=cache: ' . $ url,
555
+ 'id ' => 'aioseo-analyze-page-structureddata ' ,
556
+ 'title ' => esc_html__ ( 'Google Rich Results Test ' , 'all-in-one-seo-pack ' ),
557
+ 'href ' => 'https://search.google .com/test/rich-results?url= ' . $ url
520
558
],
521
559
[
522
560
'id ' => 'aioseo-analyze-page-structureddata ' ,
523
- 'title ' => esc_html__ ( 'Google Rich Results Test ' , 'all-in-one-seo-pack ' ),
524
- 'href ' => 'https://search.google.com/test/rich-results?url= ' . $ url ,
561
+ 'title ' => esc_html__ ( 'Schema.org Validator ' , 'all-in-one-seo-pack ' ),
562
+ 'href ' => 'https://validator.schema.org/?url= ' . $ url
563
+ ],
564
+ [
565
+ 'id ' => 'aioseo-analyze-page-inlinks ' ,
566
+ 'title ' => esc_html__ ( 'Inbound Links ' , 'all-in-one-seo-pack ' ),
567
+ 'href ' => 'https://search.google.com/search-console/links/drilldown?resource_id= ' . urlencode ( get_option ( 'siteurl ' ) ) . '&type=EXTERNAL&target= ' . $ url . '&domain= '
525
568
],
526
569
[
527
570
'id ' => 'aioseo-analyze-page-facebookdebug ' ,
528
571
'title ' => esc_html__ ( 'Facebook Debugger ' , 'all-in-one-seo-pack ' ),
529
- 'href ' => 'https://developers.facebook.com/tools/debug/?q= ' . $ url,
572
+ 'href ' => 'https://developers.facebook.com/tools/debug/?q= ' . $ url
530
573
],
531
574
[
532
- 'id ' => 'aioseo-analyze-page-pinterestvalidator ' ,
533
- 'title ' => esc_html__ ( 'Pinterest Rich Pins Validator ' , 'all-in-one-seo-pack ' ),
534
- 'href ' => ' https://developers.pinterest .com/tools/url-debugger/?link= ' . $ url,
575
+ 'id ' => 'aioseo-external-tools-linkedin-post-inspector ' ,
576
+ 'title ' => esc_html__ ( 'LinkedIn Post Inspector ' , 'all-in-one-seo-pack ' ),
577
+ 'href ' => " https://www.linkedin .com/post-inspector/inspect/ $ url"
535
578
],
536
579
[
537
580
'id ' => 'aioseo-analyze-page-htmlvalidation ' ,
538
581
'title ' => esc_html__ ( 'HTML Validator ' , 'all-in-one-seo-pack ' ),
539
- 'href ' => '//validator.w3.org/check?uri= ' . $ url,
582
+ 'href ' => '//validator.w3.org/check?uri= ' . $ url
540
583
],
541
584
[
542
585
'id ' => 'aioseo-analyze-page-cssvalidation ' ,
543
586
'title ' => esc_html__ ( 'CSS Validator ' , 'all-in-one-seo-pack ' ),
544
- 'href ' => '//jigsaw.w3.org/css-validator/validator?uri= ' . $ url ,
545
- ],
546
- [
547
- 'id ' => 'aioseo-analyze-page-pagespeed ' ,
548
- 'title ' => esc_html__ ( 'Google Page Speed Test ' , 'all-in-one-seo-pack ' ),
549
- 'href ' => 'https://pagespeed.web.dev/report?url= ' . $ url ,
550
- ],
551
- [
552
- 'id ' => 'aioseo-analyze-page-google-mobile-friendly ' ,
553
- 'title ' => esc_html__ ( 'Mobile-Friendly Test ' , 'all-in-one-seo-pack ' ),
554
- 'href ' => 'https://www.google.com/webmasters/tools/mobile-friendly/?url= ' . $ url ,
555
- ],
556
- [
557
- 'id ' => 'aioseo-external-tools-linkedin-post-inspector ' ,
558
- 'title ' => esc_html__ ( 'LinkedIn Post Inspector ' , 'all-in-one-seo-pack ' ),
559
- 'href ' => "https://www.linkedin.com/post-inspector/inspect/ $ url "
587
+ 'href ' => '//jigsaw.w3.org/css-validator/validator?uri= ' . $ url
560
588
]
561
589
];
562
590
@@ -566,7 +594,7 @@ public function addPageAnalyzerMenuItems() {
566
594
'id ' => $ item ['id ' ],
567
595
'title ' => $ item ['title ' ],
568
596
'href ' => $ item ['href ' ],
569
- 'meta ' => [ 'target ' => '_blank ' ],
597
+ 'meta ' => [ 'target ' => '_blank ' ]
570
598
];
571
599
}
572
600
}
@@ -610,7 +638,7 @@ protected function addEditSeoMenuItem() {
610
638
* @return void
611
639
*/
612
640
protected function addSettingsMenuItems () {
613
- if ( ! is_admin () ) {
641
+ if ( ! is_admin () || $ this -> isEditor ) {
614
642
$ this ->adminBarMenuItems [] = [
615
643
'id ' => 'aioseo-settings-main ' ,
616
644
'parent ' => 'aioseo-main ' ,
@@ -619,7 +647,7 @@ protected function addSettingsMenuItems() {
619
647
];
620
648
}
621
649
622
- $ parent = is_admin () ? 'aioseo-main ' : 'aioseo-settings-main ' ;
650
+ $ parent = is_admin () && ! $ this -> isEditor ? 'aioseo-main ' : 'aioseo-settings-main ' ;
623
651
foreach ( $ this ->pages as $ id => $ page ) {
624
652
// Remove page from admin bar menu.
625
653
if ( ! empty ( $ page ['hide_admin_bar_menu ' ] ) ) {
@@ -791,9 +819,9 @@ public function page() {
791
819
*/
792
820
public function hooks () {
793
821
$ currentScreen = aioseo ()->helpers ->getCurrentScreen ();
794
- global $ admin_page_hooks ;
822
+ global $ admin_page_hooks ; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
795
823
796
- if ( ! is_object ( $ currentScreen ) || empty ( $ currentScreen ->id ) || empty ( $ admin_page_hooks ) ) {
824
+ if ( ! is_object ( $ currentScreen ) || empty ( $ currentScreen ->id ) || empty ( $ admin_page_hooks ) ) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName
797
825
return ;
798
826
}
799
827
@@ -822,7 +850,7 @@ public function hooks() {
822
850
$ addScripts = true ;
823
851
}
824
852
825
- if ( ! empty ( $ admin_page_hooks ['aioseo ' ] ) && $ currentScreen ->id === $ admin_page_hooks ['aioseo ' ] ) {
853
+ if ( ! empty ( $ admin_page_hooks ['aioseo ' ] ) && $ currentScreen ->id === $ admin_page_hooks ['aioseo ' ] ) { // phpcs:ignore Squiz.NamingConventions.ValidVariableName
826
854
$ addScripts = true ;
827
855
}
828
856
@@ -968,13 +996,13 @@ public function addFooterText() {
968
996
);
969
997
970
998
// Stop WP Core from outputting its version number and instead add both theirs & ours.
971
- global $ wp_version ;
999
+ global $ wp_version ; // phpcs:ignore Squiz.NamingConventions.ValidVariableName
972
1000
printf (
973
1001
wp_kses_post ( '<p class="alignright">%1$s</p> ' ),
974
1002
sprintf (
975
1003
// Translators: 1 - WP Core version number, 2 - AIOSEO version number.
976
1004
esc_html__ ( 'WordPress %1$s | AIOSEO %2$s ' , 'all-in-one-seo-pack ' ),
977
- esc_html ( $ wp_version ),
1005
+ esc_html ( $ wp_version ), // phpcs:ignore Squiz.NamingConventions.ValidVariableName
978
1006
esc_html ( AIOSEO_VERSION )
979
1007
)
980
1008
);
0 commit comments