| 1 |
<?php |
| 2 |
/* |
| 3 |
* License: GPLv3 |
| 4 |
* License URI: https://www.gnu.org/licenses/gpl.txt |
| 5 |
* Copyright 2012-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 |
/* |
| 19 |
* Import Yoast SEO block attrs. |
| 20 |
*/ |
| 21 |
if ( ! class_exists( 'WpssoIntegDataWpseoBlocks' ) ) { |
| 22 |
|
| 23 |
class WpssoIntegDataWpseoBlocks { |
| 24 |
|
| 25 |
private $p; // Wpsso class object. |
| 26 |
|
| 27 |
public function __construct( &$plugin ) { |
| 28 |
|
| 29 |
$this->p =& $plugin; |
| 30 |
|
| 31 |
if ( $this->p->debug->enabled ) { |
| 32 |
|
| 33 |
$this->p->debug->mark(); |
| 34 |
} |
| 35 |
|
| 36 |
$this->p->util->add_plugin_filters( $this, array( |
| 37 |
'import_block_attrs_yoast_how_to_block' => 2, |
| 38 |
) ); |
| 39 |
} |
| 40 |
|
| 41 |
public function filter_import_block_attrs_yoast_how_to_block( $md_opts, $attrs ) { |
| 42 |
|
| 43 |
if ( $this->p->debug->enabled ) { |
| 44 |
|
| 45 |
$this->p->debug->mark(); |
| 46 |
} |
| 47 |
|
| 48 |
if ( empty( $attrs ) ) { // Nothing to do. |
| 49 |
|
| 50 |
if ( $this->p->debug->enabled ) { |
| 51 |
|
| 52 |
$this->p->debug->log( 'block attrs array is empty' ); |
| 53 |
} |
| 54 |
|
| 55 |
return $md_opts; |
| 56 |
} |
| 57 |
|
| 58 |
$ret[ 'schema_type' ] = 'howto'; |
| 59 |
|
| 60 |
if ( ! empty( $attrs[ 'hasDuration' ] ) ) { |
| 61 |
|
| 62 |
foreach ( array( |
| 63 |
'days' => 'schema_howto_prep_days', |
| 64 |
'hours' => 'schema_howto_prep_hours', |
| 65 |
'minutes' => 'schema_howto_prep_mins', |
| 66 |
'seconds' => 'schema_howto_prep_secs', |
| 67 |
) as $key => $opt_key ) { |
| 68 |
|
| 69 |
$ret[ $opt_key ] = isset( $attrs[ $key ] ) ? $attrs[ $key ] : 0; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
if ( ! empty( $attrs[ 'jsonDescription' ] ) ) { |
| 74 |
|
| 75 |
$ret[ 'schema_desc' ] = SucomUtil::strip_html( $attrs[ 'jsonDescription' ] ); |
| 76 |
} |
| 77 |
|
| 78 |
if ( ! empty( $attrs[ 'steps' ] ) && is_array( $attrs[ 'steps' ] ) ) { |
| 79 |
|
| 80 |
$md_opts = SucomUtil::preg_grep_keys( '/^schema_howto_step/', $md_opts, $invert = true ); // Remove any existing howto steps. |
| 81 |
|
| 82 |
$step_num = 0; // Start option number at 0. |
| 83 |
|
| 84 |
foreach ( $attrs[ 'steps' ] as $key => $step ) { |
| 85 |
|
| 86 |
$step_name = isset( $step[ 'jsonName' ] ) ? SucomUtil::strip_html( $step[ 'jsonName' ] ) : ''; |
| 87 |
$step_desc = isset( $step[ 'jsonText' ] ) ? SucomUtil::strip_html( $step[ 'jsonText' ] ) : ''; |
| 88 |
$step_img = isset( $step[ 'jsonImageSrc' ] ) ? SucomUtil::strip_html( $step[ 'jsonImageSrc' ] ) : ''; |
| 89 |
|
| 90 |
$ret[ 'schema_howto_step_section_' . $step_num ] = 0; |
| 91 |
$ret[ 'schema_howto_step_' . $step_num ] = $step_name; |
| 92 |
$ret[ 'schema_howto_step_text_' . $step_num ] = $step_desc; |
| 93 |
|
| 94 |
if ( $step_img ) { |
| 95 |
|
| 96 |
if ( $image_id = attachment_url_to_postid( $step_img ) ) { |
| 97 |
|
| 98 |
$ret[ 'schema_howto_step_img_id_' . $step_num ] = $image_id; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
$step_num++; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
foreach ( $ret as $opt_key => $val ) { |
| 107 |
|
| 108 |
$md_opts[ $opt_key . ':disabled' ] = true; |
| 109 |
$md_opts[ $opt_key ] = $val; |
| 110 |
} |
| 111 |
|
| 112 |
return $md_opts; |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
|