get( 'Version' ) ); } add_action( 'wp_enqueue_scripts', 'ansico_wp_theme_enqueue_assets' ); if ( ! function_exists( 'ansico_author_intro_shortcode' ) ) { function ansico_author_intro_shortcode() { if ( ! is_author() ) { return ''; } $author = get_queried_object(); if ( ! $author || empty( $author->ID ) ) { return ''; } $author_id = (int) $author->ID; $name = get_the_author_meta( 'display_name', $author_id ); $description = get_the_author_meta( 'description', $author_id ); $user_url = get_the_author_meta( 'user_url', $author_id ); $avatar = function_exists( 'ansico_get_author_avatar_html' ) ? ansico_get_author_avatar_html( $author_id, 120, esc_attr( $name ) ) : get_avatar( $author_id, 120, '', esc_attr( $name ), array( 'class' => 'ansico-author-intro__avatar-image' ) ); $output = '
'; $output .= '
' . $avatar . '
'; $output .= '
'; $output .= '

' . esc_html( $name ) . '

'; if ( ! empty( $description ) ) { $output .= '
' . wpautop( wp_kses_post( $description ) ) . '
'; } if ( ! empty( $user_url ) ) { $output .= '

' . esc_html( $user_url ) . '

'; } $output .= '
'; return $output; } } add_shortcode( 'ansico_author_intro', 'ansico_author_intro_shortcode' ); if ( ! function_exists( 'ansico_get_social_networks_v2' ) ) { function ansico_get_social_networks_v2() { return array( 'facebook' => array( 'label' => 'Facebook', 'icon' => 'f' ), 'linkedin' => array( 'label' => 'LinkedIn', 'icon' => 'in' ), 'instagram' => array( 'label' => 'Instagram', 'icon' => '◎' ), 'bluesky' => array( 'label' => 'Bluesky', 'icon' => '☁' ), 'twitter' => array( 'label' => 'Twitter/X', 'icon' => '𝕏' ), 'mastodon' => array( 'label' => 'Mastodon', 'icon' => 'm' ), 'friendica' => array( 'label' => 'Friendica', 'icon' => 'F' ), 'reddit' => array( 'label' => 'Reddit', 'icon' => 'r' ), ); } } if ( ! function_exists( 'ansico_format_profile_url_for_display_v2' ) ) { function ansico_format_profile_url_for_display_v2( $url ) { $url = trim( (string) $url ); $url = preg_replace( '#^https?://#i', '', $url ); return untrailingslashit( $url ); } } if ( ! function_exists( 'ansico_get_author_social_links_v2' ) ) { function ansico_get_author_social_links_v2( $author_id ) { $networks = ansico_get_social_networks_v2(); $output = ''; foreach ( $networks as $key => $network ) { $url = get_user_meta( $author_id, 'ansico_' . $key, true ); $show = get_user_meta( $author_id, 'ansico_show_' . $key, true ); if ( empty( $url ) || '1' !== (string) $show ) { continue; } $output .= ''; $output .= ''; $output .= '' . esc_html( $network['label'] ) . ''; $output .= ''; } if ( empty( $output ) ) { return ''; } return '
' . $output . '
'; } } if ( ! function_exists( 'ansico_author_intro_shortcode_v2' ) ) { function ansico_author_intro_shortcode_v2() { if ( ! is_author() ) { return ''; } $author = get_queried_object(); if ( ! $author || empty( $author->ID ) ) { return ''; } $author_id = (int) $author->ID; $name = get_the_author_meta( 'display_name', $author_id ); $description = get_the_author_meta( 'description', $author_id ); $user_url = get_the_author_meta( 'user_url', $author_id ); $avatar = function_exists( 'ansico_get_author_avatar_html' ) ? ansico_get_author_avatar_html( $author_id, 120, esc_attr( $name ) ) : get_avatar( $author_id, 120, '', esc_attr( $name ), array( 'class' => 'ansico-author-intro__avatar-image' ) ); $socials = ansico_get_author_social_links_v2( $author_id ); $output = '
'; $output .= '
' . $avatar . '
'; $output .= '
'; $output .= '

' . esc_html( $name ) . '

'; if ( ! empty( $description ) ) { $output .= '
' . wpautop( wp_kses_post( $description ) ) . '
'; } if ( ! empty( $user_url ) ) { $output .= '

' . esc_html( ansico_format_profile_url_for_display_v2( $user_url ) ) . '

'; } $output .= $socials; $output .= '
'; return $output; } add_shortcode( 'ansico_author_intro_v2', 'ansico_author_intro_shortcode_v2' ); } if ( ! function_exists( 'ansico_get_author_avatar_html' ) ) { function ansico_get_author_avatar_html( $author_id, $size = 120, $alt = '' ) { $custom_avatar_id = (int) get_user_meta( $author_id, 'ansico_custom_avatar_id', true ); if ( $custom_avatar_id ) { $image = wp_get_attachment_image( $custom_avatar_id, array( $size, $size ), false, array( 'class' => 'ansico-author-intro__avatar-image', 'alt' => $alt, ) ); if ( $image ) { return $image; } } return get_avatar( $author_id, $size, '', $alt, array( 'class' => 'ansico-author-intro__avatar-image', ) ); } } if ( ! function_exists( 'ansico_enqueue_profile_media' ) ) { function ansico_enqueue_profile_media( $hook_suffix ) { if ( 'profile.php' !== $hook_suffix && 'user-edit.php' !== $hook_suffix ) { return; } wp_enqueue_media(); $handle = 'ansico-profile-media'; wp_register_script( $handle, '', array( 'jquery' ), null, true ); wp_enqueue_script( $handle ); $script = " jQuery(function($){ var frame; $(document).on('click', '.ansico-upload-avatar-button', function(e){ e.preventDefault(); var button = $(this); var container = button.closest('.ansico-custom-avatar-field'); if (frame) { frame.open(); return; } frame = wp.media({ title: '" . esc_js( __( 'Select profile image', 'ansico' ) ) . "', button: { text: '" . esc_js( __( 'Use this image', 'ansico' ) ) . "' }, multiple: false }); frame.on('select', function(){ var attachment = frame.state().get('selection').first().toJSON(); container.find('.ansico-custom-avatar-id').val(attachment.id); container.find('.ansico-custom-avatar-preview').html('\"\"'); }); frame.open(); }); $(document).on('click', '.ansico-remove-avatar-button', function(e){ e.preventDefault(); var container = $(this).closest('.ansico-custom-avatar-field'); container.find('.ansico-custom-avatar-id').val(''); container.find('.ansico-custom-avatar-preview').empty(); }); }); "; wp_add_inline_script( $handle, $script ); } add_action( 'admin_enqueue_scripts', 'ansico_enqueue_profile_media' ); } if ( ! function_exists( 'ansico_render_profile_extensions' ) ) { function ansico_render_profile_extensions( $user ) { $networks = function_exists( 'ansico_get_social_networks_v2' ) ? ansico_get_social_networks_v2() : array(); $custom_avatar_id = (int) get_user_meta( $user->ID, 'ansico_custom_avatar_id', true ); $preview_image = $custom_avatar_id ? wp_get_attachment_image( $custom_avatar_id, array( 96, 96 ), false, array( 'style' => 'width:96px;height:96px;border-radius:999px;object-fit:cover;display:block;' ) ) : ''; ?> $network ) : ?> $network ) { $url_key = 'ansico_' . $key; $show_key = 'ansico_show_' . $key; if ( isset( $_POST[ $url_key ] ) ) { update_user_meta( $user_id, $url_key, esc_url_raw( wp_unslash( $_POST[ $url_key ] ) ) ); } update_user_meta( $user_id, $show_key, isset( $_POST[ $show_key ] ) ? '1' : '0' ); } } add_action( 'personal_options_update', 'ansico_save_profile_extensions', 99 ); add_action( 'edit_user_profile_update', 'ansico_save_profile_extensions', 99 ); } if ( ! function_exists( 'ansico_filter_author_avatar_shortcode_v2' ) ) { function ansico_filter_author_avatar_shortcode_v2( $output ) { if ( ! is_author() ) { return $output; } $author = get_queried_object(); if ( ! $author || empty( $author->ID ) ) { return $output; } $name = get_the_author_meta( 'display_name', (int) $author->ID ); $avatar = ansico_get_author_avatar_html( (int) $author->ID, 120, $name ); $output = preg_replace( '#
.*?
#s', '
' . $avatar . '
', $output, 1 ); return $output; } add_filter( 'do_shortcode_tag', function( $output, $tag, $attr ) { if ( 'ansico_author_intro_v2' === $tag && function_exists( 'ansico_filter_author_avatar_shortcode_v2' ) ) { return ansico_filter_author_avatar_shortcode_v2( $output ); } return $output; }, 10, 3 ); } if ( ! function_exists( 'ansico_hide_legacy_contact_methods' ) ) { function ansico_hide_legacy_contact_methods( $methods ) { $legacy_keys = array( 'facebook', 'linkedin', 'instagram', 'bluesky', 'twitter', 'mastodon', 'friendica', 'reddit', ); foreach ( $legacy_keys as $key ) { if ( isset( $methods[ $key ] ) ) { unset( $methods[ $key ] ); } } return $methods; } } add_filter( 'user_contactmethods', 'ansico_hide_legacy_contact_methods', 9999 );