Skip to main content

Posts

Showing posts from 2018

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,

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

WordPress Custom Login Validation

function check_checkbox($user, $password) { $user_id = $user->ID;   $key = 'code';   $single = true;   $code = get_user_meta( $user_id, $key, $single );   if($invcode != "")   {     global $wpdb; $sql = "SELECT * FROM table where `code` = '$code' and status = '0';"; $pageposts = $wpdb->get_row($sql); if(!empty($pageposts)) {         remove_action('authenticate', 'wp_authenticate_username_password', 20);         $user = new WP_Error( 'denied', __("<strong>ERROR</strong>: Your license has expired.  Please contact us for help.$user_last") );     return $user;         }       }                     return $user; } add_filter( 'wp_authenticate_user', 'check_checkbox', 10, 3 );

Create Google reCAPTCHA v3 in PHP

<?php if(isset($_POST)){     //https://www.google.com/recaptcha/api/siteverify?secret=Secret_key&response=".$_POST['g-recaptcha-response']     $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=Secret-key&response=".$_POST['g-recaptcha-response']);    $result = json_decode($response);    print_r($result);    if($result->success == 1 && $result->score > 0.8){        echo "captch valid.";         }else{        echo "captch is not valid.";    } } ?> <form action="" method="post"> <input type="text" name="fname"> <input type="text" name="g-recaptcha-response" id="g-recaptcha-response"> <input type="submit"> </form> <script src='https://www.google.com/recaptcha/api.js?render=Site-key'></script> <script> grecaptcha.ready(function() { grecaptc

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_product', $cart_item['data'], $cart_item, $cart_item_key );                 $product_id   = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );                 if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_c

Create custom menu in wordpress

<?php //add in function file function wpb_custom_new_menu() {   register_nav_menus(     array(       'my-custom-menu' => __( 'My Custom Menu' ),     )   ); } add_action( 'init', 'wpb_custom_new_menu' ); $menu_name = 'my-custom-menu'; $locations = get_nav_menu_locations(); $menu = wp_get_nav_menu_object( $locations[ $menu_name ] ); $menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) ); ?> <nav> <ul class="main-nav">     <?php     $count = 0;     $submenu = false;     foreach( $menuitems as $item ):         // set up title and url         $title = $item->title;         $link = $item->url;         // item does not have a parent so menu_item_parent equals 0 (false)         if ( !$item->menu_item_parent ):         // save this id for later comparison with sub-menu items         $parent_id = $item->ID;     ?>          <li class="item">    

Mail send in Mailgun by using CURL

send_mail($emailadderss,$subject1,$message1); function send_mail($email,$subject,$msg) {   $api_key="";  $domain ="test.com";  /*  $ch = curl_init();  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);  curl_setopt($ch, CURLOPT_USERPWD, 'api:'.$api_key);  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');  curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/'.$domain.'/messages');  curl_setopt($ch, CURLOPT_POSTFIELDS, array(   'from' => 'test <test@test.com>',   'to' => $email,   'subject' => $subject,   'html' => $msg  ));  $result = curl_exec($ch);  curl_close($ch);  print_r($result);  */  $curl_post_data=array( 'from' => 'test <test@test.com>',     'to' => $email,     'subject' => $subject,     'html' => $msg ); $service_url = '

Crurl in php in live server

global $product; $current_user = wp_get_current_user(); $useriid = $current_user->data->ID; $meta = get_user_meta( $useriid ); if($bpid == ""){ $productid = implode('-',$spid); $pdfcode = $spid[0]; }else{ $productid = $bpid; $pdfcode = $bpid; } $text = "demo".$order_id."-".$pdfcode."-1"; $url ='http://www.demo.in/wp-content/themes/wisdomstore/dompdf/barcode.php'; $fields = array( 'text'  => $text, ); //open connection $server = '103.195.184.60'; $host   = 'thewisdomstore.in'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $server); /* set the user agent - might help, doesn't hurt */ curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); /* try to follow redirects */ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); /* timeout after the specified number of seconds. as

Create admin settings in wp

<?php /* Plugin Name: Demo SMS Plugin URI: http://myasa.net Description: This plugin will integrate Demo SMS API Author: Sheikh Aamir Wahid Version: 1.0 Author URI: https://github.com/aamirwahid5 */ ob_start(); //include "functions.php"; add_action('admin_menu', function() {     add_options_page( 'SMS Settings', 'Demo SMS', 'manage_options', 'mobi-sms-plugin', 'mobiSMS_plugin_page' ); }); add_action( 'woocommerce_order_status_pending', 'mysite_pending', 10, 1); add_action( 'woocommerce_order_status_failed', 'mysite_failed', 10, 1); add_action( 'woocommerce_order_status_on-hold', 'mysite_hold', 10, 1); // Note that it's woocommerce_order_status_on-hold, and NOT on_hold. add_action( 'woocommerce_order_status_processing', 'mysite_processing', 10, 1); add_action( 'woocommerce_order_status_completed', 'mysite_completed', 10, 1);

Create post with all post type

<?php /* add_action( 'wp_enqueue_scripts', 'mpcth_child_enqueue_scripts', 1000 ); function mpcth_child_enqueue_scripts() { wp_enqueue_style( 'mpc-styles-child', get_stylesheet_directory_uri() . '/style_custom.css' ); } */ function registration_form( $username, $fname, $lname, $email, $password, $confirm_password, $account_type, $distict_city, $school_name ,$school_address, $school_type, $grade_level, $invcode ) { ?>     <style>       /* Always set the map height explicitly to define the size of the div        * element that contains the map. */     #map {     height: 260px; }     </style>   <script> function initMap() {     var map = new google.maps.Map(document.getElementById('map'), {       center: {lat: -33.8688, lng: 151.2195},       zoom: 13     });     var input = document.getElementById('searchInput');    // map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);