Questions tagged [namespace]
28
questions
0
votes
1
answer
150
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
23
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
58
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
271
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
261
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
80
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
312
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
202
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
1k
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
871
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
100
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
590
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
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
...
0
votes
1
answer
201
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 ...
0
votes
0
answers
54
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 ...
0
votes
1
answer
389
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 ...
0
votes
1
answer
275
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)...
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 ...
0
votes
1
answer
1k
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' );
$...
13
votes
2
answers
8k
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 ...
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://...
0
votes
1
answer
739
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($...
1
vote
1
answer
416
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 ...
2
votes
2
answers
380
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 ...
0
votes
1
answer
53
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 ...
1
vote
0
answers
167
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 ...
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. ...
3
votes
2
answers
849
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 ...