1

hi, i am working on a video sharing site project!

I have Created a Template file where people can submit their post as video! Everything was working very good, but the custom Taxonomy ponstars isn't getting data. The tag is working, but when people submit ponstars feild the posts pornstars feild got empty but everything is correct! My template file is -

    <?php /* Template Name: Submit a Video */

$siteKey = get_theme_mod( "wp_script_theme_pro_recaptcha_site_key", "" );
$secret = get_theme_mod( "wp_script_theme_pro_recaptcha_secret_key", "" );

if(isset($_POST['submitted']) && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')):

    if ( get_theme_mod( 'wp_script_theme_pro_enable_recaptcha', 'no' ) == 'yes' && $siteKey != '' && $secret != '' ):

        if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):

            $captcha = urlencode($_POST['g-recaptcha-response']);
            //$ip = $_SERVER['REMOTE_ADDR'];

            //get verify response data
            $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $captcha);
            $responseData = json_decode($verifyResponse);

            if($responseData->success):

                $pornstars = trim( $_POST['post_pornstars'] );

                $tags = $_POST['post_tags'];

                $uploaddir = wp_upload_dir();
$file = $_FILES['featured' ];
$uploadfile = $uploaddir['path'] . '/' . basename( $file['name'] );
move_uploaded_file( $file['tmp_name'] , $uploadfile );
$filename = basename( $uploadfile );
$wp_filetype = wp_check_filetype(basename($filename), null );
$attachment = array(
    'post_mime_type' => $wp_filetype['type'],
    'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
    'post_content' => '',
    'post_status' => 'inherit',
    'menu_order' => $_i + 1000
    );
$attach_id = wp_insert_attachment( $attachment, $uploadfile );

                $post_information = array(
                    'post_title' => esc_attr(strip_tags($_POST['video_title'])),
                    'post_content' => esc_attr(strip_tags($_POST['video_description'])),
                    'post-type' => 'post',
                    'post_status' => 'pending',
                    'tags_input'    => $tags,
                    'tax_input' => array( $pornstars ),
                    'post_category' => array($_POST['category_selected'])
                );

                $post_id = wp_insert_post($post_information);
wp_set_object_terms($post_id,$pornstars,'post_pornstars');


                if($post_id){
                    // Update Custom Meta

update_post_meta($post_id,'_thumbnail_id',$attach_id);
set_post_thumbnail( $post_id, $thumbnail_id );

                    update_post_meta($post_id, 'url_video', esc_attr(strip_tags($_POST['url_player'])));

                    update_post_meta($post_id, 'url_player', esc_attr($_POST['url_player']));

                    update_post_meta($post_id, 'wpscript_embed', esc_attr($_POST['video_embed']));

                    update_post_meta($post_id, 'wpscript_thumb', esc_attr(strip_tags($_POST['video_thumb'])));

                    if( ( isset($_POST['duration_hh']) ) && ( isset($_POST['duration_mm']) ) && ( isset($_POST['duration_ss']) ) ){
                        $duree_seconds = $_POST['duration_hh'] * 3600 + $_POST['duration_mm'] * 60 + $_POST['duration_ss'];
                        update_post_meta($post_id, 'wpscript_duration', $duree_seconds);
                    }

                    set_post_format($post_id, 'video' );
                }

                $succMsg = __( 'Thanks for submitting a video! Your submission is being moderated.', 'wp-script-theme-pro' );
            else:
                $errMsg = __( 'Captcha verification failed, please try again.', 'wp-script-theme-pro' );
            endif;
        else:
            $errMsg = __( 'Please click on the reCAPTCHA box.', 'wp-script-theme-pro' );
        endif;

            else:

        $pornstars = trim( $_POST['post_pornstars'] );

                $tags = $_POST['post_tags'];

                $uploaddir = wp_upload_dir();
$file = $_FILES['featured' ];
$uploadfile = $uploaddir['path'] . '/' . basename( $file['name'] );
move_uploaded_file( $file['tmp_name'] , $uploadfile );
$filename = basename( $uploadfile );
$wp_filetype = wp_check_filetype(basename($filename), null );
$attachment = array(
    'post_mime_type' => $wp_filetype['type'],
    'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
    'post_content' => '',
    'post_status' => 'inherit',
    'menu_order' => $_i + 1000
    );
$attach_id = wp_insert_attachment( $attachment, $uploadfile );

                $post_information = array(
                    'post_title' => esc_attr(strip_tags($_POST['video_title'])),
                    'post_content' => esc_attr(strip_tags($_POST['video_description'])),
                    'post-type' => 'post',
                    'post_status' => 'pending',
                    'tags_input'    => $tags,
                    'tax_input' => array( $pornstars ),
                    'post_category' => array($_POST['category_selected'])
                );

                $post_id = wp_insert_post($post_information);
wp_set_object_terms($post_id,$pornstars,'post_pornstars');

                if($post_id){
                    // Update Custom Meta

update_post_meta($post_id,'_thumbnail_id',$attach_id);
set_post_thumbnail( $post_id, $thumbnail_id );
                    update_post_meta($post_id, 'url_video', esc_attr(strip_tags($_POST['url_player'])));

                    update_post_meta($post_id, 'url_player', esc_attr($_POST['url_player']));

                    update_post_meta($post_id, 'wpscript_embed', esc_attr($_POST['video_embed']));

                    update_post_meta($post_id, 'wpscript_thumb', esc_attr(strip_tags($_POST['video_thumb'])));

                    if( ( isset($_POST['duration_hh']) ) && ( isset($_POST['duration_mm']) ) && ( isset($_POST['duration_ss']) ) ){
                        $duree_seconds = $_POST['duration_hh'] * 3600 + $_POST['duration_mm'] * 60 + $_POST['duration_ss'];
                        update_post_meta($post_id, 'wpscript_duration', $duree_seconds);
                    }

                    set_post_format($post_id, 'video' );

                    $succMsg = __( 'Thanks for submitting a video! Your submission is being moderated.', 'wp-script-theme-pro' );

                }

            endif;
        else:
            $errMsg = '';
            $succMsg = '';
        endif;

get_header(); ?>

    <!-- #primary BEGIN -->
    <div class="row margin-top-4">

        <?php if(get_theme_mod( 'wp_script_theme_pro_enable_user_video_submissions', 'yes') == 'yes') : ?>

        <div class="small-12 medium-9 columns">

            <?php if(!empty($errMsg)): ?><div class="callout error"><?php echo $errMsg; ?></div><?php endif; ?>
            <?php if(!empty($succMsg)): ?><div class="callout success"><?php echo $succMsg; ?></div><?php endif; ?>            

            <h1 class="widgettitle"><?php the_title(); ?></h1>

            <?php if (is_user_logged_in()) : ?>

                <form action="" id="SubmitVideo" method="post" enctype="multipart/form-data">

                    <div id="html_element"></div>

                   <fieldset class="fieldset">
                        <legend><strong><?php _e( 'Video URL or iframe', 'wp-script-theme-pro' ); ?></strong></legend>

                                <div class="callout secondary text-center"><strong><?php _e( 'Currently we have not any options to upload videos directly!', 'wp-script-theme-pro' ); ?></strong></div>                    
                        <div class="row">
                            <div class="medium-6 columns">                                
                                <label for="url_player"><?php _e('Video URL (flv or mp4)', 'wp-script-theme-pro') ?> <?php if(get_theme_mod('wp_script_theme_pro_enable_video_url_required_field', false) == true ) : ?><span class="required">*</span><?php endif; ?></label>
                                <input type="text" name="url_player" id="url_player" value="<?php if(isset($_POST['url_player'])) echo $_POST['url_player'];?>" <?php if(get_theme_mod('wp_script_theme_pro_enable_url_player_required_field', false) == true ) : ?>class="required"<?php endif; ?> />

                                <div class="callout secondary text-center"><strong><?php _e( 'OR', 'wp-script-theme-pro' ); ?></strong></div>
                            </div>
                            <div class="medium-6 columns">                            
                                <label for="video_embed"><?php _e('Iframe / Embed Code', 'wp-script-theme-pro') ?> <?php if(get_theme_mod('wp_script_theme_pro_enable_video_embed_required_field', false) == true ) : ?><span class="required">*</span><?php endif; ?></label>
                                <textarea name="video_embed" id="video_embed" rows="4" cols="30" <?php if(get_theme_mod('wp_script_theme_pro_enable_video_embed_required_field', false) == true ) : ?>class="required"<?php endif; ?>><?php if(isset($_POST['video_embed'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['video_embed']); } else { echo $_POST['video_embed']; } } ?></textarea>
                            </div>
                        </div>
                    </fieldset>

                    <fieldset class="fieldset">

                        <legend><strong><?php _e('Set Thumbnail', 'wp-script-theme-pro') ?></strong></legend>                    
                        <div class="row">                        
                            <div class="medium-6 columns">                                
                                                                <label for="featured"><?php _e('Upload thumbnail', 'wp-script-theme-pro') ?> <?php if(get_theme_mod('wp_script_theme_pro_enable_video_thumbnail_required_field', false) == true ) : ?><span class="required">*</span><?php endif; ?></label>
                                <input type="file" name="featured" id="featured" value="<?php if(isset($_POST['video_thumb'])) echo $_POST['video_thumb'];?>" <?php if(get_theme_mod('wp_script_theme_pro_enable_video_thumbnail_required_field', false) == true ) : ?>class="required"<?php endif; ?> />
                            </div>
                        </div>

                    </fieldset>

                    <fieldset class="fieldset">
                        <legend><strong><?php _e( 'Video details', 'wp-script-theme-pro' ); ?></strong></legend>
                        <div class="row">
                            <div class="medium-6 columns">
                                <label for="video_title"><?php _e('Title', 'wp-script-theme-pro') ?> <?php if(get_theme_mod('wp_script_theme_pro_enable_video_title_required_field', true) == true ) : ?><span class="required">*</span><?php endif; ?></label>
                                <input type="text" name="video_title" id="video_title" value="<?php if(isset($_POST['video_title'])) echo $_POST['video_title'];?>" <?php if(get_theme_mod('wp_script_theme_pro_enable_video_title_required_field', true) == true ) : ?>class="required"<?php endif; ?> />

                                <label for="post_tags"><?php _e('Tags', 'wp-script-theme-pro') ?> <?php if(get_theme_mod('wp_script_theme_pro_enable_video_thumbnail_required_field', false) == true ) : ?><span class="required">*</span><?php endif; ?>(<small>Separate tags with commas</small>)</label>
                                <input type="text" name="post_tags" id="post_tags" value="<?php if(isset($_POST['post_tags'])) echo $_POST['post_tags'];?>" <?php if(get_theme_mod('wp_script_theme_pro_enable_video_thumbnail_required_field', false) == true ) : ?>class="required"<?php endif; ?> />

                                <label for="post_pornstars"><?php _e('Pornstars', 'wp-script-theme-pro') ?> <?php if(get_theme_mod('wp_script_theme_pro_enable_video_thumbnail_required_field', false) == true ) : ?><span class="required">*</span><?php endif; ?>(<small>Separate pornstars with commas</small>)</label>
                                <input type="text" name="post_pornstars" id="post_pornstars" value="<?php if(isset($_POST['post_pornstars'])) echo $_POST['post_pornstars'];?>" <?php if(get_theme_mod('wp_script_theme_pro_enable_video_thumbnail_required_field', false) == true ) : ?>class="required"<?php endif; ?> />

                                <label for="category"><?php _e('Category', 'wp-script-theme-pro') ?></label>
                                <select name="category_selected" data-width="auto">
                                    <?php
                                        $categories = get_terms( 'category', array( 'hide_empty' => 0 ) );
                                        foreach ( (array)$categories as $category ): ?>

                                        <option value="<?php echo $category->term_id; ?>"><?php echo $category->name;?></option>

                                    <?php endforeach;?>
                                </select>


                            </div>
                            <div class="medium-6 columns">
                                <label for="video_description"><?php _e('Description', 'wp-script-theme-pro') ?> <?php if(get_theme_mod('wp_script_theme_pro_enable_video_description_required_field', false) == true ) : ?><span class="required">*</span><?php endif; ?></label>
                                <textarea name="video_description" id="video_description" rows="8" cols="30" <?php if(get_theme_mod('wp_script_theme_pro_enable_video_description_required_field', false) == true ) : ?>class="required"<?php endif; ?>><?php if(isset($_POST['video_description'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['video_description']); } else { echo $_POST['video_description']; } } ?></textarea>
                            </div>
                        </div>

                    </fieldset>

                    <fieldset class="fieldset text-center">

                        <legend><strong><?php _e('Submit a video', 'wp-script-theme-pro') ?></strong></legend>

                        <?php wp_nonce_field('post_nonce', 'post_nonce_field'); ?>

                        <?php if ( get_theme_mod( 'wp_script_theme_pro_enable_recaptcha', 'no' ) == 'yes' && $siteKey != '' && $secret != '' ) : ?>
                            <div class="g-recaptcha" data-sitekey="<?php echo $siteKey; ?>" <?php if (get_theme_mod( 'wp_script_theme_pro_color_scheme', 'dark') == 'dark' ) : ?>data-theme="dark"<?php endif; ?>></div>
                        <?php endif; ?>

                        <?php /*<script src="https://www.google.com/recaptcha/api.js" async defer></script>
*/ ?>
                        <input type="hidden" name="submitted" id="submitted" value="true" />
                        <button class="button large expanded margin-top-2" type="submit"><?php _e('Submit a video', 'wp-script-theme-pro') ?></button>

                    </fieldset>

                </form>

            <?php else : ?>

                <div class="callout info"><?php printf(__('You must be logged to submit a video. Please <a href="%s">login</a> or <a href="%s">register</a> a new account.', 'wp-script-theme-pro'), '#wpst-login', '#wpst-register'); ?></div>

            <?php endif; ?>

        </div>

        <?php else : ?>

            <div class="small-12 medium-8 columns">
                <div class="callout info text-center">
                    <?php _e('Video submission is disabled.', 'wp-script-theme-pro'); ?>
                </div>
            </div>

        <?php endif; ?>

        <?php if ( get_theme_mod( 'wp_script_theme_pro_enable_sidebar', 'yes') == 'yes' ) : ?>
            <?php get_sidebar(); ?>
        <?php endif; ?>
    </div><!-- #primary END -->
<?php get_footer(); ?>

And the Taxonomy register is -

    <?php //hook into the init action and call create_topics_nonhierarchical_taxonomy when it fires

add_action( 'init', 'wp_script_theme_pro_create_pornstars_taxonomy', 0 );

function wp_script_theme_pro_create_pornstars_taxonomy() {

// Labels part for the GUI

  $labels = array(
    'name' => _x( 'Pornstars', 'wp-script-theme-pro' ),
    'singular_name' => _x( 'Pornstar', 'wp-script-theme-pro' ),
    'search_items' =>  __( 'Search Pornstars' ),
    'popular_items' => __( 'Popular Pornstars' ),
    'all_items' => __( 'All Pornstars' ),
    'parent_item' => null,
    'parent_item_colon' => null,
    'edit_item' => __( 'Edit Pornstar' ), 
    'update_item' => __( 'Update Pornstar' ),
    'add_new_item' => __( 'Add New Pornstar' ),
    'new_item_name' => __( 'New Pornstar Name' ),
    'separate_items_with_commas' => __( 'Separate Pornstars with commas' ),
    'add_or_remove_items' => __( 'Add or remove Pornstars' ),
    'choose_from_most_used' => __( 'Choose from the most used Pornstars' ),
    'menu_name' => __( 'Pornstars' ),
  ); 

// Now register the non-hierarchical taxonomy like tag

  register_taxonomy('pornstars','post', array(
    'hierarchical' => false,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'update_count_callback' => '_update_post_term_count',
    'query_var' => true,
    'rewrite' => array( 'slug' => 'pornstar' )
  ));
}

The Pornstars Taxonomy is always be empty, did m i missing something? Can anyone help me with this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.