Make WordPress Core


Ignore:
Timestamp:
08/02/2026 06:51:36 AM (3 months ago)
Author:
westonruter
Message:

Build/Test Tools: Improve the constants defined for PHPStan.

Many constants were defined as empty strings, including ones that never hold an empty value in a real install. Realistic values are provided for those, matching what wp-settings.php and default-constants.php would produce, so that functions building on them can be given narrower types without the placeholder itself violating them. Constants core itself defines as empty, such as WP_DEVELOPMENT_MODE and COOKIE_DOMAIN, are left as they were.

Developed as subset of ​https://github.com/WordPress/wordpress-develop/pull/11851.

See #64898.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpstan/bootstrap.php

    r62292 r62965  
    88 */
    99
    10 // wp_initial_constants()
     10/*
     11 * A fixed, fictional path rather than the real checkout location. PHPStan resolves
     12 * no files through this constant, and deriving it from __DIR__ embeds the developer's
     13 * own path in error messages, making output differ between machines.
     14 */
     15define( 'ABSPATH', '/var/www/html/' );
     16
     17/** @see wp_initial_constants() */
    1118define( 'KB_IN_BYTES', 1024 );
    1219define( 'MB_IN_BYTES', 1024 * KB_IN_BYTES );
    … …  
    1724define( 'ZB_IN_BYTES', 1024 * EB_IN_BYTES );
    1825define( 'YB_IN_BYTES', 1024 * ZB_IN_BYTES );
    19 define( 'WP_START_TIMESTAMP', microtime( true ) );
    20 define( 'WP_MEMORY_LIMIT', '' );
    21 define( 'WP_MAX_MEMORY_LIMIT', '' );
     26define( 'WP_START_TIMESTAMP', 1700000000.0 ); // Fixed rather than microtime( true ), whose value would differ on every run.
     27define( 'WP_MEMORY_LIMIT', '40M' );
     28define( 'WP_MAX_MEMORY_LIMIT', '256M' );
     29define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
    2230define( 'WP_DEVELOPMENT_MODE', '' );
    2331define( 'WP_DEBUG', false );
    … …  
    3644define( 'YEAR_IN_SECONDS', 365 * DAY_IN_SECONDS );
    3745
    38 // wp_set_lang_dir()
    39 define( 'WP_LANG_DIR', '' );
     46/** @see wp_set_lang_dir() */
     47define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
    4048
    4149// wp_plugin_directory_constants()
    42 define( 'WP_CONTENT_URL', '' );
    43 define( 'WP_PLUGIN_DIR', '' );
    44 define( 'WP_PLUGIN_URL', '' );
    45 define( 'PLUGINDIR', '' );
    46 define( 'WPMU_PLUGIN_DIR', '' );
    47 define( 'WPMU_PLUGIN_URL', '' );
    48 define( 'MUPLUGINDIR', '' );
     50define( 'WP_CONTENT_URL', 'https://example.com/wp-content' );
     51define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
     52define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' );
     53define( 'PLUGINDIR', 'wp-content/plugins' );
     54define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' );
     55define( 'WPMU_PLUGIN_URL', WP_CONTENT_URL . '/mu-plugins' );
     56define( 'MUPLUGINDIR', 'wp-content/mu-plugins' );
    4957
    50 // ms_cookie_constants()
     58/** @see ms_cookie_constants() */
    5159define( 'COOKIEPATH', '' );
    5260define( 'SITECOOKIEPATH', '' );
    … …  
    5462define( 'COOKIE_DOMAIN', '' );
    5563
    56 // wp_cookie_constants()
     64/** @see wp_cookie_constants() */
    5765define( 'COOKIEHASH', '' );
    5866define( 'USER_COOKIE', '' );
    … …  
    6573define( 'RECOVERY_MODE_COOKIE', '' );
    6674
    67 // wp_ssl_constants()
     75/** @see wp_ssl_constants() */
    6876define( 'FORCE_SSL_LOGIN', false );
    6977define( 'FORCE_SSL_ADMIN', false );
    7078
    71 // wp_functionality_constants()
     79/** @see wp_functionality_constants() */
    7280define( 'AUTOSAVE_INTERVAL', MINUTE_IN_SECONDS );
    7381define( 'EMPTY_TRASH_DAYS', 1 );
    … …  
    7583define( 'WP_CRON_LOCK_TIMEOUT', MINUTE_IN_SECONDS );
    7684
    77 // wp_templating_constants()
    78 define( 'TEMPLATEPATH', '' );
    79 define( 'STYLESHEETPATH', '' );
    80 define( 'WP_DEFAULT_THEME', '' );
     85/** @see wp_templating_constants() */
     86define( 'TEMPLATEPATH', WP_CONTENT_DIR . '/themes/twentytwentyfive' );
     87define( 'STYLESHEETPATH', WP_CONTENT_DIR . '/themes/twentytwentyfive' );
     88define( 'WP_DEFAULT_THEME', 'twentytwentyfive' );
    8189
    82 // ms_file_constants()
     90/** @see ms_file_constants() */
    8391define( 'WPMU_SENDFILE', false );
    8492define( 'WPMU_ACCEL_REDIRECT', false );
    8593
    86 // ms_load_current_site_and_network()
     94/** @see ms_load_current_site_and_network() */
    8795define( 'NOBLOGREDIRECT', '' );
    8896
    89 // ms_upload_constants()
    90 define( 'UPLOADBLOGSDIR', '' );
    91 define( 'BLOGUPLOADDIR', '' );
     97/** @see ms_upload_constants() */
     98define( 'UPLOADBLOGSDIR', 'wp-content/blogs.dir' );
     99define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . '/blogs.dir/1/files/' );
    92100
    93 // Misc constants not part of the default lifecycle.
    94 define( 'FS_CONNECT_TIMEOUT', 1 );
    95 define( 'FS_TIMEOUT', 1 );
    96 define( 'FS_CHMOD_DIR', 1 );
    97 define( 'FS_CHMOD_FILE', 1 );
     101/** @see WP_Filesystem() */
     102define( 'FS_CONNECT_TIMEOUT', 30 ); // 30 seconds.
     103define( 'FS_TIMEOUT', 30 ); // 30 seconds.
     104define( 'FS_CHMOD_DIR', 0755 );
     105define( 'FS_CHMOD_FILE', 0644 );
Note: See TracChangeset for help on using the changeset viewer.