is_singular() in mu-plugins not working

When the active_plugins option is retrieved, WordPress does not yet know what page has been requested, so this approach will not work. In order to achieve your objective, you would selectively activate the plugin (rather than selectively deactivate the plugin), but this may cause problems and destabilize your site (untested): add_filter( ‘option_active_plugins’, static function ( … Read more

Site Health and PHP 8.1

No, the constants WP_HOME and WP_SITEURL are not required to be defined. These constants would overwrite the URLs in the Settings > General fields, so for most sites they are undefined.

Strip and print only the numbers found in current’s post excerpt (even if they are without space)

If you have a strict list of allowed years: $allowed_years = array(‘2018’, ‘2019’, ‘2020’, ‘2021’, ‘2022’, ‘2023’, ‘2024’); Then why are you using regex when you can search for those years directly: function vyperlook_get_years_in_text( string $text, array $allowed_years ) : array { $found_years = []; // the years we found // for each year that … Read more

How to make WordPress Plugin run on single specific Admin Page

You should use the load-edit.php action hook, and check for your post type (untested): add_action( ‘load-edit.php’, static function () { $screen = get_current_screen(); if ( empty( $screen->post_type ) || ‘myposttype’ !== $screen->post_type ) { return; } new the_function(); } ); You could also use the current_screen hook, but load-edit.php seems more correct.

REST API – filters not working inside plugin class

This is a problem: public function __contruct() it should be __construct, the S is missing, meaning there is no constructor and the add_filter calls never happen The function that registers the routes also never runs because the add_action call is commented out: //add_action( ‘rest_api_init’, array( $this, ‘extend_default_routes’ ) ); This means the constructor never runs, … Read more