| @@ -6,935 +6,1354 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace MainWP\Dashboard; |
| 9 | 9 | |
| 10 | +// Exit if accessed directly. | |
| 11 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | + exit; | |
| 13 | +} | |
| 14 | + | |
| 10 | 15 | /** |
| 11 | 16 | * Class MainWP_Updates_Handler |
| 12 | 17 | * |
| 13 | 18 | * @package MainWP\Dashboard |
| 14 | 19 | */ |
| 15 | -class MainWP_Updates_Handler { | |
| 20 | +class MainWP_Updates_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 16 | 21 | |
| 17 | - /** | |
| 18 | - * Get Class Name | |
| 19 | - * | |
| 20 | - * @return string __CLASS__ | |
| 21 | - */ | |
| 22 | - public static function get_class_name() { | |
| 23 | - return __CLASS__; | |
| 24 | - } | |
| 22 | + /** | |
| 23 | + * Get Class Name | |
| 24 | + * | |
| 25 | + * @return string __CLASS__ | |
| 26 | + */ | |
| 27 | + public static function get_class_name() { | |
| 28 | + return __CLASS__; | |
| 29 | + } | |
| 25 | 30 | |
| 26 | - /** | |
| 27 | - * Method upgrade_site() | |
| 28 | - * | |
| 29 | - * Check Child Site ID & Update. | |
| 30 | - * | |
| 31 | - * @param int $id Child site ID. | |
| 32 | - * | |
| 33 | - * @return string | |
| 34 | - * @throws MainWP_Exception Error messages. | |
| 35 | - * | |
| 36 | - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 37 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 38 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_option() | |
| 39 | - * @uses \MainWP\Dashboard\MainWP_Exception | |
| 40 | - * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 41 | - */ | |
| 42 | - public static function upgrade_site( $id ) { | |
| 43 | - if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) { | |
| 31 | + /** | |
| 32 | + * Method upgrade_site() | |
| 33 | + * | |
| 34 | + * Check Child Site ID & Update. | |
| 35 | + * | |
| 36 | + * @param int $id Child site ID. | |
| 37 | + * | |
| 38 | + * @return string | |
| 39 | + * @throws MainWP_Exception Error messages. | |
| 40 | + * | |
| 41 | + * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 42 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 43 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_option() | |
| 44 | + * @uses \MainWP\Dashboard\MainWP_Exception | |
| 45 | + * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 46 | + */ | |
| 47 | + public static function upgrade_site( $id ) { // phpcs:ignore -- NOSONAR - complex. | |
| 48 | + if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) { | |
| 44 | 49 | |
| 45 | - $website = MainWP_DB::instance()->get_website_by_id( $id ); | |
| 50 | + $website = MainWP_DB::instance()->get_website_by_id( $id ); | |
| 46 | 51 | |
| 47 | - if ( MainWP_System_Utility::is_suspended_site( $website ) ) { | |
| 48 | - throw new MainWP_Exception( 'ERROR', '<i class="pause circular yellow inverted icon"></i> ' . esc_html__( 'Suspended site.', 'mainwp' ) ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 49 | - } | |
| 52 | + if ( MainWP_System_Utility::is_suspended_site( $website ) ) { | |
| 53 | + throw new MainWP_Exception( 'ERROR', '<i class="pause circular yellow inverted icon"></i> ' . esc_html__( 'Suspended site.', 'mainwp' ), 'SUSPENDED_SITE' ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 54 | + } | |
| 50 | 55 | |
| 51 | - $information = self::upgrade_website( $website ); | |
| 56 | + $information = static::upgrade_website( $website ); | |
| 52 | 57 | |
| 53 | - if ( is_array( $information ) ) { | |
| 54 | - if ( isset( $information['upgrade'] ) && ( 'SUCCESS' === $information['upgrade'] ) ) { | |
| 55 | - MainWP_DB::instance()->update_website_option( $website, 'wp_upgrades', wp_json_encode( array() ) ); | |
| 56 | - do_action( 'mainwp_after_upgrade_wp_success', $website, $information ); | |
| 57 | - return '<i class="green check icon"></i>'; | |
| 58 | - } elseif ( isset( $information['upgrade'] ) ) { | |
| 59 | - $errorMsg = ''; | |
| 60 | - if ( 'LOCALIZATION' === $information['upgrade'] ) { | |
| 61 | - $errorMsg = '<i class="red times icon"></i> ' . esc_html__( 'No update found for the set locale.', 'mainwp' ); | |
| 62 | - } elseif ( 'NORESPONSE' === $information['upgrade'] ) { | |
| 63 | - $errorMsg = '<i class="red times icon"></i> ' . esc_html__( 'No response from the child site server.', 'mainwp' ); | |
| 64 | - } | |
| 65 | - throw new MainWP_Exception( 'WPERROR', $errorMsg ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 66 | - } elseif ( isset( $information['error'] ) ) { | |
| 67 | - throw new MainWP_Exception( 'WPERROR', esc_html( $information['error'] ) ); | |
| 68 | - } else { | |
| 69 | - throw new MainWP_Exception( 'ERROR', '<i class="red times icon"></i> ' . esc_html__( 'Invalid response from child site.', 'mainwp' ) ); | |
| 70 | - } | |
| 71 | - } | |
| 72 | - } | |
| 58 | + if ( is_array( $information ) ) { | |
| 59 | + $thrw_error = ''; | |
| 60 | + $thrw_extra = ''; | |
| 61 | + $success = false; | |
| 62 | + if ( isset( $information['upgrade'] ) && 'SUCCESS' === $information['upgrade'] ) { | |
| 63 | + MainWP_DB::instance()->update_website_option( $website, 'wp_upgrades', wp_json_encode( array() ) ); | |
| 64 | + do_action( 'mainwp_after_upgrade_wp_success', $website, $information ); | |
| 65 | + // Get Icon for the largest change scope of ext regression testing. | |
| 66 | + $html_regression_icon = apply_filters( 'mainwp_html_regression_largest_change_scope', $website->id, true ) ?: ''; // phpcs:ignore -- NOSONAR | |
| 67 | + if ( $website->id === $html_regression_icon ) { | |
| 68 | + $html_regression_icon = ''; | |
| 69 | + } | |
| 70 | + $raw_msg = esc_html__( 'Update successful', 'mainwp' ); | |
| 71 | + $msg_success = '<span data-inverted="" data-position="left center" data-tooltip="' . esc_html__( 'Update successful', 'mainwp' ) . '"><i class="green check icon"></i></span>' . $html_regression_icon; | |
| 72 | + $success = true; | |
| 73 | + } elseif ( isset( $information['upgrade'] ) ) { | |
| 74 | + $errorMsg = ''; | |
| 75 | + if ( 'LOCALIZATION' === $information['upgrade'] ) { | |
| 76 | + $raw_msg = esc_html__( 'No update found for the set locale.', 'mainwp' ); | |
| 77 | + $errorMsg = '<i class="red times icon"></i> ' . esc_html__( 'No update found for the set locale.', 'mainwp' ); | |
| 78 | + } elseif ( 'NORESPONSE' === $information['upgrade'] ) { | |
| 79 | + $raw_msg = esc_html__( 'No response from the child site server.', 'mainwp' ); | |
| 80 | + $errorMsg = '<i class="red times icon"></i> ' . esc_html__( 'No response from the child site server.', 'mainwp' ); | |
| 81 | + } | |
| 82 | + $thrw_error = 'WPERROR'; | |
| 83 | + $thrw_extra = $errorMsg; | |
| 84 | + } elseif ( isset( $information['error'] ) ) { | |
| 85 | + $thrw_error = 'WPERROR'; | |
| 86 | + $thrw_extra = esc_html( $information['error'] ); | |
| 87 | + $raw_msg = esc_html( $information['error'] ); | |
| 88 | + } else { | |
| 89 | + $thrw_error = 'ERROR'; | |
| 90 | + $thrw_extra = '<i class="red times icon"></i> ' . esc_html__( 'Invalid response from child site.', 'mainwp' ); | |
| 91 | + $raw_msg = esc_html__( 'Invalid response from child site.', 'mainwp' ); | |
| 92 | + } | |
| 73 | 93 | |
| 74 | - throw new MainWP_Exception( 'ERROR', '<i class="red times icon"></i> ' . esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ); | |
| 75 | - } | |
| 94 | + do_action( 'mainwp_after_upgrade_wp_core', $website, $information, $success, $raw_msg ); | |
| 76 | 95 | |
| 77 | - /** | |
| 78 | - * Method upgrade_website() | |
| 79 | - * | |
| 80 | - * Update WP for site. | |
| 81 | - * | |
| 82 | - * @param object $website Child site object. | |
| 83 | - * | |
| 84 | - * @return mixed|false update result or false. | |
| 85 | - * @throws MainWP_Exception Error message. | |
| 86 | - * | |
| 87 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 88 | - */ | |
| 89 | - public static function upgrade_website( $website ) { | |
| 90 | - if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 96 | + if ( ! empty( $thrw_error ) ) { | |
| 97 | + throw new MainWP_Exception( $thrw_error, $thrw_extra ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- NOSONAR -escaped. | |
| 98 | + } elseif ( ! empty( $msg_success ) ) { | |
| 99 | + return $msg_success; | |
| 100 | + } | |
| 101 | + } | |
| 102 | + } | |
| 91 | 103 | |
| 92 | - $wpcore_update_disabled_by = MainWP_System_Utility::disabled_wpcore_update_by( $website ); | |
| 93 | - if ( ! empty( $wpcore_update_disabled_by ) ) { | |
| 94 | - throw new MainWP_Exception( 'ERROR', $wpcore_update_disabled_by ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 95 | - } | |
| 96 | - /** | |
| 97 | - * Action: mainwp_before_wp_update | |
| 98 | - * | |
| 99 | - * Fires before WP update. | |
| 100 | - * | |
| 101 | - * @since 4.1 | |
| 102 | - */ | |
| 103 | - do_action( 'mainwp_before_wp_update', $website ); | |
| 104 | + throw new MainWP_Exception( 'ERROR', '<i class="red times icon"></i> ' . esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ); | |
| 105 | + } | |
| 104 | 106 | |
| 105 | - $information = MainWP_Connect::fetch_url_authed( $website, 'upgrade' ); | |
| 107 | + /** | |
| 108 | + * Method upgrade_website() | |
| 109 | + * | |
| 110 | + * Update WP for site. | |
| 111 | + * | |
| 112 | + * @param object $website Child site object. | |
| 113 | + * | |
| 114 | + * @return mixed|false update result or false. | |
| 115 | + * @throws MainWP_Exception Error message. | |
| 116 | + * | |
| 117 | + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 118 | + */ | |
| 119 | + public static function upgrade_website( $website ) { // phpcs:ignore -- NOSONAR - complex. | |
| 120 | + if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 106 | 121 | |
| 107 | - // logging feature. | |
| 108 | - $error = ''; | |
| 109 | - $success = false; | |
| 122 | + $wpcore_update_disabled_by = MainWP_System_Utility::disabled_wpcore_update_by( $website ); | |
| 123 | + if ( ! empty( $wpcore_update_disabled_by ) ) { | |
| 124 | + throw new MainWP_Exception( 'ERROR', $wpcore_update_disabled_by ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 125 | + } | |
| 126 | + /** | |
| 127 | + * Action: mainwp_before_wp_update | |
| 128 | + * | |
| 129 | + * Fires before WP update. | |
| 130 | + * | |
| 131 | + * @since 4.1 | |
| 132 | + */ | |
| 133 | + do_action( 'mainwp_before_wp_update', $website ); | |
| 110 | 134 | |
| 111 | - if ( is_array( $information ) ) { | |
| 112 | - if ( isset( $information['upgrade'] ) && ( 'SUCCESS' === $information['upgrade'] ) ) { | |
| 113 | - $success = true; | |
| 114 | - } elseif ( isset( $information['upgrade'] ) ) { | |
| 115 | - $errorMsg = ''; | |
| 116 | - if ( 'LOCALIZATION' === $information['upgrade'] ) { | |
| 117 | - $error = esc_html__( 'No update found for the set locale.', 'mainwp' ); | |
| 118 | - } elseif ( 'NORESPONSE' === $information['upgrade'] ) { | |
| 119 | - $error = esc_html__( 'No response from the child site server.', 'mainwp' ); | |
| 120 | - } | |
| 121 | - } elseif ( isset( $information['error'] ) ) { | |
| 122 | - $error = esc_html( $information['error'] ); | |
| 123 | - } else { | |
| 124 | - $error = esc_html__( 'Invalid response from child site.', 'mainwp' ); | |
| 125 | - } | |
| 126 | - } | |
| 135 | + $information = MainWP_Connect::fetch_url_authed( $website, 'upgrade' ); | |
| 127 | 136 | |
| 128 | - $output_array = array( | |
| 129 | - 'old_version' => isset( $information['old_version'] ) ? $information['old_version'] : '', | |
| 130 | - 'version' => isset( $information['version'] ) ? $information['version'] : '', | |
| 131 | - 'success' => $success ? 1 : 0, | |
| 132 | - 'error' => $error, | |
| 133 | - ); | |
| 134 | - mainwp_get_actions_handler_instance()->do_action_mainwp_install_actions( $website, 'updated', $output_array, 'core' ); | |
| 137 | + static::activity_log_upgrade( $website, $information ); | |
| 135 | 138 | |
| 136 | - /** | |
| 137 | - * Action: mainwp_after_wp_update | |
| 138 | - * | |
| 139 | - * Fires after WP update. | |
| 140 | - * | |
| 141 | - * @since 4.1 | |
| 142 | - */ | |
| 143 | - do_action( 'mainwp_after_wp_update', $information, $website ); | |
| 139 | + /** | |
| 140 | + * Action: mainwp_after_wp_update | |
| 141 | + * | |
| 142 | + * Fires after WP update. | |
| 143 | + * | |
| 144 | + * @since 4.1 | |
| 145 | + */ | |
| 146 | + do_action( 'mainwp_after_wp_update', $information, $website ); | |
| 144 | 147 | |
| 145 | - return $information; | |
| 146 | - } | |
| 147 | - return false; | |
| 148 | - } | |
| 148 | + return $information; | |
| 149 | + } | |
| 150 | + return false; | |
| 151 | + } | |
| 149 | 152 | |
| 150 | - /** | |
| 151 | - * Add a plugin or theme to the ignor list. | |
| 152 | - * | |
| 153 | - * @param mixed $type plugin|theme. | |
| 154 | - * @param mixed $slug Plugin or Theme Slug. | |
| 155 | - * @param mixed $name Plugin or Theme Name. | |
| 156 | - * @param mixed $id Child Site ID. | |
| 157 | - * | |
| 158 | - * @return string success. | |
| 159 | - * | |
| 160 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 161 | - * @uses \MainWP\Dashboard\MainWP_DB::update_website_values() | |
| 162 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 163 | - * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 164 | - */ | |
| 165 | - public static function ignore_plugin_theme( $type, $slug, $name, $id ) { | |
| 166 | - if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) { | |
| 167 | - $website = MainWP_DB::instance()->get_website_by_id( $id ); | |
| 168 | - if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 169 | - $slug = urldecode( $slug ); | |
| 170 | - if ( 'plugin' === $type ) { | |
| 171 | - $decodedIgnoredPlugins = json_decode( $website->ignored_plugins, true ); | |
| 172 | - if ( ! isset( $decodedIgnoredPlugins[ $slug ] ) ) { | |
| 153 | + /** | |
| 154 | + * Log upgrade activities. | |
| 155 | + * | |
| 156 | + * @param object $website Child site object. | |
| 157 | + * @param array $information Upgrade information. | |
| 158 | + * @param bool $is_auto_update Whether the update is automatic. | |
| 159 | + */ | |
| 160 | + public static function activity_log_upgrade( $website, $information, $is_auto_update = false ) { // phpcs:ignore -- NOSONAR - complex. | |
| 161 | + // Implementation for logging upgrade activities. | |
| 162 | + $error = ''; | |
| 163 | + $success = false; | |
| 173 | 164 | |
| 174 | - /** | |
| 175 | - * Action: mainwp_before_plugin_ignore | |
| 176 | - * | |
| 177 | - * Fires before plugin ignore. | |
| 178 | - * | |
| 179 | - * @since 4.1 | |
| 180 | - */ | |
| 181 | - do_action( 'mainwp_before_plugin_ignore', $decodedIgnoredPlugins, $website ); | |
| 165 | + if ( is_array( $information ) ) { | |
| 166 | + if ( isset( $information['upgrade'] ) && ( 'SUCCESS' === $information['upgrade'] ) ) { | |
| 167 | + $success = true; | |
| 168 | + } elseif ( isset( $information['upgrade'] ) ) { | |
| 169 | + if ( 'LOCALIZATION' === $information['upgrade'] ) { | |
| 170 | + $error = esc_html__( 'No update found for the set locale.', 'mainwp' ); | |
| 171 | + } elseif ( 'NORESPONSE' === $information['upgrade'] ) { | |
| 172 | + $error = esc_html__( 'No response from the child site server.', 'mainwp' ); | |
| 173 | + } | |
| 174 | + } elseif ( isset( $information['error'] ) ) { | |
| 175 | + $error = esc_html( $information['error'] ); | |
| 176 | + } else { | |
| 177 | + $error = esc_html__( 'Invalid response from child site.', 'mainwp' ); | |
| 178 | + } | |
| 179 | + } | |
| 182 | 180 | |
| 183 | - $decodedIgnoredPlugins[ $slug ] = urldecode( $name ); | |
| 184 | - MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ) ) ); | |
| 181 | + $output_array = array( | |
| 182 | + 'old_version' => is_array( $information ) && isset( $information['old_version'] ) ? $information['old_version'] : '', | |
| 183 | + 'version' => is_array( $information ) && isset( $information['version'] ) ? $information['version'] : '', | |
| 184 | + 'success' => $success ? 1 : 0, | |
| 185 | + 'error' => $error, | |
| 186 | + ); | |
| 185 | 187 | |
| 186 | - /** | |
| 187 | - * Action: mainwp_after_plugin_ignore | |
| 188 | - * | |
| 189 | - * Fires after plugin ignore. | |
| 190 | - * | |
| 191 | - * @since 4.1 | |
| 192 | - */ | |
| 193 | - do_action( 'mainwp_after_plugin_ignore', $decodedIgnoredPlugins, $website ); | |
| 188 | + if ( $is_auto_update ) { | |
| 189 | + MainWP_Updates_Report_Manager::save_update_info( $website, $output_array, 'core' ); | |
| 190 | + } | |
| 194 | 191 | |
| 195 | - } | |
| 196 | - } elseif ( 'theme' === $type ) { | |
| 197 | - $decodedIgnoredThemes = json_decode( $website->ignored_themes, true ); | |
| 198 | - if ( ! isset( $decodedIgnoredThemes[ $slug ] ) ) { | |
| 199 | - /** | |
| 200 | - * Action: mainwp_before_theme_ignore | |
| 201 | - * | |
| 202 | - * Fires before theme ignore. | |
| 203 | - * | |
| 204 | - * @since 4.1 | |
| 205 | - */ | |
| 206 | - do_action( 'mainwp_before_theme_ignore', $decodedIgnoredThemes, $website ); | |
| 192 | + $actions_handler = mainwp_get_actions_handler_instance(); | |
| 193 | + if ( is_object( $actions_handler ) ) { | |
| 194 | + $actions_handler->do_action_mainwp_install_actions( $website, 'updated', $output_array, 'core' ); | |
| 195 | + } | |
| 196 | + } | |
| 207 | 197 | |
| 208 | - $decodedIgnoredThemes[ $slug ] = urldecode( $name ); | |
| 209 | - MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ) ) ); | |
| 198 | + /** | |
| 199 | + * Add a plugin or theme to the ignor list. | |
| 200 | + * | |
| 201 | + * @param mixed $type plugin|theme. | |
| 202 | + * @param mixed $slug Plugin or Theme Slug. | |
| 203 | + * @param mixed $name Plugin or Theme Name. | |
| 204 | + * @param mixed $id Child Site ID. | |
| 205 | + * @param string $ver version ignore. | |
| 206 | + * | |
| 207 | + * @return string success. | |
| 208 | + * | |
| 209 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 210 | + * @uses \MainWP\Dashboard\MainWP_DB::update_website_values() | |
| 211 | + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 212 | + * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 213 | + */ | |
| 214 | + public static function ignore_plugin_theme( $type, $slug, $name, $id, $ver = '' ) { // phpcs:ignore -- NOSONAR - complex. | |
| 215 | + if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) { | |
| 216 | + $website = MainWP_DB::instance()->get_website_by_id( $id ); | |
| 217 | + if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 218 | + $slug = urldecode( $slug ); | |
| 219 | + if ( 'plugin' === $type ) { | |
| 220 | + $decodedIgnoredPlugins = json_decode( $website->ignored_plugins, true ); | |
| 221 | + /** | |
| 222 | + * Action: mainwp_before_plugin_ignore | |
| 223 | + * | |
| 224 | + * Fires before plugin ignore. | |
| 225 | + * | |
| 226 | + * @since 4.1 | |
| 227 | + */ | |
| 228 | + do_action( 'mainwp_before_plugin_ignore', $decodedIgnoredPlugins, $website ); | |
| 210 | 229 | |
| 211 | - /** | |
| 212 | - * Action: mainwp_after_theme_ignore | |
| 213 | - * | |
| 214 | - * Fires after theme ignore. | |
| 215 | - * | |
| 216 | - * @since 4.1 | |
| 217 | - */ | |
| 218 | - do_action( 'mainwp_after_theme_ignore', $website, $decodedIgnoredThemes ); | |
| 219 | - } | |
| 220 | - } | |
| 221 | - } | |
| 222 | - } | |
| 230 | + $ignored_info = is_array( $decodedIgnoredPlugins ) && isset( $decodedIgnoredPlugins[ $slug ] ) ? $decodedIgnoredPlugins[ $slug ] : array(); | |
| 231 | + if ( ! is_array( $ignored_info ) ) { | |
| 232 | + $ignored_info = array(); | |
| 233 | + } | |
| 223 | 234 | |
| 224 | - return 'success'; | |
| 225 | - } | |
| 235 | + $ignored_info['Name'] = urldecode( $name ); | |
| 226 | 236 | |
| 227 | - /** | |
| 228 | - * Remove a plugin or theme from the ignore list. | |
| 229 | - * | |
| 230 | - * @param mixed $type plugin|theme. | |
| 231 | - * @param mixed $slug Plugin or Theme slug. | |
| 232 | - * @param mixed $id Plugin or Theme name. | |
| 233 | - * | |
| 234 | - * @return string success. | |
| 235 | - * | |
| 236 | - * @uses \MainWP\Dashboard\MainWP_DB::query() | |
| 237 | - * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user() | |
| 238 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 239 | - * @uses \MainWP\Dashboard\MainWP_DB::update_website_values() | |
| 240 | - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object() | |
| 241 | - * @uses \MainWP\Dashboard\MainWP_DB::free_result() | |
| 242 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 243 | - * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 244 | - */ | |
| 245 | - public static function unignore_plugin_theme( $type, $slug, $id ) { | |
| 246 | - if ( ! empty( $id ) ) { | |
| 237 | + $ignored_vers = is_array( $ignored_info ) && isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array(); | |
| 238 | + if ( ! is_array( $ignored_vers ) ) { | |
| 239 | + $ignored_vers = array(); | |
| 240 | + } | |
| 241 | + if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all. | |
| 242 | + $ignored_vers = array( 'all_versions' ); | |
| 243 | + } else { | |
| 244 | + $ver = urldecode( $ver ); | |
| 245 | + if ( ! in_array( $ver, $ignored_vers ) ) { | |
| 246 | + $ignored_vers[] = $ver; | |
| 247 | + } | |
| 248 | + } | |
| 249 | + $ignored_info['ignored_versions'] = $ignored_vers; | |
| 247 | 250 | |
| 248 | - /** | |
| 249 | - * Action: mainwp_before_plugin_theme_unignore | |
| 250 | - * | |
| 251 | - * Fires after plugin/theme unignore. | |
| 252 | - * | |
| 253 | - * @since 4.1 | |
| 254 | - */ | |
| 255 | - do_action( 'mainwp_before_plugin_theme_unignore', $type, $slug, $id ); | |
| 251 | + $decodedIgnoredPlugins[ $slug ] = $ignored_info; | |
| 256 | 252 | |
| 257 | - if ( '_ALL_' === $id ) { | |
| 258 | - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() ); | |
| 259 | - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { | |
| 260 | - if ( 'plugin' === $type ) { | |
| 253 | + MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ) ) ); | |
| 261 | 254 | |
| 262 | - /** | |
| 263 | - * Action: mainwp_before_plugin_unignore | |
| 264 | - * | |
| 265 | - * Fires before plugin unignore. | |
| 266 | - * | |
| 267 | - * @since 4.1 | |
| 268 | - */ | |
| 269 | - do_action( 'mainwp_before_plugin_unignore', array(), $website ); | |
| 255 | + /** | |
| 256 | + * Action: mainwp_after_plugin_ignore | |
| 257 | + * | |
| 258 | + * Fires after plugin ignore. | |
| 259 | + * | |
| 260 | + * @since 4.1 | |
| 261 | + */ | |
| 262 | + do_action( 'mainwp_after_plugin_ignore', $decodedIgnoredPlugins, $website ); | |
| 270 | 263 | |
| 271 | - MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_plugins' => wp_json_encode( array() ) ) ); | |
| 264 | + } elseif ( 'theme' === $type ) { | |
| 265 | + $decodedIgnoredThemes = json_decode( $website->ignored_themes, true ); | |
| 272 | 266 | |
| 273 | - /** | |
| 274 | - * Action: mainwp_after_plugin_unignore | |
| 275 | - * | |
| 276 | - * Fires after plugin unignore. | |
| 277 | - * | |
| 278 | - * @since 4.1 | |
| 279 | - */ | |
| 280 | - do_action( 'mainwp_after_plugin_unignore', array(), $website ); | |
| 267 | + /** | |
| 268 | + * Action: mainwp_before_theme_ignore | |
| 269 | + * | |
| 270 | + * Fires before theme ignore. | |
| 271 | + * | |
| 272 | + * @since 4.1 | |
| 273 | + */ | |
| 274 | + do_action( 'mainwp_before_theme_ignore', $decodedIgnoredThemes, $website ); | |
| 281 | 275 | |
| 282 | - } elseif ( 'theme' === $type ) { | |
| 283 | - /** | |
| 284 | - * Action: mainwp_before_theme_unignore | |
| 285 | - * | |
| 286 | - * Fires before theme unignore. | |
| 287 | - * | |
| 288 | - * @since 4.1 | |
| 289 | - */ | |
| 290 | - do_action( 'mainwp_before_theme_unignore', array(), $website ); | |
| 291 | - MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( array() ) ) ); | |
| 276 | + $ignored_info = is_array( $decodedIgnoredThemes ) && isset( $decodedIgnoredThemes[ $slug ] ) ? $decodedIgnoredThemes[ $slug ] : array(); | |
| 277 | + if ( ! is_array( $ignored_info ) ) { | |
| 278 | + $ignored_info = array(); | |
| 279 | + } | |
| 280 | + $ignored_info['Name'] = urldecode( $name ); | |
| 292 | 281 | |
| 293 | - /** | |
| 294 | - * Action: mainwp_after_theme_unignore | |
| 295 | - * | |
| 296 | - * Fires after theme unignore. | |
| 297 | - * | |
| 298 | - * @since 4.1 | |
| 299 | - */ | |
| 300 | - do_action( 'mainwp_after_theme_unignore', array(), $website ); | |
| 301 | - } | |
| 302 | - } | |
| 303 | - MainWP_DB::free_result( $websites ); | |
| 304 | - } elseif ( MainWP_Utility::ctype_digit( $id ) ) { | |
| 305 | - $website = MainWP_DB::instance()->get_website_by_id( $id ); | |
| 306 | - if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 307 | - $slug = urldecode( $slug ); | |
| 308 | - if ( 'plugin' === $type ) { | |
| 309 | - $decodedIgnoredPlugins = json_decode( $website->ignored_plugins, true ); | |
| 310 | - if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) { | |
| 282 | + $ignored_vers = is_array( $ignored_info ) && isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array(); | |
| 283 | + if ( ! is_array( $ignored_vers ) ) { | |
| 284 | + $ignored_vers = array(); | |
| 285 | + } | |
| 286 | + if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all. | |
| 287 | + $ignored_vers = array( 'all_versions' ); | |
| 288 | + } else { | |
| 289 | + $ver = urldecode( $ver ); | |
| 290 | + if ( ! in_array( $ver, $ignored_vers ) ) { | |
| 291 | + $ignored_vers[] = $ver; | |
| 292 | + } | |
| 293 | + } | |
| 294 | + $ignored_info['ignored_versions'] = $ignored_vers; | |
| 311 | 295 | |
| 312 | - /** | |
| 313 | - * Action: mainwp_before_plugin_unignore | |
| 314 | - * | |
| 315 | - * Fires before plugin unignore. | |
| 316 | - * | |
| 317 | - * @since 4.1 | |
| 318 | - */ | |
| 319 | - do_action( 'mainwp_before_plugin_unignore', $decodedIgnoredPlugins, $website ); | |
| 296 | + $decodedIgnoredThemes[ $slug ] = $ignored_info; | |
| 297 | + MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ) ) ); | |
| 298 | + /** | |
| 299 | + * Action: mainwp_after_theme_ignore | |
| 300 | + * | |
| 301 | + * Fires after theme ignore. | |
| 302 | + * | |
| 303 | + * @since 4.1 | |
| 304 | + */ | |
| 305 | + do_action( 'mainwp_after_theme_ignore', $website, $decodedIgnoredThemes ); | |
| 306 | + } | |
| 307 | + } | |
| 308 | + } | |
| 309 | + return 'success'; | |
| 310 | + } | |
| 320 | 311 | |
| 321 | - unset( $decodedIgnoredPlugins[ $slug ] ); | |
| 322 | - MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ) ) ); | |
| 323 | 312 | |
| 324 | - /** | |
| 325 | - * Action: mainwp_after_plugin_unignore | |
| 326 | - * | |
| 327 | - * Fires after plugin unignore. | |
| 328 | - * | |
| 329 | - * @since 4.1 | |
| 330 | - */ | |
| 331 | - do_action( 'mainwp_after_plugin_unignore', $decodedIgnoredPlugins, $website ); | |
| 332 | - } | |
| 333 | - } elseif ( 'theme' === $type ) { | |
| 334 | - $decodedIgnoredThemes = json_decode( $website->ignored_themes, true ); | |
| 335 | - if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { | |
| 313 | + /** | |
| 314 | + * Remove a plugin or theme from the ignore list. | |
| 315 | + * | |
| 316 | + * @param mixed $type plugin|theme. | |
| 317 | + * @param mixed $slug Plugin or Theme slug. | |
| 318 | + * @param mixed $id Plugin or Theme name. | |
| 319 | + * @param string $ver Plugin or Theme version. | |
| 320 | + * | |
| 321 | + * @return string success. | |
| 322 | + * | |
| 323 | + * @uses \MainWP\Dashboard\MainWP_DB::query() | |
| 324 | + * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user() | |
| 325 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 326 | + * @uses \MainWP\Dashboard\MainWP_DB::update_website_values() | |
| 327 | + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object() | |
| 328 | + * @uses \MainWP\Dashboard\MainWP_DB::free_result() | |
| 329 | + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 330 | + * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 331 | + */ | |
| 332 | + public static function unignore_plugin_theme( $type, $slug, $id, $ver ) { // phpcs:ignore -- NOSONAR - complex. | |
| 333 | + if ( ! empty( $id ) ) { | |
| 336 | 334 | |
| 337 | - /** | |
| 338 | - * Action: mainwp_before_theme_unignore | |
| 339 | - * | |
| 340 | - * Fires before theme unignore. | |
| 341 | - * | |
| 342 | - * @since 4.1 | |
| 343 | - */ | |
| 344 | - do_action( 'mainwp_before_theme_unignore', $decodedIgnoredThemes, $website ); | |
| 335 | + /** | |
| 336 | + * Action: mainwp_before_plugin_theme_unignore | |
| 337 | + * | |
| 338 | + * Fires after plugin/theme unignore. | |
| 339 | + * | |
| 340 | + * @since 4.1 | |
| 341 | + */ | |
| 342 | + do_action( 'mainwp_before_plugin_theme_unignore', $type, $slug, $id ); | |
| 345 | 343 | |
| 346 | - unset( $decodedIgnoredThemes[ $slug ] ); | |
| 347 | - MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ) ) ); | |
| 344 | + if ( '_ALL_' === $id ) { | |
| 345 | + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() ); | |
| 346 | + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { | |
| 347 | + if ( 'plugin' === $type ) { | |
| 348 | 348 | |
| 349 | - /** | |
| 350 | - * Action: mainwp_after_theme_unignore | |
| 351 | - * | |
| 352 | - * Fires after theme unignore. | |
| 353 | - * | |
| 354 | - * @since 4.1 | |
| 355 | - */ | |
| 356 | - do_action( 'mainwp_after_theme_unignore', $decodedIgnoredThemes, $website ); | |
| 357 | - } | |
| 358 | - } | |
| 359 | - } | |
| 360 | - } | |
| 361 | - } | |
| 349 | + /** | |
| 350 | + * Action: mainwp_before_plugin_unignore | |
| 351 | + * | |
| 352 | + * Fires before plugin unignore. | |
| 353 | + * | |
| 354 | + * @since 4.1 | |
| 355 | + */ | |
| 356 | + do_action( 'mainwp_before_plugin_unignore', array(), $website ); | |
| 362 | 357 | |
| 363 | - return 'success'; | |
| 364 | - } | |
| 358 | + MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_plugins' => wp_json_encode( array() ) ) ); | |
| 365 | 359 | |
| 366 | - /** | |
| 367 | - * Method ignore_plugins_themes() | |
| 368 | - * | |
| 369 | - * Ignore Plugins or Themes. | |
| 370 | - * | |
| 371 | - * @param string $type Plugin or theme. | |
| 372 | - * @param string $slug Plugin or tempheme slug. | |
| 373 | - * @param string $name Plugin or theme name. | |
| 374 | - * | |
| 375 | - * @return string 'success'. | |
| 376 | - * | |
| 377 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 378 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 379 | - */ | |
| 380 | - public static function ignore_plugins_themes( $type, $slug, $name ) { | |
| 381 | - $slug = urldecode( $slug ); | |
| 382 | - $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 383 | - if ( 'plugin' === $type ) { | |
| 384 | - $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true ); | |
| 385 | - if ( ! is_array( $decodedIgnoredPlugins ) ) { | |
| 386 | - $decodedIgnoredPlugins = array(); | |
| 387 | - } | |
| 388 | - $decodedIgnoredPlugins[ $slug ] = urldecode( $name ); | |
| 389 | - MainWP_DB_Common::instance()->update_user_extension( | |
| 390 | - array( | |
| 391 | - 'userid' => null, | |
| 392 | - 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ), | |
| 393 | - ) | |
| 394 | - ); | |
| 395 | - } elseif ( 'theme' === $type ) { | |
| 396 | - $decodedIgnoredThemes = json_decode( $userExtension->ignored_themes, true ); | |
| 397 | - if ( ! is_array( $decodedIgnoredThemes ) ) { | |
| 398 | - $decodedIgnoredThemes = array(); | |
| 399 | - } | |
| 400 | - $decodedIgnoredThemes[ $slug ] = urldecode( $name ); | |
| 401 | - MainWP_DB_Common::instance()->update_user_extension( | |
| 402 | - array( | |
| 403 | - 'userid' => null, | |
| 404 | - 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ), | |
| 405 | - ) | |
| 406 | - ); | |
| 407 | - } | |
| 360 | + /** | |
| 361 | + * Action: mainwp_after_plugin_unignore | |
| 362 | + * | |
| 363 | + * Fires after plugin unignore. | |
| 364 | + * | |
| 365 | + * @since 4.1 | |
| 366 | + */ | |
| 367 | + do_action( 'mainwp_after_plugin_unignore', array(), $website ); | |
| 408 | 368 | |
| 409 | - return 'success'; | |
| 410 | - } | |
| 369 | + } elseif ( 'theme' === $type ) { | |
| 370 | + /** | |
| 371 | + * Action: mainwp_before_theme_unignore | |
| 372 | + * | |
| 373 | + * Fires before theme unignore. | |
| 374 | + * | |
| 375 | + * @since 4.1 | |
| 376 | + */ | |
| 377 | + do_action( 'mainwp_before_theme_unignore', array(), $website ); | |
| 378 | + MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( array() ) ) ); | |
| 411 | 379 | |
| 412 | - /** | |
| 413 | - * Unignore Plugins or Themes. | |
| 414 | - * | |
| 415 | - * @param mixed $type plugin|themes. | |
| 416 | - * @param mixed $slug Plugin or Themes slug. | |
| 417 | - * | |
| 418 | - * @return string success. | |
| 419 | - * | |
| 420 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 421 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 422 | - */ | |
| 423 | - public static function unignore_plugins_themes( $type, $slug ) { | |
| 424 | - $slug = urldecode( $slug ); | |
| 425 | - $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 426 | - if ( 'plugin' === $type ) { | |
| 427 | - if ( '_ALL_' === $slug ) { | |
| 428 | - $decodedIgnoredPlugins = array(); | |
| 429 | - } else { | |
| 430 | - $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true ); | |
| 431 | - if ( ! is_array( $decodedIgnoredPlugins ) ) { | |
| 432 | - $decodedIgnoredPlugins = array(); | |
| 433 | - } | |
| 434 | - if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) { | |
| 435 | - unset( $decodedIgnoredPlugins[ $slug ] ); | |
| 436 | - } | |
| 437 | - } | |
| 438 | - MainWP_DB_Common::instance()->update_user_extension( | |
| 439 | - array( | |
| 440 | - 'userid' => null, | |
| 441 | - 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ), | |
| 442 | - ) | |
| 443 | - ); | |
| 444 | - } elseif ( 'theme' === $type ) { | |
| 445 | - if ( '_ALL_' === $slug ) { | |
| 446 | - $decodedIgnoredThemes = array(); | |
| 447 | - } else { | |
| 448 | - $decodedIgnoredThemes = json_decode( $userExtension->ignored_plugins, true ); | |
| 449 | - if ( ! is_array( $decodedIgnoredThemes ) ) { | |
| 450 | - $decodedIgnoredThemes = array(); | |
| 451 | - } | |
| 452 | - if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { | |
| 453 | - unset( $decodedIgnoredThemes[ $slug ] ); | |
| 454 | - } | |
| 455 | - } | |
| 456 | - MainWP_DB_Common::instance()->update_user_extension( | |
| 457 | - array( | |
| 458 | - 'userid' => null, | |
| 459 | - 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ), | |
| 460 | - ) | |
| 461 | - ); | |
| 462 | - } | |
| 380 | + /** | |
| 381 | + * Action: mainwp_after_theme_unignore | |
| 382 | + * | |
| 383 | + * Fires after theme unignore. | |
| 384 | + * | |
| 385 | + * @since 4.1 | |
| 386 | + */ | |
| 387 | + do_action( 'mainwp_after_theme_unignore', array(), $website ); | |
| 388 | + } | |
| 389 | + } | |
| 390 | + MainWP_DB::free_result( $websites ); | |
| 391 | + } elseif ( MainWP_Utility::ctype_digit( $id ) ) { | |
| 392 | + $website = MainWP_DB::instance()->get_website_by_id( $id ); | |
| 393 | + if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 394 | + $slug = urldecode( $slug ); | |
| 395 | + if ( 'plugin' === $type ) { | |
| 396 | + $decodedIgnoredPlugins = json_decode( $website->ignored_plugins, true ); | |
| 397 | + if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) { | |
| 398 | + /** | |
| 399 | + * Action: mainwp_before_plugin_unignore | |
| 400 | + * | |
| 401 | + * Fires before plugin unignore. | |
| 402 | + * | |
| 403 | + * @since 4.1 | |
| 404 | + */ | |
| 405 | + do_action( 'mainwp_before_plugin_unignore', $decodedIgnoredPlugins, $website ); | |
| 463 | 406 | |
| 464 | - return 'success'; | |
| 465 | - } | |
| 407 | + if ( is_string( $decodedIgnoredPlugins[ $slug ] ) ) { // old ignored info. | |
| 408 | + unset( $decodedIgnoredPlugins[ $slug ] ); | |
| 409 | + } elseif ( is_array( $decodedIgnoredPlugins[ $slug ] ) ) { | |
| 410 | + $ignored_info = $decodedIgnoredPlugins[ $slug ]; | |
| 411 | + $ignored_vers = is_array( $ignored_info ) && isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array(); | |
| 466 | 412 | |
| 413 | + if ( ! is_array( $ignored_vers ) ) { | |
| 414 | + $ignored_vers = array(); | |
| 415 | + } | |
| 467 | 416 | |
| 468 | - /** | |
| 469 | - * Unignor abandoned plugins or themes. | |
| 470 | - * | |
| 471 | - * @param mixed $type plugin|themes. | |
| 472 | - * @param mixed $slug Plugin or Themes slug. | |
| 473 | - * @param mixed $id Child Site ID. | |
| 474 | - * | |
| 475 | - * @return string success. | |
| 476 | - * | |
| 477 | - * @uses \MainWP\Dashboard\MainWP_DB::query() | |
| 478 | - * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user() | |
| 479 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 480 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_option() | |
| 481 | - * @uses \MainWP\Dashboard\MainWP_DB::update_website_option() | |
| 482 | - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object() | |
| 483 | - * @uses \MainWP\Dashboard\MainWP_DB::free_result() | |
| 484 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 485 | - * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 486 | - */ | |
| 487 | - public static function unignore_abandoned_plugin_theme( $type, $slug, $id ) { | |
| 488 | - if ( isset( $id ) ) { | |
| 489 | - if ( '_ALL_' === $id ) { | |
| 490 | - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() ); | |
| 491 | - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { | |
| 492 | - if ( 'plugin' === $type ) { | |
| 493 | - MainWP_DB::instance()->update_website_option( $website, 'plugins_outdate_dismissed', wp_json_encode( array() ) ); | |
| 494 | - } elseif ( 'theme' === $type ) { | |
| 495 | - MainWP_DB::instance()->update_website_option( $website, 'themes_outdate_dismissed', wp_json_encode( array() ) ); | |
| 496 | - } | |
| 497 | - } | |
| 498 | - MainWP_DB::free_result( $websites ); | |
| 499 | - } elseif ( MainWP_Utility::ctype_digit( $id ) ) { | |
| 500 | - $website = MainWP_DB::instance()->get_website_by_id( $id ); | |
| 501 | - if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 502 | - $slug = urldecode( $slug ); | |
| 503 | - if ( 'plugin' === $type ) { | |
| 504 | - $decodedIgnoredPlugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' ); | |
| 505 | - $decodedIgnoredPlugins = ! empty( $decodedIgnoredPlugins ) ? json_decode( $decodedIgnoredPlugins, true ) : array(); | |
| 417 | + if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all. | |
| 418 | + unset( $decodedIgnoredPlugins[ $slug ] ); | |
| 419 | + } else { | |
| 420 | + $ver = urldecode( $ver ); | |
| 421 | + if ( in_array( $ver, $ignored_vers ) ) { | |
| 422 | + $ignored_vers = array_diff( $ignored_vers, array( $ver ) ); | |
| 423 | + } | |
| 424 | + $ignored_info['ignored_versions'] = $ignored_vers; | |
| 425 | + if ( empty( $ignored_vers ) ) { | |
| 426 | + unset( $decodedIgnoredPlugins[ $slug ] ); | |
| 427 | + } else { | |
| 428 | + $decodedIgnoredPlugins[ $slug ] = $ignored_info; | |
| 429 | + } | |
| 430 | + } | |
| 431 | + } | |
| 432 | + MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ) ) ); | |
| 433 | + /** | |
| 434 | + * Action: mainwp_after_plugin_unignore | |
| 435 | + * | |
| 436 | + * Fires after plugin unignore. | |
| 437 | + * | |
| 438 | + * @since 4.1 | |
| 439 | + */ | |
| 440 | + do_action( 'mainwp_after_plugin_unignore', $decodedIgnoredPlugins, $website ); | |
| 441 | + } | |
| 442 | + } elseif ( 'theme' === $type ) { | |
| 443 | + $decodedIgnoredThemes = json_decode( $website->ignored_themes, true ); | |
| 444 | + if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { | |
| 506 | 445 | |
| 507 | - if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) { | |
| 508 | - unset( $decodedIgnoredPlugins[ $slug ] ); | |
| 509 | - MainWP_DB::instance()->update_website_option( $website, 'plugins_outdate_dismissed', wp_json_encode( $decodedIgnoredPlugins ) ); | |
| 510 | - } | |
| 511 | - } elseif ( 'theme' === $type ) { | |
| 512 | - $decodedIgnoredThemes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_dismissed' ); | |
| 513 | - $decodedIgnoredThemes = ! empty( $decodedIgnoredThemes ) ? json_decode( $decodedIgnoredThemes, true ) : array(); | |
| 446 | + /** | |
| 447 | + * Action: mainwp_before_theme_unignore | |
| 448 | + * | |
| 449 | + * Fires before theme unignore. | |
| 450 | + * | |
| 451 | + * @since 4.1 | |
| 452 | + */ | |
| 453 | + do_action( 'mainwp_before_theme_unignore', $decodedIgnoredThemes, $website ); | |
| 514 | 454 | |
| 515 | - if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { | |
| 516 | - unset( $decodedIgnoredThemes[ $slug ] ); | |
| 517 | - MainWP_DB::instance()->update_website_option( $website, 'themes_outdate_dismissed', wp_json_encode( $decodedIgnoredThemes ) ); | |
| 518 | - } | |
| 519 | - } | |
| 520 | - } | |
| 521 | - } | |
| 522 | - } | |
| 455 | + if ( is_string( $decodedIgnoredThemes[ $slug ] ) ) { // old ignored info. | |
| 456 | + unset( $decodedIgnoredThemes[ $slug ] ); | |
| 457 | + } elseif ( is_array( $decodedIgnoredThemes[ $slug ] ) ) { | |
| 458 | + $ignored_info = $decodedIgnoredThemes[ $slug ]; | |
| 459 | + $ignored_vers = is_array( $ignored_info ) && isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array(); | |
| 523 | 460 | |
| 524 | - return 'success'; | |
| 525 | - } | |
| 461 | + if ( ! is_array( $ignored_vers ) ) { | |
| 462 | + $ignored_vers = array(); | |
| 463 | + } | |
| 526 | 464 | |
| 465 | + if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all. | |
| 466 | + unset( $decodedIgnoredThemes[ $slug ] ); | |
| 467 | + } else { | |
| 468 | + $ver = urldecode( $ver ); | |
| 469 | + if ( in_array( $ver, $ignored_vers ) ) { | |
| 470 | + $ignored_vers = array_diff( $ignored_vers, array( $ver ) ); | |
| 471 | + } | |
| 472 | + $ignored_info['ignored_versions'] = $ignored_vers; | |
| 473 | + if ( empty( $ignored_vers ) ) { | |
| 474 | + unset( $decodedIgnoredThemes[ $slug ] ); | |
| 475 | + } else { | |
| 476 | + $decodedIgnoredThemes[ $slug ] = $ignored_info; | |
| 477 | + } | |
| 478 | + } | |
| 479 | + } | |
| 527 | 480 | |
| 528 | - /** | |
| 529 | - * Unignore abandoned plugins or themes. | |
| 530 | - * | |
| 531 | - * @param mixed $type plugin|theme. | |
| 532 | - * @param mixed $slug Plugin or Themes slug. | |
| 533 | - * | |
| 534 | - * @return string success. | |
| 535 | - * | |
| 536 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 537 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 538 | - */ | |
| 539 | - public static function unignore_abandoned_plugins_themes( $type, $slug ) { | |
| 540 | - $slug = urldecode( $slug ); | |
| 541 | - $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 542 | - if ( 'plugin' === $type ) { | |
| 543 | - if ( '_ALL_' === $slug ) { | |
| 544 | - $decodedIgnoredPlugins = array(); | |
| 545 | - } else { | |
| 546 | - $decodedIgnoredPlugins = json_decode( $userExtension->dismissed_plugins, true ); | |
| 547 | - if ( ! is_array( $decodedIgnoredPlugins ) ) { | |
| 548 | - $decodedIgnoredPlugins = array(); | |
| 549 | - } | |
| 550 | - if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) { | |
| 551 | - unset( $decodedIgnoredPlugins[ $slug ] ); | |
| 552 | - } | |
| 553 | - } | |
| 554 | - MainWP_DB_Common::instance()->update_user_extension( | |
| 555 | - array( | |
| 556 | - 'userid' => null, | |
| 557 | - 'dismissed_plugins' => wp_json_encode( $decodedIgnoredPlugins ), | |
| 558 | - ) | |
| 559 | - ); | |
| 560 | - } elseif ( 'theme' === $type ) { | |
| 561 | - if ( '_ALL_' === $slug ) { | |
| 562 | - $decodedIgnoredThemes = array(); | |
| 563 | - } else { | |
| 564 | - $decodedIgnoredThemes = json_decode( $userExtension->dismissed_themes, true ); | |
| 565 | - if ( ! is_array( $decodedIgnoredThemes ) ) { | |
| 566 | - $decodedIgnoredThemes = array(); | |
| 567 | - } | |
| 568 | - if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { | |
| 569 | - unset( $decodedIgnoredThemes[ $slug ] ); | |
| 570 | - } | |
| 571 | - } | |
| 572 | - MainWP_DB_Common::instance()->update_user_extension( | |
| 573 | - array( | |
| 574 | - 'userid' => null, | |
| 575 | - 'dismissed_themes' => wp_json_encode( $decodedIgnoredThemes ), | |
| 576 | - ) | |
| 577 | - ); | |
| 578 | - } | |
| 481 | + MainWP_DB::instance()->update_website_values( $website->id, array( 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ) ) ); | |
| 579 | 482 | |
| 580 | - return 'success'; | |
| 581 | - } | |
| 483 | + /** | |
| 484 | + * Action: mainwp_after_theme_unignore | |
| 485 | + * | |
| 486 | + * Fires after theme unignore. | |
| 487 | + * | |
| 488 | + * @since 4.1 | |
| 489 | + */ | |
| 490 | + do_action( 'mainwp_after_theme_unignore', $decodedIgnoredThemes, $website ); | |
| 491 | + } | |
| 492 | + } | |
| 493 | + } | |
| 494 | + } | |
| 495 | + } | |
| 582 | 496 | |
| 583 | - /** | |
| 584 | - * Dismis Plugin or Theme. | |
| 585 | - * | |
| 586 | - * @param mixed $type plugin|theme. | |
| 587 | - * @param mixed $slug Plugin or Theme slug. | |
| 588 | - * @param mixed $name Plugin or Theme name. | |
| 589 | - * @param mixed $id Child Site ID. | |
| 590 | - * | |
| 591 | - * @return string success. | |
| 592 | - * | |
| 593 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 594 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_option() | |
| 595 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 596 | - * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 597 | - */ | |
| 598 | - public static function dismiss_plugin_theme( $type, $slug, $name, $id ) { | |
| 599 | - if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) { | |
| 600 | - $website = MainWP_DB::instance()->get_website_by_id( $id ); | |
| 601 | - if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 602 | - $slug = urldecode( $slug ); | |
| 603 | - if ( 'plugin' === $type ) { | |
| 604 | - $decodedDismissedPlugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' ); | |
| 605 | - $decodedDismissedPlugins = ! empty( $decodedDismissedPlugins ) ? json_decode( $decodedDismissedPlugins, true ) : array(); | |
| 497 | + return 'success'; | |
| 498 | + } | |
| 606 | 499 | |
| 607 | - if ( ! isset( $decodedDismissedPlugins[ $slug ] ) ) { | |
| 608 | - $decodedDismissedPlugins[ $slug ] = urldecode( $name ); | |
| 609 | - MainWP_DB::instance()->update_website_option( $website, 'plugins_outdate_dismissed', wp_json_encode( $decodedDismissedPlugins ) ); | |
| 610 | - } | |
| 611 | - } elseif ( 'theme' === $type ) { | |
| 612 | - $decodedDismissedThemes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_dismissed' ); | |
| 613 | - $decodedDismissedThemes = ! empty( $decodedDismissedThemes ) ? json_decode( $decodedDismissedThemes, true ) : array(); | |
| 614 | 500 | |
| 615 | - if ( ! isset( $decodedDismissedThemes[ $slug ] ) ) { | |
| 616 | - $decodedDismissedThemes[ $slug ] = urldecode( $name ); | |
| 617 | - MainWP_DB::instance()->update_website_option( $website, 'themes_outdate_dismissed', wp_json_encode( $decodedDismissedThemes ) ); | |
| 618 | - } | |
| 619 | - } | |
| 620 | - } | |
| 621 | - } | |
| 501 | + /** | |
| 502 | + * Remove WP from the ignore list. | |
| 503 | + * | |
| 504 | + * @param mixed $id Plugin or Theme name. | |
| 505 | + * @param string $ver Plugin or Theme version. | |
| 506 | + * | |
| 507 | + * @return string success. | |
| 508 | + */ | |
| 509 | + public static function unignore_core_updates( $id, $ver ) { // phpcs:ignore -- NOSONAR - complex. | |
| 510 | + if ( ! empty( $id ) ) { | |
| 622 | 511 | |
| 623 | - return 'success'; | |
| 624 | - } | |
| 512 | + if ( '_ALL_' === $id ) { | |
| 513 | + $params = array( | |
| 514 | + 'view' => 'updates_view', | |
| 515 | + 'others_fields' => array( 'premium_upgrades' ), | |
| 516 | + ); | |
| 517 | + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user_by_params( $params ) ); | |
| 518 | + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { | |
| 625 | 519 | |
| 626 | - /** | |
| 627 | - * Dismiss plugins or themes. | |
| 628 | - * | |
| 629 | - * @param mixed $type plugin|theme. | |
| 630 | - * @param mixed $slug Plugin or Theme slug. | |
| 631 | - * @param mixed $name Plugin or Theme name. | |
| 632 | - * | |
| 633 | - * @return string success. | |
| 634 | - * | |
| 635 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 636 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 637 | - */ | |
| 638 | - public static function dismiss_plugins_themes( $type, $slug, $name ) { | |
| 639 | - $slug = urldecode( $slug ); | |
| 640 | - $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 641 | - if ( 'plugin' === $type ) { | |
| 642 | - $decodedDismissedPlugins = json_decode( $userExtension->dismissed_plugins, true ); | |
| 643 | - if ( ! is_array( $decodedDismissedPlugins ) ) { | |
| 644 | - $decodedDismissedPlugins = array(); | |
| 645 | - } | |
| 646 | - $decodedDismissedPlugins[ $slug ] = urldecode( $name ); | |
| 647 | - MainWP_DB_Common::instance()->update_user_extension( | |
| 648 | - array( | |
| 649 | - 'userid' => null, | |
| 650 | - 'dismissed_plugins' => wp_json_encode( $decodedDismissedPlugins ), | |
| 651 | - ) | |
| 652 | - ); | |
| 653 | - } elseif ( 'theme' === $type ) { | |
| 654 | - $decodedDismissedThemes = json_decode( $userExtension->dismissed_themes, true ); | |
| 655 | - if ( ! is_array( $decodedDismissedThemes ) ) { | |
| 656 | - $decodedDismissedThemes = array(); | |
| 657 | - } | |
| 658 | - $decodedDismissedThemes[ $slug ] = urldecode( $name ); | |
| 659 | - MainWP_DB_Common::instance()->update_user_extension( | |
| 660 | - array( | |
| 661 | - 'userid' => null, | |
| 662 | - 'dismissed_themes' => wp_json_encode( $decodedDismissedThemes ), | |
| 663 | - ) | |
| 664 | - ); | |
| 665 | - } | |
| 520 | + /** | |
| 521 | + * Action: mainwp_before_core_unignore | |
| 522 | + * | |
| 523 | + * Fires before plugin unignore. | |
| 524 | + * | |
| 525 | + * @since 5.2 | |
| 526 | + */ | |
| 527 | + do_action( 'mainwp_before_core_unignore', '_ALL_', $website ); | |
| 666 | 528 | |
| 667 | - return 'success'; | |
| 668 | - } | |
| 529 | + MainWP_DB::instance()->update_website_option( $website->id, 'ignored_wp_upgrades', wp_json_encode( array() ) ); | |
| 530 | + /** | |
| 531 | + * Action: mainwp_after_core_unignore | |
| 532 | + * | |
| 533 | + * Fires after plugin unignore. | |
| 534 | + * | |
| 535 | + * @since 5.2 | |
| 536 | + */ | |
| 537 | + do_action( 'mainwp_before_core_unignore', '_ALL_', $website ); | |
| 669 | 538 | |
| 670 | - /** | |
| 671 | - * Method upgrade_plugin_theme_translation() | |
| 672 | - * | |
| 673 | - * Upgrade plugin or theme translations. | |
| 674 | - * | |
| 675 | - * @param int $id Child site ID. | |
| 676 | - * @param string $type Plugin or theme. | |
| 677 | - * @param array $list_items List of theme or plugin names seperated by comma. | |
| 678 | - * | |
| 679 | - * @return array | |
| 680 | - * @throws MainWP_Exception Error messages. | |
| 681 | - * | |
| 682 | - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 683 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 684 | - * @uses \MainWP\Dashboard\MainWP_Exception | |
| 685 | - * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 686 | - */ | |
| 687 | - public static function upgrade_plugin_theme_translation( $id, $type, $list_items ) { // phpcs:ignore -- complex method. | |
| 688 | - if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) { | |
| 689 | - $website = MainWP_DB::instance()->get_website_by_id( $id, false, array( 'premium_upgrades' ) ); // to fix loading premium_upgrades. | |
| 690 | - if ( MainWP_System_Utility::is_suspended_site( $website ) ) { | |
| 691 | - throw new MainWP_Exception( 'ERROR', esc_html__( 'Suspended site.', 'mainwp' ), 'SUSPENDED_SITE' ); | |
| 692 | - } | |
| 693 | - $result = self::update_plugin_theme_translation( $website, $type, $list_items ); | |
| 694 | - if ( is_array( $result ) ) { | |
| 539 | + } | |
| 540 | + MainWP_DB::free_result( $websites ); | |
| 541 | + return 'success'; | |
| 542 | + } elseif ( MainWP_Utility::ctype_digit( $id ) ) { | |
| 543 | + $website = MainWP_DB::instance()->get_website_by_id( $id, false, array( 'ignored_wp_upgrades' ) ); | |
| 544 | + if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 545 | + $ignored_info = ! empty( $website->ignored_wp_upgrades ) ? json_decode( $website->ignored_wp_upgrades, true ) : array(); | |
| 695 | 546 | |
| 696 | - $return_results = array(); | |
| 547 | + if ( ! is_array( $ignored_info ) ) { | |
| 548 | + $ignored_info = array(); | |
| 549 | + } | |
| 550 | + /** | |
| 551 | + * Action: mainwp_before_core_unignore | |
| 552 | + * | |
| 553 | + * Fires before plugin unignore. | |
| 554 | + * | |
| 555 | + * @since 5.2 | |
| 556 | + */ | |
| 557 | + do_action( 'mainwp_before_core_unignore', $ignored_info, $website ); | |
| 697 | 558 | |
| 698 | - // logging feature. | |
| 699 | - $_type = ''; | |
| 700 | - if ( 'plugin' === $type || 'theme' === $type ) { | |
| 701 | - $_type = $type; | |
| 702 | - } elseif ( 'translation' === $type ) { | |
| 703 | - $_type = 'trans'; | |
| 704 | - } | |
| 559 | + $ignored_vers = isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array(); | |
| 705 | 560 | |
| 706 | - if ( ! empty( $_type ) && isset( $result['other_data'] ) ) { // ok. | |
| 707 | - $output_array = $result['other_data']; // updated_data: plugins,themes,trans. | |
| 708 | - mainwp_get_actions_handler_instance()->do_action_mainwp_install_actions( $website, 'updated', $output_array, $_type ); | |
| 709 | - } | |
| 561 | + if ( ! is_array( $ignored_vers ) ) { | |
| 562 | + $ignored_vers = array(); | |
| 563 | + } | |
| 710 | 564 | |
| 711 | - $undefined = true; | |
| 565 | + if ( empty( $ver ) || 'all_versions' === $ver ) { // unignore all. | |
| 566 | + $ignored_vers = array(); | |
| 567 | + } elseif ( in_array( $ver, $ignored_vers ) ) { | |
| 568 | + $ignored_vers = array_diff( $ignored_vers, array( $ver ) ); | |
| 569 | + } | |
| 570 | + $ignored_info['ignored_versions'] = $ignored_vers; | |
| 571 | + MainWP_DB::instance()->update_website_option( $website->id, 'ignored_wp_upgrades', wp_json_encode( $ignored_info ) ); | |
| 572 | + /** | |
| 573 | + * Action: mainwp_after_core_unignore | |
| 574 | + * | |
| 575 | + * Fires after plugin unignore. | |
| 576 | + * | |
| 577 | + * @since 5.2 | |
| 578 | + */ | |
| 579 | + do_action( 'mainwp_after_core_unignore', $ignored_info, $website ); | |
| 580 | + return 'success'; | |
| 581 | + } | |
| 582 | + } | |
| 583 | + } | |
| 584 | + return 'failed'; | |
| 585 | + } | |
| 712 | 586 | |
| 713 | - if ( isset( $result['upgrades_error'] ) ) { | |
| 714 | - foreach ( $result['upgrades_error'] as $k => $v ) { | |
| 715 | - $return_results['result_error'][ rawurlencode( $k ) ] = esc_html( $v ); | |
| 716 | - } | |
| 717 | - } | |
| 587 | + /** | |
| 588 | + * Unignore Plugins or Themes. | |
| 589 | + * | |
| 590 | + * @param string $slug _ALL_|empty. | |
| 591 | + * @param string $ver version info. | |
| 592 | + * | |
| 593 | + * @return string success. | |
| 594 | + * | |
| 595 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 596 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 597 | + */ | |
| 598 | + public static function unignore_global_cores( $slug, $ver ) { // phpcs:ignore -- NOSONAR - complex. | |
| 599 | + $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 600 | + if ( '_ALL_' === $slug ) { | |
| 601 | + $decodedIgnoredCores = array(); | |
| 602 | + } else { | |
| 603 | + $decodedIgnoredCores = json_decode( $userExtension->ignored_plugins, true ); | |
| 604 | + if ( ! is_array( $decodedIgnoredCores ) ) { | |
| 605 | + $decodedIgnoredCores = array(); | |
| 606 | + } | |
| 607 | + if ( 'all_versions' === $ver ) { | |
| 608 | + $decodedIgnoredCores = array(); | |
| 609 | + } else { | |
| 610 | + $ignored_vers = is_array( $decodedIgnoredCores ) && isset( $decodedIgnoredCores['ignored_versions'] ) ? $decodedIgnoredCores['ignored_versions'] : array(); | |
| 611 | + if ( is_array( $ignored_vers ) && in_array( $ver, $ignored_vers ) ) { | |
| 612 | + $ignored_vers = array_diff( $ignored_vers, array( $ver ) ); | |
| 613 | + if ( empty( $ignored_vers ) ) { | |
| 614 | + $decodedIgnoredCores = array(); | |
| 615 | + } else { | |
| 616 | + $decodedIgnoredCores['ignored_versions'] = $ignored_vers; | |
| 617 | + } | |
| 618 | + } | |
| 619 | + } | |
| 620 | + } | |
| 621 | + MainWP_DB_Common::instance()->update_user_extension( | |
| 622 | + array( | |
| 623 | + 'userid' => null, | |
| 624 | + 'ignored_wp_upgrades' => wp_json_encode( $decodedIgnoredCores ), | |
| 625 | + ) | |
| 626 | + ); | |
| 718 | 627 | |
| 719 | - if ( isset( $result['upgrades'] ) ) { | |
| 720 | - if ( isset( $result['upgrades'] ) ) { | |
| 721 | - foreach ( $result['upgrades'] as $k => $v ) { | |
| 722 | - $return_results['result'][ rawurlencode( $k ) ] = $v; | |
| 723 | - } | |
| 724 | - } | |
| 628 | + return 'success'; | |
| 629 | + } | |
| 725 | 630 | |
| 726 | - if ( 'plugin' === $type ) { | |
| 727 | - if ( ! empty( $website->plugin_upgrades ) ) { | |
| 728 | - $plugin_upgrades = json_decode( $website->plugin_upgrades, true ); | |
| 729 | - if ( is_array( $plugin_upgrades ) ) { | |
| 730 | - $updated = false; | |
| 731 | - if ( isset( $return_results['result'] ) && is_array( $return_results['result'] ) && ! empty( $return_results['result'] ) ) { | |
| 732 | - foreach ( $return_results['result'] as $k => $v ) { | |
| 733 | - $k = rawurldecode( $k ); | |
| 734 | - if ( isset( $plugin_upgrades[ $k ] ) ) { | |
| 735 | - unset( $plugin_upgrades[ $k ] ); // updated. | |
| 736 | - $updated = true; | |
| 737 | - } | |
| 738 | - } | |
| 739 | - } | |
| 740 | - if ( $updated ) { | |
| 741 | - MainWP_DB::instance()->update_website_values( $id, array( 'plugin_upgrades' => wp_json_encode( $plugin_upgrades ) ) ); | |
| 742 | - } | |
| 743 | - } | |
| 744 | - } | |
| 631 | + /** | |
| 632 | + * Method ignore_plugins_themes() | |
| 633 | + * | |
| 634 | + * Ignore Plugins or Themes. | |
| 635 | + * | |
| 636 | + * @param string $type Plugin or theme. | |
| 637 | + * @param string $slug Plugin or tempheme slug. | |
| 638 | + * @param string $name Plugin or theme name. | |
| 639 | + * @param string $ver Plugin or theme version. | |
| 640 | + * | |
| 641 | + * @return string 'success'. | |
| 642 | + * | |
| 643 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 644 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 645 | + */ | |
| 646 | + public static function ignore_plugins_themes( $type, $slug, $name, $ver = '' ) { //phpcs:ignore -- NOSONAR complex function. | |
| 647 | + $slug = urldecode( $slug ); | |
| 648 | + $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 649 | + if ( 'plugin' === $type ) { | |
| 650 | + $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true ); | |
| 651 | + if ( ! is_array( $decodedIgnoredPlugins ) ) { | |
| 652 | + $decodedIgnoredPlugins = array(); | |
| 653 | + } | |
| 745 | 654 | |
| 746 | - if ( isset( $return_results['result'] ) && is_array( $return_results['result'] ) && ! empty( $return_results['result'] ) ) { | |
| 747 | - $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' ); | |
| 748 | - $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array(); | |
| 749 | - if ( is_array( $decodedPremiumUpgrades ) && ! empty( $decodedPremiumUpgrades ) ) { | |
| 750 | - $updated = false; | |
| 751 | - foreach ( $return_results['result'] as $k => $v ) { | |
| 752 | - $k = rawurldecode( $k ); | |
| 753 | - if ( isset( $decodedPremiumUpgrades[ $k ] ) ) { | |
| 754 | - unset( $decodedPremiumUpgrades[ $k ] ); // updated. | |
| 755 | - $updated = true; | |
| 756 | - } | |
| 757 | - } | |
| 758 | - if ( $updated ) { | |
| 759 | - MainWP_DB::instance()->update_website_option( $website, 'premium_upgrades', wp_json_encode( $decodedPremiumUpgrades ) ); | |
| 760 | - } | |
| 761 | - } | |
| 762 | - } | |
| 763 | - } | |
| 764 | - return $return_results; | |
| 765 | - } elseif ( isset( $result['error'] ) ) { | |
| 766 | - throw new MainWP_Exception( 'WPERROR', esc_html( $result['error'] ) ); | |
| 767 | - } elseif ( isset( $result['notices'] ) ) { | |
| 768 | - $noti = $result['notices']; | |
| 769 | - if ( ! empty( $noti ) && is_string( $noti ) ) { | |
| 770 | - throw new MainWP_Exception( $noti, '', 'MAINWP_NOTICE' ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 771 | - } | |
| 772 | - } | |
| 655 | + $ignored_info = is_array( $decodedIgnoredPlugins ) && isset( $decodedIgnoredPlugins[ $slug ] ) ? $decodedIgnoredPlugins[ $slug ] : array(); | |
| 656 | + if ( ! is_array( $ignored_info ) ) { | |
| 657 | + $ignored_info = array(); | |
| 658 | + } | |
| 773 | 659 | |
| 774 | - if ( $undefined ) { | |
| 775 | - throw new MainWP_Exception( 'ERROR', esc_html__( 'Invalid response retured from the child site. Please try again.', 'mainwp' ) ); | |
| 776 | - } | |
| 777 | - } | |
| 778 | - } | |
| 779 | - throw new MainWP_Exception( 'ERROR', esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ); | |
| 780 | - } | |
| 660 | + $ignored_info['Name'] = urldecode( $name ); | |
| 781 | 661 | |
| 782 | - /** | |
| 783 | - * Method update_plugin_theme_translation() | |
| 784 | - * | |
| 785 | - * Upgrade plugin or theme translations. | |
| 786 | - * | |
| 787 | - * @param int $website Child site object. | |
| 788 | - * @param string $type Plugin or theme. | |
| 789 | - * @param array $list_items List of theme or plugin names seperated by comma. | |
| 790 | - * | |
| 791 | - * @return array|false update result or false. | |
| 792 | - * @throws \Exception Error message. | |
| 793 | - * | |
| 794 | - * @uses \MainWP\Dashboard\MainWP_System_Utility | |
| 795 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 796 | - */ | |
| 797 | - public static function update_plugin_theme_translation( $website, $type, $list_items ) { | |
| 798 | - if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 799 | - /** | |
| 800 | - * Action: mainwp_before_plugin_theme_translation_update | |
| 801 | - * | |
| 802 | - * Fires before plugin/theme/translation update actions. | |
| 803 | - * | |
| 804 | - * @since 4.1 | |
| 805 | - */ | |
| 806 | - do_action( 'mainwp_before_plugin_theme_translation_update', $type, $list_items, $website ); | |
| 662 | + $ignored_vers = is_array( $ignored_info ) && isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array(); | |
| 663 | + if ( ! is_array( $ignored_vers ) ) { | |
| 664 | + $ignored_vers = array(); | |
| 665 | + } | |
| 807 | 666 | |
| 808 | - $information = MainWP_Connect::fetch_url_authed( | |
| 809 | - $website, | |
| 810 | - ( 'translation' === $type ? 'upgradetranslation' : 'upgradeplugintheme' ), | |
| 811 | - array( | |
| 812 | - 'type' => $type, | |
| 813 | - 'list' => urldecode( $list_items ), | |
| 814 | - ), | |
| 815 | - true | |
| 816 | - ); | |
| 817 | - /** | |
| 818 | - * Action: mainwp_after_plugin_theme_translation_update | |
| 819 | - * | |
| 820 | - * Fires before plugin/theme/translation update actions. | |
| 821 | - * | |
| 822 | - * @since 4.1 | |
| 823 | - */ | |
| 824 | - do_action( 'mainwp_after_plugin_theme_translation_update', $information, $type, $list_items, $website ); | |
| 667 | + if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all. | |
| 668 | + $ignored_vers = array( 'all_versions' ); | |
| 669 | + } else { | |
| 670 | + $ver = urldecode( $ver ); | |
| 671 | + if ( ! in_array( $ver, $ignored_vers ) ) { | |
| 672 | + $ignored_vers[] = $ver; | |
| 673 | + } | |
| 674 | + } | |
| 825 | 675 | |
| 826 | - return $information; | |
| 827 | - } | |
| 828 | - return false; | |
| 829 | - } | |
| 676 | + $ignored_info['ignored_versions'] = $ignored_vers; | |
| 677 | + $decodedIgnoredPlugins[ $slug ] = $ignored_info; | |
| 830 | 678 | |
| 831 | - /** | |
| 832 | - * Get plugin or theme slugs. | |
| 833 | - * | |
| 834 | - * @param int $id Child Site ID. | |
| 835 | - * @param string $type plugin|theme. | |
| 836 | - * | |
| 837 | - * @return array List of plugins or themes. | |
| 838 | - * | |
| 839 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 840 | - * @uses \MainWP\Dashboard\MainWP_DB::query() | |
| 841 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 842 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_option() | |
| 843 | - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object() | |
| 844 | - */ | |
| 845 | - public static function get_plugin_theme_slugs( $id, $type ) { // phpcs:ignore -- complex method. Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 679 | + MainWP_DB_Common::instance()->update_user_extension( | |
| 680 | + array( | |
| 681 | + 'userid' => null, | |
| 682 | + 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ), | |
| 683 | + ) | |
| 684 | + ); | |
| 685 | + } elseif ( 'theme' === $type ) { | |
| 686 | + $decodedIgnoredThemes = json_decode( $userExtension->ignored_themes, true ); | |
| 687 | + if ( ! is_array( $decodedIgnoredThemes ) ) { | |
| 688 | + $decodedIgnoredThemes = array(); | |
| 689 | + } | |
| 846 | 690 | |
| 847 | - $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 848 | - $sql = MainWP_DB::instance()->get_sql_website_by_id( $id ); | |
| 849 | - $websites = MainWP_DB::instance()->query( $sql ); | |
| 850 | - $website = MainWP_DB::fetch_object( $websites ); | |
| 691 | + $ignored_info = is_array( $decodedIgnoredThemes ) && isset( $decodedIgnoredThemes[ $slug ] ) ? $decodedIgnoredThemes[ $slug ] : array(); | |
| 692 | + if ( ! is_array( $ignored_info ) ) { | |
| 693 | + $ignored_info = array(); | |
| 694 | + } | |
| 851 | 695 | |
| 852 | - $slugs = array(); | |
| 853 | - if ( 'plugin' === $type ) { | |
| 854 | - if ( $website->is_ignorePluginUpdates ) { | |
| 855 | - return ''; | |
| 856 | - } | |
| 696 | + $ignored_info['Name'] = urldecode( $name ); | |
| 857 | 697 | |
| 858 | - $plugin_upgrades = json_decode( $website->plugin_upgrades, true ); | |
| 859 | - $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' ); | |
| 860 | - $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array(); | |
| 698 | + $ignored_vers = is_array( $ignored_info ) && isset( $ignored_info['ignored_versions'] ) ? $ignored_info['ignored_versions'] : array(); | |
| 699 | + if ( ! is_array( $ignored_vers ) ) { | |
| 700 | + $ignored_vers = array(); | |
| 701 | + } | |
| 702 | + if ( empty( $ver ) || 'all_versions' === $ver ) { // ignore all. | |
| 703 | + $ignored_vers = array( 'all_versions' ); | |
| 704 | + } else { | |
| 705 | + $ver = urldecode( $ver ); | |
| 706 | + if ( ! in_array( $ver, $ignored_vers ) ) { | |
| 707 | + $ignored_vers[] = $ver; | |
| 708 | + } | |
| 709 | + } | |
| 710 | + $ignored_info['ignored_versions'] = $ignored_vers; | |
| 711 | + $decodedIgnoredThemes[ $slug ] = $ignored_info; | |
| 861 | 712 | |
| 862 | - if ( is_array( $decodedPremiumUpgrades ) ) { | |
| 863 | - foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) { | |
| 864 | - $premiumUpgrade['premium'] = true; | |
| 713 | + MainWP_DB_Common::instance()->update_user_extension( | |
| 714 | + array( | |
| 715 | + 'userid' => null, | |
| 716 | + 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ), | |
| 717 | + ) | |
| 718 | + ); | |
| 719 | + } | |
| 865 | 720 | |
| 866 | - if ( 'plugin' === $premiumUpgrade['type'] ) { | |
| 867 | - if ( ! is_array( $plugin_upgrades ) ) { | |
| 868 | - $plugin_upgrades = array(); | |
| 869 | - } | |
| 870 | - $premiumUpgrade = array_filter( $premiumUpgrade ); | |
| 871 | - $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade ); | |
| 872 | - } | |
| 873 | - } | |
| 874 | - } | |
| 721 | + return 'success'; | |
| 722 | + } | |
| 875 | 723 | |
| 876 | - $ignored_plugins = json_decode( $website->ignored_plugins, true ); | |
| 877 | - if ( is_array( $ignored_plugins ) ) { | |
| 878 | - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins ); | |
| 879 | - } | |
| 724 | + /** | |
| 725 | + * Unignore Plugins or Themes. | |
| 726 | + * | |
| 727 | + * @param mixed $type plugin|themes. | |
| 728 | + * @param mixed $slug Plugin or Themes slug. | |
| 729 | + * @param string $ver Plugin or Themes version. | |
| 730 | + * | |
| 731 | + * @return string success. | |
| 732 | + * | |
| 733 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 734 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 735 | + */ | |
| 736 | + public static function unignore_global_plugins_themes( $type, $slug, $ver ) { // phpcs:ignore -- NOSONAR - complex. | |
| 737 | + $slug = urldecode( $slug ); | |
| 738 | + $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 739 | + if ( 'plugin' === $type ) { | |
| 740 | + if ( '_ALL_' === $slug ) { | |
| 741 | + $decodedIgnoredPlugins = array(); | |
| 742 | + } else { | |
| 743 | + $decodedIgnoredPlugins = json_decode( $userExtension->ignored_plugins, true ); | |
| 744 | + if ( ! is_array( $decodedIgnoredPlugins ) ) { | |
| 745 | + $decodedIgnoredPlugins = array(); | |
| 746 | + } | |
| 747 | + if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) { | |
| 748 | + if ( 'all_versions' === $ver ) { | |
| 749 | + unset( $decodedIgnoredPlugins[ $slug ] ); | |
| 750 | + } else { | |
| 751 | + $ignored_vers = is_array( $decodedIgnoredPlugins[ $slug ] ) && isset( $decodedIgnoredPlugins[ $slug ]['ignored_versions'] ) ? $decodedIgnoredPlugins[ $slug ]['ignored_versions'] : array(); | |
| 752 | + if ( is_array( $ignored_vers ) && in_array( $ver, $ignored_vers ) ) { | |
| 753 | + $ignored_vers = array_diff( $ignored_vers, array( $ver ) ); | |
| 754 | + if ( empty( $ignored_vers ) ) { | |
| 755 | + unset( $decodedIgnoredPlugins[ $slug ] ); | |
| 756 | + } else { | |
| 757 | + $decodedIgnoredPlugins[ $slug ]['ignored_versions'] = $ignored_vers; | |
| 758 | + } | |
| 759 | + } | |
| 760 | + } | |
| 761 | + } | |
| 762 | + } | |
| 763 | + MainWP_DB_Common::instance()->update_user_extension( | |
| 764 | + array( | |
| 765 | + 'userid' => null, | |
| 766 | + 'ignored_plugins' => wp_json_encode( $decodedIgnoredPlugins ), | |
| 767 | + ) | |
| 768 | + ); | |
| 769 | + } elseif ( 'theme' === $type ) { | |
| 770 | + if ( '_ALL_' === $slug ) { | |
| 771 | + $decodedIgnoredThemes = array(); | |
| 772 | + } else { | |
| 773 | + $decodedIgnoredThemes = json_decode( $userExtension->ignored_themes, true ); | |
| 774 | + if ( ! is_array( $decodedIgnoredThemes ) ) { | |
| 775 | + $decodedIgnoredThemes = array(); | |
| 776 | + } | |
| 777 | + if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { | |
| 778 | + if ( 'all_versions' === $ver ) { | |
| 779 | + unset( $decodedIgnoredThemes[ $slug ] ); | |
| 780 | + } else { | |
| 781 | + $ignored_vers = is_array( $decodedIgnoredThemes[ $slug ] ) && isset( $decodedIgnoredThemes[ $slug ]['ignored_versions'] ) ? $decodedIgnoredThemes[ $slug ]['ignored_versions'] : array(); | |
| 782 | + if ( is_array( $ignored_vers ) && in_array( $ver, $ignored_vers ) ) { | |
| 783 | + $ignored_vers = array_diff( $ignored_vers, array( $ver ) ); | |
| 784 | + if ( empty( $ignored_vers ) ) { | |
| 785 | + unset( $decodedIgnoredThemes[ $slug ] ); | |
| 786 | + } else { | |
| 787 | + $decodedIgnoredThemes[ $slug ]['ignored_versions'] = $ignored_vers; | |
| 788 | + } | |
| 789 | + } | |
| 790 | + } | |
| 791 | + } | |
| 792 | + } | |
| 793 | + MainWP_DB_Common::instance()->update_user_extension( | |
| 794 | + array( | |
| 795 | + 'userid' => null, | |
| 796 | + 'ignored_themes' => wp_json_encode( $decodedIgnoredThemes ), | |
| 797 | + ) | |
| 798 | + ); | |
| 799 | + } | |
| 880 | 800 | |
| 881 | - $ignored_plugins = json_decode( $userExtension->ignored_plugins, true ); | |
| 882 | - if ( is_array( $ignored_plugins ) ) { | |
| 883 | - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins ); | |
| 884 | - } | |
| 801 | + return 'success'; | |
| 802 | + } | |
| 885 | 803 | |
| 886 | - if ( is_array( $plugin_upgrades ) ) { | |
| 887 | - foreach ( $plugin_upgrades as $slug => $plugin_upgrade ) { | |
| 888 | - $slugs[] = rawurlencode( $slug ); | |
| 889 | - } | |
| 890 | - } | |
| 891 | - } elseif ( 'theme' === $type ) { | |
| 892 | 804 | |
| 893 | - if ( $website->is_ignoreThemeUpdates ) { | |
| 894 | - return ''; | |
| 895 | - } | |
| 805 | + /** | |
| 806 | + * Unignor abandoned plugins or themes. | |
| 807 | + * | |
| 808 | + * @param mixed $type plugin|themes. | |
| 809 | + * @param mixed $slug Plugin or Themes slug. | |
| 810 | + * @param mixed $id Child Site ID. | |
| 811 | + * | |
| 812 | + * @return string success. | |
| 813 | + * | |
| 814 | + * @uses \MainWP\Dashboard\MainWP_DB::query() | |
| 815 | + * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user() | |
| 816 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 817 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_option() | |
| 818 | + * @uses \MainWP\Dashboard\MainWP_DB::update_website_option() | |
| 819 | + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object() | |
| 820 | + * @uses \MainWP\Dashboard\MainWP_DB::free_result() | |
| 821 | + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 822 | + * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 823 | + */ | |
| 824 | + public static function unignore_abandoned_plugin_theme( $type, $slug, $id ) { // phpcs:ignore -- NOSONAR - complex. | |
| 825 | + if ( isset( $id ) ) { | |
| 826 | + if ( '_ALL_' === $id ) { | |
| 827 | + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() ); | |
| 828 | + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { | |
| 829 | + if ( 'plugin' === $type ) { | |
| 830 | + MainWP_DB::instance()->update_website_option( $website, 'plugins_outdate_dismissed', wp_json_encode( array() ) ); | |
| 831 | + } elseif ( 'theme' === $type ) { | |
| 832 | + MainWP_DB::instance()->update_website_option( $website, 'themes_outdate_dismissed', wp_json_encode( array() ) ); | |
| 833 | + } | |
| 834 | + } | |
| 835 | + MainWP_DB::free_result( $websites ); | |
| 836 | + } elseif ( MainWP_Utility::ctype_digit( $id ) ) { | |
| 837 | + $website = MainWP_DB::instance()->get_website_by_id( $id ); | |
| 838 | + if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 839 | + $slug = urldecode( $slug ); | |
| 840 | + if ( 'plugin' === $type ) { | |
| 841 | + $decodedIgnoredPlugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' ); | |
| 842 | + $decodedIgnoredPlugins = ! empty( $decodedIgnoredPlugins ) ? json_decode( $decodedIgnoredPlugins, true ) : array(); | |
| 896 | 843 | |
| 897 | - $theme_upgrades = json_decode( $website->theme_upgrades, true ); | |
| 898 | - $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' ); | |
| 899 | - $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array(); | |
| 844 | + if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) { | |
| 845 | + unset( $decodedIgnoredPlugins[ $slug ] ); | |
| 846 | + MainWP_DB::instance()->update_website_option( $website, 'plugins_outdate_dismissed', wp_json_encode( $decodedIgnoredPlugins ) ); | |
| 847 | + } | |
| 848 | + } elseif ( 'theme' === $type ) { | |
| 849 | + $decodedIgnoredThemes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_dismissed' ); | |
| 850 | + $decodedIgnoredThemes = ! empty( $decodedIgnoredThemes ) ? json_decode( $decodedIgnoredThemes, true ) : array(); | |
| 900 | 851 | |
| 901 | - if ( is_array( $decodedPremiumUpgrades ) ) { | |
| 902 | - foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) { | |
| 903 | - $premiumUpgrade['premium'] = true; | |
| 852 | + if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { | |
| 853 | + unset( $decodedIgnoredThemes[ $slug ] ); | |
| 854 | + MainWP_DB::instance()->update_website_option( $website, 'themes_outdate_dismissed', wp_json_encode( $decodedIgnoredThemes ) ); | |
| 855 | + } | |
| 856 | + } | |
| 857 | + } | |
| 858 | + } | |
| 859 | + } | |
| 904 | 860 | |
| 905 | - if ( 'theme' === $premiumUpgrade['type'] ) { | |
| 906 | - if ( ! is_array( $theme_upgrades ) ) { | |
| 907 | - $theme_upgrades = array(); | |
| 908 | - } | |
| 909 | - $theme_upgrades[ $crrSlug ] = $premiumUpgrade; | |
| 910 | - } | |
| 911 | - } | |
| 912 | - } | |
| 861 | + return 'success'; | |
| 862 | + } | |
| 913 | 863 | |
| 914 | - $ignored_themes = json_decode( $website->ignored_themes, true ); | |
| 915 | - if ( is_array( $ignored_themes ) ) { | |
| 916 | - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes ); | |
| 917 | - } | |
| 918 | 864 | |
| 919 | - $ignored_themes = json_decode( $userExtension->ignored_themes, true ); | |
| 920 | - if ( is_array( $ignored_themes ) ) { | |
| 921 | - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes ); | |
| 922 | - } | |
| 865 | + /** | |
| 866 | + * Unignore abandoned plugins or themes. | |
| 867 | + * | |
| 868 | + * @param mixed $type plugin|theme. | |
| 869 | + * @param mixed $slug Plugin or Themes slug. | |
| 870 | + * | |
| 871 | + * @return string success. | |
| 872 | + * | |
| 873 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 874 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 875 | + */ | |
| 876 | + public static function unignore_abandoned_plugins_themes( $type, $slug ) { // phpcs:ignore -- NOSONAR - complex. | |
| 877 | + $slug = urldecode( $slug ); | |
| 878 | + $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 879 | + if ( 'plugin' === $type ) { | |
| 880 | + if ( '_ALL_' === $slug ) { | |
| 881 | + $decodedIgnoredPlugins = array(); | |
| 882 | + } else { | |
| 883 | + $decodedIgnoredPlugins = json_decode( $userExtension->dismissed_plugins, true ); | |
| 884 | + if ( ! is_array( $decodedIgnoredPlugins ) ) { | |
| 885 | + $decodedIgnoredPlugins = array(); | |
| 886 | + } | |
| 887 | + if ( isset( $decodedIgnoredPlugins[ $slug ] ) ) { | |
| 888 | + unset( $decodedIgnoredPlugins[ $slug ] ); | |
| 889 | + } | |
| 890 | + } | |
| 891 | + MainWP_DB_Common::instance()->update_user_extension( | |
| 892 | + array( | |
| 893 | + 'userid' => null, | |
| 894 | + 'dismissed_plugins' => wp_json_encode( $decodedIgnoredPlugins ), | |
| 895 | + ) | |
| 896 | + ); | |
| 897 | + } elseif ( 'theme' === $type ) { | |
| 898 | + if ( '_ALL_' === $slug ) { | |
| 899 | + $decodedIgnoredThemes = array(); | |
| 900 | + } else { | |
| 901 | + $decodedIgnoredThemes = json_decode( $userExtension->dismissed_themes, true ); | |
| 902 | + if ( ! is_array( $decodedIgnoredThemes ) ) { | |
| 903 | + $decodedIgnoredThemes = array(); | |
| 904 | + } | |
| 905 | + if ( isset( $decodedIgnoredThemes[ $slug ] ) ) { | |
| 906 | + unset( $decodedIgnoredThemes[ $slug ] ); | |
| 907 | + } | |
| 908 | + } | |
| 909 | + MainWP_DB_Common::instance()->update_user_extension( | |
| 910 | + array( | |
| 911 | + 'userid' => null, | |
| 912 | + 'dismissed_themes' => wp_json_encode( $decodedIgnoredThemes ), | |
| 913 | + ) | |
| 914 | + ); | |
| 915 | + } | |
| 923 | 916 | |
| 924 | - if ( is_array( $theme_upgrades ) ) { | |
| 925 | - foreach ( $theme_upgrades as $slug => $theme_upgrade ) { | |
| 926 | - $slugs[] = $slug; | |
| 927 | - } | |
| 928 | - } | |
| 929 | - } elseif ( 'translation' === $type ) { | |
| 930 | - $translation_upgrades = json_decode( $website->translation_upgrades, true ); | |
| 931 | - if ( is_array( $translation_upgrades ) ) { | |
| 932 | - foreach ( $translation_upgrades as $translation_upgrade ) { | |
| 933 | - $slugs[] = $translation_upgrade['slug']; | |
| 934 | - } | |
| 935 | - } | |
| 936 | - } | |
| 917 | + return 'success'; | |
| 918 | + } | |
| 937 | 919 | |
| 938 | - return implode( ',', $slugs ); | |
| 939 | - } | |
| 920 | + /** | |
| 921 | + * Dismis Plugin or Theme. | |
| 922 | + * | |
| 923 | + * @param mixed $type plugin|theme. | |
| 924 | + * @param mixed $slug Plugin or Theme slug. | |
| 925 | + * @param mixed $name Plugin or Theme name. | |
| 926 | + * @param mixed $id Child Site ID. | |
| 927 | + * | |
| 928 | + * @return string success. | |
| 929 | + * | |
| 930 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 931 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_option() | |
| 932 | + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 933 | + * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 934 | + */ | |
| 935 | + public static function dismiss_plugin_theme( $type, $slug, $name, $id ) { // phpcs:ignore -- NOSONAR - complex. | |
| 936 | + if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) { | |
| 937 | + $website = MainWP_DB::instance()->get_website_by_id( $id ); | |
| 938 | + if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 939 | + $slug = urldecode( $slug ); | |
| 940 | + if ( 'plugin' === $type ) { | |
| 941 | + $decodedDismissedPlugins = MainWP_DB::instance()->get_website_option( $website, 'plugins_outdate_dismissed' ); | |
| 942 | + $decodedDismissedPlugins = ! empty( $decodedDismissedPlugins ) ? json_decode( $decodedDismissedPlugins, true ) : array(); | |
| 943 | + | |
| 944 | + if ( ! isset( $decodedDismissedPlugins[ $slug ] ) ) { | |
| 945 | + $decodedDismissedPlugins[ $slug ] = urldecode( $name ); | |
| 946 | + MainWP_DB::instance()->update_website_option( $website, 'plugins_outdate_dismissed', wp_json_encode( $decodedDismissedPlugins ) ); | |
| 947 | + } | |
| 948 | + } elseif ( 'theme' === $type ) { | |
| 949 | + $decodedDismissedThemes = MainWP_DB::instance()->get_website_option( $website, 'themes_outdate_dismissed' ); | |
| 950 | + $decodedDismissedThemes = ! empty( $decodedDismissedThemes ) ? json_decode( $decodedDismissedThemes, true ) : array(); | |
| 951 | + | |
| 952 | + if ( ! isset( $decodedDismissedThemes[ $slug ] ) ) { | |
| 953 | + $decodedDismissedThemes[ $slug ] = urldecode( $name ); | |
| 954 | + MainWP_DB::instance()->update_website_option( $website, 'themes_outdate_dismissed', wp_json_encode( $decodedDismissedThemes ) ); | |
| 955 | + } | |
| 956 | + } | |
| 957 | + } | |
| 958 | + } | |
| 959 | + | |
| 960 | + return 'success'; | |
| 961 | + } | |
| 962 | + | |
| 963 | + /** | |
| 964 | + * Dismiss plugins or themes. | |
| 965 | + * | |
| 966 | + * @param mixed $type plugin|theme. | |
| 967 | + * @param mixed $slug Plugin or Theme slug. | |
| 968 | + * @param mixed $name Plugin or Theme name. | |
| 969 | + * | |
| 970 | + * @return string success. | |
| 971 | + * | |
| 972 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 973 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::update_user_extension() | |
| 974 | + */ | |
| 975 | + public static function dismiss_plugins_themes( $type, $slug, $name ) { | |
| 976 | + $slug = urldecode( $slug ); | |
| 977 | + $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 978 | + if ( 'plugin' === $type ) { | |
| 979 | + $decodedDismissedPlugins = json_decode( $userExtension->dismissed_plugins, true ); | |
| 980 | + if ( ! is_array( $decodedDismissedPlugins ) ) { | |
| 981 | + $decodedDismissedPlugins = array(); | |
| 982 | + } | |
| 983 | + $decodedDismissedPlugins[ $slug ] = urldecode( $name ); | |
| 984 | + MainWP_DB_Common::instance()->update_user_extension( | |
| 985 | + array( | |
| 986 | + 'userid' => null, | |
| 987 | + 'dismissed_plugins' => wp_json_encode( $decodedDismissedPlugins ), | |
| 988 | + ) | |
| 989 | + ); | |
| 990 | + } elseif ( 'theme' === $type ) { | |
| 991 | + $decodedDismissedThemes = json_decode( $userExtension->dismissed_themes, true ); | |
| 992 | + if ( ! is_array( $decodedDismissedThemes ) ) { | |
| 993 | + $decodedDismissedThemes = array(); | |
| 994 | + } | |
| 995 | + $decodedDismissedThemes[ $slug ] = urldecode( $name ); | |
| 996 | + MainWP_DB_Common::instance()->update_user_extension( | |
| 997 | + array( | |
| 998 | + 'userid' => null, | |
| 999 | + 'dismissed_themes' => wp_json_encode( $decodedDismissedThemes ), | |
| 1000 | + ) | |
| 1001 | + ); | |
| 1002 | + } | |
| 1003 | + | |
| 1004 | + return 'success'; | |
| 1005 | + } | |
| 1006 | + | |
| 1007 | + /** | |
| 1008 | + * Method upgrade_plugin_theme_translation() | |
| 1009 | + * | |
| 1010 | + * Upgrade plugin or theme translations. | |
| 1011 | + * | |
| 1012 | + * @param int $id Child site ID. | |
| 1013 | + * @param string $type Plugin or theme. | |
| 1014 | + * @param array $list_items List of theme or plugin names seperated by comma. | |
| 1015 | + * | |
| 1016 | + * @return array | |
| 1017 | + * @throws MainWP_Exception Error messages. | |
| 1018 | + * | |
| 1019 | + * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 1020 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 1021 | + * @uses \MainWP\Dashboard\MainWP_Exception | |
| 1022 | + * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 1023 | + */ | |
| 1024 | + public static function upgrade_plugin_theme_translation( $id, $type, $list_items ) { // phpcs:ignore -- NOSONAR - complex method. | |
| 1025 | + if ( isset( $id ) && MainWP_Utility::ctype_digit( $id ) ) { | |
| 1026 | + $website = MainWP_DB::instance()->get_website_by_id( $id, false, array( 'premium_upgrades', 'rollback_updates_data' ) ); // to fix loading premium_upgrades. | |
| 1027 | + if ( MainWP_System_Utility::is_suspended_site( $website ) ) { | |
| 1028 | + throw new MainWP_Exception( 'ERROR', esc_html__( 'Suspended site.', 'mainwp' ), 'SUSPENDED_SITE' ); | |
| 1029 | + } | |
| 1030 | + | |
| 1031 | + $result = static::update_plugin_theme_translation( $website, $type, $list_items ); | |
| 1032 | + if ( is_array( $result ) ) { | |
| 1033 | + | |
| 1034 | + $return_results = array(); | |
| 1035 | + | |
| 1036 | + // logging feature. | |
| 1037 | + $_type = ''; | |
| 1038 | + if ( 'plugin' === $type || 'theme' === $type ) { | |
| 1039 | + $_type = $type; | |
| 1040 | + } elseif ( 'translation' === $type ) { | |
| 1041 | + $_type = 'trans'; | |
| 1042 | + } | |
| 1043 | + | |
| 1044 | + $undefined = true; | |
| 1045 | + | |
| 1046 | + // Keep this for backward compatibility. | |
| 1047 | + if ( ! empty( $result['upgrades_started'] ) && is_array( $result['upgrades_started'] ) ) { | |
| 1048 | + foreach ( $result['upgrades_started'] as $k => $v ) { | |
| 1049 | + if ( empty( $v ) ) { | |
| 1050 | + $return_results['result_error'][ rawurlencode( $k ) ] = esc_html__( 'Premium action request failed. Please try again later.', 'mainwp' ); | |
| 1051 | + } else { | |
| 1052 | + $return_results['result_started'][ rawurlencode( $k ) ] = esc_html( $v ); | |
| 1053 | + } | |
| 1054 | + } | |
| 1055 | + } | |
| 1056 | + | |
| 1057 | + if ( isset( $result['upgrades_error'] ) ) { | |
| 1058 | + foreach ( $result['upgrades_error'] as $k => $v ) { | |
| 1059 | + $return_results['result_error'][ rawurlencode( $k ) ] = esc_html( $v ); | |
| 1060 | + } | |
| 1061 | + } | |
| 1062 | + | |
| 1063 | + if ( ! empty( $_type ) && isset( $result['other_data'] ) ) { // ok. | |
| 1064 | + $output_array = $result['other_data']; // updated_data: plugins,themes,trans. | |
| 1065 | + mainwp_get_actions_handler_instance()->do_action_mainwp_install_actions( $website, 'updated', $output_array, $_type ); | |
| 1066 | + if ( is_array( $output_array ) ) { | |
| 1067 | + $updated_data = isset( $output_array['updated_data'] ) ? $output_array['updated_data'] : array(); | |
| 1068 | + if ( is_array( $updated_data ) ) { | |
| 1069 | + | |
| 1070 | + $saved_roll_items = ! empty( $website->rollback_updates_data ) ? json_decode( $website->rollback_updates_data, true ) : array(); | |
| 1071 | + if ( ! is_array( $saved_roll_items ) ) { | |
| 1072 | + $saved_roll_items = array(); | |
| 1073 | + } | |
| 1074 | + | |
| 1075 | + $update = false; | |
| 1076 | + foreach ( $updated_data as $item ) { | |
| 1077 | + $version = isset( $item['version'] ) ? $item['version'] : ''; | |
| 1078 | + if ( ! empty( $item ) && isset( $item['slug'] ) && ! empty( $item['rollback'] ) ) { | |
| 1079 | + $msg = MainWP_Updates_Helper::get_roll_msg( $item ); | |
| 1080 | + $return_results['result_error'][ rawurlencode( $item['slug'] ) ] = '[Roll]' . esc_html( $msg ); | |
| 1081 | + | |
| 1082 | + $name = isset( $item['name'] ) ? $item['name'] : ''; | |
| 1083 | + $old_version = isset( $item['old_version'] ) ? $item['old_version'] : ''; | |
| 1084 | + | |
| 1085 | + if ( ! empty( $version ) ) { | |
| 1086 | + if ( ! isset( $saved_roll_items[ $_type ] ) ) { | |
| 1087 | + $saved_roll_items[ $_type ] = array(); | |
| 1088 | + } | |
| 1089 | + | |
| 1090 | + $saved_item = array( | |
| 1091 | + 'name' => $name, | |
| 1092 | + 'old_version' => $old_version, | |
| 1093 | + 'version' => $version, | |
| 1094 | + 'created' => time(), | |
| 1095 | + ); | |
| 1096 | + | |
| 1097 | + if ( ! empty( $item['error'] ) ) { | |
| 1098 | + $saved_item['error'] = $item['error']; | |
| 1099 | + } | |
| 1100 | + | |
| 1101 | + $saved_roll_items[ $_type ][ $item['slug'] ][ $version ] = $saved_item; | |
| 1102 | + $update = true; | |
| 1103 | + } | |
| 1104 | + } elseif ( ! empty( $item ) && ! empty( $item['slug'] ) && ! empty( $item['success'] ) ) { | |
| 1105 | + if ( ! empty( $version ) && isset( $saved_roll_items[ $_type ][ $item['slug'] ][ $version ] ) ) { | |
| 1106 | + unset( $saved_roll_items[ $_type ][ $item['slug'] ][ $version ] ); | |
| 1107 | + $update = true; | |
| 1108 | + } | |
| 1109 | + } | |
| 1110 | + } | |
| 1111 | + if ( $update ) { | |
| 1112 | + MainWP_DB::instance()->update_website_option( $website, 'rollback_updates_data', wp_json_encode( $saved_roll_items ) ); | |
| 1113 | + } | |
| 1114 | + } | |
| 1115 | + } | |
| 1116 | + } | |
| 1117 | + | |
| 1118 | + if ( isset( $result['upgrades'] ) ) { | |
| 1119 | + if ( isset( $result['upgrades'] ) ) { | |
| 1120 | + foreach ( $result['upgrades'] as $k => $v ) { | |
| 1121 | + if ( ! empty( $v ) ) { // updated success. | |
| 1122 | + $return_results['result'][ rawurlencode( $k ) ] = $v; | |
| 1123 | + } | |
| 1124 | + } | |
| 1125 | + } | |
| 1126 | + | |
| 1127 | + if ( 'plugin' === $type ) { | |
| 1128 | + $website = MainWP_DB::instance()->get_website_by_id( $id, false ); // Call new data the before a updated. | |
| 1129 | + if ( ! empty( $website->plugin_upgrades ) ) { | |
| 1130 | + $plugin_upgrades = json_decode( $website->plugin_upgrades, true ); | |
| 1131 | + if ( is_array( $plugin_upgrades ) ) { | |
| 1132 | + $updated = false; | |
| 1133 | + if ( isset( $return_results['result'] ) && is_array( $return_results['result'] ) && ! empty( $return_results['result'] ) ) { | |
| 1134 | + foreach ( $return_results['result'] as $k => $v ) { | |
| 1135 | + $k = rawurldecode( $k ); | |
| 1136 | + if ( isset( $plugin_upgrades[ $k ] ) ) { | |
| 1137 | + unset( $plugin_upgrades[ $k ] ); // updated. | |
| 1138 | + $updated = true; | |
| 1139 | + } | |
| 1140 | + } | |
| 1141 | + } | |
| 1142 | + if ( $updated ) { | |
| 1143 | + MainWP_DB::instance()->update_website_values( $id, array( 'plugin_upgrades' => wp_json_encode( $plugin_upgrades ) ) ); | |
| 1144 | + } | |
| 1145 | + } | |
| 1146 | + } | |
| 1147 | + | |
| 1148 | + if ( isset( $return_results['result'] ) && is_array( $return_results['result'] ) && ! empty( $return_results['result'] ) ) { | |
| 1149 | + $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' ); | |
| 1150 | + $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array(); | |
| 1151 | + if ( is_array( $decodedPremiumUpgrades ) && ! empty( $decodedPremiumUpgrades ) ) { | |
| 1152 | + $updated = false; | |
| 1153 | + foreach ( $return_results['result'] as $k => $v ) { | |
| 1154 | + $k = rawurldecode( $k ); | |
| 1155 | + if ( isset( $decodedPremiumUpgrades[ $k ] ) ) { | |
| 1156 | + unset( $decodedPremiumUpgrades[ $k ] ); // updated. | |
| 1157 | + $updated = true; | |
| 1158 | + } | |
| 1159 | + } | |
| 1160 | + if ( $updated ) { | |
| 1161 | + MainWP_DB::instance()->update_website_option( $website, 'premium_upgrades', wp_json_encode( $decodedPremiumUpgrades ) ); | |
| 1162 | + } | |
| 1163 | + } | |
| 1164 | + } | |
| 1165 | + } | |
| 1166 | + return $return_results; | |
| 1167 | + } elseif ( isset( $result['error'] ) ) { | |
| 1168 | + $error_message = esc_html( $result['error'] ); | |
| 1169 | + | |
| 1170 | + if ( ! empty( $result['http_code'] ) ) { | |
| 1171 | + $error_message .= ' HTTP code: ' . esc_html( $result['http_code'] ) . '.'; | |
| 1172 | + } | |
| 1173 | + | |
| 1174 | + if ( ! empty( $result['rep_error'] ) ) { | |
| 1175 | + $error_message .= ' Connection error: ' . esc_html( $result['rep_error'] ) . '.'; | |
| 1176 | + } | |
| 1177 | + | |
| 1178 | + if ( ! empty( $result['rep_error_code'] ) ) { | |
| 1179 | + $error_message .= ' Error code: ' . esc_html( $result['rep_error_code'] ) . '.'; | |
| 1180 | + } | |
| 1181 | + | |
| 1182 | + throw new MainWP_Exception( 'WPERROR', $error_message ); // phpcs:ignore --NOSONAR - escaped. | |
| 1183 | + | |
| 1184 | + } elseif ( isset( $result['notices'] ) ) { | |
| 1185 | + $noti = $result['notices']; | |
| 1186 | + if ( ! empty( $noti ) && is_string( $noti ) ) { | |
| 1187 | + throw new MainWP_Exception( $noti, '', 'MAINWP_NOTICE' ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 1188 | + } | |
| 1189 | + } | |
| 1190 | + | |
| 1191 | + if ( $undefined ) { | |
| 1192 | + throw new MainWP_Exception( 'ERROR', esc_html__( 'Invalid response retured from the child site. Please try again.', 'mainwp' ) ); | |
| 1193 | + } | |
| 1194 | + } | |
| 1195 | + } | |
| 1196 | + throw new MainWP_Exception( 'ERROR', esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) ); | |
| 1197 | + } | |
| 1198 | + | |
| 1199 | + /** | |
| 1200 | + * Method update_plugin_theme_translation() | |
| 1201 | + * | |
| 1202 | + * Upgrade plugin or theme translations. | |
| 1203 | + * | |
| 1204 | + * @param int $website Child site object. | |
| 1205 | + * @param string $type Plugin or theme. | |
| 1206 | + * @param array $list_items List of theme or plugin names seperated by comma. | |
| 1207 | + * | |
| 1208 | + * @return array|false update result or false. | |
| 1209 | + * @throws \MainWP_Exception Error message. | |
| 1210 | + * | |
| 1211 | + * @uses \MainWP\Dashboard\MainWP_System_Utility | |
| 1212 | + * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 1213 | + */ | |
| 1214 | + public static function update_plugin_theme_translation( $website, $type, $list_items ) { | |
| 1215 | + if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 1216 | + /** | |
| 1217 | + * Action: mainwp_before_plugin_theme_translation_update | |
| 1218 | + * | |
| 1219 | + * Fires before plugin/theme/translation update actions. | |
| 1220 | + * | |
| 1221 | + * @since 4.1 | |
| 1222 | + */ | |
| 1223 | + do_action( 'mainwp_before_plugin_theme_translation_update', $type, $list_items, $website ); | |
| 1224 | + | |
| 1225 | + $information = MainWP_Connect::fetch_url_authed( | |
| 1226 | + $website, | |
| 1227 | + ( 'translation' === $type ? 'upgradetranslation' : 'upgradeplugintheme' ), | |
| 1228 | + array( | |
| 1229 | + 'type' => $type, | |
| 1230 | + 'list' => urldecode( $list_items ), | |
| 1231 | + ), | |
| 1232 | + true | |
| 1233 | + ); | |
| 1234 | + /** | |
| 1235 | + * Action: mainwp_after_plugin_theme_translation_update | |
| 1236 | + * | |
| 1237 | + * Fires before plugin/theme/translation update actions. | |
| 1238 | + * | |
| 1239 | + * @since 4.1 | |
| 1240 | + */ | |
| 1241 | + do_action( 'mainwp_after_plugin_theme_translation_update', $information, $type, $list_items, $website ); | |
| 1242 | + | |
| 1243 | + return $information; | |
| 1244 | + } | |
| 1245 | + return false; | |
| 1246 | + } | |
| 1247 | + | |
| 1248 | + /** | |
| 1249 | + * Get plugin or theme slugs. | |
| 1250 | + * | |
| 1251 | + * @param int $id Child Site ID. | |
| 1252 | + * @param string $type plugin|theme. | |
| 1253 | + * | |
| 1254 | + * @return array List of plugins or themes. | |
| 1255 | + * | |
| 1256 | + * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension() | |
| 1257 | + * @uses \MainWP\Dashboard\MainWP_DB::query() | |
| 1258 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 1259 | + * @uses \MainWP\Dashboard\MainWP_DB::get_website_option() | |
| 1260 | + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object() | |
| 1261 | + */ | |
| 1262 | + public static function get_plugin_theme_slugs( $id, $type ) { // phpcs:ignore -- NOSONAR - complex method. Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 1263 | + | |
| 1264 | + $userExtension = MainWP_DB_Common::instance()->get_user_extension(); | |
| 1265 | + $sql = MainWP_DB::instance()->get_sql_website_by_id( $id ); | |
| 1266 | + $websites = MainWP_DB::instance()->query( $sql ); | |
| 1267 | + $website = MainWP_DB::fetch_object( $websites ); | |
| 1268 | + | |
| 1269 | + $slugs = array(); | |
| 1270 | + if ( 'plugin' === $type ) { | |
| 1271 | + if ( $website->is_ignorePluginUpdates ) { | |
| 1272 | + return ''; | |
| 1273 | + } | |
| 1274 | + | |
| 1275 | + $plugin_upgrades = json_decode( $website->plugin_upgrades, true ); | |
| 1276 | + $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' ); | |
| 1277 | + $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array(); | |
| 1278 | + | |
| 1279 | + if ( is_array( $decodedPremiumUpgrades ) ) { | |
| 1280 | + foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) { | |
| 1281 | + $premiumUpgrade['premium'] = true; | |
| 1282 | + | |
| 1283 | + if ( 'plugin' === $premiumUpgrade['type'] ) { | |
| 1284 | + if ( ! is_array( $plugin_upgrades ) ) { | |
| 1285 | + $plugin_upgrades = array(); | |
| 1286 | + } | |
| 1287 | + $premiumUpgrade = array_filter( $premiumUpgrade ); | |
| 1288 | + $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade ); | |
| 1289 | + } | |
| 1290 | + } | |
| 1291 | + } | |
| 1292 | + | |
| 1293 | + $ignored_plugins = json_decode( $website->ignored_plugins, true ); | |
| 1294 | + if ( is_array( $ignored_plugins ) ) { | |
| 1295 | + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins ); | |
| 1296 | + | |
| 1297 | + } | |
| 1298 | + | |
| 1299 | + $ignored_plugins = json_decode( $userExtension->ignored_plugins, true ); | |
| 1300 | + if ( is_array( $ignored_plugins ) ) { | |
| 1301 | + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins ); | |
| 1302 | + | |
| 1303 | + } | |
| 1304 | + | |
| 1305 | + if ( is_array( $plugin_upgrades ) ) { | |
| 1306 | + foreach ( $plugin_upgrades as $slug => $plugin_upgrade ) { | |
| 1307 | + $slugs[] = rawurlencode( $slug ); | |
| 1308 | + } | |
| 1309 | + } | |
| 1310 | + } elseif ( 'theme' === $type ) { | |
| 1311 | + | |
| 1312 | + if ( $website->is_ignoreThemeUpdates ) { | |
| 1313 | + return ''; | |
| 1314 | + } | |
| 1315 | + | |
| 1316 | + $theme_upgrades = json_decode( $website->theme_upgrades, true ); | |
| 1317 | + $decodedPremiumUpgrades = MainWP_DB::instance()->get_website_option( $website, 'premium_upgrades' ); | |
| 1318 | + $decodedPremiumUpgrades = ! empty( $decodedPremiumUpgrades ) ? json_decode( $decodedPremiumUpgrades, true ) : array(); | |
| 1319 | + | |
| 1320 | + if ( is_array( $decodedPremiumUpgrades ) ) { | |
| 1321 | + foreach ( $decodedPremiumUpgrades as $crrSlug => $premiumUpgrade ) { | |
| 1322 | + $premiumUpgrade['premium'] = true; | |
| 1323 | + | |
| 1324 | + if ( 'theme' === $premiumUpgrade['type'] ) { | |
| 1325 | + if ( ! is_array( $theme_upgrades ) ) { | |
| 1326 | + $theme_upgrades = array(); | |
| 1327 | + } | |
| 1328 | + $theme_upgrades[ $crrSlug ] = $premiumUpgrade; | |
| 1329 | + } | |
| 1330 | + } | |
| 1331 | + } | |
| 1332 | + | |
| 1333 | + $ignored_themes = json_decode( $website->ignored_themes, true ); | |
| 1334 | + if ( is_array( $ignored_themes ) ) { | |
| 1335 | + $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes ); | |
| 1336 | + } | |
| 1337 | + | |
| 1338 | + $ignored_themes = json_decode( $userExtension->ignored_themes, true ); | |
| 1339 | + if ( is_array( $ignored_themes ) ) { | |
| 1340 | + $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes ); | |
| 1341 | + } | |
| 1342 | + | |
| 1343 | + if ( is_array( $theme_upgrades ) ) { | |
| 1344 | + foreach ( $theme_upgrades as $slug => $theme_upgrade ) { | |
| 1345 | + $slugs[] = $slug; | |
| 1346 | + } | |
| 1347 | + } | |
| 1348 | + } elseif ( 'translation' === $type ) { | |
| 1349 | + $translation_upgrades = json_decode( $website->translation_upgrades, true ); | |
| 1350 | + if ( is_array( $translation_upgrades ) ) { | |
| 1351 | + foreach ( $translation_upgrades as $translation_upgrade ) { | |
| 1352 | + $slugs[] = $translation_upgrade['slug']; | |
| 1353 | + } | |
| 1354 | + } | |
| 1355 | + } | |
| 1356 | + | |
| 1357 | + return implode( ',', $slugs ); | |
| 1358 | + } | |
| 940 | 1359 | } |