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 noticed that on one client's site, it has stopped working. They have the User Role Editor plugin that was set up to define a handful of custom roles. Once the roles were set up, the plugin was deactivated (it doesn't need to be active for the roles to exist) and …
Category: Web

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 = apply_filter( 'wpml_current_language', null ); if( $lang === 'en' ){ // Do stuff } I can't find any documentation on the ICL_LANGUAGE_CODE. The apply_filter has a documentation page, but in my opinion, the readability drops with this. Are there any obvious drawbacks using one or the other? Update I know that I …
Category: Web

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 constant that the program needs to be defined - an email address that the standalone program will use. If the program is running on a WP site (inside WP), then the program needs to use the WP admin email address (via the get_option( 'admin_email' ) function. …
Category: Web

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(); ?> <div class="cart-customlocation"> <img class="cart-img align-top" src="<?php echo HOME_URL . '/wp-content/uploads/icons/header/cart.png'; ?>" > <div id="cart-count" class="d-inline-block"><?php echo WC()->cart->cart_contents_count; ?></div> <div class="cart-description d-inline-block ml-4"> <div id="cart-title">Cart</div> <div id="cart-total"><?php echo WC()->cart->get_cart_total(); ?></div> </div> </div> <?php $fragments['div.cart-customlocation'] = ob_get_clean(); return $fragments; ob_start(); ?> <div class="mini-cart"> <?php woocommerce_mini_cart(); ?> </div> <?php $fragments['div.mini-cart'] = ob_get_clean(); return $fragments; } add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' …
Category: Web

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 minimal Wordpress instance. There is next to no documentation, and very few questions about its use, however I am interested in making use of it. What have I tried So far, I have setup a simple test php file in the root directory: define('WP_DEBUG', …
Category: Web

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 33 I have ABSPATH defined in wp-config as standard: /** Absolute path to the WordPress directory. */ if ( ! defined( 'ABSPATH' ) ) { define( 'ABSPATH', __DIR__ . '/' ); And it seems the site only accessed wp-settings because of the …
Category: Web

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: /home/public_html/my-site/wordpress I have, in my (dashboard) Settings/General window: WordPress Address (URL) https://my-site/wordpress and Site Address (URL) https://my-site BUT: this doesn't agree with the WordPress Constants listed in the (dashboard) Tools/Site_Health (info) window: ABSPATH /home/public_html/my-site/wordpress/ and WP_HOME Undefined and WP_SITEURL Undefined Any clues as to how to make WordPress "globally aware" of …
Category: Web

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 constant than why would you even trust any of their other code?" That made me wonder, what mechanism in WordPress keeps themes/plugins/etc from redefining constants? I'm guessing that it has to do with the order in which code loads.
Category: Web

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('WP_ALLOW_MULTISITE', true ); var_dump(WP_ALLOW_MULTISITE); // true define('MULTISITE', true); var_dump(MULTISITE); // false define('SUBDOMAIN_INSTALL', true); var_dump(SUBDOMAIN_INSTALL); // true MULTISITE constant is already defined with false before wp-confing.php. I searched with grep and it's defined only in ./wp-admin/includes/network.php as define('MULTISITE', true);. How to make it true? I tried on local Laradock instance and shared hosting. In both cases result is the same. EDIT (new info) Results of running …
Category: Web

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 within it were too tight, the webserver user couldn't even access them. I found the constants FS_CHMOD_DIR and FS_CHMOD_FILE that can be used to overwrite the default permissions for uploaded files. The Wordpress Codex suggests using the the following settings in the wp-config.php: define( 'FS_CHMOD_DIR', ( …
Category: Web

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 them to be site-specific (for multisite) so I thought it might be possible to append the current blog_id to the theme call and declare constants for each MultiSite in functions.php? I don't know how to code that, but what I'm trying to achieve in the theme file this …
Category: Web

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+ seconds overall before page loads). This renders my dev site unusable, as you can imagine. While browsing around I found many people complaining of this extremely slow curl issue and I've discovered that setting the WP_INSTALLING constant to true speeds the site up 100%. …
Category: Web

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 either null or 1. What I want to do is define this constant: define('WP_POST_REVISIONS', false); in the plugin file only if the option is set to 1. If I put the constant directly into the plugin functions file it works, but if I try and …
Category: Web

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 stands for in the theme_css_uri? define( 'name_THEME_URI', get_stylesheet_directory_uri()); define( 'name_THEME_TEMPLATE_URI', name_THEME_URI . '/templates' ); define( 'name_THEME_LANGUAGES_URI', name_THEME_URI . '/languages' ); define( 'name_THEME_ASSETS_URI', name_THEME_URI . '/assets' ); define( 'name_THEME_JS_URI', name_THEME_ASSETS_URI . '/js' ); define( 'name_THEME_CSS_URI', name_THEME_ASSETS_URI . '/css' ); define( 'name_THEME_IMAGES_URI', name_THEME_ASSETS_URI . '/images' …
Category: Web

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 you can set the EMPTY_TRASH_DAYS constant to zero. But it says that this will disable trash functionality altogether. I don't want to do this. I just want to disable the auto-trash emptying. Is there any way to do this? Or am …
Category: Web

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', get_template_directory() . '/admin/' ); if( !defined('ADMIN_DIR') ) define( 'ADMIN_DIR', get_template_directory_uri() . '/admin/' ); But i want to use SMOF in a plugin, not in theme, how can i get the plugin directory url? What to put in order to get_template_directory() and get_template_directory_uri() to use it in a plugin?
Category: Web

How to define constant before plugin

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 define constant BLA before PLUGIN A. Is that possible? I guess Wordpress needs to read PLUGIN B before PLUGIN A, but in which order Wordpress is reading plugins?
Category: Web

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 $x; But I am still getting English text even after adding that locale's .mo file & the text-domain. This is happening only for strings defined by PHP constants, rest all strings are working fine. So, does strings defined using PHP constants not work for translation as even in popular translated plugins I can't …
Category: Web

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 certain actions. The contents of these Mails has been localized using __() and all the other built in translation functions, as well as translated in the corresponging .mo/.po files. My users can choose the language for the frontend of the software, and this …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.