From cfdb6d15818ce1ce4c6db0841d688c0d03ee8607 Mon Sep 17 00:00:00 2001 From: "Ipstenu (Mika Epstein)" Date: Thu, 2 Jun 2022 09:44:05 -0700 Subject: [PATCH] Prefix Your Globals (#1726) * Prefix Your Globals documentation * Use consistent indentation in the file. * Expand the base explanation. * Improve the valid/invalid descriptions. * Use `` tags to mark valid/invalid code. * Expand the code samples. * Add a code comparison demonstrating how namespaces affect the prefixes. * Remove the unclear sentence regarding reserved prefixes. * Clarify the three character minimum length rule. Co-authored-by: jrfnl --- .../PrefixAllGlobalsStandard.xml | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 WordPress/Docs/NamingConventions/PrefixAllGlobalsStandard.xml diff --git a/WordPress/Docs/NamingConventions/PrefixAllGlobalsStandard.xml b/WordPress/Docs/NamingConventions/PrefixAllGlobalsStandard.xml new file mode 100644 index 0000000000..855dba8e6c --- /dev/null +++ b/WordPress/Docs/NamingConventions/PrefixAllGlobalsStandard.xml @@ -0,0 +1,115 @@ + + + + + + + 'ECPT_VERSION', '1.0' ); + +$ecpt_admin = new ECPT_Admin_Page(); + +class ECPT_Admin_Page {} + +apply_filter( + 'ecpt_modify_content', + $ecpt_content +); + ]]> + + + 'PLUGIN_VERSION', '1.0' ); + +$admin = new Admin_Page(); + +class Admin_Page {} + +apply_filter( + 'modify_content', + $content +); + ]]> + + + + + ECPT_Plugin\Admin; + +// Constants declared using `const` will +// be namespaced and therefore prefixed. +const VERSION = 1.0; + +// A class declared in a (prefixed) namespace +// is automatically prefixed. +class Admin_Page {} + +// Variables in a namespaced file are not +// namespaced, so still need prefixing. +$ecpt_admin = new Admin_Page(); + +// Hook names are not subject to namespacing. +apply_filter( + 'ecpt_modify_content', + $ecpt_content +); + ]]> + + + Admin; + +// As the namespace is not prefixed, this +// is still bad. +const VERSION = 1.0; + +// As the namespace is not prefixed, this +// is still bad. +class Admin_Page {} + ]]> + + + + + + + + mycoolplugin_save_post() {} + ]]> + + + wp_save_post() {} + ]]> + + + + + + + + MyPluginIsCool {} + ]]> + + + My {} + ]]> + + +