PluginProbe
WPSSO Core – Complete Schema Markup and Meta Tags / 22.7.0
WPSSO Core – Complete Schema Markup and Meta Tags v22.7.0
22.7.0 22.6.1 22.6.0 22.5.3 22.5.2 22.5.1 22.4.0 22.3.0 22.2.1 22.2.0 22.1.3 22.1.2 22.1.1 22.1.0 22.0.0 21.13.3 21.13.2 trunk 21.13.1
← All changes | lib/edit-media.php +307 -0 22.1.322.7.0 View file →
@@ -1,0 +1,307 @@
1 +<?php
2 +/*
3 + * License: GPLv3
4 + * License URI: https://www.gnu.org/licenses/gpl.txt
5 + * Copyright 2020-2026 Jean-Sebastien Morisset (https://wpsso.com/)
6 + */
7 +
8 +if ( ! defined( 'ABSPATH' ) ) {
9 +
10 + die( 'These aren\'t the droids you\'re looking for.' );
11 +}
12 +
13 +if ( ! defined( 'WPSSO_PLUGINDIR' ) ) {
14 +
15 + die( 'Do. Or do not. There is no try.' );
16 +}
17 +
18 +if ( ! class_exists( 'WpssoEditMedia' ) ) {
19 +
20 + class WpssoEditMedia {
21 +
22 + private $p; // Wpsso class object.
23 +
24 + public function __construct( &$plugin ) {
25 +
26 + $this->p =& $plugin;
27 +
28 + if ( $this->p->debug->enabled ) {
29 +
30 + $this->p->debug->mark();
31 + }
32 +
33 + /*
34 + * See WpssoAbstractWpMeta->get_document_sso_tabs().
35 + */
36 + $this->p->util->add_plugin_filters( $this, array(
37 + 'mb_sso_edit_media_rows' => 4,
38 + 'mb_sso_edit_media_prio_image_rows' => 5,
39 + 'mb_sso_edit_media_twitter_rows' => 5,
40 + 'mb_sso_edit_media_schema_rows' => 5,
41 + 'mb_sso_edit_media_pinterest_rows' => 5,
42 + ), PHP_INT_MIN ); // Run before any add-on filters.
43 + }
44 +
45 + public function filter_mb_sso_edit_media_rows( $table_rows, $form, $head_info, $mod ) {
46 +
47 + $max_media_items = $this->p->cf[ 'form' ][ 'max_media_items' ];
48 +
49 + $args = array(
50 + 'canonical_url' => $this->p->util->get_canonical_url( $mod ),
51 + );
52 +
53 + $form_rows = array(
54 + 'info_priority_media' => array(
55 + 'table_row' => '<td colspan="2">' . $this->p->msgs->get( 'info-meta-priority-media' ) . '</td>',
56 + ),
57 + 'og_img_max' => $mod[ 'is_post' ] ? array(
58 + 'th_class' => 'medium',
59 + 'label' => _x( 'Maximum Images', 'option label', 'wpsso' ),
60 + 'tooltip' => 'og_img_max', // Use tooltip message from settings.
61 + 'content' => $form->get_select( 'og_img_max', range( 0, $max_media_items ), $css_class = 'medium' ),
62 + ) : '',
63 + 'og_vid_max' => $mod[ 'is_post' ] ? array(
64 + 'th_class' => 'medium',
65 + 'label' => _x( 'Maximum Videos', 'option label', 'wpsso' ),
66 + 'tooltip' => 'og_vid_max', // Use the tooltip from plugin settings.
67 + 'content' => $form->get_select( 'og_vid_max', range( 0, $max_media_items ), $css_class = 'medium' ),
68 + ) : '',
69 + 'og_vid_prev_img' => $mod[ 'is_post' ] ? array(
70 + 'th_class' => 'medium',
71 + 'label' => _x( 'Include Video Previews', 'option label', 'wpsso' ),
72 + 'tooltip' => 'og_vid_prev_img', // Use the tooltip from plugin settings.
73 + 'content' => $form->get_checkbox( 'og_vid_prev_img' ) . $this->p->msgs->preview_images_are_first(),
74 + ) : '',
75 + 'subsection_opengraph' => array(
76 + 'td_class' => 'subsection',
77 + 'header' => 'h4',
78 + 'label' => _x( 'Priority Media', 'metabox title', 'wpsso' ),
79 + ),
80 + );
81 +
82 + $table_rows = $form->get_md_form_rows( $table_rows, $form_rows, $head_info, $mod );
83 +
84 + foreach( array(
85 + 'wpsso_mb_sso_edit_media_prio_image_rows',
86 + 'wpsso_mb_sso_edit_media_prio_video_rows',
87 + 'wpsso_mb_sso_edit_media_og_rows',
88 + 'wpsso_mb_sso_edit_media_twitter_rows',
89 + 'wpsso_mb_sso_edit_media_schema_rows',
90 + 'wpsso_mb_sso_edit_media_pinterest_rows',
91 + ) as $filter_name ) {
92 +
93 + if ( $this->p->debug->enabled ) {
94 +
95 + $this->p->debug->log( 'applying filters "' . $filter_name . '"' );
96 + }
97 +
98 + $table_rows = apply_filters( $filter_name, $table_rows, $form, $head_info, $mod, $args );
99 + }
100 +
101 + return $table_rows;
102 + }
103 +
104 + public function filter_mb_sso_edit_media_prio_image_rows( $table_rows, $form, $head_info, $mod, $args ) {
105 +
106 + $this->p->util->maybe_set_ref( $args[ 'canonical_url' ], $mod, __( 'getting open graph image', 'wpsso' ) );
107 +
108 + $size_name = 'wpsso-opengraph';
109 + $media_request = array( 'pid' );
110 + $media_info = $this->p->media->get_media_info( $size_name, $media_request, $mod, $md_pre = 'none' );
111 +
112 + $this->p->util->maybe_unset_ref( $args[ 'canonical_url' ] );
113 +
114 + $form_rows = array(
115 + 'subsection_priority_image' => array(
116 + 'td_class' => 'subsection top',
117 + 'header' => 'h5',
118 + 'label' => _x( 'Priority Image Information', 'metabox title', 'wpsso' )
119 + ),
120 + 'og_img_id' => array(
121 + 'th_class' => 'medium',
122 + 'label' => _x( 'Image ID', 'option label', 'wpsso' ),
123 + 'tooltip' => 'meta-og_img_id',
124 + 'content' => $form->get_input_image_upload( 'og_img', $media_info[ 'pid' ] ),
125 + ),
126 + 'og_img_url' => array(
127 + 'th_class' => 'medium',
128 + 'label' => _x( 'or an Image URL', 'option label', 'wpsso' ),
129 + 'tooltip' => 'meta-og_img_url',
130 + 'content' => $form->get_input_image_url( 'og_img' ),
131 + ),
132 + );
133 +
134 + return $form->get_md_form_rows( $table_rows, $form_rows, $head_info, $mod );
135 + }
136 +
137 + /*
138 + * X (Twitter) Card
139 + *
140 + * App and Player cards do not have a $size_name.
141 + *
142 + * Only show custom image options for the Summary and Summary Large Image cards.
143 + */
144 + public function filter_mb_sso_edit_media_twitter_rows( $table_rows, $form, $head_info, $mod, $args ) {
145 +
146 + if ( ! $mod[ 'is_public' ] ) {
147 +
148 + return $table_rows;
149 + }
150 +
151 + list( $card_type, $card_label, $size_name, $tc_prefix ) = $this->p->tc->get_card_info( $mod, $head_info );
152 +
153 + if ( ! empty( $card_label ) ) {
154 +
155 + $form_rows[ 'subsection_tc' ] = array(
156 + 'td_class' => 'subsection',
157 + 'header' => 'h4',
158 + 'label' => $card_label,
159 + );
160 +
161 + if ( empty( $size_name ) ) {
162 +
163 + $form_rows[ 'subsection_tc_msg' ] = array(
164 + 'table_row' => '<td colspan="2"><p class="status-msg">' .
165 + sprintf( __( 'No priority media options for the %s.', 'wpsso' ),
166 + $card_label ) . '</p></td>',
167 + );
168 +
169 + } else {
170 +
171 + $this->p->util->maybe_set_ref( $args[ 'canonical_url' ], $mod, __( 'getting twitter card image', 'wpsso' ) );
172 +
173 + $media_request = array( 'pid' );
174 + $media_info = $this->p->media->get_media_info( $size_name, $media_request, $mod, $md_pre = 'og' );
175 +
176 + $this->p->util->maybe_unset_ref( $args[ 'canonical_url' ] );
177 +
178 + $form_rows[ $tc_prefix . '_img_id' ] = array(
179 + 'th_class' => 'medium',
180 + 'label' => _x( 'Image ID', 'option label', 'wpsso' ),
181 + 'tooltip' => 'meta-' . $tc_prefix . '_img_id',
182 + 'content' => $form->get_input_image_upload( $tc_prefix . '_img', $media_info[ 'pid' ] ),
183 + );
184 +
185 + $form_rows[ $tc_prefix . '_img_url' ] = array(
186 + 'th_class' => 'medium',
187 + 'label' => _x( 'or an Image URL', 'option label', 'wpsso' ),
188 + 'tooltip' => 'meta-' . $tc_prefix . '_img_url',
189 + 'content' => $form->get_input_image_url( $tc_prefix . '_img' ),
190 + );
191 + }
192 +
193 + $table_rows = $form->get_md_form_rows( $table_rows, $form_rows, $head_info, $mod );
194 + }
195 +
196 + return $table_rows;
197 + }
198 +
199 + /*
200 + * Schema.
201 + */
202 + public function filter_mb_sso_edit_media_schema_rows( $table_rows, $form, $head_info, $mod, $args ) {
203 +
204 + if ( ! $mod[ 'is_public' ] ) {
205 +
206 + if ( $this->p->debug->enabled ) {
207 +
208 + $this->p->debug->mark( 'exiting early: object is not public' );
209 + }
210 +
211 + return $table_rows;
212 +
213 + } elseif ( $this->p->util->is_schema_disabled() ) {
214 +
215 + if ( $this->p->debug->enabled ) {
216 +
217 + $this->p->debug->mark( 'exiting early: schema markup is disabled' );
218 + }
219 +
220 + return $table_rows;
221 + }
222 +
223 + $this->p->util->maybe_set_ref( $args[ 'canonical_url' ], $mod, __( 'getting schema 1:1 image', 'wpsso' ) );
224 +
225 + $size_name = 'wpsso-schema-1x1';
226 + $media_request = array( 'pid' );
227 + $media_info = $this->p->media->get_media_info( $size_name, $media_request, $mod, $md_pre = 'og' );
228 +
229 + $this->p->util->maybe_unset_ref( $args[ 'canonical_url' ] );
230 +
231 + $form_rows = array(
232 + 'subsection_schema' => array(
233 + 'td_class' => 'subsection',
234 + 'header' => 'h4',
235 + 'label' => _x( 'Schema Markup and Google Rich Results', 'metabox title', 'wpsso' )
236 + ),
237 + 'schema_img_id' => array(
238 + 'th_class' => 'medium',
239 + 'label' => _x( 'Image ID', 'option label', 'wpsso' ),
240 + 'tooltip' => 'meta-schema_img_id',
241 + 'content' => $form->get_input_image_upload( 'schema_img', $media_info[ 'pid' ] ),
242 + ),
243 + 'schema_img_url' => array(
244 + 'th_class' => 'medium',
245 + 'label' => _x( 'or an Image URL', 'option label', 'wpsso' ),
246 + 'tooltip' => 'meta-schema_img_url',
247 + 'content' => $form->get_input_image_url( 'schema_img', '' ),
248 + ),
249 + );
250 +
251 + $table_rows = $form->get_md_form_rows( $table_rows, $form_rows, $head_info, $mod );
252 +
253 + return $table_rows;
254 + }
255 +
256 + /*
257 + * Pinterest Pin It.
258 + */
259 + public function filter_mb_sso_edit_media_pinterest_rows( $table_rows, $form, $head_info, $mod, $args ) {
260 +
261 + if ( ! $mod[ 'is_public' ] ) {
262 +
263 + return $table_rows;
264 + }
265 +
266 + $pin_img_msg = $this->p->msgs->maybe_pin_img_disabled();
267 + $pin_img_disabled = $pin_img_msg? true : false;
268 + $media_info = array( 'pid' => '' );
269 +
270 + if ( ! $pin_img_disabled ) {
271 +
272 + $this->p->util->maybe_set_ref( $args[ 'canonical_url' ], $mod, __( 'getting pinterest image', 'wpsso' ) );
273 +
274 + $size_name = 'wpsso-pinterest';
275 + $media_request = array( 'pid' );
276 + $media_info = $this->p->media->get_media_info( $size_name, $media_request, $mod, $md_pre = array( 'schema', 'og' ) );
277 +
278 + $this->p->util->maybe_unset_ref( $args[ 'canonical_url' ] );
279 + }
280 +
281 + $form_rows = array(
282 + 'subsection_pinterest' => array(
283 + 'tr_class' => $pin_img_disabled ? 'hide_in_basic' : '',
284 + 'td_class' => 'subsection',
285 + 'header' => 'h4',
286 + 'label' => _x( 'Pinterest Pin It', 'metabox title', 'wpsso' ),
287 + ),
288 + 'pin_img_id' => array(
289 + 'tr_class' => $pin_img_disabled ? 'hide_in_basic' : '',
290 + 'th_class' => 'medium',
291 + 'label' => _x( 'Image ID', 'option label', 'wpsso' ),
292 + 'tooltip' => 'meta-pin_img_id',
293 + 'content' => $form->get_input_image_upload( 'pin_img', $media_info[ 'pid' ], $pin_img_disabled ),
294 + ),
295 + 'pin_img_url' => array(
296 + 'tr_class' => $pin_img_disabled ? 'hide_in_basic' : '',
297 + 'th_class' => 'medium',
298 + 'label' => _x( 'or an Image URL', 'option label', 'wpsso' ),
299 + 'tooltip' => 'meta-pin_img_url',
300 + 'content' => $form->get_input_image_url( 'pin_img', '', $pin_img_disabled ) . $pin_img_msg,
301 + ),
302 + );
303 +
304 + return $form->get_md_form_rows( $table_rows, $form_rows, $head_info, $mod );
305 + }
306 + }
307 +}