Kindle Notes & Highlights
Read between
July 17, 2020 - December 31, 2023
Note If you are intending to build an app at Facebook scale, this is not the book for you. Ask your CTO what part of their billion-dollar budget is allocated to your app and which engineers you need to headhunt from Google and Amazon to build your custom solution.
Think of each WordPress release as an application framework bundled with a sample blogging app.
In WordPress, plugins are the proper place to store new data structures, complex business logic, and custom post type definitions.
You should never, ever, ever, ever1 alter any other core WordPress files. Hacking core files is a bad idea because upgrading to a new version of WordPress will override your changes. The only directory you should need to interact with is wp-content because it contains your plugins, themes, and uploaded files.
It is a good idea to check for the mu-plugins folder on any existing site you start working on to see whether it contains any plugins, and if so, to determine what they do.
We spend a lot of time working with actions and filters. Understanding this section is important to your growth as a WordPress developer.
Tools like VirtualBox, Vagrant, and Docker are also popular in the WordPress community. These tools are especially good for certain automated testing and deployment schemes.
The Akismet plugin integrates with Akismet.com to automatically filter out spam comments from your blog.
all WordPress plugins must use the General Public License, Version 2 (GPLv2), code license.
you can choose to download and modify an existing plugin, or build a new one from scratch.
The true power of WordPress for app developers is that you can make your own custom plugin to extend WordPress anyway you see fit.
To create a plugin, first create a new folder in wp-content/plugins called my-plugin and make a PHP file in that folder called my-plugin.php.
If you are new to PHP and WordPress, a good way to kickstart your skills is to download and analyze the code in other plugins to see how they are doing what they do.
You could take any plugin in the repository, change the name, and release it as a totally new plugin. Doing this could get you into a bar fight, so we suggest that you don’t “fork” plugins like this unless you are also planning to improve on and maintain the new plugin.
globalized, you can use $wpdb in custom functionality to select, update, insert, and delete database records. If you are new to WordPress and aren’t familiar with all of the functions to push and pull from the database, $wpdb is going to be your best friend.
use the dbDelta() function to create the database table. This function creates a new table if it doesn’t exist. Or if a table with the same name already exists, it figures out the correct ALTER TABLE query
There are two main ways of escaping values used in your SQL queries: you can wrap your variables in the esc_sql() function (see Example 3-2) or you can use the $wpdb->prepare() method
There are some useful free plugins that can help extend your web application. Plugins exist for almost every purpose, but if you can’t find the exact functionality you’re looking for, you could modify an existing plugin (open source, right?) or create an entirely new one if you are up for the challenge.
Advanced Custom Fields (ACF) allows administrators to easily set up available custom fields for any post type.
The WP All Import plugin comes in handy if you are looking to import data into WordPres from another source that is in either an XML or CSV file, which are two formats not routinely accepted by WordPress.
The custom tables that store groups and friend relationships between users are much easier to understand and faster to query against than if these kinds of things were stored as some combination of posts, user meta, and taxonomies.
There are approximately 485 WordPress plugins that extend or integrate with BuddyPress in one way or another.
you should follow some thought process when deciding whether a particular feature should be coded as a module of your app’s plugin or theme or as a separate plugin. The main benefactor of your good planning at this step will be your developers (maybe just you).
if you are developing a theme that will be distributed, and that relies on CPTs or other customization that would typically be coded in a plugin, it might make sense to instead include that within your theme.
If moving code from a plugin file to a theme file makes it easier to work with, do it.
WordPress will scan all of the .php files in your active theme’s folder and subfolders (and the parent theme’s folder and subfolders) for templates. Any files found with a comment that includes the phrase Template Name: in it will then be made available as a template.
CPTs are what really makes WordPress a content management system.
embed content from supported oEmbed providers
If you get tired of writing functions to register the various custom post types that you want to use, you can use this cool plugin called Custom Post Type UI.
Generally, terms that group different posts together should be coded as taxonomies, while data specific to each individual post should be coded as post meta fields.
When creating meta boxes and custom meta fields, we recommend utilizing the CMB2 plugin. You can easily include CMB2 in your theme or any custom plugin to give you a fast and easy way to create custom meta boxes and the meta fields inside them.
You can organize things in other ways, but we find that having all of your CPT-related code in one place helps a lot.
It’s useful to understand the trick WordPress is using to allow you to access user meta on demand as if each meta field were a property of the WP_User class. The WP_User class is using overloaded properties or the __get() “magic method.”
If you find yourself checking for someone’s role before performing certain actions, you should take it as a hint that you need to add a new capability.
Any class method starting with two underscores is considered a magic method in PHP because it is magically kicked off during certain events.
A cron job is a script that is run on a server at set intervals.
On Unix systems, the cron service runs every minute (generally) to check whether there is a script to run. In WordPress, that check is done on every page load. So if no one loads your website in a given day, or only pages from a static cache are loaded, your cron jobs may not fire that day.
If you aren’t distributing your code or don’t mind telling your users that they must set up server-side cron jobs, you don’t need to schedule your cron events in WordPress at all.
The core namespace is wp. This namespace is reserved and should not be used in creating custom endpoints.
New endpoints can be used to expose CPTs and other custom data your application uses
Paid Memberships Pro extends the existing /users/ route to include a new endpoint for checking a user’s membership level.
you can install the Classic Editor plugin on that site. This plugin allows you to selectively or globally use the classic editor to edit any post or page.