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
wpsso / lib / json / type / faqpage.php

faqpage.php in WPSSO Core – Complete Schema Markup and Meta Tags 22.7.0, at lib/json/type/faqpage.php

96 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * License: GPLv3
4 * License URI: https://www.gnu.org/licenses/gpl.txt
5 * Copyright 2016-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 ( ! class_exists( 'WpssoJsonTypeFAQPage' ) ) {
14
15 class WpssoJsonTypeFAQPage {
16
17 private $p; // Wpsso class object.
18
19 /*
20 * Instantiated by Wpsso->init_json_filters().
21 */
22 public function __construct( &$plugin ) {
23
24 $this->p =& $plugin;
25
26 if ( $this->p->debug->enabled ) {
27
28 $this->p->debug->mark();
29 }
30
31 $this->p->util->add_plugin_filters( $this, array(
32 'json_data_https_schema_org_faqpage' => 5,
33 'json_data_validate_https_schema_org_faqpage' => 5,
34 ) );
35 }
36
37 /*
38 * See https://developers.google.com/search/docs/appearance/structured-data/faqpage.
39 */
40 public function filter_json_data_https_schema_org_faqpage( $json_data, $mod, $mt_og, $page_type_id, $is_main ) {
41
42 if ( $this->p->debug->enabled ) {
43
44 $this->p->debug->mark();
45 }
46
47 unset( $json_data[ 'mainEntityOfPage' ] );
48
49 $prop_type_ids = array( 'mainEntity' => 'question' );
50
51 WpssoSchema::add_posts_data( $json_data, $mod, $mt_og, $page_type_id, $is_main, $prop_type_ids );
52
53 return $json_data;
54 }
55
56 public function filter_json_data_validate_https_schema_org_faqpage( $json_data, $mod, $mt_og, $page_type_id, $is_main ) {
57
58 $is_admin = is_admin();
59 $user_id = get_current_user_id();
60
61 if ( $is_admin && $user_id ) {
62
63 $entity_count = 0;
64
65 if ( isset( $json_data[ 'mainEntity' ] ) ) {
66
67 if ( SucomUtil::is_non_assoc( $json_data[ 'mainEntity' ] ) ) {
68
69 $entity_count = count( $json_data[ 'mainEntity' ] );
70 }
71 }
72
73 $notice_key = $mod[ 'name' ] . '-' . $mod[ 'id' ] . '-questions-added-to-faqpage';
74
75 if ( $entity_count ) {
76
77 $notice_msg = sprintf( _n( '%d question added to the Schema FAQPage markup.',
78 '%d questions added to the Schema FAQPage markup.', $entity_count, 'wpsso' ), $entity_count );
79
80 $this->p->notice->inf( $notice_msg, $user_id, $notice_key );
81
82 } else {
83
84 $notice_msg = __( 'No question(s) found for the Schema FAQPage markup.', 'wpsso' ) . ' ';
85
86 $notice_msg .= __( 'Google requires at least one question for the Schema FAQPage markup.', 'wpsso' );
87
88 $this->p->notice->err( $notice_msg, $user_id, $notice_key );
89 }
90 }
91
92 return $json_data;
93 }
94 }
95 }
96