Joomla & WordPress Tutorials, Info, Discussion, Tips | GavickPro Blog

What is new in WordPress 4.0 for Developers?

WordPress 4.0 naturally brings many new dashboard features for the average user to take advantage of, but there’s also a wealth of changes that will perk the interest of WordPress programmers and developers. In this article, we’ll look at some of the changes that have interested us the most.

Changes in Theme Customizer

WordPress 4.0 includes many changes to the Theme Customizer’s functionality. Take a look at these important updates:

Creating a new panel is very easy – We need only request the add_panel method that includes the identifier and new panel parameters:

$wp_customize->add_panel('test_panel', array(
    'priority'       => 10,
    'capability'     => 'customize',
    'theme_supports' => '',
    'title'          => ‘Test Panel',
    'description'    => ‘Simple test panel',
));

In order to show a panel, we have to assign a section with options to the panel – this is achieved via a panel option declared when adding a section:

$wp_customize->add_section('test_section', array(
    'priority'       => 10,
    'capability'     => 'customize',
    'theme_supports' => '',
    'title'          => 'Test Section',
    'description'    => 'Simple test section',
    'panel'          => 'test_panel',
));

The above improvement with regards to the management controls context creates a powerful tool for managing theme options. Controls context is specified with the active_callback parameter:

$wp_customize->add_control('theme_content_width', array(
	'label'   => __( 'Layout width', 'theme-slug' ),
	'section' => 'layout',
	'type'    => 'range',
	'active_callback' => 'theme_slug_show_control'
));

Where theme_slug_show_control is our own function that returns information on which subpages a given control should be displayed on e.g.:

function theme_slug_show_control() {
    return is_home();
}

In the above case, a control will be displayed only on the homepage of the theme preview.

Changes in TinyMCE

TinyMCE in WordPress 4.0 includes 3 new plugins: lists, wpautoresize and colorpicker.

There is also a useful get_editor_stylesheets function that returns the list of CSS files loaded in the editor.

Thanks to a new wp_editor_settings filter, it is possible to modify and diversify the configuration used in a particular instance of the TinyMCE editor.

Multiple ORDER BY

Starting from WordPress 4.0, we can sort columns of request results generated by get_posts and WP_Query in various orders unique to each column.

$posts = get_posts(
  array(
    'orderby' => array(
       'author' => 'DESC',
       'post_title' => 'ASC'
    )
  )
);

Before this we could sort the results into multiple columns, but the ordering method was the same for each column.

like_escape replaced with wpdb::esc_like

Please, remember that a new method containing the wpdb class should be used before the following methods are requested: wpdb::prepare and wpdb::esc_sql.

New plugin browser appearance

In order to add your own icon to a plugin, you have to create an image in one of the following formats: JPG, PNG or SVG. Should you be using JPG/PNG you’ll also have to choose one of two sizes: 128×128 or 256×256 and insert it as:

Summary

These are, we feel, the most important changes implemented in WordPress 4.0 from the developer’s point of view. There are of course many more changes included in this release so we encourage you to investigate and analyze these yourself to make sure you are well informed to take advantage of these changes as quickly as possible. On our side, we’d recommend checking out the changes to the wp_list_pluck function, the new attachment_url_to_postid and the following filters: wp_title_parts, term_search_min_chars or wp_list_comments_args.

The most important thing for programmers is the fact that the latest version of WordPress does not implement any significant changes in the API, so in the majority of cases you may update WordPress to the latest version without anything breaking!
Share