DEV Community

Cover image for Constantes de WordPress
jmau111
jmau111

Posted on • Originally published at blog.julien-maury.dev

Constantes de WordPress

Una constante [PHP] es un identificador (nombre) para un valor simple. Por convención, los identificadores de constantes siempre se declaran en mayúsculas.

define( 'IDENTIFICADOR', 'valor' );
Enter fullscreen mode Exit fullscreen mode

Según PHP.net

Su finalidad no es ofrecer la lista completa de constantes nativas de WordPress. Algunas de categorías generales de uso.

FAVOR DE UTILIZARLA CON PRECAUCIÓN!

Mostrar todas las constantes PHP

print_r(get_defined_constants(true));
Enter fullscreen mode Exit fullscreen mode

No modificar

// URLs/path
print_r(WP_INC); // /wp-includes/
print_r(ABSPATH); // root

// tiempo
print_r(MINUTE_IN_SECONDS);
print_r(HOUR_IN_SECONDS);
print_r(DAY_IN_SECONDS);
print_r(WEEK_IN_SECONDS);
print_r(MONTH_IN_SECONDS);
print_r(YEAR_IN_SECONDS);

// tamaño
print_r(KB_IN_BYTES);
print_r(MB_IN_BYTES);
print_r(GB_IN_BYTES);
print_r(TB_IN_BYTES);
Enter fullscreen mode Exit fullscreen mode

En curso

// my_script.php
print_r(DOING_AJAX);
print_r(WP_IMPORTING);
print_r(WP_LOAD_IMPORTERS);
print_r(WP_INSTALLING);
print_r(IFRAME_REQUEST);
print_r(WP_UNINSTALL_PLUGIN);// archivo
Enter fullscreen mode Exit fullscreen mode

DB

