public calculate_results ( object $post ) : array | WP_Error | ||
$post | object | Post to calculate the results for. |
Résultat | array | WP_Error |
function yoast_seo_addon_import($post_id, $data, $import_options) { global $yoast_addon; // all fields except for slider and image fields $fields = array('_yoast_wpseo_focuskw', '_yoast_wpseo_title', '_yoast_wpseo_metadesc', '_yoast_wpseo_meta-robots-noindex', '_yoast_wpseo_meta-robots-nofollow', '_yoast_wpseo_meta-robots-adv', '_yoast_wpseo_sitemap-include', '_yoast_wpseo_sitemap-prio', '_yoast_wpseo_canonical', '_yoast_wpseo_redirect', '_yoast_wpseo_opengraph-title', '_yoast_wpseo_opengraph-description', '_yoast_wpseo_twitter-title', '_yoast_wpseo_twitter-description'); // image fields $image_fields = array('_yoast_wpseo_opengraph-image', '_yoast_wpseo_twitter-image'); $fields = array_merge($fields, $image_fields); // update everything in fields arrays foreach ($fields as $field) { if ($yoast_addon->can_update_meta($field, $import_options)) { if (in_array($field, $image_fields)) { if ($yoast_addon->can_update_image($import_options)) { $id = $data[$field]['attachment_id']; $url = wp_get_attachment_url($id); update_post_meta($post_id, $field, $url); } } else { update_post_meta($post_id, $field, $data[$field]); } } } // calculate _yoast_wpseo_linkdex if (class_exists('WPSEO_Metabox')) { wpseo_admin_init(); $seo = new WPSEO_Metabox(); $seo->calculate_results(get_post($post_id)); } }