PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
← All changes | modules/widgets/goodreads.php +13 -8 13.3.3 → 16.3-beta View file →
@@ -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
@@ -167,16 +171,16 @@
167 171 */
168 172 public function update( $new_instance, $old_instance ) {
169 173 $instance = $old_instance;
170 174
171 - $instance['user_id'] = trim( wp_kses( stripslashes( $new_instance['user_id'] ), array() ) );
175 + $instance['user_id'] = trim( wp_kses( stripslashes( $new_instance['user_id'] ?? '' ), array() ) );
172 176 if ( ! empty( $instance['user_id'] ) && ( ! isset( $old_instance['user_id'] ) || $instance['user_id'] !== $old_instance['user_id'] ) ) {
173 177 if ( ! $this->goodreads_user_id_exists( $instance['user_id'] ) ) {
174 178 $instance['user_id'] = 'invalid';
175 179 }
176 180 }
177 - $instance['title'] = wp_kses( stripslashes( $new_instance['title'] ), array() );
178 - $shelf = wp_kses( stripslashes( $new_instance['shelf'] ), array() );
181 + $instance['title'] = wp_kses( stripslashes( $new_instance['title'] ?? '' ), array() );
182 + $shelf = wp_kses( stripslashes( $new_instance['shelf'] ?? '' ), array() );
179 183 if ( array_key_exists( $shelf, $this->shelves ) ) {
180 184 $instance['shelf'] = $shelf;
181 185 }
182 186
@@ -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(