add_action( 'admin_enqueue_scripts', $this, 'enqueue_assets' ); } public function enqueue_assets( string $hook ): void { if ( ! $this->is_academiccrew_page( $hook ) ) { return; } wp_enqueue_style( 'acc-admin', ACADEMICCREW_URL . 'assets/css/admin.css', [], ACADEMICCREW_VERSION ); wp_enqueue_script( 'acc-admin', ACADEMICCREW_URL . 'assets/js/admin.js', [], ACADEMICCREW_VERSION, true ); wp_localize_script( 'acc-admin', 'academiccrewAdmin', [ 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'acc_admin' ), 'i18n' => [ 'currentYear' => (int) gmdate( 'Y' ), 'currentMonth' => (int) gmdate( 'n' ), ], ] ); } private function is_academiccrew_page( string $hook ): bool { // Custom pages registered under academiccrew slug if ( str_contains( $hook, 'academiccrew' ) ) { return true; } // CPT list/edit screens global $pagenow; if ( in_array( $pagenow ?? '', [ 'edit.php', 'post.php', 'post-new.php' ], true ) ) { $post_type = sanitize_key( $_GET['post_type'] ?? '' ); // post.php?post=123&action=edit carries no post_type param — resolve from post ID if ( ! $post_type && ! empty( $_GET['post'] ) ) { $post_type = (string) get_post_type( absint( $_GET['post'] ) ); } if ( $post_type && ( str_starts_with( $post_type, 'academiccrew_' ) || $post_type === 'acc_collaboration' ) ) { return true; } } return false; } }