When I was talking about ThemeForest, I mentioned we had code on WordPress.org that made me sigh. Or cry depending on the day.
Here it is:
if (!defined('WP_CONTENT_URL')) define('WP_CONTENT_URL', get_option('siteurl').'/wp-content'); if (!defined('WP_CONTENT_DIR')) define('WP_CONTENT_DIR', ABSPATH.'wp-content'); if (!defined('WP_PLUGIN_URL')) define('WP_PLUGIN_URL', WP_CONTENT_URL.'/plugins'); if (!defined('WP_PLUGIN_DIR')) define('WP_PLUGIN_DIR', WP_CONTENT_DIR.'/plugins');
Why do I sigh?
It’s not needed.
You can use functions to determine those directories and while I’m sure someone’s thinking “But
WP_PLUGIN_DIR is shorter than
plugins_url()!” it’s not.
That code block above was used so that one line of code could exist.
Those four lines, plus the include, could be replaced with this:
include( plugins_url( 'settings.php' , __FILE__ ) );
So yes, I sigh. Because with just a little work, you could see that there’s a more efficient way to make your plugin smaller.