Skip to content

Building a custom wordpress plugin.

  1. Plugin is hosted on github
  2. Plugin automatically installed by composer
  3. Can develop plugin in Wordpress and push changes to github.
  4. Will update installed plugin point to the github repo

Resources

Setup for development

  1. Create composer.json file in root directory. - composer init
  2. 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"
    }
    
  3. Add any necessary requirements for the plugin.
  4. Enable debug log in wp-config.php

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


Last update: April 13, 2020 15:50:46