Wp User Frontend Shortcodes

Below, you’ll find a detailed guide on how to add the Wp User Frontend Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Wp User Frontend Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Wp User Frontend Plugin and the shortcodes it provides:

Plugin Icon
WP User Frontend – Registration, User Profile, Membership, Content Restriction, User Directory, and Frontend Post Submission Plugin

"WP User Frontend is a comprehensive plugin that provides user registration, profile creation, membership management, content restriction, user directory, and frontend post submission capabilities."

★★★★✩ (476) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [wpuf_account]
  • [wpuf_sub_info]
  • [wpuf_sub_pack]
  • [wpuf_form]
  • [wpuf_edit]
  • [wpuf-login]
  • [wpuf-registration]
  • [wpuf-edit-users]
  • [wpuf-meta]

Wp User Frontend [wpuf_account] Shortcode

The WP User Frontend shortcode ‘wpuf_account’ is designed to manage user account sections. It checks if the user is logged in, fetches the active tab, and initiates the account sections. It then identifies the current section based on the user’s request. If the user is not logged in, an unauthorized message is displayed. The function ends by returning the content.

Shortcode: [wpuf_account]

Examples and Usage

Basic example – Displays the user account section if the user is logged in, otherwise, it shows an unauthorized message.

[wpuf_account]

PHP Function Code

In case you have difficulties debugging what causing issues with [wpuf_account] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wpuf_account', [ $this, 'shortcode' ] );

Shortcode PHP function:

function shortcode( $atts ) {
        //phpcs:ignore
        extract( shortcode_atts( [], $atts ) );

        ob_start();

        if ( is_user_logged_in() ) {
            $default_active_tab = wpuf_get_option( 'account_page_active_tab', 'wpuf_my_account', 'dashboard' );
            $section            = isset( $_REQUEST['section'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ) : $default_active_tab;
            $sections           = wpuf_get_account_sections();
            $current_section    = [];

            foreach ( $sections as $slug => $label ) {
                if ( $section === $slug ) {
                    $current_section = $slug;
                    break;
                }
            }

            wpuf_load_template(
                'account.php', [
                    'sections' => $sections,
                    'current_section' => $current_section,
                ]
            );
        } else {
            $message = wpuf_get_option( 'un_auth_msg', 'wpuf_dashboard' );
            wpuf_load_template( 'unauthorized.php', [ 'message' => $message ] );
        }

        $content = ob_get_contents();
        ob_end_clean();

        return $content;
    }

Code file location:

wp-user-frontend/wp-user-frontend/class/frontend-account.php

Wp User Frontend [wpuf_sub_info] Shortcode

The WP User Frontend shortcode ‘wpuf_sub_info’ retrieves the subscription information for the user. It fetches the user’s account sections and triggers the ‘wpuf_account_content_subscription’ action.

Shortcode: [wpuf_sub_info]

Examples and Usage

Basic example – A simple usage of the shortcode to display subscription information.

[wpuf_sub_info /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wpuf_sub_info] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wpuf_sub_info', [ $this, 'subscription_info' ] );

Shortcode PHP function:

function subscription_info() {
        // _deprecated_function( __FUNCTION__, '2.6.0', 'wpuf_get_user()->subscription()->pack_info( $form_id );' );
        // wpuf_get_user()->subscription()->pack_info( $form_id );
        $sections = wpuf_get_account_sections();
        do_action( 'wpuf_account_content_subscription', $sections, 'subscription' );
    }

Code file location:

wp-user-frontend/wp-user-frontend/class/subscription.php

Wp User Frontend [wpuf_sub_pack] Shortcode

The WP User Frontend shortcode is used to manage subscription packs. It fetches subscription details, checks the user’s current pack, and provides options to cancel. It also handles subscription-related messages and actions, ensuring a seamless user experience.

Shortcode: [wpuf_sub_pack]

Parameters

Here is a list of all possible wpuf_sub_pack shortcode parameters and attributes:

  • include – IDs of the subscription packs to include
  • exclude – IDs of the subscription packs to exclude
  • order – Sorting order of the subscription packs, ‘ASC’ or ‘DESC’
  • orderby – Parameter to sort the subscription packs by

Examples and Usage

Basic Example – Displays the subscription packs available in ascending order.

[wpuf_sub_pack order="ASC" /]

Advanced Examples

Displays subscription packs in a specific order as per the IDs provided in the ‘include’ attribute. The ‘include’ attribute takes a comma-separated list of subscription pack IDs.

[wpuf_sub_pack include="1,2,3" /]

Excludes certain subscription packs from being displayed using the ‘exclude’ attribute. The ‘exclude’ attribute takes a comma-separated list of subscription pack IDs.

[wpuf_sub_pack exclude="4,5" /]

Displays subscription packs in a specific order based on the ‘orderby’ attribute. The ‘orderby’ attribute can take values such as ‘title’, ‘date’, ‘ID’, etc. In this example, the packs are ordered by their title in ascending order.

[wpuf_sub_pack orderby="title" order="ASC" /]

Combining multiple attributes to display subscription packs in a specific order, excluding certain packs, and ordering them by their title.

[wpuf_sub_pack include="1,2,3" exclude="4,5" orderby="title" order="ASC" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wpuf_sub_pack] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wpuf_sub_pack', [ $this, 'subscription_packs' ] );

Shortcode PHP function:

function subscription_packs( $atts = null ) {
        //$cost_per_post = isset( $form_settings['pay_per_post_cost'] ) ? $form_settings['pay_per_post_cost'] : 0;

        $action   = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
        $pack_msg = isset( $_GET['pack_msg'] ) ? sanitize_text_field( wp_unslash( $_GET['pack_msg'] ) ) : '';
        $ppp_msg  = isset( $_GET['ppp_msg'] ) ? sanitize_text_field( wp_unslash( $_GET['ppp_msg'] ) ) : '';

        $defaults = [
            'include' => '',
            'exclude' => '',
            'order'   => '',
            'orderby' => '',
        ];

        $arranged = [];
        $args     = wp_parse_args( $atts, $defaults );

        if ( $args['include'] !== '' ) {
            $pack_order = explode( ',', $args['include'] );
        } else {
            $args['order'] = isset( $args['order'] ) ? $args['order'] : 'ASC';
        }

        $packs = $this->get_subscriptions( $args );

        $details_meta = $this->get_details_meta_value();

        ob_start();

        if ( $action === 'wpuf_paypal_success' ) {
            printf( '<h1>%1$s</h1><p>%2$s</p>', esc_html( __( 'Payment is complete', 'wp-user-frontend' ) ), esc_html( __( 'Congratulations, your payment has been completed!', 'wp-user-frontend' ) ) );
        }

        if ( $pack_msg === 'buy_pack' ) {
            esc_html_e( 'Please buy a subscription pack to post', 'wp-user-frontend' );
        }

        if ( $ppp_msg === 'pay_per_post' ) {
            esc_html_e( 'Please buy a subscription pack to post', 'wp-user-frontend' );
        }

        $current_pack = self::get_user_pack( get_current_user_id() );

        if (
            isset( $current_pack['pack_id'] ) &&
            ! empty( $current_pack['pack_id'] ) &&
            isset( $current_pack['status'] ) &&
            $current_pack['status'] === 'completed'
         ) {
            global $wpdb;

            $user_id         = get_current_user_id();
            $payment_gateway = $wpdb->get_var( $wpdb->prepare( "SELECT payment_type FROM {$wpdb->prefix}wpuf_transaction WHERE user_id = %s AND status = 'completed' ORDER BY created DESC", $user_id ) );

            $payment_gateway = strtolower( $payment_gateway );
            ?>

            <?php echo wp_kses_post( __( '<p><i>You have a subscription pack activated. </i></p>', 'wp-user-frontend' ) ); ?>
            <?php /* translators: %s: pack title */ ?>
            <?php echo sprintf( wp_kses_post( __( '<p><i>Pack name: %s </i></p>', 'wp-user-frontend' ) ), esc_html( get_the_title( $current_pack['pack_id'] ) ) ); ?>

            <?php echo '<p><i>' . esc_html__( 'To cancel the pack, press the following cancel button', 'wp-user-frontend' ) . '</i></p>'; ?>

            <form action="" id="wpuf_cancel_subscription" method="post">
                <?php wp_nonce_field( 'wpuf-sub-cancel' ); ?>
                <input type="hidden" name="user_id" value="<?php echo esc_attr( get_current_user_id() ); ?>">
                <input type="hidden" name="gateway" value="<?php echo esc_attr( $payment_gateway ); ?>">
                <input type="hidden" name="wpuf_cancel_subscription" value="Cancel">
                <input type="submit" name="wpuf_user_subscription_cancel" class="btn btn-sm btn-danger" value="<?php esc_html_e( 'Cancel', 'wp-user-frontend' ); ?>">
            </form>
            <?php
        }

        wpuf_load_template(
            'subscriptions/listing.php', apply_filters(
                'wpuf_subscription_listing_args', [
                    'subscription' => $this,
                    'args'         => $args,
                    'packs'        => $packs,
                    'pack_order'   => isset( $pack_order ) ? $pack_order : '',
                    'details_meta' => $details_meta,
                    'current_pack' => $current_pack,
                ]
            )
        );

        $contents = ob_get_clean();

        return apply_filters( 'wpuf_subscription_packs', $contents, $packs );
    }

Code file location:

wp-user-frontend/wp-user-frontend/class/subscription.php

Wp User Frontend [wpuf_form] Shortcode

The ‘wpuf_form’ shortcode from the WP User Frontend plugin is designed to generate and display a form on your WordPress site. It fetches form fields and settings based on the ID provided, checks if the user can post, and renders the form. If the user can’t post, it displays a notice.

Shortcode: [wpuf_form]

Parameters

Here is a list of all possible wpuf_form shortcode parameters and attributes:

  • id – The unique number for each form created.

Examples and Usage

Basic example – Display a user frontend form using the form’s ID

[wpuf_form id=1 /]

Advanced examples

Displaying a user frontend form by referencing the form’s ID. If the form is not found by ID, it will display a message to the user.

[wpuf_form id=2 /]

Displaying a user frontend form by referencing the form’s ID and adding custom attributes. These attributes can be used to add additional functionality or customizations to the form.

[wpuf_form id=3 attr1='value1' attr2='value2' /]

Note: Replace ‘attr1’ and ‘attr2’ with the actual attribute names and ‘value1’ and ‘value2’ with the actual values you want to use. The ‘id’ should be replaced with the actual form ID.

PHP Function Code

In case you have difficulties debugging what causing issues with [wpuf_form] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wpuf_form', [ $this, 'add_post_shortcode' ] );

Shortcode PHP function:

function add_post_shortcode( $atts ) {
        add_filter( 'wpuf-form-fields', [ $this, 'add_field_settings' ] );

        // @codingStandardsIgnoreStart
        extract( shortcode_atts( [ 'id' => 0 ], $atts ) );

        // @codingStandardsIgnoreEnd
        ob_start();
        $form                         = new WPUF_Form( $id );
        $this->form_fields            = $form->get_fields();
        $this->form_settings          = $form->get_settings();
        $this->generate_auth_link(); // Translate tag %login% %registration% to login registartion url
        [ $user_can_post, $info ] = $form->is_submission_open( $form, $this->form_settings );
        $info                         = apply_filters( 'wpuf_addpost_notice', $info, $id, $this->form_settings );
        $user_can_post                = apply_filters( 'wpuf_can_post', $user_can_post, $id, $this->form_settings );

        if ( $user_can_post === 'yes' ) {
            $this->render_form( $id, null, $atts, $form );
        } else {
            echo wp_kses_post( '<div class="wpuf-info">' . $info . '</div>' );
        }
        $content = ob_get_contents();
        ob_end_clean();

        return $content;
    }

Code file location:

wp-user-frontend/wp-user-frontend/includes/class-frontend-form-post.php

Wp User Frontend [wpuf_edit] Shortcode

The ‘wpuf_edit’ shortcode from the WP User Frontend plugin allows users to edit their posts. It checks if a user is logged in, validates the post ID, and verifies edit permissions. If all checks pass, it renders the edit form.

Shortcode: [wpuf_edit]

Parameters

Here is a list of all possible wpuf_edit shortcode parameters and attributes:

  • id – Identifies the form to be used for editing

Examples and Usage

Basic example – A basic usage of the wpuf_edit shortcode that allows editing of a post with a specific ID.

[wpuf_edit id=2 /]

Advanced examples

Using the shortcode to edit a post by referencing the post ID. If the user is not logged in, it will display a login form.

[wpuf_edit id=3 /]

Using the shortcode to edit a post by referencing the post ID. If the user is not logged in or does not have the necessary permissions to edit the post, it will display an appropriate message.

[wpuf_edit id=4 /]

Using the shortcode to edit a post by referencing the post ID. If the post does not exist, it will display an error message.

[wpuf_edit id=5 /]

Using the shortcode to edit a post by referencing the post ID. If the post is locked for editing by an administrator, it will display a lock notice.

[wpuf_edit id=6 /]

Using the shortcode to edit a post by referencing the post ID. If the post is pending and editing is disabled, it will display a notice.

[wpuf_edit id=7 /]

Using the shortcode to edit a post by referencing the post ID. If the post is published and editing is disabled, it will display a notice.

[wpuf_edit id=8 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wpuf_edit] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wpuf_edit', [ $this, 'edit_post_shortcode' ] );

Shortcode PHP function:

function edit_post_shortcode( $atts ) {
        add_filter( 'wpuf-form-fields', [ $this, 'add_field_settings' ] );
        // @codingStandardsIgnoreStart
        extract( shortcode_atts( [ 'id' => 0 ], $atts ) );

        // @codingStandardsIgnoreEnd
        ob_start();

        global $userdata;

        ob_start();

        if ( ! is_user_logged_in() ) {
            echo wp_kses_post( '<div class="wpuf-message">' . __( 'You are not logged in', 'wp-user-frontend' ) . '</div>' ),

            wp_login_form();

            return;
        }

        $post_id = isset( $_GET['pid'] ) ? intval( wp_unslash( $_GET['pid'] ) ) : 0;

        if ( ! $post_id ) {
            return '<div class="wpuf-info">' . __( 'Invalid post', 'wp-user-frontend' ) . '</div>';
        }

        $edit_post_lock      = get_post_meta( $post_id, '_wpuf_lock_editing_post', true );
        $edit_post_lock_time = get_post_meta( $post_id, '_wpuf_lock_user_editing_post_time', true );

        if ( $edit_post_lock === 'yes' ) {
            return '<div class="wpuf-info">' . apply_filters( 'wpuf_edit_post_lock_user_notice', __( 'Your edit access for this post has been locked by an administrator.', 'wp-user-frontend' ) ) . '</div>';
        }

        if ( ! empty( $edit_post_lock_time ) && $edit_post_lock_time < time() ) {
            return '<div class="wpuf-info">' . apply_filters( 'wpuf_edit_post_lock_expire_notice', __( 'Your allocated time for editing this post has been expired.', 'wp-user-frontend' ) ) . '</div>';
        }

        if ( wpuf_get_user()->edit_post_locked() ) {
            if ( wpuf_get_user()->edit_post_lock_reason() ) {
                return '<div class="wpuf-info">' . wpuf_get_user()->edit_post_lock_reason() . '</div>';
            }

            return '<div class="wpuf-info">' . apply_filters( 'wpuf_user_edit_post_lock_notice', __( 'Your post edit access has been locked by an administrator.', 'wp-user-frontend' ) ) . '</div>';
        }

        //is editing enabled?
        if ( wpuf_get_option( 'enable_post_edit', 'wpuf_dashboard', 'yes' ) !== 'yes' ) {
            return '<div class="wpuf-info">' . __( 'Post Editing is disabled', 'wp-user-frontend' ) . '</div>';
        }

        $curpost = get_post( $post_id );

        if ( ! $curpost ) {
            return '<div class="wpuf-info">' . __( 'Invalid post', 'wp-user-frontend' );
        }

        // has permission?
        if ( ! current_user_can( 'delete_others_posts' ) && ( $userdata->ID !== (int) $curpost->post_author ) ) {
            return '<div class="wpuf-info">' . __( 'You are not allowed to edit', 'wp-user-frontend' ) . '</div>';
        }

        $form_id = get_post_meta( $post_id, self::$config_id, true );

        // fallback to default form
        if ( ! $form_id ) {
            $form_id = wpuf_get_option( 'default_post_form', 'wpuf_frontend_posting' );
        }

        if ( ! $form_id ) {
            return '<div class="wpuf-info">' . __( "I don't know how to edit this post, I don't have the form ID", 'wp-user-frontend' ) . '</div>';
        }

        $form = new WPUF_Form( $form_id );

        $this->form_fields = $form->get_fields();
        // $form_settings = wpuf_get_form_settings( $form_id );
        $this->form_settings = $form->get_settings();

        $disable_pending_edit = wpuf_get_option( 'disable_pending_edit', 'wpuf_dashboard', 'on' );
        $disable_publish_edit = wpuf_get_option( 'disable_publish_edit', 'wpuf_dashboard', 'off' );

        if ( 'pending' === $curpost->post_status && 'on' === $disable_pending_edit ) {
            return '<div class="wpuf-info">' . __( 'You can\'t edit a post while in pending mode.', 'wp-user-frontend' );
        }

        if ( 'publish' === $curpost->post_status && 'off' !== $disable_publish_edit ) {
            return '<div class="wpuf-info">' . __( 'You\'re not allowed to edit this post.', 'wp-user-frontend' );
        }

        $msg = isset( $_GET['msg'] ) ? sanitize_text_field( wp_unslash( $_GET['msg'] ) ) : '';

        if ( $msg === 'post_updated' ) {
            echo wp_kses_post( '<div class="wpuf-success">' );
            echo wp_kses_post( str_replace( '%link%', get_permalink( $post_id ), $this->form_settings['update_message'] ) );
            echo wp_kses_post( '</div>' );
        }

        $this->render_form( $form_id, $post_id, $atts, $form );

        $content = ob_get_contents();

        ob_end_clean();

        return $content;
    }

Code file location:

wp-user-frontend/wp-user-frontend/includes/class-frontend-form-post.php

Wp User Frontend [wpuf-login] Shortcode

The WP User Frontend Login shortcode is used for rendering a login form. It checks if a user is logged in, and displays corresponding templates. This shortcode executes the ‘login_form’ function, which handles different login scenarios. It sanitizes GET parameters, loads templates based on user status, and provides feedback messages.

Shortcode: [wpuf-login]

Examples and Usage

Basic example – The shortcode below will display a login form.

[wpuf-login /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wpuf-login] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wpuf-login', [ $this, 'login_form' ] );

Shortcode PHP function:

function login_form() {
        $getdata = wp_unslash( $_GET );

        $login_page = $this->get_login_url();
        $reset = isset( $getdata['reset'] ) ? sanitize_text_field( $getdata['reset'] ) : '';

        if ( false === $login_page ) {
            return;
        }

        ob_start();

        if ( is_user_logged_in() ) {
            wpuf_load_template(
                'logged-in.php', [
                    'user' => wp_get_current_user(),
                ]
            );
        } else {
            $action = isset( $getdata['action'] ) ? sanitize_text_field( $getdata['action'] ) : 'login';

            $args = [
                'action_url'  => $login_page,
                'redirect_to' => isset( $getdata['redirect_to'] ) ? $getdata['redirect_to'] : '',
            ];

            switch ( $action ) {
                case 'lostpassword':
                    $checkemail = isset( $getdata['checkemail'] ) ? sanitize_text_field( $getdata['checkemail'] ) : '';

                    if ( 'confirm' === $checkemail ) {
                        $this->messages[] = __( 'Check your e-mail for the confirmation link.', 'wp-user-frontend' );
                    }

                    if ( ! $checkemail ) {
                        $this->messages[] = __( 'Please enter your username or email address. You will receive a link to create a new password via email.', 'wp-user-frontend' );
                    }

                    wpuf_load_template( 'lost-pass-form.php', $args );
                    break;

                case 'rp':
                case 'resetpass':
                    if ( $reset === 'true' ) {
                        $this->messages[] = __( 'Your password has been reset successfully', 'wp-user-frontend' );

                        wpuf_load_template( 'login-form.php', $args );

                        break;
                    } else {
                        $this->messages[] = __( 'Enter your new password below.', 'wp-user-frontend' );

                        wpuf_load_template( 'reset-pass-form.php', $args );
                    }

                    break;

                default:
                    $loggedout = isset( $getdata['loggedout'] ) ? sanitize_text_field( $getdata['loggedout'] ) : '';

                    if ( $loggedout === 'true' ) {
                        $this->messages[] = __( 'You are now logged out.', 'wp-user-frontend' );
                    }

                    $args['redirect_to'] = $this->get_login_redirect_link( $args['redirect_to'] );

                    wpuf_load_template( 'login-form.php', $args );

                    break;
            }
        }

        return ob_get_clean();
    }

Code file location:

wp-user-frontend/wp-user-frontend/includes/free/class-login.php

Wp User Frontend [wpuf-registration] Shortcode

The WP User Frontend shortcode ‘wpuf-registration’ facilitates the registration process. It first checks if a user is logged in. If so, it loads the ‘logged-in.php’ template. If not, it sanitizes query parameters, encodes the user role, and loads the ‘registration-form.php’ template with the necessary arguments.

Shortcode: [wpuf-registration]

Parameters

Here is a list of all possible wpuf-registration shortcode parameters and attributes:

  • role – specifies the role to be assigned to the registering user

Examples and Usage

Basic example – Display the registration form with the default user role.

[wpuf-registration]

Advanced examples:

Display the registration form with a specific user role. In the example below, the user role is set to ‘subscriber’.

[wpuf-registration role='subscriber']

Display the registration form with a custom user role. In the example below, the user role is set to ‘custom_role’.

[wpuf-registration role='custom_role']

You can also use the shortcode within PHP code by using the do_shortcode function. This method allows you to display the registration form directly within your theme files.

<?php echo do_shortcode("[wpuf-registration role='custom_role']"); ?>

PHP Function Code

In case you have difficulties debugging what causing issues with [wpuf-registration] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wpuf-registration', [ $this, 'registration_form' ] );

Shortcode PHP function:

function registration_form( $atts ) {
        $atts = shortcode_atts(
            [
                'role' => '',
            ], $atts
        );
        $userrole = $atts['role'];

        $user_nonce  = base64_encode( random_bytes( WPUF_Encryption_Helper::get_encryption_nonce_length() ) );
        $roleencoded = wpuf_encryption( $userrole, $user_nonce );

        $reg_page = $this->get_registration_url();

        if ( false === $reg_page ) {
            return;
        }

        ob_start();

        if ( is_user_logged_in() ) {
            wpuf_load_template(
                'logged-in.php', [
                    'user' => wp_get_current_user(),
                ]
            );
        } else {
            $queries = wp_unslash( $_GET );

            array_walk(
                $queries, function ( &$a ) {
                    $a = sanitize_text_field( $a );
                }
            );

            $args = [
                'action_url' => add_query_arg( $queries, $reg_page ),
                'userrole'   => $roleencoded,
                'user_nonce' => $user_nonce,
            ];

            wpuf_load_template( 'registration-form.php', $args );
        }

        return ob_get_clean();
    }

Code file location:

wp-user-frontend/wp-user-frontend/includes/free/class-registration.php

Wp User Frontend [wpuf-edit-users] Shortcode

The WP User Frontend shortcode is designed to edit users’ profiles. It checks if a user is logged in and has the required permissions. If conditions are met, it gets the user’s data and performs actions based on the ‘action’ parameter. If ‘action’ equals ‘edit’, it displays the edit profile form if the user exists. If ‘action’ equals ‘wpuf_add_user’, it adds a new user. By default, it displays all users. If the user doesn’t have the required permissions or is not logged in, it returns an error message.

Shortcode: [wpuf-edit-users]

Examples and Usage

Basic Example – A simple usage of the shortcode to allow users with necessary permissions to edit user profiles.

[wpuf-edit-users]

PHP Function Code

In case you have difficulties debugging what causing issues with [wpuf-edit-users] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wpuf-edit-users', 'wpuf_edit_users' );

Shortcode PHP function:

function wpuf_edit_users() {
    ob_start();

    // if user is logged in
    if ( is_user_logged_in() ) {

        //this user can edit the users
        if ( current_user_can( 'edit_users' ) ) {
            $action   = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : 'show';
            $user_id  = isset( $_GET['user_id'] ) ? intval( wp_unslash( $_GET['user_id'] ) ) : 0;
            $userdata = get_userdata( $user_id );

            switch ( $action ) {
                case 'edit':
                    //if user exists
                    if ( $user_id && $userdata ) {
                        if ( ! empty( wpuf()->free_loader->edit_profile ) ) {
                            wpuf()->free_loader->edit_profile->show_form( $user_id );
                        } else {
                            printf( esc_html( __( "User doesn't exists", 'wp-user-frontend' ) ) );
                        }
                    } else {
                        printf( esc_html( __( "User doesn't exists", 'wp-user-frontend' ) ) );
                    }
                    break;

                case 'wpuf_add_user':
                    wpuf_add_user();
                    break;

                default: wpuf_show_users();
            }
        } else { // user don't have any permission
            printf( esc_html( __( "You don't have permission for this purpose", 'wp-user-frontend' ) ) );
        }
    } else { //user is not logged in
        printf( esc_html( __( 'This page is restricted. Please %s to view this page.', 'wp-user-frontend' ) ), wp_loginout( '', false ) );
    }

    return ob_get_clean();
}

Code file location:

wp-user-frontend/wp-user-frontend/includes/free/edit-user.php

Wp User Frontend [wpuf-meta] Shortcode

The WP User Frontend shortcode ‘wpuf-meta’ allows users to display custom meta data in posts. It supports different types such as image, file, map, repeat, and normal. .

Shortcode: [wpuf-meta]

Parameters

Here is a list of all possible wpuf-meta shortcode parameters and attributes:

  • name – Defines the meta key of the post meta field.
  • type – Specifies the type of the field like image, file, map, repeat or normal.
  • size – Determines the size of the thumbnail if the type is image.
  • width – Sets the width of the map if the type is map.
  • height – Sets the height of the map if the type is map.
  • zoom – Sets the zoom level of the map if the type is map.

Examples and Usage

Basic example – Displaying a normal meta field using the shortcode. In this example, the ‘name’ attribute refers to the meta key of the post.

[wpuf-meta name="my_meta_key" /]

Advanced examples

Displaying an image or file field using the shortcode. The ‘name’ attribute refers to the meta key, and the ‘type’ attribute should be set to either ‘image’ or ‘file’.

[wpuf-meta name="my_image_key" type="image" /]

Displaying a map field using the shortcode. The ‘name’ attribute refers to the meta key, and the ‘type’ attribute should be set to ‘map’. The ‘width’, ‘height’, and ‘zoom’ attributes can be used to customize the map.

[wpuf-meta name="my_map_key" type="map" width="500" height="300" zoom="14" /]

Displaying a repeating field using the shortcode. The ‘name’ attribute refers to the meta key, and the ‘type’ attribute should be set to ‘repeat’.

[wpuf-meta name="my_repeat_key" type="repeat" /]

Displaying a clickable meta field using the shortcode. The ‘name’ attribute refers to the meta key, and any other value for the ‘type’ attribute will result in a clickable meta field.

[wpuf-meta name="my_clickable_key" type="clickable" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wpuf-meta] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wpuf-meta', 'wpuf_meta_shortcode' );

Shortcode PHP function:

function wpuf_meta_shortcode( $atts ) {
    global $post;

    $attrs = shortcode_atts(
        [
            'name'   => '',
            'type'   => 'normal',
            'size'   => 'thumbnail',
            'height' => 250,
            'width'  => 450,
            'zoom'   => 12,
        ], $atts
    );

    $name   = $attrs['name'];
    $type   = $attrs['type'];
    $size   = $attrs['size'];
    $width  = $attrs['width'];
    $height = $attrs['height'];
    $zoom   = $attrs['zoom'];

    if ( empty( $name ) ) {
        return;
    }

    if ( 'image' === $type || 'file' === $type ) {
        $images = get_post_meta( $post->ID, $name, true );

        if ( ! is_array( $images ) ) {
            $images = (array) $images;
        }

        if ( $images ) {
            $html = '';

            foreach ( $images as $attachment_id ) {
                if ( 'image' === $type ) {
                    $thumb = wp_get_attachment_image( $attachment_id, $size );
                } else {
                    $thumb = get_post_field( 'post_title', $attachment_id );
                }

                $full_size = wp_get_attachment_url( $attachment_id );
                $html      .= sprintf( '<a href="%s">%s</a> ', $full_size, $thumb );
            }

            return $html;
        }
    } elseif ( 'map' === $type ) {
        ob_start();
        wpuf_shortcode_map(
            $name, $post->ID, [
                'width' => $width,
                'height' => $height,
                'zoom' => $zoom,
            ]
        );

        return ob_get_clean();
    } elseif ( 'repeat' === $type ) {
        return implode( '; ', get_post_meta( $post->ID, $name ) );
    } elseif ( 'normal' === $type ) {
        return implode( ', ', get_post_meta( $post->ID, $name ) );
    } else {
        return make_clickable( implode( ', ', get_post_meta( $post->ID, $name ) ) );
    }
}

Code file location:

wp-user-frontend/wp-user-frontend/wpuf-functions.php

Conclusion

Now that you’ve learned how to embed the Wp User Frontend Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *