| 1 |
<?php |
| 2 |
/** |
| 3 |
* Widget Social Links |
| 4 |
* |
| 5 |
* @link https://codesupply.co |
| 6 |
* @since 1.0.0 |
| 7 |
* |
| 8 |
* @package Powerkit |
| 9 |
* @subpackage Powerkit/widgets |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Widget Social Links |
| 14 |
*/ |
| 15 |
class Powerkit_Social_Links_Widget extends WP_Widget { |
| 16 |
|
| 17 |
/** |
| 18 |
* Sets up a new widget instance. |
| 19 |
*/ |
| 20 |
public function __construct() { |
| 21 |
|
| 22 |
$this->default_settings = apply_filters( 'powerkit_social_links_widget_settings', array( |
| 23 |
'title' => esc_html__( 'Social Links', 'powerkit' ), |
| 24 |
'template' => 'inline', |
| 25 |
'scheme' => 'light', |
| 26 |
'cache' => true, |
| 27 |
'labels' => true, |
| 28 |
'titles' => true, |
| 29 |
'counts' => true, |
| 30 |
'maximum' => -1, |
| 31 |
'mode' => apply_filters( 'powerkit_social_links_counter_mode', 'mixed' ), |
| 32 |
) ); |
| 33 |
|
| 34 |
$widget_details = array( |
| 35 |
'classname' => 'powerkit_social_links_widget', |
| 36 |
'description' => esc_html__( 'Add a list of social links with fan counts to your sidebar.', 'powerkit' ), |
| 37 |
); |
| 38 |
parent::__construct( 'powerkit_social_links_widget', esc_html__( 'Social Links', 'powerkit' ), $widget_details ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Outputs the content for the current widget instance. |
| 43 |
* |
| 44 |
* @param array $args Display arguments including 'before_title', 'after_title', |
| 45 |
* 'before_widget', and 'after_widget'. |
| 46 |
* @param array $instance Settings for the current widget instance. |
| 47 |
*/ |
| 48 |
public function widget( $args, $instance ) { |
| 49 |
$params = array_merge( $this->default_settings, $instance ); |
| 50 |
|
| 51 |
// Before Widget. |
| 52 |
echo $args['before_widget']; // XSS OK. |
| 53 |
?> |
| 54 |
|
| 55 |
<div class="widget-body"> |
| 56 |
<?php |
| 57 |
|
| 58 |
// Title. |
| 59 |
if ( $params['title'] ) { |
| 60 |
echo $args['before_title'] . apply_filters( 'widget_title', $params['title'], $instance, $this->id_base ) . $args['after_title']; // XSS. |
| 61 |
} |
| 62 |
|
| 63 |
powerkit_social_links_appearance( $params ); |
| 64 |
?> |
| 65 |
</div> |
| 66 |
|
| 67 |
<?php |
| 68 |
|
| 69 |
// After Widget. |
| 70 |
echo $args['after_widget']; // XSS OK. |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Handles updating settings for the current widget instance. |
| 75 |
* |
| 76 |
* @param array $new_instance New settings for this instance as input by the user via |
| 77 |
* WP_Widget::form(). |
| 78 |
* @param array $old_instance Old settings for this instance. |
| 79 |
* @return array Settings to save or bool false to cancel saving. |
| 80 |
*/ |
| 81 |
public function update( $new_instance, $old_instance ) { |
| 82 |
$instance = $new_instance; |
| 83 |
|
| 84 |
// Labels. |
| 85 |
if ( ! isset( $instance['labels'] ) ) { |
| 86 |
$instance['labels'] = false; |
| 87 |
} |
| 88 |
|
| 89 |
// Titles. |
| 90 |
if ( ! isset( $instance['titles'] ) ) { |
| 91 |
$instance['titles'] = false; |
| 92 |
} |
| 93 |
|
| 94 |
// Counts. |
| 95 |
if ( ! isset( $instance['counts'] ) ) { |
| 96 |
$instance['counts'] = false; |
| 97 |
} |
| 98 |
|
| 99 |
return $instance; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Outputs the widget settings form. |
| 104 |
* |
| 105 |
* @param array $instance Current settings. |
| 106 |
*/ |
| 107 |
public function form( $instance ) { |
| 108 |
$params = array_merge( $this->default_settings, $instance ); |
| 109 |
|
| 110 |
$templates = apply_filters( 'powerkit_social_links_templates', array() ); |
| 111 |
$color_schemes = apply_filters( 'powerkit_social_links_color_schemes', array() ); |
| 112 |
?> |
| 113 |
<!-- Title --> |
| 114 |
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'powerkit' ); ?></label> |
| 115 |
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $params['title'] ); ?>" /></p> |
| 116 |
|
| 117 |
<!-- Labels --> |
| 118 |
<p><input id="<?php echo esc_attr( $this->get_field_id( 'labels' ) ); ?>" class="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'labels' ) ); ?>" type="checkbox" <?php checked( (bool) $params['labels'] ); ?> /> |
| 119 |
<label for="<?php echo esc_attr( $this->get_field_id( 'labels' ) ); ?>"><?php esc_html_e( 'Display labels', 'powerkit' ); ?></label></p> |
| 120 |
|
| 121 |
<!-- Titles --> |
| 122 |
<p><input id="<?php echo esc_attr( $this->get_field_id( 'titles' ) ); ?>" class="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'titles' ) ); ?>" type="checkbox" <?php checked( (bool) $params['titles'] ); ?> /> |
| 123 |
<label for="<?php echo esc_attr( $this->get_field_id( 'titles' ) ); ?>"><?php esc_html_e( 'Display titles', 'powerkit' ); ?></label></p> |
| 124 |
|
| 125 |
<!-- Сounts --> |
| 126 |
<p><input id="<?php echo esc_attr( $this->get_field_id( 'counts' ) ); ?>" class="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'counts' ) ); ?>" type="checkbox" <?php checked( (bool) $params['counts'] ); ?> /> |
| 127 |
<label for="<?php echo esc_attr( $this->get_field_id( 'counts' ) ); ?>"><?php esc_html_e( 'Display counts', 'powerkit' ); ?></label></p> |
| 128 |
|
| 129 |
<!-- Maximum Number of Social Links --> |
| 130 |
<p> |
| 131 |
<label for="<?php echo esc_attr( $this->get_field_id( 'maximum' ) ); ?>"><?php esc_html_e( 'Maximum number of social links:', 'powerkit' ); ?></label> |
| 132 |
<input id="<?php echo esc_attr( $this->get_field_id( 'maximum' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'maximum' ) ); ?>" type="text" value="<?php echo (int) $params['maximum']; ?>" size="3" /> |
| 133 |
</p> |
| 134 |
|
| 135 |
<p class="help"> |
| 136 |
<?php echo esc_html__( 'Input -1 to remove the maximum limit of the social links.', 'powerkit' ); ?> |
| 137 |
</p> |
| 138 |
|
| 139 |
<!-- Template --> |
| 140 |
<?php if ( count( (array) $templates ) > 1 ) : ?> |
| 141 |
<p><label for="<?php echo esc_attr( $this->get_field_id( 'Template' ) ); ?>"><?php esc_html_e( 'Template:', 'powerkit' ); ?></label> |
| 142 |
<select name="<?php echo esc_attr( $this->get_field_name( 'template' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'template' ) ); ?>" class="widefat"> |
| 143 |
<?php |
| 144 |
if ( $templates ) { |
| 145 |
foreach ( $templates as $key => $item ) { |
| 146 |
if ( isset( $item['public'] ) && false === $item['public'] ) { |
| 147 |
continue; |
| 148 |
} |
| 149 |
?> |
| 150 |
<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $params['template'], $key ); ?>><?php echo esc_attr( $item['name'] ); ?></option> |
| 151 |
<?php |
| 152 |
} |
| 153 |
} |
| 154 |
?> |
| 155 |
</select> |
| 156 |
</p> |
| 157 |
<?php endif; ?> |
| 158 |
|
| 159 |
<!-- Color scheme --> |
| 160 |
<?php if ( count( (array) $color_schemes ) > 1 ) : ?> |
| 161 |
<p><label for="<?php echo esc_attr( $this->get_field_id( 'Template' ) ); ?>"><?php esc_html_e( 'Color scheme:', 'powerkit' ); ?></label> |
| 162 |
<select name="<?php echo esc_attr( $this->get_field_name( 'scheme' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'scheme' ) ); ?>" class="widefat"> |
| 163 |
<?php |
| 164 |
if ( $color_schemes ) { |
| 165 |
foreach ( $color_schemes as $key => $item ) { |
| 166 |
if ( isset( $item['public'] ) && false === $item['public'] ) { |
| 167 |
continue; |
| 168 |
} |
| 169 |
?> |
| 170 |
<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $params['scheme'], $key ); ?>><?php echo esc_attr( $item['name'] ); ?></option> |
| 171 |
<?php |
| 172 |
} |
| 173 |
} |
| 174 |
?> |
| 175 |
</select> |
| 176 |
</p> |
| 177 |
<?php endif; ?> |
| 178 |
|
| 179 |
<p class="pk-alert pk-alert-warning"> |
| 180 |
<?php |
| 181 |
echo sprintf( '<a href="%2$s" target="_blank">%1$s</a>', esc_html__( 'Configure Social Links', 'powerkit' ), esc_url( powerkit_get_page_url( 'social_links' ) ) ); |
| 182 |
?> |
| 183 |
</p> |
| 184 |
<?php |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Register Widget |
| 190 |
*/ |
| 191 |
function powerkit_widget_init_social_links() { |
| 192 |
register_widget( 'Powerkit_Social_Links_Widget' ); |
| 193 |
} |
| 194 |
add_action( 'widgets_init', 'powerkit_widget_init_social_links' ); |
| 195 |
|