Questions tagged [constants]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
22 views

Site Health and PHP 8.1

I just switched from PHP 7.4 to PHP 8.1 and I noticed that in Site Health under WordPress Constants, both WP_HOME and WP_SITEURL show as Undefined. Shortcodes that use site url still appear to be ...
Mike Witt's user avatar
0 votes
1 answer
23 views

Should we escape the values of constants?

In my theme folder, I store my constants in a file called constants.php. But when we use the constant, should we escape it like esc_html__('This is '. CONSTANT_A, 'text-domain'); I was wondering if a ...
ratib90486's user avatar
0 votes
1 answer
925 views

Use of undefined constant issue

I have the following warning notice from my functions.php file: Warning: Use of undefined constant ENVIRONMENT - assumed 'ENVIRONMENT' (this will throw an Error in a future version of PHP) This is ...
Mathieu Préaud's user avatar
0 votes
1 answer
98 views

Override plugin constant using a theme

I have a plugin which starts: <?php define( 'MAX_THINGS', 30 ); I would like to change the constant to be 2. I know I can edit the plugin file directly - but that will be overwritten if the plugin ...
Terence Eden's user avatar
0 votes
0 answers
81 views

Is it better to use a constant or apply_filter?

I'm using WPML, which has several ways to access the current language. ICL_LANGUAGE_CODE if( ICL_LANGUAGE_CODE === 'en' ){ // Do stuff } apply_filter( 'wpml_current_language', null )' docs $lang = ...
Zeth's user avatar
  • 828
1 vote
2 answers
46 views

Best Constant to use to check if WordPress is running

I have a program that can run standalone (outside WP) or inside WP. If the program is running 'inside' WP (via a custom template using appropriate enqueue scripts and add_actions), then there is a ...
Rick Hellewell's user avatar
0 votes
0 answers
65 views

Constant defined in header.php not visible in functions.php

