Skip to content

Create Plugin_Main class #4

@mehulkaklotar

Description

@mehulkaklotar

Description

The Plugin Main class will be used as the plugin’s most central class and will be used to bootstrap the Plugin Check plugin. Using a class allows all bootstrapping logic for the Plugin Check plugin to be consolidated in a single class, separating it from check logic and making it easier to maintain. This class will be responsible for setting up the plugin checker by registering hooks in WordPress and any other logic required, for example:

  • Adding hooks and filters to register the plugin check WP-CLI command
  • Enqueuing any assets required for the Plugin Check admin screen
  • Localization support

Plugin_Main class will be instantiated in the plugin-check.php file of the Plugin Check plugin. It will accept a single $main_file parameter in its constructor which is used to create the plugin context. The context of the plugin will be handled by the protected property $context (Plugin_Context).

Acceptance Criteria

  • A new Plugin_Main class is created
  • The class contains a single protected property named $context
  • The class __construct() method accepts a single parameter
    • (string) $main_file - A string representing the absolute path to the plugin main file
    • The $main_file parameter is passed to a new instances of the Plugin_Context class
    • The new Plugin_Context instances is assigned to the protected $context property
  • An empty add_hooks method exists in the Plugin_Main class to be updated later to register hooks to WordPress
  • A new Plugin_Context class is created. This class will be empty and setup as a basic scaffold for Create Plugin_Context class  #5
  • The plugin-check.php file is updated to include the following:
    • Constant WP_PLUGIN_CHECK_VERSION defined with the plugin version
    • Constant WP_PLUGIN_CHECK_MINIMUM_PHP defined with the minimum PHP version required for the plugin check plugin to work
    • A wp_plugin_check_load function exists which:
      • Checks the current PHP version is greater than the WP_PLUGIN_CHECK_MINIMUM_PHP constant
      • Checks the vendor/autoload.php file exists in the plugin
      • If the above checks pass
        • The vendor/autoload.php file is required in
        • The Plugin_Main class is instantiated passing __FILE__ into the constructor
        • The add_hooks() method is called on the instantiated Plugin_Main object

Metadata

Metadata

Assignees

Labels

InfrastructureIssues for the overall plugin infrastructure[Type] EnhancementA suggestion for improvement of an existing feature

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions