WordPress Version 5.2

On May 7, 2019, WordPress 5.2 “Jaco”, named for the jazz musician Jaco Pastorius, was released to the public.

As always, you can update your WordPress to the latest version or download the latest files from WordPress.org.

So what’s new with the latest version?

Site Health Check

Building on the Site Health features introduced in 5.1, this release adds two new pages to help debug common configuration issues. It also adds space where developers can include debugging information for site maintainers. Check your site status by going to Tools > Site Health, and learn how to debug issues.

WordPress 5.2 - Site Health

PHP Error Protection

This administrator-focused update will let you safely fix or manage fatal errors without requiring developer time. It features better handling of the so-called ‘white screen of death,’ and a way to enter recovery mode, which pauses error-causing plugins or themes.

WordPress 5.2 - Site Protection

Improvements for Everyone

Accessibility Updates

A number of changes work together to improve contextual awareness and keyboard navigation flow for those using screen readers and other assistive technologies.

New Dashboard Icons

Thirteen new icons include Instagram, a suite of icons for BuddyPress, and rotated Earth icons for global inclusion. Find them in the Dashboard and have some fun!

Plugin Compatibility Checks

WordPress will now automatically determine if your site’s version of PHP is compatible with installed plugins. If the plugin requires a higher version of PHP than your site currently uses, WordPress will not allow you to activate it, preventing potential compatibility errors.

Developer Happiness

As always, a large handful of developer-focused changes have also been made. The highlights of these include:

PHP Version Bump

The minimum supported PHP version is now 5.6.20. As of WordPress 5.2, themes and plugins can safely take advantage of namespaces, anonymous functions, and more!

Privacy Updates

A new theme page template, a conditional function, and two CSS classes make designing and customizing the Privacy Policy page easier.

New Body Tag Hook

5.2 introduces a wp_body_open hook, which lets themes support injecting code right at the beginning of the element.

Building JavaScript

With the addition of webpack and Babel configurations in the @wordpress/scripts package, developers won’t have to worry about setting up complex build tools to write modern JavaScript.

And plenty of more which you can read about here.

What we can do for you!

As always, it’s always best to keep your WordPress version and plugins up to date and use plugins from reliable authors that maintain their plugins. If you need assistance with upgrading your WordPress version, plugins, updating core code to be compatible with the latest versions of PHP (recommended) or anything else WordPress or digital related then get in touch by sending an email to [email protected]. We &hearths; WordPress and as specialists in the field; you can guarantee that you are in very capable hands.

Have a look at out portfolio – if it’s a web specialist you require; we’re here at your disposal ; )

It’s good to share

The Journey – Hi Ho Silva Lining…

If you would like to read about my freelance journey, you can read the full story here.

No time for the full story? No problem! You can see a visual synopsis below…

Silva Web Designs - Journey - The Struggle...

Silva Web Designs - Journey - Beaches

Silva Web Designs - Journey - Our Portfolio

Silva Web Designs - Journey - What we love - WordPress

Nathan da Silva
Founder | Silva Web Designs

‘‘ The Crazy & Creative Team ’’

 

M: +44 7511 68 1818
W: silvawebdesigns.com
E: [email protected]

If you’re a music lover, follow our Spotify playlist; maybe we’re on the same wavelength.

It’s good to share

Create a new WordPress admin user in the database

You can create a new WordPress admin user from within the database using phpMyAdmin.

Method 1

1.) Log into phpMyAdmin (cPanel / Plesk / Web Hosting / Managed WordPress).

2.) Click the _users table

3.) Click the Insert tab

4.) Fill in the following fields.

  • ID is any number you choose
  • user_login is the username for accessing the WordPress Dashboard.
  • user_pass is the password for the user. Make sure to select MD5 in the functions menu
  • user_nicename is the nickname for the user
  • user_email is the email address you want to associate with this user
  • user_registered is the date and time for when this user is registered
  • user_status should be set to 0
  • display_name is the name that will be displayed for this user on your site

5.) Click the Go button

6.) Click the _usermeta table

7.) Click the Insert tab

8.) Fill in the following fields:

  • user_id is the ID you entered in the previous step
  • meta_key should be the phrase wp_capabilities
  • meta_value should be

a:1:{s:13:"administrator";s:1:"1";}

9.) Click Go

10.) Click the Insert tab again

