register( 'adpresso-conditional-root', 'Conditionals', [ 'location' => 'admin_bar', 'context' => null, ] ); add_action( 'wp', [ $this, 'register_conditionals' ] ); } /** * Registers all true conditionals as Admin Bar Notifications. * * @return void */ public function register_conditionals(): void { $true_conditionals = $this->get_true_conditionals(); foreach ( $true_conditionals as $name ) { NotificationManager::get()->register( 'adpresso-cond-' . $name, $name . '()', [ 'location' => 'admin_bar', 'context' => 'adpresso-conditional-root', ] ); } } /** * List of all known WP Conditionals that are true. * * @return string[] */ protected function get_true_conditionals(): array { $conditionals = [ 'is_single', 'is_page', 'is_singular', 'is_front_page', 'is_home', 'is_archive', 'is_search', 'is_404', 'is_admin', 'is_user_logged_in', 'is_preview', 'is_feed', 'is_category', 'is_tag', 'is_tax', 'is_author', 'is_date', 'is_day', 'is_month', 'is_year', 'is_sticky', 'is_ssl', 'is_paged', 'is_attachment', 'is_embed', 'is_trackback', 'is_login', ]; $true = []; foreach ( $conditionals as $fn ) { if ( function_exists( $fn ) && call_user_func( $fn ) ) { $true[] = $fn; } } return $true; } }