Align widget area with zibll by removing default RSS/search/calendar widgets, and make About guest login buttons open auth modal classes.
68 lines
3.4 KiB
PHP
68 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* @package AKSRT
|
|
*/
|
|
|
|
namespace AKSRT\Widgets;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class CustomHtmlGapWidget extends \WP_Widget {
|
|
|
|
public function __construct() {
|
|
parent::__construct('aksrt_custom_html_gap', esc_html__('AKSRT 自定义HTML/间距', 'aksrt'), [
|
|
'description' => esc_html__('插入自定义 HTML 或间距', 'aksrt'),
|
|
]);
|
|
}
|
|
|
|
public function widget($args, $instance): void {
|
|
$mode = sanitize_key($instance['mode'] ?? 'html');
|
|
|
|
if ($mode === 'gap') {
|
|
$height = max(0, min(500, (int) ($instance['gap_height'] ?? 20)));
|
|
echo '<div class="widget-custom-gap" style="height:' . (int) $height . 'px;" aria-hidden="true"></div>';
|
|
return;
|
|
}
|
|
|
|
echo $args['before_widget'];
|
|
$title = apply_filters('widget_title', $instance['title'] ?? '', $instance, $this->id_base);
|
|
if ($title) echo $args['before_title'] . esc_html($title) . $args['after_title'];
|
|
echo '<div class="widget-custom-html">' . wp_kses_post($instance['content'] ?? '') . '</div>';
|
|
echo $args['after_widget'];
|
|
}
|
|
|
|
public function form($instance): void {
|
|
$mode = sanitize_key($instance['mode'] ?? 'html');
|
|
?>
|
|
<p>
|
|
<label for="<?php echo $this->get_field_id('mode'); ?>"><?php esc_html_e('模式:', 'aksrt'); ?></label>
|
|
<select class="widefat" id="<?php echo $this->get_field_id('mode'); ?>" name="<?php echo $this->get_field_name('mode'); ?>">
|
|
<option value="html" <?php selected($mode, 'html'); ?>><?php esc_html_e('自定义 HTML', 'aksrt'); ?></option>
|
|
<option value="gap" <?php selected($mode, 'gap'); ?>><?php esc_html_e('间距', 'aksrt'); ?></option>
|
|
</select>
|
|
</p>
|
|
<p>
|
|
<label for="<?php echo $this->get_field_id('title'); ?>"><?php esc_html_e('标题(仅 HTML 模式,可选):', 'aksrt'); ?></label>
|
|
<input class="widefat" type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title'] ?? ''); ?>">
|
|
</p>
|
|
<p>
|
|
<label for="<?php echo $this->get_field_id('content'); ?>"><?php esc_html_e('HTML 内容:', 'aksrt'); ?></label>
|
|
<textarea class="widefat" rows="6" id="<?php echo $this->get_field_id('content'); ?>" name="<?php echo $this->get_field_name('content'); ?>"><?php echo esc_textarea($instance['content'] ?? ''); ?></textarea>
|
|
</p>
|
|
<p>
|
|
<label for="<?php echo $this->get_field_id('gap_height'); ?>"><?php esc_html_e('间距高度(px,仅间距模式):', 'aksrt'); ?></label>
|
|
<input class="tiny-text" type="number" min="0" max="500" id="<?php echo $this->get_field_id('gap_height'); ?>" name="<?php echo $this->get_field_name('gap_height'); ?>" value="<?php echo (int) ($instance['gap_height'] ?? 20); ?>">
|
|
</p>
|
|
<?php
|
|
}
|
|
|
|
public function update($new_instance, $old_instance): array {
|
|
return [
|
|
'mode' => in_array($new_instance['mode'] ?? '', ['html', 'gap'], true) ? $new_instance['mode'] : 'html',
|
|
'title' => sanitize_text_field($new_instance['title'] ?? ''),
|
|
'content' => wp_kses_post($new_instance['content'] ?? ''),
|
|
'gap_height' => max(0, min(500, (int) ($new_instance['gap_height'] ?? 20))),
|
|
];
|
|
}
|
|
}
|