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
评论列表(0条)