close

今日错误记录

今天这段wp代码,最后我要echo出来后面通过过滤的变量名字,

function slb_save_slb_subscriber_meta($post_id,$post) {

    //verify nonce
    if (!isset($_POST['slb_subscriber_nonce']) OR !wp_verify_nonce( $_POST['slb_subscriber_nonce'],basename( __FILE__ ) ) ) {
      return $post_id;
    }

    //get the post type object
    
    $post_type = get_post_type_object( $post->post_type );

    //check if the current user has permition to edit
    
    if (!current_user_can( $post_type->cap->edit_post , $post_id )) {
      return $post_id;
    }

    //get the posted data and sanitize it
    
    $first_name = ( isset($_POST['slb_first_name'])) ? sanitize_text_field( $_POST['slb_first_name'] ) : '';
    $last_name = ( isset($_POST['slb_last_name'])) ? sanitize_text_field( $_POST['slb_last_name'] ) : '';
    $email = ( isset($_POST['slb_email'])) ? sanitize_text_field( $_POST['slb_email'] ) : '';
    $lists = ( isset($_POST['slb_list']) && is_array($_POST['slb_list'])) ? (array) $_POST['slb_list'] : [];

    echo $first_name;
    exit;
  }

  add_action('save_post','slb_save_slb_subscriber_meta',10,2);

一开始没加exit, 导致保存的时候怎样都不会提示出来这个first name的变量, 加了exit 结束后面的代码运行,终于提示出来了。

Share :