Giter Club home page Giter Club logo

starter-plugin's Introduction

Ultimate WordPress Plugin Main File

How to leave legacy technologies behind

Source code in plugin-name.php needs PHP 7 which is present on more than 90% of WordPress installations.

Support my work

Please consider sponsoring me monthly if you use my packages in an agency.

Sponsor

Parts of plugin main file

  • Header comment
  • PHP strict types
  • PHP namespaces
  • Prevent direct execution
  • Load autoloader
  • Prevent double activation
  • Define constant values in an immutable container
  • Load translations
  • Check requirements
    • PHP and WordPress minimum version
    • Multisite installation
    • Other plugins
    • Current theme
    • Composer packages
  • Hook plugin activation functions
  • Support WP-CLI
  • Display admin notice and deactivate plugin on error

💡 Anything else goes into a separate file.

What to avoid

  • ❌ Global constants
  • ❌ Global functions
  • ❌ Classes without namespace
  • ❌ Loading PHP files with require
  • ❌ Code with side-effects outside the main file
  • ❌ Immediate execution without add_action in the main file
  • ❌ Conditional function or class definitions

Required PHP Version Required WP Version

Installation

  1. Get the plugin ZIP from ...
  2. Upload to Plugins / Add new / Upload /wp-admin/plugin-install.php?tab=upload

Usage

  1. Adjust settings ...
  2. Or add a hook add_filter('project/enable', '__return_true'); to functions.php

starter-plugin's People

Contributors

szepeviktor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

starter-plugin's Issues

WordPress System Status Query 🧐

  • PHP version:
  • WordPress version:
  • List of active Plugins: screenshot(s) of /wp-admin/plugins.php?plugin_status=active
  • Important Plugin Version:
  • Active Theme:

The Ultimate WordPress Plugin Main File

  • Prevent direct execution (ABSPATH)
  • Prevent double activation (MY_FILE)
  • Check requirement: PHP, core, multisite, plugin, library
    wp => '5.1', php => '7.0', multisite => '5.1', plugins => ['wordpress-seo'], packages => ['psr/http']
    https://github.com/wearerequired/wp-requirements-check/blob/master/WP_Requirements_Check.php
  • Define constants, inspect their usage:
    • MY_FILE
    • MY_PATH
    • MY_SLUG
    • MY_URL
    • MY_VERSION
  • Call register_activation_hook(), register_deactivation_hook(), register_uninstall_hook()
  • Load autoloader
  • Load translations
  • Support WP-CLI
  • Run database migrations
  • Bootstrap the plugin in plugins_loaded
  • 💡 Anything else goes to its own file

Checklist for working on an existing plugin ✔

How to write commit messages?

$temp: $late

How to name PR branches?

$temp-$late

What code should we write daily?

  1. openly procedural
  2. masqueraded as a class, e.g. static methods and properties
  3. OOP

Where should we write typehints?

  1. In code (e.g. method signatures)
  2. In PHPDoc blocks
  3. Nowhere

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.