File: /var/www/html/insiders/wp-load/wp-content/plugins/breadly/settings/user-profile-page.php
<?php
defined( 'GTM_USER_SOCIAL_NETWORKS_KEY' ) || define( 'GTM_USER_SOCIAL_NETWORKS_KEY', 'gtm_user_social_networks' );
add_action( "admin_enqueue_scripts", 'gtm_enqueue_user_profile_page_asset', 10, 1 );
function gtm_enqueue_user_profile_page_asset( $hook_suffix ) {
if ( in_array( $hook_suffix, ['profile.php', 'user-edit.php'] ) ) {
$asset_name = 'user-profile-page';
$asset_js = "../build/$asset_name.js";
$asset_css = "../build/$asset_name.css";
wp_enqueue_script( "gtm-$asset_name", plugins_url( $asset_js, __FILE__ ), ['wp-notices', 'wp-api-fetch', 'wp-i18n', 'wp-components', 'wp-element', 'gtm-block-shared'], GTM_VERSION, true );
wp_enqueue_style( "gtm-$asset_name", plugins_url( $asset_css, __FILE__ ), array_merge( ['wp-components', 'gtm-block-shared-editor-style', 'gtm-block-editor-style'], gtm_get_icon_set_enqueue_handles() ) );
}
}
add_action( 'edit_user_profile', 'gtm_custom_user_profile_fields' ); // For users
add_action( 'show_user_profile', 'gtm_custom_user_profile_fields' ); // For admin user
add_action( 'personal_options_update', 'gtm_save_custom_user_profile_fields' ); // For users
add_action( 'edit_user_profile_update', 'gtm_save_custom_user_profile_fields' ); // For admin user
function gtm_custom_user_profile_fields( $profileuser ) {
$socials = get_user_meta( $profileuser->ID, GTM_USER_SOCIAL_NETWORKS_KEY, true );
wp_localize_script( "gtm-user-profile-page", 'gtm_user_profile_fields', [
'gtm_user_social_networks' => empty( $socials ) ? [] : $socials,
] );
?>
<div id="gtm-user-profile-page-body"></div>
<?php
}
function gtm_save_custom_user_profile_fields( $user_id ) {
if ( current_user_can( 'edit_user', $user_id ) ) {
if ( isset( $_POST['gtm_user_social_networks'] ) ) {
$socials = sanitize_text_field( wp_unslash( $_POST['gtm_user_social_networks'] ) );
$socials = json_decode( $socials, true );
if ( is_array( $socials ) ) {
$validate = rest_validate_value_from_schema( $socials, gtm_user_social_networks_schema() );
if ( true === $validate ) {
update_user_meta( $user_id, GTM_USER_SOCIAL_NETWORKS_KEY, $socials ); // Sanitized
}
}
}
}
}
function gtm_user_social_networks_schema() {
return [
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'gutenmate-user-social-networks',
'type' => 'array',
'default' => [],
'items' => [
'type' => 'object',
'properties' => [
'title' => [
'type' => 'string',
'default' => '',
],
'icon' => [
'type' => 'string',
'default' => '',
],
'link' => [
'type' => 'string',
'default' => '',
],
],
],
'additionalProperties' => false,
];
}
add_action( 'init', 'gtm_register_user_social_networks_fields' );
function gtm_register_user_social_networks_fields() {
register_meta( 'user', GTM_USER_SOCIAL_NETWORKS_KEY, [
'type' => 'array',
'single' => true,
'default' => [],
'show_in_rest' => [
'schema' => gtm_user_social_networks_schema()],
] );
}