| 1 |
<?php |
| 2 |
/** |
| 3 |
* Toggle Widget |
| 4 |
* |
| 5 |
* @package Hootkit |
| 6 |
*/ |
| 7 |
|
| 8 |
// If this file is called directly, abort. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
die; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Class HootKit_Toggle_Widget |
| 15 |
*/ |
| 16 |
class HootKit_Toggle_Widget extends HK_Widget { |
| 17 |
|
| 18 |
function __construct() { |
| 19 |
|
| 20 |
$id = 'toggle'; |
| 21 |
|
| 22 |
$settings['id'] = "hootkit-{$id}"; |
| 23 |
$settings['name'] = hootkit()->get_string( $id ); |
| 24 |
$settings['widget_options'] = array( |
| 25 |
'description' => __( 'Display Toggle', 'hootkit' ), |
| 26 |
); |
| 27 |
$settings['control_options'] = array(); |
| 28 |
$settings['form_options'] = array( |
| 29 |
'title' => array( |
| 30 |
'name' => __( 'Title (optional)', 'hootkit' ), |
| 31 |
'type' => 'text', |
| 32 |
), |
| 33 |
'subtitle' => array( |
| 34 |
'name' => __( 'Sub Title (optional)', 'hootkit' ), |
| 35 |
'type' => 'text', |
| 36 |
), |
| 37 |
'onlyone' => array( |
| 38 |
'name' => __( 'Open only one Toggle Box at a time', 'hootkit' ), |
| 39 |
'type' => 'checkbox', |
| 40 |
), |
| 41 |
'boxes' => array( |
| 42 |
'name' => __( 'Toggle Boxes', 'hootkit' ), |
| 43 |
'type' => 'group', |
| 44 |
'options' => array( |
| 45 |
'item_name' => __( 'Box', 'hootkit' ), |
| 46 |
'maxlimit' => 4, |
| 47 |
'limitmsg' => __( 'Only 4 toggle boxes available in the Free version of the theme.', 'hootkit' ), |
| 48 |
'sortable' => true, |
| 49 |
), |
| 50 |
'fields' => array( |
| 51 |
'title' => array( |
| 52 |
'name' => __( 'Toggle Heading', 'hootkit' ), |
| 53 |
'type' => 'text', |
| 54 |
), |
| 55 |
'content' => array( |
| 56 |
'name' => __( 'Toggle Content', 'hootkit' ), |
| 57 |
'type' => 'textarea', |
| 58 |
), |
| 59 |
'open' => array( |
| 60 |
'name' => __( "Check this to set Toggle box as 'open'. By default, toggle boxes are closed on page load.", 'hootkit' ), |
| 61 |
'type' => 'checkbox', |
| 62 |
), |
| 63 |
), |
| 64 |
), |
| 65 |
'customcss' => array( |
| 66 |
'name' => __( 'Widget Options', 'hootkit' ), |
| 67 |
'type' => 'collapse', |
| 68 |
'fields' => array( |
| 69 |
'class' => array( |
| 70 |
'name' => __( 'Custom CSS Class', 'hootkit' ), |
| 71 |
'desc' => __( 'Give this widget a custom css classname', 'hootkit' ), |
| 72 |
'type' => 'text', |
| 73 |
), |
| 74 |
'mt' => array( |
| 75 |
'name' => __( 'Margin Top', 'hootkit' ), |
| 76 |
'desc' => __( '(in pixels) Leave empty to load default margins.<br>Hint: You can use negative numbers also.', 'hootkit' ), |
| 77 |
'type' => 'text', |
| 78 |
'settings' => array( 'size' => 3 ), |
| 79 |
'sanitize' => 'integer', |
| 80 |
), |
| 81 |
'mb' => array( |
| 82 |
'name' => __( 'Margin Bottom', 'hootkit' ), |
| 83 |
'desc' => __( '(in pixels) Leave empty to load default margins.<br>Hint: You can use negative numbers also.', 'hootkit' ), |
| 84 |
'type' => 'text', |
| 85 |
'settings' => array( 'size' => 3 ), |
| 86 |
'sanitize' => 'integer', |
| 87 |
), |
| 88 |
), |
| 89 |
), |
| 90 |
); |
| 91 |
|
| 92 |
if ( ! hootkit()->supports( 'widget-subtitle' ) ) { |
| 93 |
unset( $settings['form_options']['subtitle'] ); |
| 94 |
} |
| 95 |
|
| 96 |
$settings = apply_filters( 'hootkit_toggle_widget_settings', $settings ); |
| 97 |
|
| 98 |
parent::__construct( $settings['id'], $settings['name'], $settings['widget_options'], $settings['control_options'], $settings['form_options'] ); |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Display the widget content |
| 104 |
*/ |
| 105 |
function display_widget( $instance, $before_title = '', $title = '', $after_title = '' ) { |
| 106 |
// Allow theme/child-themes to use their own template |
| 107 |
$widget_template = hoot_get_widget( 'toggle', false ); |
| 108 |
// Option to overwrite variables to keep html tags in title later sanitized during display => skips 'widget_title' filter (esc_html hooked) action on title; (Possibly redundant as html is sanitized in title during save) |
| 109 |
if ( apply_filters( 'hootkit_display_widget_extract_overwrite', false, 'toggle' ) ) extract( $instance, EXTR_OVERWRITE ); else extract( $instance, EXTR_SKIP ); |
| 110 |
// Fire up the template |
| 111 |
if ( is_string( $widget_template ) && file_exists( $widget_template ) ) include ( $widget_template ); |
| 112 |
} |
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Register Widget |
| 118 |
*/ |
| 119 |
function hootkit_toggle_register(){ |
| 120 |
register_widget( 'HootKit_Toggle_Widget' ); |
| 121 |
} |
| 122 |
add_action( 'widgets_init', 'hootkit_toggle_register' ); |