11.) Enter the following information:

  • user_id is the same number you entered in the previous step
  • meta_key should be the phrase wp_user_level
  • meta_value should be the number 10

12.) Click the Go button.

You can now login with the new Admin user.

Method 2

For developers who want to speed this process up, you can simply drop this SQL query in your database:-


INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('4', 'demo', MD5('demo'), 'Your Name', '[email protected]', 'http://www.test.com/', '', '', '0', 'Your Name');
 
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
 
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_user_level', '10');

Remember to change the databasename to the database you are working with. Also don’t forget to change the appropriate values.

It’s good to share

Our top 10 used plugins for WordPress – 2019 Edition

Every WordPress developer has a bunch of plugins they tend to install on pretty much every WordPress site they develop, and we are also those kind of people. These plugins give great solutions for caching, security and adding other improvements that build on WordPress core.

That’s the beauty of WordPress – there are loads of plugins to choose from and they are so quick and easy to implement. Some plugins are just a case of downloading and activating, others provide a shortcode which you can copy and paste within your pages and others is a simple as dragging and dropping a widget where ever you wish to display it.

With so many free and premium plugins available, how do you distinguish from the good and bad plugins out there?

Do note, overloading your web site with too many plugins can cause plugin conflict and reduce the speed of your web site, so if you can avoid a plugin and just code it in, that’s even better!

Below you will find our selection of essential plugins, all chosen based on their usefulness, quality and popularity.


1.) WooCommerce

WooCommerce is a great plugin and is really quick and easy to install. It turns your standard WordPress website into a an eCommerce store and creates all the necessary pages for you (My Account, Checkout, Cart etc). It allows intergration with secure payment methods such as Bank Transfer, PayPal, SagePay and many more. With a huge range of features that can be quickly changed in the Control Panel, this is definitely one of my favorites because of the speed you can set up a fantastic eCommerce website.


2.) Advanced Custom Fields

Advanced Custom Fields is an amazing plugin and without a shadow of a doubt, it’s installed on every project I build. I would definitely recommend getting a licence for the Pro version which you can find out more information about here. You can use the Advanced Custom Fields plugin to take full control of your WordPress edit screens & custom field data. It makes it super easy for clients to change text / images any many other things within your WordPress site without any risk of breaking the site.


3.) Contact Form 7

Contact Form 7 is another plugin I use on pretty much every WordPress site I develop. You can manage multiple contact forms, customise the form and the mail contents and again, it’s really easy to use. The form supports Ajax-powered submitting, CAPTCHA, Akismet spam filtering and many more. All the form elements are generated for you so you don’t even have to know any PHP code. If your not already using this plugin for your forms, I suggest giving it a try now!


4.) Yoast SEO

SEO Yoast is a fantastic platform for SEO. I have used this plugin on 100% of the WordPress sites I have developed and it is the only plugin I use in terms of SEO. If set up correctly, it will improve your site’s SEO on all needed aspects. WordPress SEO forces you to choose a focus keyword when you’re writing your articles, and then makes sure you use that focus keyword everywhere, it also ranks the SEO of all your pages and posts from ‘Bad’, ‘OK’ to ‘Good’ so you know if your content is going to have any chance of ranking on search engines. The best feature about this plugin is that it even tells you how you can improve the performance of each and every page on your site. It may say things such as, you need to include

tags or include an outbound link on your page/post. You will learn a lot about SEO if you run this plugin on your websites. We actually use the SEO Yoast Premium version which allows up to 5 keywords on each page/post/CPT including many other great features which you can read about or purchase here.


5.) Hummingbird Page Speed Optimization

The next 3 set of plugins I’m going to be talking about are plugins offered by WPMU DEV which you can read about more here. There are free versions of these plugins but they also have premium versions which offer a lot more features which I would highly recommend. Hummingbird PRO is an awesome caching plugin. It zips through your site and finds new ways to boost page speed with fine-tuned controls over file compression, minification and full-page, browser and Gravatar caching. Load your pages quicker and score higher on Google PageSpeed Insights with Hummingbird site optimization.


6.) Smush Image Compression and Optimization

This plugin is one of my favourites; it will resize, optimise and compress all of your images with the incredibly powerful and 100% free WordPress image smusher. This uses Lossly compression which will significantly reduce the file sizes of all images on your web site which will definitely increase your sites speed. Again, the premium version of this plugin is 100% recommended as it will allow you to SUPER-Smush all your images along with a few other great features which will allow you to further optimise your site. Need a high Google Speed Test score? This plugin combined with Hummingbird will make the job a piece of cake 😉


