Support » Plugin: Ultimate Member – User Profile, User Registration, Login & Membership Plugin » Is it possible to display user profile in the article he created?

  • Resolved mubiesam

    (@mubiesam)


    trying to include the user profile in every article he created in addition to the user name only, is it possible?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Asif

    (@cryptex_vinci)

    Hi @mubiesam

    You can use this snippet to display User Name, Avatar and other field values. Paste this below your theme signle article template.

    <?php
    
    	$user_id = get_the_author_meta( 'ID' );
    	um_fetch_user($user_id);
    	?>
    
    	<a href="<?php echo esc_url( um_user_profile_url() ); ?>">
            <?php 
            echo get_avatar( um_user( 'ID' ), 60 );
            echo um_user( 'display_name', 'html' ); 
            /* field_key eg: country
            * echo get_user_meta( $user_id, 'field_key', true );
            */  
            ?>
        </a>
        <?php
    }

    Thanks

    Thread Starter mubiesam

    (@mubiesam)

    Hi Asif @cryptex_vinci

    thanks for the help.

    It worked but display under comment area which is not expected.

    I’m using theme Astra

    <div id="primary" <?php astra_primary_class(); ?>>
    
    		<?php astra_primary_content_top(); ?>
    
    		<?php astra_content_loop(); ?>
    
    		<?php astra_primary_content_bottom(); ?>
    
    	</div><!-- #primary -->
    

    Had tried to place the snippet above astra_primary_content_bottom, but it still displayed under comment area.

    Is it possible to have something similar to shortcode [ultimatemember form_id=”34″] but with user profile of article author instead of log-in member above the comment area?

    Thanks

    Asif

    (@cryptex_vinci)

    Hi @mubiesam

    Insert this in your themes functions.php

    <?php
    add_action( 'astra_entry_content_single', 'um_display_user_single_article', 10 );
    
    function um_display_user_single_article(){
    
    	$user_id = get_the_author_meta( 'ID' );
    	um_fetch_user($user_id);
    	?>
    
    	<a href="<?php echo esc_url( um_user_profile_url() ); ?>">
            <?php 
            echo get_avatar( um_user( 'ID' ), 60 );
            echo um_user( 'display_name', 'html' ); 
            /* field_key eg: country
            * echo get_user_meta( $user_id, 'field_key', true );
            */  
            ?>
        </a>
        <?php
    }

    Thanks

    Thread Starter mubiesam

    (@mubiesam)

    Hi Asif @cryptex_vinci

    Added the code in the bottom of Astra themes functions.php , but got error…
    Parse error: syntax error, unexpected ‘<‘, expecting end of file in /opt/bitnami/apps/wordpress/htdocs/wp-content/themes/astra/functions.php on line 161

    Where should I add the code in functions.php?

    <?php
    /**
     * Astra functions and definitions
     *
     * @link https://developer.wordpress.org/themes/basics/theme-functions/
     *
     * @package Astra
     * @since 1.0.0
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly.
    }
    
    /**
     * Define Constants
     */
    define( 'ASTRA_THEME_VERSION', '2.6.2' );
    define( 'ASTRA_THEME_SETTINGS', 'astra-settings' );
    define( 'ASTRA_THEME_DIR', trailingslashit( get_template_directory() ) );
    define( 'ASTRA_THEME_URI', trailingslashit( esc_url( get_template_directory_uri() ) ) );
    
    /**
     * Minimum Version requirement of the Astra Pro addon.
     * This constant will be used to display the notice asking user to update the Astra addon to the version defined below.
     */
    define( 'ASTRA_EXT_MIN_VER', '2.7.0' );
    
    /**
     * Setup helper functions of Astra.
     */
    require_once ASTRA_THEME_DIR . 'inc/core/class-astra-theme-options.php';
    require_once ASTRA_THEME_DIR . 'inc/core/class-theme-strings.php';
    require_once ASTRA_THEME_DIR . 'inc/core/common-functions.php';
    
    /**
     * Update theme
     */
    require_once ASTRA_THEME_DIR . 'inc/theme-update/class-astra-theme-update.php';
    require_once ASTRA_THEME_DIR . 'inc/theme-update/astra-update-functions.php';
    require_once ASTRA_THEME_DIR . 'inc/theme-update/class-astra-theme-background-updater.php';
    require_once ASTRA_THEME_DIR . 'inc/theme-update/class-astra-pb-compatibility.php';
    
    /**
     * Fonts Files
     */
    require_once ASTRA_THEME_DIR . 'inc/customizer/class-astra-font-families.php';
    if ( is_admin() ) {
    	require_once ASTRA_THEME_DIR . 'inc/customizer/class-astra-fonts-data.php';
    }
    
    require_once ASTRA_THEME_DIR . 'inc/customizer/class-astra-fonts.php';
    
    require_once ASTRA_THEME_DIR . 'inc/core/class-astra-walker-page.php';
    require_once ASTRA_THEME_DIR . 'inc/core/class-astra-enqueue-scripts.php';
    require_once ASTRA_THEME_DIR . 'inc/core/class-gutenberg-editor-css.php';
    require_once ASTRA_THEME_DIR . 'inc/class-astra-dynamic-css.php';
    
    /**
     * Custom template tags for this theme.
     */
    require_once ASTRA_THEME_DIR . 'inc/core/class-astra-attr.php';
    require_once ASTRA_THEME_DIR . 'inc/template-tags.php';
    
    require_once ASTRA_THEME_DIR . 'inc/widgets.php';
    require_once ASTRA_THEME_DIR . 'inc/core/theme-hooks.php';
    require_once ASTRA_THEME_DIR . 'inc/admin-functions.php';
    require_once ASTRA_THEME_DIR . 'inc/core/sidebar-manager.php';
    
    /**
     * Markup Functions
     */
    require_once ASTRA_THEME_DIR . 'inc/markup-extras.php';
    require_once ASTRA_THEME_DIR . 'inc/extras.php';
    require_once ASTRA_THEME_DIR . 'inc/blog/blog-config.php';
    require_once ASTRA_THEME_DIR . 'inc/blog/blog.php';
    require_once ASTRA_THEME_DIR . 'inc/blog/single-blog.php';
    /**
     * Markup Files
     */
    require_once ASTRA_THEME_DIR . 'inc/template-parts.php';
    require_once ASTRA_THEME_DIR . 'inc/class-astra-loop.php';
    require_once ASTRA_THEME_DIR . 'inc/class-astra-mobile-header.php';
    
    /**
     * Functions and definitions.
     */
    require_once ASTRA_THEME_DIR . 'inc/class-astra-after-setup-theme.php';
    
    // Required files.
    require_once ASTRA_THEME_DIR . 'inc/core/class-astra-admin-helper.php';
    
    require_once ASTRA_THEME_DIR . 'inc/schema/class-astra-schema.php';
    
    if ( is_admin() ) {
    
    	/**
    	 * Admin Menu Settings
    	 */
    	require_once ASTRA_THEME_DIR . 'inc/core/class-astra-admin-settings.php';
    	require_once ASTRA_THEME_DIR . 'inc/lib/notices/class-astra-notices.php';
    
    	/**
    	 * Metabox additions.
    	 */
    	require_once ASTRA_THEME_DIR . 'inc/metabox/class-astra-meta-boxes.php';
    }
    
    require_once ASTRA_THEME_DIR . 'inc/metabox/class-astra-meta-box-operations.php';
    
    /**
     * Customizer additions.
     */
    require_once ASTRA_THEME_DIR . 'inc/customizer/class-astra-customizer.php';
    
    /**
     * Compatibility
     */
    require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-jetpack.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/woocommerce/class-astra-woocommerce.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/edd/class-astra-edd.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/lifterlms/class-astra-lifterlms.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/learndash/class-astra-learndash.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-beaver-builder.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-bb-ultimate-addon.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-contact-form-7.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-visual-composer.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-site-origin.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-gravity-forms.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-bne-flyout.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-ubermeu.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-divi-builder.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-amp.php';
    require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-yoast-seo.php';
    require_once ASTRA_THEME_DIR . 'inc/addons/transparent-header/class-astra-ext-transparent-header.php';
    require_once ASTRA_THEME_DIR . 'inc/addons/breadcrumbs/class-astra-breadcrumbs.php';
    require_once ASTRA_THEME_DIR . 'inc/addons/heading-colors/class-astra-heading-colors.php';
    
    // Elementor Compatibility requires PHP 5.4 for namespaces.
    if ( version_compare( PHP_VERSION, '5.4', '>=' ) ) {
    	require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-elementor.php';
    	require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-elementor-pro.php';
    }
    
    // Beaver Themer compatibility requires PHP 5.3 for anonymus functions.
    if ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
    	require_once ASTRA_THEME_DIR . 'inc/compatibility/class-astra-beaver-themer.php';
    }
    
    /**
     * Load deprecated functions
     */
    require_once ASTRA_THEME_DIR . 'inc/core/deprecated/deprecated-filters.php';
    require_once ASTRA_THEME_DIR . 'inc/core/deprecated/deprecated-hooks.php';
    require_once ASTRA_THEME_DIR . 'inc/core/deprecated/deprecated-functions.php';
    
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @mubiesam

    You can add the code with the Code Snippets plugin instead:
    https://wordpress.org/plugins/code-snippets/

    Regards,

    Thread Starter mubiesam

    (@mubiesam)

    Hi Asif @cryptex_vinci and Champ Camba @champsupertramp ,

    Thanks for your help. code-snippets is a good help to non-coder like me. It does the job.

    Just one more issue, this snippet will show avatar and display_name on top of article content, is it possible to be at the bottom of content but above comment area. Meanwhile, is it possible to get all the fields like in the [ultimatemember form_id=”34″], especially the article created. (I tried to find field_key in your documents but only Field Types found)

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.