Just completed my WP 5k 2016 walk :)

Feeling little tired but happy as I have just now completed my WP 5k 2016 walk#WWWP5K ) !! If you aren’t aware of the WP 5k 2016, it’s a 5-kilometer run/walk/hike/hop in between September 19th to September 25th. Wherever you are, whatever you are doing, if you are anyway involved with WordPress, just participate and blog about it.

Today morning I thought about taking part in the Worldwide WP 5k 2016 by walking the distance of 5 Km. Started off from my home and went to the Buddha Park and walked until I cover the WP 5k 2016 🙂 It’s really awesome to get up early and walk around that too for WordPress’s Worldwide WP 5k 2016.

I have been involved with WordPress for more than 5 years now, currently working as a WordPress developer at Axelerant. Love to unite with worldwide bloggers, runners, WP developers !!

Here is the map of my walk !!
subharanjan_wwwp5k

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Selfie afterward:

subharanjan_wwwp5k_after

How to fix 302 redirect issue when updating posts in WordPress? [Solved]

Recently, while writing a blog post I found that I am not able to update/publish any post on my WordPress website dashboard rather it redirects me to the website front page when I click the “Update” button. Now, I was unsure what’s creating this trouble and how to fix this 302 redirect when updating posts in WordPress.

Debug:

To check what could be the issue, I tried the followings :

  • I checked for any javascript errors through chrome dev tool’s console, but no errors there.
  • I deactivated all the plugins
  • Even changed the theme to the default Twenty Sixteen

Root Cause:

Still, the issue was there. After debugging a little more I found the cause of this. It was the strict Mode_Security which was causing the trouble. Now the question is: “What is Mod_Security?”

ModSecurity is an open source, cross-platform web application firewall (WAF) module. Known as the “Swiss Army Knife” of WAFs, it enables web application defenders to gain visibility into HTTP(S) traffic and provides a power rules language and API to implement advanced protections.

Basically, this is an Apache module that is installed on most servers by default to help protect your website from various attacks. It is used to block commonly known exploits by use of regular expressions and rule sets. This sometimes blocks the POST requests being generated after a post is updated or published because of the complex HTML content having all the tags, embed code, shortcodes etc. which get caught by the ModSecurity’s rule set.

cPanel-Mod-Security-Subharanjan

Solution:

To fix this issue simply disable the module on your server. This can be achieved through the Modsec Manager plugin for cPanel if you are on a shared server. Read the following to know how to disable manually on VPS and Dedicated servers. http://www.inmotionhosting.com/support/website/modsecurity/what-is-modsecurity-and-why-is-it-important

I am sure there are a ton of other reasons for a 302 redirect issue but in my case, this was Mod_Security causing the problem and after disabling the module I am able to update and publish the posts. 🙂

Like Ultimate Member, But do not need WooCommerce. Want to use EDD for Ultimate Member


Integrates the popular e-commerce plugin Easy Digital Downloads with Ultimate Member.

 

Key Features View

  • Easily integrates users purchases tab in user profile
  • You can display and view user orders from account page
  • Now manage billing address from account page
  • You allow user to have a specific role if they purchase a specific product
  • You allow user to have a specific role if they purchase any product
  • You can give options to disable any of the profile or account tabs based on role

 

How to create Social Job Portal like Linkedin using WordPress ? [Solved]

You need a site like Linkedin?

BuddyPress Job Manager

BuddyPress Job Manager

Well there you can find a lot of Job Sites, But why Linkedin is different ? Because It is Social.

In WordPress, creating a job board is much cheaper and easier to get up and running. Here is one of the most popular plugin “WP Job Manager“. But It lacks social features. Well in WordPress there is another popular plugin called “BuddyPress“. It is used creating Social Networking Sites. If We are connecting both plugin then we are done.

 

How to Connect!! Thank god there is a plugin in WordPress for It. It is BuddyPress Job Manager. It’s free too 🙂

It is very simple to use. It follows normal installation.

This very simple like other wordpress plugin:

1. Upload the plugin to the /wp-content/plugins/ directory
2. Activate the plugin through the Plugins menu in WordPress

Well there is a pro version for it too. BuddyPress Job Manager (Pro).

Try it out and create your own job board with social features integrated !!

How to pass dynamic values from PHP to CSS/JS in WordPress

There are situations when you have to use some values stored in DB or values being calculated in PHP script based upon different conditions in the java-script and css code. This can be achieved by writing the inline js/css code directly inside the php script. But in WordPress, this can be done very easily with help of functions built for that which is kind of more neat and clear way of doing the same.

Image: Flicker

Photo Credit: Dmitry

Pass dynamic values from PHP to JS in WordPress:

wp_localize_script( $handle, $name, $data ) : Makes any dynamic data available to your java-script that is available in the server side of WordPress.

