File "template_creator_new_post.php"

Full Path: /home/mba/public_html/wp-content-20250804013034-20250807183448/themes/twentytwenty-child-theme/template_creator_new_post.php
File size: 21.11 KB
MIME-type: text/x-php
Charset: utf-8

<?php
/* Template Name: New Post Creator */ 
get_header();
?>
<?php
if ( !is_user_logged_in() ) {
    $url= get_site_url().'/login/';
   echo "<script> window.location.href ='".$url."';</script>";
}
?>  
<?php
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
$LoginUser = get_current_user();
$current_users = wp_get_current_user();
$user_login = $current_users->user_login;
$user_email = $current_users->user_email;
$user_id =$current_users->ID;

$messageserr =""; 
if(isset($_POST['CreatorSavePost'])){
    $title = $_POST['title'];
    $tags = $_POST['tags_list'];
    $description = $_POST['description']; 
    $cateId = $_POST['cat']; 
    $imageAlternate = $_POST['creator_alternative_text'];
	$yoastSeoFocus = $_POST['creator_seo_focus'];
    $yoastSeoDescription = $_POST['creator_seo_description'];
    $status =  $_POST['CreatorStatusType']; 
if(empty($title) || empty($tags) || empty($description) || empty($_POST['creator_alternative_text']) || empty($_POST['creator_seo_focus']) || empty($_POST['creator_seo_description']) ){
		$messageserr = "All Fields Are mandatory";
	}
	else{
    $insertpdata = array(
							'post_title'    => $title,
							'post_content'  => $description,
							'post_status'   => $status,
							'post_type' => 'post',
							'post_author' => $user_id,  
							'comment_status' => 'open',   // if you prefer
							);
	$postdata = wp_insert_post( $insertpdata);	

    if($postdata){
		 update_post_meta($postdata, '_yoast_wpseo_focuskw', $yoastSeoFocus);
		 update_post_meta($postdata, '_yoast_wpseo_metadesc', $yoastSeoDescription);
		 
		 
		 
		 /*
		  update_post_meta($postdata, 'rank_math_focus_keyword', $yoastSeoFocus);
          update_post_meta($postdata, 'rank_math_description', $yoastSeoDescription);
		  */
        foreach($tags as $term){
           
            if(term_exists($term,"post_tag")){
                $getterm = get_term_by("name",$term,"post_tag");
                $termId = $getterm->term_id;
                
            }else{
                $insert_term = wp_insert_term( $term,"post_tag");
                $termId = $insert_term['term_id'];
                
            }
            wp_set_object_terms( $postdata, (int)$termId, 'post_tag',true );
        }
			
        	$attach_id = media_handle_upload('image', $postdata); 
        	set_post_thumbnail( $postdata,$attach_id);
        	update_post_meta($attach_id, '_wp_attachment_image_alt', $imageAlternate); 
            wp_set_object_terms( $postdata, (int)$cateId, 'category' );     
			 
			 
		$to = $user_email;
         $subject = "Article Successfully Submitted On Millionaire-Business-Articles.com";
          
         $message = '<div id="mailsub" class="notification" align="center">
				<table width="100%" border="0" cellspacing="0" cellpadding="0" style="min-width: 320px;"><tr><td align="center" bgcolor="#eff3f8">
				<table border="0" cellspacing="0" cellpadding="0" class="table_width_100" width="100%" style="max-width: 680px; min-width: 300px;">
					<tr><td>
					<div style="height: 80px; line-height: 80px; font-size: 10px;"> </div>
					</td></tr>
					<tr><td align="center" bgcolor="#ffffff">
					<div style="height: 30px; line-height: 30px; font-size: 10px;"> </div>
						<table width="90%" border="0" cellspacing="0" cellpadding="0">
							<tr><td align="left"><div class="mob_center_bl" style="float: left; display: inline-block; width: 115px;">
									<table class="mob_center" width="115" border="0" cellspacing="0" cellpadding="0" align="left" style="border-collapse: collapse;">
										<tr><td align="left" valign="middle">
										<div style="height: 10px; line-height: 20px; font-size: 10px;"> </div>
											<table border="0" cellspacing="0" cellpadding="0" >
												<tr><td align="center" valign="top" class="mob_center">
													<a href="'.home_url().'" target="_blank" >
													
													<img  src="https://millionaire-business-articles.com/wp-content/uploads/2020/10/logo_w.png"  alt="logo"/></a>
												</td></tr>
											</table>						
										</td></tr>
									</table></div>
							</tr>
						</table>
					<div style="height: 30px; line-height: 50px; font-size: 10px;"> </div>
					</td></tr>
					<tr><td align="center" bgcolor="#ffffff">
						<table width="90%" border="0" cellspacing="0" cellpadding="0">
							<tr><td align="center">
								<p style="font-size:16px;text-align:justify">Congratulations! your Article has been Submitted successfully.</p>  
			<p style="font-size:16px;text-align: justify;">Thanks for your contribution to our platform. One of our moderators will check it soon and if it passes our moderation it will be published. </p> 
						
							</td></tr>
						
							<br>			
						</table>		
					</td></tr>
					<tr><td class="iage_footer" align="center" bgcolor="#ffffff">
					<div style="height: 20px; line-height: 80px; font-size: 10px;"> </div>	
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr><td align="center">
								<font face="Arial, Helvetica, sans-serif" size="3" color="#96a5b5" style="font-size: 13px;">
								<span style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; color: #96a5b5;">
									'.date('Y').' © Millionaire-Business-Articles.com  ALL Rights Reserved.
								</span></font>				
							</td></tr>			
						</table>
						<div style="height: 30px; line-height: 30px; font-size: 10px;"> </div>	
					</td></tr>
					<tr><td>
				<div style="height: 80px; line-height: 80px; font-size: 10px;"> </div>
					</td></tr>
				</table>
				</td></tr>
				</table>
				</div>	';
         
         $header = 'From:'.get_option('blogname').' <'.get_option('admin_email').'>' . "\r\n";
         $header .= "MIME-Version: 1.0\r\n";
         $header .= "Content-type: text/html\r\n";
         
         /*add and get uiniqueness of content*/
         /*
			$postQuery = array();
		
		$postQuery['text'] = wp_strip_all_tags(stripslashes($description));
		$postQuery['userkey'] = "995ae027a7fe43da3d35b07cb15eaed5";
		
		$postQuery['exceptdomain'] = "site1.ru, site2.ru, site3.ru";
		

		$postQuery = http_build_query($postQuery, '', '&');

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, 'http://api.text.ru/post');
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $postQuery);
		$json = curl_exec($ch);
		$errno = curl_errno($ch);
		curl_close($ch);
		
		if (!$errno)
		{
			$resAdd = json_decode($json);
	
			if (isset($resAdd->text_uid))
			{
				$text_uid = $resAdd->text_uid;
				update_post_meta($postdata, 'post_text_uiqueness', $text_uid);
				
			}
			else
			{
			
				$error_code = $resAdd->error_code;
				$error_desc = $resAdd->error_desc;
				update_post_meta($postdata, 'post_text_uiqueness', "not found");
			}
		}
		 */
		 /*add and get uiniqueness of content*/
		 
		 //die;
		 
        if($status ==='draft'){
			 $redUrl = 	home_url('creator/create-new?saveasdraft=successfully');	
			 echo "<script> window.location.href ='".$redUrl."';</script>";

         }else{
             $retval = mail ($to,$subject,$message,$header);
			 $redUrl = 	home_url('creator/create-new?uploaded=successfully');
			echo "<script> window.location.href ='".$redUrl."';</script>";

         }	
		 
      }
	}
} 

