コード例 #1
0
/**
 * Can a user moderate a forum?
 *
 * @since 2.6.0 bbPress (r5834)
 *
 * @param int $user_id User id.
 * @param int $forum_id Forum id.
 * @uses bbp_get_user_id()
 * @uses bbp_get_forum_id()
 * @uses bbp_get_moderator_forum_ids()
 * @uses apply_filters() Calls 'bbp_is_user_forum_moderator' with the forums
 *
 * @return bool Return true if user is moderator of forum
 */
function bbp_is_user_forum_moderator($user_id = 0, $forum_id = 0)
{
    // Assume user cannot moderate the forum.
    $retval = false;
    // Validate user ID - fallback to current user if no ID passed.
    $user_id = bbp_get_user_id($user_id, false, !empty($user_id));
    $forum_id = bbp_get_forum_id($forum_id);
    $forum_ids = array();
    // Only check if per-forum moderation is enabled
    if (bbp_allow_forum_mods()) {
        // Get forums the user can moderate.
        $forum_ids = bbp_get_moderator_forum_ids($user_id);
        // Is this forum ID in the users array of forum IDs?
        if (!empty($forum_ids)) {
            $retval = in_array($forum_id, $forum_ids);
        }
    }
    return (bool) apply_filters('bbp_is_user_forum_moderator', $retval, $user_id, $forum_id, $forum_ids);
}
コード例 #2
0
/**
 * Handle the saving of core forum metadata (Status, Visibility, and Type)
 *
 * @since 2.1.0 bbPress (r3678)
 *
 * @param int $forum_id
 * @uses bbp_is_forum_closed() To check if forum is closed
 * @uses bbp_close_forum() To close forum
 * @uses bbp_open_forum() To open forum
 * @uses bbp_is_forum_category() To check if forum is a category
 * @uses bbp_categorize_forum() To turn forum into a category
 * @uses bbp_normalize_forum() To turn category into forum
 * @uses bbp_get_public_status_id() To get the public status ID
 * @uses bbp_get_private_status_id() To get the private status ID
 * @uses bbp_get_hidden_status_id() To get the hidden status ID
 * @uses bbp_get_forum_visibility() To get the forums visibility
 * @uses bbp_hide_forum() To hide a forum
 * @uses bbp_privatize_forum() To make a forum private
 * @uses bbp_publicize_forum() To make a forum public
 * @return If forum ID is empty
 */
function bbp_save_forum_extras($forum_id = 0)
{
    // Validate the forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    // Bail if forum ID is empty
    if (empty($forum_id) || !bbp_is_forum($forum_id)) {
        return;
    }
    /** Forum Status **********************************************************/
    if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) {
        if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) {
            bbp_close_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_open($forum_id, false)) {
            bbp_open_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) {
            bbp_open_forum($forum_id);
        }
    }
    /** Forum Type ************************************************************/
    if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) {
        if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_categorize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        }
    }
    /** Forum Visibility ******************************************************/
    if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array_keys(bbp_get_forum_visibilities()))) {
        // Get forums current visibility
        $old_visibility = bbp_get_forum_visibility($forum_id);
        // Sanitize the new visibility
        $new_visibility = sanitize_key($_POST['bbp_forum_visibility']);
        // What is the new forum visibility setting?
        switch ($new_visibility) {
            // Hidden
            case bbp_get_hidden_status_id():
                bbp_hide_forum($forum_id, $old_visibility);
                break;
                // Private
            // Private
            case bbp_get_private_status_id():
                bbp_privatize_forum($forum_id, $old_visibility);
                break;
                // Publish (default)
            // Publish (default)
            case bbp_get_public_status_id():
            default:
                bbp_publicize_forum($forum_id, $old_visibility);
                break;
        }
        /**
         * Allow custom forum visibility save actions
         *
         * @since 2.6.0 bbPress (r5855)
         *
         * @param int    $forum_id       The forum ID
         * @param string $old_visibility The current forum visibility
         * @param string $new_visibility The new forum visibility
         */
        do_action('bbp_update_forum_visibility', $forum_id, $old_visibility, $new_visibility);
    }
    /** Forum Moderators ******************************************************/
    // Either replace terms
    if (bbp_allow_forum_mods()) {
        if (current_user_can('assign_moderators') && !empty($_POST['bbp_moderators'])) {
            // Escape tag input
            $users = sanitize_text_field($_POST['bbp_moderators']);
            // Explode by comma
            $users = strstr($users, ',') ? explode(',', $users) : (array) $users;
            $user_ids = bbp_get_user_ids_from_nicenames($users);
            // Update forum moderators
            if (!empty($user_ids)) {
                // Remove all moderators
                bbp_remove_moderator($forum_id, null);
                // Add moderators
                foreach ($user_ids as $user_id) {
                    bbp_add_moderator($forum_id, $user_id);
                }
            }
            // ...or remove them.
        } elseif (isset($_POST['bbp_moderators'])) {
            bbp_remove_moderator($forum_id, null);
        }
    }
}
コード例 #3
0
ファイル: settings.php プロジェクト: joeyblake/bbpress
/**
 * Allow forum-mods setting field
 *
 * @since 2.6.0 bbPress (r5834)
 *
 * @uses checked() To display the checked attribute
 */
