本文整理汇总了PHP中WP_Widget::form方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Widget::form方法的具体用法?PHP WP_Widget::form怎么用?PHP WP_Widget::form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Widget
的用法示例。
在下文中一共展示了WP_Widget::form方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
/**
* @see WP_Widget::form()
*/
function test_wp_widget_form()
{
$widget = new WP_Widget('foo', 'Foo');
ob_start();
$retval = $widget->form(array());
$output = ob_get_clean();
$this->assertEquals('noform', $retval);
$this->assertContains('no-options-widget', $output);
}
示例2: form
/**
* Outputs the options form on admin
*
* @param array $instance The widget options
*/
public function form($instance)
{
parent::form($instance);
//Biến tạo các giá trị mặc định trong form
$defaults = ['title' => 'Widget title', 'image' => 'Widget image', 'link' => 'Link your banner'];
//Gộp các giá trị trong mảng $default vào biến $instance để nó trở thành các giá trị mặc định
$instance = wp_parse_args($instance, $defaults);
//Tạo biến riêng cho giá trị mặc định trong mảng $default
$title = esc_attr($instance['title']);
$image = esc_url($instance['image']);
$link = esc_url($instance['link']);
?>
<p>
<label for="<?php
echo $this->get_field_name('title');
?>
"><?php
_e('Title:');
?>
</label>
<input class="widefat" id="<?php
echo $this->get_field_id('title');
?>
" name="<?php
echo $this->get_field_name('title');
?>
" type="text" value="<?php
echo esc_attr($title);
?>
" />
</p>
<p>
<label for="<?php
echo $this->get_field_name('image');
?>
"><?php
_e('Image:');
?>
</label>
<input name="<?php
echo $this->get_field_name('image');
?>
" id="<?php
echo $this->get_field_id('image');
?>
" class="widefat" type="text" size="36" value="<?php
echo esc_url($image);
?>
" />
<input class="upload_image_button button button-primary" type="button" value="Upload Image" />
</p>
<p>
<label for="<?php
echo $this->get_field_name('link');
?>
"><?php
_e('Link:', KC_DOMAIN);
?>
</label>
<input class="widefat" id="<?php
echo $this->get_field_id('link');
?>
" name="<?php
echo $this->get_field_name('link');
?>
" type="text" value="<?php
echo esc_url($link);
?>
" />
</p>
<?php
}
示例3: onFormRender
/**
* Event triggered when ready to render the widget's configuration page
*
* @see form()
* @param array $instance Current settings
* @api
*/
public function onFormRender($instance)
{
parent::form($instance);
}
示例4: form
/**
* Základní (ne)formulář, resp. výpis zadaného popisku a informace, že není dostupná konfigurace widgetu
* Pozn.: pokud chcete vlastní konfiguraci widgetu, tak je třeba tuto metodu přepsat a udělat vlastní formulář
*
* @author Martin Hlaváč
* @link http://www.ktstudio.cz
*
* @param array $instance
* @return string
*/
public function form($instance)
{
echo "<p>{$this->getDescription()}</p>";
return parent::form($instance);
}