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 designed for user registration, profile management, membership control, 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 ‘wpuf_account’ shortcode is a versatile tool from the WP User Frontend plugin. It’s designed to manage user account interfaces, providing customized content based on user login status. Upon execution, the shortcode checks if a user is logged in. If true, it loads an account dashboard with sections defined by the ‘wpuf_get_account_sections()’ function. The active tab is determined by user selection or defaults to the ‘account_page_active_tab’ option. If a user is not logged in, it displays an unauthorized message defined by the ‘un_auth_msg’ option. This ensures secure and personalized user experiences.

Shortcode: [wpuf_account]

Examples and Usage

Basic example – Display user account information if the user is logged in. If the user is not logged in, an unauthorized message is displayed.

[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’, displays subscription information of a user. It fetches account sections and executes the ‘wpuf_account_content_subscription’ action.

Shortcode: [wpuf_sub_info]

Examples and Usage

Basic example – The basic usage of the ‘wpuf_sub_info’ shortcode displays the subscription information related to the current user’s account.

[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 ‘wpuf_sub_pack’ manages subscription packages. It retrieves the user’s subscription status, displays messages based on their subscription, and provides an option to cancel the subscription.

Shortcode: [wpuf_sub_pack]

Parameters

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

  • include – specifies the subscription packs to be included
  • exclude – specifies the subscription packs to be excluded
  • order – sets the order of the subscription packs
  • orderby – determines how the subscription packs should be sorted

Examples and Usage

Basic example – A shortcode that displays all subscription packs with default settings.

[wpuf_sub_pack]

Advanced examples

Display subscription packs with specific IDs. The order of IDs determines the order in which the packs will be displayed.

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

Exclude certain subscription packs from being displayed by referencing their IDs.

[wpuf_sub_pack exclude="4,5,6"]

Change the order in which the subscription packs are displayed. The default is ascending (ASC), but can be changed to descending (DESC).

[wpuf_sub_pack order="DESC"]

Change the parameter by which the subscription packs are ordered. The default is by post date, but can be changed to order by title, ID, author, and more.

[wpuf_sub_pack orderby="title"]

Combining multiple parameters/attributes in a single shortcode to customize the display of subscription packs.

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

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 WP User Frontend plugin is designed to render a form based on the given ID. It first checks if the user has permission to post, then displays the form accordingly.

Shortcode: [wpuf_form]

Parameters

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

  • id – The unique identifier for the specific form you want to display.

Examples and Usage

Basic example – A simple way to use the shortcode to display a form by referencing its ID.

[wpuf_form id=1 /]

Advanced examples

Using the shortcode to display a form by referencing its ID, and also applying a custom filter to the form fields. The filter will modify the form fields before they are displayed.


function custom_form_fields( $fields ) {
    // Modify $fields as needed
    return $fields;
}
add_filter( 'wpuf-form-fields', 'custom_form_fields' );

Then use the shortcode:

[wpuf_form id=1 /]

Another advanced example is to use the shortcode to display a form by referencing its ID, and also applying a custom filter to control whether the form can be submitted. The filter will determine whether the form can be submitted based on custom logic.


function custom_can_post( $can_post, $id, $form_settings ) {
    // Determine whether the form can be submitted based on custom logic
    return $can_post;
}
add_filter( 'wpuf_can_post', 'custom_can_post', 10, 3 );

Then use the shortcode:

[wpuf_form id=1 /]

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 WP User Frontend shortcode allows users to edit their posts from the frontend. It checks if a user is logged in and has the necessary permissions to edit the post. It validates the post ID and ensures editing isn’t locked or disabled. If conditions are met, it renders the form for editing.

Shortcode: [wpuf_edit]

Examples and Usage

Basic example – Display the editing form for a specific post by referencing the post ID in the URL.

[wpuf_edit id=1 /]

Advanced examples

Display the editing form for a specific post by referencing the post ID in the URL. If the user is not logged in, they will be prompted to log in. If the user does not have permission to edit the post, they will be shown a message.

[wpuf_edit id=1 login_message="Please log in to edit this post." permission_message="You do not have permission to edit this post."] 

Display the editing form for a specific post by referencing the post ID in the URL. If the post does not exist, a custom error message will be displayed. If the post is locked for editing, a custom lock message will be displayed.

[wpuf_edit id=1 invalid_post_message="This post does not exist." lock_message="This post is currently locked for editing."] 

Display the editing form for a specific post by referencing the post ID in the URL. If editing is disabled, a custom message will be displayed. If the user’s time to edit the post has expired, a custom expire message will be displayed.

[wpuf_edit id=1 disable_edit_message="Editing is currently disabled." expire_message="Your time to edit this post has expired."] 

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 allows users to log in, reset their password, or retrieve a lost password. It checks if a user is logged in, if not, it provides a login form. When the ‘lostpassword’ action is triggered, the user is prompted to enter their username or email to receive a reset link. If ‘resetpass’ is activated, the user can input a new password. Shortcode: [wpuf-login]

Shortcode: [wpuf-login]

Examples and Usage

Basic example – A simple implementation of the ‘wpuf-login’ shortcode to display the login form.

[wpuf-login /]

Advanced examples

Using the ‘wpuf-login’ shortcode to display the login form with a redirect URL. After successful login, the user will be redirected to the specified URL.

[wpuf-login redirect_to="https://yourwebsite.com/dashboard" /]

Using the ‘wpuf-login’ shortcode to display the lost password form. This is useful when you want to provide a direct link for users to reset their password.

[wpuf-login action="lostpassword" /]

Using the ‘wpuf-login’ shortcode to display the reset password form. This can be used in combination with the ‘reset’ parameter to confirm the password reset action.

[wpuf-login action="resetpass" reset="true" /]

Please note that these examples are based on the provided PHP code for the ‘wpuf-login’ shortcode. The actual usage may vary depending on the configuration and setup of your WordPress site and the WP User Frontend plugin.

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’ enables a customizable registration form on your site. It checks if a user is logged in, and if not, it loads the registration form. The shortcode accepts a ‘role’ attribute, allowing you to specify the user role for new registrants. It uses nonce for security, ensuring data authenticity. Finally, it returns the output of the form, ready to be inserted anywhere shortcodes are supported.

Shortcode: [wpuf-registration]

Parameters

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

  • role – defines the user role for the registration form

Examples and Usage

Basic example – A simple shortcode to display the registration form.

[wpuf-registration]

Advanced examples

Shortcode to display the registration form with a specific user role. In this example, the user role is set to ‘subscriber’.

[wpuf-registration role="subscriber"]

Shortcode to display the registration form with a custom user role. Here, the user role is ‘custom_role’ which may be a role you have set up in your WordPress site.

[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 allows users with the ‘edit_users’ permission to edit user profiles. It checks if the user is logged in and has the required permissions. If so, it either displays the edit form for an existing user or shows an error message. If the user isn’t logged in or lacks permissions, a restriction message is displayed.

Shortcode: [wpuf-edit-users]

Examples and Usage

Basic example – A simple shortcode that triggers the wpuf_edit_users function. This allows an authorized user to edit other users’ profiles.

[wpuf-edit-users /]

Advanced examples

Here are some examples of how you can use the shortcode with various parameters:

1. Using the shortcode to display the edit form for a specific user by passing their user_id as a parameter.

[wpuf-edit-users action="edit" user_id="2" /]

2. Using the shortcode to add a new user by calling the wpuf_add_user function.

[wpuf-edit-users action="wpuf_add_user" /]

3. Using the shortcode to display a list of all users by calling the wpuf_show_users function.

[wpuf-edit-users action="show" /]

Note that these shortcodes will only work if the user is logged in and has the appropriate permissions. If not, they will see an error message or be prompted to log in.

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’ is designed to display custom meta data from posts. It can handle different types of data including images, files, maps, and normal text. By using this shortcode, users can customize the appearance of their post meta data. It allows for adjustments in size, width, height, and zoom. It’s an efficient way to personalize your WordPress frontend.

Shortcode: [wpuf-meta]

Parameters

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

  • name – It signifies the meta key of the post.
  • type – It determines the type of data to be displayed (image, file, map, repeat, normal).
  • size – It specifies the size of the image (applicable if type is ‘image’).
  • height – It defines the height of the map (applicable if type is ‘map’).
  • width – It sets the width of the map (applicable if type is ‘map’).
  • zoom – It controls the zoom level of the map (applicable if type is ‘map’).

Examples and Usage

Basic example – Displaying post meta data using the ‘name’ attribute.

[wpuf-meta name="custom_field_name" /]

Advanced examples

Displaying an image from post meta data using the ‘name’ and ‘type’ attributes. The ‘type’ attribute is set to ‘image’ to specify that we want to display an image.

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

Displaying a map from post meta data using the ‘name’, ‘type’, ‘width’, ‘height’, and ‘zoom’ attributes. The ‘type’ attribute is set to ‘map’ to specify that we want to display a map. The ‘width’, ‘height’, and ‘zoom’ attributes are used to define the map’s dimensions and zoom level.

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

Displaying repeating post meta data using the ‘name’ and ‘type’ attributes. The ‘type’ attribute is set to ‘repeat’ to specify that we want to display repeating meta data.

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

Displaying post meta data as clickable links using the ‘name’ and ‘type’ attributes. The ‘type’ attribute is set to ‘link’ to specify that we want to display the meta data as clickable links.

[wpuf-meta name="custom_link_field" type="link" /]

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 *