__( 'Board', 'feature-request-system' ), // Not "Status": the Publish box uses that word for Published, Pending and so on. StatusTaxonomy::NAME => __( 'Request status', 'feature-request-system' ), ]; foreach ( $boxes as $taxonomy => $title ) { add_meta_box( $taxonomy . 'div', $title, [ self::class, 'render' ], RequestPostType::NAME, 'side', 'core', [ 'taxonomy' => $taxonomy ] ); } } /** * Prints the dropdown. * * The field posts tax_input[taxonomy][] like the core category box, so WordPress saves it * with the post and checks the taxonomy's assign_terms capability. * * @param WP_Post $post Request being edited. * @param array{args: array{taxonomy: string}} $box Meta box arguments from WordPress. */ public static function render( WP_Post $post, array $box ): void { $taxonomy = get_taxonomy( $box['args']['taxonomy'] ); if ( ! $taxonomy ) { return; } $terms = get_terms( [ 'taxonomy' => $taxonomy->name, 'hide_empty' => false, ] ); $terms = is_array( $terms ) ? $terms : []; if ( StatusTaxonomy::NAME === $taxonomy->name ) { $terms = StatusTaxonomy::sort( $terms ); } $assigned = wp_get_object_terms( $post->ID, $taxonomy->name, [ 'fields' => 'ids' ] ); $selected = is_array( $assigned ) && $assigned ? (int) $assigned[0] : RequestTerms::default_term( $taxonomy->name ); $field_id = $taxonomy->name . '-select'; printf( '', esc_attr( $field_id ), esc_html( $taxonomy->labels->singular_name ) ); printf( ''; if ( StatusTaxonomy::NAME === $taxonomy->name ) { self::render_notify_switch( $post ); } } /** * Prints the switch that decides whether a status change is emailed to the request's followers. * * @param WP_Post $post Request being edited. */ private static function render_notify_switch( WP_Post $post ): void { $followers = SubscriptionRepository::count( $post->ID ); if ( ! $followers || ! Subscriptions::enabled() ) { return; } $label = sprintf( /* translators: %s: number of followers. */ _n( 'Email %s follower when the status changes', 'Email %s followers when the status changes', $followers, 'feature-request-system' ), number_format_i18n( $followers ) ); printf( '

%1$s

%2$s

', NotifySwitch::field( $label ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in field(). esc_html( NotifySwitch::timing() ) ); } }