resume_plugin

函数
resume_plugin ( $plugin, $redirect = '' )
参数
  • (string) $plugin Single plugin to resume.
    Required:
  • (string) $redirect Optional. URL to redirect to. Default empty string.
    Required:
    Default: (empty)
返回值
  • (bool|WP_Error) True on success, false if `$plugin` was not paused, `WP_Error` on failure.
定义位置
相关方法
delete_pluginsget_pluginsget_mu_pluginswp_update_pluginwp_update_plugins
引入
5.2.0
弃用
-

resume_plugin: 这是一个WordPress动作,当一个插件被停用后恢复时被触发: 当一个插件被停用时,它的功能不会被执行: 当该插件被重新激活时,resume_plugin被调用,允许该插件恢复其功能。

尝试恢复一个插件。

如果提供了一个重定向,我们首先确保该插件不再抛出致命的错误。

它的工作方式是,在尝试包含插件文件之前,将重定向设置为错误。如果该插件失败了,那么重定向将不会 被成功信息覆盖,并且该插件不会被恢复。”

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function resume_plugin( $plugin, $redirect = '' ) {
/*
* We'll override this later if the plugin could be resumed without
* creating a fatal error.
*/
if ( ! empty( $redirect ) ) {
wp_redirect(
add_query_arg(
'_error_nonce',
wp_create_nonce( 'plugin-resume-error_' . $plugin ),
$redirect
)
);
// Load the plugin to test whether it throws a fatal error.
ob_start();
plugin_sandbox_scrape( $plugin );
ob_clean();
}
list( $extension ) = explode( '/', $plugin );
$result = wp_paused_plugins()->delete( $extension );
if ( ! $result ) {
return new WP_Error(
'could_not_resume_plugin',
__( 'Could not resume the plugin.' )
);
}
return true;
}
function resume_plugin( $plugin, $redirect = '' ) { /* * We'll override this later if the plugin could be resumed without * creating a fatal error. */ if ( ! empty( $redirect ) ) { wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-resume-error_' . $plugin ), $redirect ) ); // Load the plugin to test whether it throws a fatal error. ob_start(); plugin_sandbox_scrape( $plugin ); ob_clean(); } list( $extension ) = explode( '/', $plugin ); $result = wp_paused_plugins()->delete( $extension ); if ( ! $result ) { return new WP_Error( 'could_not_resume_plugin', __( 'Could not resume the plugin.' ) ); } return true; }
function resume_plugin( $plugin, $redirect = '' ) {
	/*
	 * We'll override this later if the plugin could be resumed without
	 * creating a fatal error.
	 */
	if ( ! empty( $redirect ) ) {
		wp_redirect(
			add_query_arg(
				'_error_nonce',
				wp_create_nonce( 'plugin-resume-error_' . $plugin ),
				$redirect
			)
		);

		// Load the plugin to test whether it throws a fatal error.
		ob_start();
		plugin_sandbox_scrape( $plugin );
		ob_clean();
	}

	list( $extension ) = explode( '/', $plugin );

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

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

	return true;
}

常见问题

FAQs
查看更多 >