/** * Display error messages after form submitted, if any. * * @since 0.0.1 */ function vp_error_messages() { // Only show when there are any errors if ($codes = vp_errors()->get_error_codes()) { echo '<div class="form-message error"><ul class="errors-list">'; // Loop error codes and display errors foreach ($codes as $code) { $message = vp_errors()->get_error_message($code); echo '<li class="error-item">' . $message . '</li>'; } echo '</ul></div>'; } }
/** * Do the edit topic form process. * * @since 0.0.1 */ function vp_do_edit_topic() { if (empty($_POST['action']) || 'edit_topic' != $_POST['action']) { return; } if (isset($_POST['topic_title']) && wp_verify_nonce($_POST['edit_topic_nonce'], 'edit-topic-nonce')) { $topic_id = get_query_var('p'); $title = $_POST['topic_title']; $content_filtered = strip_tags($_POST['topic_content_filtered']); // Title empty if (empty($title)) { vp_errors()->add('topic_title_empty', __('Please enter the topic title', 'v2press')); } // Content empty if (empty($content_filtered)) { vp_errors()->add('topic_content_empty', __('Please write something useful', 'v2press')); } $errors = vp_errors()->get_error_messages(); if (empty($errors)) { $data = array('ID' => $topic_id, 'post_title' => $title, 'post_content_filtered' => $content_filtered); require_once VP_LIBS_PATH . '/markdown-extra.php'; $data['post_content'] = Markdown($content_filtered); $topic = wp_update_post($data); if ($topic) { $topic_url = get_permalink($topic); wp_redirect($topic_url); exit; } } } }