Skip to main content

Get Google Calendar Event List in WordPress

<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, ...

CRUD IN WP

CRUD Operation
<?php
add_action( 'admin_menu', 'sitter_details_page' );
function sitter_details_page(){
    add_menu_page( 'Sitter Details', 'Sitter Details', 'manage_options','sitter_details', 'sitter_details_options');
  if ( current_user_can( 'administrator' )  || current_user_can( 'sitter_leaders' )) {
   add_submenu_page(
            'sitter_details', 'Add Sitter', 'Add Sitter', 'manage_options', 'add_sitter', 'add_sitter_here'
    );
 add_submenu_page(
            'sitter_details', 'Edit Sitter', 'Edit Sitter', 'manage_options', 'edit_sitter', 'edit_sitter_here'
    );

  }
}
//view sitter link
function sitter_details_options()
{
global $wpdb;
$sql = "SELECT * FROM sitter;";
$pageposts = $wpdb->get_results($sql);?>
<script>
 function delete_event(id){
 flag=confirm("Do you really want to delete record");
 if(flag==true)
  {
        jQuery.ajax({
          type:'POST',
          data:{action:'delete_boot',id:id},
            url: '<?php echo  get_site_url(); ?>/wp-content/themes/snappysitter/action.php',
          success: function(value) {  
      location.reload();
           //jQuery("#showcontent").html(value);
          },
        }); 
  }
}
 jQuery(document).ready(function() {
    jQuery('input[type=radio]').live('change', function() {

 var id= jQuery(this).attr('data-id');
 var atten= jQuery(this).val();
jQuery.ajax({
          type:'POST',
          data:{action:'add_atten',id:id,atten:atten},
            url: '<?php echo  get_site_url(); ?>/wp-content/themes/snappysitter/action.php',
          success: function(value) {  
     // location.reload();
           //jQuery("#showcontent").html(value);
          },
        });
 
 
 });
});
 
</script>
<style>
.title_text{font-size:12px;}
table td{ font-size:11px;}
.event_table{ padding:0 10px 0 0;}
.red{color:#dc1522; line-height:30px; font-weight:700;}
.green{color:#00c42e; line-height:30px; font-weight:700;}
.pagination{ float:right; margin:10px 10px 0 0; border:#CCCCCC solid 1px; background:#FFFFFF;}
.pagination a{ border-right:#CCCCCC solid 1px; padding:0 10px; line-height:20px; text-decoration:none;}
.pagination a:last-child{ border-right:none;}
</style>
<div class="wrap">
<h2>Sitter Details <a href="<?php echo  get_site_url();?>/wp-admin/admin.php?page=add_sitter" class="add-new-h2">Add New sitter</a>
</h2>
</div>
<div class="event_table">
<table width="100%" border="0" cellspacing="1" cellpadding="5" bgcolor="#e5e5e5">
  <tr>
 
      <td align="center" valign="middle" bgcolor="#dfdfdf" class="title_text"><strong>name</strong></td>  
   <td align="center" valign="middle" bgcolor="#dfdfdf" class="title_text"><strong>Phone</strong></td>
   <td align="center" valign="middle" bgcolor="#dfdfdf" class="title_text"><strong>email</strong></td>
   <td align="center" valign="middle" bgcolor="#dfdfdf" class="title_text"><strong>About you</strong></td>
   <td align="center" valign="middle" bgcolor="#dfdfdf" class="title_text"><strong>Action</strong></td>
  </tr>
<?php
foreach ($pageposts as $singlepost) {
?>
  <tr>
    <td align="left" valign="top" bgcolor="#FFFFFF"><?php echo $singlepost->name;?></td>
      <td align="left" valign="top" bgcolor="#FFFFFF"><?php echo $singlepost->phone;?></td>
  <td align="left" valign="top" bgcolor="#FFFFFF"><?php echo $singlepost->email;?></td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><?php echo $singlepost->about;?></td>
    <td align="left" valign="top" bgcolor="#FFFFFF">
 <a href="<?php echo get_site_url() ?>/wp-admin/admin.php?page=edit_sitter&id=<?php echo $singlepost->id;?>" onclick="edit_record(<?php echo $singlepost->id;?>);">Edit</a>&nbsp;&nbsp;<span>|</span>&nbsp;&nbsp;
 <a href="javascript:void(0);" onclick="delete_event(<?php echo $singlepost->id;?>);">Delete</a>
 </td>
  
  </tr>
<?php
}?>
</table></div>
<?php die;
}
//end  sitter link

//add category
function add_sitter_here(){

 function random_password( $length = 8 ) {
    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$?";
    $password = substr( str_shuffle( $chars ), 0, $length );
    return $password;
}
 ?>
<link rel="stylesheet" media="all" type="text/css" href="http://code.jquery.com/ui/1.8.23/themes/smoothness/jquery-ui.css" />
<!--<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>-->
<script type="text/javascript" src="http://code.jquery.com/ui/1.8.23/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script> <script type="text/javascript">
bkLib.onDomLoaded(function() {
new nicEditor({maxHeight : 1000}).panelInstance('description');
});
jQuery(function() {
jQuery('#start_date').datepicker({minDate:0});
});
</script>
<script>
function add_sitter_categorys()
{
 var category_name=jQuery("#category_name").val();
 var startdate=jQuery("#start_date").val();
 var description=jQuery("#description").val();
 formData = jQuery("form").serialize();

 if(category_name!="") {
         jQuery.ajax({
          type:'POST',
          data:formData,
          url: '<?php echo  get_site_url(); ?>/wp-content/themes/snappysitter/action.php',
          success: function(value) {
       // location.reload();
  window.location.href = "<?php echo  get_site_url(); ?>/wp-admin/admin.php?page=sitter_details&msg=event_added";
          },
        }); 
 }
else {
 jQuery("#msg").html("Please fill mandatory fields");//alert(jQuery("#msg").html());
 jQuery("#msg").show();
 jQuery("#category_name").css("border-color", "red")
}
}
</script>
<style>
table td span{ color:#F00;}
table td input{ font-size:11px;}
table td textarea{ overflow:hidden; font-size:11px;}
table td{ font-size:11px;}
@media screen and (max-width:320px) {
.add_event{ overflow-x:scroll;}
}
.red{color:#dc1522; line-height:30px; font-weight:700;}
.green{color:#00c42e; line-height:30px; font-weight:700;}
</style>
<div class="wrap">
<h2>Add sitter <a href="<?php echo  get_site_url();?>/wp-admin/admin.php?page=sitter_details" class="add-new-h2">Back</a></h2>
</div>
 <form id="sitter_category" action="" method="post">
<table width="50%" border="0" cellspacing="1" cellpadding="5" bgcolor="#e5e5e5">
 <THEAD>
 <h3>Please fill below information </h3>
 <span id="msg" class='red' style="display:none"></span>
 </THEAD>
 <TBODY>
   <input type="hidden" name="action" id="action" value="add_sitter"/>
   <input type="hidden" name="id" id="id" value="<?php echo $events->id; ?>"/>
 
   
    <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">name</td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><input type="text" name="name" id="name" value="<?php echo $events->name; ?>"/>
   </td>
  </tr>

    <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">phone</td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><input type="text" name="phone" id="phone" value="<?php echo $events->phone; ?>"/>
   </td>
  </tr>
    <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">Email</td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><input type="text" name="email" id="email" value="<?php echo $events->email; ?>"/>
   </td>
  </tr>
   <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">About you</td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><textarea name="about"><?php echo $events->about; ?></textarea>
   </td>
   </td>
  </tr>
 
  </tr>
  <tr>
    <td align="center" valign="top" bgcolor="#FFFFFF" colspan="2">
    <input type="button" class="button" onclick="add_sitter_categorys()" name="add_sitter_category" id="add_sitter_category" value="Submit">
    </td>
  </tr>
  </TBODY>
 </table>
 </form>
 <?php
}


//edit sitter category
//add_action('wp_ajax_edit_sitter_category','edit_sitter_category'); 
//add_action('wp_ajax_nopriv_edit_sitter_category','edit_sitter_category'); 
function edit_sitter_here()
{
global $wpdb;
$id=$_GET['id'];
$sql="select * from sitter where id='$id'";
$events = $wpdb->get_row($sql);
//print_r($events);
?>
<script>
function editevent()
{
 var title=jQuery("#title").val();
 var startdate=jQuery("#start_date").val();
 var description=jQuery("#description").val();
     if(title!="" && startdate!="") {
         jQuery.ajax({
          type:'POST',
          data:jQuery("form").serialize(),
          url: '<?php echo  get_site_url(); ?>/wp-content/themes/snappysitter/action.php',
          success: function(value) {  
   //  location.reload();
           //jQuery("#showcontent").html(value);
          },
        }); 
  }
     else {
 jQuery("#msg").html("Please fill mandatory fields");//alert(jQuery("#msg").html());
 jQuery("#msg").show(); 
  } 
}
</script>
<style>
table td span{ color:#F00;}
table td input{ font-size:11px;}
table td textarea{ overflow:hidden; font-size:11px;}
table td{ font-size:11px;}
@media screen and (max-width:320px) {
.add_event{ overflow-x:scroll;}
}
.red{color:#dc1522; line-height:30px; font-weight:700;}
.green{color:#00c42e; line-height:30px; font-weight:700;}
</style>
<div class="add_event">
<form id="editevent" action="<?php echo  get_site_url(); ?>/wp-content/themes/superiorkneerehab/action.php" method="post" enctype="multipart/form-data">
<table width="50%" border="0" cellspacing="1" cellpadding="5" bgcolor="#e5e5e5">
 <THEAD>
 <h3>Please fill below information, </h3>
 <span id="msg" class='red' style="display:none"></span>
 </THEAD>
 <TBODY>
   <input type="hidden" name="action" id="action" value="edit_sitter"/>
   <input type="hidden" name="id" id="id" value="<?php echo $events->id; ?>"/>
 
    <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">name</td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><input type="text" name="name" id="name" value="<?php echo $events->name; ?>"/>
   </td>
  </tr>

    <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">phone</td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><input type="text" name="phone" id="phone" value="<?php echo $events->phone; ?>"/>
   </td>
  </tr>
    <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">Email</td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><input type="text" name="email" id="email" value="<?php echo $events->email; ?>"/>
   </td>
  </tr>
   <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">About you</td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><textarea name="about"><?php echo $events->about; ?></textarea>
   </td>
   </td>
  </tr>
 
  <tr>
    <td align="center" valign="top" bgcolor="#FFFFFF" colspan="2">
    <input type="button" onclick="editevent()" name="edit_event" id="edit_event" value="Submit" class="button">
    </td>
  </tr>
  </TBODY>
 </table>
 </form>
 </div>
<?php die;}

action.php
<?php
include_once("../../../wp-load.php");
global $wpdb;
$id=$_POST['id'];
$action=$_POST['action'];
$admin_email = get_option( 'admin_email' );

if($action=='add_atten')
{
$atten=$_POST['atten'];
 echo $sql = "UPDATE .`boot_camp` SET
`atten` = '$atten' WHERE `boot_camp`.`id` =$id";
 $wpdb->query($sql);
 exit;
}
?>

ck editer note
*********************
get the data
var email_text = CKEDITOR.instances['txtContent2'].getData();
set the data
//CKEDITOR.instances.yourInstanceName.setData( data );
CKEDITOR.instances['txtContent'].setData( data );

<script src="<?php echo get_template_directory_uri(); ?>/js/ckeditor/ckeditor.js"></script>
<script>
 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 )
 CKEDITOR.tools.enableHtml5Elements( document );
CKEDITOR.config.height = 150;
CKEDITOR.config.width = 'auto';
var initSample = ( function() {
 var wysiwygareaAvailable = isWysiwygareaAvailable(),
  isBBCodeBuiltIn = !!CKEDITOR.plugins.get( 'bbcode' );
 return function() {
  var editorElement = CKEDITOR.document.getById( 'txtContent' );
  if ( isBBCodeBuiltIn ) {
   editorElement.setHtml(
    'Hello world!\n\n' +
    'I\'m an instance of [url=http://ckeditor.com]CKEditor[/url].'
   );
  }
  if ( wysiwygareaAvailable ) {
   CKEDITOR.replace( 'txtContent' );
  } else {
   editorElement.setAttribute( 'contenteditable', 'true' );
   CKEDITOR.inline( 'txtContent' );
  }
 };
 function isWysiwygareaAvailable() {
  if ( CKEDITOR.revision == ( '%RE' + 'V%' ) ) {
   return true;
  }
  return !!CKEDITOR.plugins.get( 'wysiwygarea' );
 }
} )();
</script>
<div id="txtContent">
</div>
 <script>
 initSample()
</script>

Comments

Popular posts from this blog

Create Signature pad with save on database in php

Create Signature pad with save on database in php 1.create a folder images index.php ============   <!DOCTYPE >     <head>     <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />     <title>Signature Pad</title>     <script type="text/javascript" src="jquery-1.8.0.min.js"></script>     <script type="text/javascript"> $(document).ready(function () {     /** Set Canvas Size **/     var canvasWidth = 400;     var canvasHeight = 100;     /** IE SUPPORT **/     var canvasDiv = document.getElementById('signaturePad');     canvas = document.createElement('canvas');     canvas.setAttribute('width', canvasWidth);     canvas.setAttribute('height', canvasHeight);     canvas.setAttribute('id', 'canvas');     canvasDiv.appendChild(canvas);    ...

Get Google Calendar Event List in WordPress

<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, ...

WooCommerce Mini cart With Ajax

WooCommerce Mini cart //MINI CART SECTION   <div class="productdiv rightcart">                                                         <?php if ( ! WC()->cart->is_empty() ) : ?>     <ul class="woocommerce-mini-cart cart_list product_list_widget <?php echo esc_attr( $args['list_class'] ); ?>">         <?php             do_action( 'woocommerce_before_mini_cart_contents' );             foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {                 $_product     = apply_filters( 'woocommerce_cart_item_pro...