7.) Defender Security, Monitoring, and Hack Protection

Security is definitely important when it comes to WordPress, the amount of sites I’ve had to restore/repair and remove Malware from is crazy. So make sure you have fully configured a great security plugin to prevent your web site from these kind of attacks. Defender is layered security for WordPress made easy. And by easy, I mean amazingly easy! No longer do you have to go through hideously complex settings and get a virtual PhD in security. Defender adds all the hardening and security tweaks you need, in just minutes!


8.) Akismet Anti-Spam

Sick and tired of spam comments and junk email from your WordPress site? Akismet has you covered! Akismet checks your comments and contact form submissions against their global database of spam to prevent your site from publishing malicious content. You can review the comment spam it catches on your blog’s “Comments” admin screen.


9.) MailChimp for WordPress

MailChimp for WordPress allows your visitors to subscribe to your newsletter very easily. This plugin helps you grow your MailChimp lists and write better newsletters through various methods. You can create good looking opt-in forms or integrate with any existing form on your site, like your comment, contact or checkout form.


10.) Classic Editor

Finally, our last plugin which we have made a lot of use from since WordPress 5 is classic editor! Classic Editor is an official plugin maintained by the WordPress team that restores the previous (“classic”) WordPress editor and the “Edit Post” screen. It makes it possible to use plugins that extend that screen, add old-style meta boxes, or otherwise depend on the previous editor. By default, this plugin hides all functionality available in the new Block Editor (“Gutenberg”). Since a lot of people are finding it difficult to get their heads around Gutenberg, this is a great quick fix plugin which will restore the editor back to the way you’ve known and loved for a long time.

It’s good to share

What’s New in WordPress 5.0, Plus What to Expect From the Gutenberg Editor

Each time a new version of WordPress rolls out, we’re all excited about getting to play with its new features. However, few versions in the past have garnered as much buzz around them as WordPress 5.0 because of these two simple words; Gutenberg Editor.

Gutenberg is a complete redesign and re-imagination of the WordPress editor; with this, the default way that people create content with WordPress will radically change.

Big changes to your favourite platform can be difficult to accept. However, even massively popular platforms such as WordPress need to adapt to the times, or risk losing market share. Gutenberg is a bold leap forward, and it’s not the only update that’s coming up.

In this article, we’re going to discuss what makes WordPress 5.0 unique in comparison to previous releases, and then we’ll get into what to expect from WordPress 5.0 and the Gutenberg Editor. Let’s talk about the future!

WordPress 5.0 will be a bigger jump than recent major updates

If you’ve been using WordPress for a while, then you’ll know how much the platform has changed over time. Even individual updates often bring significant shifts. For example, the 4.9 ‘Tipton’ update enabled users to schedule design changes in the WordPress Customiser so they can go live at later dates, just like post drafts.

WordPress 4.8, on the other hand, brought us plenty of widget updates. For example, if you wanted images in your widgets in the past, you had to add them manually. Now, there are three dedicated media widgets for image, audio, and video files.

Another of our favourite features of 4.8 was the option to check up on nearby WordPress events right from your dashboard, which is handy if you want to do some networking:
A list of nearby WordPress events.
However, all the changes we’ve mentioned so far are pretty incremental. They’re useful, but not exactly game-changing. Most WordPress updates have been more about taking small steps forward rather than major leaps – that is, until WordPress 5.0.

What to expect from WordPress 5.0

WordPress 5.0 is kicking “incremental” to the curb with some pretty major changes. The biggest is the aforementioned Gutenberg Editor, which we’ll talk more about in a moment.

But WordPress 5.0 also marks a change to how the platform handles releases. It used to be the case that you could count on getting two major WordPress releases per year, with plenty of mini-updates in the meantime.

Aside from that, here are a few of the other significant changes to see with WordPress 5.0:

  • The platform’s focus is moving towards a more intuitive site-building experience. WordPress already leads the pack in terms of market share. And by improving WordPress’ site-building functionality, the core team aims to hold that market share against the rise of hosted website builders.
  • We’ll see some improvements to the WordPress Rest API. The WordPress Rest API helps developers create more feature-rich products by making it easier to send and pull data from your website. This update means developers will be able to more easily create applications using the platform as a framework.
  • Building custom themes will become easier. In the past, you needed at least a simple development background to put together a WordPress theme. With Gutenberg, theme creation will become much more accessible thanks to blocks.
  • Page builder plugins might lose some relevance. There are a lot of fantastic page-builder tools that you can use with WordPress, some of which rival professional platforms. Gutenberg won’t be a match for them at first, but it might dissuade people from using them in the long run.

What the Gutenberg editor means for you

The launch of Gutenberg means that you’ll need to get acquainted with a whole new editing experience.

You can expect a lot of activity for a few weeks, as everyone learns to contend with the new editor.

⚠️ Don’t panic – if you don’t want to use the Gutenberg Editor, you’ll still be able to keep the classic editor by installing the official Classic Editor plugin.

Gutenberg will affect themes and plugins, too

Aside from your own editing experience, Gutenberg will also bring important changes to a lot of your favourite plugins and themes. For example, we’ll probably see the emergence of a lot of Gutenberg-friendly themes, which will be designed to take advantage of all the new features the editor offers.

We’ve already seen a couple of interesting themes being released, such as Atomic Blocks and even the new default theme, Twenty Nineteen that proclaim their Gutenberg-first focus. And existing themes are no slouches either. Popular themes like Neve and Hestia now come with full Gutenberg compatibility too.

Similarly, you’ll see changes with some of your favourite plugins. A lot of plugins interact with the WordPress editor directly, whether that’s to add new functionality or include shortcodes. Those plugins will need to become Gutenberg compatible, unless they want to alienate a large part of their user base. Years from now, it might even be common to find plugins that only support Gutenberg.

When is the WordPress 5.0 release date?

As of today (6th December), you can update your WordPress to 5.0.

Get ready because the times they are a-changin’

Each major release of WordPress brings changes to the way we use the platform. However, even before it’s out, we can say with complete certainty that 5.0 will fundamentally change the way most people interact with WordPress because of the Gutenberg Editor.

If you’re old-school, you’ll be able to stick with the classic WordPress editor for the foreseeable future. However, if you plan on adapting, you’ll want to start reading up on how Gutenberg works right away. This will give you a leg up on the competition once WordPress 5.0 is live, and will help you determine which of your themes and plugins may be most affected.

So…

Do you plan on making the switch to Gutenberg, or sticking with the classic WordPress editor? Share your reasons with us in the comments section below!

It’s good to share

WooCommerce – Hide shipping rates when free shipping is available.

Have you noticed with WooCommerce that when free shipping is available it displays the free shipping as a shipping method but still charges the flat rate? Annoying right?

If free shipping is available then it should only show the free shipping method in my opinion. They’re may be exceptions when you want to display other shipping methods for a quicker delivery service but for the particular site I built there is just ‘flat rate’ and ‘free shipping’ methods available.

So, how can this be done? Simply add the following code in your functions.php file and this will hide any other shipping methods if free shipping is available to the customer:-


<?php
/**
 * Hide shipping rates when free shipping is available.
 * Updated to support WooCommerce 2.6 Shipping Zones.
 *
 * @param array $rates Array of rates found for the package.
 * @return array
 */
function my_hide_shipping_when_free_is_available( $rates ) {
	$free = array();
	foreach ( $rates as $rate_id => $rate ) {
		if ( 'free_shipping' === $rate->method_id ) {
			$free[ $rate_id ] = $rate;
			break;
		}
	}
	return ! empty( $free ) ? $free : $rates;
}
add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );

It’s good to share

How to Build a WordPress Plugin

In this tutorial, I will go through the process of creating a plugin for WordPress. A WordPress plugin extends the WordPress core and is intended to be reusable code or functionality across multiple projects. This is one of the most interesting things about it – you can share your code or functionality on the web.

I am sure many, if not all of you, have already searched for a plugin in the WordPress repository or any of the available market places. This is one of the reasons why WordPress is so widely used. It’s extremely extensible and has a huge community of developers around it. As of today, there are more than 39,000 publicly available free plugins on the WordPress repository.

Creating a Plugin

When creating a WordPress plugin there are some standards to uphold to when doing so. Below I’ll outline some key points to remember when creating your own.

Plugin Name

If you’re planning on making a plugin that doesn’t exist yet you will need to first determine its name. To be extra sure you will want to do a search in the WordPress Plugin repository. Some developers choose a name that describes more of what the plugin does so the end user can establish a quick connection with the name. The name itself can be multiple words.

