ID, self::LISTED ); $enabled = Subscriptions::enabled(); if ( ! $enabled && ! $subscriptions ) { return; } $own = get_current_user_id() === $user->ID; echo '

' . esc_html__( 'Feature requests', 'feature-request-system' ) . '

'; echo ''; if ( $enabled ) { printf( '', esc_html__( 'Following', 'feature-request-system' ), esc_attr( Subscriptions::META_AUTO_FOLLOW ), checked( Subscriptions::wants_automatic( $user->ID ), true, false ), $own ? esc_html__( 'Follow the requests I vote for or suggest', 'feature-request-system' ) : esc_html__( 'Follow the requests this user votes for or suggests', 'feature-request-system' ), esc_html__( 'A follower of a request gets an email when its status changes.', 'feature-request-system' ) ); } echo ''; } /** * Saves the section, when the profile form was submitted by someone who may edit the user. * * @param int $user_id User whose profile is saved. */ public static function save( int $user_id ): void { if ( ! current_user_can( 'edit_user', $user_id ) || ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'update-user_' . $user_id ) ) { return; } // The choice is only on the form while the site emails followers. if ( isset( $_POST[ Subscriptions::META_AUTO_FOLLOW ] ) ) { Subscriptions::set_automatic( $user_id, '1' === $_POST[ Subscriptions::META_AUTO_FOLLOW ] ); } $unfollow = isset( $_POST[ self::FIELD_UNFOLLOW ] ) && is_array( $_POST[ self::FIELD_UNFOLLOW ] ) ? array_map( 'absint', $_POST[ self::FIELD_UNFOLLOW ] ) : []; foreach ( $unfollow as $request_id ) { SubscriptionRepository::remove( $request_id, $user_id ); } } /** * Prints the requests a user follows, each with a box to stop following it. * * @param array> $subscriptions The user's newest subscriptions. * @param int $total How many requests the user follows. */ private static function render_list( array $subscriptions, int $total ): void { if ( ! $subscriptions ) { echo '

' . esc_html__( 'None.', 'feature-request-system' ) . '

'; return; } echo '
' . esc_html__( 'Followed requests', 'feature-request-system' ) . ''; if ( $total > count( $subscriptions ) ) { printf( '

%s

', /* translators: %s: number of requests. */ esc_html( sprintf( _n( 'And %s more.', 'And %s more.', $total - count( $subscriptions ), 'feature-request-system' ), number_format_i18n( $total - count( $subscriptions ) ) ) ) ); } echo '
'; } }