Пример #1
0
/**
 * Gets the footer of an idea
 *
 * @package WP Idea Stream
 * @subpackage ideas/tags
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream() to get plugin's main instance
 * @uses   wp_idea_stream_ideas_get_the_term_list() to get the taxonomy term list
 * @uses   wp_idea_stream_get_category() to get the category taxonomy identifier
 * @uses   wp_idea_stream_get_tag() to get the tag taxonomy identifier
 * @uses   mysql2date() to format the date
 * @uses   wp_idea_stream_is_single_idea() to check if the idea is displayed on its single template
 * @uses   wp_idea_stream_user_can() to check for user's capability
 * @uses   esc_url() to sanitize url
 * @uses   get_edit_post_link() to get the edit link of an idea
 * @uses   wp_idea_stream_users_get_user_data() to get user's attribute
 * @uses   wp_idea_stream_users_get_user_profile_url() to get user's profile link
 * @uses   get_avatar() to get user's avatar
 * @uses   esc_html() to sanitize the output
 * @uses   apply_filters() call 'wp_idea_stream_ideas_get_idea_footer' to override the output
 * @return string  output for the footer
 */
function wp_idea_stream_ideas_get_idea_footer()
{
    $idea = wp_idea_stream()->query_loop->idea;
    $retarray = array('start' => __('This idea', 'wp-idea-stream'));
    $category_list = wp_idea_stream_ideas_get_the_term_list($idea->ID, wp_idea_stream_get_category());
    if (!empty($category_list)) {
        $retarray['category'] = sprintf(_x('was posted in %s', 'idea categories comma separated list', 'wp-idea-stream'), $category_list);
    }
    $tag_list = wp_idea_stream_ideas_get_the_term_list($idea->ID, wp_idea_stream_get_tag());
    if (!empty($tag_list)) {
        $in = _x('and tagged', 'idea tags join words', 'wp-idea-stream');
        if (empty($category_list)) {
            $in = _x('was tagged', 'idea tags join words no category', 'wp-idea-stream');
        }
        $retarray['tag'] = sprintf(_x('%1$s %2$s', 'idea tags comma separated list', 'wp-idea-stream'), $in, $tag_list);
    }
    if (empty($retarray['category']) && empty($retarray['tag'])) {
        $retarray['posted'] = _x('was posted', 'idea footer empty tags and categories', 'wp-idea-stream');
    }
    $date = apply_filters('get_the_date', mysql2date(get_option('date_format'), $idea->post_date));
    if (!wp_idea_stream_is_single_idea()) {
        // point at the end
        $retarray['date'] = sprintf(_x('on %s.', 'idea date of publication point', 'wp-idea-stream'), $date);
    } else {
        // no point at the end
        $retarray['date'] = sprintf(_x('on %s', 'idea date of publication no point', 'wp-idea-stream'), $date);
        $user = wp_idea_stream_users_get_user_data('id', $idea->post_author);
        $user_link = '<a class="idea-author" href="' . esc_url(wp_idea_stream_users_get_user_profile_url($idea->post_author, $user->user_nicename)) . '" title="' . esc_attr($user->display_name) . '">';
        $user_link .= get_avatar($idea->post_author, 20) . esc_html($user->display_name) . '</a>';
        $retarray['author'] = sprintf(_x('by %s.', 'single idea author link', 'wp-idea-stream'), $user_link);
    }
    // Init edit url
    $edit_url = '';
    // Super admin will use the IdeaStream Administration screens
    if (wp_idea_stream_user_can('wp_idea_stream_ideas_admin')) {
        $edit_url = get_edit_post_link($idea->ID);
        // The author will use the front end edit form
    } else {
        if (wp_idea_stream_ideas_can_edit($idea)) {
            $edit_url = wp_idea_stream_get_form_url(wp_idea_stream_edit_slug(), $idea->post_name);
        }
    }
    if (!empty($edit_url)) {
        $retarray['edit'] = '<a href="' . esc_url($edit_url) . '" title="' . esc_attr__('Edit Idea', 'wp-idea-stream') . '">' . esc_html__('Edit Idea', 'wp-idea-stream') . '</a>';
    }
    /**
     * @param  string  the footer to output
     * @param  array   $retarray the parts of the footer organized in an associative array
     * @param  WP_Post $idea the idea object
     */
    return apply_filters('wp_idea_stream_ideas_get_idea_footer', join(' ', $retarray), $retarray, $idea);
}
Пример #2
0
/**
 * Handles updating an idea
 *
 * @package WP Idea Stream
 * @subpackage ideas/functions
 *
 * @since 2.0.0
 *
 * @uses   check_admin_referer() to check the request has been done from current site
 * @uses   wp_idea_stream_get_redirect_url() to get default redirect url
 * @uses   get_query_var() to get the value of a specific query var
 * @uses   wp_idea_stream_get_post_type() to get the ideas post type identifier
 * @uses   get_queried_object() to try to get the idea object WordPress built
 * @uses   wp_idea_stream_ideas_get_idea_by_name() to get an idea object out of its post name
 * @uses   wp_idea_stream_user_can() to check user's capability
 * @uses   wp_idea_stream_add_message() to add a feddback message to user
 * @uses   wp_safe_redirect() to safely redirect the user and avoid duplicates
 * @uses   wp_idea_stream_ideas_save_idea() to save the idea
 * @uses   wp_idea_stream_get_form_url() to get the add new form url
 * @uses   wp_idea_stream_ideas_get_idea_permalink() to get the idea link
 */
