Skip to content

Commit 86b2750

Browse files
authored
make use of passed hook for admin_enqueue_scripts to avoid needing get_current_screen (#992)
1 parent 7923f42 commit 86b2750

File tree

7 files changed

+14
-29
lines changed

7 files changed

+14
-29
lines changed

inc/about.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
*
2222
* @since 1.6.0
2323
*/
24-
function cptui_about_assets() {
25-
$current_screen = get_current_screen();
24+
function cptui_about_assets( $hook ) {
2625

27-
if ( ! is_object( $current_screen ) || 'toplevel_page_cptui_main_menu' !== $current_screen->base ) {
26+
if ( 'toplevel_page_cptui_main_menu' !== $hook ) {
2827
return;
2928
}
3029

inc/listings.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
*
2222
* @since 1.6.0
2323
*/
24-
function cptui_listings_assets() {
25-
$current_screen = get_current_screen();
24+
function cptui_listings_assets( $hook ) {
2625

27-
if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_listings' !== $current_screen->base ) {
26+
if ( 'cpt-ui_page_cptui_listings' !== $hook ) {
2827
return;
2928
}
3029

inc/post-types.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
*
2424
* @internal
2525
*/
26-
function cptui_post_type_enqueue_scripts() {
26+
function cptui_post_type_enqueue_scripts( $hook ) {
2727

28-
$current_screen = get_current_screen();
29-
30-
if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_manage_post_types' !== $current_screen->base ) {
28+
if ( 'cpt-ui_page_cptui_manage_post_types' !== $hook ) {
3129
return;
3230
}
3331

inc/support.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
*
2424
* @internal
2525
*/
26-
function cptui_support_enqueue_scripts() {
26+
function cptui_support_enqueue_scripts( $hook ) {
2727

28-
$current_screen = get_current_screen();
29-
30-
if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_support' !== $current_screen->base ) {
28+
if ( 'cpt-ui_page_cptui_support' !== $hook ) {
3129
return;
3230
}
3331

inc/taxonomies.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
*
2424
* @internal
2525
*/
26-
function cptui_taxonomies_enqueue_scripts() {
26+
function cptui_taxonomies_enqueue_scripts( $hook ) {
2727

28-
$current_screen = get_current_screen();
29-
30-
if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_manage_taxonomies' !== $current_screen->base ) {
28+
if ( 'cpt-ui_page_cptui_manage_taxonomies' !== $hook ) {
3129
return;
3230
}
3331

inc/tools.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
*
2424
* @return void
2525
*/
26-
function cptui_tools_assets() {
27-
$current_screen = get_current_screen();
26+
function cptui_tools_assets( $hook ) {
2827

29-
if ( ! is_object( $current_screen ) || 'cpt-ui_page_cptui_tools' !== $current_screen->base ) {
28+
if ( 'cpt-ui_page_cptui_tools' !== $hook ) {
3029
return;
3130
}
3231

inc/utility.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -431,21 +431,15 @@ function cptui_newsletter_form() {
431431
* @author Scott Anderson <[email protected]>
432432
* @since 1.7.3
433433
*/
434-
function enqueue_email_octopus_assets() {
435-
436-
$current_screen = get_current_screen();
437-
438-
if ( ! is_object( $current_screen ) ) {
439-
return;
440-
}
434+
function enqueue_email_octopus_assets( $hook ) {
441435

442436
$screens = [
443437
'toplevel_page_cptui_main_menu',
444438
'cpt-ui_page_cptui_manage_post_types',
445439
'cpt-ui_page_cptui_manage_taxonomies',
446440
];
447441

448-
if ( ! in_array( $current_screen->base, $screens, true ) ) {
442+
if ( ! in_array( $hook, $screens, true ) ) {
449443
return;
450444
}
451445

0 commit comments

Comments
 (0)