function bbp_admin_setting_callback_forum_mods()
{
    ?>

	<input name="_bbp_allow_forum_mods" id="_bbp_allow_forum_mods" type="checkbox" value="1" <?php 
    checked(bbp_allow_forum_mods(true));
    bbp_maybe_admin_setting_disabled('_bbp_allow_forum_mods');
    ?>
 />
	<label for="_bbp_allow_forum_mods"><?php 
    esc_html_e('Allow forums to have dedicated moderators', 'bbpress');
    ?>
</label>

<?php 
}
コード例 #4
0
							<label><?php 
        esc_html_e('You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:', 'bbpress');
        ?>
</label><br />
							<code><?php 
        bbp_allowed_tags();
        ?>
</code>
						</p>

					<?php 
    }
    ?>

					<?php 
    if (bbp_allow_forum_mods() && current_user_can('assign_moderators')) {
        ?>

						<?php 
        do_action('bbp_theme_before_forum_form_mods');
        ?>

						<p>
							<label for="bbp_moderators"><?php 
        esc_html_e('Forum Moderators:', 'bbpress');
        ?>
</label><br />
							<input type="text" value="<?php 
        bbp_form_forum_moderators();
        ?>
" size="40" name="bbp_moderators" id="bbp_moderators" />
コード例 #5
0
ファイル: forums.php プロジェクト: joeyblake/bbpress
 /**
  * Manage the column headers for the forums page
  *
  * @since 2.0.0 bbPress (r2485)
  *
  * @param array $columns The columns
  * @uses apply_filters() Calls 'bbp_admin_forums_column_headers' with
  *                        the columns
  * @return array $columns bbPress forum columns
  */
 public function column_headers($columns)
 {
     if ($this->bail()) {
         return $columns;
     }
     // Set list table column headers
     $columns = array('cb' => '<input type="checkbox" />', 'title' => __('Forum', 'bbpress'), 'bbp_forum_topic_count' => __('Topics', 'bbpress'), 'bbp_forum_reply_count' => __('Replies', 'bbpress'), 'author' => __('Creator', 'bbpress'), 'bbp_forum_mods' => __('Moderators', 'bbpress'), 'bbp_forum_created' => __('Created', 'bbpress'), 'bbp_forum_freshness' => __('Freshness', 'bbpress'));
     // Remove forum mods column if not enabled
     if (!bbp_allow_forum_mods()) {
         unset($columns['bbp_forum_mods']);
     }
     return apply_filters('bbp_admin_forums_column_headers', $columns);
 }
コード例 #6
0
ファイル: template.php プロジェクト: joeyblake/bbpress
/**
 * Return the moderators of a forum
 *
 * @since 2.6.0 bbPress (r5834)
 *
 * @param int   $forum_id Optional. Forum id
 * @param array $args     This function supports these arguments:
 *  - before: Before the tag list
 *  - sep: Tag separator
 *  - after: After the tag list
 * @uses bbp_get_forum_id()  To get the forum id
 * @uses get_the_term_list() To get the moderator list
 *
 * @return string Moderator list of the forum
 */
function bbp_get_forum_mod_list($forum_id = 0, $args = array())
{
    // Bail if forum-mods are off
    if (!bbp_allow_forum_mods()) {
        return '';
    }
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('before' => '<div class="bbp-forum-mods"><p>' . esc_html__('Moderators:', 'bbpress') . '&nbsp;', 'sep' => ', ', 'after' => '</p></div>', 'none' => ''), 'get_forum_mod_list');
    // Bail if forum ID is invalid
    $forum_id = bbp_get_forum_id($forum_id);
    if (empty($forum_id)) {
        return '';
    }
    // Get forum moderators
    $moderators = bbp_get_forum_mods($forum_id);
    if (!empty($moderators)) {
        // In admin, use nicenames
        if (is_admin()) {
            // @todo link to filtering forums by moderator
            $users = wp_list_pluck($moderators, 'name');
            // In theme, use display names & profile links
        } else {
            $users = array();
            $term_ids = wp_list_pluck($moderators, 'term_id');
            foreach ($term_ids as $term_id) {
                $user_id = bbp_get_term_taxonomy_user_id($term_id);
                $users[] = bbp_get_user_profile_link($user_id);
            }
        }
        $retval = $r['before'] . implode($r['sep'], $users) . $r['after'];
        // No forum moderators
    } else {
        $retval = $r['none'];
    }
    return $retval;
}
コード例 #7
0
ファイル: capabilities.php プロジェクト: joeyblake/bbpress
/**
 * Maps topic capabilities
 *
 * @since 2.2.0 bbPress (r4242)
 *
 * @param array $caps Capabilities for meta capability
 * @param string $cap Capability name
 * @param int $user_id User id
 * @param array $args Arguments
 * @uses get_post() To get the post
 * @uses get_post_type_object() To get the post type object
 * @uses bbp_get_public_status_id() To get the public status id
 * @uses bbp_is_user_forum_mod() To check if the user is a forum moderator
 * @uses bbp_get_reply_forum_id() To get the repliy forum id
 * @uses apply_filters() Filter mapped results
 *
 * @return array Actual capabilities for meta capability
 */