function wp_idea_stream_ideas_update_idea()
{
    global $wp_query;
    // Bail if not a post request
    if ('POST' != strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if not a post idea request
    if (empty($_POST['wp_idea_stream']) || !is_array($_POST['wp_idea_stream'])) {
        return;
    }
    // Bail if it's not an update
    if (empty($_POST['wp_idea_stream']['_the_id'])) {
        return;
    }
    // Check nonce
    check_admin_referer('wp_idea_stream_save');
    $redirect = wp_idea_stream_get_redirect_url();
    // Get idea name
    $idea_name = get_query_var(wp_idea_stream_get_post_type());
    // Get Idea Object
    $idea = get_queried_object();
    // If queried object doesn't match or wasn't helpfull, try to get the idea using core function
    if (empty($idea->post_name) || empty($idea_name) || $idea_name != $idea->post_name) {
        $idea = wp_idea_stream_ideas_get_idea_by_name($idea_name);
    }
    // Found no idea, redirect and inform the user
    if (empty($idea->ID)) {
        wp_idea_stream_add_message(array('type' => 'error', 'content' => __('The idea you are trying to edit does not seem to exist.', 'wp-idea-stream')));
        // Redirect to main archive page
        wp_safe_redirect($redirect);
        exit;
    }
    // Checks if the user can edit the idea
    if (!wp_idea_stream_ideas_can_edit($idea)) {
        // Add feedback to the user
        wp_idea_stream_add_message(array('type' => 'error', 'content' => __('You are not allowed to edit this idea.', 'wp-idea-stream')));
        // Redirect to main archive page
        wp_safe_redirect($redirect);
        exit;
    }
    $updated = array_diff_key($_POST['wp_idea_stream'], array('save' => 'submit'));
    // Title & content are required
    if (empty($updated['_the_title']) || empty($updated['_the_content'])) {
        // Add feedback to the user
        wp_idea_stream_add_message(array('type' => 'error', 'content' => __('Title and description are required fields.', 'wp-idea-stream')));
        // Simply stop, so that the user keeps the posted values.
        return;
    }
    // Reset '_the_id' param to the ID of the idea found
    $updated['_the_id'] = $idea->ID;
    $feedback_message = array();
    $featured_error = __('There was a problem saving the featured image, sorry.', 'wp-idea-stream');
    $featured_type = 'info';
    // Take care of the featured image
    $thumbnail_id = (int) get_post_thumbnail_id($idea);
    if (!empty($updated['_the_thumbnail'])) {
        $thumbnail_src = key($updated['_the_thumbnail']);
        $thumbnail = reset($updated['_the_thumbnail']);
        // Update the Featured image
        if (!is_numeric($thumbnail) || $thumbnail_id !== (int) $thumbnail) {
            if (is_numeric($thumbnail)) {
                // validate the attachment
                if (!get_post($thumbnail)) {
                    $feedback_message[] = $featured_error;
                    // Set the new Featured image
                } else {
                    set_post_thumbnail($idea->ID, $thumbnail);
                }
            } else {
                $sideload = WP_Idea_Stream_Ideas_Thumbnail::start($thumbnail_src, $idea->ID);
                if (is_wp_error($sideload->result)) {
                    $feedback_message[] = $featured_error;
                }
            }
        }
        // Delete the featured image
    } elseif (!empty($thumbnail_id)) {
        delete_post_thumbnail($idea);
    }
    // Update the idea
    $id = wp_idea_stream_ideas_save_idea($updated);
    if (empty($id)) {
        // Set the feedback for the user
        $featured_type = 'error';
        $feedback_message = __('Something went wrong while trying to update your idea.', 'wp-idea-stream');
        // Redirect to the form
        $redirect = wp_idea_stream_get_form_url(wp_idea_stream_edit_slug(), $idea_name);
        // Redirect to the idea
    } else {
        $redirect = wp_idea_stream_ideas_get_idea_permalink($id);
    }
    if (!empty($feedback_message)) {
        // Add feedback to the user
        wp_idea_stream_add_message(array('type' => $featured_type, 'content' => join(' ', $feedback_message)));
    }
    wp_safe_redirect($redirect);
    exit;
}
/**
 * Check the main WordPress query to match WP Idea Stream conditions
 * Eventually Override query vars and set global template conditions / vars
 *
 * This the key function of the plugin, it is definining the templates
 * to load and is setting the displayed user.
 *
 * Inspired by bbPress 's bbp_parse_query()
 *
 * @package WP Idea Stream
 * @subpackage core/template-functions
 *
 * @since 2.0.0
 *
 * @param WP_Query $posts_query The WP_Query instance
 * @uses  WP_Query->is_main_query() to check it's the main query
 * @uses  WP_Query->get() to get a query var
 * @uses  wp_idea_stream_is_admin() to check if in IdeaStream's Admin territory
 * @uses  wp_idea_stream_is_sticky_enabled() to check if sticky feature is available
 * @uses  WP_Query->set() to set a query var
 * @uses  wp_idea_stream_is_rating_disabled() to check if ratings feature are available
 * @uses  wp_idea_stream_set_idea_var() to globalize a var
 * @uses  is_admin() to check for WordPress administration
 * @uses  wp_idea_stream_get_post_type() to get the ideas post type identifier
 * @uses  wp_idea_stream_user_rewrite_id() to get the user rewrite id
 * @uses  wp_idea_stream_users_get_user_data() to get a specific user's data
 * @uses  WP_Query->set_404() to set a 404
 * @uses  wp_idea_stream_user_rates_rewrite_id() to get the user rates rewrite id
 * @uses  wp_idea_stream_user_comments_rewrite_id() to get the user comments rewrite id
 * @uses  wp_idea_stream_action_rewrite_id() to get the action rewrite id
 * @uses  wp_idea_stream_addnew_slug() to get the add new slug
 * @uses  wp_idea_stream_edit_slug() to get the edit slug
 * @uses  has_action() to check if the action 'wp_idea_stream_custom_action' is used by any plugins
 * @uses  do_action() Calls 'wp_idea_stream_custom_action' to perform actions relative to ideas
 * @uses  wp_idea_stream_get_category() to get the ideas category identifier
 * @uses  wp_idea_stream_get_tag() to get the ideas tag identifier
 * @uses  wp_idea_stream_search_rewrite_id() to get the search rewrite id
 */
function wp_idea_stream_parse_query($posts_query = null)
{
    // Bail if $posts_query is not the main loop
    if (!$posts_query->is_main_query()) {
        return;
    }
    // Bail if filters are suppressed on this query
    if (true === $posts_query->get('suppress_filters')) {
        return;
    }
    // Handle the specific queries in IdeaStream Admin
    if (wp_idea_stream_is_admin()) {
        // Display sticky ideas if requested
        if (wp_idea_stream_is_sticky_enabled() && !empty($_GET['sticky_ideas'])) {
            $posts_query->set('post__in', wp_idea_stream_ideas_get_stickies());
        }
        // Build meta_query if orderby rates is set
        if (!wp_idea_stream_is_rating_disabled() && !empty($_GET['orderby']) && 'rates_count' == $_GET['orderby']) {
            $posts_query->set('meta_query', array(array('key' => '_ideastream_average_rate', 'compare' => 'EXISTS')));
            // Set the orderby idea var
            wp_idea_stream_set_idea_var('orderby', 'rates_count');
        }
        do_action('wp_idea_stream_admin_request', $posts_query);
        return;
    }
    // Bail if else where in admin
    if (is_admin()) {
        return;
    }
    // Ideas post type for a later use
    $idea_post_type = wp_idea_stream_get_post_type();
    /** User's profile ************************************************************/
    // Are we requesting the user-profile template ?
    $user = $posts_query->get(wp_idea_stream_user_rewrite_id());
    $embed_page = wp_idea_stream_is_embed_profile();
    if (!empty($user)) {
        if (!is_numeric($user)) {
            // Get user by his username
            $user = wp_idea_stream_users_get_user_data('slug', $user);
        } else {
            // Get user by his id
            $user = wp_idea_stream_users_get_user_data('id', $user);
        }
        // No user id: no profile!
        if (empty($user->ID) || true === apply_filters('wp_idea_stream_users_is_spammy', is_multisite() && is_user_spammy($user), $user)) {
            $posts_query->set_404();
            // Make sure the WordPress Embed Template will be used
            if ('true' === get_query_var('embed') || true === get_query_var('embed')) {
                $posts_query->is_embed = true;
                $posts_query->set('p', -1);
            }
            return;
        }
        // Set the displayed user id
        wp_idea_stream_set_idea_var('is_user', absint($user->ID));
        // Make sure the post_type is set to ideas.
        $posts_query->set('post_type', $idea_post_type);
        // Are we requesting user rates
        $user_rates = $posts_query->get(wp_idea_stream_user_rates_rewrite_id());
        // Or user comments ?
        $user_comments = $posts_query->get(wp_idea_stream_user_comments_rewrite_id());
        if (!empty($user_rates) && !wp_idea_stream_is_rating_disabled()) {
            // We are viewing user's rates
            wp_idea_stream_set_idea_var('is_user_rates', true);
            // Define the Meta Query to get his rates
            $posts_query->set('meta_query', array(array('key' => '_ideastream_rates', 'value' => ';i:' . $user->ID . ';', 'compare' => 'LIKE')));
        } else {
            if (!empty($user_comments)) {
                // We are viewing user's comments
                wp_idea_stream_set_idea_var('is_user_comments', true);
                /**
                 * Make sure no result.
                 * Query will be built later in user comments loop
                 */
                $posts_query->set('p', -1);
            } else {
                if ('true' === get_query_var('embed') || true === get_query_var('embed')) {
                    $posts_query->is_embed = true;
                    $posts_query->set('p', -1);
                    if ($embed_page) {
                        wp_idea_stream_set_idea_var('is_user_embed', true);
                    } else {
                        $posts_query->set_404();
                        return;
                    }
                }
                // Default to the ideas the user submitted
                $posts_query->set('author', $user->ID);
            }
        }
        // No stickies on user's profile
        $posts_query->set('ignore_sticky_posts', true);
        // Make sure no 404
        $posts_query->is_404 = false;
        // Set the displayed user.
        wp_idea_stream_set_idea_var('displayed_user', $user);
    }
    /** Actions (New Idea) ********************************************************/
    $action = $posts_query->get(wp_idea_stream_action_rewrite_id());
    if (!empty($action)) {
        // Make sure the post type is set to ideas
        $posts_query->set('post_type', $idea_post_type);
        // Define a global to inform we're dealing with an action
        wp_idea_stream_set_idea_var('is_action', true);
        // Is the new idea form requested ?
        if (wp_idea_stream_addnew_slug() == $action) {
            // Yes so set the corresponding var
            wp_idea_stream_set_idea_var('is_new', true);
            /**
             * Make sure no result.
             * We are not querying any content, but creating one
             */
            $posts_query->set('p', -1);
            // Edit action ?
        } else {
            if (wp_idea_stream_edit_slug() == $action) {
                // Yes so set the corresponding var
                wp_idea_stream_set_idea_var('is_edit', true);
                // Signup support
            } else {
                if (wp_idea_stream_signup_slug() == $action && wp_idea_stream_is_signup_allowed_for_current_blog()) {
                    // Set the signup global var
                    wp_idea_stream_set_idea_var('is_signup', true);
                    /**
                     * Make sure no result.
                     * We are not querying any content, but creating one
                     */
                    $posts_query->set('p', -1);
                } else {
                    if (has_action('wp_idea_stream_custom_action')) {
                        /**
                         * Allow plugins to other custom idea actions
                         *
                         * @param string   $action      The requested action
                         * @param WP_Query $posts_query The WP_Query instance
                         */
                        do_action('wp_idea_stream_custom_action', $action, $posts_query);
                    } else {
                        $posts_query->set_404();
                        return;
                    }
                }
            }
        }
    }
    /** Ideas by category *********************************************************/
    $category = $posts_query->get(wp_idea_stream_get_category());
    if (!empty($category)) {
        // Make sure the post type is set to ideas
        $posts_query->set('post_type', $idea_post_type);
        // Define the current category
        wp_idea_stream_set_idea_var('is_category', $category);
    }
    /** Ideas by tag **************************************************************/
    $tag = $posts_query->get(wp_idea_stream_get_tag());
    if (!empty($tag)) {
        // Make sure the post type is set to ideas
        $posts_query->set('post_type', $idea_post_type);
        // Define the current tag
        wp_idea_stream_set_idea_var('is_tag', $tag);
    }
    /** Searching ideas ***********************************************************/
    $search = $posts_query->get(wp_idea_stream_search_rewrite_id());
    if (!empty($search)) {
        // Make sure the post type is set to ideas
        $posts_query->set('post_type', $idea_post_type);
        // Define the query as a search one
        $posts_query->set('is_search', true);
        /**
         * Temporarly set the 's' parameter of WP Query
         * This will be reset while building ideas main_query args
         * @see wp_idea_stream_set_template()
         */
        $posts_query->set('s', $search);
        // Set the search conditionnal var
        wp_idea_stream_set_idea_var('is_search', true);
    }
    /** Changing order ************************************************************/
    // Here we're using built-in var
    $orderby = $posts_query->get('orderby');
    // Make sure we are ordering ideas
    if (!empty($orderby) && $idea_post_type == $posts_query->get('post_type')) {
        if (!wp_idea_stream_is_rating_disabled() && 'rates_count' == $orderby) {
            /**
             * It's an order by rates request, set the meta query to achieve this.
             * Here we're not ordering yet, we simply make sure to get ideas that
             * have been rated.
             * Order will happen thanks to wp_idea_stream_set_rates_count_orderby()
             * filter.
             */
            $posts_query->set('meta_query', array(array('key' => '_ideastream_average_rate', 'compare' => 'EXISTS')));
        }
        // Set the order by var
        wp_idea_stream_set_idea_var('orderby', $orderby);
    }
    // Set the idea archive var if viewing ideas archive
    if ($posts_query->is_post_type_archive()) {
        wp_idea_stream_set_idea_var('is_idea_archive', true);
    }
    /**
     * Finally if post_type is ideas, then we're in IdeaStream's
     * territory so set this
     */
    if ($idea_post_type === $posts_query->get('post_type')) {
        wp_idea_stream_set_idea_var('is_ideastream', true);
        // Reset the pagination
        if (-1 !== $posts_query->get('p')) {
            $posts_query->set('posts_per_page', wp_idea_stream_ideas_per_page());
        }
    }
}
Пример #4
0
/**
 * Gets the url to the form to submit new ideas
 *
 * So far only adding new ideas is supported, but
 * there will surely be an edit action to allow users
 * to edit their ideas. Reason of the $type param
 *
 * @package WP Idea Stream
 * @subpackage core/functions
 *
 * @since 2.0.0
 *
 * @global $wp_rewrite
 * @param  string $type action (defaults to new)
 * @param  string $idea_name the post name of the idea to edit
 * @uses   wp_idea_stream_addnew_slug() can be customized through plugin's settings
 * @uses   apply_filters() call 'wp_idea_stream_pre_get_form_url' to customize the form url before it has been built
 * @uses   wp_idea_stream_action_slug()
 * @uses   wp_idea_stream_action_rewrite_id()
 * @uses   home_url()
 * @uses   user_trailingslashit()
 * @uses   wp_idea_stream_edit_slug() to get the edit slug
 * @uses   apply_filters() call 'wp_idea_stream_get_form_url' to customize the form url after it has been built
 * @return string the url of the form to add ideas
 */
function wp_idea_stream_get_form_url($type = '', $idea_name = '')
{
    global $wp_rewrite;
    if (empty($type)) {
        $type = wp_idea_stream_addnew_slug();
    }
    /**
     * Early filter to override form url before being built
     *
     * @param mixed false or url to override
     * @param string $type (only add new for now)
     */
    $early_form_url = apply_filters('wp_idea_stream_pre_get_form_url', false, $type, $idea_name);
    if (!empty($early_form_url)) {
        return $early_form_url;
    }
    // Pretty permalinks
    if ($wp_rewrite->using_permalinks()) {
        $url = $wp_rewrite->root . wp_idea_stream_action_slug() . '/%' . wp_idea_stream_action_rewrite_id() . '%';
        $url = str_replace('%' . wp_idea_stream_action_rewrite_id() . '%', $type, $url);
        $url = home_url(user_trailingslashit($url));
        // Unpretty permalinks
    } else {
        $url = add_query_arg(array(wp_idea_stream_action_rewrite_id() => $type), home_url('/'));
    }
    if ($type == wp_idea_stream_edit_slug() && !empty($idea_name)) {
        $url = add_query_arg(wp_idea_stream_get_post_type(), $idea_name, $url);
    }
    /**
     * Filter to override form url after being built
     *
     * @param string url to override
     * @param string $type add new or edit
     * @param string $idea_name the post name of the idea to edit
     */
    return apply_filters('wp_idea_stream_get_form_url', $url, $type, $idea_name);
}
Пример #5
0
 /**
  * Map IdeaStream needed vars to the group's context and prepare the
  * group's extension display method
  *
  * @package WP Idea Stream
  * @subpackage buddypress/groups
  *
  * @since  2.0.0
  *
  * @uses bp_is_group() to check a group is displayed
  * @uses bp_is_current_action() to check the group's current action
  * @uses wp_idea_stream_root_slug() to get the IdeaStream root slug
  * @uses WP_Idea_Stream_Group::group_get_option() to check for the group setting
  * @uses bp_get_current_group_id() to get current group's ID
  * @uses bp_core_redirect() to safely redirect the user
  * @uses bp_get_group_permalink() to get the group's permalink
  * @uses groups_get_current_group() to get the current group's object
  * @uses wp_idea_stream_buddypress_set_is_ideastream() to set a new IdeaStream territory for a later use
  * @uses bp_action_variables() to get all action variables at once
  * @uses wp_idea_stream_action_get_slug() to get IdeaStream's action slug
  * @uses wp_idea_stream_addnew_slug() to get IdeaStream's add slug
  * @uses wp_idea_stream_buddypress_set_is_new() to set IdeaStream global 'is_new' for a later use
  * @uses add_action() to add a field to the new idea form
  * @uses wp_idea_stream_edit_slug() to get the edit slug
  * @uses get_query_var() to get the value of a specific query var
  * @uses wp_idea_stream_get_post_type() to get the ideas post type identifier
  * @uses wp_idea_stream_ideas_get_idea_by_name() to get the idea object
  * @uses wp_idea_stream_ideas_lock_idea() to check if the idea is edited by another user
  * @uses wp_idea_stream_ideas_can_edit() to check if the user can edit the idea
  * @uses WP_Idea_Stream_Group->is_idea_attached_to_group() to check if the idea is attached to currrent group
  * @uses wp_idea_stream_set_idea_var() to set an IdeaStream global for a later use
  * @uses wp_idea_stream_buddypress_set_is_edit() to set IdeaStream global 'is_edit' for a later use
  * @uses wp_idea_stream_idea_get_slug() to get IdeaStream's idea slug
  * @uses wp_idea_stream_tag_get_slug() to get the ideas tag taxonomy slug
  * @uses wp_idea_stream_category_get_slug() to get the ideas category taxonomy slug
  * @uses set_query_var() to set some query var for a later use
  * @uses get_term_by() to get idea's term
  * @uses wp_idea_stream_paged_slug() to get the ideas paged slug
  * @uses wp_idea_stream_add_message() to add a feedback to display to the user once redirected
  * @uses WP_Idea_Stream_Group->group_ideas_archive_url() to get the group's IdeaStream archive page
  * @uses bp_is_current_component() to check for a BuddyPress component
  * @uses bp_current_item() to make sure a group item is requested
  * @uses bp_do_404() to set the WP Query to a 404.
  */
 public function maybe_set_ideastream()
 {
     if (bp_is_group() && bp_is_current_action(wp_idea_stream_root_slug())) {
         // Bail if group is not (more) using IdeaStream
         if (!self::group_get_option(bp_get_current_group_id(), '_group_ideastream_activate', false)) {
             bp_core_redirect(bp_get_group_permalink(groups_get_current_group()));
         }
         // Set is_ideastream to load main css file
         wp_idea_stream_buddypress_set_is_ideastream();
         $actions = array_map('sanitize_title', (array) bp_action_variables());
         $message = false;
         switch ($actions[0]) {
             // Adding a new idea
             case wp_idea_stream_action_get_slug():
                 if (wp_idea_stream_addnew_slug() == $actions[1]) {
                     $this->group_ideastream->is_action = 'new';
                     $this->group_ideastream->context = 'new-idea';
                     // Set is_new to load javascripts
                     wp_idea_stream_buddypress_set_is_new();
                     // Add the group_id field in the form
                     add_action('wp_idea_stream_ideas_the_idea_meta_edit', array($this, 'meta_group_id'));
                 } else {
                     if (wp_idea_stream_edit_slug() == $actions[1]) {
                         $idea_name = get_query_var(wp_idea_stream_get_post_type());
                         if (empty($idea_name)) {
                             $message = __('No idea was requested', 'wp-idea-stream');
                         }
                         // Get the idea thanks to its name
                         $idea = wp_idea_stream_ideas_get_idea_by_name($idea_name);
                         // Check if the idea is currently being edited by someone else
                         $user_is_editing = wp_idea_stream_ideas_lock_idea($idea->ID);
                         if (!empty($user_is_editing)) {
                             $message = sprintf(__('The idea: &#34;%s&#34; is already being edited by another user.', 'wp-idea-stream'), $idea->post_title);
                             break;
                         }
                         // Does the user can edit the idea ?
                         if (!wp_idea_stream_ideas_can_edit($idea)) {
                             $message = __('You are not allowed to edit this idea.', 'wp-idea-stream');
                             break;
                         }
                         if ($this->is_idea_attached_to_group($idea)) {
                             $this->group_ideastream->is_action = 'edit';
                             $this->group_ideastream->context = 'edit-idea';
                             // Set the query loop
                             $query_loop = new StdClass();
                             $query_loop->idea = $idea;
                             wp_idea_stream_set_idea_var('query_loop', $query_loop);
                             wp_idea_stream_set_idea_var('single_idea_id', $idea->ID);
                             // Set is_new to load javascripts
                             wp_idea_stream_buddypress_set_is_edit();
                             // Add the group_id field in the form
                             add_action('wp_idea_stream_ideas_the_idea_meta_edit', array($this, 'meta_group_id'));
                         } else {
                             $message = __('The idea was not found in this group.', 'wp-idea-stream');
                         }
                     } else {
                         $message = __('The action requested is not available', 'wp-idea-stream');
                     }
                 }
                 break;
                 // Viewing a single idea
             // Viewing a single idea
             case wp_idea_stream_idea_get_slug():
                 // No name, stop
                 if (empty($actions[1])) {
                     $message = __('No idea was requested', 'wp-idea-stream');
                     break;
                 }
                 // Get the idea thanks to its name
                 $idea = wp_idea_stream_ideas_get_idea_by_name($actions[1]);
                 if ($this->is_idea_attached_to_group($idea)) {
                     $this->group_ideastream->is_action = 'idea';
                     $this->group_ideastream->idea_name = $actions[1];
                     // Set the query loop
                     $query_loop = new StdClass();
                     $query_loop->idea = $idea;
                     wp_idea_stream_set_idea_var('query_loop', $query_loop);
                     wp_idea_stream_set_idea_var('single_idea_id', $idea->ID);
                 } else {
                     $message = __('The idea was not found in this group.', 'wp-idea-stream');
                 }
                 break;
             case wp_idea_stream_tag_get_slug():
             case wp_idea_stream_category_get_slug():
                 // No term name, stop
                 if (empty($actions[1])) {
                     $message = sprintf(__('No %s was requested', 'wp-idea-stream'), $actions[0]);
                     break;
                 }
                 // Does the group support categories ?
                 if ($actions[0] == wp_idea_stream_category_get_slug() && !self::group_get_option(bp_get_current_group_id(), '_group_ideastream_categories', true)) {
                     $message = sprintf(__('This group does not support the %s feature.', 'wp-idea-stream'), $actions[0]);
                     break;
                 }
                 // Using tag as default, as category can be disabled from group settings.
                 if ($actions[0] == wp_idea_stream_tag_get_slug()) {
                     $this->group_ideastream->current_taxonomy = wp_idea_stream_get_tag();
                     // Set tag as a query var.
                     set_query_var(wp_idea_stream_get_tag(), $actions[1]);
                 } else {
                     if ($actions[0] == wp_idea_stream_category_get_slug()) {
                         $this->group_ideastream->current_taxonomy = wp_idea_stream_get_category();
                         // Set category as a query var.
                         set_query_var(wp_idea_stream_get_category(), $actions[1]);
                     }
                 }
                 // Try to get the term with its slug
                 $this->group_ideastream->current_term = get_term_by('slug', $actions[1], $this->group_ideastream->current_taxonomy);
                 if (!empty($this->group_ideastream->current_term)) {
                     $this->group_ideastream->is_action = $actions[0];
                     $this->group_ideastream->context = 'taxonomy';
                     // Set the current term
                     wp_idea_stream_set_idea_var('current_term', $this->group_ideastream->current_term);
                 } else {
                     $message = sprintf(__('The %s was not found', 'wp-idea-stream'), $actions[0]);
                     break;
                 }
                 break;
             default:
                 $this->group_ideastream->is_action = 'archive';
                 $this->group_ideastream->context = 'archive';
                 break;
         }
         // Set pagination for taxonomy & archive page
         if (!empty($this->group_ideastream->context) && in_array($this->group_ideastream->context, array('taxonomy', 'archive'))) {
             $possible_page_number = array($actions[0]);
             if (!empty($actions[2])) {
                 $possible_page_number = array_merge($possible_page_number, array($actions[2]));
             }
             if (in_array(wp_idea_stream_paged_slug(), $possible_page_number)) {
                 if (is_numeric($actions[1])) {
                     $this->group_ideastream->is_paged = absint($actions[1]);
                 } else {
                     if (is_numeric($actions[3])) {
                         $this->group_ideastream->is_paged = absint($actions[3]);
                     } else {
                         $this->group_ideastream->is_paged = 0;
                     }
                 }
             }
         }
         if (!empty($message)) {
             wp_idea_stream_add_message(array('type' => 'error', 'content' => $message));
             bp_core_redirect($this->group_ideas_archive_url(groups_get_current_group(), true));
         }
         /**
          * Redirect to a 404 if needed
          *
          * It's the case when trying to see an idea attached to an hidden group while the user
          * is not a member of this group.
          */
     } else {
         if (bp_is_current_component('groups') && bp_is_current_action(wp_idea_stream_root_slug()) && bp_current_item()) {
             bp_do_404();
             return;
         }
     }
 }
Пример #6
0
/**
 * Edit idea slug of the plugin
 *
 * @package WP Idea Stream
 * @subpackage admin/settings
 *
 * @since 2.0.0
 *
 * @uses   esc_attr() to sanitize the attribute
 * @uses   wp_idea_stream_edit_slug() to get the active slug
 * @return string HTML output
 */
function wp_idea_stream_edit_slug_setting_callback()
{
    ?>

	<input name="_ideastream_edit_slug" id="_ideastream_edit_slug" type="text" class="regular-text code" value="<?php 
    echo esc_attr(wp_idea_stream_edit_slug());
    ?>
" />

	<?php 
}