Posts

Showing posts from September, 2023

Woocommerce : Add Body class to product page if the current product is in the cart

 function ywp_check_product_is_in_cart( $product_id ) {     if ( ! WC()->cart->is_empty() ) {         foreach( WC()->cart->get_cart() as $cart_item ) {             $cart_item_ids = array( $cart_item['product_id'], $cart_item['variation_id'] );             if( in_array( $product_id, $cart_item_ids ) ) {                 return true;             }         }         return false;     }     return false; } add_filter( 'body_class', 'ywp_body_class_for_cart_items' ); function ywp_body_class_for_cart_items( $classes ) {     // Check user currently is in product page     if( ! is_singular( 'product' ) ) {         return $classes;     }     if( ywp_check_product_is_in_cart( get_the_id() ) ) {   ...

Understanding the Default WordPress .htaccess File: Functions and Configuration

The default WordPress .htaccess file is a crucial component of a WordPress site's configuration. This post delves into its significance, explaining its functions and how it influences site behavior. From handling permalinks to enhancing security, the .htaccess file plays a pivotal role in customizing site settings. This guide provides a comprehensive overview of the default directives in the WordPress .htaccess file and how they impact website performance. Whether you're a beginner seeking to grasp the basics or an experienced user looking for advanced customization tips, this post covers it all. Dive in to discover the power of the .htaccess file and learn how to leverage it for an optimized and secure WordPress site. # BEGIN WordPress RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress 

Exceeding Maximum Execution Time Error (30s)

 Increase the time limit As a last resort, you could temporarily extend the time limit, using either ini_set('max_execution_time', '300'); //300 seconds = 5 minutes or set_time_limit(300); In php.ini, like this: max_execution_time = 360; Maximum execution time of each script, in seconds (I CHANGED THIS VALUE) max_input_time = 120; Maximum amount of time each script may spend parsing request data ;max_input_nesting_level = 64; Maximum input variable nesting level memory_limit = 128M; Maximum amount of memory a script may consume (128MB by default)

Export commands in MySQL

 Use the mysqldump utility to export the database. The command is used as follows: mysqldump -uUSERNAME -p DB_NAME > exported.sql To export a specific table, you can use the following command: $ mysqldump -u USER_NAME -p DB_NAME table1 table2 > file_name To export multiple databases, you can use the following command: $ mysqldump -u USER_NAME -p ---databases DB_NAME1 DB_Name2 DB_Name3> file_name To prevent a table from being exported, use the following command: $ mysqldump -u USER_NAME -p DB_NAME --ignore-table=DB_NAME.TABLE_NAME > file_name

Setting up Virtual Hosts in XAMPP

Step 1) C:\WINDOWS\system32\drivers\etc\ Open the "hosts" file : 127.0.0.1       localhost 127.0.0.1       nownow.com 127.0.0.1       xpendy.in ::1             localhost Step 2) xampp\apache\conf\extra\httpd-vhosts.conf <VirtualHost *:80>     ServerAdmin admin@nownow.com     DocumentRoot "C:/xamppnew/htdocs"     ServerName nownow.com     ErrorLog "logs/nownow.com.log"     CustomLog "logs/nownow.com-access.log" common </VirtualHost> <VirtualHost *:80>     ServerAdmin admin@xpendy.in     DocumentRoot "C:/xamppnew/htdocs/xpendy"     ServerName xpendy.in     ErrorLog "logs/xpendy.in.log"     CustomLog "logs/xpendy.in-access.log" common </VirtualHost> Step 3) Restart XAMPP and now run :

Got a packet bigger than max_allowed_packet

 Also, change the my.cnf or my.ini file (usually found in /etc/mysql/) or(C:\xampp\mysql\bin\) under the mysqld section and set: max_allowed_packet=100M or you could run these commands in a MySQL console connected to that same server: set global net_buffer_length=1000000;  set global max_allowed_packet=1000000000;

PHP Artisan Tinker toolkit

 Provide us Intractive Shell For application by which we can make Opreations in Application # Craete,Update,Delete, Get and all coding things C:\xamppnew\htdocs\laravel>php artisan tinker Psy Shell v0.11.20 (PHP 8.2.4 — cli) by Justin Hileman > env('SESSION_DRIVER') = "file" > env('DB_CONNECTION') = "mysql" > User::all(): > User::create(['name'=>'test','email' => 'terst@gmail.com','password' => '123456']);

Fibonacci series in PHP

Learn how to print the Fibonacci series in PHP with this step-by-step tutorial. Explore PHP code examples and techniques for Fibonacci series output. Master PHP Fibonacci series printing today! <?php $n1 = 0; $n2 = 1; $limit = 10; echo $n1.' '.$n2.' ';  for($i=0;$i<=$limit;$i++){ $n3 = $n2 + $n1;       echo $n3.' ';       $n1 = $n2;       $n2 = $n3;   } ?> OutPut:- 0 1 1 2 3 5 8 13 21 34 55 89 144  

Increase PHP execution time

 Ways to Change PHP Program Execution Time There are various ways to change the value that is set with the PHP configuration file. These are, 1)Use the PHP function set_time_limit() that accepts the execution time limit in seconds as its argument. $execu_time_limit = 60; set_time_limit($execu_time_limit); 2) Search the php.ini file for a max_execution_time directive and edit its default value as required. If we have access to the php.ini file then we can see the settings related to max_execution_time, like. ; Maximum execution time of each script, in seconds ; http://php.net/max-execution-time ; Note: This directive is hardcoded to 0 for the CLI SAPI max_execution_time = 30 3) Use the ini_set() function in a PHP program by specifying the php.ini file directive name and its corresponding value to be set. ini_set("max_execution_time", 120); 4)Use the php_value command in the .htaccess file to set max_execution_time. We can change the value of the execution time limit with the ....