Example #1
0
function frontend_form_shortcode($atts = array())
{
    // current user
    $user_id = get_current_user_id();
    // user ID of metabox in front_end_metabox
    $metabox_id = '_frontend_form';
    // since post ID will not exist yet, just need to pass it
    $object_id = 'fake_object_id';
    // get cmb2 metabox object
    $cmb = cmb2_get_metabox($metabox_id, $object_id);
    // get $cmb object_type
    $post_types = $cmb->prop('object_types');
    $atts = shortcode_atts(array('post_author' => $user_id ? $user_id : 1, 'post_status' => 'pending', 'post_type' => reset($post_types)), $atts, 'cmb-frontend-form');
    foreach ($atts as $key => $value) {
        $cmb->add_hidden_field(array('field_args' => array('id' => "atts[{$key}]", 'type' => 'hidden', 'default' => $value)));
    }
    // Initiate our output variable
    $output = '';
    // Get any submission errors
    if (($error = $cmb->prop('submission_error')) && is_wp_error($error)) {
        // If there was an error with the submission, add it to our ouput.
        $output .= '<h3>' . sprintf(__('There was an error in the submission: %s', 'sexy'), '<strong>' . $error->get_error_message() . '</strong>') . '</h3>';
    }
    // If the post was submitted successfully, notify the user.
    if (isset($_GET['post_submitted']) && ($post = get_post(absint($_GET['post_submitted'])))) {
        // Get submitter's name
        $name = get_post_meta($post->ID, '_frontend_name', 1);
        $name = $name ? ' ' . $name : '';
        // Add notice of submission to our output
        $output .= '<h3>' . sprintf(__('Thank you%s, your new post has been submitted and is pending review by a site administrator.', 'sexy'), esc_html($name)) . '</h3>';
    }
    // Get our form
    $output .= cmb2_get_metabox_form($cmb, 'fake_object_id', array('save_button' => __('Submit Post', 'sexy')));
    return $output;
}
function tbws_do_new_offer_submission_shortcode()
{
    // Initiate our output variable
    $output = '';
    // Display a success message after form submission
    // Also hides our form by returning early
    if (isset($_GET['success']) && $_GET['success'] == 'true') {
        $output .= '<div id="message" class="success">' . __('Thank you! Your testimonial has been submitted.', 'tbws') . '</div>';
        return apply_filters('tbws_success_message', $output);
    }
    // Get CMB2 metabox object
    $cmb = tbws_testimonial_cmb2_get();
    // Parse attributes
    $atts = shortcode_atts(array('post_status' => 'draft'), $atts, 'tbws_testimonial');
    /*
     * Let's add these attributes as hidden fields to our cmb form
     * so that they will be passed through to our form submission
     */
    foreach ($atts as $key => $value) {
        $cmb->add_hidden_field(array('field_args' => array('id' => 'submitted_' . $key, 'type' => 'hidden', 'default' => $value)));
    }
    // Set our default button text
    $button_text = __('Submit', 'tbws');
    // Form button text
    $form_args = array('save_button' => apply_filters('tbws_submit_button_text', $button_text));
    // Get our form
    $output .= cmb2_get_metabox_form($cmb, 'tbws_testimonial_id', $form_args);
    $output = apply_filters('tbws_submission_form', $output);
    return $output;
}
/**
 * Handle the user-submit-frontend-form shortcode
 *
 * @param  array  $atts Array of shortcode attributes
 * @return string       Form html
 */
