| @@ -6,107 +6,155 @@ | ||
| 6 | 6 | * |
| 7 | 7 | * @package MainWP/Dashboard |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | +// Exit if accessed directly. | |
| 11 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | + exit; | |
| 13 | +} | |
| 14 | + | |
| 10 | 15 | if ( ! defined( 'FILTER_SANITIZE_STRING_COMPATIBLE' ) ) { // to compatible. |
| 11 | - define( 'FILTER_SANITIZE_STRING_COMPATIBLE', 513 ); | |
| 16 | + define( 'FILTER_SANITIZE_STRING_COMPATIBLE', 513 ); | |
| 12 | 17 | } |
| 13 | 18 | |
| 14 | 19 | if ( ! function_exists( 'mainwpdir' ) ) { |
| 15 | 20 | |
| 16 | - /** | |
| 17 | - * Grab MainWP Directory | |
| 18 | - * | |
| 19 | - * @return string | |
| 20 | - */ | |
| 21 | - function mainwpdir() { | |
| 22 | - return WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . dirname( plugin_basename( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR; | |
| 23 | - } | |
| 21 | + /** | |
| 22 | + * Grab MainWP Directory | |
| 23 | + * | |
| 24 | + * @return string | |
| 25 | + */ | |
| 26 | + function mainwpdir() { | |
| 27 | + return WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . dirname( plugin_basename( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR; | |
| 28 | + } | |
| 24 | 29 | } |
| 25 | 30 | |
| 26 | 31 | |
| 27 | -if ( ! function_exists( 'mainwp_do_not_have_permissions' ) ) { | |
| 32 | +if ( ! function_exists( '\mainwp_do_not_have_permissions' ) ) { | |
| 28 | 33 | |
| 29 | - /** | |
| 30 | - * Detect permission level & display message to end user. | |
| 31 | - * | |
| 32 | - * @param string $where User's location. | |
| 33 | - * @param bool $echo_out Defines weather or not to echo error message. | |
| 34 | - * @return string|bool $msg|false | |
| 35 | - */ | |
| 36 | - function mainwp_do_not_have_permissions( $where = '', $echo_out = true ) { | |
| 37 | - $msg = sprintf( esc_html__( 'You do not have sufficient permissions to access this page (%s).', 'mainwp' ), ucwords( $where ) ); | |
| 38 | - if ( $echo_out ) { | |
| 39 | - echo '<div class="mainwp-permission-error"><p>' . esc_html( $msg ) . '</p>If you need access to this page please contact the dashboard administrator.</div>'; | |
| 40 | - } else { | |
| 41 | - return $msg; | |
| 42 | - } | |
| 34 | + /** | |
| 35 | + * Detect permission level & display message to end user. | |
| 36 | + * | |
| 37 | + * @param string $where User's location. | |
| 38 | + * @param bool $echo_out Defines weather or not to echo error message. | |
| 39 | + * @return string|bool $msg|false | |
| 40 | + */ | |
| 41 | + function mainwp_do_not_have_permissions( $where = '', $echo_out = true ) { | |
| 42 | + /* translators: %s: Page or section name where access was denied */ | |
| 43 | + $msg = sprintf( esc_html__( 'You do not have sufficient permissions to access this page (%s).', 'mainwp' ), ucwords( $where ) ); | |
| 44 | + if ( $echo_out ) { | |
| 45 | + echo '<div class="mainwp-permission-error"><p>' . esc_html( $msg ) . '</p>If you need access to this page please contact the dashboard administrator.</div>'; | |
| 46 | + } else { | |
| 47 | + return $msg; | |
| 48 | + } | |
| 43 | 49 | |
| 44 | - return false; | |
| 45 | - } | |
| 50 | + return false; | |
| 51 | + } | |
| 46 | 52 | } |
| 47 | 53 | |
| 48 | 54 | if ( ! function_exists( 'mainwp_current_user_can' ) ) { |
| 49 | 55 | |
| 50 | - /** | |
| 51 | - * Check permission level. | |
| 52 | - * | |
| 53 | - * To compatible with extensions. | |
| 54 | - * | |
| 55 | - * @param string $cap_type Group or type of capabilities. | |
| 56 | - * @param string $cap Capabilities for current user. | |
| 57 | - * | |
| 58 | - * @return bool true|false | |
| 59 | - */ | |
| 60 | - function mainwp_current_user_can( $cap_type = '', $cap = '' ) { | |
| 61 | - if ( function_exists( 'MainWP\Dashboard\mainwp_current_user_have_right' ) ) { | |
| 62 | - return MainWP\Dashboard\mainwp_current_user_have_right( $cap_type, $cap ); | |
| 63 | - } | |
| 64 | - return true; | |
| 65 | - } | |
| 56 | + /** | |
| 57 | + * Check permission level. | |
| 58 | + * | |
| 59 | + * To compatible with extensions. | |
| 60 | + * | |
| 61 | + * @param string $cap_type Group or type of capabilities. | |
| 62 | + * @param string $cap Capabilities for current user. | |
| 63 | + * | |
| 64 | + * @return bool true|false | |
| 65 | + */ | |
| 66 | + function mainwp_current_user_can( $cap_type = '', $cap = '' ) { | |
| 67 | + if ( function_exists( 'MainWP\Dashboard\mainwp_current_user_have_right' ) ) { | |
| 68 | + return MainWP\Dashboard\mainwp_current_user_have_right( $cap_type, $cap ); | |
| 69 | + } | |
| 70 | + return true; | |
| 71 | + } | |
| 66 | 72 | } |
| 67 | 73 | |
| 68 | 74 | if ( ! function_exists( 'mainwp_get_actions_handler_instance' ) ) { |
| 69 | 75 | |
| 70 | - /** | |
| 71 | - * Function to get mainwp actions handler instance. | |
| 72 | - * | |
| 73 | - * @return bool true|false | |
| 74 | - */ | |
| 75 | - function mainwp_get_actions_handler_instance() { | |
| 76 | - return \MainWP\Dashboard\MainWP_Actions_Handler::instance(); | |
| 77 | - } | |
| 76 | + /** | |
| 77 | + * Function to get mainwp actions handler instance. | |
| 78 | + * | |
| 79 | + * @return bool true|false | |
| 80 | + */ | |
| 81 | + function mainwp_get_actions_handler_instance() { | |
| 82 | + return \MainWP\Dashboard\MainWP_Actions_Handler::instance(); | |
| 83 | + } | |
| 78 | 84 | } |
| 79 | 85 | |
| 80 | 86 | if ( ! function_exists( 'mainwp_send_json_output' ) ) { |
| 81 | - /** | |
| 82 | - * Handle send json output. | |
| 83 | - * | |
| 84 | - * @param array $output Array output. | |
| 85 | - */ | |
| 86 | - function mainwp_send_json_output( $output ) { | |
| 87 | - if ( is_array( $output ) ) { | |
| 88 | - $output['execute_time'] = \MainWP\Dashboard\MainWP_Execution_Helper::instance()->get_exec_time(); | |
| 89 | - } | |
| 90 | - wp_send_json( $output ); | |
| 91 | - } | |
| 87 | + /** | |
| 88 | + * Handle send json output. | |
| 89 | + * | |
| 90 | + * @param array $output Array output. | |
| 91 | + */ | |
| 92 | + function mainwp_send_json_output( $output ) { | |
| 93 | + if ( is_array( $output ) ) { | |
| 94 | + $output['execute_time'] = \MainWP\Dashboard\MainWP_Execution_Helper::get_run_time(); | |
| 95 | + } | |
| 96 | + wp_send_json( $output ); | |
| 97 | + } | |
| 92 | 98 | } |
| 93 | 99 | |
| 94 | 100 | |
| 95 | 101 | if ( ! function_exists( 'mainwp_modules_is_enabled' ) ) { |
| 96 | 102 | |
| 97 | - /** | |
| 98 | - * Check if module is enable. | |
| 99 | - * | |
| 100 | - * @param string $module module slug. | |
| 101 | - * | |
| 102 | - * @return bool true|false | |
| 103 | - */ | |
| 104 | - function mainwp_modules_is_enabled( $module ) { | |
| 105 | - $enable_mainwp_modules = array( | |
| 106 | - 'logs' => defined( 'MAINWP_MODULE_LOG_ENABLED' ) && MAINWP_MODULE_LOG_ENABLED ? true : false, | |
| 107 | - 'cost-tracker' => defined( 'MAINWP_MODULE_COST_TRACKER_ENABLED' ) && MAINWP_MODULE_COST_TRACKER_ENABLED ? true : false, | |
| 108 | - 'api-backups' => defined( 'MAINWP_MODULE_API_BACKUPS_ENABLED' ) && MAINWP_MODULE_API_BACKUPS_ENABLED ? true : false, | |
| 109 | - ); | |
| 110 | - return ! empty( $enable_mainwp_modules[ $module ] ) ? true : false; | |
| 111 | - } | |
| 103 | + /** | |
| 104 | + * Check if module is enable. | |
| 105 | + * | |
| 106 | + * @param string $module module slug. | |
| 107 | + * | |
| 108 | + * @return bool true|false | |
| 109 | + */ | |
| 110 | + function mainwp_modules_is_enabled( $module ) { | |
| 111 | + $enable_mainwp_modules = array( | |
| 112 | + 'logs' => defined( 'MAINWP_MODULE_LOG_ENABLED' ) && MAINWP_MODULE_LOG_ENABLED ? true : false, | |
| 113 | + 'cost-tracker' => defined( 'MAINWP_MODULE_COST_TRACKER_ENABLED' ) && MAINWP_MODULE_COST_TRACKER_ENABLED ? true : false, | |
| 114 | + 'api-backups' => defined( 'MAINWP_MODULE_API_BACKUPS_ENABLED' ) && MAINWP_MODULE_API_BACKUPS_ENABLED ? true : false, | |
| 115 | + ); | |
| 116 | + return ! empty( $enable_mainwp_modules[ $module ] ) ? true : false; | |
| 117 | + } | |
| 118 | +} | |
| 119 | + | |
| 120 | +if ( ! function_exists( 'mainwp_get_timestamp' ) ) { | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Function mainwp_get_timestamp. | |
| 124 | + * | |
| 125 | + * @param int $add_time add time. | |
| 126 | + * @return int | |
| 127 | + */ | |
| 128 | + function mainwp_get_timestamp( $add_time = 0 ) { | |
| 129 | + return (int) $add_time + (int) \MainWP\Dashboard\MainWP_Utility::get_timestamp(); | |
| 130 | + } | |
| 131 | + | |
| 132 | + | |
| 133 | +} | |
| 134 | + | |
| 135 | +if ( ! function_exists( 'mainwp_get_current_utc_datetime_db' ) ) { | |
| 136 | + /** | |
| 137 | + * Function mainwp_get_current_utc_datetime_db. | |
| 138 | + * | |
| 139 | + * @param bool $get_db_datetime To get db datetime. | |
| 140 | + * | |
| 141 | + * @return int | |
| 142 | + */ | |
| 143 | + function mainwp_get_current_utc_datetime_db( $get_db_datetime = true ) { | |
| 144 | + $utcTime = new \DateTime( 'now', new \DateTimeZone( 'UTC' ) ); | |
| 145 | + return $get_db_datetime ? $utcTime->format( 'Y-m-d H:i:s' ) : $utcTime->getTimestamp(); // Outputs: YYYY-MM-DD HH:MM:SS. | |
| 146 | + } | |
| 147 | +} | |
| 148 | + | |
| 149 | +if ( ! function_exists( 'mainwp_secure_request' ) ) { | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * Function mainwp_secure_request. | |
| 153 | + * | |
| 154 | + * @param string $action request action. | |
| 155 | + * @return void | |
| 156 | + */ | |
| 157 | + function mainwp_secure_request( $action ) { | |
| 158 | + \MainWP\Dashboard\MainWP_Post_Handler::instance()->secure_request( $action ); | |
| 159 | + } | |
| 112 | 160 | } |