Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using a plugin called Frontier Post to allow users to post on front end. When I try to create a post on the front end using this plugin, it does not display a custom meta box that comes with my theme that was created in the functions php.

How can I display and allow the user to use the custom meta box?

The code in my functions.php creating the metabox is

     /**
  * Post Meta Data Box and Custom fields
  *
  */

  add_action( 'load-post.php', 'imwb_videopress_meta_boxes_setup' );
  add_action( 'load-post-new.php', 'imwb_videopress_meta_boxes_setup' );

  function imwb_videopress_meta_boxes_setup() {

       /* Add meta boxes on the 'add_meta_boxes' hook. */
       add_action( 'add_meta_boxes', 'imwb_videopress_add_post_meta_boxes' );
       add_action( 'save_post', 'imwb_videopress_save_post_video_meta' );
  }

  function imwb_videopress_add_post_meta_boxes() {

    add_meta_box(
        'imwb_videopress-post-video',           // Unique ID
        esc_html__( 'Video', 'imwb_videopress' ),       // Title
        'imwb_videopress_post_video_meta_box',      // Callback function
        'post',             // Admin page (or post type)
        'normal',                   // Context
        'high'                  // Priority
    );

  }

  if ( in_array( basename( $_SERVER['PHP_SELF'] ), array( 'post-new.php', 'post.php') ) ) {
     add_action( 'admin_head', 'imwb_videopress_meta_boxes_head' );
  }

  function imwb_videopress_meta_boxes_head() {
  ?>
    <style>

       .imwbvp_video_thumbnail {
          border: 1px solid #DFDFDF;
          width: 200px;
          float: right;
          top:  3px;
          right: 5px;
       }
       .imwbvp_video_thumbnail span {
          text-align: center;
          background-color: #E9E9E9;
          display: block;
          padding: 3px;
       }
        .imwbvp_video_thumbnail .image {
          width: 200px;
          height: 150px;
          text-align: center;
          font-weight: bold;
       }

    </style>
    <script>
    ( function( $ ) {

       $(document).ready(function() {
          $hints = Array();
          $hints['D'] = 'Please enter the URL where the video can be viewed. <b>E.G.</b> http://www.dailymotion.com/video/xi9v9h_slow-mo-of-giant-bubbles-on-stinson-beach-ca_tech';
          $hints['F'] = 'Please enter the URL to the video file. <b>E.G.</b> http://yoursite.com/video.mp4';
          $hints['M'] = 'Please enter the URL where the video can be viewed. <b>E.G.</b> http://www.metacafe.com/watch/8748970/the_amazing_spider_man/';
          $hints['V'] = 'Please enter the URL where the video can be viewed. <b>E.G.</b> http://vimeo.com/40132261';
          $hints['Y'] = 'Please enter the URL where the video can be viewed. <b>E.G.</b> http://www.youtube.com/watch?v=SqtXkv0jigQ';

          $('input[name="imwb_videopress_post_video-type"]').change(function() {
              $('#imwb_videopress_post_video-label').html($hints[$(this).val()]);
          });

          $('#imwb_videopress_post_video-label').html($hints[$('input[name="imwb_videopress_post_video-type"]:checked').val()])

       });

    } ) ( jQuery );
    </script>
  <?php
  }

  function imwb_videopress_post_video_meta_box( $object, $box ) { ?>

    <?php wp_nonce_field( basename( __FILE__ ), 'imwb_videopress-post-video_nonce' );
      $videoType = get_post_meta( $object->ID, 'imwb_videopress_post_video_type', true );
      if(empty($videoType)) $videoType = 'F';
     ?>
     <?php if(imwb_videopress_get_option('autogenthumbs') == '1') { ?>
            <div class="imwbvp_video_thumbnail">
             <span>Video Thumbnail</span>
             <div class="image">
     <?php
                $img = imwb_videopress_get_the_post_thumbnail();
                if(empty($img))
                   echo '<br>Thumbnail generation will be attempted on next save/update';
                else 
                 echo $img;
     ?> 
             </div>
            </div>
     <?php } ?> 
    <p>
       <input type="radio" name="imwb_videopress_post_video-type" id="imwb_videopress_post_video-type" value="F" <?php checked( $videoType, 'F' ); ?>> Video File&nbsp;&nbsp;
       <input type="radio" name="imwb_videopress_post_video-type" id="imwb_videopress_post_video-type" value="Y" <?php checked( $videoType, 'Y' ); ?>> You Tube&nbsp;&nbsp;
       <input type="radio" name="imwb_videopress_post_video-type" id="imwb_videopress_post_video-type" value="V" <?php checked( $videoType, 'V' ); ?>> Vimeo&nbsp;&nbsp;
       <input type="radio" name="imwb_videopress_post_video-type" id="imwb_videopress_post_video-type" value="D" <?php checked( $videoType, 'D' ); ?>> DailyMotion&nbsp;&nbsp;
       <input type="radio" name="imwb_videopress_post_video-type" id="imwb_videopress_post_video-type" value="M" <?php checked( $videoType, 'M' ); ?>> Metacafe
       <br><br>
        <label id="imwb_videopress_post_video-label" for="imwb_videopress_post_video-url">Link URL:</label><br>
        <input type="text" name="imwb_videopress_post_video-url" id="imwb_videopress_post_video-url" value="<?php echo esc_attr( get_post_meta( $object->ID, 'imwb_videopress_post_video_url', true ) ); ?>" size="60" />
    </p>        
    <p>
    <label id="imwb_videopress_post_video-label" for="imwb_videopress_post_video-views">View Count:</label> <input type="text" name="imwb_videopress_post_video-views" id="imwb_videopress_post_video-views" value="<?php echo esc_attr( get_post_meta( $object->ID, '_imwb_videopress_post_video_views', true ) ); ?>" size="10" />
    <label id="imwb_videopress_post_video-label" for="imwb_videopress_post_video-rating">Rating (From 0 to 5):</label>  <input type="text" name="imwb_videopress_post_video-rating" id="imwb_videopress_post_video-rating" value="<?php echo esc_attr( imwb_videopress_get_rating($object->ID ) ); ?>" size="10" />
    </p>
            <div style="clear: both"></div>
  <?php }

  function imwb_videopress_save_post_video_meta($post_id) {

    // verify if this is an auto save routine. 
    // If it is our form has not been submitted, so we dont want to do anything
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
        return;

    /* Verify the nonce before proceeding. */
    if ( !isset( $_POST['imwb_videopress-post-video_nonce'] ) || !wp_verify_nonce( $_POST['imwb_videopress-post-video_nonce'], basename( __FILE__ ) ) )
        return $post_id;

   // Check permissions
   if ( 'page' == $_POST['post_type'] ) 
         return;
   else
   {
     if ( !current_user_can( 'edit_post', $post_id ) )
         return;
   }

   if(wp_is_post_revision($post_id))
      return;

    $vtChanged = true;

    /* Get the posted data and sanitize it for use as an HTML class. */
    $vt_meta_value = ( isset( $_POST['imwb_videopress_post_video-type'] ) ?  $_POST['imwb_videopress_post_video-type'] : '' );

    /* Get the meta key. */
    $meta_key = 'imwb_videopress_post_video_type';

    /* Get the meta value of the custom field key. */
    $meta_value = get_post_meta( $post_id, $meta_key, true );

    /* If a new meta value was added and there was no previous value, add it. */
    if ( $vt_meta_value && '' == $meta_value ) 
        add_post_meta( $post_id, $meta_key, $vt_meta_value, true );

    /* If the new meta value does not match the old value, update it. */
    elseif ( $vt_meta_value && $vt_meta_value != $meta_value ) 
        update_post_meta( $post_id, $meta_key, $vt_meta_value );

    /* If there is no new meta value but an old value exists, delete it. */
    elseif ( '' == $vt_meta_value && $meta_value ) 
        delete_post_meta( $post_id, $meta_key, $meta_value );  

    /* Nothing changed */
    else 
    $vtChanged = false;     

    $vuChanged = true;

    /* Get the posted data and sanitize it for use as an HTML class. */
    $vu_meta_value = ( isset( $_POST['imwb_videopress_post_video-url'] ) ? $_POST['imwb_videopress_post_video-url'] : '' );

    /* Get the meta key. */
    $meta_key = 'imwb_videopress_post_video_url';

    /* Get the meta value of the custom field key. */
    $meta_value = get_post_meta( $post_id, $meta_key, true );

    /* If a new meta value was added and there was no previous value, add it. */
    if ( $vu_meta_value && '' == $meta_value )
        add_post_meta( $post_id, $meta_key, $vu_meta_value, true );

    /* If the new meta value does not match the old value, update it. */
    elseif ( $vu_meta_value && $vu_meta_value != $meta_value ) 
        update_post_meta( $post_id, $meta_key, $vu_meta_value );

    /* If there is no new meta value but an old value exists, delete it. */
    elseif ( '' == $vu_meta_value && $meta_value ) 
        delete_post_meta( $post_id, $meta_key, $meta_value );

   /* Nothing changed */
   else 
    $vuChanged = false;

   /* Do we need to generate a thumbnail */
   if(($vtChanged || $vuChanged) && imwb_videopress_get_option('autogenthumbs') == '1') 
         imwb_videopress_generate_thumbnail($post_id, $vt_meta_value, $vu_meta_value );

   /* Set the video id */
   if($vtChanged) { // If the video type changed then remove any existing id's
      delete_post_meta( $post_id , 'imwb_ctc_dailymotion_id');
      delete_post_meta( $post_id , 'imwb_ctc_metacafe_id');
      delete_post_meta( $post_id , 'imwb_ctc_youtube_id');
      delete_post_meta( $post_id , 'imwb_ctc_vimeo_id');
   }

   $video_id = imwb_videopress_get_video_id($vt_meta_value, $vu_meta_value);
   switch ( $vt_meta_value ) {
      case 'D': update_post_meta( $post_id , 'imwb_ctc_dailymotion_id', trim($video_id) );
                break;
      case 'M': update_post_meta( $post_id , 'imwb_ctc_metacafe_id', trim($video_id) );
                  break;                              
    case 'Y': update_post_meta( $post_id , 'imwb_ctc_youtube_id', trim($video_id) );
               break;
      case 'V': update_post_meta( $post_id , 'imwb_ctc_vimeo_id', trim($video_id) );            
               break;
   } 

   /* Views */
   $vc_meta_value = ( isset( $_POST['imwb_videopress_post_video-views'] ) ? $_POST['imwb_videopress_post_video-views'] : '0' );
   if(empty($vc_meta_value) || !is_numeric($vc_meta_value))
      $vc_meta_value = '0';

   if ( !update_post_meta( $post_id, '_imwb_videopress_post_video_views', $vc_meta_value ) ) 
      add_post_meta( $post_id, '_imwb_videopress_post_video_views', $vc_meta_value, true );

   /* Rating */
   $vr_meta_value = ( isset( $_POST['imwb_videopress_post_video-rating'] ) ? $_POST['imwb_videopress_post_video-rating'] : '0' );
   if(empty($vr_meta_value) || !is_numeric($vr_meta_value))
      $vr_meta_value = '0';

   if($vr_meta_value < 0 || $vr_meta_value > 5)
      $vr_meta_value = '0';

   // * get current rating
   $rating_value = imwb_videopress_get_rating($post_id);   

   // If Changed then reset */
   if($vr_meta_value != $rating_value) {

         if ( !update_post_meta( $post_id, '_imwb_videopress_post_video_score', $vr_meta_value ) ) 
            add_post_meta( $post_id, '_imwb_videopress_post_video_score', $vr_meta_value, true );   

         if ( !update_post_meta( $post_id, '_imwb_videopress_post_video_count', '1' ) ) 
               add_post_meta( $post_id, '_imwb_videopress_post_video_count', '1', true );  

         if ( !update_post_meta( $post_id, '_imwb_videopress_post_video_rating', $vr_meta_value ) ) 
               add_post_meta( $post_id, '_imwb_videopress_post_video_rating', $vr_meta_value, true );  
   }

  }

  // checks is WP is at least a certain version (makes sure it has sufficient comparison decimals
  function imwb_videopress_is_wp_version( $is_ver ) {
      $wp_ver = explode( '.', get_bloginfo( 'version' ) );
      $is_ver = explode( '.', $is_ver );
      for( $i=0; $i<=count( $is_ver ); $i++ )
          if( !isset( $wp_ver[$i] ) ) array_push( $wp_ver, 0 );

      foreach( $is_ver as $i => $is_val )
          if( $wp_ver[$i] < $is_val ) return false;
      return true;
  }
share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.