function ot_do_frontend_form_submission_shortcode($atts = array())
{
    // Get CMB2 metabox object
    $cmb = ot_frontend_cmb2_get();
    // Get $cmb object_types
    $post_types = $cmb->prop('object_types');
    /**
     * Get the user id from the display name.
     * This is an attempt to sync between dev and production environments. 
     * ID's are pretty flaky when switching from one to the other.
     */
    // Current user
    /* Use customiser */
    $user_id = get_theme_mod('ot_bv_user_selected_links_author');
    /* or get the id from the slug */
    //$user = get_user_by('slug', 'anon');
    //$user_id = $user->ID;
    // Parse attributes
    $atts = shortcode_atts(array('post_author' => $user_id ? $user_id : 1, 'post_status' => 'pending', 'post_type' => reset($post_types)), $atts, 'user-submit-frontend-form');
    /*
     * Let's add these attributes as hidden fields to our cmb form
     * so that they will be passed through to our form submission
     */
    foreach ($atts as $key => $value) {
        $cmb->add_hidden_field(array('field_args' => array('id' => "atts[{$key}]", 'type' => 'hidden', 'default' => $value)));
    }
    // Initiate our output variable
    $output = '';
    // Get any submission errors
    if (($error = $cmb->prop('submission_error')) && is_wp_error($error)) {
        // If there was an error with the submission, add it to our ouput.
        $output .= '<h3 class="label label-error">' . sprintf(__('There was an error in the submission: %s', 'ot-post-submit'), '<strong>' . $error->get_error_message() . '</strong>') . '</h3>';
    }
    // If the post was submitted successfully, notify the user.
    if (isset($_GET['post_submitted']) && ($post = get_post(absint($_GET['post_submitted'])))) {
        // Get submitter's name
        $name = get_post_meta($post->ID, '_ot_bv_link_submit_name', 1);
        $name = $name ? ' ' . $name : '';
        // Add notice of submission to our output
        $output .= '<h3 class="label label-success">' . sprintf(__('Thank you%s, your link has been submitted and is pending review.', 'ot-post-submit'), esc_html($name)) . '</h3>';
    }
    // Get our form
    $output .= cmb2_get_metabox_form($cmb, 'fake-object-id', array('save_button' => __('Submit', 'ot-post-submit')));
    return $output;
}
/**
 * Shortcode to display a CMB2 form for a post ID.
 * Adding this shortcode to your WordPress editor would look something like this:
 *
 * [cmb-form id="test_metabox" post_id=2]
 *
 * The shortcode requires a metabox ID, and (optionally) can take
 * a WordPress post ID (or user/comment ID) to be editing.
 *
 * @param  array  $atts Shortcode attributes
 * @return string       Form HTML markup
 */
function jt_cmb2_do_frontend_form_shortcode($atts = array())
{
    global $post;
    /**
     * Make sure a WordPress post ID is set.
     * We'll default to the current post/page
     */
    if (!isset($atts['post_id'])) {
        $atts['post_id'] = $post->ID;
    }
    // If no metabox id is set, yell about it
    if (empty($atts['id'])) {
        return 'Please add an "id" attribute to specify the CMB2 form to display.';
    }
    $metabox_id = esc_attr($atts['id']);
    $object_id = absint($atts['post_id']);
    // Get our form
    $form = cmb2_get_metabox_form($metabox_id, $object_id);
    return $form;
}
Example #5
0
function parinite_shortcode($atts = array())
{
    $cmb = get_parinite();
    $post_types = $cmb->prop('object_types');
    $user_id = get_current_user_id();
    $atts = shortcode_atts(array('post_author' => $user_id ? $user_id : 1, 'post_status' => 'pending', 'post_type' => reset($post_types)), $atts, 'cmb-frontend-form');
    foreach ($atts as $key => $value) {
        $cmb->add_hidden_field(array('id' => "atts[{$key}]", 'type' => 'hidden', 'default' => $value));
    }
    $output = '';
    // if error
    if (($error = $cmb->prop('submission_error')) && is_wp_error($error)) {
        $output .= '<h3>' . sprintf(__('There was an error in the submission: %s', 'sexy'), '<strong>' . $error->get_error_message() . '</strong>') . '</h3>';
    }
    // if succes
    if (isset($_GET['post_submitted']) && ($post = get_post(absint($_GET['post_submitted'])))) {
        $name = get_post_meta($post->ID, '_frontend_name', 1);
        $name = $name ? ' ' . $name : '';
        $output .= '<h3>' . sprintf(__('Thank you%s, your new post has been submitted and is pending review by a site administrator .', 'sexy'), esc_html($name)) . '</h3>';
    }
    $output .= cmb2_get_metabox_form($cmb, 'fake-object-id', array('save_button' => __('Submit Post', 'sexy')));
    return $output;
}
/**
 * Handle the cmb-frontend-form shortcode
 *
 * @param  array  $atts Array of shortcode attributes
 * @return string       Form html
 */