function bbp_map_reply_meta_caps($caps = array(), $cap = '', $user_id = 0, $args = array())
{
    // What capability is being checked?
    switch ($cap) {
        /** Reading ***********************************************************/
        case 'read_reply':
            // User cannot spectate
            if (!user_can($user_id, 'spectate')) {
                $caps = array('do_not_allow');
                // Do some post ID based logic
            } else {
                // Get the post
                $_post = get_post($args[0]);
                if (!empty($_post)) {
                    // Get post type object
                    $post_type = get_post_type_object($_post->post_type);
                    // Post is public
                    if (bbp_get_public_status_id() === $_post->post_status) {
                        $caps = array('spectate');
                        // User is author so allow read
                    } elseif ((int) $user_id === (int) $_post->post_author) {
                        $caps = array('spectate');
                        // Unknown so map to private posts
                    } else {
                        $caps = array($post_type->cap->read_private_posts);
                    }
                }
            }
            break;
            /** Publishing ********************************************************/
        /** Publishing ********************************************************/
        case 'publish_replies':
            // Moderators can always publish
            if (user_can($user_id, 'moderate')) {
                $caps = array('moderate');
            }
            break;
            /** Editing ***********************************************************/
            // Used primarily in wp-admin
        /** Editing ***********************************************************/
        // Used primarily in wp-admin
        case 'edit_replies':
        case 'edit_others_replies':
            // Moderators can always edit
            if (user_can($user_id, 'moderate')) {
                $caps = array('moderate');
                // Otherwise, block
            } else {
                $caps = array('do_not_allow');
            }
            break;
            // Used everywhere
        // Used everywhere
        case 'edit_reply':
            // Get the post
            $_post = get_post($args[0]);
            if (!empty($_post)) {
                // Get post type object
                $post_type = get_post_type_object($_post->post_type);
                $caps = array();
                // Add 'do_not_allow' cap if user is spam or deleted
                if (bbp_is_user_inactive($user_id)) {
                    $caps[] = 'do_not_allow';
                    // User is author so allow edit if not in admin
                } elseif (!is_admin() && (int) $user_id === (int) $_post->post_author) {
                    $caps[] = $post_type->cap->edit_posts;
                    // User is a per-forum moderator, make sure they can spectate.
                } elseif (bbp_allow_forum_mods() && bbp_is_user_forum_mod($user_id, bbp_get_reply_forum_id($_post->ID))) {
                    $caps = array('spectate');
                    // Fallback to edit_others_posts.
                } else {
                    $caps[] = $post_type->cap->edit_others_posts;
                }
            }
            break;
            /** Deleting **********************************************************/
        /** Deleting **********************************************************/
        case 'delete_reply':
            // Get the post
            $_post = get_post($args[0]);
            if (!empty($_post)) {
                // Get post type object
                $post_type = get_post_type_object($_post->post_type);
                $caps = array();
                // Add 'do_not_allow' cap if user is spam or deleted
                if (bbp_is_user_inactive($user_id)) {
                    $caps[] = 'do_not_allow';
                    // Moderators can always edit forum content
                } elseif (user_can($user_id, 'moderate')) {
                    $caps[] = 'moderate';
                    // User is author so allow edit if not in admin
                } elseif (!is_admin() && (int) $user_id === (int) $_post->post_author) {
                    $caps[] = $post_type->cap->delete_posts;
                    // Unknown so map to delete_others_posts
                } else {
                    $caps[] = $post_type->cap->delete_others_posts;
                }
            }
            break;
            // Moderation override
        // Moderation override
        case 'delete_replies':
        case 'delete_others_replies':
            // Moderators can always delete
            if (user_can($user_id, 'moderate')) {
                $caps = array('moderate');
            }
            break;
            /** Admin *************************************************************/
        /** Admin *************************************************************/
        case 'bbp_replies_admin':
            $caps = array('moderate');
            break;
    }
    return apply_filters('bbp_map_reply_meta_caps', $caps, $cap, $user_id, $args);
}
コード例 #8
0
ファイル: bbpress.php プロジェクト: joeyblake/bbpress
 /**
  * Register the topic tag and forum moderator taxonomies
  *
  * @since 2.0.0 bbPress (r2464) Added bbp_get_topic_tag_tax_id() taxonomy
  * @since 2.6.0 bbPress (r5834) Added bbp_get_forum_mod_tax_id() taxonomy
  *
  * @uses register_taxonomy() To register the taxonomy
  * @uses bbp_get_topic_post_type() To get the topic post type
  * @uses bbp_get_topic_tag_tax_labels() To get the topic tag taxonomy labels
  * @uses bbp_get_topic_tag_tax_rewrite() To get the topic tag taxonomy slug
  * @uses bbp_get_topic_tag_caps() To get topic tag capabilities
  * @uses bbp_allow_topic_tags() To check if topic tags are allowed
  * @uses current_user_can() To check if the current user can edit/delete tags
  * @uses bbp_get_forum_post_type() To get the forum post type
  * @uses bbp_get_forum_mod_tax_labels() To get the forum moderator taxonomy label
  * @uses bbp_get_forum_mod_caps() To check the forum moderator capabilities
  * @uses bbp_allow_forum_mods() To check if forum moderators are allowed
  * @uses current_user_can() To check if the current user can edit/delete forums
  */
 public static function register_taxonomies()
 {
     // Register the topic-tag taxonomy.
     register_taxonomy(bbp_get_topic_tag_tax_id(), bbp_get_topic_post_type(), apply_filters('bbp_register_topic_taxonomy', array('labels' => bbp_get_topic_tag_tax_labels(), 'rewrite' => bbp_get_topic_tag_tax_rewrite(), 'capabilities' => bbp_get_topic_tag_caps(), 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'show_tagcloud' => true, 'hierarchical' => false, 'show_in_nav_menus' => false, 'public' => true, 'show_ui' => bbp_allow_topic_tags() && current_user_can('bbp_topic_tags_admin'))));
     // Register the forum-mod taxonomy.
     register_taxonomy(bbp_get_forum_mod_tax_id(), bbp_get_forum_post_type(), apply_filters('bbp_register_forum_moderator_taxonomy', array('labels' => bbp_get_forum_mod_tax_labels(), 'capabilities' => bbp_get_forum_mod_caps(), 'update_count_callback' => '_update_post_term_count', 'query_var' => false, 'show_tagcloud' => true, 'hierarchical' => false, 'show_in_menu' => true, 'show_in_nav_menus' => false, 'public' => false, 'show_ui' => bbp_allow_forum_mods() && current_user_can('bbp_forum_mods_admin'))));
 }