Now in the JS code the above passed values can be accessed as: ajaxobject.ajaxurl, ajaxobject.ajaxnonce

 

Pass dynamic values from PHP to CSS in WordPress:

wp_add_inline_style( $handle, $data ) : Adds in-line style with dynamic data being passed from php.

It will add inline css into the header of your page like the below.

 

References:
http://codex.wordpress.org/Function_Reference/wp_localize_script
http://codex.wordpress.org/Function_Reference/wp_add_inline_style

Setup PHP CodeSniffer along with WordPress Coding Standards [ Windows, XAMPP ]

The other day, I had some problem setting up latest WordPress coding standard for PHP CodeSniffer on a Windows machine. It was throwing some errors/warnings like the below. There were some others, but eventually we had fixed some of those. However the WP coding standards were not getting listed in phpcs. 🙁

Here are the steps to fix the problems and setup PHP CodeSniffer along with WordPress Coding Standards namely WordPress, WordPress-Core, WordPress-Extra and WordPress-VIP. FYI, I am on a Windows 7 box with XAMPP setup for Apache, MySql & PHP.

Image: Flicker

Image: Flicker cc

Install PHP CodeSniffer on Windows through PEAR installer:
Uninstall the old CodeSniffer(if any):

Install the latest CodeSniffer using PEAR:

It failed, that means we need to clear the cache:

Again, try installing the latest version of the PHP_CodeSniffer package:

Update the channel as asked above:

Upgrade pear too. Incase if any things are old.

Do a cache clear again:

See the list of default coding standards in PHP CodeSniffer:

 

Install WordPress coding standard definitions for the CodeSniffer:
Navigate to the coding standards directory:

Fetch the WordPress coding standards into CodeSniffer’s standards directory. (if git command not working on your command prompt, you may use any gui for git clone)

As, all of the individual standards of WordPress namely WordPress, WordPress-Core, WordPress-Extra and WordPress-VIP are in one directory, for phpcs to be able to detect the standards we need to add the path to phpcs’s installed_paths.

Check if all the installed standards are listed now:

 

How to use PHP_CodeSniffer:
You can use command prompt to check your code, or you can also configure the same with different IDEs like NetBeans, PHPStrom etc.

You can write the output of code sniffer to a file:

Selectively disable plugins on WordPress for a specific request

For last few days, I have been working on a WordPress project where I am creating a set of APIs to be consumed by mobile apps. While writing these REST APIs I have tried to make the things work faster. While checking the REQUEST/RESPONSE time, I found that the WordPress initialization is taking much time then the API method processing. I looked into the time taken for the whole flow through xDebug Profiler and discovered that there are lots of plugins which are not needed for the API processing and are consuming most part of the loading and API response timing. Plugins like Backup WordPress, Contact Form 7, Simple Responsive Slider, Google Site-map, FancyBox, WordPress SEO etc. are required for the website front-end and don’t really play any role in the APIs.selective-loading-wp-plugins

Now, my intention was to selectively disable the plugins specifically for the API requests coming to the server. How to do that on WordPress ? Before jumping to the solution, below are some backgrounds:

Basic flow of WordPress init for loading the plugins.

WordPress loads it’s core environment –> Must Use plugins are loaded –> if you’re on multisite setup – Network activated plugins are loaded –> Registers a few initial post types –> Sets up the theme directory –> finally loads the currently active plugins.

The relative lines of wp-settings.php:

wp_get_active_and_valid_plugins() is the function which fetches all the active plugins and load them. This function gets these active plugins from the database where the list of active plugins are stored as an array in the wpdb_options table with option name as “active_plugins”. So, we can use the filter hook “option_active_plugins” to do modification to the list active plugins for temporary period.

Code for selectively disable plugins on WordPress for a specific request. This must be made a MU (Must Use) plugin to load and remove the plugins which are to be removed while initializing the WP.

List of useful tools for WordPress development

When a developer starts WordPress development and tries to make the process easier and faster, generally he searches for best tools and various boiler plates which can alleviate the manual task of starting the development from scratch.

wpgearWordPress Gear (WPgear.org) is a website which lists out lots of useful tools those are free and GPL(OpenSource). The list includes tools and its related information for all aspects of WordPress development. Starting from WordPress base tools to Debug tools, PHP boiler plates, Meta fields frameworks, Theme development tools and lot more..

New and latest tools are being added constantly into this list as this is a community driven site. Whole of the code for this page resides in Github and anybody can add any free tool into the list. Just fork the project, add/edit your tool with a link, submit a pull request.

Visit WPGear.org to browse the complete list of tools. Happy WP Coding 🙂
1) http://wpgear.org/
2) https://github.com/wycks/WordPress-Gear