55 *
66 * @package button-widget
77 * @author MyPreview (Github: @mahdiyazdani, @mypreview)
8- * @since 1.1.1
8+ * @since 1.2.0
99 */
1010
1111// Exit if accessed directly.
@@ -47,6 +47,7 @@ public function __construct() {
4747 'text ' => '' ,
4848 'title ' => '' ,
4949 'id ' => '' ,
50+ 'class ' => 'button ' ,
5051 'link ' => '' ,
5152 'target ' => 0 ,
5253 'text_color ' => '' ,
@@ -70,6 +71,7 @@ public function widget( $args, $instance ) {
7071 $ get_text = isset ( $ instance ['text ' ] ) ? $ instance ['text ' ] : $ this ->defaults ['text ' ];
7172 $ get_title = isset ( $ instance ['title ' ] ) ? $ instance ['title ' ] : $ this ->defaults ['title ' ];
7273 $ get_id = isset ( $ instance ['id ' ] ) ? $ instance ['id ' ] : $ this ->defaults ['id ' ];
74+ $ get_class = isset ( $ instance ['class ' ] ) ? $ instance ['class ' ] : $ this ->defaults ['class ' ];
7375 $ get_link = isset ( $ instance ['link ' ] ) ? $ instance ['link ' ] : $ this ->defaults ['link ' ];
7476 $ get_target = isset ( $ instance ['target ' ] ) ? self ::string_to_bool ( $ instance ['target ' ] ) : $ this ->defaults ['target ' ];
7577 $ get_colors [] = ! empty ( $ instance ['text_color ' ] ) ? sprintf ( 'color:%s; ' , sanitize_hex_color ( $ instance ['text_color ' ] ) ) : $ this ->defaults ['text_color ' ];
@@ -81,7 +83,7 @@ public function widget( $args, $instance ) {
8183 return ;
8284 } // End If Statement
8385
84- $ output = sprintf ( '%s<a href="%s" id="%s" title="%s" target="%s" rel="%s" style="%s" class="%s">%s</a>%s ' , $ args ['before_widget ' ], ! empty ( $ get_link ) ? esc_url ( $ get_link ) : '# ' , esc_attr ( $ get_id ), esc_attr ( $ get_title ), $ get_target ? '_blank ' : '_self ' , $ get_target ? 'noopener noreferrer nofollow ' : '' , implode ( '' , $ get_colors ), esc_attr ( apply_filters ( ' button_widget_classname ' , ' button ' ) ), esc_html ( $ get_text ), $ args ['after_widget ' ] );
86+ $ output = sprintf ( '%s<a href="%s" id="%s" title="%s" target="%s" rel="%s" style="%s" class="%s">%s</a>%s ' , $ args ['before_widget ' ], ! empty ( $ get_link ) ? esc_url ( $ get_link ) : '# ' , esc_attr ( $ get_id ), esc_attr ( $ get_title ), $ get_target ? '_blank ' : '_self ' , $ get_target ? 'noopener noreferrer nofollow ' : '' , implode ( '' , $ get_colors ), esc_attr ( $ get_class ), esc_html ( $ get_text ), $ args ['after_widget ' ] );
8587
8688 /**
8789 * Filters the `Button` widget output.
@@ -153,6 +155,23 @@ class="widefat"
153155 value="<?php echo esc_attr ( $ instance ['title ' ] ); ?> "
154156 />
155157 </p>
158+ <p>
159+ <label
160+ for="<?php echo esc_attr ( $ this ->get_field_id ( 'class ' ) ); ?> "
161+ >
162+ <?php
163+ /* translators: %s: Small open and close tags. */
164+ printf ( esc_html_x ( 'CSS Class(es) %1$sSeparate multiple classes with spaces%2$s: ' , 'field label ' , 'button-widget ' ), '<small> ' , '</small> ' );
165+ ?>
166+ </label>
167+ <input
168+ type="text"
169+ class="widefat"
170+ id="<?php echo esc_attr ( $ this ->get_field_id ( 'class ' ) ); ?> "
171+ name="<?php echo esc_attr ( $ this ->get_field_name ( 'class ' ) ); ?> "
172+ value="<?php echo esc_attr ( $ instance ['class ' ] ); ?> "
173+ />
174+ </p>
156175 <p>
157176 <label
158177 for="<?php echo esc_attr ( $ this ->get_field_id ( 'link ' ) ); ?> "
@@ -236,6 +255,7 @@ public function update( $new_instance, $old_instance ) {
236255 $ instance = array ();
237256 $ instance ['text ' ] = sanitize_text_field ( $ new_instance ['text ' ] );
238257 $ instance ['id ' ] = sanitize_text_field ( $ new_instance ['id ' ] );
258+ $ instance ['class ' ] = sanitize_text_field ( $ new_instance ['class ' ] );
239259 $ instance ['title ' ] = sanitize_text_field ( $ new_instance ['title ' ] );
240260 $ instance ['link ' ] = esc_url_raw ( $ new_instance ['link ' ] );
241261 $ instance ['target ' ] = ( ! isset ( $ new_instance ['target ' ] ) ) ? 0 : 1 ;
0 commit comments