Skip to main content

Posts

Showing posts from February, 2020

How to fetch data (messages) in every second with ajax (setinterval) from mysql (PHP) in wordpress?

Fetch data (messages) in every second with ajax (setinterval) from mysql (PHP) in wordpress. In main file <script> jQuery(document).ready(function($){ var own_id = $("#own_id").val(); var user_id = $("#user_id").val(); alert('helo'); function sandeep(){ var data = { 'action':'fetch_message', 'own_id':own_id, 'user_id':user_id, } $.post(myajax.ajaxurl,data,function(response){ //$("#response").html(response); $("#jassi").html(response); console.log(response); }); } setInterval(function(){ sandeep(); }, 500); }); </script> <div id="jassi"> </div> In Funtion.php file  function fetch_message(){ $msg_content = $_POST['msg_content']; $own_id = $_POST['own_id']; $user_id = $_POST['user_id']; echo $user_id; global

How to shrink navbar on scroll ?

Shrink navbar on scroll  <style> .nav_logo_scroll{ width: 120px !important;     transition: all 0.5s linear; margin-left: 45px } .jassi{ width: 100% !important;   transition: all 0.5s linear; } </style> <script> jQuery(document).ready(function($){ $(window).scroll(function() { if($(document).scrollTop() >=1) { $('.nav').css('position','fixed'); $('.nav_logo').addClass('nav_logo_scroll'); $('.nav_logo').css(' transition','all 0.5s linear'); $('.nav_logo').removeClass('jassi'); } else if($(document).scrollTop() < 250) { {  $('.nav').css('position','relative'); $('.nav').css(' transition','all 0.5s linear'); $('.nav_logo').removeClass('nav_logo_scroll'); $('.nav_logo').addClass('jassi'); } } }); }); </script>

How to Alternative to “header” for re-directs in PHP

Alternative to “header” for re-directs in PHP function redirect($url) {     if (!headers_sent())     {            header('Location: '.$url);         exit;         }     else         {          echo '<script type="text/javascript">';         echo 'window.location.href="'.$url.'";';         echo '</script>';         echo '<noscript>';         echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';         echo '</noscript>'; exit;     } }

How to detect the current user has an active subscription in woocommerce?

Detect the current user has an active subscription in Woocommerce. function has_active_subscription( $user_id=null ) {     // When a $user_id is not specified, get the current user Id     if( null == $user_id && is_user_logged_in() )         $user_id = get_current_user_id();     // User not logged in we return false     if( $user_id == 0 )         return false;     // Get all active subscriptions for a user ID     $active_subscriptions = get_posts( array(         'numberposts' => 1, // Only one is enough         'meta_key'    => '_customer_user',         'meta_value'  => $user_id,         'post_type'   => 'shop_subscription', // Subscription post type         'post_status' => 'wc-active', // Active subscription         'fields'      => 'ids', // return only IDs (instead of complete post objects)     ) );     return sizeof($active_subscriptions) == 0 ? false

How to use ob_start() function in php?

PHP | ob_start() Function PHP is an interpreted language thus each statement is executed one after another, therefore PHP tends to send HTML to browsers in chunks thus reducing performance. Using output buffering the generated HTML gets stored in a buffer or a string variable and is sent to the buffer to render after the execution of the last statement in the PHP script. But Output Buffering is not enabled by default. In order to enable the Output Buffering one must use the ob_start() function before any echoing any HTML content in a script. function jassi { ob_start(); echo "Hello there!"; $output = ob_get_contents(); ob_end_clean(); } OR function jassi { ob_start(); echo "Hello there!"; $obc = ob_get_contents(); ob_end_clean(); return $obc; }