| 1 |
<?php |
| 2 |
/** |
| 3 |
* HTTP Error Handler |
| 4 |
* |
| 5 |
* Throw this error when MainWP is not detected |
| 6 |
* due to either an HTTP error or if MainWP Child Plugin is not found. |
| 7 |
* |
| 8 |
* @package MainWP/Dashboard |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace MainWP\Dashboard; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class MainWP Error Helper |
| 15 |
* |
| 16 |
* @return $error |
| 17 |
*/ |
| 18 |
class MainWP_Error_Helper { |
| 19 |
|
| 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(); |
| 31 |
|
| 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 = 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> <i class="external alternate icon"></i>' ); |
| 36 |
} |
| 37 |
|
| 38 |
return $error; |
| 39 |
} |
| 40 |
|
| 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(); |
| 52 |
|
| 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 = 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>' ); |
| 57 |
} elseif ( $pException->getMessage() !== 'WPERROR' && ! empty( $pException->get_message_extra() ) ) { |
| 58 |
$error .= ' - ' . $pException->get_message_extra(); |
| 59 |
} |
| 60 |
|
| 61 |
return $error; |
| 62 |
} |
| 63 |
} |
| 64 |
|