0

我使用终极会员多年,我在编辑个人资料中创建了一个自定义选项卡来更新一个值。事实上,我的用户(学生)可以编辑(添加或删除)他们预先注册的课程。问题是当他们尝试添加或删除课程时,会发生错误,“遇到错误”。令人惊讶的是,即使课程显示错误,他们也可以删除课程,但他们无法添加任何课程。在 Ultimate 会员的最新更新之前,它一直运行良好。代码如下:

* */
/* create new tab */
  add_filter('um_account_page_default_tabs_hook', 'CoursesTab', 100 );
    function CoursesTab( $tabs ) {
    $tabs[800]['CoursesTab']['icon'] = 'um-faicon-pencil'; // tab icon
    $tabs[800]['CoursesTab']['title'] = 'Registered Courses'; // tab title
    $tabs[800]['CoursesTab']['submit_title'] = 'Update'; // button text
    $tabs[800]['CoursesTab']['custom'] = true;
    return $tabs;
  }

  /* make our new tab hookable */
  add_action('um_account_tab__CoursesTab', 'um_account_tab__CoursesTab');
    function um_account_tab__CoursesTab( $info ) {
    extract( $info );
    $output = UM()->account->get_tab_output('CoursesTab');
    if ( $output ) { echo $output; }
  }

  /* Finally we add some content in the tab */
  add_filter('um_account_content_hook_CoursesTab', 'um_account_content_hook_CoursesTab');
  function um_account_content_hook_CoursesTab( $output ){
    ob_start();
    $id = um_user('ID');
    $output = '<div class="um-field">';
    $names = array('course','course'); 

    $fields = array(); 
    foreach( $names as $name ){
      $fields[ $name ] = UM()->builtin()->get_specific_field( $name );
    }
    $fields = apply_filters('um_account_secure_fields', $fields, $id);
    foreach( $fields as $key => $data ){
      $output .= UM()->fields()->edit_field( $key, $data );
    }

    $output .= '</div>';

    $output .= ob_get_contents();
    ob_end_clean();
    return $output;
  }

  /* ensure that the custom fields are updated when the account is updated */
  add_action('um_account_pre_update_profile', 'getUMFormData', 100);

  function getUMFormData(){
    $id = um_user('ID');
    $names = array('course','course');  // ADD THE META-KEYS HERE
    foreach( $names as $name )
      update_user_meta( $id, $name, $_POST[$name] );
  }

我搜索了很多,但是,没有发现如何解决这个问题的线索。谢谢

4

1 回答 1

0

我在这个函数中添加了代码:

add_filter('um_account_content_hook_CoursesTab', 'um_account_content_hook_CoursesTab');
function um_account_content_hook_CoursesTab( $output ){
    ob_start();
        $id = um_user('ID');
        $output = '<div class="um-field">';
        $names = array('course','course'); 

        $fields = array(); 
        foreach( $names as $name ){
        $fields[ $name ] = UM()->builtin()->get_specific_field( $name );
        }
        $fields = apply_filters('um_account_secure_fields', $fields, $id);
        foreach( $fields as $key => $data ){
        $output .= UM()->fields()->edit_field( $key, $data );
        }

        $output .= '<input type="hidden" name="um_account_nonce_'. esc_attr( 'coursestab' ).'" value="'.esc_attr( wp_create_nonce( 'um_update_account_coursestab' ) ).'" />';
                                    
        $output .= '</div>';

        $output .= ob_get_contents();
    ob_end_clean();

    return $output;
}

我添加了一个隐藏的 nonce 字段:

$output .= '<input type="hidden" name="um_account_nonce_'. esc_attr( 'coursestab' ).'" value="'.esc_attr( wp_create_nonce( 'um_update_account_coursestab' ) ).'" />';

请尝试一下,如果您仍然遇到问题,请告诉我。

问候,

于 2021-08-11T04:28:24.080 回答