?>

<div class="dashboard-heading">
    <h1 class="text-center">Submit Your Post</h1>
    <div class="snow-blanket"></div>
</div>

<div class="container"> 
    <div class="creator_newpost_section">
            <div class="col-md-12 creator_newpost_content_area">    
            <?php if(isset($_GET['uploaded']) && $_GET['uploaded']=="successfully"){
        	echo "<div class='success-outer'><div class='success-inner'>Your post has been submitted successfully.Thanks for your contribution to our platform. One of our moderators will check it soon and if it passes our moderation it will be published. </div></div>"; 
        } ?>
        <?php if(isset($_GET['saveasdraft']) && $_GET['saveasdraft']=="successfully"){
        	echo "<div class='success-outer'><div class='success-inner'>Your post has been submitted as a Draft successfully. </div></div>"; 
        } ?> 
        <div class="back_btn_creator"><a href="<?php echo site_url(); ?>/creator/" class="back_to_page aps_btn_primary">
            <i class="fa fa-long-arrow-left pr-1"></i> Back</a></div> 
        <div class="error-msg-save" <?php if(!empty($messageserr)){ ?> style="display:block" <?php } ?>><?php if(!empty($messageserr)){ echo $messageserr; } ?></div>
            <form method="post" id="creatorFormData" enctype="multipart/form-data" class="row creator_newpost_form" >
                 <div class="col-md-12 form-group creator_form_style">
	 	            <label>Title</label>
                    <input type="text" name="title" class="CreatorPostTitle" maxlength="60">
                    <label>Title should be less then 60 character</label>
                    </div>
                    <div class="col-md-12 form-group creator_form_style">
		                <label>Tag</label>
                        <input type="text" name="tags" class="CreatorPostTags">
                        <span class="add_tags_line"><b>Please Add Tags using Enter Seperation</b></span>
                        </div>
                    <div class="col-md-12 form-group creator_form_style">
                		<label>Category</label>
                		<?php wp_dropdown_categories( 'taxonomy=category&class=creator_post_category&exclude=1&hide_empty=0&orderby=name&order=ASC&show_option_none=Select category' ); ?>
		            </div> 
		            <div class="col-md-12 form-group creator_form_style">
                		<?php 
                		$settings =   array(
                							'wpautop' => true,
                							'media_buttons' => true, 
                							'textarea_name' =>"description", 
                							'textarea_rows' => get_option('default_post_edit_rows', 10), // rows="..."
                							'tabindex' => '',
                							'editor_css' => '',
                							'editor_class' => '',
                							'teeny' => false, 
                							'dfw' => false, 
                							'tinymce' => true, 
                							'quicktags' => true,
                							
                						);
																
                        		wp_editor( "", 'description',$settings );   
                        		
                        		?>
                		<div class="editor_below_content">
                		    <div id="wordcount"></div>
                		    <b>Please Insert Your Content Here</b>  
                		</div>
                		
                    </div> 
                    <div class="col-md-12 form-group creator_form_style">
                		 <label>Featured Image</label>
                        <input type="file" id="featured-image" accept="image/*" name="image" class="CreatorPostimage">
		
		            </div>
		            <div class="col-md-12 form-group creator_form_style">  
                    <label>Image Alt Text</label>  
                    <input type="text" name="creator_alternative_text" class="CreateAlternativeText">
            		</div>
		            <div class="col-md-12 form-group creator_form_style">  
                    <label>Seo Focus keyphrase</label>  
                    <input type="text" name="creator_seo_focus" class="CreateSeoFocus">
            		</div><!-- Seo Meta description -->
            		<div class="col-md-12 form-group creator_form_style">  
                    <label>Seo Meta description</label>  
                    <textarea minlength=130 maxlength="160" name="creator_seo_description" class="CreateSeoDescription" id="theTextArea"  placeholder="Between 130 and 160 characters are allowed" rows="9" required></textarea> 
					
					 <label for="FollowUsInsta">  
				   <div class="checkBoxDe mt-3">
				     
				          
    				    <input type="checkbox" id="FollowUsInsta" name="FollowUsInsta">
    				    <i class="jli-instagram" style="background: #d6249f;
    background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%,#d6249f 60%,#285AEB 90%); font-size: 24px;
    padding: 7px 10px;
    color: #fff; display: inline-block;">
    				     </i> Follow Us On Instagram <span class="checkIconC">✓</span>
				    </div>
				     </label>
				    <!--<div id="textarea_feedback"></div> -->
				    <div class="progress">
                        <div class="progress-bar famad-counter"  role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
                        <span class="famad-counter-text"></span>
                        </div>
                    </div>
            		</div>
		            <div class="col-md-12 form-group creator_submit_form creator_form_style">
		                <input type="hidden" class="CreatorStatusType" name="CreatorStatusType" value="" > 
                        <input type="hidden" name="CreatorSavePost" value="Submit for Review" >  
                        <input type="button" name="CreatorSavePost" value="Submit for Review" class="CreatorSavePost CreatorSubmitPost">
                        <input type="button" name="CreatorSaveasDraft" value="Save as Draft" class="CreatorSavePost CreatorSubmitPost">
						<!--input type="button" name="CreatorPreview" value="Preview" class="CreatorSavePost CreatorSubmitPost CreatorPreviewPost"-->
                    </div>
                 </form>
            
        </div><!--.creator_newpost_content end -->
    
    </div><!--.creator_newpost_section end -->
