OSDN Git Service

Eコマース機能更新。
[magic3/magic3.git] / include / wp / wp-includes / load.php
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 = $_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 /*
30 function wp_unregister_GLOBALS() {
31         if ( !ini_get( 'register_globals' ) )
32                 return;
33
34         if ( isset( $_REQUEST['GLOBALS'] ) )
35                 die( 'GLOBALS overwrite attempt detected' );
36
37         // Variables that shouldn't be unset
38         $no_unset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix' );
39
40         $input = array_merge( $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset( $_SESSION ) && is_array( $_SESSION ) ? $_SESSION : array() );
41         foreach ( $input as $k => $v )
42                 if ( !in_array( $k, $no_unset ) && isset( $GLOBALS[$k] ) ) {
43                         unset( $GLOBALS[$k] );
44                 }
45 }
46 */
47 /**
48  * Fix `$_SERVER` variables for various setups.
49  *
50  * @since 3.0.0
51  * @access private
52  *
53  * @global string $PHP_SELF The filename of the currently executing script,
54  *                          relative to the document root.
55  */
56 /*
57 function wp_fix_server_vars() {
58         global $PHP_SELF;
59
60         $default_server_values = array(
61                 'SERVER_SOFTWARE' => '',
62                 'REQUEST_URI' => '',
63         );
64
65         $_SERVER = array_merge( $default_server_values, $_SERVER );
66
67         // Fix for IIS when running with PHP ISAPI
68         if ( empty( $_SERVER['REQUEST_URI'] ) || ( PHP_SAPI != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {
69
70                 // IIS Mod-Rewrite
71                 if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
72                         $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
73                 }
74                 // IIS Isapi_Rewrite
75                 elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) {
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                         // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice)
83                         if ( isset( $_SERVER['PATH_INFO'] ) ) {
84                                 if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] )
85                                         $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
86                                 else
87                                         $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
88                         }
89
90                         // Append the query string if it exists and isn't null
91                         if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
92                                 $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
93                         }
94                 }
95         }
96
97         // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
98         if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) )
99                 $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
100
101         // Fix for Dreamhost and other PHP as CGI hosts
102         if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false )
103                 unset( $_SERVER['PATH_INFO'] );
104
105         // Fix empty PHP_SELF
106         $PHP_SELF = $_SERVER['PHP_SELF'];
107         if ( empty( $PHP_SELF ) )
108                 $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER["REQUEST_URI"] );
109 }
110 */
111 /**
112  * Check for the required PHP version, and the MySQL extension or
113  * a database drop-in.
114  *
115  * Dies if requirements are not met.
116  *
117  * @since 3.0.0
118  * @access private
119  *
120  * @global string $required_php_version The required PHP version string.
121  * @global string $wp_version           The WordPress version string.
122  */
123 /*function wp_check_php_mysql_versions() {
124         global $required_php_version, $wp_version;
125         $php_version = phpversion();
126
127         if ( version_compare( $required_php_version, $php_version, '>' ) ) {
128                 wp_load_translations_early();
129
130                 $protocol = wp_get_server_protocol();
131                 header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
132                 header( 'Content-Type: text/html; charset=utf-8' );
133                 // translators: 1: Current PHP version number, 2: WordPress version number, 3: Minimum required PHP version number
134                 die( sprintf( __( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.' ), $php_version, $wp_version, $required_php_version ) );
135         }
136
137         if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
138                 wp_load_translations_early();
139
140                 $protocol = wp_get_server_protocol();
141                 header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
142                 header( 'Content-Type: text/html; charset=utf-8' );
143                 die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) );
144         }
145 }
146 */
147 /**
148  * Don't load all of WordPress when handling a favicon.ico request.
149  *
150  * Instead, send the headers for a zero-length favicon and bail.
151  *
152  * @since 3.0.0
153  */
154 function wp_favicon_request() {
155         if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {
156                 header('Content-Type: image/vnd.microsoft.icon');
157                 exit;
158         }
159 }
160
161 /**
162  * Die with a maintenance message when conditions are met.
163  *
164  * Checks for a file in the WordPress root directory named ".maintenance".
165  * This file will contain the variable $upgrading, set to the time the file
166  * was created. If the file was created less than 10 minutes ago, WordPress
167  * enters maintenance mode and displays a message.
168  *
169  * The default message can be replaced by using a drop-in (maintenance.php in
170  * the wp-content directory).
171  *
172  * @since 3.0.0
173  * @access private
174  *
175  * @global int $upgrading the unix timestamp marking when upgrading WordPress began.
176  */
177 function wp_maintenance() {
178         if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() )
179                 return;
180
181         global $upgrading;
182
183         include( ABSPATH . '.maintenance' );
184         // If the $upgrading timestamp is older than 10 minutes, don't die.
185         if ( ( time() - $upgrading ) >= 600 )
186                 return;
187
188         /**
189          * Filters whether to enable maintenance mode.
190          *
191          * This filter runs before it can be used by plugins. It is designed for
192          * non-web runtimes. If this filter returns true, maintenance mode will be
193          * active and the request will end. If false, the request will be allowed to
194          * continue processing even if maintenance mode should be active.
195          *
196          * @since 4.6.0
197          *
198          * @param bool $enable_checks Whether to enable maintenance mode. Default true.
199          * @param int  $upgrading     The timestamp set in the .maintenance file.
200          */
201         if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
202                 return;
203         }
204
205         if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
206                 require_once( WP_CONTENT_DIR . '/maintenance.php' );
207                 die();
208         }
209
210         wp_load_translations_early();
211
212         $protocol = wp_get_server_protocol();
213         header( "$protocol 503 Service Unavailable", true, 503 );
214         header( 'Content-Type: text/html; charset=utf-8' );
215         header( 'Retry-After: 600' );
216 ?>
217         <!DOCTYPE html>
218         <html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
219         <head>
220         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
221                 <title><?php _e( 'Maintenance' ); ?></title>
222
223         </head>
224         <body>
225                 <h1><?php _e( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ); ?></h1>
226         </body>
227         </html>
228 <?php
229         die();
230 }
231
232 /**
233  * Start the WordPress micro-timer.
234  *
235  * @since 0.71
236  * @access private
237  *
238  * @global float $timestart Unix timestamp set at the beginning of the page load.
239  * @see timer_stop()
240  *
241  * @return bool Always returns true.
242  */
243 function timer_start() {
244         global $timestart;
245         $timestart = microtime( true );
246         return true;
247 }
248
249 /**
250  * Retrieve or display the time from the page start to when function is called.
251  *
252  * @since 0.71
253  *
254  * @global float   $timestart Seconds from when timer_start() is called.
255  * @global float   $timeend   Seconds from when function is called.
256  *
257  * @param int|bool $display   Whether to echo or return the results. Accepts 0|false for return,
258  *                            1|true for echo. Default 0|false.
259  * @param int      $precision The number of digits from the right of the decimal to display.
260  *                            Default 3.
261  * @return string The "second.microsecond" finished time calculation. The number is formatted
262  *                for human consumption, both localized and rounded.
263  */
264 function timer_stop( $display = 0, $precision = 3 ) {
265         global $timestart, $timeend;
266         $timeend = microtime( true );
267         $timetotal = $timeend - $timestart;
268         $r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
269         if ( $display )
270                 echo $r;
271         return $r;
272 }
273
274 /**
275  * Set PHP error reporting based on WordPress debug settings.
276  *
277  * Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`.
278  * All three can be defined in wp-config.php. By default, `WP_DEBUG` and
279  * `WP_DEBUG_LOG` are set to false, and `WP_DEBUG_DISPLAY` is set to true.
280  *
281  * When `WP_DEBUG` is true, all PHP notices are reported. WordPress will also
282  * display internal notices: when a deprecated WordPress function, function
283  * argument, or file is used. Deprecated code may be removed from a later
284  * version.
285  *
286  * It is strongly recommended that plugin and theme developers use `WP_DEBUG`
287  * in their development environments.
288  *
289  * `WP_DEBUG_DISPLAY` and `WP_DEBUG_LOG` perform no function unless `WP_DEBUG`
290  * is true.
291  *
292  * When `WP_DEBUG_DISPLAY` is true, WordPress will force errors to be displayed.
293  * `WP_DEBUG_DISPLAY` defaults to true. Defining it as null prevents WordPress
294  * from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY`
295  * as false will force errors to be hidden.
296  *
297  * When `WP_DEBUG_LOG` is true, errors will be logged to debug.log in the content
298  * directory.
299  *
300  * Errors are never displayed for XML-RPC, REST, and Ajax requests.
301  *
302  * @since 3.0.0
303  * @access private
304  */
305 function wp_debug_mode() {
306         /**
307          * Filters whether to allow the debug mode check to occur.
308          *
309          * This filter runs before it can be used by plugins. It is designed for
310          * non-web run-times. Returning false causes the `WP_DEBUG` and related
311          * constants to not be checked and the default php values for errors
312          * will be used unless you take care to update them yourself.
313          *
314          * @since 4.6.0
315          *
316          * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true.
317          */
318         if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ){
319                 return;
320         }
321
322         if ( WP_DEBUG ) {
323                 error_reporting( E_ALL );
324
325                 if ( WP_DEBUG_DISPLAY )
326                         ini_set( 'display_errors', 1 );
327                 elseif ( null !== WP_DEBUG_DISPLAY )
328                         ini_set( 'display_errors', 0 );
329
330                 if ( WP_DEBUG_LOG ) {
331                         ini_set( 'log_errors', 1 );
332                         ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );
333                 }
334         } else {
335                 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 );
336         }
337
338         if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) {
339                 @ini_set( 'display_errors', 0 );
340         }
341 }
342
343 /**
344  * Set the location of the language directory.
345  *
346  * To set directory manually, define the `WP_LANG_DIR` constant
347  * in wp-config.php.
348  *
349  * If the language directory exists within `WP_CONTENT_DIR`, it
350  * is used. Otherwise the language directory is assumed to live
351  * in `WPINC`.
352  *
353  * @since 3.0.0
354  * @access private
355  */
356 function wp_set_lang_dir() {
357         if ( !defined( 'WP_LANG_DIR' ) ) {
358                 if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || !@is_dir(ABSPATH . WPINC . '/languages') ) {
359                         /**
360                          * Server path of the language directory.
361                          *
362                          * No leading slash, no trailing slash, full path, not relative to ABSPATH
363                          *
364                          * @since 2.1.0
365                          */
366                         define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
367                         if ( !defined( 'LANGDIR' ) ) {
368                                 // Old static relative path maintained for limited backward compatibility - won't work in some cases.
369                                 define( 'LANGDIR', 'wp-content/languages' );
370                         }
371                 } else {
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', ABSPATH . WPINC . '/languages' );
380                         if ( !defined( 'LANGDIR' ) ) {
381                                 // Old relative path maintained for backward compatibility.
382                                 define( 'LANGDIR', WPINC . '/languages' );
383                         }
384                 }
385         }
386 }
387
388 /**
389  * Load the database class file and instantiate the `$wpdb` global.
390  *
391  * @since 2.5.0
392  *
393  * @global wpdb $wpdb The WordPress database class.
394  */
395 function require_wp_db() {
396         global $wpdb;
397
398         require_once( ABSPATH . WPINC . '/wp-db.php' );
399         if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
400                 require_once( WP_CONTENT_DIR . '/db.php' );
401
402         if ( isset( $wpdb ) ) {
403                 return;
404         }
405
406         $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
407 }
408
409 /**
410  * Set the database table prefix and the format specifiers for database
411  * table columns.
412  *
413  * Columns not listed here default to `%s`.
414  *
415  * @since 3.0.0
416  * @access private
417  *
418  * @global wpdb   $wpdb         The WordPress database class.
419  * @global string $table_prefix The database table prefix.
420  */
421 function wp_set_wpdb_vars() {
422         global $wpdb, $table_prefix;
423         if ( !empty( $wpdb->error ) )
424                 dead_db();
425
426         $wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
427                 'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'comment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
428                 'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',
429                 'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d',
430                 // multisite:
431                 'active' => '%d', 'cat_id' => '%d', 'deleted' => '%d', 'lang_id' => '%d', 'mature' => '%d', 'public' => '%d', 'site_id' => '%d', 'spam' => '%d',
432         );
433
434         $prefix = $wpdb->set_prefix( $table_prefix );
435
436         if ( is_wp_error( $prefix ) ) {
437                 wp_load_translations_early();
438                 wp_die(
439                         /* translators: 1: $table_prefix 2: wp-config.php */
440                         sprintf( __( '<strong>ERROR</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ),
441                                 '<code>$table_prefix</code>',
442                                 '<code>wp-config.php</code>'
443                         )
444                 );
445         }
446 }
447
448 /**
449  * Toggle `$_wp_using_ext_object_cache` on and off without directly
450  * touching global.
451  *
452  * @since 3.7.0
453  *
454  * @global bool $_wp_using_ext_object_cache
455  *
456  * @param bool $using Whether external object cache is being used.
457  * @return bool The current 'using' setting.
458  */
459 function wp_using_ext_object_cache( $using = null ) {
460         global $_wp_using_ext_object_cache;
461         $current_using = $_wp_using_ext_object_cache;
462         if ( null !== $using )
463                 $_wp_using_ext_object_cache = $using;
464         return $current_using;
465 }
466
467 /**
468  * Start the WordPress object cache.
469  *
470  * If an object-cache.php file exists in the wp-content directory,
471  * it uses that drop-in as an external object cache.
472  *
473  * @since 3.0.0
474  * @access private
475  */
476 function wp_start_object_cache() {
477         global $wp_filter;
478
479         $first_init = false;
480         if ( ! function_exists( 'wp_cache_init' ) ) {
481                 if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
482                         require_once ( WP_CONTENT_DIR . '/object-cache.php' );
483                         if ( function_exists( 'wp_cache_init' ) ) {
484                                 wp_using_ext_object_cache( true );
485                         }
486
487                         // Re-initialize any hooks added manually by object-cache.php
488                         if ( $wp_filter ) {
489                                 $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
490                         }
491                 }
492
493                 $first_init = true;
494         } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
495                 /*
496                  * Sometimes advanced-cache.php can load object-cache.php before
497                  * it is loaded here. This breaks the function_exists check above
498                  * and can result in `$_wp_using_ext_object_cache` being set
499                  * incorrectly. Double check if an external cache exists.
500                  */
501                 wp_using_ext_object_cache( true );
502         }
503
504         if ( ! wp_using_ext_object_cache() ) {
505                 require_once ( ABSPATH . WPINC . '/cache.php' );
506         }
507
508         /*
509          * If cache supports reset, reset instead of init if already
510          * initialized. Reset signals to the cache that global IDs
511          * have changed and it may need to update keys and cleanup caches.
512          */
513         if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) {
514                 wp_cache_switch_to_blog( get_current_blog_id() );
515         } elseif ( function_exists( 'wp_cache_init' ) ) {
516                 wp_cache_init();
517         }
518
519         if ( function_exists( 'wp_cache_add_global_groups' ) ) {
520                 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
521                 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
522         }
523 }
524
525 /**
526  * Redirect to the installer if WordPress is not installed.
527  *
528  * Dies with an error message when Multisite is enabled.
529  *
530  * @since 3.0.0
531  * @access private
532  */
533 function wp_not_installed() {
534         if ( is_multisite() ) {
535                 if ( ! is_blog_installed() && ! wp_installing() ) {
536                         nocache_headers();
537
538                         wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
539                 }
540         } elseif ( ! is_blog_installed() && ! wp_installing() ) {
541                 nocache_headers();
542
543                 require( ABSPATH . WPINC . '/kses.php' );
544                 require( ABSPATH . WPINC . '/pluggable.php' );
545                 require( ABSPATH . WPINC . '/formatting.php' );
546
547                 $link = wp_guess_url() . '/wp-admin/install.php';
548
549                 wp_redirect( $link );
550                 die();
551         }
552 }
553
554 /**
555  * Retrieve an array of must-use plugin files.
556  *
557  * The default directory is wp-content/mu-plugins. To change the default
558  * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL`
559  * in wp-config.php.
560  *
561  * @since 3.0.0
562  * @access private
563  *
564  * @return array Files to include.
565  */
566 function wp_get_mu_plugins() {
567         $mu_plugins = array();
568         if ( !is_dir( WPMU_PLUGIN_DIR ) )
569                 return $mu_plugins;
570         if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) )
571                 return $mu_plugins;
572         while ( ( $plugin = readdir( $dh ) ) !== false ) {
573                 if ( substr( $plugin, -4 ) == '.php' )
574                         $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
575         }
576         closedir( $dh );
577         sort( $mu_plugins );
578
579         return $mu_plugins;
580 }
581
582 /**
583  * Retrieve an array of active and valid plugin files.
584  *
585  * While upgrading or installing WordPress, no plugins are returned.
586  *
587  * The default directory is wp-content/plugins. To change the default
588  * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL`
589  * in wp-config.php.
590  *
591  * @since 3.0.0
592  * @access private
593  *
594  * @return array Files.
595  */
596 function wp_get_active_and_valid_plugins() {
597         $plugins = array();
598 //      $active_plugins = (array) get_option( 'active_plugins', array() );
599         // Magic3暫定
600         $active_plugins = array();
601         $active_plugins[] = 'wp-multibyte-patch/wp-multibyte-patch.php';
602
603         // Check for hacks file if the option is enabled
604         if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
605                 _deprecated_file( 'my-hacks.php', '1.5.0' );
606                 array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
607         }
608
609         if ( empty( $active_plugins ) || wp_installing() )
610                 return $plugins;
611
612         $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
613
614         foreach ( $active_plugins as $plugin ) {
615                 if ( ! validate_file( $plugin ) // $plugin must validate as file
616                         && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
617                         && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
618                         // not already included as a network plugin
619                         && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) )
620                         )
621                 $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
622         }
623         return $plugins;
624 }
625
626 /**
627  * Set internal encoding.
628  *
629  * In most cases the default internal encoding is latin1, which is
630  * of no use, since we want to use the `mb_` functions for `utf-8` strings.
631  *
632  * @since 3.0.0
633  * @access private
634  */
635 function wp_set_internal_encoding() {
636         if ( function_exists( 'mb_internal_encoding' ) ) {
637                 $charset = get_option( 'blog_charset' );
638                 if ( ! $charset || ! @mb_internal_encoding( $charset ) )
639                         mb_internal_encoding( 'UTF-8' );
640         }
641 }
642
643 /**
644  * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`.
645  *
646  * Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`,
647  * `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly.
648  *
649  * @since 3.0.0
650  * @access private
651  */
652 function wp_magic_quotes() {
653         // If already slashed, strip.
654         if ( get_magic_quotes_gpc() ) {
655                 $_GET    = stripslashes_deep( $_GET    );
656                 $_POST   = stripslashes_deep( $_POST   );
657                 $_COOKIE = stripslashes_deep( $_COOKIE );
658         }
659
660         // Escape with wpdb.
661         $_GET    = add_magic_quotes( $_GET    );
662         $_POST   = add_magic_quotes( $_POST   );
663         $_COOKIE = add_magic_quotes( $_COOKIE );
664         $_SERVER = add_magic_quotes( $_SERVER );
665
666         // Force REQUEST to be GET + POST.
667         $_REQUEST = array_merge( $_GET, $_POST );
668 }
669
670 /**
671  * Runs just before PHP shuts down execution.
672  *
673  * @since 1.2.0
674  * @access private
675  */
676 function shutdown_action_hook() {
677         /**
678          * Fires just before PHP shuts down execution.
679          *
680          * @since 1.2.0
681          */
682         // WooCommerceセッション保存処理等
683         do_action( 'shutdown' );
684
685 //      wp_cache_close();
686 }
687
688 /**
689  * Copy an object.
690  *
691  * @since 2.7.0
692  * @deprecated 3.2.0
693  *
694  * @param object $object The object to clone.
695  * @return object The cloned object.
696  */
697 function wp_clone( $object ) {
698         // Use parens for clone to accommodate PHP 4. See #17880
699         return clone( $object );
700 }
701
702 /**
703  * Whether the current request is for an administrative interface page.
704  *
705  * Does not check if the user is an administrator; current_user_can()
706  * for checking roles and capabilities.
707  *
708  * @since 1.5.1
709  *
710  * @global WP_Screen $current_screen
711  *
712  * @return bool True if inside WordPress administration interface, false otherwise.
713  */
714 function is_admin() {
715         if ( isset( $GLOBALS['current_screen'] ) )
716                 return $GLOBALS['current_screen']->in_admin();
717         elseif ( defined( 'WP_ADMIN' ) )
718                 return WP_ADMIN;
719
720         return false;
721 }
722
723 /**
724  * Whether the current request is for a site's admininstrative interface.
725  *
726  * e.g. `/wp-admin/`
727  *
728  * Does not check if the user is an administrator; current_user_can()
729  * for checking roles and capabilities.
730  *
731  * @since 3.1.0
732  *
733  * @global WP_Screen $current_screen
734  *
735  * @return bool True if inside WordPress blog administration pages.
736  */
737 /*function is_blog_admin() {
738         if ( isset( $GLOBALS['current_screen'] ) )
739                 return $GLOBALS['current_screen']->in_admin( 'site' );
740         elseif ( defined( 'WP_BLOG_ADMIN' ) )
741                 return WP_BLOG_ADMIN;
742
743         return false;
744 }*/
745
746 /**
747  * Whether the current request is for the network administrative interface.
748  *
749  * e.g. `/wp-admin/network/`
750  *
751  * Does not check if the user is an administrator; current_user_can()
752  * for checking roles and capabilities.
753  *
754  * @since 3.1.0
755  *
756  * @global WP_Screen $current_screen
757  *
758  * @return bool True if inside WordPress network administration pages.
759  */
760 function is_network_admin() {
761         if ( isset( $GLOBALS['current_screen'] ) )
762                 return $GLOBALS['current_screen']->in_admin( 'network' );
763         elseif ( defined( 'WP_NETWORK_ADMIN' ) )
764                 return WP_NETWORK_ADMIN;
765
766         return false;
767 }
768
769 /**
770  * Whether the current request is for a user admin screen.
771  *
772  * e.g. `/wp-admin/user/`
773  *
774  * Does not inform on whether the user is an admin! Use capability
775  * checks to tell if the user should be accessing a section or not
776  * current_user_can().
777  *
778  * @since 3.1.0
779  *
780  * @global WP_Screen $current_screen
781  *
782  * @return bool True if inside WordPress user administration pages.
783  */
784 function is_user_admin() {
785         if ( isset( $GLOBALS['current_screen'] ) )
786                 return $GLOBALS['current_screen']->in_admin( 'user' );
787         elseif ( defined( 'WP_USER_ADMIN' ) )
788                 return WP_USER_ADMIN;
789
790         return false;
791 }
792
793 /**
794  * If Multisite is enabled.
795  *
796  * @since 3.0.0
797  *
798  * @return bool True if Multisite is enabled, false otherwise.
799  */
800 function is_multisite() {
801         if ( defined( 'MULTISITE' ) )
802                 return MULTISITE;
803
804         if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) )
805                 return true;
806
807         return false;
808 }
809
810 /**
811  * Retrieve the current site ID.
812  *
813  * @since 3.1.0
814  *
815  * @global int $blog_id
816  *
817  * @return int Site ID.
818  */
819 function get_current_blog_id() {
820         global $blog_id;
821         return absint($blog_id);
822 }
823
824 /**
825  * Retrieves the current network ID.
826  *
827  * @since 4.6.0
828  *
829  * @return int The ID of the current network.
830  */
831 function get_current_network_id() {
832         if ( ! is_multisite() ) {
833                 return 1;
834         }
835
836         $current_network = get_network();
837
838         if ( ! isset( $current_network->id ) ) {
839                 return get_main_network_id();
840         }
841
842         return absint( $current_network->id );
843 }
844
845 /**
846  * Attempt an early load of translations.
847  *
848  * Used for errors encountered during the initial loading process, before
849  * the locale has been properly detected and loaded.
850  *
851  * Designed for unusual load sequences (like setup-config.php) or for when
852  * the script will then terminate with an error, otherwise there is a risk
853  * that a file can be double-included.
854  *
855  * @since 3.4.0
856  * @access private
857  *
858  * @global WP_Locale $wp_locale The WordPress date and time locale object.
859  *
860  * @staticvar bool $loaded
861  */
862 function wp_load_translations_early() {
863         global $wp_locale;
864
865         static $loaded = false;
866         if ( $loaded )
867                 return;
868         $loaded = true;
869
870         if ( function_exists( 'did_action' ) && did_action( 'init' ) )
871                 return;
872
873         // We need $wp_local_package
874         require ABSPATH . WPINC . '/version.php';
875
876         // Translation and localization
877         require_once ABSPATH . WPINC . '/pomo/mo.php';
878         require_once ABSPATH . WPINC . '/l10n.php';
879         require_once ABSPATH . WPINC . '/class-wp-locale.php';
880         require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php';
881
882         // General libraries
883         require_once ABSPATH . WPINC . '/plugin.php';
884
885         $locales = $locations = array();
886
887         while ( true ) {
888                 if ( defined( 'WPLANG' ) ) {
889                         if ( '' == WPLANG )
890                                 break;
891                         $locales[] = WPLANG;
892                 }
893
894                 if ( isset( $wp_local_package ) )
895                         $locales[] = $wp_local_package;
896
897                 if ( ! $locales )
898                         break;
899
900                 if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) )
901                         $locations[] = WP_LANG_DIR;
902
903                 if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) )
904                         $locations[] = WP_CONTENT_DIR . '/languages';
905
906                 if ( @is_dir( ABSPATH . 'wp-content/languages' ) )
907                         $locations[] = ABSPATH . 'wp-content/languages';
908
909                 if ( @is_dir( ABSPATH . WPINC . '/languages' ) )
910                         $locations[] = ABSPATH . WPINC . '/languages';
911
912                 if ( ! $locations )
913                         break;
914
915                 $locations = array_unique( $locations );
916
917                 foreach ( $locales as $locale ) {
918                         foreach ( $locations as $location ) {
919                                 if ( file_exists( $location . '/' . $locale . '.mo' ) ) {
920                                         load_textdomain( 'default', $location . '/' . $locale . '.mo' );
921                                         if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) )
922                                                 load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' );
923                                         break 2;
924                                 }
925                         }
926                 }
927
928                 break;
929         }
930
931         $wp_locale = new WP_Locale();
932 }
933
934 /**
935  * Check or set whether WordPress is in "installation" mode.
936  *
937  * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`.
938  *
939  * @since 4.4.0
940  *
941  * @staticvar bool $installing
942  *
943  * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off.
944  *                            Omit this parameter if you only want to fetch the current status.
945  * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will
946  *              report whether WP was in installing mode prior to the change to `$is_installing`.
947  */
948 function wp_installing( $is_installing = null ) {
949         static $installing = null;
950
951         // Support for the `WP_INSTALLING` constant, defined before WP is loaded.
952         if ( is_null( $installing ) ) {
953                 $installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING;
954         }
955
956         if ( ! is_null( $is_installing ) ) {
957                 $old_installing = $installing;
958                 $installing = $is_installing;
959                 return (bool) $old_installing;
960         }
961
962         return (bool) $installing;
963 }
964
965 /**
966  * Determines if SSL is used.
967  *
968  * @since 2.6.0
969  * @since 4.6.0 Moved from functions.php to load.php.
970  *
971  * @return bool True if SSL, otherwise false.
972  */
973 function is_ssl() {
974         if ( isset( $_SERVER['HTTPS'] ) ) {
975                 if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) {
976                         return true;
977                 }
978
979                 if ( '1' == $_SERVER['HTTPS'] ) {
980                         return true;
981                 }
982         } elseif ( isset($_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
983                 return true;
984         }
985         return false;
986 }
987
988 /**
989  * Converts a shorthand byte value to an integer byte value.
990  *
991  * @since 2.3.0
992  * @since 4.6.0 Moved from media.php to load.php.
993  *
994  * @link https://secure.php.net/manual/en/function.ini-get.php
995  * @link https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
996  *
997  * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
998  * @return int An integer byte value.
999  */
1000 function wp_convert_hr_to_bytes( $value ) {
1001         $value = strtolower( trim( $value ) );
1002         $bytes = (int) $value;
1003
1004         if ( false !== strpos( $value, 'g' ) ) {
1005                 $bytes *= GB_IN_BYTES;
1006         } elseif ( false !== strpos( $value, 'm' ) ) {
1007                 $bytes *= MB_IN_BYTES;
1008         } elseif ( false !== strpos( $value, 'k' ) ) {
1009                 $bytes *= KB_IN_BYTES;
1010         }
1011
1012         // Deal with large (float) values which run into the maximum integer size.
1013         return min( $bytes, PHP_INT_MAX );
1014 }
1015
1016 /**
1017  * Determines whether a PHP ini value is changeable at runtime.
1018  *
1019  * @since 4.6.0
1020  *
1021  * @link https://secure.php.net/manual/en/function.ini-get-all.php
1022  *
1023  * @param string $setting The name of the ini setting to check.
1024  * @return bool True if the value is changeable at runtime. False otherwise.
1025  */
1026 function wp_is_ini_value_changeable( $setting ) {
1027         static $ini_all;
1028
1029         if ( ! isset( $ini_all ) ) {
1030                 $ini_all = false;
1031                 // Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes".
1032                 if ( function_exists( 'ini_get_all' ) ) {
1033                         $ini_all = ini_get_all();
1034                 }
1035         }
1036
1037         // 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.
1038         if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) {
1039                 return true;
1040         }
1041
1042         // If we were unable to retrieve the details, fail gracefully to assume it's changeable.
1043         if ( ! is_array( $ini_all ) ) {
1044                 return true;
1045         }
1046
1047         return false;
1048 }
1049
1050 /**
1051  * Determines whether the current request is a WordPress Ajax request.
1052  *
1053  * @since 4.7.0
1054  *
1055  * @return bool True if it's a WordPress Ajax request, false otherwise.
1056  */
1057 function wp_doing_ajax() {
1058         // AJAX起動かどうかは$_GET['wc-ajax']の値があるかどうかで判断される
1059         /**
1060          * Filters whether the current request is a WordPress Ajax request.
1061          *
1062          * @since 4.7.0
1063          *
1064          * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request.
1065          */
1066         return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
1067 }
1068
1069 /**
1070  * Check whether variable is a WordPress Error.
1071  *
1072  * Returns true if $thing is an object of the WP_Error class.
1073  *
1074  * @since 2.1.0
1075  *
1076  * @param mixed $thing Check if unknown variable is a WP_Error object.
1077  * @return bool True, if WP_Error. False, if not WP_Error.
1078  */
1079 function is_wp_error( $thing ) {
1080         return ( $thing instanceof WP_Error );
1081 }