I suggest the namespace WPSE
for the code snippets we use in our answers.
Namespaces are a feature of PHP 5.3; WordPress core requires just PHP 5.2.4 currently. But even PHP 5.3 development has stopped already, PHP 5.4 is the stable version now, and 5.5 will be out soon.
PHP 5.2 was last updated in January 2011. Since then it didn’t even get security patches.
The WordPress ecosystem suffers from a copy&paste culture. We could use that to promote PHP upgrades. The more servers are updated, the sooner the core can update its requirements. I think we should discourage the use of insecure software.
The other benefit is cleaner code: function register_banner_widget()
is much easier to read than function wpse_80202_register_banner_widget()
. Namespaces are the better alternative to prefix everything.
Here is a sample plugin to illustrate how it could look:
<?php # -*- coding: utf-8 -*-
namespace WPSE;
/**
* Plugin Name: Namespace WPSE
* Description: Demo plugin for a common namespace on WordPress Stack Exchange.
* Plugin URL: http://wordpress.stackexchange.com
*/
\add_filter( 'admin_footer_text', __NAMESPACE__ . '\show_php_version' );
/**
* Show the current PHP version in admin footer.
*
* @wp-hook admin_footer_text
* @param string $text Default text.
* @return string
*/
function show_php_version( $text )
{
if ( ! \current_user_can( 'update_core' ) )
return $text;
return $text . ' PHP version ' . PHP_VERSION;
}
Your thoughts?
Rarst
. How do we combine -WPSE\Rarst\...
orRarst\WPSE\...
?WPSE\username\...
as this would (in a perfectPSR-0
world) meant that we'd have aWPSE
folder with subfolders that contains code snippets for each member. The other way 'round, we'd have all names as flat folder and then one unnecessary additional folder in it - which means less organisation and more clicks or keystrokes.