Ejemplo n.º 1
0
 /**
  * Setup available nav items
  *
  * @package WP Idea Stream
  * @subpackage core/widgets
  *
  * @since 2.0.0
  *
  * @uses  wp_idea_stream_get_root_url() to get the root url
  * @uses  wp_idea_stream_archive_title() to get the name of the archive page
  * @uses  wp_idea_stream_get_form_url() to get the url of the add new form
  * @uses  is_user_logged_in() to check we have a logged in user
  * @uses  wp_idea_stream_users_get_logged_in_profile_url() to get current user's profile url
  * @uses  apply_filters() call 'wp_idea_stream_widget_nav_items' to allow overrides
  */
 public function set_available_nav_items()
 {
     // construct nav
     $this->nav_items_available = array('idea_archive' => array('url' => wp_idea_stream_get_root_url(), 'name' => wp_idea_stream_archive_title()), 'addnew' => array('url' => wp_idea_stream_get_form_url(), 'name' => __('New idea', 'wp-idea-stream')));
     if (is_user_logged_in()) {
         $this->nav_items_available['current_user_profile'] = array('url' => wp_idea_stream_users_get_logged_in_profile_url(), 'name' => __('My profile', 'wp-idea-stream'));
     }
     /**
      * @param array the available nav items
      * @param string the widget's id base
      */
     $this->nav_items_available = apply_filters('wp_idea_stream_widget_nav_items', $this->nav_items_available, $this->id_base);
 }
Ejemplo n.º 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;
}
Ejemplo n.º 3
0
/**
 * Displays a message to not logged in users
 *
 * @package WP Idea Stream
 * @subpackage ideas/tags
 *
 * @since 2.0.0
 *
 * @uses   is_user_logged_in() to check if the user is logged in
 * @uses   esc_url() to sanitize url
 * @uses   wp_login_url() to build login url
 * @uses   wp_idea_stream_get_form_url() to get the new idea form url
 * @uses   wp_idea_stream_login_message() to get the custom message to display
 * @uses   apply_filters() call 'wp_idea_stream_ideas_not_loggedin' to override the output
 * @return string the not logged in message output
 */
function wp_idea_stream_ideas_not_loggedin()
{
    $output = esc_html__('You are not allowed to submit ideas', 'wp-idea-stream');
    if (!is_user_logged_in()) {
        if (wp_idea_stream_is_signup_allowed_for_current_blog()) {
            $output = sprintf(__('Please <a href="%s" title="Log in">log in</a> or <a href="%s" title="Sign up">register</a> to this site to submit an idea.', 'wp-idea-stream'), esc_url(wp_login_url(wp_idea_stream_get_form_url())), esc_url(wp_idea_stream_users_get_signup_url()));
        } else {
            $output = sprintf(__('Please <a href="%s" title="Log in">log in</a> to this site to submit an idea.', 'wp-idea-stream'), esc_url(wp_login_url(wp_idea_stream_get_form_url())));
        }
        // Check for a custom message..
        $custom_message = wp_idea_stream_login_message();
        if (!empty($custom_message)) {
            $output = $custom_message;
        }
    }
    /**
     * @param  string $output the message to output
     */
    echo apply_filters('wp_idea_stream_ideas_not_loggedin', $output);
}
/**
 * Reset the page (post) title depending on the context
 *
 * @package WP Idea Stream
 * @subpackage core/template-functions
 *
 * @since 2.0.0
 *
 * @param string $context the context to build the title for
 * @uses  wp_idea_stream_archive_title() to get the IdeaStream archive page title
 * @uses  wp_idea_stream_user_can() to check for user's capability
 * @uses  wp_idea_stream_get_root_url() to get IdeaStream's root url
 * @uses  wp_idea_stream_get_form_url() to get IdeaStream's add new form url
 * @uses  wp_idea_stream_get_term_name() to get the term name
 * @uses  wp_idea_stream_users_get_displayed_user_displayname() to get the displayed user name
 * @uses  apply_filters() call 'wp_idea_stream_reset_post_title' to override the title of the page
 * @return string the post title
 */
function wp_idea_stream_reset_post_title($context = '')
{
    $post_title = wp_idea_stream_archive_title();
    switch ($context) {
        case 'archive':
            if (wp_idea_stream_user_can('publish_ideas')) {
                $post_title = '<a href="' . esc_url(wp_idea_stream_get_root_url()) . '">' . $post_title . '</a>';
                $post_title .= ' <a href="' . esc_url(wp_idea_stream_get_form_url()) . '" class="button wpis-title-button">' . esc_html__('Add new', 'wp-idea-stream') . '</a>';
            }
            break;
        case 'taxonomy':
            $post_title = '<a href="' . esc_url(wp_idea_stream_get_root_url()) . '">' . $post_title . '</a>';
            $post_title .= '<span class="idea-title-sep"></span>' . wp_idea_stream_get_term_name();
            break;
        case 'user-profile':
            $post_title = '<a href="' . esc_url(wp_idea_stream_get_root_url()) . '">' . $post_title . '</a>';
            $post_title .= '<span class="idea-title-sep"></span>' . sprintf(esc_html__('%s&#39;s profile', 'wp-idea-stream'), wp_idea_stream_users_get_displayed_user_displayname());
            break;
        case 'new-idea':
            $post_title = '<a href="' . esc_url(wp_idea_stream_get_root_url()) . '">' . $post_title . '</a>';
            $post_title .= '<span class="idea-title-sep"></span>' . __('New Idea', 'wp-idea-stream');
            break;
        case 'edit-idea':
            $post_title = '<a href="' . esc_url(wp_idea_stream_get_root_url()) . '">' . $post_title . '</a>';
            $post_title .= '<span class="idea-title-sep"></span>' . __('Edit Idea', 'wp-idea-stream');
            break;
        case 'signup':
            $post_title = '<a href="' . esc_url(wp_idea_stream_get_root_url()) . '">' . $post_title . '</a>';
            $post_title .= '<span class="idea-title-sep"></span>' . __('Create an account', 'wp-idea-stream');
            break;
    }
    /**
     * @param  string $post_title the title for the template
     * @param  string $context the context
     */
    return apply_filters('wp_idea_stream_reset_post_title', $post_title, $context);
}