Maintenance Mode in WordPress

In WordPress 3.0 wp_maintenance() function introduced to die with a maintenance message when conditions are met. You need to create a file .maintenance in the WordPress root directory. In this file, you need to add variable $upgrading and set to the time the file was created. If the file was created less than 10 minutes ago, WordPress enters maintenance mode and displays a message.

You can also display maintenance message more than 10 minutes by adding following code in .maintenance file.

<?php
$upgrading = time();

Here, we’ve set current time in $upgrading variable. So WordPress will display maintenance message until you delete .maintenance file.

In WordPress 4.6, enable_maintenance_mode filter introduced to enable/disable maintenance mode. This filter runs before it can be used by plugins. It is designed for non-web runtimes. If this filter returns true, maintenance mode will be active and the request will end. If false, the request will be allowed to continue processing even if maintenance mode should be active.

Default maintenance message is Briefly unavailable for scheduled maintenance. Check back in a minute. The default message can be replaced by using a drop-in (maintenance.php in the wp-content directory).

How to get sample permalink

My colleague was working on an issue where we needed a permalink of the draft post. So he used get_permalink() function to get post permalink. However the get_permalink() returns URL something like https://example.com?p=6 and we needed full permalink something like https://example.com/post-slug/

The get_permalink() function returns full permalink for the published post only. He explored WordPress codebase and he found get_sample_permalink() which returns an array containing the sample permalink with a placeholder for the post name, and the post name.


Visual Studio Code Editor for WordPress Development

I’m using Visual Studio Code editor for WordPress Development. Following are the list of extensions and theme I have installed.

Extensions

WordPress Toolbox – The ultimate WordPress snippet collection for Visual Studio Code.

WooCommerce – Snippets & autocomplete – A collection of WooCommerce snippets and autocompletion.

PHP IntelliSense – Advanced Autocompletion and Refactoring support for PHP

phpcs – PHP CodeSniffer for Visual Studio Code

phpcbf – PHP Code Beautifier and Fixer

PHP DocBlocker – A simple, dependency free PHP specific DocBlocking package

PHP Debug – Debug support for PHP with Xdebug

GitLens — Git supercharged – Supercharge the Git capabilities built into Visual Studio Code — Visualize code authorship at a glance via Git blame annotations and code lens, seamlessly navigate and explore Git repositories, gain valuable insights via powerful comparison commands, and so much more

Git History – View git log, file history, compare branches or commits

WPCS Whitelist Flags – Add WordPress Coding Standards whitelist flags to your code.

Prettify Selected JSON – VS Code Extension to prettify selected JSON blocks

XML Tools – XML Formatting, XQuery, and XPath Tools for Visual Studio Code

Rainbow CSV – highlight csv and tsv files in different colors

Excel Viewer – View Excel spreadsheets and CSV files within Visual Studio Code workspaces.

Theme

Shades of Purple – ⚡ A professional theme with hand-picked & bold shades of purple 💜 to go along with your VS Code. A custom VS Code theme with style.

wp_cache_flush() – Think twice before using it

wp_cache_flush() is WordPress core function which can be used to flush entire object cache. But why I said, “Think twice before using it“. There is a reason why not to use this function in the plugin/theme.

Continue reading “wp_cache_flush() – Think twice before using it”

Functions and Hooks for Comment Template

Following are the list of functions and hooks for Comment Template. Continue reading “Functions and Hooks for Comment Template”

Functions and Hooks in Comment API

Following are the list of functions and hooks of Comment API. Continue reading “Functions and Hooks in Comment API”

Hooks and Functions for Meta Box

Following are the hooks and functions which use to add custom meta boxes to one or more screens.

Hooks

Functions

WordCamp Udaipur 2017

WordCamp Udaipur is the second WordCamp in India in 2017 and first WordCamp for me in 2017. I decided to attend WordCamp Udaipur when it’s announced. Also planned Udaipur trip because public holiday on Thursday, 26 Jan 2017 (Republic Day of India) and took one day leave on Friday, 27 Jan 2017. So I got two days to explore Udaipur city.

I was excited by the WordCamp Udaipur Organizers’ tweets of beautiful places, popular foods and “Wapuu Saa” that were waiting for us. 🙂 Here are some tweets.

Continue reading “WordCamp Udaipur 2017”

WordPress widgets – where and how they are saved in database

In this article, I will tell you how WordPress widgets stored in {prefix}_options table as key/value pair when you set widget in a sidebar.

sidebars_widgets and widget_{widget_ID}  are the options.

Continue reading “WordPress widgets – where and how they are saved in database”

REST API – Filter REST URL prefix

REST API architecture is included in WordPress 4.4 version. So you can register custom REST API endpoints. Default REST API URL prefix is wp-json. Continue reading “REST API – Filter REST URL prefix”

%d bloggers like this: