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

WordPress admin CRUD Operation

WordPress admin CRUD Operation
//for adding testimonials post type
add_action( 'init', 'testimonials' );
function testimonials() {
  register_post_type( 'Testimonials',
    array(
      'labels' => array(
        'name' => __( 'Testimonials' ),
        'singular_name' => __( 'Testimonials' )
      ),
      'public' => true,
      'has_archive' => true,
 'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
    )
  );
}

//for adding js and create ajax object
function admin_scripts() {
            wp_register_style('main_admin', get_bloginfo('stylesheet_directory') . '/css/main_admin.css');
            wp_register_style('jquery_ui_css', get_bloginfo('stylesheet_directory') . '/css/jquery-ui.css');
            wp_register_script('jquery_ui_js', get_bloginfo('stylesheet_directory') . '/js/jquery-ui.js');
            wp_register_script('custom_admin_js', get_bloginfo('stylesheet_directory') . '/js/custom-admin.js', array('jquery'));
            wp_enqueue_style('main_admin');
            wp_enqueue_style('thickbox');
            wp_enqueue_script('thickbox');
            wp_enqueue_style('jquery_ui_css');
            wp_enqueue_script('jquery_ui_js');
            wp_enqueue_script('custom_admin_js');
            wp_localize_script('custom_admin_js', 'ajax_obj', array('ajaxurl' => admin_url('admin-ajax.php')));
        }
add_action('admin_enqueue_scripts', 'admin_scripts');



for add menu and item

add_action( 'admin_menu', 'social_media' );
 function social_media(){
    add_menu_page( 'Social Media Details', 'Social Media Details', 'manage_options','social_details', 'social_details');

add_submenu_page(
            'social_details', 'Add Event', 'Add Event', 'manage_options', 'new_social_details', 'social_options_display_here'
    );
}


function social_details()
{
global $wpdb;
$sql="select * from social";
$social = $wpdb->get_results($sql);

?>
<script>
function edit_record(id)
{
 jQuery.ajax({
          type:"GET",
          data:{action:"edit_social",id:id},
          url: "<?php echo get_site_url() ?>/wp-admin/admin-ajax.php",
          success: function(value) {
 jQuery("#wpbody-content").html(value);
 jQuery(".tablenav-pages").hide();
          // jQuery("#showcontent").html(value);
          },
        });

}


function add_record()
{
 jQuery.ajax({
          type:"GET",
          data:{action:"add_registered_user"},
          url: "<?php echo get_site_url() ?>/wp-admin/admin-ajax.php",
          success: function(value) {
  jQuery("#wpbody-content").html(value);
  jQuery(".tablenav-pages").hide();
          // jQuery("#showcontent").html(value);
          },
        });

}

function delete_record(id){
 flag=confirm("Do you really want to delete record");
 if(flag==true)
  {
        jQuery.ajax({
          type:'POST',
          data:{action:'delete_rec',id:id},
           url: '<?php echo get_template_directory_uri(); ?>/action.php',
          success: function(value) {
  jQuery("."+value).hide();
  // location.reload();
           //jQuery("#showcontent").html(value);
          },
        });
  }
}

function view_record(id)
{
 jQuery.ajax({
          type:"GET",
          data:{action:"view_social",id:id},
          url: "<?php echo get_site_url() ?>/wp-admin/admin-ajax.php",
          success: function(value) {
  jQuery("#wpbody-content").html(value);
  jQuery(".tablenav-pages").hide();
          // jQuery("#showcontent").html(value);
          },
        });

}
</script>





<h2>Details <a href="javascript:void(0);" class="add-new-h2" onclick="add_record();">Add User</a>

<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
    <td align="center" valign="middle" bgcolor="#dfdfdf" class="title_text"><strong>Id</strong></td>
    <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>Email</strong></td>
    <td align="center" valign="middle" bgcolor="#dfdfdf" class="title_text"><strong>Action</strong></td>
  </tr>
<?php
foreach ($social as $socials)
 {?>
  <tr class="<?php echo $socials->id;?>">
    <td align="left"  valign="middle"><?php echo $socials->id;?></td>
    <td align="left"   valign="middle"><?php echo $socials->name;?></td>
    <td align="left"   valign="middle"><?php echo $socials->email;?></td>
    <td align="left"   valign="middle">
<a href="javascript:void(0);" onclick="edit_record(<?php echo $socials->id;?>);">Edit</a>
<a href="javascript:void(0);" onclick="delete_record(<?php echo $socials->id;?>);">Delete</a>
<a href="javascript:void(0);" onclick="view_record(<?php echo $socials->id;?>);">View</a>
</td>
  </tr>
<?php
}
?>
</table>
<?php



}


//for Edit