</div> <!--.container end -->   
<?php
get_footer();
?>
<script src="<?php echo get_stylesheet_directory_uri(); ?>/js/word-count.js"></script>
<script src="<?php echo get_stylesheet_directory_uri(); ?>/js/jQuery.tagify.min.js"></script>
<script src="<?php echo get_stylesheet_directory_uri(); ?>/js/tagify.js"></script>
<link href="<?php echo get_stylesheet_directory_uri(); ?>/css/tagify.css" rel="stylesheet">   

<script>
(function(){

var input = document.querySelector('input[name=tags]'),
 
    tagify = new Tagify(input, {
		pattern             : /^.{1,25}$/,
	    maxTags:6
    });


tagify.on('add', onAddTag)
      .on('remove', onRemoveTag)
      .on('input', onInput)
      .on('invalid', onInvalidTag);


function onAddTag(e){
    console.log(e, e.detail);
    console.log( tagify.DOM.originalInput.value )
    tagify.off('add', onAddTag)
}


function onRemoveTag(e){
    console.log(e, e.detail);
}

function onInput(e){
    console.log(e, e.detail);
}

function onInvalidTag(e){
    console.log(e, e.detail);
}

})()
</script>
<script type="text/javascript">

jQuery(document).ready(function() {
var text_max = 160;
$('.famad-counter-text').html(text_max + ' remaining'); 
$('#theTextArea').keyup(function() {
  var text_length = $('#theTextArea').val().length;
  var text_remaining = text_max - text_length; 
  var text_percent = parseInt((text_remaining * 100) / text_max);
  var percent = 100 - text_percent;
  $('.famad-counter').removeClass('progress-bar-success').removeClass('progress-bar-warning');
  if(percent >= 0 && percent < 82){
     $('.famad-counter').addClass('progress-bar-warning')
  }
 
  if(percent >= 82 && percent < 100){
     $('.famad-counter').addClass('progress-bar-success')
  }
  if(percent == 100){ 
     $('.famad-counter').addClass('progress-bar-warning') 
  }
  $('.famad-counter').attr("aria-valuenow","10").css("width",percent+"%"); 
  $('.famad-counter-text').html(text_remaining + ' remaining'); 
});
    
 // var text_max = 160; 
    // $('#textarea_feedback').html(text_max + ' characters remaining');

    // $('#theTextArea').keyup(function() {
    //     var text_length = $('#theTextArea').val().length;
    //     var text_remaining = text_max - text_length;

    //     $('#textarea_feedback').html(text_remaining + ' characters remaining'); 
    // });
});
</script>
<script>
$ = jQuery;

function updateCount(){
	prevCount = 0;
	
	
		var Description = tinyMCE.get('description').getContent();
		var counter = new window.wp.utils.WordCounter();
		var str = document.getElementById('description').value
		var text, count;

			if ( ! tinyMCE.get('description') || tinyMCE.get('description').isHidden() ) {
				text = str;
			} else {
				text = tinyMCE.get('description').getContent( { format: 'raw' } );
			}

			count = counter.count( text );

			prevCount = count;
			return prevCount;
}
// $( document ).on( 'tinymce-editor-init', function( event, editor ) {
// 	prevCount =0;
// 	editor.on( 'nodechange keyup', function(){
// 			var text, count;
// 			var counter = new window.wp.utils.WordCounter();
// 			text = tinyMCE.get('description').getContent( { format: 'raw' } );
// 			count = counter.count( text);
// 			if ( count !== prevCount ) {
// 				$("#wordcount").text("Words Count: " + count  );
// 			}
// 			prevCount = count;
			
// 	});
// 	$("#description").on( 'input keyup', function(){
// 		var text, count;
// 			var counter = new window.wp.utils.WordCounter();
// 			text = document.getElementById('description').value
// 			count = counter.count( text );
// 			if ( count !== prevCount ) {
// 				$("#wordcount").text("Words Count: " + count  );
// 			}
// 			prevCount = count;
// 	});
	
