<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function get_calender_events() { $params = array(); /*Get current date*/ $current_date = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key = "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url, ...
<script src="/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
function CKupdate(){
for ( instance in CKEDITOR.instances ){
CKEDITOR.instances[instance].updateElement();
}
CKEDITOR.instances[instance].setData('');
}
CKEDITOR.replace( 'txtContent' , {
removeButtons: 'save',
});
</script>
<form method="post" action="#" class="acf-form" id="post" enctype="multipart/form-data">
<?php
$args = array(
'post_id' => 'new',
'field_groups' => array(1), //it's the ID of your custom field Form
'form' => false
);
acf_form( $args );
?>
<div class="content-box">
<div class="content-box-content">
Title: <input type="text" name="resource_title" id="resource_title">
<div>
<textarea class="ckeditor" id="txtContent" name="emailtxt2" rows=15 cols=30></textarea>
</div>
<p class="label"><label for="acf-field-file">Image</label></p>
<div class="acf-input-wrap">
<input type="file" id="my_image_upload" name="my_image_upload">
</div>
<p class="label"><label for="acf-field-file">Image</label></p>
<div class="acf-input-wrap">
<input type="file" id="my_file_upload" name="my_file_upload">
</div>
<p class="label"><label for="acf-field-file">Tags</label></p>
<div class="acf-input-wrap">
<input type="text" id="resources_tags" name="resources_tags">
</div>
<ul>
<li>
<label>Looking For</label>
<div class="selectbox_outer"><div class="custselect">
<select name="looking_for" id="looking_for" class="postform">
<option value="">All Media</option>
<?php
$looking_for = $_GET['looking_for'];
$taxonomy = 'looking_for';
$tax_terms = get_terms($taxonomy, array('hide_empty' => false));
foreach($tax_terms as $tax_term){
?>
<option value="<?php echo $tax_term->slug; ?>" <?php if($looking_for==$tax_term->slug){ echo 'selected="selected"';} ?> ><?php echo $tax_term->name; ?></option>
<?php
}
?>
</select>
<div class="select__arrow"></div>
</div></div>
</li>
<li> <label>About</label>
<div class="selectbox_outer"><div class="custselect">
<select name="about" id="about" class="postform">
<option value="">All Mindsets</option>
<?php
$about = $_GET['about'];
$taxonomy = 'about';
$tax_terms = get_terms($taxonomy, array('hide_empty' => false));
foreach($tax_terms as $tax_term){
?>
<option value="<?php echo $tax_term->slug; ?>" <?php if($about==$tax_term->slug){ echo 'selected="selected"';} ?> ><?php echo $tax_term->name; ?></option>
<?php
}
?>
</select>
<div class="select__arrow"></div>
</div></div>
</li>
<li>
<label>For</label>
<div class="selectbox_outer"><div class="custselect">
<select name="age_group" id="age_group" class="postform">
<option value="">All Ages</option>
<?php
$age_group = $_GET['age_group'];
$taxonomy = 'age_group';
$tax_terms = get_terms($taxonomy, array('hide_empty' => false));
foreach($tax_terms as $tax_term){
?>
<option value="<?php echo $tax_term->slug; ?>" <?php if($age_group==$tax_term->slug){ echo 'selected="selected"';} ?> ><?php echo $tax_term->name; ?></option>
<?php
}
?>
</select>
<div class="select__arrow"></div>
</div></div>
</li>
<input id="submit_my_image_upload" name="submit_my_image_upload" type="submit" value="Submit" />
<a href="javascript:void(0);" class="Button" onclick="update_new_estimonial1(1);">Add Resource</a>
<!-- End #tab1 -->
</div>
<!-- End .content-box-content -->
</div>
</form>
</div>
<script>
initSample();
function update_new_estimonial1(id){
var c_text = CKEDITOR.instances['txtContent'].getData();
//var c_text = escape(c_text)
var resource_title = jQuery('#resource_title').val();
if(resource_title==""){alert("Please enter title."); return false;}
var looking_for = jQuery('#looking_for').val();
var about = jQuery('#about').val();
var age_group = jQuery('#age_group').val();
var formData = new FormData(jQuery('form')[0]);
formData.append("c_text", c_text);
jQuery.ajax({
type: 'POST',
xhr: function() { // Custom XMLHttpRequest
var myXhr = $.ajaxSettings.xhr();
//if(myXhr.upload){ // Check if upload property exists
// myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // For handling the progress of the upload
//}
return myXhr;
},
// Form data
enctype: 'multipart/form-data',
data: formData,
//Options to tell jQuery not to process data or worry about content-type.
cache: false,
contentType: false,
processData: false,
url: '<?php echo get_site_url(); ?>/wp-content/themes/midsets/action.php',
success: function(value) {
jQuery('#resource_title').val("");
jQuery('#looking_for').val("");
jQuery('#about').val("");
jQuery('#age_group').val("");
jQuery('#txtContent').val("");
CKupdate();
jQuery('#post')[0].reset();
alert("your post added successfully..");
//window.location.href = "<?php echo get_site_url(); ?>/wp-admin/admin.php?page=manage_testimonials&w=2";
//location.reload();
},
});
}
</script>
action.php
<?php
include_once("../../../wp-load.php");
global $wpdb;
print_r($_POST);
print_r($_FILES);
$title = addslashes($_POST['resource_title']);
$about=$_POST['about'];
$age_group=$_POST['age_group'];
$looking_for=$_POST['looking_for'];
$c_text = $_POST['c_text'];
$resources_tags = $_POST['resources_tags'];
// before saving post
remove_filter('content_save_pre', 'wp_filter_post_kses');
remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
// save code here
$my_post = array(
'post_title' => $_POST['resource_title'],
'post_content' => $c_text,
'post_type'=>'resources',
'post_status' => 'pending',
'filter' => false,
'post_author' => get_current_user_id(),
);
// Insert the post into the database.
$post_id = wp_insert_post( $my_post );
wp_set_object_terms( $post_id, $looking_for, 'looking_for' );
wp_set_object_terms( $post_id, $age_group, 'age_group' );
wp_set_object_terms( $post_id, $about, 'about' );
wp_set_object_terms( $post_id, $resources_tags, 'resources_tags' );
// after saving post
add_filter('content_save_pre', 'wp_filter_post_kses');
add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
$current_user = wp_get_current_user();
/**
* @example Safe usage: $current_user = wp_get_current_user();
* if ( !($current_user instanceof WP_User) )
* return;
*/
// 'Username: ' . $current_user->user_login . '<br />';
$email = $current_user->user_email;
$user_id = $current_user->ID;
$cdate = date("Y-m-d H:i:s");
echo $sql = "INSERT INTO `wp_resources` (`id`, `pid`, `user_id`, `user_email`, `title`, `content`, `looking_for`, `about`, `age_group`, `status`, `date`) VALUES (NULL, '$post_id', '$user_id', '$email', '$title', '$c_text', '$looking_for', '$about', '$age_group', '0', '$cdate');";
$wpdb->query($sql);
/*
image and pdf upload in acf
// Create a new post
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attachment_id = media_handle_upload( 'my_image_upload', $post_id );
update_field('my_image_upload', $attachment_id, $post_id);
$attachment_id = media_handle_upload( 'pdf', $post_id );
update_field('pdf', $attachment_id, $post_id);
*/
if ( !function_exists('wp_handle_upload') ) {
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
}
// Move file to media library
$movefile = wp_handle_upload( $_FILES['my_image_upload'], array('test_form' => false) );
// If move was successful, insert WordPress attachment
if ( $movefile && !isset($movefile['error']) ) {
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename($movefile['file']),
'post_mime_type' => $movefile['type'],
'post_title' => preg_replace( '/\.[^.]+$/', "", basename($movefile['file']) ),
'post_content' => "",
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment($attachment, $movefile['file']);
// Assign the file as the featured image
//set_post_thumbnail($post_id, $attach_id);
update_field('thumbnail_image', $attach_id, $post_id);
$attachment_id = media_handle_upload( 'my_file_upload', $post_id );
update_field('attach_file', $attachment_id, $post_id);
}
?>
Comments
Post a Comment