Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.00 KB | None | 0 0
  1. ?php
  2.  
  3. /**
  4.  * A class for managing plugin dependencies and loading the plugin.
  5.  *
  6.  * @package WordPress
  7.  * @subpackage LXB_Boilerplate
  8.  * @since LXB_Boilerplate 0.1
  9.  */
  10.  
  11.  
  12. // This has to occur in the global scope.
  13. new LXB_BOILERPLATE_Bootstrap;
  14.  
  15. class LXB_BOILERPLATE_Bootstrap {
  16.  
  17.     function __construct() {
  18.  
  19.         add_action( 'plugins_loaded', array( $this, 'test' ), 1 );
  20.  
  21.         add_action( 'after_setup_theme', array( $this, 'load' ) );
  22.  
  23.         add_action( 'admin_notices', array( $this, 'warn' ) );
  24.         add_action( 'network_admin_notices', array( $this, 'warn' ) );
  25.  
  26.     }
  27.  
  28.     /**
  29.      * Setup the required components for unit testing.
  30.      */
  31.     function test() {
  32.        
  33.         // This function is only important during unit tests.
  34.         if( ! defined( 'WP_TESTS_MULTISITE' ) ) { return FALSE; }
  35.  
  36.         $dm_file = '../../plugins/wordpress-mu-domain-mapping/domain_mapping.php';
  37.         require_once( $dm_file );
  38.  
  39.         $zd_file = '../../plugins/lxb-zendesk/plugin.php';
  40.         require_once( $zd_file );
  41.  
  42.         $nsfw_file = realpath( '../../plugins/lxb-network-settings-factory-warehouse/plugin.php' );
  43.         require_once( $nsfw_file );
  44.  
  45.         $mct_file = realpath( '../../plugins/lxb-mailchimp-tools/lxb-mailchimp-tools.php' );
  46.         require_once( $mct_file );
  47.  
  48.         $cf_file = realpath( '../../plugins/lxb-cloudflare-toolbar/lxb-cloudflare-toolbar.php' );
  49.         require_once( $cf_file );
  50.  
  51.         $import_users_file = realpath( '../../plugins/lxb-import-users-from-csv/import-users-from-csv.php' );
  52.         require_once( $import_users_file );
  53.  
  54.     }
  55.  
  56.     /**
  57.      * Without all of its dependencies, this plugin throws some admin notices.
  58.      */
  59.     function warn() {
  60.  
  61.         $out = '';
  62.  
  63.         $messages = array();
  64.  
  65.         if( ! defined( 'LXB_ZENDESK' ) ) {
  66.             $messages[]= esc_html__( 'LXB Boilerplate requires the LXB ZENDESK plugin for determining the proper email template.', 'lxb-boilerplate' );    
  67.         }
  68.  
  69.         if( ! function_exists( 'dm_text_domain' ) ) {
  70.             $messages[]= esc_html__( 'LXB Boilerplate requires the WPMU Domain Mapping plugin for setting the primary domain.', 'lxb-boilerplate' );       
  71.         }
  72.  
  73.         if( ! defined( 'LXB_NSFW' ) ) {
  74.             $messages[]= esc_html__( 'LXB Boilerplate requires the LXB Network Settings Factory Warehouse plugin for making calls to the control install.', 'lxb-boilerplate' );
  75.         }
  76.  
  77.         if( ! is_network_admin() ) {
  78.  
  79.             if( ! defined( 'LXB_CF_VERSION' ) ) {
  80.                 $messages[]= esc_html__( 'LXB Boilerplate requires the LXB CloudFlare Tools plugin plugin for making calls to the CloudFlare.com.', 'lxb-boilerplate' );
  81.             }
  82.  
  83.             if( ! defined( 'LXB_AF' ) ) {
  84.                 $messages[]= esc_html__( 'LXB Boilerplate requires the Apple Fritter theme.', 'lxb-boilerplate' );
  85.             }
  86.  
  87.             if( ! class_exists( 'MailChimp' ) ) {
  88.                 $messages[]= esc_html__( 'LXB Boilerplate requires the LXB MailChimp Tools plugin for making calls to MailChimp.com.', 'lxb-boilerplate' );
  89.             }
  90.  
  91.             if( ! class_exists( 'IS_IU_Import_Users' ) ) {
  92.                 $messages[]= esc_html__( 'LXB Boilerplate requires the LXB Import Users From CSV plugin for importing users.', 'lxb-boilerplate' );
  93.             }          
  94.  
  95.         }
  96.  
  97.         $message_count = count( $messages );
  98.         if( ! empty( $message_count ) ) {
  99.             foreach( $messages as $message ) {
  100.                 $out .= "
  101.                     <div class='error notice is-dismissible'><p>$message</p></div>
  102.                 ";
  103.             }
  104.         }
  105.  
  106.         if( empty( $out ) ) { return FALSE; }
  107.  
  108.         echo $out;
  109.  
  110.     }
  111.    
  112.     /**
  113.      * If this plugin does not have all of its dependencies, it refuses to load its files.
  114.      *
  115.      * @return boolean Returns FALSE if it's missing dependencies, else TRUE.
  116.      */
  117.     function load() {
  118.  
  119.         if( ! defined( 'LXB_ZENDESK' ) ) { return FALSE; }
  120.  
  121.         if( ! defined( 'LXB_CF_VERSION' ) ) { return FALSE; }
  122.  
  123.         if( ! defined( 'LXB_NSFW' ) ) { return FALSE; }
  124.  
  125.         if( ! defined( 'LXB_AF' ) ) { return FALSE; }
  126.  
  127.         if( ! class_exists( 'MailChimp' ) ) { return FALSE; }
  128.  
  129.         if( ! class_exists( 'IS_IU_Import_Users' ) ) { return FALSE; }     
  130.  
  131.         // For each php file in the inc/ folder, require it.
  132.         foreach( glob( LXB_BOILERPLATE_PATH . 'inc/*.php' ) as $filename ) {
  133.  
  134.             require_once( $filename );
  135.  
  136.         }
  137.  
  138.         return TRUE;
  139.  
  140.     }
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement