• Resolved Imagejim5471

    (@jim5471)


    Hi there,

    I have a question about the 1.7.0 update which is listing a number of new errors (below) referring to “theme/plugin prefix”.

    Can’t seem to find anywhere that has a specific answer and haven’t been able to work it out !

    What would be the “plugin prefix” for a plugin named “My Plugin” ?
    Do I need a line of code to set the “plugin prefix” ?
    It would be useful if PCP stated what the “theme/plugin prefix” was so you can work out what is wrong.

    ERRORS:
    WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound
    Classes declared by a theme/plugin should start with the theme/plugin prefix.

    WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
    Global variables defined by a theme/plugin should start with the theme/plugin prefix.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Imagejim5471

    (@jim5471)

    Answering my own question…

    Turned out the problem was PCP wasn’t able to traverse this one plugin. I realised this when I moved to a different plugin.

    The “plugin prefix” for a plugin named “My Plugin” is “my_plugin”.

    The WordPress documentation (below) does not include the “theme/plugin prefix” requirement.

    https://developer.wordpress.org/plugins/plugin-basics/best-practices/

    This document says…
    “All globally accessible code should be prefixed with a unique identifier…
    In order to prevent conflicts with other plugins, your prefix should be at least 4 letters long, though we recommend 5″

    So according to WP it doesn’t need to be the “theme/plugin prefix”.

    https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/

    In this document there is no mention of using a prefix for globals.

    This shows that PCP is not presently aligned with WP best practice.

    Clearly a prefix is required and at least 4-5 letters would be my choice rather than the “theme/plugin prefix” which is now causing me problems.

    • This reply was modified 5 months, 2 weeks ago by Imagejim5471.
    • This reply was modified 5 months, 2 weeks ago by Imagejim5471.
    Thread Starter Imagejim5471

    (@jim5471)

    More…

    The current github documentation does not specify “theme/plugin prefix” for prefixing.

    https://github.com/WordPress/plugin-check/blob/trunk/docs/checks.md

    says this…
    “prefixing – Checks plugin for unique prefixing for everything the plugin defines in the public namespace”

    Thread Starter Imagejim5471

    (@jim5471)

    I have found the problem.

    My plugin uses SimpleXLSX from https://github.com/shuchkin/simplexlsx/

    This is a single php file: SimpleXLSX.php

    When this file is included in the plugin, PCP throws “theme/plugin prefix” errors. Take the file out and the errors go away.

    PCP reports no errors for SimpleXLSX and there are no PHP errors.

    Thread Starter Imagejim5471

    (@jim5471)

    All sorted -thanks

    Plugin Author ImageDavid Perez

    (@davidperez)

    Great that you found it! All global variables, constants and functions basically have to be prefixed.

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.