I have a plugin rejected by wordpress.org, one of the resasons is this:

Unsafe Requiring of Common Libraries Since you're using a common library, it's important that you enqueue it safely. Example(s):


Since that is a common library, you need to detect IF the code is already included and not re-include it, as doing so will cause conflicts if two people call the same defines and functions.

I understand about enqueueing jQuery and CSS - but this is a PHP script with multiple functions.

  1. If this script is common do I need to just reference it in the WP Core?
  2. Otherwise do I need to just look at the functions I'm calling and wrap them in a class (I'm uncertain about this) or can I refer to the whole php script?
  3. What is the standard way of doing this?



2 Answers 2

  1. No, it just means it's used by many plugins, not that Core includes it.
  2. Many of the functions in that library seem to use the JsonLdProcessor class that is also in that library, I'd check for that before including:


if ( ! class_exists( 'JsonLdProcessor' ) ) {
    require_once( 'jsonld.php' )

You can check included files first.

$included_files = get_included_files();

if (!in_array("jsonld.php",$included files)) {

  • 1
    get_includes_files() includes the whole path, so just checking the filename will probably return true, because just jsonld.php will not be included. some/path/to/jsonld.php would be. You'd need to loop through each file and check the filename. But I'm not sure I'd consider the filename a safe way to check. Better checking that actual code hasn't been loaded. Aug 25, 2017 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.