post_type ) { return; } $status = RequestTerms::term_of( $post->ID, StatusTaxonomy::NAME ); printf( '
%2$d
', esc_attr( self::FIELD ), $status ? (int) $status->term_id : 0 ); } /** * Sets the chosen status when a request is saved from Quick Edit or Bulk Edit. * * @param int $post_id Request ID. */ public static function save( int $post_id ): void { if ( ! self::is_quick_or_bulk_edit() ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Checked in is_quick_or_bulk_edit(). $status = isset( $_REQUEST[ self::FIELD ] ) ? absint( $_REQUEST[ self::FIELD ] ) : 0; $taxonomy = get_taxonomy( StatusTaxonomy::NAME ); if ( $status && $taxonomy && current_user_can( $taxonomy->cap->assign_terms ) && current_user_can( 'edit_post', $post_id ) && term_exists( $status, StatusTaxonomy::NAME ) ) { wp_set_object_terms( $post_id, $status, StatusTaxonomy::NAME ); } } /** * Loads the script on the requests list. * * @param string $screen File name of the admin screen. */ public static function enqueue_script( string $screen ): void { if ( 'edit.php' === $screen && RequestPostType::NAME === get_current_screen()->post_type ) { wp_enqueue_script( self::SCRIPT, Plugin::url( 'assets/admin/quick-edit.js' ), [ 'inline-edit-post' ], Plugin::VERSION, true ); } } /** * Prints the dropdown next to the Status column's place in the form. * * @param string $column Column the form is asking about. * @param string $post_type Post type of the list. * @param string $no_change Label of an option that leaves the status alone, or '' for none. */ private static function render( string $column, string $post_type, string $no_change ): void { $taxonomy = get_taxonomy( StatusTaxonomy::NAME ); if ( RequestList::taxonomy_column( StatusTaxonomy::NAME ) !== $column || RequestPostType::NAME !== $post_type || ! $taxonomy || ! current_user_can( $taxonomy->cap->assign_terms ) ) { return; } $statuses = get_terms( [ 'taxonomy' => StatusTaxonomy::NAME, 'hide_empty' => false, ] ); printf( // The label is longer than the column WordPress gives labels here, so it sizes itself. '
'; if ( Subscriptions::enabled() ) { printf( '
%1$s

%2$s

', // WordPress gives labels here the height of a text field, which pulls the lines of a long label apart. NotifySwitch::field( __( 'Email followers when the status changes', 'feature-request-system' ), 'line-height:1.5;margin:0.6em 0' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in field(). esc_html( NotifySwitch::timing() ) ); } echo '
'; } /** * Whether the current request is a Quick Edit or Bulk Edit save that WordPress accepted. */ public static function is_quick_or_bulk_edit(): bool { $quick = isset( $_POST['_inline_edit'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_inline_edit'] ) ), 'inlineeditnonce' ); $bulk = isset( $_REQUEST['bulk_edit'], $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'bulk-posts' ); return $quick || $bulk; } }