0

所以我有一个问题 - 关于 WordPress 插件,特别是短代码


附加信息 >

CMS : WordPress (5.7.1)

语言:PHP 7<,JS

插件:终极会员


我正在寻找一种在不使用插件简码(最终成员)的情况下将插件外部的配置文件功能调用__DIR__到 wordpress 主题(2021 主题)中的方法 - 只需在主题文件夹中的自定义模板中手动调用它

为什么 ?

我构建了一个自定义 JS、HTML5、CSS 网页,我想调用

[ username , email , user account information ]

个人资料简码(最终会员)==“ [ultimatemember form_id="76"]

输出: 个人资料门户的图片 一切正常


现在我如何在没有短代码的情况下调用该配置文件门户?这就是我试图做的

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 );

此行负责加载 Ultimate Member 运行配置文件门户所需的功能


#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:        }

只是为了在一个名为的命名空间中清除所有这些

namespace um\core;

在一个班级里面Shortcodes

所以当我尝试打电话时(仍在同一个文件夹中测试)(在课堂上)

ultimatemember(); 

出现此错误

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

如何 ?

期待“功能”

不是ultimatemember();一个函数??

如果我在类之外调用它,它会作为未定义的函数返回

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

1 回答 1

0

@amarinediary 已经回答了这个问题

您必须在这样的方法之前调用类变量名称

class Shortcode{
function runme{
//code 
}}

这就是你所说的

$classin = new Shortcodes();
$classin-> ultimatemember();
于 2021-05-06T23:41:32.087 回答