How to setup W3 total cache with WooCommerce

W3 Cache Plugin configuration for work with Woocommerce

For Improve website performance we use many cache plugins but its disturbed woo-commerce functionality some time.

Like W3 Cache Plugin stop product page gallery page images slider or checkout page functions for fix these issue we should nee d to configure W3 properly .Following things need to configure.

1 – You must add _wc_session_ to the “Ignored Query Strings” option in W3TC settings.

WP-admin go to Performance > Database Cache and add _wc_session_ to the Ignored query stems: Textarea box

2 – Add mfunc to the list of Ignored Comment Stems:

According wootheme guidelines for WooCommerce Cache Ensure you add ‘mfunc’ to the ‘Ignored comment stems’ option in the Minify settings.

Go to Performance > Minify, add mfunc to the list of Ignored comment stems:

3 – Exclude WooCommerce specific pages from the W3 Total cache

To exclude following WooCommerce pages from Cache

Add cart, checkout, shop, /shop* etc in Performance > Page Cache – Never cache the following pages text-area box.

Contact Form 7 Special Mail Tags

There may be times when you need more information than just the submitter’s input through contact form fields. For example, you may need to know the submitter’s IP address for security reasons. For such purposes, special mail-tags can be very helpful.

Unlike other mail-tags, special mail-tags are independent from form fields or the submitter’s input. You can place these special mail-tags anywhere mail-tags are allowed to be used, such as in the message body or other mail fields.

Special Mail Tags for Submissions

1
[_remote_ip]

 — This tag is replaced by the submitter’s IP address.

1
[_user_agent]

 — This tag is replaced by the submitter’s user agent (browser) information.

1
[_url]

 — This tag is replaced by the URL of the page in which the contact form is placed.

1
[_date]

 — This tag is replaced by the date of the submission.

1
[_time]

 — This tag is replaced by the time of the submission.

1
[_invalid_fields]

 — This tag is replaced by the number of form fields with invalid input.

1
[_serial_number]

 — This tag is replaced by a numeric string whose value increments, so this tag can work as the serial number of each submission.

How to increase wp memory limit and PHP Max Input Vars in wordpress

Increasing memory allocated to PHP:

 

Just add this line into wp-config.php file:

1
define( 'WP_MEMORY_LIMIT', '64M' );

Add this code into htaccess file:

1
php_value memory_limit 128M

max_input_vars

The most common issue stems from the

1
max_input_vars

PHP directive, which was introduced in PHP 5.3.9. By default, max_input_vars is set to 1000, which can easily be reached with the WordPress menu system, since each menu item sends about 12 variables per item.

Solution

The solution is to simply configure the

1
max_input_vars

so that it is large enough to handle the number of variables being sent by WordPress to save your menu.

php.ini

If you have access to your

1
php.ini

, you can just add this directive (or change the value of the existing directive) to includes your max input variables:

1
max_input_vars = 3000;

If you don’t have access to this file (as with many shared hosts), you may need to contact your host to increase this limit.

.htaccess

Alternatively, you can try placing this in your

1
.htaccess

. This won’t work on some servers, so your mileage may vary.

1
php_value max_input_vars 3000

A Simple Way to Protect Images from ‘Casual Copying’

If you don’t want other people to download images from your website, don’t put them online because – the way the web works – it is almost impossible to prevent someone from copying or saving your images.

However there’s one little trick that may discourage the less-technical people from casually copying, or even hot-linking, to your web images. To give you an example, try saving the following image to your computer using the standard “save as” option.

The “save picture” option under right-click is still available for the above image but instead of downloading the actual photograph, all it would save is a blank image. Also, the URL for the image (under Properties) would appear as some junk characters (it’s called a data URI) and thus would deter the non-techies from hotlinking to that image.
Here’s how you may implement something similar for your own images:
The standard embed code for an image looks something like this:

1
<img src="photograph.jpg" alt="" width="500" height="250" />

What you need to do is change the value of the src attribute to point to a blank image and then add a new style attribute to render the actual image. Also make sure that the value of the height and the width parameters are exactly the same as the actual image.

1
<img style="background-image: url('photograph.jpg');" src="data:image/gif;base64, R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="" width="500" height="250" />

This is like overlaying a completely transparent screen over your photograph and anyone trying to save the image will end up downloading that screen instead of the image.

Obviously, there are simple workarounds to get around the above method. For instance, a copy of the full image will still be available in your browser’s cache. You may look at the HTML source or may even save the image using screen capture but again, these techniques may not always be known to the non-technical users of your website.

How to Reduce and clean the options table of wp session entries

Every visitor will have a temporary session stored on the options table. The session tokens are very small, it is a server side cookie store. The sessions automatically purge after 30 minutes of inactivity.

But when its not not purge automatically then it create a problem and your database size increase too much that effected your site speed.

So we should need to delete these entries manually or create a plugin for that i will show you how can be delete these through phpmyadmin command or by a plugin.

By Mysql command:

1
2
3
DELETE
FROM `wp_options`
WHERE option_name LIKE '_wp_session%'

You should create a plugin that will schedule an event that occurs daily:

1
2
register_activation_hook(__FILE__, 'my_activation');
add_action('my_daily_event', 'do_this_daily');

function my_activation() {
wp_schedule_event(time(), ‘daily’, ‘my_daily_event’);
}

function do_this_daily() {
$wpdb->query(
“DELETE FROM $wpdb->options
WHERE option_name LIKE ‘_wp_session%’

)
}

How to purge wordpress option table

Sometimes the options table can get really big when it comes to WordPress. This could be related to poorly written WP plugins or either tons of

1
_transient

entries left in the database, for what I blame WordPress. Transient entries are usually created to simply store cached information. In many cases this is completely fine, but they could also be abused by hackers who can insert injections to your WP site and in this case size of options table can get really huge and your blog may start performing slow.

If you don’t know if this particular issues is related to your site, I recommend you typing the following URL in your browser’s address bar:

1
yourwpblog.com/wp-admin/options.php

. Please make sure you are logged in as an admin user.

If you see many entries like those shown below you must know this is complete junk and you can safely get ride of it.

Screenshot

How to Remove Unnecessarily _transient Entries?

1. Login to phpMyAdmin.
2. Navigate to database of your WP blog and click on SQL tab, appearing on the top.
3. Run the following qeury:

 

1
DELETE FROM `wp_options` WHERE `option_name` LIKE ('_transient_%');

4. Transient entries are now removed and the size of your wp_options table should be now reduced.

How to Disable Update Notifications in WordPress

For all the WordPress users, it is really annoying when WordPress update notice is displayed on the dashboard if there are any upgrade available for the installed WordPress version as shown in the figure below. The notice will not clear until the WordPress is upgraded to latest version. Similarly the update notice for installed plugins & themes is displayed on the WordPress dashboard, plugins & themes pages. Actually it is good to know that updates are available but administrators who maintain multiple installations of WordPress on behalf of other people (eg. clients) may not want theme update notifications to be shown to the users of these installations, then disabling such notifications becomes necessary. In this article, I will show how to disable update notifications for core WordPress as well as for plugins and themes.

This scenario is also very important in case of WordPress Multisite (Network) installation where Super Admin can disable the notifications for individual site’s administrators as well.

 

Disable Update WordPress nags with Plugin’s and Theme’s Update Notifications :

1. To Disable Update WordPress nag :

1
2
3
4
5
6
7
8
add_action('after_setup_theme','remove_core_updates');
function remove_core_updates()
{
if(! current_user_can('update_core')){return;}
add_action('init', create_function('$a',"remove_action( 'init', 'wp_version_check' );"),2);
add_filter('pre_option_update_core','__return_null');
add_filter('pre_site_transient_update_core','__return_null');
}

2. To Disable Plugin Update Notifications :

Insert the following code to the functions.php file of your active theme. It will remove the update notifications of all the installed plugins.

1
2
remove_action('load-update-core.php','wp_update_plugins');
add_filter('pre_site_transient_update_plugins','__return_null');

3. To Disable all the Nags & Notifications :

Insert the following code the functions.php file of your active theme. This code disables all the updates notifications regarding plugins, themes & WordPress completely.

1
2
3
4
5
6
function remove_core_updates(){
global $wp_version;return(object) array('last_checked'=&gt; time(),'version_checked'=&gt; $wp_version,);
}
add_filter('pre_site_transient_update_core','remove_core_updates');
add_filter('pre_site_transient_update_plugins','remove_core_updates');
add_filter('pre_site_transient_update_themes','remove_core_updates');

Apart form these codes there are some WordPress plugins available to Disable WordPress Update Notifications & Nags :

If you install & activate these plugins, you will have to keep yourself updated with the latest version of your active WordPress, plugins & themes so that your blog or website wont be susceptible to security vulnerabilities or performance issues. Just deactivate the plugin for short period of time & update yourself.

WordPress plugins to Disable Update WordPress nags with Plugin’s and Theme’s Update Notifications :

