PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
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 13.8.3 All 506 releases
← All changes | modules/widgets/flickr.php +45 -11 12.0.3 → 16.3-a.5 View file →
@@ -1,5 +1,17 @@
1 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 +/**
3 + * Flickr Widget, pulling recent photos from Flickr using RSS feed.
4 + *
5 + * This widget is now deprecated.
6 + * Existing widgets will continue to work, but Flickr no longer displays RSS feeds,
7 + * making it impossible for site owners to configure this widget.
8 + * We consequently only register the widget if it's already in use on the site.
9 + *
10 + * @see https://github.com/Automattic/jetpack/issues/39824
11 + *
12 + * @package automattic/jetpack
13 + */
2 14
3 15 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
4 16
5 17 /**
@@ -5,9 +17,9 @@
5 17 /**
6 18 * Disable direct access/execution to/of the widget code.
7 19 */
8 20 if ( ! defined( 'ABSPATH' ) ) {
9 - exit;
21 + exit( 0 );
10 22 }
11 23
12 24 if ( ! class_exists( 'Jetpack_Flickr_Widget' ) ) {
13 25 /**
@@ -29,12 +41,8 @@
29 41 'customize_selective_refresh' => true,
30 42 ),
31 43 array()
32 44 );
33 -
34 - if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) {
35 - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ) );
36 - }
37 45 }
38 46
39 47 /**
40 48 * Enqueue style.
@@ -62,8 +70,12 @@
62 70
63 71 /**
64 72 * Front-end display of the widget.
65 73 *
74 + * @html-template-var array $instance
75 + * @html-template-var string|null $flickr_home
76 + * @html-template-var string $photos';
77 + *
66 78 * @param array $args Widget arguments.
67 79 * @param array $instance Saved values from database.
68 80 */
69 81 public function widget( $args, $instance ) {
@@ -68,8 +80,11 @@
68 80 */
69 81 public function widget( $args, $instance ) {
70 82 $instance = wp_parse_args( $instance, $this->defaults() );
71 83
84 + // Enqueue front end assets.
85 + $this->enqueue_style();
86 +
72 87 if ( ! empty( $instance['flickr_rss_url'] ) ) {
73 88 /*
74 89 * Parse the URL, and rebuild a URL that's sure to display images.
75 90 * Some Flickr Feeds do not display images by default.
@@ -79,9 +94,9 @@
79 94 // Is it a Flickr Feed.
80 95 if (
81 96 ! empty( $flickr_parameters['host'] )
82 97 && ! empty( $flickr_parameters['query'] )
83 - && false !== strpos( $flickr_parameters['host'], 'flickr' )
98 + && str_contains( $flickr_parameters['host'], 'flickr' )
84 99 ) {
85 100 parse_str( $flickr_parameters['query'], $vars );
86 101
87 102 // Do we have an ID in the feed? Let's continue.
@@ -89,9 +104,9 @@
89 104
90 105 // Flickr Feeds can be used for groups or for individuals.
91 106 if (
92 107 ! empty( $flickr_parameters['path'] )
93 - && false !== strpos( $flickr_parameters['path'], 'groups' )
108 + && str_contains( $flickr_parameters['path'], 'groups' )
94 109 ) {
95 110 $feed_url = 'https://api.flickr.com/services/feeds/groups_pool.gne';
96 111 } else {
97 112 $feed_url = 'https://api.flickr.com/services/feeds/photos_public.gne';
@@ -113,9 +128,10 @@
113 128 }
114 129
115 130 $rss = fetch_feed( $rss_url );
116 131
117 - $photos = '';
132 + $photos = '';
133 + $flickr_home = null; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Used in flickr/widget.php template file.
118 134 if ( ! is_wp_error( $rss ) ) {
119 135 foreach ( $rss->get_items( 0, $instance['items'] ) as $photo ) {
120 136 switch ( $instance['flickr_image_size'] ) {
121 137 case 'thumbnail':
@@ -127,8 +143,11 @@
127 143 break;
128 144 case 'large':
129 145 $src = $photo->get_enclosure()->get_link();
130 146 break;
147 + default:
148 + $src = '';
149 + break;
131 150 }
132 151
133 152 $photos .= '<a href="' . esc_url( $photo->get_permalink(), array( 'http', 'https' ) ) . '" ';
134 153 if ( $instance['target'] ) {
@@ -138,10 +157,10 @@
138 157 $photos .= 'alt="' . esc_attr( $photo->get_title() ) . '" ';
139 158 $photos .= 'title="' . esc_attr( $photo->get_title() ) . '" ';
140 159 $photos .= ' /></a>';
141 160 }
142 - if ( ! empty( $photos ) && class_exists( 'Jetpack_Photon' ) && Jetpack::is_module_active( 'photon' ) ) {
143 - $photos = Jetpack_Photon::filter_the_content( $photos );
161 + if ( ! empty( $photos ) ) {
162 + $photos = apply_filters( 'jetpack_image_cdn_content', $photos );
144 163 }
145 164
146 165 $flickr_home = $rss->get_link(); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Used in flickr/widget.php template file.
147 166 }
@@ -166,9 +185,12 @@
166 185
167 186 /**
168 187 * Back-end widget form.
169 188 *
189 + * @html-template-var array $instance
190 + *
170 191 * @param array $instance Previously saved values from database.
192 + * @return string|void
171 193 */
172 194 public function form( $instance ) {
173 195 $instance = wp_parse_args( $instance, $this->defaults() );
174 196 require __DIR__ . '/flickr/form.php';
@@ -220,8 +242,20 @@
220 242 /**
221 243 * Register Jetpack_Flickr_Widget widget.
222 244 */
223 245 function jetpack_register_flickr_widget() {
224 - register_widget( 'Jetpack_Flickr_Widget' );
246 + $transient = 'jetpack_flickr_widget::is_active';
247 + $has_widget = get_transient( $transient );
248 +
249 + if ( false === $has_widget ) {
250 + $is_active_widget = is_active_widget( false, false, 'flickr', false );
251 + $has_widget = (int) ! empty( $is_active_widget );
252 + set_transient( $transient, $has_widget, 1 * HOUR_IN_SECONDS );
253 + }
254 +
255 + // [DEPRECATION]: Only register widget if active widget exists already
256 + if ( $has_widget ) {
257 + register_widget( 'Jetpack_Flickr_Widget' );
258 + }
225 259 }
226 260 add_action( 'widgets_init', 'jetpack_register_flickr_widget' );
227 261 }