Plugin Files

Typically a plugin lives within its own folder under wp-content/plugins/ inside your WordPress installation. There is usually at least one PHP file that is typically named after the plugin. So if your plugin was named amazing-plug then your PHP file name would most likely be amazing-plug.php. Using a unique name is crucial so no two plugins use the same name.

You can also choose to split your plugin into multiple files; similar to the way WordPress is built. Assets such as images, CSS, and JavaScript are common to see within installed plugins.

Readme File

Readme files are useful for other developers and users. Usually these files give a quick description of the plugin as well as sometimes offer change logs which indicate previous updates and maintenance announcements to users.

Home Page

If you plan to share you plugin with the WordPress community, having a dedicated home page would be wise. This page can be used as a place to download the plugin, report bugs, and announce updates to your user community.

Standard Plugin File

A plugin must contain a bit of meta information which tells WordPress what it is and how to handle it within your website. Plugins can be installed, deleted, activated, and inactivated. A standard header is introduced below to establish your plugin’s presence. The parameters shown will tell WordPress how to optimize it within your website and WordPress admin area.


<?php
/**
* Plugin Name: My Plugin Name
* Plugin URI: http://mypluginuri.com/
* Description: A brief description about your plugin.
* Version: 1.0 or whatever version of the plugin (pretty self explanatory)
* Author: Plugin Author's Name
* Author URI: Author's website
* License: A "Slug" license name e.g. GPL12
*/

The minimum WordPress needs to establish your file as a plugin is the line

Plugin Name: My Plugin Name

The rest of the information will be displayed within the Admin area under the Plugins section.

Programming the Plugin

Now the time comes to create our own demo plugin. I’ll be working on a local copy of WordPress using the our Divi 2.0 theme. You can follow along whichever method you prefer but to limit any downtime on your website I suggest you work locally or on a testing server. Our blog features other posts about installing WordPress locally if you are new to the concept. Find the links below depending on your platform.

For this tutorial I will be creating a plugin that creates a custom post type for our blog as well as establishes some other custom parameters. This plugin will be useful because we will be able to use it among any theme rather than just modifying one.

Plugin Scope

Our plugin will start with a simple PHP file. We will call this file custom-music-reviews.php. Within our file we will create a custom post type as well as define some new categories within that post type. The purpose of this plugin will be to write music reviews within specific genres without needing to touch code in the future. Each review will have a feature image, excerpt, rating, and genre type.

Starting Off

Assuming you have a local copy of WordPress ready to use, navigate to your wp-content folder inside of a code editor of your choice. Inside that folder you should see a folder called plugins. Inside of that folder create a new folder called custom-music-reviews.

With the folder created create a new file inside it called custom-music-reviews.php.

The path to the file should now be wp-content/plugins/custom-music-reviews/custom-music-reviews.php.

With your new file created we need to add some parameters in comment form like I explained earlier. For our plugin our parameters will look like this:


<?php
/**
* Plugin Name: Custom Music Reviews
* Plugin URI: https://www.elegantthemes.com/
* Description: A custom music review plugin built for example.
* Version: 1.0
* Author: Andy Leverenz
* Author URI: http://justalever.com/
**/

With this information added, save your file and navigate to your WordPress admin area. Click on Plugins on the left side navigation and you should now see our plugin available. Wasn’t that easy?

With our parameters in place our plugin becomes available to activate under “Installed Plugins”.

Even though our file is empty we can go ahead and activate the plugin. Go ahead and do that now. You’ll hopefully notice nothing different about your site with the plugin activate. If you do you probably typed the content above wrong or failed to close the comment.

Adding Our Plugin Code

With our file all set up and plugin active we can now add the inner workings of the plugin which we will be using for this tutorial.

Add the code below:


// Register the Custom Music Review Post Type
 
