/** * Handles posting ideas * * @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 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 get_post() to get the idea object * @uses wp_idea_stream_moderation_message() to check for a custom moderation message * @uses wp_idea_stream_ideas_get_idea_permalink() to get the idea link */ function wp_idea_stream_ideas_post_idea() { // 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 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(); // Check capacity if (!wp_idea_stream_user_can('publish_ideas')) { // Add feedback to the user wp_idea_stream_add_message(array('type' => 'error', 'content' => __('You are not allowed to publish ideas', 'wp-idea-stream'))); // Redirect to main archive page wp_safe_redirect($redirect); exit; } $posted = array_diff_key($_POST['wp_idea_stream'], array('save' => 'submit')); // Title & content are required if (empty($posted['_the_title']) || empty($posted['_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; } $id = wp_idea_stream_ideas_save_idea($posted); if (empty($id)) { // Add feedback to the user wp_idea_stream_add_message(array('type' => 'error', 'content' => __('Something went wrong while trying to save your idea.', 'wp-idea-stream'))); // Redirect to an empty form wp_safe_redirect(wp_idea_stream_get_form_url()); exit; } else { $idea = get_post($id); $feedback_message = array(); if (!empty($posted['_the_thumbnail'])) { $thumbnail = reset($posted['_the_thumbnail']); $sideload = WP_Idea_Stream_Ideas_Thumbnail::start($thumbnail, $id); if (is_wp_error($sideload->result)) { $feedback_message[] = __('There was a problem saving the featured image, sorry.', 'wp-idea-stream'); } } if ('pending' == $idea->post_status) { // Build pending message. $feedback_message['pending'] = __('Your idea is currently awaiting moderation.', 'wp-idea-stream'); // Check for a custom pending message $custom_pending_message = wp_idea_stream_moderation_message(); if (!empty($custom_pending_message)) { $feedback_message['pending'] = $custom_pending_message; } // redirect to the idea } else { $redirect = wp_idea_stream_ideas_get_idea_permalink($idea); } if (!empty($feedback_message)) { // Add feedback to the user wp_idea_stream_add_message(array('type' => 'info', 'content' => join(' ', $feedback_message))); } wp_safe_redirect($redirect); exit; } }
/** * Custom moderation message callback * * @package WP Idea Stream * @subpackage admin/settings * * @since 2.0.0 * * @uses wp_idea_stream_setting_disabled() to disable the field if an option has a specific value * @uses esc_textarea() to sanitize a textarea element * @uses wp_idea_stream_moderation_message() to get the active message * @return string HTML output */ function wp_idea_stream_moderation_message_setting_callback() { ?> <label for="_ideastream_moderation_message"><?php esc_html_e('In case Pending is the status for all ideas, you can customize the moderation message', 'wp-idea-stream'); ?> </label> <textarea name="_ideastream_moderation_message" id="_ideastream_moderation_message" rows="10" cols="50" class="large-text code" <?php wp_idea_stream_setting_disabled('wp_idea_stream_default_idea_status', 'publish'); ?> ><?php echo esc_textarea(wp_idea_stream_moderation_message()); ?> </textarea> <?php }