| 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( 'WpssoJsonTypeHowTo' ) ) { |
| 14 |
|
| 15 |
class WpssoJsonTypeHowTo { |
| 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_howto' => 5, |
| 33 |
) ); |
| 34 |
} |
| 35 |
|
| 36 |
public function filter_json_data_https_schema_org_howto( $json_data, $mod, $mt_og, $page_type_id, $is_main ) { |
| 37 |
|
| 38 |
if ( $this->p->debug->enabled ) { |
| 39 |
|
| 40 |
$this->p->debug->mark(); |
| 41 |
} |
| 42 |
|
| 43 |
if ( $page_type_id === 'recipe' ) { |
| 44 |
|
| 45 |
if ( $this->p->debug->enabled ) { |
| 46 |
|
| 47 |
$this->p->debug->log( 'exiting early: page_type_id is recipe (avoiding conflicting properties)' ); |
| 48 |
} |
| 49 |
|
| 50 |
return $json_data; |
| 51 |
} |
| 52 |
|
| 53 |
$json_ret = array(); |
| 54 |
$md_opts = array(); |
| 55 |
|
| 56 |
WpssoSchema::add_type_opts_md_pad( $md_opts, $mod ); |
| 57 |
|
| 58 |
/* |
| 59 |
* See https://schema.org/yield. |
| 60 |
*/ |
| 61 |
if ( ! empty( $md_opts[ 'schema_howto_yield' ] ) ) { |
| 62 |
|
| 63 |
$json_ret[ 'yield' ] = (string) $md_opts[ 'schema_howto_yield' ]; |
| 64 |
} |
| 65 |
|
| 66 |
/* |
| 67 |
* See https://schema.org/prepTime. |
| 68 |
* See https://schema.org/totalTime. |
| 69 |
*/ |
| 70 |
WpssoSchema::add_data_time_from_assoc( $json_ret, $md_opts, array( |
| 71 |
'prepTime' => 'schema_howto_prep', |
| 72 |
'totalTime' => 'schema_howto_total', |
| 73 |
) ); |
| 74 |
|
| 75 |
/* |
| 76 |
* See https://schema.org/step. |
| 77 |
*/ |
| 78 |
WpssoSchema::add_howto_steps_data( $json_ret, $mod, $md_opts, $opt_pre = 'schema_howto_step', $prop_name = 'step' ); |
| 79 |
|
| 80 |
/* |
| 81 |
* See https://schema.org/supply. |
| 82 |
*/ |
| 83 |
foreach ( SucomUtil::preg_grep_keys( '/^schema_howto_supply_[0-9]+$/', $md_opts ) as $md_key => $md_val ) { |
| 84 |
|
| 85 |
$json_ret[ 'supply' ][] = WpssoSchema::get_schema_type_context( 'https://schema.org/HowToSupply', array( |
| 86 |
'name' => $md_val, |
| 87 |
) ); |
| 88 |
} |
| 89 |
|
| 90 |
/* |
| 91 |
* See https://schema.org/tool. |
| 92 |
*/ |
| 93 |
foreach ( SucomUtil::preg_grep_keys( '/^schema_howto_tool_[0-9]+$/', $md_opts ) as $md_key => $md_val ) { |
| 94 |
|
| 95 |
$json_ret[ 'tool' ][] = WpssoSchema::get_schema_type_context( 'https://schema.org/HowToTool', array( |
| 96 |
'name' => $md_val, |
| 97 |
) ); |
| 98 |
} |
| 99 |
|
| 100 |
if ( $this->p->debug->enabled ) { |
| 101 |
|
| 102 |
$this->p->debug->log( 'merging json_data and json_ret arrays' ); |
| 103 |
} |
| 104 |
|
| 105 |
return WpssoSchema::return_data_from_filter( $json_data, $json_ret, $is_main ); |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|