Questions tagged [namespace]

The tag has no usage guidance, but it has a tag wiki.

Filter by
Sorted by
Tagged with
0 votes
1 answer
26 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 ...
user avatar
  • 286
0 votes
0 answers
22 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 ...
user avatar
  • 206
0 votes
1 answer
29 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]...
user avatar
0 votes
0 answers
62 views

WooCommerce custom product type not saving with namespaces

I am try to create my custom product type, but when I save it is still simple product. This because I am using namespacees but I can not figure out the problem. This is class with new pt namespace ...
user avatar
0 votes
0 answers
134 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 ...
user avatar
0 votes
1 answer
168 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 ...
user avatar
  • 497
0 votes
1 answer
62 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: ...
user avatar
  • 598
0 votes
1 answer
271 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 ...
user avatar
0 votes
1 answer
160 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 ...
user avatar
  • 103
1 vote
1 answer
869 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". (...
user avatar
  • 111
1 vote
1 answer
785 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 ...
user avatar
  • 125
1 vote
1 answer
68 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( '...
user avatar
  • 103
0 votes
1 answer
449 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 ...
user avatar
  • 51
0 votes
1 answer
1k 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 ...
user avatar
0 votes
1 answer
142 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 ...
user avatar
  • 325
0 votes
0 answers
53 views

Hiding class namespace from plugin's extensions

I'm developing a plugin using this boilerplate and I designed it to be extensible. The boilerplate supports namespacing and uses it and namespaces are bind to folder structure. The extensible part is ...
user avatar
  • 66
0 votes
1 answer
368 views

Update body class based on theme as well as a html attribute

I just started using wordpress. Now I'm trying to create a theme for a static web page I wrote. For that web page I'm using barbajs, which is why I have a html tag (in my case a section tag) with a ...
user avatar
  • 195
0 votes
1 answer
239 views

wp_localize_script() and JavaScript namespaces

As you are aware, wp_localize_script() allows the creation of a JavaScript object from a PHP object. So, after running the code in the example below: wp_localize_script('my-script', 'var_name', $var)...
user avatar
  • 2,004
0 votes
1 answer
2k views

REST route from a plugin not working if WordPress is installed in a subdirectory

This question is basically a copy from the trac ticket I created #42973. On the Theme Sniffer plugin I replaced admin-ajax.php with REST endpoints. So when you want to run a check against the theme ...
user avatar
  • 1,894
0 votes
1 answer
972 views

Autoloader not finding classes from my plugin

I am trying to work with autoloader in my plugin. In the main file of my plugin I have use My_Plugin\Includes; require_once( plugin_dir_path( __FILE__ ) . 'includes/class-autoloader.php' ); $...
user avatar
  • 1,894
8 votes
2 answers
7k views

add_action in namespace not working

I decided to namespace my plugin, and I got it all to work, except in my main plugin file. I added two actions in that plugin, before calling the init method of the plugin. <?php namespace ...
user avatar
  • 1,894
0 votes
0 answers
1k views

Custom Rest API namespace and endpoints are responding with 404 & 503 errors

I am new to WordPress plugin development. I was developing a plugin for WordPress that would be used to create mobile apps for WordPress Bloggers. The whole source code of the plugin is at:- https://...
user avatar
0 votes
1 answer
700 views

worldpay class not working with namespace in WordPress

I am trying to create Worldpay gateway with help of Worldpay library and my own extending code. Here is my code which I tried and failed to work on. require_once('init.php'); use lib\Worldpay; if($...
user avatar
  • 868
1 vote
1 answer
354 views

How to add in my plugin a third vendor Git project with composer.json

I need to use this Git project in my plugin. First I drop source code in a folder, and load it with require_once dirname(__FILE__) . '/vendor/Frozensheep/RightmoveADF/RightmoveADF.php'; But there ...
user avatar
  • 133
2 votes
2 answers
361 views

How to use defined in class file with namespace

Here is my code. defined( 'ABSPATH' ) || exit; namespace JSR; class myClass{ ... } This is giving below error Global code should be enclosed in global namespace declaration Any idea how to fix ...
user avatar
  • 1,340
0 votes
1 answer
52 views

Reorganization of namespaces

First of all thank You for Your time. I use autoload in my 2 plugins. They have to different namespaces but i want to build one main plugin with autoload for this two plugins. In future i am going to ...
user avatar
1 vote
0 answers
160 views

Why namespaces are rarely used in WordPress plugins?

This is currently my impression. Many WordPress plugins I used do not use namespaces. On few occasions, on this website, I saw namespaces are good and should be used. Are there any drawbacks using ...
user avatar
  • 4,149
1 vote
2 answers
4k views

Change name of custom post type archive

I have a custom post type acme_reviews. I've namespaced it as suggested in tutorials to prevent future conflicts. But I want its archive page to simply be acme.com/reviews, not acme.com/acme_reviews. ...
user avatar
3 votes
2 answers
808 views

Implementing namespaces in plugin template

To get with the time and improve my coding practices, I'm starting to implementing namespaces in my own plugins moving forward since there are some advantages, such as eliminating ambiguity. I found ...
user avatar