| @@ -1,0 +1,244 @@ | ||
| 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 ( ! class_exists( 'WpssoUpgradeMeta' ) ) { | |
| 14 | + | |
| 15 | + class WpssoUpgradeMeta { | |
| 16 | + | |
| 17 | + private $p; // Wpsso class object. | |
| 18 | + | |
| 19 | + private static $rename_md_options = array( | |
| 20 | + 'wpsso' => array( | |
| 21 | + 499 => array( | |
| 22 | + 'link_desc' => 'seo_desc', | |
| 23 | + 'meta_desc' => 'seo_desc', | |
| 24 | + ), | |
| 25 | + 503 => array( | |
| 26 | + 'schema_recipe_calories' => 'schema_recipe_nutri_cal', | |
| 27 | + ), | |
| 28 | + 514 => array( | |
| 29 | + 'rp_img_id' => 'pin_img_id', | |
| 30 | + 'rp_img_id_pre' => 'pin_img_id_lib', | |
| 31 | + 'rp_img_width' => '', | |
| 32 | + 'rp_img_height' => '', | |
| 33 | + 'rp_img_crop' => '', | |
| 34 | + 'rp_img_crop_x' => '', | |
| 35 | + 'rp_img_crop_y' => '', | |
| 36 | + 'rp_img_url' => 'pin_img_url', | |
| 37 | + ), | |
| 38 | + 537 => array( | |
| 39 | + 'schema_add_type_url' => 'schema_addl_type_url_0', | |
| 40 | + ), | |
| 41 | + 569 => array( | |
| 42 | + 'schema_add_type_url' => 'schema_addl_type_url', // Option modifiers are preserved. | |
| 43 | + ), | |
| 44 | + 615 => array( | |
| 45 | + 'org_type' => 'org_schema_type', | |
| 46 | + ), | |
| 47 | + 628 => array( | |
| 48 | + 'product_gender' => 'product_target_gender', | |
| 49 | + ), | |
| 50 | + 649 => array( | |
| 51 | + 'product_ean' => 'product_gtin13', | |
| 52 | + ), | |
| 53 | + | |
| 54 | + /* | |
| 55 | + * The custom width, height, and crop options were removed in preference for attachment specific | |
| 56 | + * options (ie. 'attach_img_crop_x' and 'attach_img_crop_y'). | |
| 57 | + */ | |
| 58 | + 660 => array( | |
| 59 | + 'og_img_width' => '', | |
| 60 | + 'og_img_height' => '', | |
| 61 | + 'og_img_crop' => '', | |
| 62 | + 'og_img_crop_x' => '', | |
| 63 | + 'og_img_crop_y' => '', | |
| 64 | + 'schema_article_img_width' => '', | |
| 65 | + 'schema_article_img_height' => '', | |
| 66 | + 'schema_article_img_crop' => '', | |
| 67 | + 'schema_article_img_crop_x' => '', | |
| 68 | + 'schema_article_img_crop_y' => '', | |
| 69 | + 'schema_img_width' => '', | |
| 70 | + 'schema_img_height' => '', | |
| 71 | + 'schema_img_crop' => '', | |
| 72 | + 'schema_img_crop_x' => '', | |
| 73 | + 'schema_img_crop_y' => '', | |
| 74 | + 'tc_sum_img_width' => '', | |
| 75 | + 'tc_sum_img_height' => '', | |
| 76 | + 'tc_sum_img_crop' => '', | |
| 77 | + 'tc_sum_img_crop_x' => '', | |
| 78 | + 'tc_sum_img_crop_y' => '', | |
| 79 | + 'tc_lrg_img_width' => '', | |
| 80 | + 'tc_lrg_img_height' => '', | |
| 81 | + 'tc_lrg_img_crop' => '', | |
| 82 | + 'tc_lrg_img_crop_x' => '', | |
| 83 | + 'tc_lrg_img_crop_y' => '', | |
| 84 | + 'thumb_img_width' => '', | |
| 85 | + 'thumb_img_height' => '', | |
| 86 | + 'thumb_img_crop' => '', | |
| 87 | + 'thumb_img_crop_x' => '', | |
| 88 | + 'thumb_img_crop_y' => '', | |
| 89 | + ), | |
| 90 | + 692 => array( | |
| 91 | + 'product_mpn' => 'product_mfr_part_no', | |
| 92 | + 'product_sku' => 'product_retailer_part_no', | |
| 93 | + ), | |
| 94 | + 696 => array( | |
| 95 | + 'og_art_section' => 'schema_article_section', | |
| 96 | + ), | |
| 97 | + 701 => array( | |
| 98 | + 'article_topic' => 'schema_article_section', | |
| 99 | + ), | |
| 100 | + 725 => array( | |
| 101 | + 'product_volume_value' => 'product_fluid_volume_value', | |
| 102 | + ), | |
| 103 | + 786 => array( | |
| 104 | + 'og_img_id_pre' => 'og_img_id_lib', | |
| 105 | + 'p_img_id_pre' => 'pin_img_id_lib', | |
| 106 | + 'tc_lrg_img_id_pre' => 'tc_lrg_img_id_lib', | |
| 107 | + 'tc_sum_img_id_pre' => 'tc_sum_img_id_lib', | |
| 108 | + 'schema_img_id_pre' => 'schema_img_id_lib', | |
| 109 | + ), | |
| 110 | + 812 => array( | |
| 111 | + 'sharing_url' => '', | |
| 112 | + ), | |
| 113 | + 815 => array( | |
| 114 | + 'p_img_id' => 'pin_img_id', | |
| 115 | + 'p_img_id_lib' => 'pin_img_id_lib', | |
| 116 | + 'p_img_url' => 'pin_img_url', | |
| 117 | + ), | |
| 118 | + 829 => array( | |
| 119 | + 'book_isbn' => 'schema_book_isbn', | |
| 120 | + ), | |
| 121 | + 920 => array( // Renamed for WPSSO Core v13.5.0. | |
| 122 | + 'article_section' => 'schema_article_section', | |
| 123 | + 'reading_mins' => 'schema_reading_mins', | |
| 124 | + ), | |
| 125 | + 935 => array( // Renamed for WPSSO Core v14.0.0. | |
| 126 | + 'product_adult_oriented' => 'product_adult_type', | |
| 127 | + 'product_depth_value' => 'product_length_value', | |
| 128 | + 'product_size_type' => 'product_size_group_0', | |
| 129 | + 'schema_review_rating_from' => 'schema_review_rating_min', | |
| 130 | + 'schema_review_rating_to' => 'schema_review_rating_max', | |
| 131 | + ), | |
| 132 | + 936 => array( // Renamed for WPSSO Core v14.2.0. | |
| 133 | + 'product_size_group' => 'product_size_group_0', | |
| 134 | + ), | |
| 135 | + 944 => array( // Renamed for WPSSO Core v14.4.0. | |
| 136 | + 'schema_keywords' => 'schema_keywords_csv', | |
| 137 | + ), | |
| 138 | + 979 => array( | |
| 139 | + 'schema_howto_step_css_id' => 'schema_howto_step_anchor_id', | |
| 140 | + 'schema_howto_step_anchor' => 'schema_howto_step_anchor_id', | |
| 141 | + 'schema_howto_step_container_id' => 'schema_howto_step_anchor_id', | |
| 142 | + 'schema_recipe_instruction_css_id' => 'schema_recipe_instruction_anchor_id', | |
| 143 | + 'schema_recipe_instruction_anchor' => 'schema_recipe_instruction_anchor_id', | |
| 144 | + 'schema_recipe_instruction_container_id' => 'schema_recipe_instruction_anchor_id', | |
| 145 | + ), | |
| 146 | + ), | |
| 147 | + ); | |
| 148 | + | |
| 149 | + public function __construct( &$plugin ) { | |
| 150 | + | |
| 151 | + $this->p =& $plugin; | |
| 152 | + | |
| 153 | + if ( $this->p->debug->enabled ) { | |
| 154 | + | |
| 155 | + $this->p->debug->mark(); | |
| 156 | + } | |
| 157 | + } | |
| 158 | + | |
| 159 | + public function md_options( array $md_opts, array $mod ) { | |
| 160 | + | |
| 161 | + /* | |
| 162 | + * Get the current options version number for checks to follow. | |
| 163 | + */ | |
| 164 | + $prev_version = $this->p->opt->get_version( $md_opts, 'wpsso' ); // Returns 'opt_version'. | |
| 165 | + | |
| 166 | + /* | |
| 167 | + * Maybe renamed some option keys. | |
| 168 | + */ | |
| 169 | + $version_keys = apply_filters( 'wpsso_rename_md_options_keys', self::$rename_md_options, $mod ); | |
| 170 | + | |
| 171 | + $md_opts = $this->p->util->rename_options_by_ext( $md_opts, $version_keys ); | |
| 172 | + | |
| 173 | + /* | |
| 174 | + * Check for schema type IDs that need to be renamed. | |
| 175 | + */ | |
| 176 | + $schema_type_keys_preg = '/^(schema_type|place_schema_type|plm_place_schema_type)(_[0-9]+)?$/'; | |
| 177 | + | |
| 178 | + foreach ( SucomUtil::preg_grep_keys( $schema_type_keys_preg, $md_opts ) as $md_key => $md_val ) { | |
| 179 | + | |
| 180 | + if ( ! empty( $this->p->cf[ 'head' ][ 'schema_renamed' ][ $md_val ] ) ) { | |
| 181 | + | |
| 182 | + $md_opts[ $md_key ] = $this->p->cf[ 'head' ][ 'schema_renamed' ][ $md_val ]; | |
| 183 | + } | |
| 184 | + } | |
| 185 | + | |
| 186 | + /* | |
| 187 | + * Import and delete deprecated robots post metadata. | |
| 188 | + */ | |
| 189 | + if ( $prev_version > 0 && $prev_version <= 759 ) { | |
| 190 | + | |
| 191 | + foreach ( array( | |
| 192 | + 'noarchive', | |
| 193 | + 'nofollow', | |
| 194 | + 'noimageindex', | |
| 195 | + 'noindex', | |
| 196 | + 'nosnippet', | |
| 197 | + 'notranslate', | |
| 198 | + ) as $directive_key ) { | |
| 199 | + | |
| 200 | + $opt_key = 'robots_' . $directive_key; | |
| 201 | + $meta_key = '_wpsso_' . $directive_key; | |
| 202 | + | |
| 203 | + $directive_value = $mod[ 'obj' ]::get_meta( $mod[ 'id' ], $meta_key, $single = true ); // Use static method from child. | |
| 204 | + | |
| 205 | + if ( '' !== $directive_value ) { | |
| 206 | + | |
| 207 | + $md_opts[ $opt_key ] = (int) $directive_value; | |
| 208 | + | |
| 209 | + $mod[ 'obj' ]::delete_meta( $mod[ 'id' ], $meta_key ); // Use static method from child. | |
| 210 | + } | |
| 211 | + } | |
| 212 | + } | |
| 213 | + | |
| 214 | + if ( $prev_version > 0 && $prev_version <= 902 ) { | |
| 215 | + | |
| 216 | + /* | |
| 217 | + * If there is a multilingual plugin available, trust the plugin and ignore any previous / | |
| 218 | + * inherited custom language value. | |
| 219 | + */ | |
| 220 | + if ( $this->p->avail[ 'lang' ][ 'any' ] ) { | |
| 221 | + | |
| 222 | + unset( $md_opts[ 'schema_lang' ] ); | |
| 223 | + } | |
| 224 | + } | |
| 225 | + | |
| 226 | + if ( $prev_version > 0 && $prev_version <= 917 ) { | |
| 227 | + | |
| 228 | + if ( ! empty( $md_opts[ 'product_target_gender' ] ) ) { | |
| 229 | + | |
| 230 | + $md_opts[ 'product_target_gender' ] = strtolower( $md_opts[ 'product_target_gender' ] ); | |
| 231 | + } | |
| 232 | + } | |
| 233 | + | |
| 234 | + $md_opts = apply_filters( 'wpsso_upgraded_md_options', $md_opts, $mod ); | |
| 235 | + | |
| 236 | + /* | |
| 237 | + * Add plugin and add-on versions (ie. 'checksum', 'opt_checksum', and 'opt_versions'). | |
| 238 | + */ | |
| 239 | + $this->p->opt->add_versions_checksum( $md_opts ); // $md_opts must be an array. | |
| 240 | + | |
| 241 | + return $md_opts; | |
| 242 | + } | |
| 243 | + } | |
| 244 | +} | |