add_action in namespace not working

Before going too far down this path I would suggest that you familiarize yourself with PHP name resolution rules. To answer your actual question – When you namespace functions, the fully qualified name of those functions includes the namespace. In your example, you have defined two functions: \myPlugin\add_activation_notice and \myPlugin\activation_notice. When calling either of these … Read more

Getting wp_timezone undefined within a namespace

Thank you Tom J Nowell for the insightful comment above. Turns out that wp_timezone is a relatively recent addition to WordPress, and didn’t exist in the version of WP I was developing in. It was added, as the Changelog says, in v5.3. I was using v5.2. The function itself: function wp_timezone() { return new DateTimeZone( … Read more

How do I define and register a shortcode function in a namespaced functions.php file?

Thanks to Stanislav Khromov (also active on WPSE!), I learned any Callable referenced in add_shortcode() must be fully qualified, even if it is defined in the same file you’re referencing it. <?php /** * theme’s functions.php */ namespace MyNamespace; //[foobar] function foobar_func( $atts ){ return “foo and bar”; } add_shortcode( ‘foobar’, ‘\MyNamespace\foobar_func’ ); You may … Read more

Why is a wp function used in current PHP namespace’s callback not resolved to global scope?

From your comment: Apparently the function can indeed not be used on the frontend in wp (see here), can anyone confirm this? I can confirm that the post_exists() function can be used on the front-end, but you need to manually load the file that defines the function, which is wp-admin/includes/post.php — see the “File: <path>” … Read more

Autoloader not finding classes from my plugin

Given the first PHP code snippet you posted, I don’t see that you’re using the class yet, which explains why you’re not seeing your classes in the autoload error log that you’re debugging with. Note that use will not trigger PHP’s autoloader. use My_Plugin\Includes; You need to actually instantiate a class, check that it exists, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)