PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / trunk
MainWP Dashboard: Self-hosted WordPress Management for Agencies vtrunk
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-error-helper.php

class-mainwp-error-helper.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies trunk, at class/class-mainwp-error-helper.php

83 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 /**
19 * Class MainWP Error Helper
20 *
21 * @return $error
22 */
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();
36
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 }
42
43 if ( $escape_msg ) {
44 return esc_html( wp_strip_all_tags( $error ) );
45 }
46
47 return $error;
48 }
49
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();
61
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 }
69
70 return $error;
71 }
72
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 }
82 }
83