| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- class Simple_Author_Box_User_Profile {
- function __construct() {
- // Social Links
- add_action( 'show_user_profile', array( $this, 'add_social_area' ) );
- add_action( 'edit_user_profile', array( $this, 'add_social_area' ) );
- // Custom Profile Image
- add_action( 'show_user_profile', array( $this, 'add_profile_image' ), 9, 1 );
- add_action( 'edit_user_profile', array( $this, 'add_profile_image' ), 9, 1 );
- add_action( 'personal_options_update', array( $this, 'save_user_profile' ) );
- add_action( 'edit_user_profile_update', array( $this, 'save_user_profile' ) );
- // Allow HTML in user description.
- remove_filter( 'pre_user_description', 'wp_filter_kses' );
- add_filter( 'pre_user_description', 'wp_kses_post' );
- }
- public function add_social_area( $profileuser ) {
- $user_id = $profileuser->data->ID;
- $social_links = Simple_Author_Box_Helper::get_user_social_links( $user_id );
- $social_icons = apply_filters( 'sabox_social_icons', Simple_Author_Box_Helper::$social_icons );
- unset( $social_icons['user_email'] );
- ?>
- <div class="sab-user-profile-wrapper">
- <h2><?php _e( 'Social Media Links (Simple Author Box)', 'saboxplugin' ); ?></h2>
- <table class="form-table" id="sabox-social-table">
- <?php
- if ( ! empty( $social_links ) ) {
- foreach ( $social_links as $social_platform => $social_link ) {
- ?>
- <tr>
- <th>
- <span class="sabox-drag"></span>
- <select name="sabox-social-icons[]">
- <?php foreach ( $social_icons as $sabox_social_id => $sabox_social_name ) { ?>
- <option value="<?php echo $sabox_social_id; ?>" <?php selected( $sabox_social_id, $social_platform ); ?>><?php echo $sabox_social_name; ?></option>
- <?php } ?>
- </select>
- </th>
- <td>
- <input name="sabox-social-links[]" type="text" class="regular-text" value="<?php echo esc_url( $social_link ); ?>">
- <span class="dashicons dashicons-trash"></span>
- <td>
- </tr>
- <?php
- }
- } else {
- ?>
- <tr>
- <th>
- <span class="sabox-drag"></span>
- <select name="sabox-social-icons[]">
- <?php foreach ( $social_icons as $sabox_social_id => $sabox_social_name ) { ?>
- <option value="<?php echo $sabox_social_id; ?>"><?php echo $sabox_social_name; ?></option>
- <?php } ?>
- </select>
- </th>
- <td>
- <input name="sabox-social-links[]" type="text" class="regular-text" value="">
- <span class="dashicons dashicons-trash"></span>
- <td>
- </tr>
- <?php
- }
- ?>
- </table>
- <div class="sabox-add-social-link">
- <a href="#" class="button button-primary button-hero"></span><?php esc_html_e( '+ Add new social platform', 'saboxplugin' ); ?></a>
- </div>
- </div>
- <?php
- }
- public function add_profile_image( $user ) {
- if ( ! current_user_can( 'upload_files' ) ) {
- return;
- }
- $default_url = SIMPLE_AUTHOR_BOX_ASSETS . 'img/default.png';
- $image = get_user_meta( $user->ID, 'sabox-profile-image', true );
- ?>
- <div id="sabox-custom-profile-image">
- <h3><?php _e( 'Custom User Profile Image (Simple Author Box)', 'saboxplugin' ); ?></h3>
- <table class="form-table">
- <tr>
- <th><label for="cupp_meta"><?php _e( 'Profile Image', 'saboxplugin' ); ?></label></th>
- <td>
- <div id="sab-current-image">
- <?php wp_nonce_field( 'sabox-profile-image', 'sabox-profile-nonce' ); ?>
- <img data-default="<?php echo esc_url_raw( $default_url ); ?>" src="<?php echo '' != $image ? esc_url_raw( $image ) : esc_url_raw( $default_url ); ?>"><br>
- <input type="text" name="sabox-custom-image" id="sabox-custom-image" class="regular-text" value="<?php echo esc_attr( $image ); ?>">
- </div>
- <div class="actions">
- <a href="#" class="button-secondary" id="sabox-remove-image"><?php _e( 'Remove Image', 'saboxplugin' ); ?></a>
- <a href="#" class="button-primary" id="sabox-add-image"><?php _e( 'Upload Image', 'saboxplugin' ); ?></a>
- </div>
- </td>
- </tr>
- </table>
- </div>
- <?php
- }
- public function save_user_profile( $user_id ) {
- if ( isset( $_POST['sabox-social-icons'] ) && isset( $_POST['sabox-social-links'] ) ) {
- $social_platforms = apply_filters( 'sabox_social_icons', Simple_Author_Box_Helper::$social_icons );
- $social_links = array();
- foreach ( $_POST['sabox-social-links'] as $index => $social_link ) {
- if ( $social_link ) {
- $social_platform = isset( $_POST['sabox-social-icons'][ $index ] ) ? $_POST['sabox-social-icons'][ $index ] : false;
- if ( $social_platform && isset( $social_platforms[ $social_platform ] ) ) {
- $social_links[ $social_platform ] = esc_url_raw( $social_link );
- }
- }
- }
- update_user_meta( $user_id, 'sabox_social_links', $social_links );
- } else {
- delete_user_meta( $user_id, 'sabox_social_links' );
- }
- if ( ! isset( $_POST['sabox-profile-nonce'] ) || ! wp_verify_nonce( $_POST['sabox-profile-nonce'], 'sabox-profile-image' ) ) {
- return;
- }
- if ( ! current_user_can( 'upload_files', $user_id ) ) {
- return;
- }
- if ( isset( $_POST['sabox-custom-image'] ) && '' != $_POST['sabox-custom-image'] ) {
- update_user_meta( $user_id, 'sabox-profile-image', esc_url_raw( $_POST['sabox-custom-image'] ) );
- } else {
- delete_user_meta( $user_id, 'sabox-profile-image' );
- }
- }
- }
- new Simple_Author_Box_User_Profile();
|