This repository contains a custom plugin developed by following the video tutorials from LinkedIn Learning by Jeff Starr to customize the admin area and login page appearance. This repository also contains exercise files, helpful resources and guidelines for developing WordPress plugins. It includes useful links, best practices, and code examples to help you get started with your own plugin development.
Customize the Login Page with following things
- URL for login link
- Title attribute for login link
- Enable custom login styles
- Custom login message
Customize the admin area with the following customizations
- Custom footer text
- Remove toolbar items
- Choose default admin color scheme for new users
plug-basics folder containt the short examples for learning purposes. All files and folders are self explanatory with comments. Most of the files are single file plugin that can be test by moving the files into the plugins directory of the WordPress project. Rest of the repository contains the learning plugin that can be installed just like a normal WordPress plugin.
Following is the list of the plugins that can be used for the development puporses. Some of them are out-dated bu still can be consider to use.
- Developer By Automattic
- WP-Developer-Tools By PressPage Entertainment Inc. DBA PINGLEWARE
- Query Monitor By John Blackbourn
- Debug Bar By wordpressdotorg
- Debug Queries By Frank Bültge
- Log Deprecated Notices By Andrew Nacin
- Simply Show Hooks By Stuart O'Brien, cxThemes
- Loco Translate By Tim Whitlock
- Theme Switcha – Easily Switch Themes for Development and Testing By Jeff Starr
- Debug Objects By Frank Bültge
- WP-FirePHP By Frank Bültge
- Debug Bar Rewrite Rules By Frédéric GILLES
- WP Developer Assistant By Chris Jean
- Latency Tracker By Shaun Kester
- TPC! Memory Usage By Chris Strosser
It's best practice to turn the debug mode on for the development purpose to keep an eye on the errors and warning. Debug mode should be off for the production project. Add the following lines into the wp-config.php file
ini_set('display_errors','on');
ini_set('error_reporting', E_ALL );
define( 'WP_DEBUG', true ); // Turn on the debug mode.
define( 'WP_DEBUG_LOG', true ); // Log the errors and warning in the debug.log file located in the **/wp-content/** directory
define( 'WP_DEBUG_DISPLAY', false ); // This prevent to display the errors and warning on the public facing pages of the site.
define( 'SAVEQUERIES', true);
To turn off the debug mode use the following lines.
ini_set('display_errors','off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', false);
define('WP_DEBUG_DISPLAY', false);
define( 'SAVEQUERIES', false);
Visit 5 Ways to Debug WordPress to learn more about debugging.
Plugin name should match with the following. Let's suppose the name of the plugin is My Plugin.
- main plugin folder i.e. /my-plugin/
- main plugin file i.e. /my-plugin/my-plugin.php
- Text Domain i.e. 'my-plugin'
Below is the list of WordPress default APIs.
- Dashboard API
- Database API
- HTTP API
- REST API
- File Header API
- Filesystem API
- Metadata API
- Options API
- Plugin API
- Quicktags API
- Rewrite API
- Settings API
- Shortcode API
- Transients API
- Widgets API
- XML-RPC API
Visit the following links to learn more about action and filter hook.
- Activation Hook - Run on plugin activation.
- Deactivation Hook - Run on plugin deactivation.
- Uninstall Hook - Run on deleting the plugin,
Pluggable Functions are the functions that can be redefined by the developers in the plugins and themes.
To build secure plugin, must use data validation, data sanitization, nonces etc.
Guide to create the best plugin directory structure.
- Separate admin assets from public assets
- Put geenral PHP files in the /includes/ folder
- Add a proper file header to the main plugin file
- Keep the root directory as uncluttered as possible
- Single plugin file, containing functions
- Single plugin file, containing a class
- Main plugin file, then one or more class files. Demo
Always include the admin and public facing files on respective screens using the conditional tags.
List of PHP functions that used as a conditional tags.
- For Variables - isset()
- For Functions - function_exists()
- For Classes - class_exist()
- For Constants - defined()
- Learn more about Conditional Tags
To add a custom admin sub-menu page under the already created page use the following parent page slugs.
Parent Menu Title | Parent Slug to Use |
---|---|
Dashboard Menu | index.php |
Posts | edit.php |
Pages | edit.php?post_type=page |
Media | upload.php |
Comments | edit-comments.php |
Temes | themes.php |
Plugins | plugins.php |
Users | users.php |
Tools | tools.php |
Settings | options-feneral.php |
Follow these 3 steps to internationalize your plugin for greater reach.
- Phase 1: Prepare folders and files
- Add a /language/ folder.
- Use the same slug/name for the main plugin folder and file.
- Add "Text Domain" and "Domain Path" to the file header. (main plugin file and readme.txt file)
- Phase 2: Add localization functions
- include load_plugin_textdomain().
- Replace all text strings with a localization function. __(), e(), x(), esc_html(), esc_html_e(), esc_html _x(),
- Phase 3: Generate the POT file
- Generate the POT file.
- Tools to use.
- Poedit - Standalone: works on all major operating systems. Enables translations, template generation, and more.
- Loco Translate - WordPress Plugin. Enable translations, template generation, and more.
Visit the following links to read more about Plugin Internationalization
- Super Admin
- Administrator
- Editor
- Author
- Contributor
- Subscriber
- post
- page
- attachment
- revision
- menu
- category
- post_tag
- link_category
- post_format
- Post get_post_meta(), update_post_meta(), add_post_meta(), delete_post_meta()
- User get_user_meta(), update_user_meta(),add_user_meta(), delete_user_meta()
- Comment get_comment_meta(), update_comment_meta(), add_comment_meta(), delete_comment_meta()
- Term get_term_meta(), update_term_meta(), add_term_meta(), delete_term_meta()
Purpose | Method |
---|---|
Escape a SQL Query | $wpdb->prepare() |
Get generic results | $wpdb->get_results() |
Get a variable | $wpdb->get_var() |
Get a column | $wpdb->get_col() |
Get column information | $wpdb->get_col_info() |
Get a row | $wpdb->get_row() |
Insert row | $wpdb->insert() |
Replace row | $wpdb->replace() |
Update row | $wpdb->update() |
Delete row | $wpdb->delete() |
Run general query | $wpdb->query() |
- notice-error error message displayed (red border)
- notice-warning warning message (yellow border)
- notice-success success message (green border)
- notice-info info message (blue border)
- Stores cached data in the options table
- Transients expire at a specified time
- Useful for storing temporary data
- Functions - get_transient(), set_transient(), delete_transient()
- User Transients Manager wp plugin to work with trnsient.
- Transients API Documentation
- WP Crons only run on page load. So when a page is loaded, WP-Cron checks the queue of schedules tasks and run anything that is past the scheduled time.
- While System cron runs at specific times like 3:16 in the morning.
- Wp-Cron runs at specified intervals like every hour, twice daily, once in a day.
- To run wp-cron manually, visit this URL. https://example.com/wp-cron.php
- To disable the cron - Define this in wp-config.php file
define( 'DISABLE_WP_CRON', true );
- Enable alternate WP-Cron functionality
define( 'ALTERNATE_WP_CRON', true );
- wp_schedule_single_event() - Schedule a hook that only fires once
- wp_unschedule_event() - Unschedule a previously scheduled event
- wp_get_schedule() - Retrieve the schedule for the specified hook
- Learn more about WP CRON
- Advanced Cron Manager: Use this plugin to check registered crons.
Hire me for your next WordPress plugin development from one of the following.