| @@ -11,393 +11,374 @@ | ||
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * Class MainWP_Widget_Plugins |
| 14 | 14 | */ |
| 15 | -class MainWP_Widget_Plugins { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 16 | - /** | |
| 17 | - * Method get_class_name() | |
| 18 | - * | |
| 19 | - * Get Class Name | |
| 20 | - * | |
| 21 | - * @return string __CLASS__ Class Name. | |
| 22 | - */ | |
| 23 | - public static function get_class_name() { | |
| 24 | - return __CLASS__; | |
| 25 | - } | |
| 15 | +class MainWP_Widget_Plugins { | |
| 16 | + /** | |
| 17 | + * Method get_class_name() | |
| 18 | + * | |
| 19 | + * Get Class Name | |
| 20 | + * | |
| 21 | + * @return string __CLASS__ Class Name. | |
| 22 | + */ | |
| 23 | + public static function get_class_name() { | |
| 24 | + return __CLASS__; | |
| 25 | + } | |
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * Method render() | |
| 29 | - * | |
| 30 | - * Fire off render_widget(). | |
| 31 | - */ | |
| 32 | - public static function render() { | |
| 33 | - static::render_widget(); | |
| 34 | - } | |
| 27 | + /** | |
| 28 | + * Method render() | |
| 29 | + * | |
| 30 | + * Fire off render_widget(). | |
| 31 | + */ | |
| 32 | + public static function render() { | |
| 33 | + self::render_widget(); | |
| 34 | + } | |
| 35 | 35 | |
| 36 | - /** | |
| 37 | - * Method prepair_icons() | |
| 38 | - * | |
| 39 | - * Utilizes WP API to grab plugin icons, last_updated, active_installs | |
| 40 | - */ | |
| 41 | - public function prepare_icons() { | |
| 42 | - include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // NOSONAR - WP compatible. | |
| 36 | + /** | |
| 37 | + * Method prepair_icons() | |
| 38 | + * | |
| 39 | + * Utilizes WP API to grab plugin icons, last_updated, active_installs | |
| 40 | + */ | |
| 41 | + public function prepare_icons() { | |
| 42 | + include ABSPATH . 'wp-admin/includes/plugin-install.php'; | |
| 43 | 43 | |
| 44 | - $args = array( | |
| 45 | - 'fields' => array( | |
| 46 | - 'last_updated' => true, | |
| 47 | - 'icons' => true, | |
| 48 | - 'active_installs' => true, | |
| 49 | - ), | |
| 50 | - ); | |
| 44 | + $args = array( | |
| 45 | + 'fields' => array( | |
| 46 | + 'last_updated' => true, | |
| 47 | + 'icons' => true, | |
| 48 | + 'active_installs' => true, | |
| 49 | + ), | |
| 50 | + ); | |
| 51 | 51 | |
| 52 | - $api = plugins_api( 'query_plugins', $args ); | |
| 52 | + $api = plugins_api( 'query_plugins', $args ); | |
| 53 | 53 | |
| 54 | - if ( is_wp_error( $api ) ) { | |
| 55 | - $this->error = $api; | |
| 56 | - return; | |
| 57 | - } | |
| 54 | + if ( is_wp_error( $api ) ) { | |
| 55 | + $this->error = $api; | |
| 56 | + return; | |
| 57 | + } | |
| 58 | 58 | |
| 59 | - $this->items = $api->plugins; | |
| 60 | - } | |
| 59 | + $this->items = $api->plugins; | |
| 60 | + } | |
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** | |
| 64 | - * Method render_widget() | |
| 65 | - * | |
| 66 | - * Build Plugins Widget | |
| 67 | - * | |
| 68 | - * @uses \MainWP\Dashboard\MainWP_DB::query() | |
| 69 | - * @uses \MainWP\Dashboard\MainWP_DB::get_sql_website_by_id() | |
| 70 | - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object() | |
| 71 | - * @uses \MainWP\Dashboard\MainWP_DB::free_result() | |
| 72 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid() | |
| 73 | - */ | |
| 74 | - public static function render_widget() { // phpcs:ignore -- NOSONAR - complex. | |
| 75 | - $current_wpid = MainWP_System_Utility::get_current_wpid(); | |
| 76 | - if ( empty( $current_wpid ) ) { | |
| 77 | - return; | |
| 78 | - } | |
| 63 | + /** | |
| 64 | + * Method render_widget() | |
| 65 | + * | |
| 66 | + * Build Plugins Widget | |
| 67 | + * | |
| 68 | + * @uses \MainWP\Dashboard\MainWP_DB::query() | |
| 69 | + * @uses \MainWP\Dashboard\MainWP_DB::get_sql_website_by_id() | |
| 70 | + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object() | |
| 71 | + * @uses \MainWP\Dashboard\MainWP_DB::free_result() | |
| 72 | + * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid() | |
| 73 | + */ | |
| 74 | + public static function render_widget() { | |
| 75 | + $current_wpid = MainWP_System_Utility::get_current_wpid(); | |
| 76 | + if ( empty( $current_wpid ) ) { | |
| 77 | + return; | |
| 78 | + } | |
| 79 | 79 | |
| 80 | - $sql = MainWP_DB::instance()->get_sql_website_by_id( $current_wpid ); | |
| 81 | - $websites = MainWP_DB::instance()->query( $sql ); | |
| 82 | - $allPlugins = array(); | |
| 83 | - if ( $websites ) { | |
| 84 | - $website = MainWP_DB::fetch_object( $websites ); | |
| 85 | - if ( $website && '' !== $website->plugins ) { | |
| 86 | - $plugins = json_decode( $website->plugins, 1 ); | |
| 87 | - if ( is_array( $plugins ) && ! empty( $plugins ) ) { | |
| 88 | - foreach ( $plugins as $plugin ) { | |
| 89 | - if ( isset( $plugin['mainwp'] ) && ( 'T' === $plugin['mainwp'] ) ) { | |
| 90 | - continue; | |
| 91 | - } | |
| 92 | - $allPlugins[] = $plugin; | |
| 93 | - } | |
| 94 | - } | |
| 95 | - } | |
| 96 | - MainWP_DB::free_result( $websites ); | |
| 97 | - } | |
| 80 | + $sql = MainWP_DB::instance()->get_sql_website_by_id( $current_wpid ); | |
| 81 | + $websites = MainWP_DB::instance()->query( $sql ); | |
| 82 | + $allPlugins = array(); | |
| 83 | + if ( $websites ) { | |
| 84 | + $website = MainWP_DB::fetch_object( $websites ); | |
| 85 | + if ( $website && '' !== $website->plugins ) { | |
| 86 | + $plugins = json_decode( $website->plugins, 1 ); | |
| 87 | + if ( is_array( $plugins ) && 0 != count( $plugins ) ) { | |
| 88 | + foreach ( $plugins as $plugin ) { | |
| 89 | + if ( isset( $plugin['mainwp'] ) && ( 'T' === $plugin['mainwp'] ) ) { | |
| 90 | + continue; | |
| 91 | + } | |
| 92 | + $allPlugins[] = $plugin; | |
| 93 | + } | |
| 94 | + } | |
| 95 | + } | |
| 96 | + MainWP_DB::free_result( $websites ); | |
| 97 | + } | |
| 98 | 98 | |
| 99 | - static::render_html_widget( $website, $allPlugins ); | |
| 100 | - } | |
| 99 | + self::render_html_widget( $website, $allPlugins ); | |
| 100 | + } | |
| 101 | 101 | |
| 102 | - /** | |
| 103 | - * Method render_html_widget(). | |
| 104 | - * | |
| 105 | - * Render HTML plugins widget for current site | |
| 106 | - * | |
| 107 | - * @param object $website Object containing the child site info. | |
| 108 | - * @param array $allPlugins Array containing all detected plugins data. | |
| 109 | - * | |
| 110 | - * @uses \MainWP\Dashboard\MainWP_Utility::get_sub_array_having() | |
| 111 | - * @uses \MainWP\Dashboard\MainWP_Utility::sortmulti() | |
| 112 | - */ | |
| 113 | - public static function render_html_widget( $website, $allPlugins ) { // phpcs:ignore -- NOSONAR - complex. | |
| 102 | + /** | |
| 103 | + * Method render_html_widget(). | |
| 104 | + * | |
| 105 | + * Render HTML plugins widget for current site | |
| 106 | + * | |
| 107 | + * @param object $website Object containing the child site info. | |
| 108 | + * @param array $allPlugins Array containing all detected plugins data. | |
| 109 | + * | |
| 110 | + * @uses \MainWP\Dashboard\MainWP_Utility::get_sub_array_having() | |
| 111 | + * @uses \MainWP\Dashboard\MainWP_Utility::sortmulti() | |
| 112 | + */ | |
| 113 | + public static function render_html_widget( $website, $allPlugins ) { | |
| 114 | 114 | |
| 115 | - $is_demo = MainWP_Demo_Handle::is_demo_mode(); | |
| 115 | + $actived_plugins = MainWP_Utility::get_sub_array_having( $allPlugins, 'active', 1 ); | |
| 116 | + $actived_plugins = MainWP_Utility::sortmulti( $actived_plugins, 'name', 'asc' ); | |
| 116 | 117 | |
| 117 | - $actived_plugins = MainWP_Utility::get_sub_array_having( $allPlugins, 'active', 1 ); | |
| 118 | - $actived_plugins = MainWP_Utility::sortmulti( $actived_plugins, 'name', 'asc' ); | |
| 118 | + $inactive_plugins = MainWP_Utility::get_sub_array_having( $allPlugins, 'active', 0 ); | |
| 119 | + $inactive_plugins = MainWP_Utility::sortmulti( $inactive_plugins, 'name', 'asc' ); | |
| 119 | 120 | |
| 120 | - $inactive_plugins = MainWP_Utility::get_sub_array_having( $allPlugins, 'active', 0 ); | |
| 121 | - $inactive_plugins = MainWP_Utility::sortmulti( $inactive_plugins, 'name', 'asc' ); | |
| 121 | + ?> | |
| 122 | + <div class="ui grid"> | |
| 123 | + <div class="twelve wide column"> | |
| 124 | + <h3 class="ui header handle-drag"> | |
| 125 | + <?php | |
| 126 | + /** | |
| 127 | + * Filter: mainwp_plugins_widget_title | |
| 128 | + * | |
| 129 | + * Filters the Plugins widget title text. | |
| 130 | + * | |
| 131 | + * @param object $website Object containing the child site info. | |
| 132 | + * | |
| 133 | + * @since 4.1 | |
| 134 | + */ | |
| 135 | + echo esc_html( apply_filters( 'mainwp_plugins_widget_title', __( 'Plugins', 'mainwp' ), $website ) ); | |
| 136 | + ?> | |
| 137 | + <div class="sub header"><?php esc_html_e( 'Installed plugins on the child site', 'mainwp' ); ?></div> | |
| 138 | + </h3> | |
| 139 | + </div> | |
| 140 | + <div class="four wide column right aligned"> | |
| 141 | + <div class="ui dropdown right mainwp-dropdown-tab"> | |
| 142 | + <div class="text"><?php esc_html_e( 'Active', 'mainwp' ); ?></div> | |
| 143 | + <i class="dropdown icon"></i> | |
| 144 | + <div class="menu"> | |
| 145 | + <a class="item" data-tab="active_plugins" data-value="active_plugins" title="<?php esc_attr_e( 'Active', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Active', 'mainwp' ); ?></a> | |
| 146 | + <a class="item" data-tab="inactive_plugins" data-value="inactive_plugins" title="<?php esc_attr_e( 'Inactive', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Inactive', 'mainwp' ); ?></a> | |
| 147 | + </div> | |
| 148 | + </div> | |
| 149 | + </div> | |
| 150 | + </div> | |
| 151 | + <div class="ui section hidden divider"></div> | |
| 152 | + <?php | |
| 153 | + /** | |
| 154 | + * Action: mainwp_plugins_widget_top | |
| 155 | + * | |
| 156 | + * Fires at the top of the Plugins widget on the Individual site overview page. | |
| 157 | + * | |
| 158 | + * @param object $website Object containing the child site info. | |
| 159 | + * @param array $allPlugins Array containing all detected plugins data. | |
| 160 | + * | |
| 161 | + * @since 4.1 | |
| 162 | + */ | |
| 163 | + do_action( 'mainwp_plugins_widget_top', $website, $allPlugins ); | |
| 164 | + ?> | |
| 165 | + <div id="mainwp-widget-active-plugins" class="ui tab active" data-tab="active_plugins"> | |
| 166 | + <?php | |
| 167 | + /** | |
| 168 | + * Action: mainwp_before_active_plugins_list | |
| 169 | + * | |
| 170 | + * Fires before the active plugins list in the Plugins widget on the Individual site overview page. | |
| 171 | + * | |
| 172 | + * @param object $website Object containing the child site info. | |
| 173 | + * @param array $actived_plugins Array containing all active plugins data. | |
| 174 | + * | |
| 175 | + * @since 4.1 | |
| 176 | + */ | |
| 177 | + do_action( 'mainwp_before_active_plugins_list', $website, $actived_plugins ); | |
| 178 | + ?> | |
| 179 | + <div class="ui divided selection list"> | |
| 180 | + <?php | |
| 181 | + $_count = count( $actived_plugins ); | |
| 182 | + for ( $i = 0; $i < $_count; $i ++ ) { | |
| 183 | + $slug = wp_strip_all_tags( $actived_plugins[ $i ]['slug'] ); | |
| 184 | + ?> | |
| 185 | + <div class="item <?php echo esc_html( dirname( $slug ) ); ?>"> | |
| 186 | + <input class="pluginSlug" type="hidden" name="slug" value="<?php echo esc_attr( wp_strip_all_tags( $actived_plugins[ $i ]['slug'] ) ); ?>"/> | |
| 187 | + <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $website->id ); ?>"/> | |
| 188 | + <div class="right floated pluginsAction"> | |
| 189 | + <?php if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) { ?> | |
| 190 | + <a href="#" class="mainwp-plugin-deactivate ui mini button green" data-position="top right" data-tooltip="<?php esc_attr_e( 'Deactivate the ', 'mainwp' ) . esc_html( $actived_plugins[ $i ]['name'] ) . esc_attr_e( ' plugin on the child site.', 'mainwp' ); ?>" data-inverted=""><?php esc_html_e( 'Deactivate', 'mainwp' ); ?></a> | |
| 191 | + <?php } ?> | |
| 192 | + </div> | |
| 193 | + <div class="middle aligned content"> | |
| 194 | + <a href="<?php echo admin_url() . 'plugin-install.php?tab=plugin-information&plugin=' . dirname( wp_strip_all_tags( $actived_plugins[ $i ]['slug'] ) ) . '&TB_iframe=true&width=640&height=477'; ?>" target="_blank" class="thickbox open-plugin-details-modal" title="More information about <?php echo wp_strip_all_tags( $actived_plugins[ $i ]['name'] ); ?>"> | |
| 195 | + <?php echo esc_html( $actived_plugins[ $i ]['name'] . ' ' . $actived_plugins[ $i ]['version'] ); ?> | |
| 196 | + </a> | |
| 197 | + </div> | |
| 198 | + <div class="mainwp-row-actions-working"> | |
| 199 | + <i class="notched circle loading icon"></i> <?php esc_html_e( 'Please wait...', 'mainwp' ); ?> | |
| 200 | + </div> | |
| 201 | + </div> | |
| 202 | + <?php } ?> | |
| 203 | + </div> | |
| 204 | + <?php | |
| 205 | + /** | |
| 206 | + * Action: mainwp_after_active_plugins_list | |
| 207 | + * | |
| 208 | + * Fires after the active plugins list in the Plugins widget on the Individual site overview page. | |
| 209 | + * | |
| 210 | + * @param object $website Object containing the child site info. | |
| 211 | + * @param array $actived_plugins Array containing all active plugins data. | |
| 212 | + * | |
| 213 | + * @since 4.1 | |
| 214 | + */ | |
| 215 | + do_action( 'mainwp_after_active_plugins_list', $website, $actived_plugins ); | |
| 216 | + ?> | |
| 217 | + </div> | |
| 218 | + <div id="mainwp-widget-inactive-plugins" class="ui tab" data-tab="inactive_plugins"> | |
| 219 | + <?php | |
| 220 | + /** | |
| 221 | + * Action: mainwp_before_inactive_plugins_list | |
| 222 | + * | |
| 223 | + * Fires before the inactive plugins list in the Plugins widget on the Individual site overview page. | |
| 224 | + * | |
| 225 | + * @param object $website Object containing the child site info. | |
| 226 | + * @param array $inactive_plugins Array containing all active plugins data. | |
| 227 | + * | |
| 228 | + * @since 4.1 | |
| 229 | + */ | |
| 230 | + do_action( 'mainwp_before_inactive_plugins_list', $website, $inactive_plugins ); | |
| 231 | + ?> | |
| 232 | + <div class="ui middle aligned divided selection list"> | |
| 233 | + <?php | |
| 234 | + $_count = count( $inactive_plugins ); | |
| 235 | + for ( $i = 0; $i < $_count; $i ++ ) { | |
| 236 | + $slug = $inactive_plugins[ $i ]['slug']; | |
| 237 | + ?> | |
| 238 | + <div class="item <?php echo esc_html( sanitize_text_field( dirname( $slug ) ) ); ?>"> | |
| 239 | + <input class="pluginSlug" type="hidden" name="slug" value="<?php echo esc_attr( wp_strip_all_tags( $inactive_plugins[ $i ]['slug'] ) ); ?>"/> | |
| 240 | + <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $website->id ); ?>"/> | |
| 241 | + <div class="right floated content pluginsAction"> | |
| 242 | + <?php if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) { ?> | |
| 243 | + <a href="#" class="mainwp-plugin-activate ui mini green button" data-position="top right" data-tooltip="<?php esc_attr_e( 'Activate the ', 'mainwp' ) . wp_strip_all_tags( $inactive_plugins[ $i ]['name'] ) . esc_attr_e( ' plugin on the child site.', 'mainwp' ); ?>" data-inverted=""><?php esc_html_e( 'Activate', 'mainwp' ); ?></a> | |
| 244 | + <?php } ?> | |
| 245 | + <?php if ( mainwp_current_user_have_right( 'dashboard', 'delete_plugins' ) ) { ?> | |
| 246 | + <a href="#" class="mainwp-plugin-delete ui mini basic button" data-position="top right" data-tooltip="<?php esc_attr_e( 'Delete the ', 'mainwp' ) . wp_strip_all_tags( $inactive_plugins[ $i ]['name'] ) . esc_attr_e( ' plugin from the child site.', 'mainwp' ); ?>" data-inverted=""><?php esc_html_e( 'Delete', 'mainwp' ); ?></a> | |
| 247 | + <?php } ?> | |
| 248 | + </div> | |
| 249 | + <div class="middle aligned content"> | |
| 250 | + <a href="<?php echo admin_url() . 'plugin-install.php?tab=plugin-information&plugin=' . dirname( $inactive_plugins[ $i ]['slug'] ) . '&TB_iframe=true&width=640&height=477'; ?>" target="_blank" class="thickbox open-plugin-details-modal" title="More information about <?php echo wp_strip_all_tags( $inactive_plugins[ $i ]['name'] ); ?>"> | |
| 251 | + <?php echo esc_html( $inactive_plugins[ $i ]['name'] . ' ' . $inactive_plugins[ $i ]['version'] ); ?> | |
| 252 | + </a> | |
| 253 | + </div> | |
| 254 | + <div class="mainwp-row-actions-working"> | |
| 255 | + <i class="ui active inline loader tiny"></i> <?php esc_html_e( 'Please wait...', 'mainwp' ); ?> | |
| 256 | + </div> | |
| 257 | + </div> | |
| 258 | + <?php } ?> | |
| 259 | + </div> | |
| 260 | + <?php | |
| 261 | + /** | |
| 262 | + * Action: mainwp_after_inactive_plugins_list | |
| 263 | + * | |
| 264 | + * Fires after the inactive plugins list in the Plugins widget on the Individual site overview page. | |
| 265 | + * | |
| 266 | + * @param object $website Object containing the child site info. | |
| 267 | + * @param array $inactive_plugins Array containing all active plugins data. | |
| 268 | + * | |
| 269 | + * @since 4.1 | |
| 270 | + */ | |
| 271 | + do_action( 'mainwp_after_inactive_plugins_list', $website, $inactive_plugins ); | |
| 272 | + ?> | |
| 273 | + </div> | |
| 274 | + <?php | |
| 275 | + /** | |
| 276 | + * Action: mainwp_plugins_widget_bottom | |
| 277 | + * | |
| 278 | + * Fires at the bottom of the Plugins widget on the Individual site overview page. | |
| 279 | + * | |
| 280 | + * @param object $website Object containing the child site info. | |
| 281 | + * @param array $allPlugins Array containing all detected plugins data. | |
| 282 | + * | |
| 283 | + * @since 4.1 | |
| 284 | + */ | |
| 285 | + do_action( 'mainwp_plugins_widget_bottom', $website, $allPlugins ); | |
| 286 | + } | |
| 122 | 287 | |
| 123 | - ?> | |
| 124 | - <div class="ui grid mainwp-widget-header"> | |
| 125 | - <div class="twelve wide column"> | |
| 126 | - <h3 class="ui header handle-drag"> | |
| 127 | - <?php | |
| 128 | - /** | |
| 129 | - * Filter: mainwp_plugins_widget_title | |
| 130 | - * | |
| 131 | - * Filters the Plugins widget title text. | |
| 132 | - * | |
| 133 | - * @param object $website Object containing the child site info. | |
| 134 | - * | |
| 135 | - * @since 4.1 | |
| 136 | - */ | |
| 137 | - echo esc_html( apply_filters( 'mainwp_plugins_widget_title', esc_html__( 'Plugins', 'mainwp' ), $website ) ); | |
| 138 | - ?> | |
| 139 | - <div class="sub header"><?php esc_html_e( 'Installed plugins on the child site', 'mainwp' ); ?></div> | |
| 140 | - </h3> | |
| 141 | - </div> | |
| 142 | - <div class="four wide column right aligned"> | |
| 143 | - <div class="ui dropdown right pointing mainwp-dropdown-tab"> | |
| 144 | - <div class="text"><?php esc_html_e( 'Active', 'mainwp' ); ?></div> | |
| 145 | - <i class="dropdown icon"></i> | |
| 146 | - <div class="menu"> | |
| 147 | - <a class="item" data-tab="active_plugins" data-value="active_plugins" title="<?php esc_attr_e( 'Active', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Active', 'mainwp' ); ?></a> | |
| 148 | - <a class="item" data-tab="inactive_plugins" data-value="inactive_plugins" title="<?php esc_attr_e( 'Inactive', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Inactive', 'mainwp' ); ?></a> | |
| 149 | - </div> | |
| 150 | - </div> | |
| 151 | - </div> | |
| 152 | - </div> | |
| 153 | - <div class="mainwp-scrolly-overflow"> | |
| 154 | - <?php | |
| 155 | - /** | |
| 156 | - * Action: mainwp_plugins_widget_top | |
| 157 | - * | |
| 158 | - * Fires at the top of the Plugins widget on the Individual site overview page. | |
| 159 | - * | |
| 160 | - * @param object $website Object containing the child site info. | |
| 161 | - * @param array $allPlugins Array containing all detected plugins data. | |
| 162 | - * | |
| 163 | - * @since 4.1 | |
| 164 | - */ | |
| 165 | - do_action( 'mainwp_plugins_widget_top', $website, $allPlugins ); | |
| 166 | - ?> | |
| 167 | - <div id="mainwp-widget-active-plugins" class="ui tab active" data-tab="active_plugins"> | |
| 168 | - <?php | |
| 169 | - /** | |
| 170 | - * Action: mainwp_before_active_plugins_list | |
| 171 | - * | |
| 172 | - * Fires before the active plugins list in the Plugins widget on the Individual site overview page. | |
| 173 | - * | |
| 174 | - * @param object $website Object containing the child site info. | |
| 175 | - * @param array $actived_plugins Array containing all active plugins data. | |
| 176 | - * | |
| 177 | - * @since 4.1 | |
| 178 | - */ | |
| 179 | - do_action( 'mainwp_before_active_plugins_list', $website, $actived_plugins ); | |
| 180 | - ?> | |
| 181 | - <div class="ui divided selection middle aligned list"> | |
| 182 | - <?php | |
| 183 | - $_count = count( $actived_plugins ); | |
| 184 | - for ( $i = 0; $i < $_count; $i++ ) { | |
| 185 | - $slug = wp_strip_all_tags( $actived_plugins[ $i ]['slug'] ); | |
| 186 | - $plugin_directory = dirname( $slug ); | |
| 187 | - ?> | |
| 188 | - <div class="item <?php echo esc_html( dirname( $slug ) ); ?> row-manage-item"> | |
| 189 | - <input class="pluginSlug" type="hidden" name="slug" value="<?php echo esc_attr( wp_strip_all_tags( $actived_plugins[ $i ]['slug'] ) ); ?>"/> | |
| 190 | - <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $website->id ); ?>"/> | |
| 191 | - <div class="right floated pluginsAction"> | |
| 192 | - <?php if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) { ?> | |
| 193 | - <span data-position="left center" data-tooltip="<?php echo esc_attr__( 'Deactivate the ', 'mainwp' ) . esc_html( $actived_plugins[ $i ]['name'] ) . ' ' . esc_attr__( 'plugin on the child site.', 'mainwp' ); ?>" data-inverted=""><div class="mainwp-plugin-deactivate ui mini button green <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'Deactivate', 'mainwp' ); ?></div></span> | |
| 194 | - <?php } ?> | |
| 195 | - </div> | |
| 196 | - <div class="middle aligned content"> | |
| 197 | - <?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); // phpcs:ignore WordPress.Security.EscapeOutput ?> | |
| 198 | - <a href="<?php echo esc_url( admin_url() . 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $website->id ) . '&plugin=' . esc_html( dirname( wp_strip_all_tags( $actived_plugins[ $i ]['slug'] ) ) ) ); ?>" target="_blank" class="open-plugin-details-modal" title="More information about <?php echo wp_strip_all_tags( $actived_plugins[ $i ]['name'] ); // phpcs:ignore WordPress.Security.EscapeOutput ?>"> | |
| 199 | - <?php echo esc_html( $actived_plugins[ $i ]['name'] . ' ' . $actived_plugins[ $i ]['version'] ); ?> | |
| 200 | - </a> | |
| 201 | - </div> | |
| 202 | - <div class="mainwp-row-actions-working"> | |
| 203 | - <i class="notched circle loading icon"></i> <?php esc_html_e( 'Please wait...', 'mainwp' ); ?> | |
| 204 | - </div> | |
| 205 | - </div> | |
| 206 | - <?php } ?> | |
| 207 | - </div> | |
| 208 | - <?php | |
| 209 | - /** | |
| 210 | - * Action: mainwp_after_active_plugins_list | |
| 211 | - * | |
| 212 | - * Fires after the active plugins list in the Plugins widget on the Individual site overview page. | |
| 213 | - * | |
| 214 | - * @param object $website Object containing the child site info. | |
| 215 | - * @param array $actived_plugins Array containing all active plugins data. | |
| 216 | - * | |
| 217 | - * @since 4.1 | |
| 218 | - */ | |
| 219 | - do_action( 'mainwp_after_active_plugins_list', $website, $actived_plugins ); | |
| 220 | - ?> | |
| 221 | - </div> | |
| 222 | - <div id="mainwp-widget-inactive-plugins" class="ui tab" data-tab="inactive_plugins"> | |
| 223 | - <?php | |
| 224 | - /** | |
| 225 | - * Action: mainwp_before_inactive_plugins_list | |
| 226 | - * | |
| 227 | - * Fires before the inactive plugins list in the Plugins widget on the Individual site overview page. | |
| 228 | - * | |
| 229 | - * @param object $website Object containing the child site info. | |
| 230 | - * @param array $inactive_plugins Array containing all active plugins data. | |
| 231 | - * | |
| 232 | - * @since 4.1 | |
| 233 | - */ | |
| 234 | - do_action( 'mainwp_before_inactive_plugins_list', $website, $inactive_plugins ); | |
| 235 | - ?> | |
| 236 | - <div class="ui middle aligned divided selection list"> | |
| 237 | - <?php | |
| 238 | - $_count = count( $inactive_plugins ); | |
| 239 | - for ( $i = 0; $i < $_count; $i++ ) { | |
| 240 | - $slug = $inactive_plugins[ $i ]['slug']; | |
| 241 | - $plugin_directory = dirname( $slug ); | |
| 242 | - ?> | |
| 243 | - <div class="item <?php echo esc_html( sanitize_text_field( dirname( $slug ) ) ); ?> row-manage-item"> | |
| 244 | - <input class="pluginSlug" type="hidden" name="slug" value="<?php echo esc_attr( wp_strip_all_tags( $inactive_plugins[ $i ]['slug'] ) ); ?>"/> | |
| 245 | - <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $website->id ); ?>"/> | |
| 246 | - <div class="right floated content pluginsAction"> | |
| 247 | - <?php if ( mainwp_current_user_have_right( 'dashboard', 'activate_deactivate_plugins' ) ) { ?> | |
| 248 | - <span data-position="left center" data-tooltip="<?php echo esc_attr__( 'Activate the ', 'mainwp' ) . wp_strip_all_tags( $inactive_plugins[ $i ]['name'] ) . ' ' . esc_attr__( 'plugin on the child site.', 'mainwp' ); ?>" data-inverted=""><a href="#" class="mainwp-plugin-activate ui mini green button <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'Activate', 'mainwp' );// phpcs:ignore WordPress.Security.EscapeOutput ?></a></span> | |
| 249 | - <?php } ?> | |
| 250 | - <?php if ( mainwp_current_user_have_right( 'dashboard', 'delete_plugins' ) ) { ?> | |
| 251 | - <span data-position="left center" data-tooltip="<?php echo esc_attr__( 'Delete the ', 'mainwp' ) . wp_strip_all_tags( $inactive_plugins[ $i ]['name'] ) . ' ' . esc_attr__( 'plugin from the child site.', 'mainwp' ); ?>" data-inverted=""><a href="#" class="mainwp-plugin-delete ui mini basic button <?php echo $is_demo ? 'disabled' : ''; ?>"><?php esc_html_e( 'Delete', 'mainwp' ); // phpcs:ignore WordPress.Security.EscapeOutput ?></a></span> | |
| 252 | - <?php } ?> | |
| 253 | - </div> | |
| 254 | - <div class="middle aligned content"> | |
| 255 | - <?php echo MainWP_System_Utility::get_plugin_icon( $plugin_directory ); // phpcs:ignore WordPress.Security.EscapeOutput ?> | |
| 256 | - <a href="<?php echo esc_url( admin_url() . 'plugin-install.php?tab=plugin-information&wpplugin=' . intval( $website->id ) . '&plugin=' . esc_html( dirname( $inactive_plugins[ $i ]['slug'] ) ) ); ?>" target="_blank" class="open-plugin-details-modal" title="More information about <?php echo wp_strip_all_tags( $inactive_plugins[ $i ]['name'] ); // phpcs:ignore WordPress.Security.EscapeOutput ?>"> | |
| 257 | - <?php echo esc_html( $inactive_plugins[ $i ]['name'] . ' ' . $inactive_plugins[ $i ]['version'] ); ?> | |
| 258 | - </a> | |
| 259 | - </div> | |
| 260 | - <div class="mainwp-row-actions-working"> | |
| 261 | - <i class="ui active inline loader tiny"></i> <?php esc_html_e( 'Please wait...', 'mainwp' ); ?> | |
| 262 | - </div> | |
| 263 | - </div> | |
| 264 | - <?php } ?> | |
| 265 | - </div> | |
| 266 | - <?php | |
| 267 | - /** | |
| 268 | - * Action: mainwp_after_inactive_plugins_list | |
| 269 | - * | |
| 270 | - * Fires after the inactive plugins list in the Plugins widget on the Individual site overview page. | |
| 271 | - * | |
| 272 | - * @param object $website Object containing the child site info. | |
| 273 | - * @param array $inactive_plugins Array containing all active plugins data. | |
| 274 | - * | |
| 275 | - * @since 4.1 | |
| 276 | - */ | |
| 277 | - do_action( 'mainwp_after_inactive_plugins_list', $website, $inactive_plugins ); | |
| 278 | - ?> | |
| 279 | - </div> | |
| 280 | - </div> | |
| 281 | - <?php | |
| 282 | - /** | |
| 283 | - * Action: mainwp_plugins_widget_bottom | |
| 284 | - * | |
| 285 | - * Fires at the bottom of the Plugins widget on the Individual site overview page. | |
| 286 | - * | |
| 287 | - * @param object $website Object containing the child site info. | |
| 288 | - * @param array $allPlugins Array containing all detected plugins data. | |
| 289 | - * | |
| 290 | - * @since 4.1 | |
| 291 | - */ | |
| 292 | - do_action( 'mainwp_plugins_widget_bottom', $website, $allPlugins ); | |
| 293 | - MainWP_Updates::render_plugin_details_modal(); | |
| 294 | - } | |
| 288 | + /** | |
| 289 | + * Method activate_plugin() | |
| 290 | + * | |
| 291 | + * Fire off Action activate & display result | |
| 292 | + */ | |
| 293 | + public static function activate_plugin() { | |
| 294 | + self::action( 'activate' ); | |
| 295 | + die( wp_json_encode( array( 'result' => __( 'Plugin has been activated!', 'mainwp' ) ) ) ); | |
| 296 | + } | |
| 295 | 297 | |
| 296 | - /** | |
| 297 | - * Method activate_plugin() | |
| 298 | - * | |
| 299 | - * Fire off Action activate & display result | |
| 300 | - */ | |
| 301 | - public static function activate_plugin() { | |
| 302 | - static::action( 'activate' ); | |
| 303 | - die( wp_json_encode( array( 'result' => esc_html__( 'Plugin has been activated!', 'mainwp' ) ) ) ); | |
| 304 | - } | |
| 298 | + /** | |
| 299 | + * Method deactivate_plugin() | |
| 300 | + * | |
| 301 | + * Fire off action deactivate & display result | |
| 302 | + */ | |
| 303 | + public static function deactivate_plugin() { | |
| 304 | + self::action( 'deactivate' ); | |
| 305 | + die( wp_json_encode( array( 'result' => __( 'Plugin has been deactivated!', 'mainwp' ) ) ) ); | |
| 306 | + } | |
| 305 | 307 | |
| 306 | - /** | |
| 307 | - * Method deactivate_plugin() | |
| 308 | - * | |
| 309 | - * Fire off action deactivate & display result | |
| 310 | - */ | |
| 311 | - public static function deactivate_plugin() { | |
| 312 | - static::action( 'deactivate' ); | |
| 313 | - die( wp_json_encode( array( 'result' => esc_html__( 'Plugin has been deactivated!', 'mainwp' ) ) ) ); | |
| 314 | - } | |
| 308 | + /** | |
| 309 | + * Method delete_plugin() | |
| 310 | + * | |
| 311 | + * Fire off action delete & display result | |
| 312 | + */ | |
| 313 | + public static function delete_plugin() { | |
| 314 | + self::action( 'delete' ); | |
| 315 | + die( wp_json_encode( array( 'result' => __( 'Plugin has been permanently deleted!', 'mainwp' ) ) ) ); | |
| 316 | + } | |
| 315 | 317 | |
| 316 | - /** | |
| 317 | - * Method delete_plugin() | |
| 318 | - * | |
| 319 | - * Fire off action delete & display result | |
| 320 | - */ | |
| 321 | - public static function delete_plugin() { | |
| 322 | - static::action( 'delete' ); | |
| 323 | - die( wp_json_encode( array( 'result' => esc_html__( 'Plugin has been permanently deleted!', 'mainwp' ) ) ) ); | |
| 324 | - } | |
| 318 | + /** | |
| 319 | + * Method action() | |
| 320 | + * | |
| 321 | + * Initiate try catch for chosen Action | |
| 322 | + * | |
| 323 | + * @param mixed $action Plugin Action. | |
| 324 | + * | |
| 325 | + * @throws \Exception Error message. | |
| 326 | + * | |
| 327 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 328 | + * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message() | |
| 329 | + * @uses \MainWP\Dashboard\MainWP_Exception | |
| 330 | + * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 331 | + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 332 | + */ | |
| 333 | + public static function action( $action ) { | |
| 334 | + $plugin = isset( $_POST['plugin'] ) ? wp_unslash( $_POST['plugin'] ) : ''; | |
| 335 | + $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false; | |
| 325 | 336 | |
| 326 | - /** | |
| 327 | - * Method action() | |
| 328 | - * | |
| 329 | - * Initiate try catch for chosen Action | |
| 330 | - * | |
| 331 | - * @param mixed $action Plugin Action. | |
| 332 | - * | |
| 333 | - * @throws \MainWP_Exception Error message. | |
| 334 | - * | |
| 335 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 336 | - * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message() | |
| 337 | - * @uses \MainWP\Dashboard\MainWP_Exception | |
| 338 | - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 339 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 340 | - */ | |
| 341 | - public static function action( $action ) { | |
| 342 | - $plugin = isset( $_POST['plugin'] ) ? wp_unslash( $_POST['plugin'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 343 | - $plugin = urldecode( $plugin ); | |
| 344 | - $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 337 | + if ( empty( $plugin ) || empty( $websiteId ) ) { | |
| 338 | + die( wp_json_encode( array( 'error' => __( 'Plugin or site ID not found. Please, reload the page and try again.', 'mainwp' ) ) ) ); | |
| 339 | + } | |
| 345 | 340 | |
| 346 | - if ( empty( $plugin ) || empty( $websiteId ) ) { | |
| 347 | - die( wp_json_encode( array( 'error' => esc_html__( 'Plugin or site ID not found. Please, reload the page and try again.', 'mainwp' ) ) ) ); | |
| 348 | - } | |
| 341 | + $website = MainWP_DB::instance()->get_website_by_id( $websiteId ); | |
| 342 | + if ( ! MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 343 | + die( wp_json_encode( array( 'error' => __( 'You cannot edit this website.', 'mainwp' ) ) ) ); | |
| 344 | + } | |
| 349 | 345 | |
| 350 | - $website = MainWP_DB::instance()->get_website_by_id( $websiteId ); | |
| 351 | - if ( ! MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 352 | - die( wp_json_encode( array( 'error' => esc_html__( 'You cannot edit this website.', 'mainwp' ) ) ) ); | |
| 353 | - } | |
| 346 | + try { | |
| 354 | 347 | |
| 355 | - if ( MainWP_System_Utility::is_suspended_site( $website ) ) { | |
| 356 | - die( | |
| 357 | - wp_json_encode( | |
| 358 | - array( | |
| 359 | - 'error' => esc_html__( 'Suspended site.', 'mainwp' ), | |
| 360 | - 'errorCode' => 'SUSPENDED_SITE', | |
| 361 | - ) | |
| 362 | - ) | |
| 363 | - ); | |
| 364 | - } | |
| 348 | + /** | |
| 349 | + * Action: mainwp_before_plugin_action | |
| 350 | + * | |
| 351 | + * Fires before plugin activate/deactivate/delete actions. | |
| 352 | + * | |
| 353 | + * @since 4.1 | |
| 354 | + */ | |
| 355 | + do_action( 'mainwp_before_plugin_action', $action, $plugin, $website ); | |
| 365 | 356 | |
| 366 | - try { | |
| 357 | + $information = MainWP_Connect::fetch_url_authed( | |
| 358 | + $website, | |
| 359 | + 'plugin_action', | |
| 360 | + array( | |
| 361 | + 'action' => $action, | |
| 362 | + 'plugin' => $plugin, | |
| 363 | + ) | |
| 364 | + ); | |
| 367 | 365 | |
| 368 | - /** | |
| 369 | - * Action: mainwp_before_plugin_action | |
| 370 | - * | |
| 371 | - * Fires before plugin activate/deactivate/delete actions. | |
| 372 | - * | |
| 373 | - * @since 4.1 | |
| 374 | - */ | |
| 375 | - do_action( 'mainwp_before_plugin_action', $action, $plugin, $website ); | |
| 366 | + /** | |
| 367 | + * Action: mainwp_after_plugin_action | |
| 368 | + * | |
| 369 | + * Fires after plugin activate/deactivate/delete actions. | |
| 370 | + * | |
| 371 | + * @since 4.1 | |
| 372 | + */ | |
| 373 | + do_action( 'mainwp_after_plugin_action', $information, $action, $plugin, $website ); | |
| 376 | 374 | |
| 377 | - $information = MainWP_Connect::fetch_url_authed( | |
| 378 | - $website, | |
| 379 | - 'plugin_action', | |
| 380 | - array( | |
| 381 | - 'action' => $action, | |
| 382 | - 'plugin' => $plugin, | |
| 383 | - ) | |
| 384 | - ); | |
| 375 | + } catch ( MainWP_Exception $e ) { | |
| 376 | + die( wp_json_encode( array( 'error' => MainWP_Error_Helper::get_error_message( $e ) ) ) ); | |
| 377 | + } | |
| 385 | 378 | |
| 386 | - /** | |
| 387 | - * Action: mainwp_after_plugin_action | |
| 388 | - * | |
| 389 | - * Fires after plugin activate/deactivate/delete actions. | |
| 390 | - * | |
| 391 | - * @since 4.1 | |
| 392 | - */ | |
| 393 | - do_action( 'mainwp_after_plugin_action', $information, $action, $plugin, $website ); | |
| 379 | + if ( ! isset( $information['status'] ) || ( 'SUCCESS' !== $information['status'] ) ) { | |
| 380 | + die( wp_json_encode( array( 'error' => __( 'Unexpected error occurred. Please try again.', 'mainwp' ) ) ) ); | |
| 381 | + } | |
| 382 | + } | |
| 394 | 383 | |
| 395 | - } catch ( MainWP_Exception $e ) { | |
| 396 | - die( wp_json_encode( array( 'error' => MainWP_Error_Helper::get_error_message( $e ) ) ) ); | |
| 397 | - } | |
| 398 | - | |
| 399 | - if ( ! isset( $information['status'] ) || ( 'SUCCESS' !== $information['status'] ) ) { | |
| 400 | - die( wp_json_encode( array( 'error' => esc_html__( 'Unexpected error occurred. Please try again.', 'mainwp' ) ) ) ); | |
| 401 | - } | |
| 402 | - } | |
| 403 | 384 | } |