php 依赖插件激活/停用和警报

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 依赖插件激活/停用和警报相关的知识,希望对你有一定的参考价值。

<?php 
/*
 * Dependent Plugin Activation/Deactivation
 * 
 * Sources:
 * 1. https://pippinsplugins.com/checking-dependent-plugin-active/
 * 2. http://10up.com/blog/2012/wordpress-plug-in-self-deactivation/
 *
 */
 
function child_plugin_init() {
	
	// If Parent Plugin is NOT active
	if ( current_user_can( 'activate_plugins' ) && !class_exists( 'Parent Plugin Class' ) ) {
		
		add_action( 'admin_init', 'my_plugin_deactivate' );
		add_action( 'admin_notices', 'my_plugin_admin_notice' );
		
		// Deactivate the Child Plugin
		function my_plugin_deactivate() {
		  deactivate_plugins( plugin_basename( __FILE__ ) );
		}
		
		// Throw an Alert to tell the Admin why it didn't activate
		function my_plugin_admin_notice() {
			$dpa_child_plugin = __( 'Child Plugin', 'textdomain' );
            		$dpa_parent_plugin = __( 'Parent Plugin', 'textdomain' );
            		
            		echo '<div class="error"><p>'
                		. sprintf( __( '%1$s requires %2$s to function correctly. Please activate %2$s before activating %1$s. For now, the plugin has been deactivated.', 'textdomain' ), '<strong>' . esc_html( $dpa_child_plugin ) . '</strong>', '<strong>' . esc_html( $dpa_parent_plugin ) . '</strong>' )
                		. '</p></div>';
                
		   if ( isset( $_GET['activate'] ) )
			unset( $_GET['activate'] );
		}

    	} else {
		
	// include all your plugin files here
		
	}
}

add_action( 'plugins_loaded', 'child_plugin_init' );

以上是关于php 依赖插件激活/停用和警报的主要内容,如果未能解决你的问题,请参考以下文章

C#:Excel 2007 插件,如何挂钩 Windows 激活和停用事件

我无法在 localhost 上激活我的 WordPress 插件

php 插件停用#white

PHP 停用所有wordpress插件

如何从wordpress站点停用维护模式

激活和停用 textInput