示例#1
0
/**
 * Save all description sent from the Bulk Editor.
 */
function wpseo_save_all_descriptions()
{
    check_ajax_referer('wpseo-bulk-editor');
    $new_metadescs = $_POST['metadescs'];
    $original_metadescs = $_POST['existing_metadescs'];
    $results = array();
    if (is_array($new_metadescs) && $new_metadescs !== array()) {
        foreach ($new_metadescs as $id => $new_metadesc) {
            $original_metadesc = $original_metadescs[$id];
            $results[] = wpseo_upsert_new_description($id, $new_metadesc, $original_metadesc);
        }
    }
    echo json_encode($results);
    die;
}
 function save_seo_info($params)
 {
     if ($this->_checkYWPSEO()) {
         $ywpseo_meta_file = WP_PLUGIN_DIR . '/wordpress-seo-premium/inc/class-wpseo-meta.php';
         $ywpseo_ajax_file = WP_PLUGIN_DIR . '/wordpress-seo-premium/admin/ajax.php';
         if (file_exists($ywpseo_meta_file)) {
             @(include_once $ywpseo_meta_file);
             if (class_exists('WPSEO_Meta')) {
                 if (file_exists($ywpseo_ajax_file)) {
                     @(include_once $ywpseo_ajax_file);
                     for ($i = 0; $i < count($params['data']); $i++) {
                         $post_id = $params['data'][$i]['post_id'];
                         $original_title = $params['data'][$i]['old_title'];
                         $new_title = $params['data'][$i]['new_title'];
                         $original_metadesc = $params['data'][$i]['old_metadesc'];
                         $new_metadesc = $params['data'][$i]['new_metadesc'];
                         $title_check = intval($params['data'][$i]['title_check']);
                         $metadesc_check = intval($params['data'][$i]['metadesc_check']);
                         if ($original_title == 'null') {
                             $original_title == null;
                         }
                         if ($new_title == 'null') {
                             $new_title == null;
                         }
                         if ($original_metadesc == 'null') {
                             $original_metadesc == null;
                         }
                         if ($new_metadesc == 'null') {
                             $new_metadesc == null;
                         }
                         $save_title = array();
                         $save_metadesc = array();
                         if ($title_check) {
                             $save_title = wpseo_upsert_new_title($post_id, $new_title, $original_title);
                         } else {
                             $save_title = array('status' => 'neutral');
                         }
                         if ($metadesc_check) {
                             $save_metadesc = wpseo_upsert_new_description($post_id, $new_metadesc, $original_metadesc);
                         } else {
                             $save_metadesc = array('status' => 'neutral');
                         }
                         if ($save_title['status'] != 'failure' && $save_metadesc['status'] != 'failure') {
                             $result[$post_id] = array('original_title' => $original_title, 'original_metadesc' => $original_metadesc, 'new_title' => $new_title, 'new_metadesc' => $new_metadesc);
                         } else {
                             if ($save_title['status'] == 'failure') {
                                 $errorMsg = $save_title['results'];
                             }
                             if ($save_metadesc['status'] == 'failure') {
                                 $errorMsg = $save_metadesc['results'];
                             }
                             $result[$post_id] = array('error' => $errorMsg);
                         }
                     }
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         } else {
             return false;
         }
         return $result;
     }
 }