[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: user-data.php
<?php namespace Elementor; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class User_Data { const API_NAMESPACE = 'elementor/v1'; const API_BASE = '/user-data/current-user'; public static function init() { add_action( 'rest_api_init', fn() => self::register_routes() ); } private static function register_routes() { register_rest_route( self::API_NAMESPACE, self::API_BASE, [ [ 'methods' => 'GET', 'callback' => fn( $request ) => self::route_wrapper( fn() => self::get_current_user( $request ) ), 'permission_callback' => fn() => is_user_logged_in(), ], [ 'methods' => 'PATCH', 'callback' => fn( $request ) => self::route_wrapper( fn() => self::update_current_user( $request ) ), 'permission_callback' => fn() => is_user_logged_in(), 'args' => [ 'suppressedMessages' => [ 'required' => false, 'type' => 'array', 'description' => 'Array of suppressed message keys', 'items' => [ 'type' => 'string', ], 'validate_callback' => function( $param, $request, $key ) { return is_array( $param ); }, 'sanitize_callback' => fn( $param, $request, $key ) => self::sanitize_suppressed_messages( $param, $request, $key ), ], ], ], ] ); } /** * @param \WP_REST_Request $request The request object. * @return \WP_REST_Response|\WP_Error Response object or error. */ public static function get_current_user( $request ) { $current_user = wp_get_current_user(); $introduction_meta = User::get_introduction_meta(); $suppressed_messages = []; if ( is_array( $introduction_meta ) ) { foreach ( $introduction_meta as $key => $value ) { if ( $value ) { $suppressed_messages[] = $key; } } } $capabilities = array_keys( $current_user->allcaps ); $data = [ 'suppressedMessages' => $suppressed_messages, 'capabilities' => $capabilities, ]; return new \WP_REST_Response( $data, 200 ); } /** * @param \WP_REST_Request $request The request object. * @return \WP_REST_Response|\WP_Error Response object or error. */ public static function update_current_user( $request ) { $user_id = get_current_user_id(); $suppressed_messages = $request->get_param( 'suppressedMessages' ); if ( $request->has_param( 'suppressedMessages' ) && is_array( $suppressed_messages ) ) { $introduction_meta = []; foreach ( $suppressed_messages as $message ) { $introduction_meta[ $message ] = true; } update_user_meta( $user_id, User::INTRODUCTION_KEY, $introduction_meta ); } return self::get_current_user( $request ); } /** * @param array $param The parameter value. * @param \WP_REST_Request $request The request object. * @param string $key The parameter key. * * @return array|null The sanitized array or null. */ public static function sanitize_suppressed_messages( $param, $request, $key ) { if ( ! is_array( $param ) ) { return null; } $sanitized_messages = []; foreach ( $param as $message ) { if ( is_string( $message ) ) { $sanitized_message = sanitize_text_field( $message ); if ( ! empty( $sanitized_message ) ) { $sanitized_messages[] = $sanitized_message; } } } return $sanitized_messages; } private static function route_wrapper( callable $cb ) { try { $response = $cb(); } catch ( \Exception $e ) { return new \WP_Error( 'unexpected_error', 'Something went wrong', [ 'status' => 500 ] ); } return $response; } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.69 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002