Skip to main content

Posts

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,
Recent posts

Datepicker Show grren color date if any database records found

                     <p class="dateP">Date: <input type="text" value="<?php if($_GET['date_by_student'] == ""){echo $createdate = date('Y-m-d');}else{ echo $_GET['date_by_student'];} ?>" readonly class="datepicker" id="datepicker_student" ></p>                                           <?php                        global $wpdb;          $id = $pagepost->id;        $sqls = "SELECT DISTINCT(`date`) FROM `userdata` where `id` = '$id'";       $pagepostssaa_dae = $wpdb->get_results($sqls);                                                ?>                                                                <script>   $( function() {               // An array of dates     var eventDates = {};     <?php foreach($pagepostssaa_dae as $datte){            $originalDate = $datte->date; $newDate = date("m/d/Y", strtotime($originalDate));     ?>

Remove custom post type permalink

'publicly_queryable'  => false, //remove link for the post 'rewrite'            => false, //Triggers the handling of rewrites for this post type. To prevent rewrites, set to false 'query_var'          => false, - Disables query_var key use. A post type cannot be loaded at /?{query_var}={single_post_slug} 'public' => false,  // it's not public, it shouldn't have it's own permalink, and so on 'show_ui' => true,  // you should be able to edit it in wp-admin 'exclude_from_search' => true,  // you should exclude it from search results 'show_in_nav_menus' => false,  // you shouldn't be able to add it to menus 'has_archive' => false,  // it shouldn't have archive page

Add a metabox to display options for hide sidebar WordPress

<?php /* ------------------------------------------------------------------------- *  *  Page meta boxes /* ------------------------------------------------------------------------- */ /*  Add a metabox to display options for hide sidebar WordPress /* ------------------------------------ */ if ( ! function_exists( 'samrat_add_page_options_box' ) ) {     function samrat_add_page_options_box() {         add_meta_box( 'samrat_page_options_metabox', __( 'Page Options:', 'samrat' ), 'samrat_page_options_box', 'page', 'side', 'high' );     } } add_action( 'admin_menu', 'samrat_add_page_options_box' ); /*  Metabox output /* ------------------------------------ */ if ( ! function_exists( 'samrat_page_options_box' ) ) {     function samrat_page_options_box() {         global $post;         // Get some info         $hide_sidebar = get_post_meta( $post->ID, 'samrat_page_hide_sidebar', true );   

Ajax in Wordpress

Ajax in Wordpress <script type="text/javascript">  jQuery.ajax({             type: "POST",             url: "<?php echo admin_url('admin-ajax.php'); ?>",             data: { action: 'my_ajax_call' , id: "id" },             async: false,           }).done(function( msg ) {                alert(msg);          }); </script> Add this code in function.php add_action('wp_ajax_my_ajax_call', 'my_ajax_call'); add_action('wp_ajax_nopriv_my_ajax_call', 'my_ajax_call'); function my_ajax_call() { echo $_POST['param']; exit; }

Contact Form7 Google reCAPTCHA v3 Validation

Add below code in Form [hidden g-recaptcha-response id:g-recaptcha-response] Add below Code in function File add_filter( 'wpcf7_validate_text*', 'custom_text_validation_filter', 20, 2 ); function custom_text_validation_filter( $result, $tag ) {     if ( 'g-recaptcha-response' == $tag->name ) {          $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=Secret-key&response=".$_POST['g-recaptcha-response']);    $result = json_decode($response);    if($result->success == 1 && $result->score > 0.7){     }else{        $result->invalidate($tag, "You are a robot" );    }     }     return $result; }

Contact form 7 custom validation hook In Wordpress

add_filter( 'wpcf7_validate_email', 'customemailvalidation', 10, 2 ); function customemailvalidation( $result, $tag ) { $type = $tag['type'];  $name = $tag['name'];  if($type == 'email' && $_POST[$name] != '') {       if(substr($_POST[$name], 0, 1) == '.' ||    !preg_match('/^[A-Za-z0-9.]+@(?:[A-Za-z0-9-]+\.){1,2}[A-Za-z]{1,}+$/', $_POST[$name])) {          $result->invalidate( $name, wpcf7_get_message($name) );   }     }  if($type == 'text*' && $_POST[$name] != ''){    if(!preg_match('/^[A-Za-z.]+$/', $_POST[$name])){   $result->invalidate( $name, wpcf7_get_message( $name ) );     }  }  return $result; } add_filter( 'wpcf7_validate_text*', 'custom_name_validation', 10, 2 ); function custom_name_validation( $result, $tag ) { $type = $tag['type'];  $name = $tag['name'];  if($type == 'text*' && $_POST[$name