// });
i=0;
$(document).ready(function(){
    // visual mode
    // the iframe id
    $("#description_ifr").ready(function () {
        setInterval(function(){
            var tinymceval = $('#description_ifr').contents().find('body').text();
            var wordscount = tinymceval.split(" ");
                    // you should crete a div with the 
                    // the id = #wordcount to show count
            $("#wordcount").text("Words Count: " + wordscount.length);
        }, 2000)  
    }); 

    // html mode
// #description is the id of the text area
/*
    $("#description").keypress(function(){
        $("#wordcount").text(i+=1);
    });
    */
});


jQuery(document).ready(function(){ 
    
   jQuery(".CreatorSubmitPost").on("click",function(){
		statusType = $(this).attr("name");
		if(statusType === "CreatorSaveasDraft"){
		    $(".CreatorStatusType").val("draft");
		}else{
		    $(".CreatorStatusType").val("pending");

		}
		$(".success-outer").hide(); 
		
        error = "";
    var PostTitle =    $(".CreatorPostTitle").val();
    var PostTags =    $(".tagList").val();
    var categoryDropdown = $("#cat").val();
    var Postimage = $(".CreatorPostimage").val();
    var ImageAlt  = $(".CreateAlternativeText").val();
	//var Description = tinyMCE.get('description').getContent();
	var Description = tinyMCE.get('description').getContent();
	var DescriptionLength =   updateCount();
	var PostSeoFocus =   $(".CreateSeoFocus").val();
	var PostSeoDescription =    $("#theTextArea").val(); 
	var FollowUsInsta = $("#FollowUsInsta").prop('checked');
	
    if(PostTitle ===""){
        error = "Title is Required";
    }
	else if(PostTitle.length > 60){
		error = "Title length should be less then 60 character";
	}
	else if(PostTags == null){
        error = "Tag field is Required";
    }
    else if( categoryDropdown === '-1'){
        error = "Please Select Category";
    }
	else if(DescriptionLength < 800){
		 error = "Editor Content should be more then 800 words";  
	}
	else if(Postimage === ""){
        error = "Please Select Featured Image";   
    }
    else if(ImageAlt ===""){
        error = "Image Alt Text is Required"; 
    }
	else if(PostSeoFocus ===""){
        error = "Seo Focus keyphrase is Required";
    }
    else if(PostSeoDescription == ""){
		error = "Seo Meta description is Required";
	}
	else if(PostSeoDescription.length < 130){
		error = "Seo Meta Description Length should be more then 130 ";
	}
	else if(PostSeoDescription.length > 160){
		error = "Seo Meta Description Length should be less then 160 "; 
	}else if(FollowUsInsta == false){
	    error = "Please follow us on instagram to serve you better.Click Follow Us And Then Submit "; 
	}
	
    if(error !==""){
        $('html,body').animate({
        scrollTop: $("body").offset().top},
        'slow');
       $(".error-msg-save").show();
       $(".error-msg-save").text(error);
    }else{
		if(statusType ==="CreatorPreview"){
			$("#creatorFormData").attr("action","<?php echo site_url(); ?>/creator/preview/");
			$("#creatorFormData").attr('target', '_blank');  
			 $("#creatorFormData").submit();
			 $(".error-msg-save").hide();
         $(".error-msg-save").text("");
		}else{
		    $("#creatorFormData").removeAttr("action");
			$("#creatorFormData").removeAttr('target');
         $("#creatorFormData").submit();
         $(".error-msg-save").hide();
         $(".error-msg-save").text("");
		}
         
    }
    
   }); 

$(".checkBoxDe").click(function(){
    window.open('https://www.instagram.com/millionairebusinessarticles/', '_blank');
})
});
</script>
<style>
.error-msg-save{
width: 100%;
float: left;
background: red;
color: #fff; 
padding: 16px;
display: none;
}
.success-outer {
    background: #63b900;
    padding: 10px;
    color: #fff;
    margin-bottom: 10px;
}
.progress {
  position: relative;
  margin: 7px 0;
  height: 17px;
  border-radius: 45px; 
}

.progress span {
    position: absolute;
    display: block;
    width: 100%;
    font-size: 12px;
    color: black;
}
.wp-switch-editor{
height:auto;
color: #fff;
}
button#insert-media-button {
    color: #fff;
}
button#menu-item-upload {
    color: #2271b1;
}
</style>