Questions tagged [namespace]
29 questions
0 votes
1 answer
55 views
Admin notices action failing to fire
For some reason I can't get the admin_notices action to work. For context, I am trying to show errors when my custom post type is saved and fields fail validation. However I have stripped out most of ...
0 votes
1 answer
560 views
Why is a wp function used in current PHP namespace's callback not resolved to global scope?
Imagine the following script: <?php namespace MySpace; class MyClass { public static function execute() { // Do something post_exists(1,'','','my_post_type'); } } ?> I'm now ...
0 votes
0 answers
25 views
How do I add an action using namespaces, and file separation? [duplicate]
I'm working on a plugin, and I'm trying to get to grips with namespaces and how they work with actions. In a separate file, I have a single function with a namespace declared at the top: namespace ...
0 votes
1 answer
419 views
How do I define and register a shortcode function in a namespaced functions.php file?
I wrote a function in my theme's functions.php and am attempting to register it with add_shortcode() as shown in the Codex: <?php /** * theme's functions.php */ namespace MyNamespace; //[foobar]...
0 votes
0 answers
608 views
Does the namespace always have to be prefixed to the function or class when referencing callbacks in WordPress, even when they are in the same file?
I want to use namespaces instead of prefixes for a plugin, since now the minimum supported PHP version for WP is 5.6.20 and namespaces can be used. But it does not seem to work with hooks: namespace ...
0 votes
1 answer
499 views
Getting wp_timezone undefined within a namespace
My workaround at the moment, within a shortcode, is to just copy the WP native code to get the Timezone within my (namespaced) class: new \DateTimeZone( $this->wp_timezone_string() )); private ...
0 votes
1 answer
185 views
Use Composer Package inside class - Namespacing error
I have my theme, with a folder called classes, with a single class: wp-content |- themes |- mycustomtheme |- classes |- FooBar.php In FooBar, I would like to use this package here: ...
0 votes
1 answer
513 views
How to call a WP Class inside my theme
I wrote a WP theme using namespaces and autoload. Everything went smooth until I started to use WP classes which I understand of course because I understand how namespacing works. My question is, is ...
0 votes
1 answer
274 views
Why does wp_die() not work when inside a namespace?
Consider the following code copied from ACF docs, refactored to work inside a namespace: add_filter('acf/location/rule_match/user', __NAMESPACE__ . '\acf_location_rule_match_user', 10, 4); function ...
1 vote
1 answer
2k views
Namespaces declared by a theme/plugin should start with the theme/plugin prefix. Found: "eustatos\test_plugin"
I want to use namespace in my plugin. And I have error after PHP_Code_Sniffer check. Namespaces declared by a theme/plugin should start with the theme/plugin prefix. Found: "eustatos\test_plugin". (...
1 vote
1 answer
1k views
Sage WordPress - Plugin Namespace: Not Found
I originally posted in the Sage forum here. I'm trying to get a plugin to work but it's not, and I feel like it's a very general Namespace problem, and not something with the actual plugin, so I ...
1 vote
1 answer
279 views
How to reference a function from a class in a different file which is also namespaced?
For example I am inside a file1.php with a namespaced class, like so: <?php namespace FrameWork\CPT; class CPT{ ..... public function register_custom_post_type() { $args = array( '...
0 votes
1 answer
955 views
Access WP_REST_Server from within plugin namespace
I am new to OOP and developing plugins. I have developed a plugin using the Plugin-Boilerplate with namespace. I expanded the boilerplate to include a REST folder and class so I could create custom ...
0 votes
1 answer
2k views
Override plugin class which has namespace
I would like to override this plugin class in child theme : class-config.php namespace um; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'um\Config' ) ) { /** * Class Config ...
0 votes
1 answer
383 views
Problem with autoloader and namespaces
I'm writing a simple plugin with oop and using namespaces and autoloading. Here is my main file: add_action('plugins_loaded', array(My_Test_Plugin::get_instance(), 'plugin_setup')); class ...