I have defined constant in header.php file: define( 'HOME_URL', esc_url( home_url() ) ); and used in functions.php file: function woocommerce_header_add_to_cart_fragment( $fragments ) { ob_start()...
Juraj's user avatar
  • 144
1 vote
0 answers
2k views

why would ABSPATH not get defined

Last week I got an error in my logs on a standard WP install - Use of undefined constant ABSPATH - assumed 'ABSPATH' (this will throw an Error in a future version of PHP) in /wp-settings.php on line ...
Jon's user avatar
  • 366
0 votes
0 answers
2k views

WP_HOME (and WP_URL) are undefined

My site's working, but there's a "cannot complete a loopback request" error in the (dashboard) Tools/Site_Health window I'm tracking down. My installation is in a subdirectory on my server: /...
Ryan's user avatar
  • 101
1 vote
1 answer
109 views

What mechanism does WordPress use to keep constants from being redefined?

I recently posted a comment on a general tech group about this line of code: define('WP_POST_REVISIONS', true); Someone replied, "If the original coders don't know that you can't redefine a ...
Nora McDougall-Collins's user avatar
7 votes
1 answer
6k views

Understanding SHORTINIT with Wordpress 5

What I am trying to achieve I am looking at using Wordpress decoupled, and most tutorials and guides go into detail on using the Rest API. Recently, I discovered the SHORTINIT option to load a very ...
Alexander Holsgrove's user avatar
1 vote
1 answer
320 views

Define a wordpress constant through plugin functions?

I'm working on a plugin and trying to build in an option to disable post revisions. I have the setting registered, and confirmed that the checkbox is linking to the database. The option value is ...
Nexus6's user avatar
  • 23
0 votes
0 answers
1k views

Cannot enable Wordpress Network - 'MULTISITE' already defined and false

In wp-config.php I have this code: var_dump(defined('WP_ALLOW_MULTISITE')); // false var_dump(defined('MULTISITE')); // true var_dump(defined('SUBDOMAIN_INSTALL')); // false define('...
Alan's user avatar
  • 101
1 vote
1 answer
20 views

difference of each codes for wordpress

I'm studying wordpress development and i was bumped to this codes. i'm trying my best to look from google but i can't seem to find it. Just wondering if what these codes means. what does the /admin ...
Ragna0282's user avatar
4 votes
1 answer
5k views

Syntax of FS_CHMOD_DIR and FS_CHMOD_FILE

I ran into an issue today with files uploaded through the Wordpress Backend not getting the correct permissions. The permission on the new 2018 folder in the uploads directory as well as the files ...
MoritzLost's user avatar
0 votes
1 answer
8k views

How to define constant before plugin [duplicate]

I have the plugin which have constant defined, i will call this plugin PLUGIN A: if ( ! defined('BLA')){ define('BLA', 'http://google.com); } I want to make another plugin PLUGIN B which will ...
gardelin's user avatar
  • 125
0 votes
1 answer
2k views

Can't we use strings defined as PHP constants if we want to translate them in a plugin?

I want to translate constant strings in my plugin defined as: define( 'CONSTANT', __( 'string-A', 'textdomain' ) ); And later using it somewhere like: $x= '<h4>'.CONSTANT_NAME.'<h4>'; echo ...
learning_13's user avatar
1 vote
1 answer
1k views

DISALLOW_FILE_EDIT constant being ignored

In my wp-config.php file, I have the line: define('DISALLOW_FILE_EDIT', true); I always include this on all sites as standard, and it's always worked exactly as expected. However, I've only just ...
indextwo's user avatar
  • 431
2 votes
2 answers
425 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 ...
pixelngrain's user avatar
  • 1,390
1 vote
0 answers
46 views

How can I change the language of automated Mails?

I've got a problem with translations, that sounds pretty simple, but I can't find a way around this. The Situation I got a software running on WordPress, and I need to send Emails to my users after ...
fischi's user avatar
  • 7,469
0 votes
1 answer
205 views

Child theme functions.php file change database entries

I'm sure my title is not the correct terminology. I will do my best to explain what I'm trying to accomplish. Years ago I spent countless hours customizing a theme. I was finally forced to update ...
Andy__'s user avatar
  • 1
0 votes
1 answer
519 views

Autosave interval remains default despite wp-config.php defines

On site which I maintain there are writers that spend a lot of time editing single posts, and autosave every minute is very painful for them. So they asked me to set it to at least 10 minutes. I ...
Forien's user avatar
  • 103
0 votes
1 answer
46 views

Where and how to define variables for URLs etc

I have one online version of a site, and one developer version which I am working and making changes on. If I have a form with a url which the user will be redirected to: <input type="hidden" ...
Galivan's user avatar
  • 243
0 votes
2 answers
433 views

is there a benefit in using a constant over get_stylesheet_directory_uri?

Is there any benefit perfomance wise when defining a constant in the wp-config.php like so <php define('PATH_TO_THEME', get_stylesheet_directory_uri() ); ?> and then referring to PATH_TO_THEME ...
MrKainig's user avatar
  • 431
2 votes
1 answer
424 views

Are there any security issues with setting the WP_INSTALLING constant to true?

Running Wordpress 4.1 on a CentOS 6.5 instance through VirtualBox as a dev server. When logged in as admin on both ssl and non-ssl sites Wordpress curl requests are taking a long time to run (45+ ...
adamgedney's user avatar
0 votes
1 answer
37 views

Constant for 'barebones' update of Wordpress

I feel slightly stupid asking this, but I could have sworn I stumbled across a constant that could be added to wp-config.php so that, when you update your Wordpress installation, it only updates ...
indextwo's user avatar
  • 431
-1 votes
1 answer
8k views

Notice: Use of undefined constant - assumed ' ' [closed]

Thanks in advance for your help. I am getting this error in my WordPress theme: Notice: Use of undefined constant - assumed ' ' in .../themes/theme/homepage.php on line 10 Here is the ...
the Freelancer's user avatar
0 votes
1 answer
2k views

Notice: Use of undefined constant Redux_TEXT_DOMAIN - assumed 'Redux_TEXT_DOMAIN'

I am building my first Wordpress site, I just downloaded and installed v3.9.1. I bought a theme (rustik3) and I am trying to install it, but I am running into these errors produced by WP_DEBUG: ...
ewizard's user avatar
  • 101
1 vote
0 answers
163 views

URL for images folder on Multisite

I am developing a theme locally on a local multisite installation and trying to change the default gravitar with the following function: function custom_gravitar ($avatar_defaults) { $myavatar = ...
mantis's user avatar
  • 780
1 vote
1 answer
45 views

Calling directories to load in wordpress

I have a wordpress install, with two sub folders "assets" and "functions" these folders contain important files for the wordpress theme. What would be the best way to load these files I've tried ...
dannyw24's user avatar
  • 431
3 votes
2 answers
22k views

get plugin directory url

I am trying to use SMOF Options Framework in a plugin and i have this problem. SMOOF use this constants to get theme directory url: if( !defined('ADMIN_PATH') ) define( 'ADMIN_PATH', ...
Genethic's user avatar
0 votes
1 answer
518 views

Update the value of a constant

I have a file containing all the constants used in the plugin. For example, I have a variable in one of my file define('APPOINTMENTS_DEFAULT_ENABLE_PAYPAL', 1); I have a checkbox in admin area where ...
Zammuuz's user avatar
  • 788
0 votes
0 answers
1k views

Notice: Use of undefined constant - assumed ' '

I turned on debug mode and see the following in my header: Notice: Use of undefined constant - assumed ' ' I'm using the following function in header.php: <?php if ( is_user_logged_in() ) { ...
elbatron's user avatar
  • 395
0 votes
0 answers
104 views

Making Site A Use Site B's wp-content Folder

I'm trying to synchronize two WordPress sites and on my way I've faced few challenges. One of the challenges is to either synchronize the wp-content folder of two sites or make one site use the wp-...
Omar Tariq's user avatar
0 votes
2 answers
10k views

Synchronizing Two WordPress Sites Content

I've googled a lot, and I do have found answers at WordPress SE and at stackoverflow.com. However, the answers are somewhat incomplete or doesn't work at all. Here I'll explain my problem in detail, ...
Omar Tariq's user avatar
22 votes
2 answers
18k views

What should I use instead of WP_CONTENT_DIR and WP_PLUGIN_DIR?

The WordPress documentation for Determining Plugin and Content Directories states that: WordPress makes use of the following constants when determining the path to the content and plugin ...
Nick's user avatar
  • 583
0 votes
1 answer
822 views

Define constant for one plugin in mu-plugin

I'm trying to define the constant ACF_Lite as true so that the interface of the Advanced Custom Fields plugin is hidden on all of my multisite subsites except the parent. For clarity and ...
mrwweb's user avatar
  • 10.2k
0 votes
1 answer
717 views

Get WP Install Directory

I have a theme which - I was quite proud of myself! - I designed to be installed in wp sites where wp is on root level. Then half my users installed the theme on a mysite.com*/wordpress/* ! ...and ...
user1915665's user avatar
0 votes
1 answer
867 views

Get variable value based on string constant

In my plugin I define a constant as follows: define('DEFAULT_NUM', 5); I also define a constant representing the name by which I want to refer to this number: define('DEFAULT_NUM_NAME', 'numitems');...
JimmyPena's user avatar
  • 107
0 votes
2 answers
4k views

Checking for existence of constants before defining them

I am seeing many plugins use the following format for defining their constant: /* Set the constant path to the plugin's javascript directory. */ if( !defined( 'MY_ETS_JS' ) ) define( 'MY_ETS_JS', ...
urok93's user avatar
  • 3,964
0 votes
1 answer
297 views

Can't Access Constant from within Included File

First of all, I'm completely sure I'm being an idiot on this one - but an hour of scratching my head and searching this site has still left me perplexed. I'm trying to access a constant that's ...
Paul McCarthy's user avatar
1 vote
2 answers
5k views

Accessing site's root from themes folder

Having some troubles with a PHP script I am trying to build. I need to access the a file which is located in the root folder of my Wordpress install: wordpress-root/live-config.php Problem is, my ...
remi90's user avatar
  • 417
2 votes
1 answer
2k views

Use theme constants in plugin?

I'm creating a plugin version of the Roots Theme function additions - to make it a bit more portable, but have run into a snag. Part of what Roots does is add htaccess rules based on the current ...
Zach's user avatar
  • 1,923
0 votes
1 answer
108 views

Insert functions-defined constant into get_tags code

I'm using the below code from WordPress' get_tags Function Reference page $tags = get_tags(); $html = '<div class="post_tags">'; foreach ($tags as $tag){ $tag_link = ...
TheLoneCuber's user avatar
0 votes
1 answer
345 views

Many Single Sites, One Plugin directory - adjust plugins_url()

[this is not a Multisite question] Update: this question is a logical impossibility, or a mind loop if you will, check update bellow. The technique is laid out here in WPEngineer. It allows having ...
brasofilo's user avatar
  • 22k
1 vote
1 answer
1k views

ABSPATH in Windows

I'm having a a pain in the head using the ABSPATH constant in Windows. Addressing files and folders in Windows is usually done using the \ (forward-slash) character while for Linux the character would ...
2hamed's user avatar
  • 370
1 vote
1 answer
196 views

wp_enqueue_script & constants?

I'm enqueuing a script: wp_enqueue_script('my-script', MY_SCRIPTS."/my-script.js"); How to get MY_SCRIPTS const working in this context? I know this works: $template_dir = get_bloginfo('...
Wordpressor's user avatar
  • 5,011
0 votes
2 answers
544 views

How can I append blog_id to ... echo [functions-defined-constant]?

I use 'constants' a lot. I set them in functions.php like define('mytheme_town', 'Orlando'); and then call them into the theme <?php echo mytheme_town ; ?>. It's simple and easy. But I need ...
TheLoneCuber's user avatar
1 vote
1 answer
2k views

Using the ABSPATH constant - What files need to be loaded before use?

I need to make use of the ABSPATH constant but need to know what WP files I need to include so I can make use of it. Thanks a lot!
Brett's user avatar
  • 404
7 votes
2 answers
6k views

Turn Off Automatic Trash Deletion?

I have a client who wants to use the trash feature, but keep items in there indefinitely (I have no idea why, but they insist on it). From reading this codex article on the trash status, I see that ...
MathSmath's user avatar
  • 5,568