Skip to content

Commit

Permalink
Issue #864: Ensure register_widgets() fires on 'widget_init.'
Browse files Browse the repository at this point in the history
Before, I had registered this too late.
Also, move is_amp_endpoint() conditional to widget().
This isn't ideal.
But that function isn't available before 'parse_query.'
And that runs after 'widgets_init.'
Also, is seems that all but 2 of these subclass widgets will be removed.
@todo: Look at a regression, where the 'amp-form' extension isn't included.
  • Loading branch information
Ryan Kienstra committed Jan 23, 2018
1 parent a0b9848 commit 6053f9a
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function amp_after_setup_theme() {
}

add_action( 'init', 'amp_init' );
add_action( 'widgets_init', 'AMP_Theme_Support::register_widgets' );
add_action( 'admin_init', 'AMP_Options_Manager::register_settings' );
add_filter( 'amp_post_template_analytics', 'amp_add_custom_analytics' );
add_action( 'wp_loaded', 'amp_post_meta_box' );
Expand Down
2 changes: 0 additions & 2 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ public static function register_paired_hooks() {
*/
public static function register_hooks() {

add_action( 'widgets_init', array( __CLASS__, 'register_widgets' ) );

// Remove core actions which are invalid AMP.
remove_action( 'wp_head', 'locale_stylesheet' );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
Expand Down
8 changes: 8 additions & 0 deletions includes/widgets/class-amp-widget-archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class AMP_Widget_Archives extends WP_Widget_Archives {
* @return void.
*/
public function widget( $args, $instance ) {
if ( ! is_amp_endpoint() ) {
parent::widget( $args, $instance );
return;
}

ob_start();
$c = ! empty( $instance['count'] ) ? '1' : '0';
$d = ! empty( $instance['dropdown'] ) ? '1' : '0';

Expand Down Expand Up @@ -89,6 +95,8 @@ public function widget( $args, $instance ) {
<?php
endif;
echo wp_kses_post( $args['after_widget'] );
$output = ob_get_clean();
echo AMP_Theme_Support::filter_the_content( $output ); // WPCS: XSS ok.
}

}
8 changes: 8 additions & 0 deletions includes/widgets/class-amp-widget-categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public function modify_select( $dropdown ) {
* @return void.
*/
public function widget( $args, $instance ) {
if ( ! is_amp_endpoint() ) {
parent::widget( $args, $instance );
return;
}

ob_start();
static $first_dropdown = true;
$title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Categories', 'default' );
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
Expand Down Expand Up @@ -79,6 +85,8 @@ public function widget( $args, $instance ) {
<?php
endif;
echo wp_kses_post( $args['after_widget'] );
$output = ob_get_clean();
echo AMP_Theme_Support::filter_the_content( $output ); // WPCS: XSS ok.
}

}
5 changes: 5 additions & 0 deletions includes/widgets/class-amp-widget-media-audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class AMP_Widget_Media_Audio extends WP_Widget_Media_Audio {
* @return void.
*/
public function render_media( $instance ) {
if ( ! is_amp_endpoint() ) {
parent::render_media( $instance );
return;
}

ob_start();
parent::render_media( $instance );
$output = ob_get_clean();
Expand Down
5 changes: 5 additions & 0 deletions includes/widgets/class-amp-widget-media-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class AMP_Widget_Media_Gallery extends WP_Widget_Media_Gallery {
* @return void.
*/
public function render_media( $instance ) {
if ( ! is_amp_endpoint() ) {
parent::render_media( $instance );
return;
}

ob_start();
parent::render_media( $instance );
$output = ob_get_clean();
Expand Down
5 changes: 5 additions & 0 deletions includes/widgets/class-amp-widget-media-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class AMP_Widget_Media_Image extends WP_Widget_Media_Image {
* @return void.
*/
public function render_media( $instance ) {
if ( ! is_amp_endpoint() ) {
parent::render_media( $instance );
return;
}

ob_start();
parent::render_media( $instance );
$output = ob_get_clean();
Expand Down
5 changes: 5 additions & 0 deletions includes/widgets/class-amp-widget-media-video.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class AMP_Widget_Media_Video extends WP_Widget_Media_Video {
* @return void.
*/
public function render_media( $instance ) {
if ( ! is_amp_endpoint() ) {
parent::render_media( $instance );
return;
}

ob_start();
parent::render_media( $instance );
$output = ob_get_clean();
Expand Down
4 changes: 3 additions & 1 deletion includes/widgets/class-amp-widget-recent-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class AMP_Widget_Recent_Comments extends WP_Widget_Recent_Comments {
*/
public function __construct() {
parent::__construct();
add_filter( 'show_recent_comments_widget_style', '__return_false' );
if ( is_amp_endpoint() ) {
add_filter( 'show_recent_comments_widget_style', '__return_false' );
}
}

}
5 changes: 5 additions & 0 deletions includes/widgets/class-amp-widget-rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class AMP_Widget_RSS extends WP_Widget_RSS {
* @return void.
*/
public function widget( $args, $instance ) {
if ( is_amp_endpoint() ) {
parent::widget( $args, $instance );
return;
}

ob_start();
parent::widget( $args, $instance );
$output = ob_get_clean();
Expand Down

0 comments on commit 6053f9a

Please sign in to comment.