| @@ -9,64 +9,74 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | namespace MainWP\Dashboard; |
| 12 | 12 | |
| 13 | +// Exit if accessed directly. | |
| 14 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 15 | + exit; | |
| 16 | +} | |
| 17 | + | |
| 13 | 18 | /** |
| 14 | 19 | * Class MainWP Error Helper |
| 15 | 20 | * |
| 16 | 21 | * @return $error |
| 17 | 22 | */ |
| 18 | -class MainWP_Error_Helper { | |
| 23 | +class MainWP_Error_Helper { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 24 | + /** | |
| 25 | + * Method get_error_message() | |
| 26 | + * | |
| 27 | + * Check for http error and or "nomainwp" error. | |
| 28 | + * | |
| 29 | + * @param object $pException Exception object. | |
| 30 | + * @param bool $escape_msg escape message or not. | |
| 31 | + * | |
| 32 | + * @return string $error Error message. | |
| 33 | + */ | |
| 34 | + public static function get_error_message( $pException, $escape_msg = false ) { | |
| 35 | + $error = $pException->getMessage(); | |
| 19 | 36 | |
| 20 | - /** | |
| 21 | - * Method get_error_message() | |
| 22 | - * | |
| 23 | - * Check for http error and or "nomainwp" error. | |
| 24 | - * | |
| 25 | - * @param object $pException Exception object. | |
| 26 | - * | |
| 27 | - * @return string $error Error message. | |
| 28 | - */ | |
| 29 | - public static function get_error_message( $pException ) { | |
| 30 | - $error = $pException->getMessage(); | |
| 37 | + if ( $pException->getMessage() === 'HTTPERROR' ) { | |
| 38 | + $error = 'HTTP error' . ( ! empty( $pException->get_message_extra() ) ? ' - ' . $pException->get_message_extra() : '' ); | |
| 39 | + } elseif ( $pException->getMessage() === 'NOMAINWP' ) { | |
| 40 | + $error = static::get_error_not_detected_connect(); | |
| 41 | + } | |
| 31 | 42 | |
| 32 | - if ( $pException->getMessage() === 'HTTPERROR' ) { | |
| 33 | - $error = 'HTTP error' . ( ! empty( $pException->get_message_extra() ) ? ' - ' . $pException->get_message_extra() : '' ); | |
| 34 | - } elseif ( $pException->getMessage() === 'NOMAINWP' ) { | |
| 35 | - $error = self::get_error_not_detected_connect(); | |
| 36 | - } | |
| 43 | + if ( $escape_msg ) { | |
| 44 | + return esc_html( wp_strip_all_tags( $error ) ); | |
| 45 | + } | |
| 37 | 46 | |
| 38 | - return $error; | |
| 39 | - } | |
| 47 | + return $error; | |
| 48 | + } | |
| 40 | 49 | |
| 41 | - /** | |
| 42 | - * Method get_console_error_message() | |
| 43 | - * | |
| 44 | - * Check for http error and or "nomainwp" and or "WPERROR". | |
| 45 | - * | |
| 46 | - * @param mixed $pException The exception. | |
| 47 | - * | |
| 48 | - * @return string @error Error message. | |
| 49 | - */ | |
| 50 | - public static function get_console_error_message( $pException ) { | |
| 51 | - $error = $pException->getMessage(); | |
| 50 | + /** | |
| 51 | + * Method get_console_error_message() | |
| 52 | + * | |
| 53 | + * Check for http error and or "nomainwp" and or "WPERROR". | |
| 54 | + * | |
| 55 | + * @param mixed $pException The exception. | |
| 56 | + * | |
| 57 | + * @return string @error Error message. | |
| 58 | + */ | |
| 59 | + public static function get_console_error_message( $pException ) { | |
| 60 | + $error = $pException->getMessage(); | |
| 52 | 61 | |
| 53 | - if ( $pException->getMessage() === 'HTTPERROR' ) { | |
| 54 | - $error = 'HTTP error' . ( ! empty( $pException->get_message_extra() ) ? ' - ' . $pException->get_message_extra() : '' ); | |
| 55 | - } elseif ( $pException->getMessage() === 'NOMAINWP' ) { | |
| 56 | - $error = self::get_error_not_detected_connect(); | |
| 57 | - } elseif ( $pException->getMessage() !== 'WPERROR' && ! empty( $pException->get_message_extra() ) ) { | |
| 58 | - $error .= ' - ' . $pException->get_message_extra(); | |
| 59 | - } | |
| 62 | + if ( $pException->getMessage() === 'HTTPERROR' ) { | |
| 63 | + $error = 'HTTP error' . ( ! empty( $pException->get_message_extra() ) ? ' - ' . $pException->get_message_extra() : '' ); | |
| 64 | + } elseif ( $pException->getMessage() === 'NOMAINWP' ) { | |
| 65 | + $error = static::get_error_not_detected_connect(); | |
| 66 | + } elseif ( $pException->getMessage() !== 'WPERROR' && ! empty( $pException->get_message_extra() ) ) { | |
| 67 | + $error .= ' - ' . $pException->get_message_extra(); | |
| 68 | + } | |
| 60 | 69 | |
| 61 | - return $error; | |
| 62 | - } | |
| 70 | + return $error; | |
| 71 | + } | |
| 63 | 72 | |
| 64 | - /** | |
| 65 | - * Method get_error_not_detected_connect() | |
| 66 | - * | |
| 67 | - * @return string @error Error message. | |
| 68 | - */ | |
| 69 | - public static function get_error_not_detected_connect() { | |
| 70 | - return sprintf( esc_html__( 'MainWP Child plugin not detected or could not be reached! Ensure the MainWP Child plugin is installed and activated on the child site, and there are no security rules blocking requests. If you continue experiencing this issue, check the %1$sMainWP Community%2$s for help.', 'mainwp' ), '<a href="https://managers.mainwp.com/c/community-support/5" target="_blank>', '</a>' ); | |
| 71 | - } | |
| 73 | + /** | |
| 74 | + * Method get_error_not_detected_connect() | |
| 75 | + * | |
| 76 | + * @return string @error Error message. | |
| 77 | + */ | |
| 78 | + public static function get_error_not_detected_connect() { | |
| 79 | + /* translators: 1: Opening anchor tag, 2: Closing anchor tag */ | |
| 80 | + return sprintf( esc_html__( 'MainWP Child plugin not detected or could not be reached! Ensure the MainWP Child plugin is installed and activated on the child site, and there are no security rules blocking requests. If you continue experiencing this issue, check the %1$sMainWP Community%2$s for help.', 'mainwp' ), '<a href="https://community.mainwp.com/c/community-support/5" target="_blank">', '</a>' ); | |
| 81 | + } | |
| 72 | 82 | } |