Last active
December 14, 2015 00:38
-
-
Save PaulHughes01/4999758 to your computer and use it in GitHub Desktop.
This is the code you can use to display the proper error messages for Modern Tribe's The Events Calendar add-ons. Instructions included in the comments below.
This file contains hidden or 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 | |
| /** | |
| * In the root plugin file, where you initialize your class on 'plugins_loaded', run a check | |
| * to see if class TribeEvents exists, if it doesn't, show the error message. This takes | |
| * care of if TEC is not installed. The below code is an example from | |
| * The Events Calendar: Community Events. | |
| */ | |
| /////////////////// | |
| // File: the-events-calendar-community-events/tribe-community-events.php | |
| /////////////////// | |
| // ... | |
| /** | |
| * Instantiate class and set up WordPress actions. | |
| */ | |
| function Tribe_CE_Load() { | |
| if ( class_exists( 'TribeEvents' ) && defined( 'TribeEvents::VERSION' ) ) { | |
| TribeCommunityEvents::instance(); | |
| } else { | |
| add_action( 'admin_notices', 'tribe_ce_show_fail_message' ); | |
| } | |
| } | |
| /** | |
| * Shows message if the plugin can't load due to TEC not being installed. | |
| */ | |
| function tribe_ce_show_fail_message() { | |
| if ( current_user_can( 'activate_plugins' ) ) { | |
| $url = 'plugin-install.php?tab=plugin-information&plugin=the-events-calendar&TB_iframe=true'; | |
| $title = __( 'The Events Calendar', 'tribe-events-community' ); | |
| echo '<div class="error"><p>'.sprintf( __( 'To begin using The Events Calendar: Community Events, please install the latest version of <a href="%s" class="thickbox" title="%s">The Events Calendar</a>.', 'tribe-events-community' ), $url, $title ) . '</p></div>'; | |
| } | |
| } | |
| add_action( 'plugins_loaded', 'Tribe_CE_Load', 1 ); // high priority so that it's not too late for tribe_register-helpers class | |
| //... | |
| /////////////////// | |
| /** | |
| * To the main class of the add-on, hook in an init_addon() method to the hook 'tribe_tec_addons'. | |
| * This takes care of making sure the versions line up. | |
| * This is the excerpt from the Community Events main class file. | |
| */ | |
| /////////////////// | |
| // File: the-events-calendar-community-events/tribe-community-events.class.php | |
| /////////////////// | |
| // ... | |
| /** | |
| * The current version of Community Events | |
| */ | |
| const VERSION = '1.0.6'; | |
| /** | |
| * required The Events Calendar Version | |
| */ | |
| const REQUIRED_TEC_VERSION = '3.0'; | |
| // ... | |
| add_filter( 'tribe_tec_addons', array( $this, 'init_addon' ) ); | |
| // ... | |
| public function init_addon( $plugins ) { | |
| $plugins['TribeCE'] = array( | |
| 'plugin_name' => 'The Events Calendar: Community Events', | |
| 'required_version' => TribeCommunityEvents::REQUIRED_TEC_VERSION, | |
| 'current_version' => TribeCommunityEvents::VERSION, | |
| 'plugin_dir_file' => basename( dirname( dirname( __FILE__ ) ) ) . '/tribe-community-events.php' | |
| ); | |
| return $plugins; | |
| } | |
| // ... | |
| /////////////////// | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment