Skip to main content

Posts

Handling timezone conversion with PHP DateTime

Handling timezone conversion with PHP DateTime Create function function convert_to_server_datetime($date, $userTimeZone = 'America/Los_Angeles', $serverTimeZone = 'UTC') {     try {         $dateTime = new DateTime ($date, new DateTimeZone($userTimeZone));         $dateTime->setTimezone(new DateTimeZone($serverTimeZone));         return $dateTime->format("Y-m-d H:i:s");     } catch (Exception $e) {         return '';     } } Example: $userDate = '2019-04-19 13:20:00'; echo  convert_to_server_datetime ($userDate); Other Method public function convert($clienttimezone = null, $servertimezone = null){ $clientz=timezone_open("$clienttimezone"); $serverdateTime=date_create("now",timezone_open("$servertimezone")); $offset1 = timezone_offset_get($clientz,$serverdateTime); $servertz=timezone_open("$servertimezone"); $clientdateTime=date_crea...

How to create jQuery fadeIn fadeOut Animation

How to create jQuery fadeIn fadeOut Animation Html: <ul> <li class="client-testimonial"><img src="demo1.png"></li> <li class="client-testimonial"><img src="demo2.png"></li> <li class="client-testimonial"><img src="demo3.png"></li> <li class="client-testimonial"><img src="demo4.png"></li> </ul> jQuery: jQuery(document).ready(function(){ if(jQuery('.client-testimonial').length > 0){ var showImg = jQuery(".client-testimonial-img"); var quoteIndex = -1; function showFadeInFadeOut() { ++quoteIndex; showImg.eq(quoteIndex % showImg.length) .fadeIn(2000) .delay(2000) .fadeOut(2000, showFadeInFadeOut); } showFadeInFadeOut(); } });

How to get custom image size url in Wordpress

Here are simple way to get custom image from URL $imgUrl = 'http://localhost/wptest/wp-content/themes/sydney/images/header.jpg';   global $wpdb; $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $imgUrl )); $image_id = $attachment[0]; $thumbnail_url = wp_get_attachment_image_src($image_id, array('615','440'), true );

How to set varchar primary key field in Mysql

