Last active
December 18, 2018 05:38
-
-
Save huanyichuang/47735fb9c15307105ee330fdea5d3bb5 to your computer and use it in GitHub Desktop.
Use this action to check if required WordPress plugins are already installed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 因為在開發佈景主題的時候,會使用其他外掛的 shortcodes 來輔助。 | |
* 掛在佈景主題的 functions.php 裡面,可以提醒使用者安裝相容的外掛。 | |
*/ | |
add_action( 'admin_init', 'check_plugin'); | |
function check_plugin() { | |
$plugins = array( | |
'plugin-name' => array( | |
'name' => 'plugin-name', | |
'path' => 'plugin-directory/plugin-file.php', | |
'url' => 'https://plugin.url/', | |
), | |
); | |
foreach ($plugins as $plugin){ | |
if ( !is_plugin_active( $plugin['path'] ) ) { | |
add_action( 'admin_notices', function() use( $plugin ) {?> | |
<div class="notice notice-warning is-dismissible"><p><?php esc_html_e('To fully apply this theme, please install required plugin: ','text-domain'); ?><a href="<?php echo $plugin['url']; ?>" title="<?php echo $plugin['name']; ?>"><?php echo $plugin['name']; ?></a></p></div> | |
<?php } ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment