[wp-trac] [WordPress Trac] #60414: Core PHP autoloader proposal
WordPress Trac
noreply at wordpress.org
Thu Aug 8 23:04:31 UTC 2024
#60414: Core PHP autoloader proposal
-------------------------------------+-------------------------------------
Reporter: aristath | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: General | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit- | Focuses: performance,
tests early | sustainability
-------------------------------------+-------------------------------------
Comment (by peterwilsoncc):
I figured I'd check the practicality of overriding a core class.
Regrettably it's exceptionally practical as is.
{{{#!php
<?php
namespace No\No\No\No\No;
spl_autoload_register( __NAMESPACE__ . '\\wp_post_replace', true, true );
function wp_post_replace( $class_name ) {
$class_name = strtolower( $class_name );
if ( 'wp_post' !== $class_name ) {
return;
}
require_once __DIR__ . '/overrides/class-wp-post.php';
}
}}}
Like @spacedmonkey, I think it would be good to wait for Ari's
investigation in to seeing if it is possible to prevent it.
Along similar lines, it's also regrettably practical to override a
WordPress JavaScript file as Core provides a filter for the purpose:
{{{#!php
<?php
namespace No\No\No\No\No;
add_filter( 'script_loader_src', __NAMESPACE__ . '\\wp_data_replace', 10,
2 );
function wp_data_replace( $src, $handle ) {
if ( 'wp-data' === $handle ) {
$src = content_url( '/mu-plugins/overrides/wp-data.js' );
}
return $src;
}
}}}
The code differs but it's something WordPress contributors do in the
Gutenberg plugin.
As contributors, it's generally considered that a plugin replacing
WordPress scripts is to run WordPress outside of the ''warranty''. Could
replacing classes be considered in the same way and would it be possible
for the plugin review team to block plugins replacing core classes?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60414#comment:40>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list