Professional WordPress Plugin Development. Brad Williams

Читать онлайн.
Название Professional WordPress Plugin Development
Автор произведения Brad Williams
Жанр Программы
Серия
Издательство Программы
Год выпуска 0
isbn 9781119666936



Скачать книгу

       BuddyPress: A suite of components used to bring common social networking features to your website. Features for online communities include member profiles, activity streams, user groups, messaging, and more!https://wordpress.org/plugins/buddypress

       WooCommerce: Advanced eCommerce solution built on WordPress. This is an extremely powerful plugin allowing anyone to sell physical and digital goods online.https://wordpress.org/plugins/woocommerce

       Custom Post Type UI: Easy‐to‐use interface for registering and managing custom post types and taxonomies in WordPress.https://wordpress.org/plugins/custom-post-type-ui

      Popular Plugin Tags

      Now you will look at some popular tags for plugins. Plugin tags are just like blog post tags, simple keywords that describe a plugin in the Plugin Directory. This makes it easy to search for existing plugins by tag. The following are popular examples:

       Twitter: Everyone loves Twitter for micro‐blogging and sharing links. You can find an abundance of Twitter‐related plugins for WordPress.https://wordpress.org/plugins/tags/twitter

       Google: With so many different services and APIs, Google is a popular plugin tag. Everything from Google ads to Google maps have been integrated into a WordPress plugin.https://wordpress.org/plugins/tags/google

       Blocks: Most plugins that include block editor integration also use the blocks tag. This is great for viewing the many different types of blocks available for WordPress.https://wordpress.org/plugins/tags/blocks

      Viewing popular plugin tags can provide inspiration when developing new plugins for WordPress.

      WordPress offers many advantages when using plugins. It's important to understand the advantages of building plugins to truly understand why you should spend time building them. This can also help when determining the need for a specific plugin in WordPress.

      Not Modifying Core

      One of the main advantages to plugins is the ability to modify the behavior of WordPress without modifying any core files. Core files refer to any file that is part of the default WordPress installation.

      Hacking core files can make it difficult to update WordPress when a new version is released. If you made any modifications to a core file, that modification would be overwritten when the update occurs. Keeping WordPress up‐to‐date with the latest version is essential in keeping your website secure.

      Modifying core files can also lead to an unstable website. Different areas of WordPress rely on other areas to function as expected. If you modify a core file and it no longer works as expected, it can cause instability and quite possibly break a completely unrelated feature in WordPress.

      Why Reinvent the Wheel?

      <?php if ( current_user_can( 'manage_options' ) ) { //any code entered here will only be executed IF //user is an administrator } ?>

      As you can see, it's easy to verify that a user has proper permissions prior to executing any code in your plugin. You will learn about user accounts and roles in Chapter 9, “Users and User Data.”

      As another example, look at sending an email in WordPress. Sure, you could create a new function in your plugin to send email, but why? WordPress has a handy function called wp_mail()for sending email. Look at this example:

      <?php $email_to = '[email protected]'; $email_subject = 'Plugin email example'; $email_message = 'How do you like my new plugin?'; wp_mail( $email_to, $email_subject, $email_message ); ?>

      As you can see, sending an email in WordPress couldn't be easier. Unless your plugin needs some customized emailing functionality, you don't need to re‐create this function from scratch. Using this function also ensures the widest adoption for sending emails from WordPress because you use the built‐in function.

      Using the available built‐in features of WordPress can greatly reduce the time to develop a plugin. Another advantage of not reinventing the wheel is that this approach more often than not will allow for your plugins to work across a greater number of servers and setups, thereby maximizing compatibility. Don't reinvent the wheel with features that already exist in WordPress.

      Separating Plugins and Themes

      A plugin can take control of the rendering process; therefore, the plugin can become a “theme.” Similarly, a theme can have plugin functionality included. Because of this, the difference between the two can sometimes become blurred, so why not just include your plugin code directly in a theme? This is a common question and one that can have a few different answers.

      Should themes include plugin functionality? The short answer is no. The primary reason for this is because plugins are meant to add features and functionality to WordPress, regardless of the theme used. This creates a nice separation between your website design and the functionality of your website. The reason this separation is needed is so your theme is not directly tied to the functionality required. WordPress is built so that you can easily change your design, or theme, at any point with just a couple clicks. If all plugin functionality existed in your theme and you switched themes, you will have lost all that functionality you required.

      Easy Updates

      WordPress makes it easy to update a plugin to the latest version. Every plugin installed from the WordPress.org Plugin Directory alerts you when a new version of the plugin has been released. Updating the plugin is as simple as clicking the update notification listed just below the plugin details on the Plugin screen of your WordPress Dashboard.

      Plugins not installed from the Plugin Directory can also be updated using the auto‐update functionality of WordPress. This is the method that premium plugins, specifically plugins that are sold on third‐party websites outside of the Plugin Directory, push out updates to their plugins. The plugin author must define where WordPress can download the latest version, and WordPress will take care of the rest. If the plugin author doesn't define this location, you must manually update the plugin.

      Keeping plugins updated is an important part of keeping your website free from security vulnerabilities and bugs.

      Easier to Share and Reuse

      Plugins are easy to share with others.