function register_cpt_music_review() {
 
    $labels = array(
        'name' => _x( 'Music Reviews', 'music_review' ),
        'singular_name' => _x( 'Music Review', 'music_review' ),
        'add_new' => _x( 'Add New', 'music_review' ),
        'add_new_item' => _x( 'Add New Music Review', 'music_review' ),
        'edit_item' => _x( 'Edit Music Review', 'music_review' ),
        'new_item' => _x( 'New Music Review', 'music_review' ),
        'view_item' => _x( 'View Music Review', 'music_review' ),
        'search_items' => _x( 'Search Music Reviews', 'music_review' ),
        'not_found' => _x( 'No music reviews found', 'music_review' ),
        'not_found_in_trash' => _x( 'No music reviews found in Trash', 'music_review' ),
        'parent_item_colon' => _x( 'Parent Music Review:', 'music_review' ),
        'menu_name' => _x( 'Music Reviews', 'music_review' ),
    );
 
    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'description' => 'Music reviews filterable by genre',
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
        'taxonomies' => array( 'genres' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 5,
        'menu_icon' => 'dashicons-format-audio',
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'post'
    );
 
    register_post_type( 'music_review', $args );
}
 
add_action( 'init', 'register_cpt_music_review' );

This code above may look like a lot and almost seem like an unknown language to you if you’re new to WordPress but if not you’ll recognize this code as a Custom Post Type. In this case our custom post type is called music_review. The code is essentially telling WordPress to establish a new type of post within your theme. The post type has parameters that go along with it such as labels, arguments, and more. I won’t go into a ton of detail on how Custom Post Types work because I’ve already covered it within another article on Elegant Themes. Be sure to read it to gain a full understanding.

With our post type set up you can already see it active within the WordPress admin area.

Our custom post type is successfully implemented.

Lets take things one set further and include a custom Taxonomy called Genre inside our plugin. Think of a Taxonomy as a type of categorizing feature that is completely custom. WordPress already includes Categories and Tag support by default but developers can create custom taxonomies to extend their themes or plugins even further.
Read more about WordPress Taxonomies here.

Add the code below under the custom post type function we just added.


function genres_taxonomy() {
    register_taxonomy(
        'genres',
        'music_review',
        array(
            'hierarchical' => true,
            'label' => 'Genres',
            'query_var' => true,
            'rewrite' => array(
                'slug' => 'genre',
                'with_front' => false
            )
        )
    );
}
add_action( 'init', 'genres_taxonomy');

Registering a new Taxonomy is relatively easy. We have made the connection to our custom post type by using the
register_taxonomy() function which creates a new taxonomy called genres and assigns it to our post type music_review.

We need to add one more line to our custom post type to make everything sync up. Add this code just below the supports argument within the custom post type.

Here’s all our plugin code up until this point. For better legibility I’ve stripped our code of any comments we had prior to this.


function register_cpt_music_review() {
 
    $labels = array(
        'name' => _x( 'Music Reviews', 'music_review' ),
        'singular_name' => _x( 'Music Review', 'music_review' ),
        'add_new' => _x( 'Add New', 'music_review' ),
        'add_new_item' => _x( 'Add New Music Review', 'music_review' ),
        'edit_item' => _x( 'Edit Music Review', 'music_review' ),
        'new_item' => _x( 'New Music Review', 'music_review' ),
        'view_item' => _x( 'View Music Review', 'music_review' ),
        'search_items' => _x( 'Search Music Reviews', 'music_review' ),
        'not_found' => _x( 'No music reviews found', 'music_review' ),
        'not_found_in_trash' => _x( 'No music reviews found in Trash', 'music_review' ),
        'parent_item_colon' => _x( 'Parent Music Review:', 'music_review' ),
        'menu_name' => _x( 'Music Reviews', 'music_review' ),
    );
 
    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'description' => 'Music reviews filterable by genre',
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
        'taxonomies' => array( 'genres' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 5,
        'menu_icon' => 'dashicons-format-audio',
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'post'
    );
 
    register_post_type( 'music_review', $args );
}
 
add_action( 'init', 'register_cpt_music_review' );
 
function genres_taxonomy() {
    register_taxonomy(
        'genres',
        'music_review',
        array(
            'hierarchical' => true,
            'label' => 'Genres',
            'query_var' => true,
            'rewrite' => array(
                'slug' => 'genre',
                'with_front' => false
            )
        )
    );
}
add_action( 'init', 'genres_taxonomy');

The only line that changed was the 'taxonomies' => array('genre') line within our custom post type. I added this line to tell our custom post type to connect to our new taxonomy and use it instead of the default category or tag structure WordPress comes installed with.

If you’ve made it this far you can now visit your WordPress admin area and see your new custom post type and taxonomy(Genres) present. Congrats!

custom-pt-and-tax-available
Our custom post type and taxonomy are successfully implemented. Here we can add a new Music Review which contains various types of genres decided upon by the user.

