.1.0 bbPress (r3653) * * @todo Links and filter */ function bbp_topic_row_actions() { do_action( 'bbp_topic_row_actions' ); } /** * Output value of topic tags field * * @since 2.0.0 bbPress (r2976) */ function bbp_form_topic_tags() { echo bbp_get_form_topic_tags(); } /** * Return value of topic tags field * * @since 2.0.0 bbPress (r2976) * * @return string Value of topic tags field */ function bbp_get_form_topic_tags() { // Default return value $topic_tags = ''; // Get _POST data if ( ( bbp_is_topic_form_post_request() || bbp_is_reply_form_post_request() ) && isset( $_POST['bbp_topic_tags'] ) ) { $topic_tags = wp_unslash( $_POST['bbp_topic_tags'] ); // Get edit data } elseif ( bbp_is_single_topic() || bbp_is_single_reply() || bbp_is_topic_edit() || bbp_is_reply_edit() ) { // Determine the topic id based on the post type switch ( get_post_type() ) { // Post is a topic case bbp_get_topic_post_type() : $topic_id = bbp_get_topic_id( get_the_ID() ); break; // Post is a reply case bbp_get_reply_post_type() : $topic_id = bbp_get_reply_topic_id( get_the_ID() ); break; } // Topic exists if ( ! empty( $topic_id ) ) { // Topic is spammed so display pre-spam terms if ( bbp_is_topic_spam( $topic_id ) ) { // Get pre-spam terms $spam_terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true ); $topic_tags = ( ! empty( $spam_terms ) ) ? implode( ', ', $spam_terms ) : ''; // Topic is not spam so get real terms } else { $topic_tags = bbp_get_topic_tag_names( $topic_id ); } } } // Filter & return return apply_filters( 'bbp_get_form_topic_tags', $topic_tags ); } /** * Output value of topic forum * * @since 2.0.0 bbPress (r2976) */ function bbp_form_topic_forum() { echo bbp_get_form_topic_forum(); } /** * Return value of topic forum * * @since 2.0.0 bbPress (r2976) * * @return string Value of topic content field */ function bbp_get_form_topic_forum() { // Get _POST data if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_forum_id'] ) ) { $topic_forum = (int) $_POST['bbp_forum_id']; // Get edit data } elseif ( bbp_is_topic_edit() ) { $topic_forum = bbp_get_topic_forum_id(); // No data } else { $topic_forum = 0; } // Filter & return return apply_filters( 'bbp_get_form_topic_forum', $topic_forum ); } /** * Output checked value of topic subscription * * @since 2.0.0 bbPress (r2976) */ function bbp_form_topic_subscribed() { echo bbp_get_form_topic_subscribed(); } /** * Return checked value of topic subscription * * @since 2.0.0 bbPress (r2976) * * @return string Checked value of topic subscription */ function bbp_get_form_topic_subscribed() { // Default value $topic_subscribed = false; // Get _POST data if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_topic_subscription'] ) ) { $topic_subscribed = (bool) $_POST['bbp_topic_subscription']; // Get edit data } elseif ( bbp_is_topic_edit() || bbp_is_reply_edit() ) { $post_author = (int) bbp_get_global_post_field( 'post_author', 'raw' ); $topic_subscribed = bbp_is_user_subscribed( $post_author, bbp_get_topic_id() ); // Get current status } elseif ( bbp_is_single_topic() ) { $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_topic_id() ); } // Get checked output $checked = checked( $topic_subscribed, true, false ); // Filter & return return apply_filters( 'bbp_get_form_topic_subscribed', $checked, $topic_subscribed ); } /** * Output checked value of topic log edit field * * @since 2.0.0 bbPress (r2976) */ function bbp_form_topic_log_edit() { echo bbp_get_form_topic_log_edit(); } /** * Return checked value of topic log edit field * * @since 2.0.0 bbPress (r2976) * * @return string Topic log edit checked value */ function bbp_get_form_topic_log_edit() { // Get _POST data if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_log_topic_edit'] ) ) { $topic_revision = (bool) $_POST['bbp_log_topic_edit']; // No data } else { $topic_revision = true; } // Get checked output $checked = checked( $topic_revision, true, false ); // Filter & return return apply_filters( 'bbp_get_form_topic_log_edit', $checked, $topic_revision ); } /** * Output the value of the topic edit reason * * @since 2.0.0 bbPress (r2976) */ function bbp_form_topic_edit_reason() { echo bbp_get_form_topic_edit_reason(); } /** * Return the value of the topic edit reason * * @since 2.0.0 bbPress (r2976) * * @return string Topic edit reason value */ function bbp_get_form_topic_edit_reason() { // Get _POST data if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_topic_edit_reason'] ) ) { $topic_edit_reason = wp_unslash( $_POST['bbp_topic_edit_reason'] ); // No data } else { $topic_edit_reason = ''; } // Filter & return return apply_filters( 'bbp_get_form_topic_edit_reason', $topic_edit_reason ); } /** * Verify if a POST request came from a failed topic attempt. * * Used to avoid cross-site request forgeries when checking posted topic form * content. * * @see bbp_topic_form_fields() * * @since 2.6.0 bbPress (r5558) * * @return boolean True if is a post request with valid nonce */ function bbp_is_topic_form_post_request() { // Bail if not a post request if ( ! bbp_is_post_request() ) { return false; } // Creating a new topic if ( bbp_verify_nonce_request( 'bbp-new-topic' ) ) { return true; } // Editing an existing topic if ( bbp_verify_nonce_request( 'bbp-edit-topic_' . bbp_get_topic_id() ) ) { return true; } return false; } /** Warning *******************************************************************/ /** * Should the topic-lock alert appear? * * @since 2.6.0 bbPress (r6342) * * @return bool */ function bbp_show_topic_lock_alert() { // Default to not showing the alert $retval = false; // Get the current topic ID $topic_id = bbp_get_topic_id(); // Only show on single topic pages if ( bbp_is_topic_edit() || bbp_is_single_topic() ) { // Only show to moderators if ( current_user_can( 'moderate', $topic_id ) ) { // Locked? $user_id = bbp_check_post_lock( $topic_id ); // Only show if not locked by the current user if ( ! empty( $user_id ) && ( bbp_get_current_user_id() !== $user_id ) ) { $retval = true; } } } // Filter & return return (bool) apply_filters( 'bbp_show_topic_lock_alert', $retval, $topic_id ); } /** * Output the topic lock description * * @since 2.6.0 bbPress (r6343) * * @param int $topic_id Optional. Topic id */ function bbp_topic_lock_description( $topic_id = 0 ) { echo bbp_get_topic_lock_description( $topic_id ); } /** * Return the topic lock description * * @since 2.6.0 bbPress (r6343) * * @param int $topic_id Optional. Topic id */ function bbp_get_topic_lock_description( $topic_id = 0 ) { // Check if topic is edit locked $topic_id = bbp_get_topic_id( $topic_id ); $user_id = bbp_check_post_lock( $topic_id ); $person = empty( $user_id ) ? esc_html__( 'Nobody', 'bbpress' ) : bbp_get_user_profile_link( $user_id ); // Get the text $text = sprintf( esc_html__( '%1$s is currently editing this topic.', 'bbpress' ), $person ); // Filter & return return apply_filters( 'bbp_get_topic_lock_description', $text, $user_id, $topic_id ); }