Category: PHP

Difference between CHAR and VARCHAR?

Following are the differences between CHAR and VARCHAR:

  • CHAR and VARCHAR types differ in storage and retrieval
  • CHAR column length is fixed to the length that is declared while creating table. The length value ranges from 1 and 255
  • When CHAR values are stored then they are right padded using spaces to specific length. Trailing spaces are removed when CHAR values are retrieved.

How to disable comments in WordPress?

To disable comments in WordPress, Please follow below steps

Step 1: Login to your WordPress admin panel.
Step 2: Go to the Settings menu.
Step 3: Under Settings menu click on Discussion.
Step 4: Uncheck Allow people to post comments on new articles. checkbox
Step 5: Click on save changes button, you done

What is usermeta function in WordPress?

The usermeta function is used to retrieve the metadata of users. It can return a single value or an array of metadata.

Syntax is: get_user_meta( int $user_id, string $key = ”, bool $single = false )

User id is the required user id parameter

Key is the optional parameter which is the meta key to retrieve. By default, it returns data for all key values.

Single is an optional parameter that tells whether the single value will return. By default, it is false.

How to register new order status in WooCommerce

In this article, I will show you how to add/register new order status in the WooCommerce. Here is an example to add Manufacture status in to the WooCommerce order status. Add this to your theme’s functions.php

function register_manufacture_order_status() {
    register_post_status( 'wc-manufacture', array(
        'label'                     => 'Manufacture',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Manufacture (%s)', 'Manufacture (%s)' )
    ) );
}
add_action( 'init', 'register_manufacture_order_status' );

// Add to list of WC Order statuses
function add_manufacture_to_order_statuses( $order_statuses ) {

    $new_order_statuses = array();

    // add new order status after processing
    foreach ( $order_statuses as $key => $status ) {

        $new_order_statuses[ $key ] = $status;
        $new_order_statuses['wc-manufacture'] = 'Manufacture';
    }

    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_manufacture_to_order_statuses' );

You can change wc-manufacture and Manufacture into your custom status to register new order status in WooCommerce.

Have any doubt, then comment here!

How to enable GZIP COMPRESSION in WordPress using htaccess?

To enable GZIP COMPRESSION in WordPress using htaccess. Add the following code in your htaccess file located in WordPress root folder.

# BEGIN GZIP COMPRESSION
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
	 AddOutputFilterByType DEFLATE application/atom+xml
	 AddOutputFilterByType DEFLATE application/javascript
	 AddOutputFilterByType DEFLATE application/json
	 AddOutputFilterByType DEFLATE application/ld+json
	 AddOutputFilterByType DEFLATE application/manifest+json
	 AddOutputFilterByType DEFLATE application/rdf+xml
	 AddOutputFilterByType DEFLATE application/rss+xml
	 AddOutputFilterByType DEFLATE application/schema+json
	 AddOutputFilterByType DEFLATE application/vnd.geo+json
	 AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
	 AddOutputFilterByType DEFLATE application/x-font
	 AddOutputFilterByType DEFLATE application/x-font-opentype
	 AddOutputFilterByType DEFLATE application/x-font-otf
	 AddOutputFilterByType DEFLATE application/x-font-truetype
	 AddOutputFilterByType DEFLATE application/x-font-ttf
	 AddOutputFilterByType DEFLATE application/x-font-woff
	 AddOutputFilterByType DEFLATE application/x-javascript
	 AddOutputFilterByType DEFLATE application/xhtml+xml
	 AddOutputFilterByType DEFLATE application/xml
	 AddOutputFilterByType DEFLATE font/opentype
	 AddOutputFilterByType DEFLATE font/eot
	 AddOutputFilterByType DEFLATE font/otf
	 AddOutputFilterByType DEFLATE font/ttf
	 AddOutputFilterByType DEFLATE image/bmp
	 AddOutputFilterByType DEFLATE image/svg+xml
	 AddOutputFilterByType DEFLATE image/vnd.microsoft.icon
	 AddOutputFilterByType DEFLATE image/x-icon
	 AddOutputFilterByType DEFLATE text/cache-manifest
	 AddOutputFilterByType DEFLATE text/css
	 AddOutputFilterByType DEFLATE text/html
	 AddOutputFilterByType DEFLATE text/javascript
	 AddOutputFilterByType DEFLATE text/plain
	 AddOutputFilterByType DEFLATE text/vcard
	 AddOutputFilterByType DEFLATE text/vnd.rim.location.xloc
	 AddOutputFilterByType DEFLATE text/vtt
	 AddOutputFilterByType DEFLATE text/x-component
	 AddOutputFilterByType DEFLATE text/x-cross-domain-policy
	 AddOutputFilterByType DEFLATE text/xml
</IfModule>
# END GZIP COMPRESSION

Have any doubt, then comment here!

How to add Expires Headers in WordPress using htaccess?

To add Expires Headers in WordPress using htaccess. Add the following code in your htaccess file located in WordPress root folder.

#BEGIN EXPIRES CACHING 
<IfModule mod_expires.c>
	ExpiresActive On
	ExpiresByType text/css "access 1 month"
	ExpiresByType text/html "access 1 month"
	ExpiresByType image/gif "access 1 year"
	ExpiresByType image/png "access 1 year"
	ExpiresByType image/jpg "access 1 year"
	ExpiresByType image/jpeg "access 1 year"
	ExpiresByType image/jp2 "access 1 year"
	ExpiresByType image/x-icon "access 1 year"
	ExpiresByType image/svg+xml "access plus 1 month"
	ExpiresByType audio/ogg "access plus 1 year"
	ExpiresByType video/mp4 "access plus 1 year"
	ExpiresByType video/ogg "access plus 1 year"
	ExpiresByType video/webm "access plus 1 year"
	ExpiresByType application/atom+xml "access plus 1 hour"
	ExpiresByType application/rss+xml "access plus 1 hour"
	ExpiresByType application/pdf "access 1 month"
	ExpiresByType application/javascript "access 1 month"
	ExpiresByType text/x-javascript "access 1 month"
	ExpiresByType text/x-component "access plus 1 month"
	ExpiresByType application/x-shockwave-flash "access 1 month"
	ExpiresByType font/opentype "access plus 1 year"	
	ExpiresByType font/truetype "access plus 1 year"
	ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
	ExpiresByType application/x-font-ttf "access plus 1 year"
	ExpiresByType application/x-font-opentype "access plus 1 year"
	ExpiresByType application/font-woff "access plus 1 year"
	ExpiresByType application/font-woff2 "access plus 1 year"
	ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
	ExpiresDefault "access plus 1 year"
</IfModule>
#END EXPIRES CACHING

Have any doubt, then comment here!

How to enable ENABLE MOD_PAGESPEED in WordPress using htaccess?

To enable ENABLE MOD_PAGESPEED in WordPress using htaccess. Add the following code in your htaccess file located in WordPress root folder.

# ENABLE MOD_PAGESPEED START
# COMBINE CSS, COMPRESS IMAGES, REMOVE HTML WHITE SPACE AND COMMENTS
<IfModule pagespeed_module>
	ModPagespeed on
	ModPagespeedEnableFilters rewrite_css,combine_css
	ModPagespeedEnableFilters recompress_images
	ModPagespeedEnableFilters convert_png_to_jpeg,convert_jpeg_to_webp
	ModPagespeedEnableFilters collapse_whitespace,remove_comments
</IfModule>
# ENABLE MOD_PAGESPEED END

Have any doubt, then comment here!