Support » Plugin: Custom Logging Service » Global variable issue when running with WP-CLI

  • I’m having difficulty using the plugin from WP-CLI. It seems as if some of the global variables which Custom Logging Service uses — for example, $severity_list and $clgs_last_log in custom_logging_service.php, are not global and so remain unset, causing problems later on when they’re used.

    I’m confused by this because they’re defined in the top level of the file, so I would assume they *must* be globals because of PHP’s variable scope; but I wonder if WP-CLI is doing some kind of strange voodoo that prevents them from actually being global, despite being on the top-level.

    $cgls_db is already explicitly marked global and there are no problems with that variable.

    Marking those variables global seems to fix my problem. I’m not sure if there are other potential bugs lurking due to the lack of an explicit global declaration.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author ccprog

    (@ccprog)

    Thank you for the report. I never looked into WP-CLI, so I’ll have to test for myself.

    Varables declared in a plugin, as I understand it, are not really global, as the plugin file itself seems to be loaded from inside a function. For normal use, this only has effects for certain specialized hooks like plugin activation. Maybe the CLI does things differently.

    I am in the middle of a general overhaul anyway (to implement REST API endpoints), so look out for a new version within the next two weeks.

    Thread Starter ed-fusionary

    (@ed-fusionary)

    Great to hear! I’ll keep an eye out for the new version.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Global variable issue when running with WP-CLI’ is closed to new replies.