Building a custom wordpress plugin.¶
- Plugin is hosted on github
- Plugin automatically installed by composer
- Can develop plugin in Wordpress and push changes to github.
- Will update installed plugin point to the github repo
Resources¶
- Boilerplate template - WORDPRESS PLUGIN BOILERPLATE GENERATOR
- GenerateWP Generate for WordPress Developers
- Docs
Setup for development¶
- Create composer.json file in root directory. -
composer init
- Add “type”: “wordpress-plugin” to get composer to install it in the wordpress plugin directory
{ "name": "", "description": "", "authors": [ { "name": "Johan Martin", "homepage": "http://www.johan-martin.com", "role": "developer" } ], "keywords":[ "Wordpress", "Plug-in", ], "type": "wordpress-plugin" }
- Add any necessary requirements for the plugin.
- Enable debug log in wp-config.php
define( 'WP_DEBUG_LOG', true );
- will write to /wp-content/debug.log - Debugging in Wordpress
Wordpress Plugin Development from Scratch¶
- Create Contact Form plugin to submit contact information via API.
- Use Composer.
- PHP 7.0
Setup for plugin development.¶
- Update composer
sudo composer self-update
- Create folder for plugin
mkdir paseo-contact-form
- Create composer.json
composer init
- For type use wordpress-plugin
- Create git repository -
git init
- Create README.md for github.
- Include information about plugin in README file
- Create .gitignore file
- Add wp-config.php file to insure it does not get committed.
- Add files to repo -
git add .
- Commit files -
git commit -a -m 'initial commit'
- Create github repository
- paseo-wp-form-api - name or repo
- Add as remote repo to your local repository.
git remote add origin git@github.com:catenare/paseo-wp-form-api.git
git push -u origin master
- Plugin can now be added to your Wordpress site as a dependency.
Create the plugin file with header information¶
touch paseo-contact-form.php
- Add header requirements to the file- Header Requirements
- Plugin can now be enabled on the Wordpress site.
- Create dev-master branch. Seems like you can’t use the vcs plugin setup with straight master
git checkout -b dev-master
git push origin --all
- push all the branches to github.
Enable plugin in Wordpress.¶
- Edit composer.json file in Wordpress application folder.
- Add github repository under “repositories” section.
"respositories": [ { "type": "vcs", "url": "https://github.com/catenare/paseo-wp-form-api.git" } ]
- Add plugin to “require” section.
"paseo/contact-form-api": "dev-master"
- Plugin is now installable in Wordpress Admin.
Setup plugin in Wordpress¶
- Run
composer update
to install necessary dependencies. - Activate plugin.
Using namespace and classes for plugin development¶
Using database in wordpress¶
Multi-site development¶
- Making Plugins Compatible with WordPress Multisite
- Wordpress Create a Network
- How to Build a Multisite Compatible WordPress Plugin
- Write a Plugin for WordPress Multi-Site
Last update: April 13, 2020 15:50:46