Getting Our Code To Output
Below I’ll try adding a new music review. You should see the new Genres section that we set up with our custom Taxonomy. With some data entered I’ll publish the post.

new-music-review
Create a new music review as an example.

At this point we have our functionality set up within our plugin.

In order to make things effortless we will rely on the plugin to create a new page called Music Reviews. The page will be referenced by our plugin and output any new music reviews the user posts. We are doing this so the user doesn’t have to edit a single line of code.

Tying it All Together

Our code now works but we should create a page that will use

<code class="language-PHP">
// Function used to automatically create Music Reviews page.
function create_music_review_pages()
  {
   //post status and options
    $post = array(
          'comment_status' => 'open',
          'ping_status' =>  'closed' ,
          'post_date' => date('Y-m-d H:i:s'),
          'post_name' => 'music_review',
          'post_status' => 'publish' ,
          'post_title' => 'Music Reviews',
          'post_type' => 'page',
    );
    //insert page and save the id
    $newvalue = wp_insert_post( $post, false );
    //save the id in the database
    update_option( 'mrpage', $newvalue );
  }

And finally we need to create our Music Reviews page once the plugin is activated. Adding the code below initiates the function we just wrote above ( function create_music_review_pages(){…}).


// // Activates function if plugin is activated
register_activation_hook( __FILE__, 'create_music_review_pages');

Testing

Our plugin should be ready to test at this point. Lets create an example music review and see what outputs.

new-music-review-test
Create another music review to verify our plugin is working correctly.

If you click View Music Review once the post is published you should be taken to a screen which looks similar to the image below. Your theme and styles may vary…

You may notice that I modified the menu to include our new Music Reviews page. Doing this gives us easy access.

With your menu in place and saved click on Music Reviews to see all the posts we have made so far.

Based on the page template supplied by your theme the Music Review should output all together and be clickable through to the single review template. You will probably notice that the music review I posted earlier has output as well as the one we just created.

Our feature image, title, genre, and review all have posted successfully. Our plugin works!

To verify, you can deactivate the plugin and reinstall it or activate it. Upon doing so a new Page called Music Reviews should be created. You can delete or reuse the one from before if there are duplicates but there should be only one “Music Reviews” page. We could have added a function to delete and restore this page within our plugin but I wanted to keep things as simple as possible.

Finish

Our plugin is a relatively simple one. You can extend it so much further by including it’s own predefined templates, custom widgets, more taxonomies and so much more. Creating a plugin is no easy feat. You will want to plan your plugin before even moving to development. Knowing what you can an can’t do with WordPress before coding your own plugin is a crucial step to developing a quality one. The plugin create in this tutorial is meant to teach by example. There are better standards to follow and more useful practices to endure. Be sure to read the WordPress Codex and get familiar with the WordPress Plugin API. If a plugin isn’t out there and you need custom functionality for your website then I stronger encourage trying to create your own!

All album covers and rights belong to their creators. Elegant Themes does not own or have any relation to the artists being reviewed in this tutorial. Imagery and titles were used by example only.

It’s good to share

9 Awesome WordPress features you probably didn't know existed

At the rapid rate WordPress is growing, when a new update becomes available, WordPress doesn’t mention or promote some of the awesome little bits and pieces it contains, which means that some features get overlooked.

I hope after reading this you learn at least a few things you don’t know about everyone’s favorite CMS.

1. Paste to Make a Link

This one is a cool little feature that not a lot of people know about. When in visual mode in the post editor, you can select some text and paste to make the selected text a link. Usually, you would expect the selected text to be replaced with a link but this is not the case in WordPress.

2. Delete the Post Name to Regenerate It

If you rename a post before it is published, you’ll generally want to edit the link to make sure the post name follows the post title. If you click edit and just delete the whole thing the post name will be regenerated based on the current title.

Countless times have I retyped the permalink when I’ve changed the page title, definitely a time saver.

3. Screen Options Are per User

Screen options may be something you already know about, but probably don’t take advantage of. They are not only saved in cookies and in the database but are stored per user, which means that you can set up a completely different layout for yourself than others would see.

The cookie-database saving means that you can set up a specific layout on one computer and then log in from a different device and still see your own layout. This isn’t very well-communicated in the admin, which is why users seem to be afraid to use it.

4. Markdown-Style Shortcuts

As of WordPress 4.3, you can use markdown-like syntax to make your writing a lot faster. Stars and dashes make lists, hashes make titles and so on.

