wp_is_maintenance_mode

函式
wp_is_maintenance_mode ( No parameters )
返回值
  • (bool) True if maintenance mode is enabled, false otherwise.
定義位置
相關方法
wp_maintenancewp_is_recovery_modewp_set_internal_encodingmaintenance_nagwp_json_encode
引入
5.5.0
棄用
-

wp_is_maintenance_mode: 這個函式用來檢查WordPress網站是否處於維護模式。如果網站處於維護模式,它返回true,否則返回false。

檢查是否啟用了維護模式。

檢查WordPress根目錄下是否有一個名為””.maintenance””的檔案。這個檔案將包含變數$upgrading,設定為檔案的建立時間。如果該檔案是在不到10分鐘前建立的,那麼WordPress就處於維護模式。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_is_maintenance_mode() {
global $upgrading;
if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) {
return false;
}
require ABSPATH . '.maintenance';
// If the $upgrading timestamp is older than 10 minutes, consider maintenance over.
if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) {
return false;
}
/**
* Filters whether to enable maintenance mode.
*
* This filter runs before it can be used by plugins. It is designed for
* non-web runtimes. If this filter returns true, maintenance mode will be
* active and the request will end. If false, the request will be allowed to
* continue processing even if maintenance mode should be active.
*
* @since 4.6.0
*
* @param bool $enable_checks Whether to enable maintenance mode. Default true.
* @param int $upgrading The timestamp set in the .maintenance file.
*/
if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
return false;
}
return true;
}
function wp_is_maintenance_mode() { global $upgrading; if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) { return false; } require ABSPATH . '.maintenance'; // If the $upgrading timestamp is older than 10 minutes, consider maintenance over. if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) { return false; } /** * Filters whether to enable maintenance mode. * * This filter runs before it can be used by plugins. It is designed for * non-web runtimes. If this filter returns true, maintenance mode will be * active and the request will end. If false, the request will be allowed to * continue processing even if maintenance mode should be active. * * @since 4.6.0 * * @param bool $enable_checks Whether to enable maintenance mode. Default true. * @param int $upgrading The timestamp set in the .maintenance file. */ if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) { return false; } return true; }
function wp_is_maintenance_mode() {
	global $upgrading;

	if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) {
		return false;
	}

	require ABSPATH . '.maintenance';
	// If the $upgrading timestamp is older than 10 minutes, consider maintenance over.
	if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) {
		return false;
	}

	/**
	 * Filters whether to enable maintenance mode.
	 *
	 * This filter runs before it can be used by plugins. It is designed for
	 * non-web runtimes. If this filter returns true, maintenance mode will be
	 * active and the request will end. If false, the request will be allowed to
	 * continue processing even if maintenance mode should be active.
	 *
	 * @since 4.6.0
	 *
	 * @param bool $enable_checks Whether to enable maintenance mode. Default true.
	 * @param int  $upgrading     The timestamp set in the .maintenance file.
	 */
	if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
		return false;
	}

	return true;
}

常見問題

FAQs
檢視更多 >