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 / integ / job / simplejobboard.php

simplejobboard.php in WPSSO Core – Complete Schema Markup and Meta Tags 22.7.0, at lib/integ/job/simplejobboard.php

183 lines 4.0 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 2017-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( 'WpssoIntegJobSimpleJobBoard' ) ) {
14
15 class WpssoIntegJobSimpleJobBoard {
16
17 private $p; // Wpsso class object.
18
19 public function __construct( &$plugin ) {
20
21 $this->p =& $plugin;
22
23 if ( $this->p->debug->enabled ) {
24
25 $this->p->debug->mark();
26 }
27
28 $this->p->util->add_plugin_filters( $this, array(
29 'get_md_defaults' => 2,
30 'get_post_options' => 3,
31 'get_job_options' => 3,
32 ) );
33 }
34
35 public function filter_get_md_defaults( array $md_defs, array $mod ) {
36
37 if ( $this->p->debug->enabled ) {
38
39 $this->p->debug->mark();
40 }
41
42 if ( ! $mod[ 'is_post' ] || $mod[ 'post_type' ] !== 'jobpost' ) {
43
44 return $md_defs;
45 }
46
47 self::add_schema_job_defaults( $md_defs, $mod[ 'id' ] );
48
49 return $md_defs;
50 }
51
52 public function filter_get_post_options( array $md_opts, $post_id, array $mod ) {
53
54 if ( $this->p->debug->enabled ) {
55
56 $this->p->debug->mark();
57 }
58
59 if ( ! $mod[ 'is_post' ] || $mod[ 'post_type' ] !== 'jobpost' ) {
60
61 return $md_opts;
62 }
63
64 $job_opts = array();
65
66 self::add_schema_job_defaults( $job_opts, $post_id ); // Add defaults to empty array.
67
68 foreach ( $job_opts as $key => $val ) { // Hard-code defaults and disable the option.
69
70 $md_opts[ $key ] = $val;
71 $md_opts[ $key . ':disabled' ] = true;
72 }
73
74 return $md_opts;
75 }
76
77 public function filter_get_job_options( $opts, $mod, $job_id ) {
78
79 if ( $this->p->debug->enabled ) {
80
81 $this->p->debug->mark();
82 }
83
84 if ( ! $mod[ 'is_post' ] || $mod[ 'post_type' ] !== 'jobpost' ) {
85
86 return $opts;
87 }
88
89 $job_opts = self::get_schema_job_options( $mod[ 'id' ] );
90
91 $job_opts = SucomUtil::preg_grep_keys( '/^schema_(job_.*)$/', $job_opts, $invert = false, $replace = '$1' );
92
93 return $job_opts;
94 }
95
96 private static function get_schema_job_options( $post_id ) {
97
98 $wpsso =& Wpsso::get_instance();
99
100 if ( $wpsso->debug->enabled ) {
101
102 $wpsso->debug->mark();
103 }
104
105 $job_opts = array();
106
107 self::add_schema_job_defaults( $job_opts, $post_id );
108
109 return $job_opts;
110 }
111
112 private static function add_schema_job_defaults( array &$job_opts, $post_id ) {
113
114 $wpsso =& Wpsso::get_instance();
115
116 if ( $wpsso->debug->enabled ) {
117
118 $wpsso->debug->mark();
119 }
120
121 static $local_cache = array();
122
123 if ( ! isset( $local_cache[ $post_id ] ) ) { // Only create the defaults array once.
124
125 if ( $wpsso->debug->enabled ) {
126
127 $wpsso->debug->log( 'creating a new defaults static array' );
128 }
129
130 $local_cache[ $post_id ] = array();
131
132 /*
133 * Get the default schema type (job.posting by default).
134 */
135 $local_cache[ $post_id ][ 'schema_type' ] = $wpsso->options[ 'schema_type_for_jobpost' ];
136
137 $job_type_terms = wp_get_object_terms( $post_id, 'jobpost_job_type' );
138
139 if ( ! empty( $job_type_terms ) ) {
140
141 foreach ( $job_type_terms as $term_obj ) {
142
143 if ( ! empty( $term_obj->name ) ) { // Just in case.
144
145 /*
146 * Google approved values (case sensitive):
147 *
148 * FULL_TIME
149 * PART_TIME
150 * CONTRACTOR
151 * TEMPORARY
152 * INTERN
153 * VOLUNTEER
154 * PER_DIEM
155 * OTHER
156 */
157 $empl_type = SucomUtil::sanitize_hookname( $term_obj->name ); // Sanitize with underscores.
158
159 $empl_type = strtoupper( $empl_type );
160
161 $local_cache[ $post_id ][ 'schema_job_empl_type_' . $empl_type ] = 1; // Checkbox value is 0 or 1.
162 }
163 }
164 }
165
166 if ( $wpsso->debug->enabled ) {
167
168 $wpsso->debug->log_arr( 'defaults static array', $local_cache[ $post_id ] );
169 }
170
171 } elseif ( $wpsso->debug->enabled ) {
172
173 $wpsso->debug->log( 'using the cached defaults static array' );
174 }
175
176 if ( ! empty( $local_cache[ $post_id ] ) ) {
177
178 $job_opts = array_merge( $job_opts, $local_cache[ $post_id ] );
179 }
180 }
181 }
182 }
183