plugins ) { $check_premi_plugins = json_decode( $website->plugins, 1 ); } if ( '' !== $website->themes ) { $check_premi_themes = json_decode( $website->themes, 1 ); } } elseif ( 'upgradeplugintheme' === $what ) { $update_type = ( isset( $params['type'] ) ) ? $params['type'] : ''; if ( 'plugin' === $update_type ) { if ( '' !== $website->plugins ) { $check_premi_plugins = json_decode( $website->plugins, 1 ); } } elseif ( 'theme' === $update_type ) { if ( '' !== $website->themes ) { $check_premi_themes = json_decode( $website->themes, 1 ); } } } if ( static::check_premium_updates( $check_premi_plugins, 'plugin' ) ) { static::try_to_detect_premiums_update( $website, 'plugin' ); } if ( static::check_premium_updates( $check_premi_themes, 'theme' ) ) { static::try_to_detect_premiums_update( $website, 'theme' ); } if ( 'upgradeplugintheme' === $what && ( 'plugin' === $update_type || 'theme' === $update_type ) && static::check_request_update_premium( $params['list'], $update_type ) ) { static::request_premiums_update( $website, $update_type, $params['list'] ); $request_update = true; } } return $request_update; } /** * Method check_request_update_premium() * * Check if any updates are on the premiums list. * * @param array $list_items List of updates. * @param string $type Type of update. plugin|theme. * * @return bool true|false. */ public static function check_request_update_premium( $list_items, $type ) { // phpcs:ignore -- NOSONAR - complex. $updates = explode( ',', $list_items ); if ( ! is_array( $updates ) || empty( $updates ) ) { return false; } if ( 1 < count( $updates ) ) { return false; } if ( 'plugin' === $type ) { $update_premiums = array( 'yith-woocommerce-request-a-quote-premium/init.php', ); /** * Filter: mainwp_request_update_premium_plugins * * Filters supported premium plugins to fix compatibility problmes with updating premium plugins. * * @since Unknown */ $update_premiums = apply_filters( 'mainwp_request_update_premium_plugins', $update_premiums ); if ( is_array( $update_premiums ) && ! empty( $update_premiums ) ) { foreach ( $updates as $slug ) { if ( ! empty( $slug ) && in_array( $slug, $update_premiums ) ) { return true; } } } } elseif ( 'theme' === $type ) { $update_premiums = array(); /** * Filter: mainwp_request_update_premium_themes * * Filters supported premium themes to fix compatibility problmes with updating premium themes. * * @since Unknown */ $update_premiums = apply_filters( 'mainwp_request_update_premium_themes', $update_premiums ); if ( is_array( $update_premiums ) && ! empty( $update_premiums ) ) { foreach ( $updates as $slug ) { if ( ! empty( $slug ) && in_array( $slug, $update_premiums ) ) { return true; } } } } return false; } /** * Method redirect_request_site() * * Redirect to requested Site. * * @param mixed $website Child Site. * @param mixed $where_url page to redirerct to. * * @uses \MainWP\Dashboard\MainWP_Connect::get_get_data_authed() * @uses \MainWP\Dashboard\MainWP_Logger::debug() * @uses \MainWP\Dashboard\MainWP_System::$version */ public static function redirect_request_site( $website, $where_url ) { $request_url = MainWP_Connect::get_get_data_authed( $website, $where_url ); $agent = 'Mozilla/5.0 (compatible; MainWP/' . MainWP_System::$version . '; +http://mainwp.com)'; $args = array( 'timeout' => 25, 'httpversion' => '1.1', 'User-Agent' => $agent, ); if ( ! empty( $website->http_user ) && ! empty( $website->http_pass ) ) { $args['headers'] = array( 'Authorization' => 'Basic ' . base64_encode( $website->http_user . ':' . stripslashes( $website->http_pass ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. ); } MainWP_Logger::instance()->debug( ' :: tryRequest :: [website=' . $website->url . ']' ); return wp_remote_get( $request_url, $args ); } /** * Method request_premiums_update() * * Request to update plugin or theme. * * @param mixed $website Child Site to update. * @param mixed $type Type of update, plugin|theme. * @param mixed $list_items list of plugins & themes installed. * * @return mixed null|true. */ public static function request_premiums_update( $website, $type, $list_items ) { if ( 'plugin' === $type ) { $where_url = 'plugins.php?_request_update_premiums_type=plugin&list=' . $list_items; } elseif ( 'theme' === $type ) { $where_url = 'update-core.php?_request_update_premiums_type=theme&list=' . $list_items; } else { return null; } static::redirect_request_site( $website, $where_url ); return true; } /** * Method try_to_detect_premiums_update() * * Try to detect if pugin and themes are premium. * * @param mixed $website Child Site. * @param mixed $type Type of update, plugin|theme. * * @return mixed false|static::redirect_request_site() */ public static function try_to_detect_premiums_update( $website, $type ) { if ( 'plugin' === $type ) { $where_url = 'plugins.php?_detect_plugins_updates=yes'; } elseif ( 'theme' === $type ) { $where_url = 'update-core.php?_detect_themes_updates=yes'; } else { return false; } static::redirect_request_site( $website, $where_url ); } }