本文整理匯總了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);
}