resume_theme

函式
resume_theme ( $theme, $redirect = '' )
引數
  • (string) $theme Single theme to resume.
    Required:
  • (string) $redirect Optional. URL to redirect to. Default empty string.
    Required:
    Default: (empty)
返回值
  • (bool|WP_Error) True on success, false if `$theme` was not paused, `WP_Error` on failure.
定義位置
相關方法
preview_themeremove_theme_modremove_theme_modsget_themedelete_theme
引入
5.2.0
棄用
-

resume_theme: 這是一個WordPress動作,當一個主題被停用後恢復時被觸發: 當一個主題被停用時,它的功能不會被執行: 當主題被重新啟用時,resume_theme被呼叫,允許主題恢復它的功能。

試圖恢復一個單一的主題。

如果提供了重定向,並且找到了function.php檔案,我們首先確保function.php檔案不再丟擲致命的錯誤。

它的工作方式是在嘗試包含該檔案之前將重定向設定為錯誤。如果主題失敗了,那麼重定向將不會被成功資訊覆蓋,主題也不會被恢復。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function resume_theme( $theme, $redirect = '' ) {
list( $extension ) = explode( '/', $theme );
/*
* We'll override this later if the theme could be resumed without
* creating a fatal error.
*/
if ( ! empty( $redirect ) ) {
$functions_path = '';
if ( strpos( STYLESHEETPATH, $extension ) ) {
$functions_path = STYLESHEETPATH . '/functions.php';
} elseif ( strpos( TEMPLATEPATH, $extension ) ) {
$functions_path = TEMPLATEPATH . '/functions.php';
}
if ( ! empty( $functions_path ) ) {
wp_redirect(
add_query_arg(
'_error_nonce',
wp_create_nonce( 'theme-resume-error_' . $theme ),
$redirect
)
);
// Load the theme's functions.php to test whether it throws a fatal error.
ob_start();
if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
define( 'WP_SANDBOX_SCRAPING', true );
}
include $functions_path;
ob_clean();
}
}
$result = wp_paused_themes()->delete( $extension );
if ( ! $result ) {
return new WP_Error(
'could_not_resume_theme',
__( 'Could not resume the theme.' )
);
}
return true;
}
function resume_theme( $theme, $redirect = '' ) { list( $extension ) = explode( '/', $theme ); /* * We'll override this later if the theme could be resumed without * creating a fatal error. */ if ( ! empty( $redirect ) ) { $functions_path = ''; if ( strpos( STYLESHEETPATH, $extension ) ) { $functions_path = STYLESHEETPATH . '/functions.php'; } elseif ( strpos( TEMPLATEPATH, $extension ) ) { $functions_path = TEMPLATEPATH . '/functions.php'; } if ( ! empty( $functions_path ) ) { wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'theme-resume-error_' . $theme ), $redirect ) ); // Load the theme's functions.php to test whether it throws a fatal error. ob_start(); if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) { define( 'WP_SANDBOX_SCRAPING', true ); } include $functions_path; ob_clean(); } } $result = wp_paused_themes()->delete( $extension ); if ( ! $result ) { return new WP_Error( 'could_not_resume_theme', __( 'Could not resume the theme.' ) ); } return true; }
function resume_theme( $theme, $redirect = '' ) {
	list( $extension ) = explode( '/', $theme );

	/*
	 * We'll override this later if the theme could be resumed without
	 * creating a fatal error.
	 */
	if ( ! empty( $redirect ) ) {
		$functions_path = '';
		if ( strpos( STYLESHEETPATH, $extension ) ) {
			$functions_path = STYLESHEETPATH . '/functions.php';
		} elseif ( strpos( TEMPLATEPATH, $extension ) ) {
			$functions_path = TEMPLATEPATH . '/functions.php';
		}

		if ( ! empty( $functions_path ) ) {
			wp_redirect(
				add_query_arg(
					'_error_nonce',
					wp_create_nonce( 'theme-resume-error_' . $theme ),
					$redirect
				)
			);

			// Load the theme's functions.php to test whether it throws a fatal error.
			ob_start();
			if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {
				define( 'WP_SANDBOX_SCRAPING', true );
			}
			include $functions_path;
			ob_clean();
		}
	}

	$result = wp_paused_themes()->delete( $extension );

	if ( ! $result ) {
		return new WP_Error(
			'could_not_resume_theme',
			__( 'Could not resume the theme.' )
		);
	}

	return true;
}

常見問題

FAQs
檢視更多 >