PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
← All changes | src/integrations/front-end/open-graph-oembed.php +28 -11 18.428.5 View file →
@@ -34,8 +34,15 @@
34 34 */
35 35 private $post_id;
36 36
37 37 /**
38 + * The post meta.
39 + *
40 + * @var Meta|false
41 + */
42 + private $post_meta;
43 +
44 + /**
38 45 * Returns the conditionals based in which this loadable should be active.
39 46 *
40 47 * @return array
41 48 */
@@ -77,14 +84,17 @@
77 84 * @return array An array of oEmbed data with modified values where appropriate.
78 85 */
79 86 public function set_oembed_data( $data, $post ) {
80 87 // Data to be returned.
81 - $this->data = $data;
82 - $this->post_id = $post->ID;
88 + $this->data = $data;
89 + $this->post_id = $post->ID;
90 + $this->post_meta = $this->meta->for_post( $this->post_id );
83 91
84 - $this->set_title();
85 - $this->set_description();
86 - $this->set_image();
92 + if ( ! empty( $this->post_meta ) ) {
93 + $this->set_title();
94 + $this->set_description();
95 + $this->set_image();
96 + }
87 97
88 98 return $this->data;
89 99 }
90 100
@@ -89,11 +99,13 @@
89 99 }
90 100
91 101 /**
92 102 * Sets the OpenGraph title if configured.
103 + *
104 + * @return void
93 105 */
94 106 protected function set_title() {
95 - $opengraph_title = $this->meta->for_post( $this->post_id )->open_graph_title;
107 + $opengraph_title = $this->post_meta->open_graph_title;
96 108
97 109 if ( ! empty( $opengraph_title ) ) {
98 110 $this->data['title'] = $opengraph_title;
99 111 }
@@ -100,11 +112,13 @@
100 112 }
101 113
102 114 /**
103 115 * Sets the OpenGraph description if configured.
116 + *
117 + * @return void
104 118 */
105 119 protected function set_description() {
106 - $opengraph_description = $this->meta->for_post( $this->post_id )->open_graph_description;
120 + $opengraph_description = $this->post_meta->open_graph_description;
107 121
108 122 if ( ! empty( $opengraph_description ) ) {
109 123 $this->data['description'] = $opengraph_description;
110 124 }
@@ -111,18 +125,21 @@
111 125 }
112 126
113 127 /**
114 128 * Sets the image if it has been configured.
129 + *
130 + * @return void
115 131 */
116 132 protected function set_image() {
117 - $images = $this->meta->for_post( $this->post_id )->open_graph_images;
118 - $image = \reset( $images );
133 + $images = $this->post_meta->open_graph_images;
119 134
120 - if ( empty( $image ) ) {
135 + if ( ! \is_array( $images ) ) {
121 136 return;
122 137 }
123 138
124 - if ( ! isset( $image['url'] ) ) {
139 + $image = \reset( $images );
140 +
141 + if ( empty( $image ) || ! isset( $image['url'] ) ) {
125 142 return;
126 143 }
127 144
128 145 $this->data['thumbnail_url'] = $image['url'];