Take a look at the announcement for more details on how to use this feature.

5. Multi-Page Posts

You can use the tag to split content into multiple pages. WordPress will take all of your tags and generate the pagination based on them.

6. WordPress Has Image Editing Power

WordPress can perform basic image editing tasks like rotating, cropping and resizing. No filters just yet, but this feature is pretty useful if you need to rotate an image the right way up quickly.

Select an image and click on the edit image link near the image thumbnail in the details section and off you go. I’ve personally told some of my clients to use this facility which they love as they don’t need to come to me every time they need to make a quick tweak to an image that I would normally do in Photoshop.

7. WordPress Has a Filesystem API

Here’s one for the developers out there. The Filesystem API was created back in WordPress 2.6 to handle the auto-update features.

This is not one of those systems you’ll use every day, but when you need it, it’s nice to know there’s something in WordPress core to help you out.

8. Terms Have Metadata

As of the 4.4 release of WordPress, taxonomies now have metadata.

This includes a new wp_termmeta table complete with get_term_meta(), update_term_meta() and all the other usual suspects.

You can read all about it in the core developer teams 4.4 Taxonomy Roundup post.

9. Embed Third Party Content by Pasting a Link

WordPress uses oEmbed to allow you to embed Tweets, Vimeo and Youtube videos, Soundcloud and all sorts of other fun things in your content. In fact, you can just paste a link to the resource in question and it will be converted to an embed for you.

When version 4.4 is released, WordPress will become an oEmbed provider, so as long as you are running 4.4 and so is the blog you want ot target, you can even link to other WordPress sites’ content in this way.

And that wraps it up. If you know any cool hacks or obscure features in WordPress, let us know your tips in the comments below.

It’s good to share

How to Import and Export posts from one website to another

Migrating content from one website to another website can be a headache you may face at some point. Copying specific posts and pages over to a new website involves copying table rows from one database to another. Doing this directly using a database management tool such as PHPMyAdmin requires knowledge of MySQL and a good understanding of how databases operate.

Thankfully, a more practical solution exists. The Official WordPress Importer allows you to easily export content into another website using an XML file. It allows you to move:

  • Posts, pages and other custom post types
  • Comments
  • Custom fields and post meta
  • Categories, tags and terms from custom taxonomies
  • Authors

In this post, I will walk you through the process of exporting and importing content between two WordPress websites. The procedure is simple and does not require any technical knowledge.

You need access to both websites in order to migrate the content successfully. Additionally, I strongly encourage you to take a back up of the database of both websites so that you can restore them if something goes wrong.

Exporting Content To Another Website

The core version of WordPress (i.e. with no plugins installed) has export functionality built-in. You will find the export feature in the main WordPress admin menu in the Tools section.

There are three options available. The first option backs up all content including posts, pages, comments, custom fields, categories and tags.

import-export-wordpress

Alternatively, you can choose to only export posts or pages. You can filter what is exported and only export content from particular categories, authors, date range and publication status.

The export function will also list any other post types that your website uses. For example, I use the Ninja Popups plugin on my personal blog to display pop up messages. As this is a custom post type, WordPress gives me the option of exporting the content for that post type to another website.

Once you have decided what content to export, save the XML export file to your computer.

Importing Content From Another Website

The WordPress import options can also be found in the main admin menu under tools. Import functionality is not built into the WordPress core, however there is a good reason for this.

In total, WordPress provides eight official import systems. Therefore, WordPress offers these import systems as plugins so that the core version of WordPress is not bloated.

import-wordpress

As we are importing from another WordPress website, we need to install the WordPress installer. You can do this by clicking on the WordPress link on the import page. This will bring up a pop up box that allows you to install the plugin directly through your website.

wordpress-import-plugin

Once the plugin has been installed and activated, you will be taken to the import page. This is where you upload the XML file you exported earlier.

You will then be given the option to assign imported authors to existing authors on your website. This is useful if the same authors exist in both websites. Alternatively, you can create a new account for each author’s posts.

This page also has an option for downloading attachments. When you select this, WordPress will attempt to import all of the images that are attached to the posts and pages you are importing.

That’s all there is to it. Your content will now be imported into your website. You can verify this by checking your posts and pages.

All information will be identical to what it was before. Therefore, posts and pages will have the same publication date and be assigned to the same categories.

It’s good to share