function wds_do_frontend_form_submission_shortcode($atts = array())
{
    // Get CMB2 metabox object
    $cmb = wds_frontend_cmb2_get();
    // Get $cmb object_types
    $post_types = $cmb->prop('object_types');
    // Current user
    $user_id = get_current_user_id();
    // Parse attributes
    $atts = shortcode_atts(array('post_author' => $user_id ? $user_id : 1, 'post_status' => 'pending', 'post_type' => reset($post_types)), $atts, 'cmb-frontend-form');
    /*
     * Let's add these attributes as hidden fields to our cmb form
     * so that they will be passed through to our form submission
     */
    foreach ($atts as $key => $value) {
        $cmb->add_hidden_field(array('field_args' => array('id' => "atts[{$key}]", 'type' => 'hidden', 'default' => $value)));
    }
    // Initiate our output variable
    $output = '';
    // Get any submission errors
    if (($error = $cmb->prop('submission_error')) && is_wp_error($error)) {
        // If there was an error with the submission, add it to our ouput.
        $output .= '<h3>' . sprintf(__('There was an error in the submission: %s', 'wds-post-submit'), '<strong>' . $error->get_error_message() . '</strong>') . '</h3>';
    }
    // If the post was submitted successfully, notify the user.
    if (isset($_GET['post_submitted']) && ($post = get_post(absint($_GET['post_submitted'])))) {
        // Get submitter's name
        $name = get_post_meta($post->ID, 'submitted_author_name', 1);
        $name = $name ? ' ' . $name : '';
        // Add notice of submission to our output
        $output .= '<h3>' . sprintf(__('Thank you%s, your new post has been submitted and is pending review by a site administrator.', 'wds-post-submit'), esc_html($name)) . '</h3>';
    }
    // Get our form
    $output .= cmb2_get_metabox_form($cmb, 'fake-oject-id', array('save_button' => __('Submit Post', 'wds-post-submit')));
    return $output;
}
Example #7
0
/**
 * Display a metabox form (or optionally return it) & save it on submission
 * @since  1.0.0
 * @param  mixed   $meta_box  Metabox config array or Metabox ID
 * @param  int     $object_id Object ID
 * @param  array   $args      Optional arguments array
 */
function cmb2_metabox_form($meta_box, $object_id = 0, $args = array())
{
    if (!isset($args['echo']) || $args['echo']) {
        cmb2_print_metabox_form($meta_box, $object_id, $args);
    } else {
        return cmb2_get_metabox_form($meta_box, $object_id, $args);
    }
}
Example #8
0
    public function test_cmb2_print_metabox_form()
    {
        $expected_form = '
		<form class="cmb-form" method="post" id="' . $this->cmb_id . '" enctype="multipart/form-data" encoding="multipart/form-data">
			<input type="hidden" name="object_id" value="' . $this->post_id . '">
			' . wp_nonce_field($this->cmb->nonce(), $this->cmb->nonce(), false, false) . '
			<!-- Begin CMB2 Fields -->
			<div class="cmb2-wrap form-table">
				<div id="cmb2-metabox-' . $this->cmb_id . '" class="cmb2-metabox cmb-field-list">
					function test_before_row Description test_test
					<div class="cmb-row cmb-type-text cmb2-id-test-test table-layout">
						<div class="cmb-th">
							<label for="test_test">Name</label>
						</div>
						<div class="cmb-td">
							testing before
							<input type="text" class="regular-text" name="test_test" id="test_test" value=""/>
							<p class="cmb2-metabox-description">Description</p>
							function test_after Description test_test
						</div>
					</div>
					testing after row
				</div>
			</div>
			<!-- End CMB2 Fields -->
			<input type="submit" name="submit-cmb" value="Save" class="button-primary">
		</form>
		';
        $form_get = cmb2_get_metabox_form($this->cmb_id, $this->post_id);
        $this->assertHTMLstringsAreEqual($expected_form, $form_get);
    }
 /**
  * Submission index
  *
  * @access public
  * @return string|void
  */
 public static function submission($atts)
 {
     if (!is_user_logged_in()) {
         echo Realia_Template_Loader::load('misc/not-allowed');
         return;
     }
     $metaboxes = apply_filters('cmb2_meta_boxes', array());
     if (!isset($metaboxes[REALIA_PROPERTY_PREFIX . 'front'])) {
         return __('A metabox with the specified \'metabox_id\' doesn\'t exist.', 'realia');
     }
     // CMB2 is getting fields values from current post what means it will fetch data from submission page
     // We need to remove all data before.
     $post_id = !empty($_GET['id']) ? $_GET['id'] : false;
     if ($post_id == false && empty($_GET['id'])) {
         unset($_POST);
         foreach ($metaboxes[REALIA_PROPERTY_PREFIX . 'front']['fields'] as $field_name => $field_value) {
             delete_post_meta(get_the_ID(), $field_value['id']);
         }
     }
     if (!empty($post_id) && !empty($_POST['object_id'])) {
         $post_id = $_POST['object_id'];
     }
     echo cmb2_get_metabox_form($metaboxes[REALIA_PROPERTY_PREFIX . 'front'], $post_id, array('form_format' => '<form action="//' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '" class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%2$s">%3$s<input type="submit" name="submit-cmb" value="%4$s" class="button-primary"></form>', 'save_button' => __('Save property', 'realia')));
 }