How to set varchar primary key field in Mysql Table structure of Users table CREATE TABLE `users` (    `id` varchar(36) NOT NULL DEFAULT 'InitiallyEmpty',    `first_name` varchar(100) NOT NULL,    `last_name` varchar(100) NULL,    `email` varchar(100) NOT NULL,    `password` varchar(100) NOT NULL,    PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 Want to fill id an automatically filled. You need to create trigger Trigger structure for automatically update DROP trigger if exists before_insert_users; delimiter $$ CREATE TRIGGER before_insert_users BEFORE INSERT ON users FOR EACH ROW BEGIN     SET new.id = uuid(); END $$ delimiter ; Now create insert query insert into users (first_name,last_name,email,password) values ('Sudhir','Pandey','psudhir20@gmail.com','123465');

How to Add Next Previous links to The Event Calendar

Add Next/Previous links to The Event Calendar Wordpress Plugin Add code to your child theme’s functions.php file /**  * Allows visitors to page forward/backwards in any direction within month view */ if ( class_exists( 'Tribe__Events__Main' ) ) { class ContinualMonthViewPagination {     public function __construct() {         add_filter( 'tribe_events_the_next_month_link', array( $this, 'next_month' ) );         add_filter( 'tribe_events_the_previous_month_link', array( $this, 'previous_month' ) );     }     public function next_month() {         $url = tribe_get_next_month_link();         $text = tribe_get_next_month_text();         $date = Tribe__Events__Main::instance()->nextMonth( tribe_get_month_view_date() );         return '<a data-month="' . $date . '" href="' . $url . '" rel="next"...

How to use registered post type Hook

How to use registered_post_type Hook and modify post type registration Create custom post type hook for products inside function.php file add_action( 'init', 'wpyog_register_products_cpt' ); /**  * Register Products Custom Post Type   */ function wpyog_register_products_cpt() {     // change 'wpyog_products' to whatever your text_domain is.          /** Setup labels */     $labels = array(         'name'               => x_( 'Products', 'wpyog_products' ),         'singular_name'      => x_( 'Product', 'wpyog_products' ),         'add_new'            => x_( 'Add New', 'wpyog_products' ),         'all_items'          => x_( 'All Products', 'wpyog_products' ),         'add_new_item'  ...

How to change integer value in number format jQuery

Here are simple way you can change integer value in number format on key up using jQuery Html Code: <input type="text" name="amount" class="required" value=""> jQuery Code: <script> jQuery.noConflict(); jQuery(document).ready( function($){  $(document).on('keyup', 'input.required', function(event){ if($(this).hasClass('field-error')){ $(this).css('border-color', '#83A4C5'); $(this).removeClass('field-error'); }    var selection = window.getSelection().toString(); if ( selection !== '' ) { return; }            // When the arrow keys are pressed, abort it. if ( $.inArray( event.keyCode, [38,40,37,39] ) !== -1 ) { return; }       var $this = $( this );            // Get the value. var input = $this.val();             var input = input.replace(/[\D\s\._\-]+/g, ""); input = input ? pa...

How to implement routing in Nodejs

A route is a mapping from a url to an object.It handles HTTP client requests. Basic Routing Hope you have install and have basic knowledge Express module. npm install express Note: Above command download the required express modules and install them. Here is our Server file. var express = require( 'express' ); var app = express(); //Creating Router() object var router = express.Router(); // Provide all routes here, this is for Home page. router.get("/",function(req,res){   res.json({"message" : "Hello World"}); }); app.use("/",router); // Listen to this Port app.listen(3000,function(){   console.log("Live at Port 3000"); }); Code Explanation: 1. In our first line of code, include the "express module." 2. Create object of the express module. 3. Creating a callback function. This function call when you hit url from browser http://localhost:3000 .It send the string 'Hello World' to ...

How to implement Real time notification in NodeJs

Here are simple steps to create real time notification using NodeJs, Socket.io and Mysql Socket.IO enables real-time bidirectional event-based communication.It has two parts: a client-side library that runs in the browser, and a server-side library for node.js. Install Socket.IO npm install --save socket.io I hope you have install express and mysql. This are basic few code inside server file. var express = require( 'express' ); var app = express(); app.use( express.static( __dirname + '/public') ); var mysql = require('mysql'); var server = require( 'http' ).Server( app ); var io = require( 'socket.io' )( server ); server.listen( 3000, function(){   console.log( 'listening on *:3000' ); } ); app.get('/', function(req, res) {    res.sendFile(__dirname + '/index.html'); }); The require('socket.io')(http) creates a new socket.io instance attached to the http server. Now make mysql conn...

How to Implement CRUD in Node js With MySQL

How to Implement CRUD in Node.js With MySQL In this post, we are going to create a simple CRUD application in Node.js with MySQL as the database. We are using EJS as the template engine. Before get started with this tutorial: You need to have Node installed. Read my previous post for Node.js installation. Step 1: Create index.js as main file and package.json file package.json { "name": "curdnode", "version": "1.0.0", "description": "Create simple curd example in nodejs", "main": "index.js", "scripts": { "start": "node index.js", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "techsudhir", "license": "ISC" } index.js console.log('Welcome You'); Now open up your command line and run : npm start Output: Welcome You Stop the c...

How to Create a jQuery Autocomplete in Wordpress

How to Create a jquery-ui Autocomplete in wordpress. Autocomplete provides suggestions while you type into the text field. In Wordpress we fetch dynamically matched pattern. Include javascript and css files in header. Create action inside functions.php or inside plugin code. add_action('wp_head', 'custom_register_scripts'); function custom_register_scripts(){ wp_register_style( 'techsudhir_jquery_ui_css', plugin_dir_url(__FILE__) . 'css/jquery-ui.css', false,'1.0.0' ); wp_enqueue_style( 'techsudhir_jquery_ui_css' ); wp_register_script('techsudhir_jquery_ui_js',plugin_dir_url(__FILE__) . 'js/jquery-ui.js',array('jquery'),'1.1', false); wp_enqueue_script('techsudhir_jquery_ui_js'); wp_localize_script( 'techsudhir_autocomplete', 'jqueryAutocomplete', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); wp_enqueue_script( 'techsudhir_...

Simple CRUD Example in Cakephp

Simple CRUD Operation in CakePHP 2.x This tutorial will explain about CRUD Operation in CakePHP. Here we will perform mysql Insert, Select, Update, Delete operation in cakePHP Framework. As we know CakePHP uses MVC design patterns. Here we will cover following points: 1. MySQL Database Table Used 2. We are using CakePHP Version 2.x 3. Create/Select/Update/Delete records. We have assume that you have already created you database table. Here is simple users table structure. CREATE TABLE `users` (   `id` bigint(20) UNSIGNED NOT NULL primary key AUTO_INCREMENT,   `firstname` varchar(128) NOT NULL,   `lastname` varchar(128) DEFAULT NULL,   `username` varchar(128) DEFAULT NULL,   `password` varchar(128) DEFAULT NULL,   `email` varchar(128) DEFAULT NULL,   `created` datetime DEFAULT NULL,   `modified` datetime DEFAULT NULL, ) Create action inside Users controller. Controller: app/Controller/UsersController.php Create add functi...