-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5577 from google/enhancement/5451-twg-widget
Enhancement/5451 twg widget
- Loading branch information
Showing
2 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
includes/Modules/Thank_With_Google/Supporter_Wall_Widget.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
/** | ||
* Class Google\Site_Kit\Modules\Thank_With_Google\Supporter_Wall_Widget | ||
* | ||
* @package Google\Site_Kit\Modules\Thank_With_Google | ||
* @copyright 2022 Google LLC | ||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 | ||
* @link https://sitekit.withgoogle.com | ||
*/ | ||
|
||
namespace Google\Site_Kit\Modules\Thank_With_Google; | ||
|
||
use WP_Widget; | ||
|
||
/** | ||
* The supporter wall widget for Thank with Google. | ||
* | ||
* @since n.e.x.t | ||
* @access private | ||
* @ignore | ||
*/ | ||
class Supporter_Wall_Widget extends WP_Widget { | ||
|
||
const WIDGET_ID = 'googlesitekit-twg-supporter-wall'; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @since n.e.x.t | ||
*/ | ||
public function __construct() { | ||
parent::__construct( | ||
self::WIDGET_ID, | ||
__( 'Thank with Google: Supporter Wall', 'google-site-kit' ) | ||
); | ||
} | ||
|
||
/** | ||
* Renders the widget form. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @param array $instance The widget instance. | ||
*/ | ||
public function form( $instance ) { | ||
$title = ! empty( $instance['title'] ) ? $instance['title'] : ''; | ||
$title_id = $this->get_field_id( 'title' ); | ||
|
||
?> | ||
<p> | ||
<label for="<?php echo esc_attr( $title_id ); ?>"> | ||
<?php esc_html_e( 'Title:', 'google-site-kit' ); ?> | ||
</label> | ||
<input | ||
type="text" | ||
id="<?php echo esc_attr( $title_id ); ?>" | ||
class="widefat" | ||
name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" | ||
value="<?php echo esc_attr( $title ); ?>" | ||
> | ||
</p> | ||
<p class="description"> | ||
<?php esc_html_e( 'The color of the supporter wall is based on the color theme you selected in the Thank with Google module settings.', 'google-site-kit' ); ?> | ||
</p> | ||
<?php | ||
} | ||
|
||
/** | ||
* Updates the widget settings. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @param array $new_instance The array with new settings for the widget. | ||
* @param array $old_instance The array with old settings for the widget. | ||
* @return array New settings widgets. | ||
*/ | ||
public function update( $new_instance, $old_instance ) { | ||
$instance = array(); | ||
|
||
$instance['title'] = ! empty( $new_instance['title'] ) | ||
? sanitize_text_field( $new_instance['title'] ) | ||
: ''; | ||
|
||
return $instance; | ||
} | ||
|
||
/** | ||
* Displays the widget. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @param array $args The widget arguments. | ||
* @param array $instance The widget settings. | ||
*/ | ||
public function widget( $args, $instance ) { | ||
wp_enqueue_script( 'google_thankjs' ); | ||
|
||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | ||
|
||
if ( ! empty( $instance['title'] ) ) { | ||
echo $args['before_title'], apply_filters( 'widget_title', $instance['title'] ), $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | ||
} | ||
|
||
echo '<div twg-thank-wall style="width:100%;height:490px;min-height:150px;overflow:hidden;border:1px solid #e3e3e3;border-radius:15px;margin:20px 0"></div>'; | ||
|
||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | ||
} | ||
|
||
} |