'404 redirect', 'access_denied_redirect' => 'Access denied redirect', 'roles' => 'Roles and capabilities', 'policies' => 'Access policies', ]; /** * Get translated labels for settings groups * * @return array Group keys and labels * @access public * @version 2.0.0 */ public static function labels() { return [ 'not_found_redirect' => __('404 redirect', 'aam-extension-mainwp'), 'access_denied_redirect' => __('Access denied redirect', 'aam-extension-mainwp'), 'roles' => __('Roles and capabilities', 'aam-extension-mainwp'), 'policies' => __('Access policies', 'aam-extension-mainwp'), ]; } /** * Get connected sites available to this extension * * @return array Sites indexed by MainWP site ID * @access public * @version 2.0.0 */ public static function sites() { $enabled = apply_filters('mainwp_extension_enabled_check', MAINWP_AAM_PLUGIN_FILE); $key = is_array($enabled) ? ($enabled['key'] ?? '') : ''; if (!$key) { return []; } $sites = apply_filters('mainwp_getsites', MAINWP_AAM_PLUGIN_FILE, $key, null, false); $result = []; foreach (is_array($sites) ? $sites : [] as $site) { if (!empty($site['id'])) { $result[(int) $site['id']] = $site; } } return $result; } /** * Send an authenticated settings request to a child site * * @param int $site_id MainWP site ID * @param array $request Export, preview, or apply request * @return array Child response or an error * @access public * @version 2.0.0 */ public static function call($site_id, $request) { if (!class_exists('\\MainWP\\Dashboard\\MainWP_Extensions_Handler')) { return ['error' => __('MainWP is unavailable', 'aam-extension-mainwp')]; } $encoded = wp_json_encode($request); if (!is_string($encoded) || strlen($encoded) > 4194304) { return ['error' => __('Settings payload is too large', 'aam-extension-mainwp')]; } $response = \MainWP\Dashboard\MainWP_Extensions_Handler::fetch_url_authed( $site_id, 'extra_execution', ['aam_mainwp_request' => $encoded] ); if (!is_array($response)) { return ['error' => __('Child site did not return a valid response', 'aam-extension-mainwp')]; } if (!empty($response['error'])) { return ['error' => (string) $response['error']]; } if (empty($response['aam_mainwp']) || !is_array($response['aam_mainwp'])) { return ['error' => __('Install this extension alongside AAM 8 and MainWP Child on this site', 'aam-extension-mainwp')]; } return $response['aam_mainwp']; } /** * Calculate a fingerprint for a settings snapshot * * @param array $snapshot Settings snapshot * @return string SHA-256 fingerprint * @access public * @version 2.0.0 */ public static function fingerprint($snapshot) { return hash('sha256', wp_json_encode($snapshot)); } }