Skip to content

Create Plugin_Main class #4

Closed

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

Activity

  1. added
    [Type] Enhancement
    Infrastructure
    on Nov 23, 2022
  2. moved this from Backlog to Definition in Plugin Checkon Nov 29, 2022
  3. moved this from Definition to To Do in Plugin Checkon Nov 29, 2022
  4. added
    Needs Review
    on Nov 29, 2022
  5. felixarntz commented on Dec 1, 2022

    @felixarntz
    Member

    @jjgrainger The ACs here look good, but I think a problem here is that they already refer to Plugin_Context which is implemented as part of #5. So we should:

    Either approach works, I don't have a strong preference; but for things like this it is crucial to define the sequence as part of ACs so that the scope of the issue is clear.

    My only other more minor question here is on the instantiation of Plugin_Main: Is the idea that the plugin-check.php file would simply have new Plugin_Main( __FILE__ ) or it happen in a certain hook or so?

  6. moved this from To Do to AC Review in Plugin Checkon Dec 7, 2022
  7. moved this from AC Review to Definition in Plugin Checkon Dec 7, 2022
  8. removed
    Needs Review
    on Dec 7, 2022
  9. self-assigned this
    on Dec 7, 2022
  10. added this to the Sprint 1 milestone on Dec 7, 2022
  11. jjgrainger commented on Dec 7, 2022

    @jjgrainger
    Contributor

    Thanks @felixarntz

    I've updated the ACs to include the points you've raised.

    For the Plugin_Context class, I believe the second option is best where we create an empty Plugin_Context class so the code does not break and the code for the class is implemented in #5

  12. moved this from Definition to AC Review in Plugin Checkon Dec 7, 2022
  13. felixarntz commented on Dec 7, 2022

    @felixarntz
    Member

    @jjgrainger Thanks, LGTM!

  14. moved this from AC Review to To Do in Plugin Checkon Dec 7, 2022
  15. moved this from To Do to In Progress in Plugin Checkon Dec 16, 2022
  16. moved this from In Progress to Code Review in Plugin Checkon Dec 20, 2022
  17. Repository owner moved this from Code Review to Done in Plugin Checkon Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Infrastructure[Type] Enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions