php - Wordpress trying to activate wrong plugin -
when try activate plugin wrote, wordpres tries activate wrong plugin, go plugins->installed plugins , activate, wordpress return error message 'anspress' plugin can't found.
my plugin's name "academy", folder name "academy", plugin filename "academy.php".
academy.php content:
<?php /** * @package academy */ /* plugin name: academy description: academy features version: 0.1 author: victor aurélio santos text domain: academy */ /* is_plugin_active */ include_once( abspath . 'wp-admin/includes/plugin.php' ); define ('academy_include', plugin_dir_path( __file__ ) . '/include'); define ('academy_temaple', academy_include . '/templates'); global $academy_err; $academy_err = array(); $plugin_dependencies = array('woocommerce' => false, 'anspress' => false); /* dependencies check */ foreach ($plugin_dependencies $plugin => &$enabled) { if (! $enabled = is_plugin_active("{$plugin}/{$plugin}.php") ) { $academy_err[] = "the {$plugin} plugin isn't installed and/or activated."; } } /* check current theme, if not 'academy' don't load files depends... */ if ( "academy" == wp_get_theme()->name ) { include academy_include . '/buddypress/bp-loader.php'; include academy_include . '/news-feed.php'; } else { $academy_err[] = "current theme isn't \"academy\" not loading newsfeed..."; } /* check woocommerce */ if ( $plugin_dependencies['woocommerce'] && $plugin_dependencies['anspress'] ){ include academy_include . '/anspress-woocommerce.php'; } include (academy_include . '/settings.php'); function academy_admin_notices() { global $academy_err; foreach ($academy_err $err) { ?> <div class="update-nag"> <p>academy error: <?php echo $err; ?></p> </div> <?php } } add_action('admin_notices', 'academy_admin_notices'); function academy_init() { $plugin_dir = basename(dirname(__file__)) . '/languages'; load_plugin_textdomain( 'academy', false, $plugin_dir ); } add_action('plugins_loaded', 'academy_init'); function academy_plugin_action_links ($links, $file) { static $this_plugin; if (!$this_plugin) { $this_plugin = plugin_basename(__file__); } if ($file == $this_plugin) { $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php? page=academy-settings">' . __('settings', 'academy') . '</a>'; array_unshift($links, $settings_link); } return $links; } add_filter('plugin_action_links', 'academy_plugin_action_links', 10, 2); i think wrong plugin, can't find what.
at root of plugin, should avoid @ costs doing direct calls wordpress functions. best practice encapsulate inside relevant hooks.
the function get_option safe use, though. it, deal includes.
for rest, use register_activation_hook grab active plugins on activation. check activation/deactivation of required plugins, can use hooks activate_$pluginname , deactivate_$pluginname. theme state changes can captured hook after_switch_theme.
<?php /** * plugin name: (so) academy * plugin uri: http://stackoverflow.com/a/22648487/1287812 * description: activate plugin, check others, show warnings * version: 0.1b * author: victor aurélio santos, brasofilo */ define ('academy_include', plugin_dir_path( __file__ ) . '/include'); define ('academy_temaple', academy_include . '/templates'); $academy_err = get_option('academy_err'); if( !isset( $academy_err['woocommerce'] ) && !isset( $academy_err['anspress'] ) ) { include academy_include . '/anspress-woocommerce.php'; } if( !isset( $academy_err['theme'] ) ) { include academy_include . '/buddypress/bp-loader.php'; include academy_include . '/news-feed.php'; } include (academy_include . '/settings.php'); register_activation_hook( __file__, 'academy_on_activation' ); add_action( 'admin_notices', 'academy_admin_notices' ); add_action( 'activate_woocommerce/woocommerce.php', 'activate_plugin_woocommerce' ); function academy_on_activation() { $academy_err = array(); $plugin_dependencies = array( 'woocommerce' => 'woocommerce/woocommerce.php', 'anspress' => 'anspress/anspress.php' ); /* dependencies check */ foreach ( $plugin_dependencies $plugin => $file ) { if ( !is_plugin_active( $file ) ) { $academy_err[$plugin] = "the {$plugin} plugin isn't installed and/or activated."; } } /* check current theme, if not 'academy' don't load files depends... */ if ( 'academy' !== wp_get_theme()->name ) { $academy_err['theme'] = "current theme isn't \"academy\" not loading newsfeed..."; } update_option( 'academy_err', $academy_err ); } function academy_admin_notices() { $academy_err = get_option('academy_err'); foreach ($academy_err $err) { ?> <div class="update-nag"> <p>academy error: <?php echo $err; ?></p> </div> <?php } } function activate_plugin_woocommerce() { $academy_err = get_option('academy_err'); unset( $academy_err['woocommerce'] ); update_option( 'academy_err', $academy_err ); } to start oop , rid of defines , globals, here's nice plugin base.
Comments
Post a Comment