pluginExists() ) {
add_filter( 'admin_notices', array( $this, 'displayAdminNotificationNotExist' ) );
// If the class doesn't exist, the plugin is inactive. Throw admin notice to activate plugin.
} else if ( ! class_exists( self::TITAN_CLASS ) ) {
add_filter( 'admin_notices', array( $this, 'displayAdminNotificationInactive' ) );
}
}
/**
* Displays a notification in the admin with a link to search
*
* @since 1.6
*/
public function displayAdminNotificationNotExist() {
// Check for TGM use, if used, let TGM do the notice.
// We do this here since performCheck() is too early
if ( $this->tgmPluginActivationExists() ) {
return;
}
echo "
"
. __( "Titan Framework needs to be installed.", "default" )
. sprintf( " %s",
admin_url( "plugin-install.php?tab=search&type=term&s=titan+framework" ),
__( "Click here to search for the plugin.", "default" ) )
. "
";
}
/**
* Displays a notification in the admin if the Titan Framework is found but not activated.
*
* @since 1.6
*/
public function displayAdminNotificationInactive() {
// Check for TGM use, if used, let TGM do the notice.
// We do this here since performCheck() is too early
if ( $this->tgmPluginActivationExists() ) {
return;
}
echo ""
. __( "Titan Framework needs to be activated.", "default" )
. sprintf( " %s",
admin_url( "plugins.php" ),
__( "Click here to go to the plugins page and activate it.", "default" ) )
. "
";
}
/**
* Checks the existence of Titan Framework in the list of plugins,
* uses the slug path of the plugin for checking.
*
* @return boolean True if the TF exists
* @since 1.6
*/
public function pluginExists() {
// Required function as it is only loaded in admin pages.
require_once ABSPATH . 'wp-admin/includes/plugin.php';
// Get all plugins, activated or not.
$plugins = get_plugins();
// Check plugin existence by checking if the name is registered as an array key. get_plugins collects all plugin path into arrays.
foreach ( $plugins as $slug => $plugin ) {
if ( preg_match( self::SEARCH_REGEX, $slug, $matches ) ) {
return true;
}
}
return false;
}
/**
* Checks whether TGM Plugin Activation is being used.
*
* @return boolean True if the TF was used in TGM
* @since 1.7.4
* @see http://tgmpluginactivation.com/
*/
public function tgmPluginActivationExists() {
return class_exists( 'TGM_Plugin_Activation' )
&& function_exists( 'tgmpa' );
}
/**
* Includes Titan Framework in TGM Plugin Activation if it's
* available.
*
* @return void
* @since 1.7.4
* @see http://tgmpluginactivation.com/
*/
public function tgmPluginActivationInclude() {
if ( ! $this->tgmPluginActivationExists() ) {
return;
}
tgmpa( array(
array(
'name' => 'Titan Framework',
'slug' => self::PLUGIN_SLUG,
'required' => true,
),
) );
}
}
new TitanFrameworkChecker();
}