2016-06-13 35 views
-1

我使用插件wp-members for wordpress,我需要修改登錄表單,並且在我將數組輸入到函數後,我得到這個錯誤「致命錯誤:調用上的空成員函數get_text()」「致命的錯誤:調用一個成員函數get_text()null」在wordpress

這是我的functions.php

add_filter('wpmem_login_form', 'my_login_form_filter'); 

function my_login_form_filter($form, $action = 'login') 
{ 
     /** 
    * The login form is brought in with $form 
    * You can append to it or filter it 
    * 
    * $action specifies the form being constructed. It 
    * can be: login|pwdreset|pwdchange 
    */ 

$form = array(
    array(
     'name' => $wpmem->get_text("login_username"), 
     'type' => 'text', 
     'tag' => 'log', 
     'class' => 'username', 
     'div' => 'div_text', 
    ), 
    array( 
     'name' => $wpmem->get_text("login_password"), 
     'type' => 'password', 
     'tag' => 'pwd', 
     'class' => 'password', 
     'div' => 'div_text', 
    ), 
    array(
     'name' => $wpmem->get_text("login_number"), 
     'type' => 'text', 
     'tag' => 'log', 
     'class' => 'username', 
     'div' => 'div_text',) 
); 

return $form; 
} 

碼這是插件的代碼有問題

if (! function_exists('wpmem_inc_login')): 
      /** 
      * Login Dialog. 
      * 
      * Loads the login form for user login. 
      * 
      * @since 1.8 
      * 
      * @global object $wpmem  The WP_Members object. 
      * @global string $wpmem_regchk The WP-Members message container. 
      * @global object $post   The WordPress Post object. 
      * 
      * @param string $page 
      * @param string $redirect_to 
      * @return string $str   The generated html for the login form. 
      */ 
      function wpmem_inc_login($page = "page", $redirect_to = null, $show = 'show') { 

       global $wpmem, $wpmem_regchk, $post; 

       $str = ''; 

       if ($page == "page") { 

        if ($wpmem_regchk != "success") { 

         $dialogs = get_option('wpmembers_dialogs'); 

         // This shown above blocked content. 
         $msg = $wpmem->get_text('restricted_msg'); 
         $msg = ($dialogs['restricted_msg'] == $msg) ? $msg : __(stripslashes($dialogs['restricted_msg']), 'wp-members'); 
         $str = "<p>$msg</p>"; 

         /** 
         * Filter the post restricted message. 
         * 
         * @since 2.7.3 
         * 
         * @param string $str The post restricted message. 
         */ 
         $str = apply_filters('wpmem_restricted_msg', $str); 

        } 
       } 

       // Create the default inputs. 
       $default_inputs = array(
        array(
         'name' => $wpmem->get_text('login_username'), 
         'type' => 'text', 
         'tag' => 'log', 
         'class' => 'username', 
         'div' => 'div_text', 
        ), 
        array( 
         'name' => $wpmem->get_text('login_password'), 
         'type' => 'password', 
         'tag' => 'pwd', 
         'class' => 'password', 
         'div' => 'div_text', 
        ), 
       ); 

       /** 
       * Filter the array of login form fields. 
       * 
       * @since 2.9.0 
       * 
       * @param array $default_inputs An array matching the      elements used by default. 
       */ 
       $default_inputs = apply_filters('wpmem_inc_login_inputs', $default_inputs); 

       $defaults = array( 
        'heading'  => $wpmem->get_text('login_heading'), 
        'action'  => 'login', 
        'button_text' => $wpmem->get_text('login_button'), 
        'inputs'  => $default_inputs, 
        'redirect_to' => $redirect_to, 
       ); 

       /** 
       * Filter the arguments to override login form defaults. 
       * 
       * @since 2.9.0 
       * 
       * @param array $args An array of arguments to use. Default null. 
       */ 
       $args = apply_filters('wpmem_inc_login_args', ''); 

       $arr = wp_parse_args($args, $defaults); 

       $str = ($show == 'show') ? $str . wpmem_login_form($page, $arr) : $str; 

       return $str; 
      } 
      endif; 
+0

這意味着您正在調用的函數沒有從您使用的表單獲取值。嘗試尋找表單輸入名稱 –

回答

1

似乎喜歡e您正嘗試在對象$wpmem上調用功能get_text(),但它是null

您可以嘗試在你的my_login_form_filter函數定義的頂部添加global $wpmem;這樣的:

<?php 
add_filter('wpmem_login_form', 'my_login_form_filter'); 

function my_login_form_filter($form, $action = 'login') 
{ 
global $wpmem; // add this 
+0

現在沒有更多的,但現在我只得到「陣列」,沒有更多 – OunknownO

+0

你期望什麼?你正在返回'$ form'你的函數是一個數組。 –

+0

不,它不返回整個數組,它只是說字符串「數組」 – OunknownO

0

$wpmem爲空在你的功能。將global $wpmem添加到您的函數中以使用全局值。

相關問題