How to call a functions/classes without using shortcodes | Wordpress?

526 views Asked by At

So i have a question - regarding WordPress plugins specifically shortcodes


Additional Info >

CMS : Wordpress (5.7.1)

Language : PHP 7< , JS

Plugin : Ultimate Member


i looking for a way to call the profile functions outside the plugin __DIR__ into the wordpress theme ( 2021 theme ) without using the plugin shortcodes (ultimate member ) -just to call it manually in custom template in theme folder

why ?

i built a custom JS,HTML5,CSS webpage and i want to call

[ username , email , user account information ]

profile shortcode ( ultimate member ) == " [ultimatemember form_id="76"] "

OUTPUT : A Picture Of The Profile Portal Everything works okay


Now how can i call that profile portal without the short code ? here's what i tried to do

UMDIR = Ultimate Member Plugin Directory

UMDIR : wp-content\plugins\ultimate-member\includes\core\class-shortcodes.php

  # Shortcode

    558: function ultimatemember( $args = array() ) {
    559:
    560:            return $this->load( $args );
    561:        }

return $this->load( $args );

This Line Is Responsible to load the functions that Ultimate Member Need to run the profile portal


#Load a module with global function

569:    function load( $args ) {
570:            $defaults = array();
571:            $args = wp_parse_args( $args, $defaults );
572:
573:            // when to not continue
        $this->form_id = isset( $args['form_id'] ) ? $args['form_id'] : null;
        if ( ! $this->form_id ) {
            return;
        }

        $this->form_status = get_post_status( $this->form_id );
        if ( $this->form_status != 'publish' ) {
            return;
        }

        // get data into one global array
        $post_data = UM()->query()->post_data( $this->form_id );
        $args = array_merge( $args, $post_data );

        ob_start();

        /**
         * UM hook
         *
         * @type filter
         * @title um_pre_args_setup
         * @description Change arguments on load shortcode
         * @input_vars
         * [{"var":"$post_data","type":"string","desc":"$_POST data"}]
         * @change_log
         * ["Since: 2.0"]
         * @usage
         * <?php add_filter( 'um_pre_args_setup', 'function_name', 10, 1 ); ?>
         * @example
         * <?php
         * add_filter( 'um_pre_args_setup', 'my_pre_args_setup', 10, 1 );
         * function my_pre_args_setup( $post_data ) {
         *     // your code here
         *     return $post_data;
         * }
         * ?>
         */
        $args = apply_filters( 'um_pre_args_setup', $args );

        if ( ! isset( $args['template'] ) ) {
            $args['template'] = '';
        }

        if ( isset( $post_data['template'] ) && $post_data['template'] != $args['template'] ) {
            $args['template'] = $post_data['template'];
        }

        if ( ! $this->template_exists( $args['template'] ) ) {
            $args['template'] = $post_data['mode'];
        }

        if ( ! isset( $post_data['template'] ) ) {
            $post_data['template'] = $post_data['mode'];
        }

        if ( 'directory' == $args['mode'] ) {
            wp_enqueue_script( 'um_members' );
            if ( is_rtl() ) {
                wp_enqueue_style( 'um_members_rtl' );
            } else {
                wp_enqueue_style( 'um_members' );
            }
        }

        if ( 'directory' != $args['mode'] ) {
            $args = array_merge( $post_data, $args );

            if ( empty( $args['use_custom_settings'] ) ) {
                $args = array_merge( $args, $this->get_css_args( $args ) );
            } else {
                $args = array_merge( $this->get_css_args( $args ), $args );
            }
        }
        // filter for arguments

        /**
         * UM hook
         *
         * @type filter
         * @title um_shortcode_args_filter
         * @description Change arguments on load shortcode
         * @input_vars
         * [{"var":"$args","type":"string","desc":"Shortcode arguments"}]
         * @change_log
         * ["Since: 2.0"]
         * @usage
         * <?php add_filter( 'um_shortcode_args_filter', 'function_name', 10, 1 ); ?>
         * @example
         * <?php
         * add_filter( 'um_shortcode_args_filter', 'my_shortcode_args', 10, 1 );
         * function my_shortcode_args( $args ) {
         *     // your code here
         *     return $args;
         * }
         * ?>
         */
        $args = apply_filters( 'um_shortcode_args_filter', $args );

        /**
         * @var string $mode
         */
        extract( $args, EXTR_SKIP );

        //not display on admin preview
        if ( empty( $_POST['act_id'] ) || $_POST['act_id'] != 'um_admin_preview_form' ) {
            if ( 'register' == $mode && is_user_logged_in() ) {
                ob_get_clean();
                return __( 'You are already registered', 'ultimate-member' );
            }
        }

        // for profiles only
        if ( $mode == 'profile' && um_profile_id() ) {

            //set requested user if it's not setup from permalinks (for not profile page in edit mode)
            if ( ! um_get_requested_user() ) {
                um_set_requested_user( um_profile_id() );
            }

            if ( ! empty( $args['use_custom_settings'] ) ) { // Option "Apply custom settings to this form"
                if ( ! empty( $args['role'] ) ) { // Option "Make this profile form role-specific"

                    // show the first Profile Form with role selected, don't show profile forms below the page with other role-specific setting
                    if ( empty( $this->profile_role ) ) {
                        $current_user_roles = UM()->roles()->get_all_user_roles( um_profile_id() );

                        if ( empty( $current_user_roles ) ) {
                            ob_get_clean();
                            return '';
                        } elseif ( is_array( $args['role'] ) ) {
                            if ( ! count( array_intersect( $args['role'], $current_user_roles ) ) ) {
                                ob_get_clean();
                                return '';
                            }
                        } else {
                            if ( ! in_array( $args['role'], $current_user_roles ) ) {
                                ob_get_clean();
                                return '';
                            }
                        }

                        $this->profile_role = $args['role'];
                    } else {
                        ob_get_clean();
                        return '';
                    }
                }
            }
        }

        /**
         * UM hook
         *
         * @type action
         * @title um_pre_{$mode}_shortcode
         * @description Action pre-load form shortcode
         * @input_vars
         * [{"var":"$args","type":"array","desc":"Form shortcode pre-loading"}]
         * @change_log
         * ["Since: 2.0"]
         * @usage add_action( 'um_pre_{$mode}_shortcode', 'function_name', 10, 1 );
         * @example
         * <?php
         * add_action( 'um_pre_{$mode}_shortcode', 'my_pre_shortcode', 10, 1 );
         * function my_pre_shortcode( $args ) {
         *     // your code here
         * }
         * ?>
         */
        do_action( "um_pre_{$mode}_shortcode", $args );
        /**
         * UM hook
         *
         * @type action
         * @title um_before_form_is_loaded
         * @description Action pre-load form shortcode
         * @input_vars
         * [{"var":"$args","type":"array","desc":"Form shortcode pre-loading"}]
         * @change_log
         * ["Since: 2.0"]
         * @usage add_action( 'um_before_form_is_loaded', 'function_name', 10, 1 );
         * @example
         * <?php
         * add_action( 'um_before_form_is_loaded', 'my_pre_shortcode', 10, 1 );
         * function my_pre_shortcode( $args ) {
         *     // your code here
         * }
         * ?>
         */
        do_action( "um_before_form_is_loaded", $args );
        /**
         * UM hook
         *
         * @type action
         * @title um_before_{$mode}_form_is_loaded
         * @description Action pre-load form shortcode
         * @input_vars
         * [{"var":"$args","type":"array","desc":"Form shortcode pre-loading"}]
         * @change_log
         * ["Since: 2.0"]
         * @usage add_action( 'um_before_{$mode}_form_is_loaded', 'function_name', 10, 1 );
         * @example
         * <?php
         * add_action( 'um_before_{$mode}_form_is_loaded', 'my_pre_shortcode', 10, 1 );
         * function my_pre_shortcode( $args ) {
         *     // your code here
         * }
         * ?>
         */
        do_action( "um_before_{$mode}_form_is_loaded", $args );

        $this->template_load( $template, $args );

        $this->dynamic_css( $args );

        if ( um_get_requested_user() || $mode == 'logout' ) {
            um_reset_user();
        }

        /**
         * UM hook
         *
         * @type action
         * @title um_after_everything_output
         * @description Action after load shortcode content
         * @change_log
         * ["Since: 2.0"]
         * @usage add_action( 'um_after_everything_output', 'function_name', 10 );
         * @example
         * <?php
         * add_action( 'um_after_everything_output', 'my_after_everything_output', 10 );
         * function my_after_everything_output() {
         *     // your code here
         * }
         * ?>
         */
        do_action( 'um_after_everything_output' );

            $output = ob_get_clean();
813:            return $output;
814:        }

And just to clearfiy all of them inside a namespace called

namespace um\core;

and inside a class Shortcodes

so when i try and call ( still testing in the same folder ) ( inside the class )

ultimatemember(); 

this error shows up

syntax error, unexpected identifier "ultimatemember", expecting "function" or "const" in

HOW ?

expecting "function"

Isn't ultimatemember(); a function ??

and if i called it outside the class it return as undefined function

Uncaught Error: Call to undefined function um\core\ultimatemember()
1

There are 1 answers

0
mok On

This question has been answered by @amarinediary

You have to call the class variable name before the method like this

class Shortcode{
function runme{
//code 
}}

this is how you call it

$classin = new Shortcodes();
$classin-> ultimatemember();