I hope with the help of this article you will surely be able to Disable Update WordPress nags with Plugin’s and Theme’s Update Notifications appearing on your WordPress dashboard. If you have any query or suggestion regarding the same, do share with us.

How To Create A WordPress Widget Plugin

In this tutorial, I’m going to explain you how to create your own widgets within a small plugin. This post will cover some extra points that you need to understand before creating the widget itself.

Step 1: How to create a plugin

First step is the creation of the plugin. And as you’ll see, it’s the not the hardest part. A plugin is extra code added to WordPress once you activate it. WordPress creates a loop through a folder to retrieve all available plugins and list them in the back office. To create your plugin, you’ll need an editor such as Dreamweaver (PC & Mac). I recommend you to create your plugin in a local install of WordPress, making it on a live server can cause some troubles if you make an error. So please, wait to test our plugin before placing on it your hosting.

Open now the folder wp-content/plugins. This where you are going to add your plugin. Create a new directory and call it “widget-plugin” (actually, this name can be whatever you want). Even if our plugin will only have one single file, it’s always better to use a folder for each plugin. In your directory, create a new file called “widget-plugin.php” (this name can be changed too), and open it. We are now about to add our first lines of code. The definition of a plugin under WordPress follows some rules that you can read here on the codex. Here is how WordPress defines a plugin:

1
2
3
4
5
6
7
8
9
10
11
<?php
/*
Plugin Name: Widget Plugin
Plugin URI: http://www.wpexplorer.com/
Description: A simple plugin that adds a simple widget
Version: 1.0
Author: WPExplorer
Author URI: http://www.wpexplorer.com/
License: GPL2
*/
?>

Save your file. By only adding code to our widget-plugin.php file we have created a plugin! Well, for now the plugin doesn’t do anything, but WordPress recognizes it. To make sure it’s the case, go your administration, and go under “Plugins” menu. If your plugin appears in the plugins list you’re good, otherwise make sure you followed my instructions and try again. You can now activate the plugin.

Step 2: Create the Widget

We are now going to create the widget itself. This widget will be a PHP class extending the core WordPress class WP_Widget. Basically, our widget will be defined this way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class wp_my_plugin extends WP_Widget {

    // constructor
    function wp_my_plugin() {
        /* ... */
    }

    // widget form creation
    function form($instance) { 
    /* ... */
    }

    // widget update
    function update($new_instance, $old_instance) {
        /* ... */
    }

    // widget display
    function widget($args, $instance) {
        /* ... */
    }
}

// register widget
add_action('widgets_init', create_function('', 'return register_widget("wp_my_plugin");'));

This code gives WordPress all the information the system needs to be able to use the widget:

    The constructor, to initiate the widget
    The form() function to create the widget form in the administration
    The update() function, to save widget data during edition
    And the widget() function to display the widget content on the front-end

1 – The constructor

The constructor is the part of code that defines the widget name, so we’ll only add one line of code to it, to make it look like this:

1
2
3
4
// constructor
    function wp_my_plugin() {
        parent::WP_Widget(false, $name = __('My Widget', 'wp_widget_plugin') );
    }

Please not the use of __(). This function is use by WordPress for translation. I really recommend you to always use these functions, to make your theme fully translatable.

2 – The form() function

This function is the one that creates the widget in the WordPress administration, this is were you’ll enter your data to be displayed on the the website. For now I’m just going to explain you ho to add text fields and text areas. We’ll see check-box, drop-down select and other methods in a next post. Here is what form’) must contain:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// widget form creation
function form($instance) {

// Check values
if( $instance) {
     $title = esc_attr($instance['title']);
     $text = esc_attr($instance['text']);
     $textarea = esc_textarea($instance['textarea']);
} else {
     $title = '';
     $text = '';
     $textarea = '';
}
?>

<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Text:', 'wp_widget_plugin'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>" type="text" value="<?php echo $text; ?>" />
</p>

<p>
<label for="<?php echo $this->get_field_id('textarea'); ?>"><?php _e('Textarea:', 'wp_widget_plugin'); ?></label>
<textarea class="widefat" id="<?php echo $this->get_field_id('textarea'); ?>" name="<?php echo $this->get_field_name('textarea'); ?>"><?php echo $textarea; ?></textarea>
</p>
<?php
}

This code is simply adding 3 fields to the widget. The first one is the widget title, the second a text field, and the last one is a textarea. Let’s see now how to save and update each field value with the update() function.

3 – The update() function

The update() function is really simple. As WordPress core developers added a really powerful widgets API, we only need to add this code to update each field:

