Pages

Sep 10, 2019

Append custom class to body element in wordpress



Have you ever wondered how to add custom class to body in any wordpress plugin or page.
Place the below code to update/add new class with any conditions.


add_filter('body_class','append_body_class');
function append_body_class( $classes ) {

    if (is_singular('post')) {
 
    $classes[] =  'news-single';
 
}

 
  return $classes;
}

Fix to increase google page speed (google insight)



If you are stuck in finding a stable solution to score high in google insight pagespeed then there is a simple solution.
Open your function file and add these code :

<?php function motyw_botfix() { ?>

 //Include header scripts and external scripts
//Any kind of scripts that is impossible to break.

<?php }

if (!isset($_SERVER['HTTP_USER_AGENT']) || stripos($_SERVER['HTTP_USER_AGENT'], 'Chrome-Lighthouse') === false) {
add_action('wp_head','motyw_botfix');
}

Aug 29, 2019

Simple method to remotely transfer any files(mdia,zip etc) from one host to another host



Simple method to remotely transfer any files(mdia,zip etc) from one host to another host

<?php
define('BUFSIZ', 4095);
$url = 'http://www.xyz.me/test.zip';
$rfile = fopen($url, 'r');
$lfile = fopen(basename($url), 'w');
while(!feof($rfile))
fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);
fclose($rfile);
fclose($lfile);
?>

Step 1: First you need to create a file by any name remote_upload.php your files to be uploaded.
Step 2: Add the above code and replace urls with your actual url to be remotely upload.
Step 3 : Now , run the file remote_upload.php and your requested files will be automatically tranfered in a fraction of second.

Jun 5, 2019

Disable " terms and conditions" toggle and force it to open in a new tab in a checkout page


Disable " terms and conditions"  toggle and force it to open in a new tab in a checkout page
 
WC 3.4.0 +
Use the following remove_action and WC will default back to opening a tab with the terms and conditions page.
add_action( 'wp', 'my_project_wc_change_hooks' );
function my_project_wc_change_hooks() {
  remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_checkout_privacy_policy_text', 20 );
  remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 );
}

Apr 2, 2019

Wordpress Change Password for a logged in user



This is simple method to update Current/Online user password in through wordpress. Remember to
update the required file with extreme precaution as this could affect the user dramatically and might lead to unseen issues, if not handled properly.
$current_user = wp_get_current_user();
   $user_id = $current_user->ID;  //Current User Id
   $current_pswd =  $_POST['$current_pswd']; //CURRENT PASSWORD

  $new_pswd =   $_POST['$new_pswd'];//NEW PASSWORD
  $confirm_pswd =    $_POST['$confirm_pswd'];//CONFIRM PASSWORD

if(  $confirm_pswd ==  $new_pswd )   {

     if( wp_check_password( $current_pswd, $current_user->data->user_pass, $user_id)){
      $user_data = array(
      'ID' => $user_id,
      'user_pass' => $new_pswd
      );
      wp_update_user($user_data);
      wp_logout();

     $validation = 'SUCCESS';
 
     }else{

     $validation = 'ERROR FAILED';
    }
   }else{
    $validation = 'TOTAL ERROR';

}

echo $validation ;