WordPress

Custom Dashboard

WordPress plugin stub to customize the dashboard for users without administrator access.

Source Code

Custom Homepage

Clone and edit the existing theme index.php template. Open index.php in an editor and Save As… home.php. This file will automatically take over the themes index.php, and it will be displayed as the homepage.


Custom Widget

Step 1 - Copy Core Widget into your Theme

Copy the Wordpress widget php file from wp-includes/widgets into your theme. This example copies the pages widget, class-wp-widget-pages.php into a widgets folder in mytheme.

cp wp-includes/widgets/class-wp-widget-pages.php wp-content/themes/mytheme/widgets/class-wp-widget-pages-custom.php

Step 2 - Edit the Widget

Update the widget, for example, rename the class.

<?php
/**
 * Widget API: WP_Widget_Pages_Custom class
 *
 * @package WordPress
 * @subpackage Widgets
 * @since 4.4.0
 */

/**
 * Modified copy of Core WP_Widget_Pages class used to implement a Pages widget.
 *
 * @since 2.8.0
 *
 * @see WP_Widget
 */
class WP_Widget_Pages_Custom extends WP_Widget {

Step 3 - Register the Widget

In your themes functions.php file, require the customized widget file and register it. For example,

namespace mytheme;

...

// modified copy of WP_Widget_Pages class
require_once get_template_directory() . '/widgets/class-wp-widget-pages-custom.php';

function widget_pages_custom_init(){
    register_widget('WP_Widget_Pages_Custom');
}

// register modified copy of WP_Widget_Pages class
add_action("widgets_init", __NAMESPACE__ . '\\widget_pages_custom_init');

Function Snippets

Various snippets for functions.php

Disable automatic <p> tags.

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

Reference: codex.wordpress.org/Function_Reference/wpautop#Disabling_the_filter


Development Environments

Docker

WordPress from Development to Production using Docker

Vagrant

Laravel Homestead If you develop Laravel apps on Homestead, you can also install Wordpress on the same Virtual Machine. This example Homestead.yaml file has a configuration for 4 different sites. Two Laravel sites, a Wordpress site and a phpmyadmin site.

Vagrant configuration designed for development of WordPress plugins, themes, or websites.

http://vccw.cc/

What’s Included

Git Setup

To provision from the master branch,

git clone https://github.com/vccw-team/vccw.git

cd vccw

cp provision/default.yml site.yml

# edit php.ini settings in site.yml as needed

vagrant up

vccw.cc zip download link uses release branch.


XAMPP, MAMP, IIS


Development Resources

wp-config.php

REPLACE

define('WP_DEBUG', false);

WITH

// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );

// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

Log Your Debug Statements

// array or object variable
error_log(print_r($myvariable, true));

// string
error_log('hardcoded string');

Tail Command

View log file updates in realtime using the tail command. Open up a terminal and navigate to the location of your debug.log. For example,

cd wp-content

tail -F debug.log

Use shell redirect null when you want to clear the contents of the debug.log. e.g., > debug.log.


comments powered by Disqus