1
2
3
4
5
6
7
8
9
// update widget
function update($new_instance, $old_instance) {
      $instance = $old_instance;
      // Fields
      $instance['title'] = strip_tags($new_instance['title']);
      $instance['text'] = strip_tags($new_instance['text']);
      $instance['textarea'] = strip_tags($new_instance['textarea']);
     return $instance;
}

And tada! the magic appears! You don’t need more code to save values, isn’t it awesome?

4 – The widget() function

The widget() function is the one that will output the content on the website. It’s what your visitors will see. This function can be customized to include CSS classes, and specific tags to match perfectly your theme display. Here is the code (please not that this code can be modified easily to fit your needs):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// display widget
function widget($args, $instance) {
   extract( $args );
   // these are the widget options
   $title = apply_filters('widget_title', $instance['title']);
   $text = $instance['text'];
   $textarea = $instance['textarea'];
   echo $before_widget;
   // Display the widget
   echo '<div class="widget-text wp_widget_plugin_box">';

   // Check if title is set
   if ( $title ) {
      echo $before_title . $title . $after_title;
   }

   // Check if text is set
   if( $text ) {
      echo '<p class="wp_widget_plugin_text">'.$text.'</p>';
   }
   // Check if textarea is set
   if( $textarea ) {
     echo '<p class="wp_widget_plugin_textarea">'.$textarea.'</p>';
   }
   echo '</div>';
   echo $after_widget;
}

This code isn’t complex, all you have to remember is to to check if a variable is set, if you don’t and if you want to print it, you’ll get an error message.

How to disable wordpress Automatic Background Updates

Automatic background updates were introduced in WordPress 3.7 in an effort to promote better security, and to streamline the update experience overall. By default, only minor releases – such as for maintenance and security purposes – and translation file updates are enabled on most sites. In special cases, plugins and themes may be updated.

In WordPress, there are four types of automatic background updates:

Core updates
Plugin updates
Theme updates
Translation file updates

Automatic updates can be configured using one of methods: defining constants in wp-config.php

Constant to Disable All Updates

1
define( 'AUTOMATIC_UPDATER_DISABLED', true );

Constant to Configure Core Updates

1
define( 'WP_AUTO_UPDATE_CORE', false );

WP_AUTO_UPDATE_CORE can be defined with one of three values, each producing a different behavior:

Value of true – Development, minor, and major updates are all enabled
Value of false – Development, minor, and major updates are all disabled
Value of ‘minor’ – Minor updates are enabled, development, and major updates are disabled

To enable automatic updates for all plugins, use the following:

1
add_filter( 'auto_update_plugin', '__return_true' );

To enable automatic updates for all themes, use the following:

1
add_filter( 'auto_update_theme', '__return_true' );

To disable automatic updates for all plugins including security team updates, use the following:

1
add_filter( 'auto_update_plugin', '__return_false' );

To disable automatic updates for all themes including security team updates, use the following:

1
add_filter( 'auto_update_theme', '__return_false' );

How to Disable or Enable All WordPress Plugins and Theme via the Database

This article explains how to deactivate, change or delete themes and plugins on a WordPress site without the dashboard. This may be helpful if you have a plugin or theme that has malfunctioned and caused you to lose access to the dashboard.

Deactivating a Plugin

These steps explain how to deactive plugins on a WordPress site without the dashboard.

Note: This will deactivate all plugins, however it does not remove the plugin, or its settings.

First open phpMyAdmin for access your database.

Clearing Active Plugins

1. In phpMyAdmin find your WordPress database in the list of databases.

2.In the list of tables click on the table name that ends with “options”.

3.In the options table click on the column heading “option_name” to sort the table rows by name. This should make active_plugins the first table row.

4.Click the edit link on the active_plugins row.

5.Clear out all text in the option_value box.

6.Click the “Go” button at the bottom.

You should get a page indicating that the query was executed. You are finished, all plugins should now be disabled in WordPress.

Alternately, here is a one-second query to disable all plugins:

1
UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins';

Changing the WordPress Theme

These instructions will explain how to change the theme setting in WordPress without the WordPress dashboard.

1. In phpMyAdmin find your WordPress database in the list of databases. In this case our example database is examplec_wo5647.

2.In the list of tables click on the table name that ends with “options”.

3.In the options table locate the rows for template and stylesheet. They are usually on the second page and their option_id will be around 40.

4.Click edit to change both the theme and stylesheet’s option_value to the theme you wish to use. This should be the exact, case sensitve name of the folder inside wp-content/themes that contains the theme you want to use.

5.Click the “Go” button.

The theme should now be set to your chosen theme.