| @@ -1,134 +1,88 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * Plugin Name: MainWP Dashboard | |
| 4 | - * | |
| 5 | - * Description: Manage all of your WP sites, even those on different servers, from one central dashboard that runs off of your own self-hosted WordPress install. | |
| 6 | - * | |
| 7 | - * Author: MainWP | |
| 8 | - * Author URI: https://mainwp.com | |
| 9 | - * Plugin URI: https://mainwp.com/ | |
| 10 | - * Text Domain: mainwp | |
| 11 | - * Version: 5.3 | |
| 12 | - * | |
| 13 | - * @package MainWP/Dashboard | |
| 14 | - * | |
| 15 | - * @uses \MainWP\Dashboard\MainWP_System | |
| 2 | + | |
| 3 | +/* | |
| 4 | + Plugin Name: MainWP Dashboard | |
| 5 | + Plugin URI: https://mainwp.com/ | |
| 6 | + Description: Manage all of your WP sites, even those on different servers, from one central dashboard that runs off of your own self-hosted WordPress install. | |
| 7 | + Author: MainWP | |
| 8 | + Author URI: https://mainwp.com | |
| 9 | + Text Domain: mainwp | |
| 10 | + Version: 4.0.5 | |
| 16 | 11 | */ |
| 17 | 12 | |
| 18 | -if ( ! defined( 'MAINWP_PLUGIN_FILE' ) ) { | |
| 19 | - | |
| 20 | - /** | |
| 21 | - * Define MainWP Dashboard Plugin absolute full path and filename of this file. | |
| 22 | - * | |
| 23 | - * @const ( string ) Defined MainWP dashboard file path. | |
| 24 | - * @source https://github.com/mainwp/mainwp/blob/master/mainwp.php | |
| 25 | - */ | |
| 26 | - define( 'MAINWP_PLUGIN_FILE', __FILE__ ); | |
| 13 | +if ( !defined( 'MAINWP_PLUGIN_FILE' ) ) { | |
| 14 | + define( 'MAINWP_PLUGIN_FILE', __FILE__ ); | |
| 27 | 15 | } |
| 28 | 16 | |
| 29 | -if ( ! defined( 'MAINWP_PLUGIN_DIR' ) ) { | |
| 30 | - /** | |
| 31 | - * Define MainWP Dashboard Plugin Directory. | |
| 32 | - * | |
| 33 | - * @const ( string ) Defined MainWP Dashboard Plugin Directory. | |
| 34 | - * @source https://github.com/mainwp/mainwp/blob/master/mainwp.php | |
| 35 | - */ | |
| 36 | - define( 'MAINWP_PLUGIN_DIR', plugin_dir_path( MAINWP_PLUGIN_FILE ) ); | |
| 17 | +if ( !defined( 'MAINWP_PLUGIN_DIR' ) ) { | |
| 18 | + define( 'MAINWP_PLUGIN_DIR', plugin_dir_path( MAINWP_PLUGIN_FILE ) ); | |
| 37 | 19 | } |
| 38 | 20 | |
| 39 | -if ( ! defined( 'MAINWP_PLUGIN_URL' ) ) { | |
| 40 | - /** | |
| 41 | - * Define MainWP Child Dashboard URL. | |
| 42 | - * | |
| 43 | - * @const ( string ) Defined MainWP Dashboard Plugin URL. | |
| 44 | - * @source https://github.com/mainwp/mainwp/blob/master/mainwp.php | |
| 45 | - */ | |
| 46 | - define( 'MAINWP_PLUGIN_URL', plugin_dir_url( MAINWP_PLUGIN_FILE ) ); | |
| 21 | +if ( !defined( 'MAINWP_PLUGIN_URL' ) ) { | |
| 22 | + define( 'MAINWP_PLUGIN_URL', plugin_dir_url( MAINWP_PLUGIN_FILE ) ); | |
| 47 | 23 | } |
| 48 | 24 | |
| 25 | +include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php' ); //Version information from wordpress | |
| 49 | 26 | |
| 50 | -if ( ! defined( 'MAINWP_MODULES_DIR' ) ) { | |
| 51 | - define( 'MAINWP_MODULES_DIR', MAINWP_PLUGIN_DIR . 'modules' . DIRECTORY_SEPARATOR ); | |
| 52 | -} | |
| 27 | +if ( !function_exists( 'mainwp_autoload' ) ) { | |
| 53 | 28 | |
| 54 | -if ( ! defined( 'MAINWP_MODULES_URL' ) ) { | |
| 55 | - define( 'MAINWP_MODULES_URL', MAINWP_PLUGIN_URL . 'modules/' ); | |
| 56 | -} | |
| 29 | + function mainwp_autoload( $class_name ) { | |
| 30 | + if ( 0 !== strpos( $class_name, 'MainWP_' ) ) | |
| 31 | + return; | |
| 57 | 32 | |
| 33 | + $autoload_types = array( 'class' => 'class', 'pages' => 'page', 'widgets' => 'widget' ); | |
| 58 | 34 | |
| 59 | -/** | |
| 60 | - * Define enable Log Module. | |
| 61 | - */ | |
| 62 | -if ( ! defined( 'MAINWP_MODULE_LOG_ENABLED' ) ) { | |
| 63 | - define( 'MAINWP_MODULE_LOG_ENABLED', true ); | |
| 64 | -} | |
| 35 | + foreach ( $autoload_types as $type => $prefix ) { | |
| 36 | + $autoload_dir = \trailingslashit( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $type ); | |
| 37 | + $autoload_path = sprintf( '%s%s-%s.php', $autoload_dir, $prefix, strtolower( str_replace( '_', '-', $class_name ) ) ); | |
| 65 | 38 | |
| 66 | -if ( ! defined( 'MAINWP_MODULE_COST_TRACKER_ENABLED' ) ) { | |
| 67 | - define( 'MAINWP_MODULE_COST_TRACKER_ENABLED', true ); | |
| 68 | -} | |
| 39 | + if ( file_exists( $autoload_path ) ) { | |
| 40 | + require_once( $autoload_path ); | |
| 41 | + break; | |
| 42 | + } | |
| 43 | + } | |
| 44 | + } | |
| 69 | 45 | |
| 70 | -if ( ! defined( 'MAINWP_MODULE_API_BACKUPS_ENABLED' ) ) { | |
| 71 | - define( 'MAINWP_MODULE_API_BACKUPS_ENABLED', true ); | |
| 72 | 46 | } |
| 73 | 47 | |
| 48 | +spl_autoload_register( 'mainwp_autoload' ); | |
| 74 | 49 | |
| 75 | -// Version information from WordPress. | |
| 76 | -require_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php'; // NOSONAR - WP compatible. | |
| 50 | +if ( !function_exists( 'mainwpdir' ) ) { | |
| 77 | 51 | |
| 78 | -if ( ! function_exists( 'mainwp_autoload' ) ) { | |
| 52 | + function mainwpdir() { | |
| 53 | + return WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . dirname( plugin_basename( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR; | |
| 54 | + } | |
| 79 | 55 | |
| 80 | - /** | |
| 81 | - * Autoloader for all classes, pages & widgets | |
| 82 | - * | |
| 83 | - * @param string $class_name Folder name class|pages|widgets. | |
| 84 | - * @return require_once $autoload_path; | |
| 85 | - */ | |
| 86 | - function mainwp_autoload( $class_name ) { | |
| 56 | +} | |
| 87 | 57 | |
| 88 | - if ( 0 === strpos( $class_name, 'MainWP\Dashboard' ) ) { | |
| 89 | - // trip the namespace prefix: MainWP\Dashboard\ . | |
| 90 | - $class_name = substr( $class_name, 17 ); | |
| 91 | - } | |
| 58 | +if ( file_exists( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . plugin_basename( __DIR__ ) . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class-mainwp-creport.php' ) ) { | |
| 59 | + include_once WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . plugin_basename( __DIR__ ) . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class-mainwp-creport.php'; | |
| 60 | +} | |
| 92 | 61 | |
| 93 | - if ( 0 !== strpos( $class_name, 'MainWP_' ) ) { | |
| 94 | - return; | |
| 95 | - } | |
| 62 | +if ( !function_exists( 'mainwp_do_not_have_permissions' ) ) { | |
| 96 | 63 | |
| 97 | - $autoload_types = array( | |
| 98 | - 'class' => 'class', | |
| 99 | - 'pages' => 'page', | |
| 100 | - 'widgets' => 'widget', | |
| 101 | - ); | |
| 64 | + function mainwp_do_not_have_permissions( $where = '', $echo = true ) { | |
| 65 | + $msg = sprintf( __( 'You do not have sufficient permissions to access this page (%s).', 'mainwp' ), ucwords( $where ) ); | |
| 66 | + if ( $echo ) { | |
| 67 | + echo '<div class="mainwp-permission-error"><p>' . esc_html( $msg ) . '</p>If you need access to this page please contact the dashboard administrator.</div>'; | |
| 68 | + } else { | |
| 69 | + return $msg; | |
| 70 | + } | |
| 102 | 71 | |
| 103 | - foreach ( $autoload_types as $type => $prefix ) { | |
| 104 | - $autoload_dir = \trailingslashit( __DIR__ . DIRECTORY_SEPARATOR . $type ); | |
| 105 | - $autoload_path = sprintf( '%s%s-%s.php', $autoload_dir, $prefix, strtolower( str_replace( '_', '-', $class_name ) ) ); | |
| 72 | + return false; | |
| 73 | + } | |
| 106 | 74 | |
| 107 | - if ( file_exists( $autoload_path ) ) { | |
| 108 | - require_once $autoload_path; // NOSONAR - WP compatible. | |
| 109 | - break; | |
| 110 | - } | |
| 111 | - } | |
| 112 | - } | |
| 113 | 75 | } |
| 114 | 76 | |
| 115 | -spl_autoload_register( 'mainwp_autoload' ); | |
| 116 | - | |
| 117 | -require_once MAINWP_PLUGIN_DIR . 'includes' . DIRECTORY_SEPARATOR . 'functions.php'; // NOSONAR -- WP compatible. | |
| 118 | -require_once MAINWP_PLUGIN_DIR . 'includes' . DIRECTORY_SEPARATOR . 'core-functions.php'; // NOSONAR -- WP compatible. | |
| 119 | -require_once MAINWP_PLUGIN_DIR . 'includes' . DIRECTORY_SEPARATOR . 'compatible.php'; // NOSONAR -- WP compatible. | |
| 120 | -require_once MAINWP_PLUGIN_DIR . 'includes' . DIRECTORY_SEPARATOR . 'class-mainwp-includes.php'; // NOSONAR -- WP compatible. | |
| 121 | - | |
| 122 | -// Detect if secupress_scanner is running. | |
| 123 | 77 | $mainwp_is_secupress_scanning = false; |
| 124 | -if ( ! empty( $_GET ) && isset( $_GET['test'] ) && isset( $_GET['action'] ) && 'secupress_scanner' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized.Recommended | |
| 125 | - $mainwp_is_secupress_scanning = true; | |
| 78 | +if ( !empty( $_GET ) && isset( $_GET[ 'test' ] ) && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'secupress_scanner' ) { | |
| 79 | + $mainwp_is_secupress_scanning = true; | |
| 126 | 80 | } |
| 127 | 81 | |
| 128 | -// Fix a conflict with SecuPress plugin. | |
| 129 | -if ( ! $mainwp_is_secupress_scanning ) { | |
| 130 | - $mainWP = new MainWP\Dashboard\MainWP_System( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . plugin_basename( __FILE__ ) ); | |
| 131 | - register_activation_hook( __FILE__, array( $mainWP, 'activation' ) ); | |
| 132 | - register_deactivation_hook( __FILE__, array( $mainWP, 'deactivation' ) ); | |
| 133 | - add_action( 'plugins_loaded', array( $mainWP, 'update_install' ) ); | |
| 82 | +//to fix conflict with SecuPress plugin | |
| 83 | +if ( !$mainwp_is_secupress_scanning ) { | |
| 84 | + $mainWP = new MainWP_System( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . plugin_basename( __FILE__ ) ); | |
| 85 | + register_activation_hook( __FILE__, array( $mainWP, 'activation' ) ); | |
| 86 | + register_deactivation_hook( __FILE__, array( $mainWP, 'deactivation' ) ); | |
| 87 | + add_action( 'plugins_loaded', array( $mainWP, 'update' ) ); | |
| 134 | 88 | } |