コード例 #9
0
ファイル: functions.php プロジェクト: joeyblake/bbpress
/**
 * Handles the front end edit forum submission
 *
 * @param string $action The requested action to compare this function to
 * @uses bbPress:errors::add() To log various error messages
 * @uses bbp_get_forum() To get the forum
 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
 * @uses bbp_is_forum_anonymous() To check if forum is by an anonymous user
 * @uses current_user_can() To check if the current user can edit the forum
 * @uses bbp_filter_anonymous_post_data() To filter anonymous data
 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
 * @uses bbp_is_forum_category() To check if the forum is a category
 * @uses bbp_is_forum_closed() To check if the forum is closed
 * @uses bbp_is_forum_private() To check if the forum is private
 * @uses remove_filter() To remove kses filters if needed
 * @uses apply_filters() Calls 'bbp_edit_forum_pre_title' with the title and
 *                        forum id
 * @uses apply_filters() Calls 'bbp_edit_forum_pre_content' with the content
 *                        and forum id
 * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors
 * @uses wp_save_post_revision() To save a forum revision
 * @uses bbp_update_forum_revision_log() To update the forum revision log
 * @uses wp_update_post() To update the forum
 * @uses do_action() Calls 'bbp_edit_forum' with the forum id, forum id,
 *                    anonymous data and reply author
 * @uses bbp_move_forum_handler() To handle movement of a forum from one forum
 *                                 to another
 * @uses bbp_get_forum_permalink() To get the forum permalink
 * @uses bbp_redirect() To redirect to the forum link
 * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error
 *                                              messages
 */