add_action('wp_ajax_edit_social','edit_social');
add_action('wp_ajax_nopriv_edit_social','edit_social');
function edit_social()
{
global $wpdb;
$id=$_GET['id'];
$sql="select * from social where id='$id'";
$events = $wpdb->get_row($sql);
//print_r($events);
?>
<script>



function editevent()
{
 var name=jQuery("#title").val();
 var email=jQuery("#start_date").val();
     if(name!="" && email!="") {
         jQuery.ajax({
          type:'POST',
          data:jQuery("form").serialize(),
          url: '<?php echo get_template_directory_uri(); ?>/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>

<div class="add_event">
<form id="editevent" 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>
  <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">Name <span>*</span></td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><input type="text" name="name" id="title" value="<?php echo $events->name; ?>"/>
   <input type="hidden" name="action" id="action" value="edit_social"/>
   <input type="hidden" name="id" id="id" value="<?php echo $events->id; ?>"/>
   </td>
  </tr>
    <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">Email <span>*</span></td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><input type="text" name="email" id="start_date" value="<?php echo $events->email; ?>"/> </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;}


//for adding


add_action('wp_ajax_add_registered_user','add_registered_user');
add_action('wp_ajax_nopriv_add_registered_user','add_registered_user');
function add_registered_user()
{
global $wpdb;

?>
<script>
function add_register()
{ //alert();

var name= jQuery("#name").val();
var email= jQuery("#email").val();

//var badge= jQuery("#badge").val();
//var letters = /[A-Za-z]+$/;
//var emailPattern1 = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

  formData = jQuery("form").serialize();
          jQuery.ajax({
          type:'POST',
          data:formData,
       url: '<?php echo get_template_directory_uri(); ?>/action.php',
          success: function(value) {

        window.location.href = "<?php echo  get_site_url(); ?>/wp-admin/admin.php?page=social_details&msg=added";
          },
        });


}
</script>

<div class="wrap">
<h2>Please fill below information <a href="<?php echo  get_site_url();?>/wp-admin/admin.php?page=social_details"  class="add-new-h2">Back</a></h2>
</div>
<div class="add_event">
<form id="edit_register" action="" method="post">
<table width="50%" border="0" cellspacing="1" cellpadding="5" bgcolor="#e5e5e5">
 <THEAD>
  <span id="msg" class='red' style="display:none">

  </span>

 </THEAD>
 <TBODY>

<input type="hidden" name="action" id="action" value="add_socials"/>
   <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">Name <span>*</span></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">Email <span>*</span></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="center" valign="top" bgcolor="#FFFFFF" colspan="2">
    <input type="button" onclick="add_register();" name="addregister" id="addregister" value="Submit" class="button">
    </td>
  </tr>
  </TBODY>
 </table>
 </form>
 </div>
<?php die;
}
add_action('wp_ajax_view_social','view_social');
add_action('wp_ajax_nopriv_view_social','view_social');
function view_social()
{
global $wpdb;
$id=$_GET['id'];
$sql="select * from social where id='$id'";
$events = $wpdb->get_row($sql);
//print_r($events);
?>

<div class="wrap">
<h2>View social <a href="<?php echo  get_site_url();?>/wp-admin/admin.php?page=social_details" class="add-new-h2">Back</a></h2>
</div>
<div class="add_event">
<form id="addevent" action="" method="post">
<table width="50%" border="0" cellspacing="1" cellpadding="5" bgcolor="#e5e5e5">
 <THEAD>
  <span id="msg" style="display:none"></span>
 </THEAD>
 <TBODY>
  <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">Name</td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><?php echo $events->name; ?>
   </td>
  </tr>
    <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">Email</td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><?php echo $events->email; ?></td>
  </tr>

  </TBODY>
 </table>
 </form>
 </div>
<?php die;}

function social_options_display_here(){
 ?>
<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 addsocial()
{
 var title=jQuery("#title").val();
 var startdate=jQuery("#start_date").val();
 var description=jQuery("#description").val();
 formData = jQuery("form").serialize();
 formData = formData + '&description=' + jQuery(".nicEdit-main").html();

 if(title!="" && startdate!="") {
         jQuery.ajax({
          type:'POST',
          data:formData,
         url: '<?php echo get_template_directory_uri(); ?>/action.php',
          success: function(value) {
   //location.reload('<?php echo  get_site_url(); ?>/wp-admin/admin.php?page=event_details');
           //jQuery("#showcontent").html(value);
  window.location.href = "<?php echo  get_site_url(); ?>/wp-admin/admin.php?page=social_details&msg=social_added";
          },
        });
 }
else {
 jQuery("#msg").html("Please fill mandatory fields");//alert(jQuery("#msg").html());
 jQuery("#msg").show();
}
}
</script>


<div class="wrap">
<h2>Add new social <a href="<?php echo  get_site_url();?>/wp-admin/admin.php?page=social_details" class="add-new-h2">Back</a></h2>
</div>
 <form id="addevent" 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>
  <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">Title <span>*</span></td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><input type="text" name="title" id="title" value=""/>
   <input type="hidden" name="action" id="action" value="add_event"/>
   </td>
  </tr>
    <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">Start Date <span>*</span></td>
   <td align="left" valign="top" bgcolor="#FFFFFF"><input type="text" name="start_date" id="start_date" value="" class="prjtitlediv"/> </td>
  </tr>
  <tr>
   <td align="left" valign="top" bgcolor="#FFFFFF">Description</td>
   <td align="left" valign="top" bgcolor="#FFFFFF">
<textarea name="description" id="description" rows="10" cols="60" ></textarea>
   <?php
/*  $settings = array(
        'textarea_name' => 'description',
        'textarea_rows' => 8
    );
 wp_editor($content, 'description', $settings);  */

?>
   </td>
  </tr>
  <tr>
    <td align="center" valign="top" bgcolor="#FFFFFF" colspan="2">
    <input type="button" class="button" onclick="addsocial()" name="add_social" id="add_social" value="Submit">
    </td>
  </tr>
  </TBODY>
 </table>
 </form>
 <?php
}
***************************************************
action.php

<?php
include_once("../../../wp-load.php");
global $wpdb;
$id=$_POST['id'];
$action=$_POST['action'];
if($action=='edit_social')
{
    $sql = "update social set email='".$_POST['email']."',name='".$_POST['name']."' where id=".$_POST['id'];
echo $sql;
$wpdb->query($sql);
     echo "confirm";
exit;
}


if($action=='add_socials')
{

$name=$_POST['name'];
$email=$_POST['email'];

$sql="insert into social (name,email) values('$name','$email')";
echo $sql;
$wpdb->query($sql);
exit;
}
if($action=='delete_rec')
{
$id=$_POST['id'];
$sql="delete from social where id='$id'";
$wpdb->query($sql);
echo $id;
exit;
}
?>

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