Example #10
0
    public function test_cmb2_print_metabox_form()
    {
        $form = '
		<form class="cmb-form" method="post" id="' . $this->cmb_id . '" enctype="multipart/form-data" encoding="multipart/form-data">
			<input type="hidden" name="object_id" value="' . $this->post_id . '">
			' . wp_nonce_field($this->cmb->nonce(), $this->cmb->nonce(), false, false) . '
			<!-- Begin CMB Fields -->
			<div class="cmb2_wrap form-table">
				<ul id="cmb2_metabox_' . $this->cmb_id . '" class="cmb2_metabox">
					<li class="cmb-row cmb-type-text cmb2_id_test_test">
						<div class="cmb-th">
							<label for="test_test">Name</label>
						</div>
						<div class="cmb-td">
							<input type="text" class="regular-text" name="test_test" id="test_test" value=""/>
							<p class="cmb2_metabox_description"></p>
						</div>
					</li>
				</ul>
			</div>
			<!-- End CMB Fields -->
			<input type="submit" name="submit-cmb" value="Save" class="button-primary">
		</form>
		';
        $form_get = cmb2_get_metabox_form($this->cmb_id, $this->post_id);
        $this->assertEquals($this->clean_string($form_get), $this->clean_string($form));
    }
 /**
  * Process property form - front end submission
  *
  * @access public
  * @return void
  */
 public static function process_property_form()
 {
     if (!isset($_POST['submit-cmb'])) {
         return;
     }
     // Setup and sanitize data
     if (isset($_POST[REALIA_PROPERTY_PREFIX . 'title'])) {
         $post_id = !empty($_GET['id']) ? $_GET['id'] : false;
         $review_before = get_theme_mod('realia_submission_review_before', false);
         $post_status = 'publish';
         if ($review_before && get_post_status($post_id) != 'publish') {
             $post_status = 'pending';
         }
         // If we are updating the post get old one. We need old post to set proper
         // post_date value because just modified post will at the top in archive pages.
         if (!empty($post_id)) {
             $old_post = get_post($post_id);
             $post_date = $old_post->post_date;
         } else {
             $post_date = '';
         }
         $data = array('post_title' => sanitize_text_field($_POST[REALIA_PROPERTY_PREFIX . 'title']), 'post_author' => get_current_user_id(), 'post_status' => $post_status, 'post_type' => 'property', 'post_date' => $post_date, 'post_content' => wp_kses($_POST[REALIA_PROPERTY_PREFIX . 'text'], '<b><strong><i><em><h1><h2><h3><h4><h5><h6><pre><code><span>'));
         if (!empty($post_id)) {
             $data['ID'] = $post_id;
         }
         $post_id = wp_insert_post($data, true);
         if (!empty($post_id) && !empty($_POST['object_id'])) {
             $_POST['object_id'] = $post_id;
             $post_id = $_POST['object_id'];
             $metaboxes = apply_filters('cmb2_meta_boxes', array());
             cmb2_get_metabox_form($metaboxes[REALIA_PROPERTY_PREFIX . 'front'], $post_id);
             // Create featured image
             $featured_image = get_post_meta($post_id, REALIA_PROPERTY_PREFIX . 'featured_image', true);
             if (!empty($_POST[REALIA_PROPERTY_PREFIX . 'featured_image'])) {
                 $featured_image_id = get_post_meta($post_id, REALIA_PROPERTY_PREFIX . 'featured_image_id', true);
                 set_post_thumbnail($post_id, $featured_image_id);
             } else {
                 update_post_meta($post_id, REALIA_PROPERTY_PREFIX . 'featured_image', null);
                 delete_post_thumbnail($post_id);
             }
             $_SESSION['messages'][] = array('success', __('Property has been successfully updated.', 'realia'));
             wp_redirect(get_permalink(get_theme_mod('realia_submission_list_page', '/')));
             exit;
         }
     }
     return;
 }