__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
namespace Automattic\WooCommerce\Internal\Admin;
/**
* WCAdminUser Class.
*/
class WCAdminUser {
/**
* Class instance.
*
* @var WCAdminUser instance
*/
protected static $instance = null;
/**
* Constructor.
*/
public function __construct() {
add_action( 'rest_api_init', array( $this, 'register_user_data' ) );
}
/**
* Get class instance.
*
* @return object Instance.
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Registers WooCommerce specific user data to the WordPress user API.
*/
public function register_user_data() {
register_rest_field(
'user',
'is_super_admin',
array(
'get_callback' => function( $user ) {
if ( ! isset( $user['id'] ) || 0 === $user['id'] ) {
return false;
}
return is_super_admin( $user['id'] );
},
'schema' => null,
)
);
register_rest_field(
'user',
'woocommerce_meta',
array(
'get_callback' => array( $this, 'get_user_data_values' ),
'update_callback' => array( $this, 'update_user_data_values' ),
'schema' => null,
)
);
}
/**
* For all the registered user data fields ( Loader::get_user_data_fields ), fetch the data
* for returning via the REST API.
*
* @param WP_User $user Current user.
*/
public function get_user_data_values( $user ) {
$values = array();
foreach ( $this->get_user_data_fields() as $field ) {
$values[ $field ] = self::get_user_data_field( $user['id'], $field );
}
return $values;
}
/**
* For all the registered user data fields ( Loader::get_user_data_fields ), update the data
* for the REST API.
*
* @param array $values The new values for the meta.
* @param WP_User $user The current user.
* @param string $field_id The field id for the user meta.
*/
public function update_user_data_values( $values, $user, $field_id ) {
if ( empty( $values ) || ! is_array( $values ) || 'woocommerce_meta' !== $field_id ) {
return;
}
$fields = $this->get_user_data_fields();
$updates = array();
foreach ( $values as $field => $value ) {
if ( in_array( $field, $fields, true ) ) {
$updates[ $field ] = $value;
self::update_user_data_field( $user->ID, $field, $value );
}
}
return $updates;
}
/**
* We store some WooCommerce specific user meta attached to users endpoint,
* so that we can track certain preferences or values such as the inbox activity panel last open time.
* Additional fields can be added in the function below, and then used via wc-admin's currentUser data.
*
* @return array Fields to expose over the WP user endpoint.
*/
public function get_user_data_fields() {
/**
* Filter user data fields exposed over the WordPress user endpoint.
*
* @since 4.0.0
* @param array $fields Array of fields to expose over the WP user endpoint.
*/
return apply_filters( 'woocommerce_admin_get_user_data_fields', array( 'variable_product_tour_shown' ) );
}
/**
* Helper to update user data fields.
*
* @param int $user_id User ID.
* @param string $field Field name.
* @param mixed $value Field value.
*/
public static function update_user_data_field( $user_id, $field, $value ) {
update_user_meta( $user_id, 'woocommerce_admin_' . $field, $value );
}
/**
* Helper to retrieve user data fields.
*
* Migrates old key prefixes as well.
*
* @param int $user_id User ID.
* @param string $field Field name.
* @return mixed The user field value.
*/
public static function get_user_data_field( $user_id, $field ) {
$meta_value = get_user_meta( $user_id, 'woocommerce_admin_' . $field, true );
// Migrate old meta values (prefix changed from `wc_admin_` to `woocommerce_admin_`).
if ( '' === $meta_value ) {
$old_meta_value = get_user_meta( $user_id, 'wc_admin_' . $field, true );
if ( '' !== $old_meta_value ) {
self::update_user_data_field( $user_id, $field, $old_meta_value );
delete_user_meta( $user_id, 'wc_admin_' . $field );
$meta_value = $old_meta_value;
}
}
return $meta_value;
}
/**
* Get the current user data.
*
* @return array User data.
*/
public static function get_user_data() {
$user_controller = new \WP_REST_Users_Controller();
$request = new \WP_REST_Request();
$request->set_query_params( array( 'context' => 'edit' ) );
$user_response = $user_controller->get_current_item( $request );
$current_user_data = is_wp_error( $user_response ) ? (object) array() : $user_response->get_data();
$current_user_data = self::filter_user_capabilities( $current_user_data );
return $current_user_data;
}
/**
* Filter user capabilities to respect file modification restrictions.
*
* @param array $user_data User data.
* @return array Filtered user data.
*/
private static function filter_user_capabilities( $user_data ) {
if ( ! is_array( $user_data ) || ! isset( $user_data['capabilities'] ) ) {
return $user_data;
}
// If the user has install_plugins capability, check if file modifications are allowed.
if ( isset( $user_data['capabilities']->install_plugins ) && $user_data['capabilities']->install_plugins ) {
$user_data['capabilities']->install_plugins = wp_is_file_mod_allowed( 'woocommerce' );
}
return $user_data;
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| Agentic | Folder | 0775 |
|
|
| BlockTemplates | Folder | 0775 |
|
|
| EmailImprovements | Folder | 0775 |
|
|
| EmailPreview | Folder | 0775 |
|
|
| Emails | Folder | 0775 |
|
|
| ImportExport | Folder | 0775 |
|
|
| Logging | Folder | 0775 |
|
|
| Marketing | Folder | 0775 |
|
|
| Notes | Folder | 0775 |
|
|
| Onboarding | Folder | 0775 |
|
|
| Orders | Folder | 0775 |
|
|
| ProductForm | Folder | 0775 |
|
|
| ProductReviews | Folder | 0775 |
|
|
| RemoteFreeExtensions | Folder | 0775 |
|
|
| Schedulers | Folder | 0775 |
|
|
| Settings | Folder | 0775 |
|
|
| Suggestions | Folder | 0775 |
|
|
| WCPayPromotion | Folder | 0775 |
|
|
| ActivityPanels.php | File | 1.58 KB | 0664 |
|
| Analytics.php | File | 11.73 KB | 0664 |
|
| CategoryLookup.php | File | 7.99 KB | 0664 |
|
| Coupons.php | File | 2.86 KB | 0664 |
|
| CouponsMovedTrait.php | File | 2.15 KB | 0664 |
|
| CustomerEffortScoreTracks.php | File | 17.65 KB | 0664 |
|
| Events.php | File | 8.56 KB | 0664 |
|
| FeaturePlugin.php | File | 6.53 KB | 0664 |
|
| Homescreen.php | File | 8.65 KB | 0664 |
|
| Loader.php | File | 19.18 KB | 0664 |
|
| Marketing.php | File | 6.29 KB | 0664 |
|
| Marketplace.php | File | 3.89 KB | 0664 |
|
| MobileAppBanner.php | File | 956 B | 0664 |
|
| RemoteInboxNotifications.php | File | 932 B | 0664 |
|
| Settings.php | File | 13.25 KB | 0664 |
|
| ShippingLabelBanner.php | File | 4.67 KB | 0664 |
|
| ShippingLabelBannerDisplayRules.php | File | 3.63 KB | 0664 |
|
| SiteHealth.php | File | 2.31 KB | 0664 |
|
| Survey.php | File | 768 B | 0664 |
|
| SystemStatusReport.php | File | 5.85 KB | 0664 |
|
| Translations.php | File | 11.66 KB | 0664 |
|
| WCAdminAssets.php | File | 17.58 KB | 0664 |
|
| WCAdminSharedSettings.php | File | 2.08 KB | 0664 |
|
| WCAdminUser.php | File | 5.26 KB | 0664 |
|
| WcPayWelcomePage.php | File | 6.33 KB | 0664 |
|