escaping and sanitizing input for custom widget form fields

Is there a better way to validate the form method inputs of a custom widget? I want to avoid to create a long list of co

Is there a better way to validate the form method inputs of a custom widget? I want to avoid to create a long list of control structure or variables. For eample here is the code I've used for a custom widget form method:

public function form( $instance )
  {
    $background = '';
    $title = '';
    $claime = '';
    $organization = '';
    $address = '';
    $phone = '';
    $email = '';
    $vat = '';
    $fb = '';
    $ig = '';

    if( $instance ){
      $background = esc_url( $instance['bg_image'] );
      $title = esc_attr( $instance['title'] );
      $claime = esc_attr( $instance['claime'] );
      $organization = esc_attr( $instance['organization'] );
      $address = esc_attr( $instance['address'] );
      $phone = esc_attr( $instance['phone'] );
      $email = esc_attr( $instance['email'] );
      $vat = esc_attr( $instance['vat'] );
      $fb = esc_url( $instance['fb'] );
      $ig = esc_url( $instance['ig'] );
    }
    ?>
    // html inputs here...
    <?php
  }

As you can see there are many variables that are escaped using the esc_ functions of wp. I imagine a series of control structures with if and else for each variable, but I'm sure there's a better way? Any suggestion will be appreciated

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744887502a4599206.html

相关推荐

  • escaping and sanitizing input for custom widget form fields

    Is there a better way to validate the form method inputs of a custom widget? I want to avoid to create a long list of co

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信