// wp-config.php
define( 'DB_NAME', 'database' );
define( 'DB_USER', 'username' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
define( 'WP_ALLOW_REPAIR', false ); //  por defecto false
define( 'CUSTOM_USER_TABLE', 'usr' ); // por defecto 'wp_users'
define( 'CUSTOM_USER_META_TABLE', 'usr-metadata' ); // por defecto 'wp_usermeta'
Enter fullscreen mode Exit fullscreen mode

Bootstrap

// bootstrap.php
define( 'SHORTINIT', true );
define( 'WP_USE_THEMES', false );
require_once $_SERVER[ 'DOCUMENT_ROOT' ] . '/wp-load.php';
Enter fullscreen mode Exit fullscreen mode

URLs - Archivos

// wp-config.php
define( 'WP_SITEURL', 'https://sitio.es' );
define( 'WP_HOME', 'https://sitio.es' );
define( 'WP_CONTENT_DIR', 'wp-content' );
define( 'WPMU_PLUGIN_DIR', '{WP_CONTENT_DIR}/mu-plugins' );
define( 'WP_PLUGIN_DIR', '{WP_CONTENT_DIR}/plugins' );
define( 'WP_CONTENT_URL',  '{Sitio URL}/wp-content' );
define( 'WPMU_PLUGIN_URL', '{WP_CONTENT_URL}/mu-plugins' );
define( 'WP_TEMP_DIR', '/path/to/tmp' ); // no público
define( 'WP_LANG_DIR', '{WP_CONTENT_DIR}/languages' );
define( 'UPLOADS', '{WP_CONTENT_DIR}/uploads' );
define( 'WP_DEFAULT_THEME', 'mi-tema' );
Enter fullscreen mode Exit fullscreen mode
// wp-content/themes/thema/functions.php
if (!defined('TEMPLATEPATH'))
    define( 'TEMPLATEPATH', get_template_directory() );

// wp-content/themes/thema-child/functions.php
if (!defined('STYLESHEETPATH'))
    define( 'STYLESHEETPATH', get_stylesheet_directory() );
Enter fullscreen mode Exit fullscreen mode

Debug (ENV DEV)

// wp-config.php
define( 'WP_DEBUG', true );
define( 'SCRIPT_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
define( 'WP_DEBUG_LOG', '/path/to/error.log' );
define( 'SAVEQUERIES', true ); // $wpdb->queries
Enter fullscreen mode Exit fullscreen mode

Sistema de archivos

// wp-config.php
define( 'FS_CHMOD_DIR', '0755' );
define( 'FS_CHMOD_FILE', '0644' );
define( 'FS_METHOD', true );
define( 'FS_CONNECT_TIMEOUT', 30 );// segundos
define( 'FS_TIMEOUT', 30 );// segundos
define( 'FTP_BASE', ABSPATH );
define( 'FTP_CONTENT_DIR', WP_CONTENT_DIR );
define( 'FTP_LANG_DIR', WP_LANG_DIR );
define( 'FTP_HOST', '221.22.11.11' );
define( 'FTP_USER', 'xxxxxxx' );
define( 'FTP_PASS', 'yyyyyyy' );
define( 'FTP_PRIKEY', 'privkey' );
define( 'FTP_PUBKEY', 'pubkey' );
define( 'FTP_SSH', true );
define( 'FTP_SSL', true );
Enter fullscreen mode Exit fullscreen mode

Rendimiento

Cache - memory

// wp-config.php
define( 'WP_CACHE', true );
define( 'WP_CACHE_KEY_SALT', '' ); // object-cache.php
define( 'WP_MAX_MEMORY_LIMIT', '256M' );
define( 'WP_MEMORY_LIMIT', '128M' );
define( 'WP_POST_REVISIONS', false );
define( 'AUTOSAVE_INTERVAL', 120 );
define( 'EMPTY_TRASH_DAYS', 0 );
define( 'MEDIA_TRASH', true );


// archivo.php
define( 'DONOTCACHEPAGE', true ); // 0 cache
Enter fullscreen mode Exit fullscreen mode

CSS - JS - GZIP

define( 'CONCATENATE_SCRIPTS', true );
define( 'COMPRESS_CSS', true );
define( 'COMPRESS_SCRIPTS', true );
define( 'ENFORCE_GZIP', true );
Enter fullscreen mode Exit fullscreen mode

CRON

define( 'DISABLE_WP_CRON', true ); // utilizar el CRON del servidor
Enter fullscreen mode Exit fullscreen mode

Seguridad

Fortalecimiento de la seguridad

// wp-config.php
define( 'DISALLOW_FILE_EDIT', true );
define( 'DISALLOW_FILE_MODS', true );
define( 'DISALLOW_UNFILTERED_HTML', true );
define( 'FORCE_SSL_ADMIN', true );
define( 'ALLOW_UNFILTERED_UPLOADS', false );

// wp-config.php - salt keys
// https://api.wordpress.org/secret-key/1.1/salt
define( 'AUTH_KEY', '$JA]2Be{ Up0&yVF_-*rWt(5{Y/^St>$1Toq*}|<&FTVp5WOTr9 v9qMKd?OB55b' );
define( 'SECURE_AUTH_KEY', '*7]}KUj(L@-qh&$qcUfHy.1%G{KyS8t|m.fkg]B2<E`0 O@|.TG3(t!3XL+B-M!H' );
define( 'LOGGED_IN_KEY', '{GM-.qgy93K@<!je,W5%_DZ>+| 4sN5A+`zuKksP[b*h8Cp097f2SddkymPTj=|_' );
define( 'NONCE_KEY', '=#vpZYdG{QP8m!81%c9w8kXNyMX{7mqc|A9C??gLkH:Vk,9S`y.U&-vn#S#eeeWV' );
define( 'AUTH_SALT', '+4_)~Qs6 }6!1/U}X-P378LY_=AaA(xe9~Iw*un!c7[n]VF7KuKH|+X5h,6jAh2+' );
define( 'SECURE_AUTH_SALT', '0zcKS|J{E*Njl!@e;%pSvdD/`]^rU-OW<-:j!C-9 >ulz,M^7|hB:[nh.RT}`A]p' );
define( 'LOGGED_IN_SALT', 'jc^rkY5kNuk6nhyVzPD{ J8,-{ y1#X6(8S&E%@4Y(<=A!nc+D8d-+qGG9FJtxR^' );
define( 'NONCE_SALT', '[;2nqDhw@:AL{;^=ViY-YX-Sm7y$K7!f<O+MI!gqKyt;f~0PX:g1g*=x/p4dgWuS' );
Enter fullscreen mode Exit fullscreen mode

Actualización

// wp-config.php
define( 'AUTOMATIC_UPDATER_DISABLED', false ); // true, false
define( 'WP_AUTO_UPDATE_CORE', false ); // true, false, minor
define( 'CORE_UPGRADE_SKIP_NEW_BUNDLED', true ); // twenty themes, hello dolly
define ( 'DO_NOT_UPGRADE_GLOBAL_TABLES', true );
Enter fullscreen mode Exit fullscreen mode

Bloqueo && Proxy (para los iniciados!)

// wp-config.php
define( 'WP_HTTP_BLOCK_EXTERNAL', true ); // solicitudes salientes
define( 'WP_ACCESSIBLE_HOSTS', 'localhost, www.example.com, *.wordpress.org' );

// proxy
define( 'WP_PROXY_HOST', '192.168.84.104' );
define( 'WP_PROXY_PORT', '8080' );
define( 'WP_PROXY_USERNAME', 'xxxxxxx' );
define( 'WP_PROXY_PASSWORD', 'yyyyyyy' );
define( 'WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com, *.wordpress.org' );
Enter fullscreen mode Exit fullscreen mode

Cookies

// wp-config.php
define( 'COOKIEHASH', '' );
define( 'USER_COOKIE', 'wordpressuser_' . COOKIEHASH );
define( 'PASS_COOKIE', 'wordpresspass_' . COOKIEHASH );
define( 'AUTH_COOKIE', 'wordpress_' . COOKIEHASH );
define( 'SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH );
define( 'LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH );
define( 'TEST_COOKIE', 'wordpress_test_cookie' );
define( 'COOKIEPATH', preg_replace( '|https?://[^/]+|i', '', get_option( 'home' ) . '/' ) );
define( 'SITECOOKIEPATH', preg_replace( '|https?://[^/]+|i', '', get_option( 'siteurl' ) . '/' ) );
define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
define( 'PLUGINS_COOKIE_PATH', preg_replace( '|https?://[^/]+|i', '', WP_PLUGIN_URL ) );
define( 'COOKIE_DOMAIN', false );
define( 'RECOVERY_MODE_COOKIE', 'wordpress_rec_' . COOKIEHASH );
Enter fullscreen mode Exit fullscreen mode

Multisite

// wp-config.php
// No se trata de una lista completa
define( 'WP_ALLOW_MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false ); // sitio.es/site1, sitio.es/site2, sitio.es/site3
define( 'DOMAIN_CURRENT_SITE', 'sitio.es' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
Enter fullscreen mode Exit fullscreen mode

Pruebas

// wp-tests-config.php
define( 'WP_TESTS_DOMAIN', 'example.org' );
define( 'WP_TESTS_EMAIL', 'admin@example.org' );
define( 'WP_TESTS_TITLE', 'Test Blog' );
define( 'WP_PHP_BINARY', 'php' );
define( 'WP_TESTS_FORCE_KNOWN_BUGS', true );
define( 'REST_TESTS_IMPOSSIBLY_HIGH_NUMBER', 100000 );
Enter fullscreen mode Exit fullscreen mode

Foto del autor Kazuo ota

Discussion (0)