| @@ -1,6 +1,10 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit( 0 ); | |
| 5 | +} | |
| 6 | + | |
| 3 | 7 | // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. |
| 4 | 8 | |
| 5 | 9 | add_action( 'widgets_init', 'jetpack_goodreads_widget_init' ); |
| 6 | 10 | /** |
| @@ -44,11 +48,8 @@ | ||
| 44 | 48 | 'currently-reading' => __( 'Currently Reading', 'jetpack' ), |
| 45 | 49 | 'to-read' => _x( 'To Read', 'my list of books to read', 'jetpack' ), |
| 46 | 50 | ); |
| 47 | 51 | |
| 48 | - if ( is_active_widget( '', '', 'wpcom-goodreads' ) || is_customize_preview() ) { | |
| 49 | - add_action( 'wp_print_styles', array( $this, 'enqueue_style' ) ); | |
| 50 | - } | |
| 51 | 52 | add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) ); |
| 52 | 53 | } |
| 53 | 54 | |
| 54 | 55 | /** |
| @@ -85,9 +86,9 @@ | ||
| 85 | 86 | /** This action is documented in modules/widgets/gravatar-profile.php */ |
| 86 | 87 | do_action( 'jetpack_stats_extra', 'widget_view', 'goodreads' ); |
| 87 | 88 | |
| 88 | 89 | /** This filter is documented in core/src/wp-includes/default-widgets.php */ |
| 89 | - $title = apply_filters( 'widget_title', isset( $instance['title'] ) ? $instance['title'] : '' ); | |
| 90 | + $title = apply_filters( 'widget_title', $instance['title'] ?? '' ); | |
| 90 | 91 | |
| 91 | 92 | if ( empty( $instance['user_id'] ) || 'invalid' === $instance['user_id'] ) { |
| 92 | 93 | if ( current_user_can( 'edit_theme_options' ) ) { |
| 93 | 94 | echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| @@ -113,8 +114,11 @@ | ||
| 113 | 114 | if ( ! array_key_exists( $instance['shelf'], $this->shelves ) ) { |
| 114 | 115 | return; |
| 115 | 116 | } |
| 116 | 117 | |
| 118 | + // Enqueue front end assets. | |
| 119 | + $this->enqueue_style(); | |
| 120 | + | |
| 117 | 121 | $instance['user_id'] = absint( $instance['user_id'] ); |
| 118 | 122 | |
| 119 | 123 | // Set widget ID based on shelf. |
| 120 | 124 | $this->goodreads_widget_id = $instance['user_id'] . '_' . $instance['shelf']; |
| @@ -126,9 +130,9 @@ | ||
| 126 | 130 | |
| 127 | 131 | echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 128 | 132 | echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 129 | 133 | |
| 130 | - $goodreads_url = 'https://www.goodreads.com/review/custom_widget/' . rawurlencode( $instance['user_id'] ) . '.' . rawurlencode( $instance['title'] ) . ':%20' . rawurlencode( $instance['shelf'] ) . '?cover_position=&cover_size=small&num_books=5&order=d&shelf=' . rawurlencode( $instance['shelf'] ) . '&sort=date_added&widget_bg_transparent=&widget_id=' . rawurlencode( $this->goodreads_widget_id ); | |
| 134 | + $goodreads_url = 'https://www.goodreads.com/review/custom_widget/' . rawurlencode( (string) $instance['user_id'] ) . '.' . rawurlencode( $instance['title'] ) . ':%20' . rawurlencode( $instance['shelf'] ) . '?cover_position=&cover_size=small&num_books=5&order=d&shelf=' . rawurlencode( $instance['shelf'] ) . '&sort=date_added&widget_bg_transparent=&widget_id=' . rawurlencode( $this->goodreads_widget_id ); | |
| 131 | 135 | |
| 132 | 136 | echo '<div class="jetpack-goodreads-legacy-widget gr_custom_widget" id="gr_custom_widget_' . esc_attr( $this->goodreads_widget_id ) . '"></div>' . "\n"; |
| 133 | 137 | echo '<script src="' . esc_url( $goodreads_url ) . '"></script>' . "\n"; // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript |
| 134 | 138 | |
| @@ -186,8 +190,9 @@ | ||
| 186 | 190 | /** |
| 187 | 191 | * Outputs the widget settings form. |
| 188 | 192 | * |
| 189 | 193 | * @param array $instance Current settings. |
| 194 | + * @return string|void | |
| 190 | 195 | */ |
| 191 | 196 | public function form( $instance ) { |
| 192 | 197 | // Defaults. |
| 193 | 198 | $instance = wp_parse_args( |