function bbp_edit_forum_handler($action = '')
{
    // Bail if action is not bbp-edit-forum
    if ('bbp-edit-forum' !== $action) {
        return;
    }
    // Define local variable(s)
    $anonymous_data = array();
    $forum = $forum_id = $forum_parent_id = 0;
    $forum_title = $forum_content = $forum_edit_reason = '';
    /** Forum *****************************************************************/
    // Forum id was not passed
    if (empty($_POST['bbp_forum_id'])) {
        bbp_add_error('bbp_edit_forum_id', __('<strong>ERROR</strong>: Forum ID not found.', 'bbpress'));
        return;
        // Forum id was passed
    } elseif (is_numeric($_POST['bbp_forum_id'])) {
        $forum_id = (int) $_POST['bbp_forum_id'];
        $forum = bbp_get_forum($forum_id);
    }
    // Nonce check
    if (!bbp_verify_nonce_request('bbp-edit-forum_' . $forum_id)) {
        bbp_add_error('bbp_edit_forum_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
        return;
        // Forum does not exist
    } elseif (empty($forum)) {
        bbp_add_error('bbp_edit_forum_not_found', __('<strong>ERROR</strong>: The forum you want to edit was not found.', 'bbpress'));
        return;
        // User cannot edit this forum
    } elseif (!current_user_can('edit_forum', $forum_id)) {
        bbp_add_error('bbp_edit_forum_permissions', __('<strong>ERROR</strong>: You do not have permission to edit that forum.', 'bbpress'));
        return;
    }
    // Remove kses filters from title and content for capable users and if the nonce is verified
    if (current_user_can('unfiltered_html') && !empty($_POST['_bbp_unfiltered_html_forum']) && wp_create_nonce('bbp-unfiltered-html-forum_' . $forum_id) === $_POST['_bbp_unfiltered_html_forum']) {
        remove_filter('bbp_edit_forum_pre_title', 'wp_filter_kses');
        remove_filter('bbp_edit_forum_pre_content', 'bbp_encode_bad', 10);
        remove_filter('bbp_edit_forum_pre_content', 'bbp_filter_kses', 30);
    }
    /** Forum Parent ***********************************************************/
    // Forum parent id was passed
    if (!empty($_POST['bbp_forum_parent_id'])) {
        $forum_parent_id = bbp_get_forum_id($_POST['bbp_forum_parent_id']);
    }
    // Current forum this forum is in
    $current_parent_forum_id = bbp_get_forum_parent_id($forum_id);
    // Forum exists
    if (!empty($forum_parent_id) && $forum_parent_id !== $current_parent_forum_id) {
        // Forum is closed and user cannot access
        if (bbp_is_forum_closed($forum_parent_id) && !current_user_can('edit_forum', $forum_parent_id)) {
            bbp_add_error('bbp_edit_forum_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new forums.', 'bbpress'));
        }
        // Forum is private and user cannot access
        if (bbp_is_forum_private($forum_parent_id) && !current_user_can('read_private_forums')) {
            bbp_add_error('bbp_edit_forum_forum_private', __('<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress'));
        }
        // Forum is hidden and user cannot access
        if (bbp_is_forum_hidden($forum_parent_id) && !current_user_can('read_hidden_forums')) {
            bbp_add_error('bbp_edit_forum_forum_hidden', __('<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress'));
        }
    }
    /** Forum Title ***********************************************************/
    if (!empty($_POST['bbp_forum_title'])) {
        $forum_title = sanitize_text_field($_POST['bbp_forum_title']);
    }
    // Filter and sanitize
    $forum_title = apply_filters('bbp_edit_forum_pre_title', $forum_title, $forum_id);
    // No forum title
    if (empty($forum_title)) {
        bbp_add_error('bbp_edit_forum_title', __('<strong>ERROR</strong>: Your forum needs a title.', 'bbpress'));
    }
    /** Forum Content *********************************************************/
    if (!empty($_POST['bbp_forum_content'])) {
        $forum_content = $_POST['bbp_forum_content'];
    }
    // Filter and sanitize
    $forum_content = apply_filters('bbp_edit_forum_pre_content', $forum_content, $forum_id);
    // No forum content
    if (empty($forum_content)) {
        bbp_add_error('bbp_edit_forum_content', __('<strong>ERROR</strong>: Your forum description cannot be empty.', 'bbpress'));
    }
    /** Forum Blacklist *******************************************************/
    if (!bbp_check_for_blacklist($anonymous_data, bbp_get_forum_author_id($forum_id), $forum_title, $forum_content)) {
        bbp_add_error('bbp_forum_blacklist', __('<strong>ERROR</strong>: Your forum cannot be edited at this time.', 'bbpress'));
    }
    /** Forum Moderation ******************************************************/
    $post_status = bbp_get_public_status_id();
    if (!bbp_check_for_moderation($anonymous_data, bbp_get_forum_author_id($forum_id), $forum_title, $forum_content)) {
        $post_status = bbp_get_pending_status_id();
    }
    /** Forum Mods ************************************************************/
    // Either replace terms
    if (bbp_allow_forum_mods() && current_user_can('assign_forum_mods') && !empty($_POST['bbp_forum_mods'])) {
        // Escape tag input
        $terms = sanitize_text_field($_POST['bbp_forum_mods']);
        // Explode by comma
        if (strstr($terms, ',')) {
            $terms = explode(',', $terms);
        }
        // Add forum mod ID as main key
        $terms = array(bbp_get_forum_mod_tax_id() => $terms);
        // ...or remove them.
    } elseif (isset($_POST['bbp_forum_mods'])) {
        $terms = array(bbp_get_forum_mod_tax_id() => array());
        // Existing terms
    } else {
        $terms = array(bbp_get_forum_mod_tax_id() => explode(',', bbp_get_forum_mod_names($forum_id, ',')));
    }
    /** Additional Actions (Before Save) **************************************/
    do_action('bbp_edit_forum_pre_extras', $forum_id);
    // Bail if errors
    if (bbp_has_errors()) {
        return;
    }
    /** No Errors *************************************************************/
    // Add the content of the form to $forum_data as an array
    // Just in time manipulation of forum data before being edited
    $forum_data = apply_filters('bbp_edit_forum_pre_insert', array('ID' => $forum_id, 'post_title' => $forum_title, 'post_content' => $forum_content, 'post_status' => $post_status, 'post_parent' => $forum_parent_id));
    // Insert forum
    $forum_id = wp_update_post($forum_data);
    /** Revisions *************************************************************/
    /**
    * @todo omitted for 2.1
    	// Revision Reason
    	if ( ! empty( $_POST['bbp_forum_edit_reason'] ) )
    		$forum_edit_reason = sanitize_text_field( $_POST['bbp_forum_edit_reason'] );
    
    	// Update revision log
    	if ( ! empty( $_POST['bbp_log_forum_edit'] ) && ( "1" === $_POST['bbp_log_forum_edit'] ) && ( $revision_id = wp_save_post_revision( $forum_id ) ) ) {
    		bbp_update_forum_revision_log( array(
    			'forum_id'    => $forum_id,
    			'revision_id' => $revision_id,
    			'author_id'   => bbp_get_current_user_id(),
    			'reason'      => $forum_edit_reason
    		) );
    	}
    */
    /** No Errors *************************************************************/
    if (!empty($forum_id) && !is_wp_error($forum_id)) {
        // Update counts, etc...
        do_action('bbp_edit_forum', array('forum_id' => $forum_id, 'post_parent' => $forum_parent_id, 'forum_author' => $forum->post_author, 'last_topic_id' => 0, 'last_reply_id' => 0, 'last_active_id' => 0, 'last_active_time' => 0, 'last_active_status' => bbp_get_public_status_id()));
        // If the new forum parent id is not equal to the old forum parent
        // id, run the bbp_move_forum action and pass the forum's parent id
        // as the first arg and new forum parent id as the second.
        // @todo implement
        //if ( $forum_id !== $forum->post_parent )
        //	bbp_move_forum_handler( $forum_parent_id, $forum->post_parent, $forum_id );
        /** Additional Actions (After Save) ***********************************/
        do_action('bbp_edit_forum_post_extras', $forum_id);
        /** Redirect **********************************************************/
        // Redirect to
        $redirect_to = bbp_get_redirect_to();
        // View all?
        $view_all = bbp_get_view_all();
        // Get the forum URL
        $forum_url = bbp_get_forum_permalink($forum_id, $redirect_to);
        // Add view all?
        if (!empty($view_all)) {
            $forum_url = bbp_add_view_all($forum_url);
        }
        // Allow to be filtered
        $forum_url = apply_filters('bbp_edit_forum_redirect_to', $forum_url, $view_all, $redirect_to);
        /** Successful Edit ***************************************************/
        // Redirect back to new forum
        bbp_redirect($forum_url);
        /** Errors ****************************************************************/
    } else {
        $append_error = is_wp_error($forum_id) && $forum_id->get_error_message() ? $forum_id->get_error_message() . ' ' : '';
        bbp_add_error('bbp_forum_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your forum:' . $append_error . 'Please try again.', 'bbpress'));
    }
}
コード例 #10
0
ファイル: functions.php プロジェクト: joeyblake/bbpress
function bbp_filter_forum_mod_term_link($termlink = '', $term = '', $taxonomy = '')
{
    // Bail if taxonomy is not forum mod
    if (bbp_get_forum_mod_tax_id() !== $taxonomy) {
        return $termlink;
    }
    // Bail if forum mods is not allowed
    if (!bbp_allow_forum_mods()) {
        return $termlink;
    }
    // Get user ID from taxonomy term
    $user_id = bbp_get_term_taxonomy_user_id($term->term_id, bbp_get_forum_mod_tax_id());
    if (is_admin()) {
        // Get the moderator's display name
        $display_name = get_userdata($user_id)->display_name;
        $user_link = get_edit_user_link($user_id);
        // Link or name only
        if (!empty($user_link)) {
            $retval = '<a href="' . esc_url($user_link) . '">' . esc_html($display_name) . '</a>';
            // Can't edit
        } else {
            $retval = $display_name;
        }
        // Theme side term link
    } else {
        $retval = bbp_get_user_profile_link($user_id);
    }
    return $retval;
}