Last active
August 10, 2017 04:49
-
-
Save ipokkel/bcc6b1bde4b5a5b44b110aa06c948ddf to your computer and use it in GitHub Desktop.
Wordpress 3rd party depency checks. Verify that a specific theme, child theme or plugin is installed and active. This snippet checks wheter the Divi theme, Divi child theme or Divi Builder plugin is installed.
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 | |
/** | |
* @version 1.0.0 | |
* @author Theuns Coetzee (pokkel/ipokkel) | |
* @link http://www.theunscoetzee.com | |
*/ | |
/** | |
* @param checkstatus( string, bool ) | |
* Accepts string and boolean argument | |
* Returns string in green when boolean true and red when false | |
*/ | |
function checkstatus($checked_item, $checked_status) { | |
$the_colour = 'red'; | |
if ($checked_status) { | |
$the_colour = 'green'; | |
} | |
$the_phrase = '<div style="color:' . $the_colour . '"><p>' . $checked_item . '</p></div>'; | |
return $the_phrase; | |
} | |
function get_default_theme_stylesheet_path(){ | |
$the_theme_name = wp_get_theme()->get_core_default_theme()->get( 'TextDomain' ); | |
$the_stylesheet_path = get_theme_root() . '/' . $the_theme_name . '/style.css'; | |
return str_replace('\\', '/', $the_stylesheet_path); | |
} | |
function get_active_theme_stylesheet_path(){ | |
$the_stylesheet_path = wp_get_theme()->get_stylesheet_directory() . '/style.css'; | |
return str_replace('\\', '/', $the_stylesheet_path); | |
} | |
function get_custom_theme_stylesheet_path($the_theme_name){ | |
$the_stylesheet_path = get_theme_root() . '/' . $the_theme_name . '/style.css'; | |
return str_replace('\\', '/', $the_stylesheet_path); | |
} | |
function validate_theme_stylesheet($the_theme_name) { | |
if ( ! file_exists( get_custom_theme_stylesheet_path($the_theme_name) ) ) { | |
// Invalid. | |
} else { | |
// Valid. | |
return true; | |
} | |
} | |
// Check if the divi theme exist in the themes folder. | |
echo checkstatus('Divi theme exist', validate_theme_stylesheet('Divi')); // Done | |
// Check if Divi is the active theme | |
$theme = wp_get_theme( ); | |
echo checkstatus('Divi is active', ( wp_get_theme( )->name == 'Divi')); | |
// Check if Current theme has Divi as parent | |
echo checkstatus('Divi is parent', ( wp_get_theme()->template == 'Divi')); | |
// Check whether divi builder installed | |
echo checkstatus('Builder is active', (is_plugin_active('divi-builder/divi-builder.php'))); | |
$plugin_root = str_replace('\\', '/', WP_PLUGIN_DIR) . '/'; // convert backslash to forward slash in string when on windows. This can be removed for the stable/production version. | |
$Divi_Builder_Plugin_Path = $plugin_root . 'divi-builder/divi-builder.php'; // construct path string | |
echo checkstatus('plugin exist in directory but is not installed or active', (file_exists($Divi_Builder_Plugin_Path))); | |
// Check whether divi builder active | |
echo checkstatus('Divi Builder Plugin class exist', (class_exists('ET_Builder_Plugin'))); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment