• Resolved markburton52

    (@markburton52)


    I’ve tried this snippet which allows you to embed a UM user profile in a WP post or page.

    I’d like to do the same but display a link to the profile rather than the profile itself on the page.

    I assume this is a simple change to the return statement(s) at the end, but can’t see how to do it.

    Has anyone done this or is able to suggest the solution?

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 23 total)
  • @markburton52

    You can use these code lines for your EM code snippets

    $user_profile_url = um_user_profile_url( $user_id ); 
    echo '<div>' . esc_url( $user_profile_url ) . '</div>';
    Thread Starter markburton52

    (@markburton52)

    Thanks. I’m not sure where that goes. Here’s my attempt at modifying the snippet to embed the profile via shortcode so it returns a link. I’m not confident in php and it doesn’t work.

    /**
    * Sample usage: [um_link_profile user_id="123" form_id="3"]
    */
    add_shortcode("um_link_profile","um_082321_link_specific_profile");
    function um_082321_link_specific_profile( $atts ){

    $atts = shortcode_atts( array(
    'user_id' => get_current_user_id(),
    'form_id' => 0,
    ), $atts );
    extract( $atts );
    UM()->user()->target_id = $user_id;
    $user_profile_url = um_user_profile_url( $user_id );
    echo '&lt;div&gt;' . esc_url( $user_profile_url ) . '&lt;/div&gt;';
    }

    @markburton52

    Here you have a shortcode for Profile links

    add_shortcode( 'um_profile_link', 'um_profile_link_shortcode' );
    function um_profile_link_shortcode( $atts, $content ) {
    
    // shortcode [um_profile_link user_id="2"]title text[/um_profile_link]
    // user_id empty for current profile page user_id
    // title text optional
    
        if ( ! class_exists( 'UM' )) {
            return '';
        }
    
        if ( ! isset( $atts['user_id'] ) || empty( $atts['user_id'] )) {
            $atts['user_id'] = um_profile_id();
        }
    
        $user_id = absint( $atts['user_id'] );
        if ( empty( $user_id ) ) {
            return '';
        }
    
        $user_profile_url = um_user_profile_url( $user_id );
    
        return '<a href="' . esc_url( $user_profile_url ) . '" title="' . esc_attr( $content ) . '">Link to profile</a>';
    }
    Thread Starter markburton52

    (@markburton52)

    Thanks – it is just giving me the shortcode entered:

    [um_profile_link user_id=”NNN″]title text [/um_profile_link]

    (where ‘NNN’ is the user id that I used)

    @markburton52

    OK, I am working on a new shortcode plugin, which includes all your current shortcodes to make your site easier to setup and support.
    The user ID will be entered via a WP filter from your EM pages.

    Thread Starter markburton52

    (@markburton52)

    Thank you, that’s very kind.

    @markburton52

    The UM User Meta shortcode will be included also.
    I have included support for video links also.

    @markburton52

    Now you can download the first version of the “Shortcode Profile Info” plugin.

    https://github.com/MissVeronica/um-shortcode-profile-info

    Thread Starter markburton52

    (@markburton52)

    Thanks. I’ve tried it and you can see the results on this page.

    It all worked for me except for the user profile link which delivered the logged in user’s profile, not the user specified via user id. I didn’t try the video version.

    It would also be good if it were possible to put a field’s content into the link text in the URL versions. E.g. the last test on my page delivers the artist’s performance name – having that link to their profile would save a few steps for me. I know that you can’t usually nest shortcodes within one another.

    It’s going to be a great resource and I’ll acknowledge your work when we implement it on the live site.

    @markburton52

    Thanks for your feedback.

    It all worked for me except for the user profile link which delivered the logged in user’s profile, not the user specified via user id

    I have tested the profile link and it’s ok at my site.
    Link to the logged in user’s profile is the UM default if user_id is missing.

    to put a field’s content into the link text in the URL versions

    Yes will be done in the next version of the plugin.

    @markburton52

    Now available for download an updated “Shortcode Profile Info” plugin.

    Version 1.1.0 Addition of: text_meta_key=”key_name”. Fix for user_id in type=”profile_link”. WP Users table fields included in meta_key selections.

    Version 1.2.0 Addition of $atts in the filter. Fix for the filter function.

    https://github.com/MissVeronica/um-shortcode-profile-info

    • This reply was modified 2 months, 2 weeks ago by missveronica.
    Thread Starter markburton52

    (@markburton52)

    Thanks – that is all working properly now for me (I haven’t tried the video version).

    @markburton52

    Do you have the user_id available from the “Events Manager” plugin
    to insert in the “Shortcode Profile Info” plugin’s user_id filter?

    Plugin Support yuriinalivaiko

    (@yuriinalivaiko)

    Hello @markburton52

    You can use the [um_author_profile_link] shortcode to display a profile link. This shortcode displays a link to the post author by default but you can use the user_id attribute to display a link to any custom profile. See details here: User Profile URL.

    Regards

    @markburton52

    Thanks! @yuriinalivaiko

    Using this UM coding from the UM [um_author_profile_link] shortcode in the “Shortcode Profile Info” plugin’s filter function, you will get the artist’s user_id for all plugin Types.

    add_filter( 'um_profile_info_shortcode', 'um_profile_info_shortcode_userid', 10, 3 );
    function um_profile_info_shortcode_userid( $user_id, $type, $atts ) {
        $default_user_id = 0;
        if ( is_singular() ) {
            $default_user_id = get_post()->post_author;
        } elseif ( is_author() ) {
            $default_user_id = get_the_author_meta( 'ID' );
        }
        return $default_user_id;
    }
Viewing 15 replies - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.