ultimatemember / Extended

All custom extended features and codes
16 stars 13 forks source link

User Meta Shortcodes #78

Open MissVeronica opened 6 months ago

MissVeronica commented 6 months ago

Describe the bug User Meta Shortcodes user_id parameter is not set by um_profile_id() when user_id is empty in the shortcode.

UM Support Forum issue https://wordpress.org/support/topic/unable-to-get-user-info/

Versions Tested both version 1.0.0 included in UM Extended 2.0.4 and version 1.0.1 in the old ZIP file format.

MissVeronica commented 1 month ago

This statement in source code is WRONG

Usage [um_user user_id="" meta_key="" ] // leave user_id empty if you want to retrive the current user's meta value.

Correct statement is

Usage [um_user meta_key="any_meta_key" ] //remove user_id if you want to retrieve the current user's meta value.

Make this clear in the documentation too. Users are using [um_user user_id="" meta_key="birth_date"] which will not give desired results.

UM Support Forum issue https://wordpress.org/support/topic/display-custom-field-8/

MissVeronica commented 1 month ago

Addition of 'um_user' in the parameter list will allow for usage of the WP filter hook "shortcode_atts_{$shortcode}"

    public function shortcode( $atts ) {

        $atts = shortcode_atts(
            array(
                'user_id'  => um_profile_id(),
                'meta_key' => '', //phpcs:ignore
            ),
            $atts,
            'um_user'
        );
        /**
         * Filters shortcode attributes.
         *
         * If the third parameter of the shortcode_atts() function is present then this filter is available.
         * The third parameter, $shortcode, is the name of the shortcode.
         *
         * @since 3.6.0
         * @since 4.4.0 Added the `$shortcode` parameter.
         *
         * @param array  $out       The output array of shortcode attributes.
         * @param array  $pairs     The supported attributes and their defaults.
         * @param array  $atts      The user defined shortcode attributes.
         * @param string $shortcode The shortcode name.
         */
        $out = apply_filters( "shortcode_atts_{$shortcode}", $out, $pairs, $atts, $shortcode );