コード例 #1
0
 /**
  * @param int     $pidd
  * @param WP_Post $post
  *
  * @return void
  */
 public function save_post_actions($pidd, $post)
 {
     global $sitepress;
     wp_defer_term_counting(true);
     $post = isset($post) ? $post : get_post($pidd);
     // exceptions
     if (!$this->has_save_post_action($post)) {
         wp_defer_term_counting(false);
         return;
     }
     $default_language = $sitepress->get_default_language();
     // allow post arguments to be passed via wp_insert_post directly and not be expected on $_POST exclusively
     $post_vars = (array) $_POST;
     foreach ((array) $post as $k => $v) {
         $post_vars[$k] = $v;
     }
     $post_vars['post_type'] = isset($post_vars['post_type']) ? $post_vars['post_type'] : $post->post_type;
     $post_id = isset($post_vars['post_ID']) ? $post_vars['post_ID'] : $pidd;
     //latter case for XML-RPC publishing
     $language_code = $this->get_save_post_lang($post_id, $sitepress);
     $trid = $this->get_save_post_trid($post_id, $post->post_status);
     // after getting the right trid set the source language from it by referring to the root translation
     // of this trid, in case no proper source language has been set yet
     $source_language = isset($source_language) ? $source_language : $this->get_save_post_source_lang($trid, $language_code, $default_language);
     $this->after_save_post($trid, $post_vars, $language_code, $source_language);
 }
コード例 #2
0
 function import_start($file)
 {
     if (!is_file($file)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'wordpress-importer') . '</strong><br/>';
         echo __('The file does not exist, please try again.', 'wordpress-importer') . '</p>';
         $this->footer();
         die;
     }
     $import_data = $this->parse($file);
     if (is_wp_error($import_data)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'wordpress-importer') . '</strong><br/>';
         echo esc_html($import_data->get_error_message()) . '</p>';
         $this->footer();
         die;
     }
     $this->version = $import_data['version'];
     $this->get_authors_from_import($import_data);
     $this->posts = $import_data['posts'];
     $this->terms = $import_data['terms'];
     $this->categories = $import_data['categories'];
     $this->tags = $import_data['tags'];
     $this->base_url = esc_url($import_data['base_url']);
     // fix for: 'http://localhost/justmarriedmarried' = str_replace('http://localhost/just', 'http://localhost/justmarried', 'http://localhost/justmarried')
     $this->wrong_replace = network_home_url() !== ($wrong_replace = str_replace($this->base_url, network_home_url(), network_home_url())) ? $wrong_replace : false;
     wp_defer_term_counting(true);
     wp_defer_comment_counting(true);
     do_action('import_start');
     // deprecated
     do_action('tf_ext_import_start');
 }
コード例 #3
0
 /**
  * Parses the XML file and prepares us for the task of processing parsed data
  *
  * @param string $file Path to the WXR file for importing
  */
 function import_start($file)
 {
     if (!is_file($file)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'anno') . '</strong><br />';
         echo __('The file does not exist, please try again.', 'anno') . '</p>';
         $this->footer();
         die;
     }
     $import_data = $this->parse($file);
     if (is_wp_error($import_data)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'anno') . '</strong><br />';
         echo esc_html($import_data->get_error_message()) . '</p>';
         $this->footer();
         die;
     }
     $this->version = $import_data['version'];
     $this->get_authors_from_import($import_data);
     $this->posts = $import_data['posts'];
     $this->terms = $import_data['terms'];
     $this->categories = $import_data['categories'];
     $this->tags = $import_data['tags'];
     $this->base_url = esc_url($import_data['base_url']);
     wp_defer_term_counting(true);
     wp_defer_comment_counting(true);
     do_action('import_start');
 }
コード例 #4
0
 /**
  * @param int     $pidd
  * @param WP_Post $post
  *
  * @return void
  */
 public function save_post_actions($pidd, $post)
 {
     global $sitepress;
     wp_defer_term_counting(true);
     $post = isset($post) ? $post : get_post($pidd);
     // exceptions
     if (!$this->has_save_post_action($post)) {
         wp_defer_term_counting(false);
         return;
     }
     $default_language = $sitepress->get_default_language();
     // allow post arguments to be passed via wp_insert_post directly and not be expected on $_POST exclusively
     $post_vars = (array) $_POST;
     foreach ((array) $post as $k => $v) {
         $post_vars[$k] = $v;
     }
     $post_vars['post_type'] = isset($post_vars['post_type']) ? $post_vars['post_type'] : $post->post_type;
     $post_id = isset($post_vars['post_ID']) ? $post_vars['post_ID'] : $pidd;
     //latter case for XML-RPC publishing
     $language_code = $this->get_save_post_lang($post_id, $sitepress);
     $trid = $this->get_save_post_trid($post_id, $post->post_status);
     // after getting the right trid set the source language from it by referring to the root translation
     // of this trid, in case no proper source language has been set yet
     $source_language = isset($source_language) ? $source_language : $this->get_save_post_source_lang($trid, $language_code, $default_language);
     $this->maybe_set_elid($trid, $post->post_type, $language_code, $post_id, $source_language);
     $translation_sync = $this->get_sync_helper();
     $original_id = $this->get_original_element($post_id);
     if ($original_id) {
         $translation_sync->sync_with_translations($original_id, $post_vars);
     }
     require_once ICL_PLUGIN_PATH . '/inc/cache.php';
     icl_cache_clear($post_vars['post_type'] . 's_per_language', true);
     wp_defer_term_counting(false);
 }
コード例 #5
0
ファイル: ti_import.php プロジェクト: adisonc/MaineLearning
 function import_end()
 {
     // Switch off importing flag and flush rewrite cache
     wp_defer_term_counting(false);
     wp_defer_comment_counting(true);
     global $wp_rewrite;
     $wp_rewrite->flush_rules();
 }
コード例 #6
0
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     wp_import_cleanup($this->id);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     do_action('import_end');
 }
コード例 #7
0
 public function save_post_actions($pidd, $post)
 {
     global $sitepress, $wpdb;
     wp_defer_term_counting(true);
     $post = isset($post) ? $post : get_post($pidd);
     // exceptions
     if (!$this->has_save_post_action($post)) {
         wp_defer_term_counting(false);
         return;
     }
     if (WPML_WordPress_Actions::is_bulk_trash($pidd) || WPML_WordPress_Actions::is_bulk_untrash($pidd)) {
         return;
     }
     $default_language = $sitepress->get_default_language();
     // allow post arguments to be passed via wp_insert_post directly and not be expected on $_POST exclusively
     $post_vars = (array) $_POST;
     foreach ((array) $post as $k => $v) {
         $post_vars[$k] = $v;
     }
     $post_vars['post_type'] = isset($post_vars['post_type']) ? $post_vars['post_type'] : $post->post_type;
     $post_id = $pidd;
     if (isset($post_vars['action']) && $post_vars['action'] === 'post-quickpress-publish') {
         $language_code = $default_language;
     } else {
         $post_id = isset($post_vars['post_ID']) ? $post_vars['post_ID'] : $pidd;
         //latter case for XML-RPC publishing
         $language_code = $this->get_save_post_lang($post_id, $sitepress);
     }
     if ($this->is_inline_action($post_vars) && !($language_code = $this->get_element_lang_code($post_id))) {
         return;
     }
     if (isset($post_vars['icl_translation_of']) && is_numeric($post_vars['icl_translation_of'])) {
         $translation_of_data_prepared = $wpdb->prepare("SELECT trid, language_code\n\t\t\t\t FROM {$wpdb->prefix}icl_translations\n\t\t\t\t WHERE element_id=%d\n\t\t\t\t  AND element_type=%s", $post_vars['icl_translation_of'], 'post_' . $post->post_type);
         list($trid, $source_language) = $wpdb->get_row($translation_of_data_prepared, 'ARRAY_N');
     }
     $trid = isset($trid) && $trid ? $trid : $this->get_save_post_trid($post_id, $post->post_status);
     // after getting the right trid set the source language from it by referring to the root translation
     // of this trid, in case no proper source language has been set yet
     $source_language = isset($source_language) ? $source_language : $this->get_save_post_source_lang($trid, $language_code, $default_language);
     $this->maybe_set_elid($trid, $post->post_type, $language_code, $post_id, $source_language);
     $translation_sync = $this->get_sync_helper();
     $original_id = $this->get_original_element($post_id);
     if ($original_id) {
         $translation_sync->sync_with_translations($original_id, $post_vars);
     }
     if (isset($post_vars['icl_tn_note'])) {
         update_post_meta($post_id, '_icl_translator_note', $post_vars['icl_tn_note']);
     }
     require_once ICL_PLUGIN_PATH . '/inc/cache.php';
     icl_cache_clear($post_vars['post_type'] . 's_per_language', true);
     wp_defer_term_counting(false);
 }
コード例 #8
0
 public function import_end()
 {
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     echo '<p>' . __('All done.', 'wordpress-importer') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'wordpress-importer') . '</a>' . '</p>';
     echo '<p>' . __('Remember to update the passwords and roles of imported users.', 'wordpress-importer') . '</p>';
     do_action('import_end');
 }
コード例 #9
0
 public function save_post_actions($pidd, $post)
 {
     global $sitepress;
     wp_defer_term_counting(true);
     $post = isset($post) ? $post : get_post($pidd);
     // exceptions
     if (!$this->has_save_post_action($post)) {
         wp_defer_term_counting(false);
         return;
     }
     if (WPML_WordPress_Actions::is_bulk_trash($pidd) || WPML_WordPress_Actions::is_bulk_untrash($pidd) || WPML_WordPress_Actions::is_heartbeat()) {
         return;
     }
     $default_language = $sitepress->get_default_language();
     $post_vars = (array) $_POST;
     foreach ((array) $post as $k => $v) {
         $post_vars[$k] = $v;
     }
     $post_vars['post_type'] = isset($post_vars['post_type']) ? $post_vars['post_type'] : $post->post_type;
     $post_id = $pidd;
     if (isset($post_vars['action']) && $post_vars['action'] === 'post-quickpress-publish') {
         $language_code = $default_language;
     } else {
         $post_id = isset($post_vars['post_ID']) ? $post_vars['post_ID'] : $pidd;
         //latter case for XML-RPC publishing
         $language_code = $this->get_save_post_lang($post_id, $sitepress);
     }
     if ($this->is_inline_action($post_vars) && !($language_code = $this->get_element_lang_code($post_id))) {
         return;
     }
     if (isset($post_vars['icl_translation_of']) && is_numeric($post_vars['icl_translation_of'])) {
         $translation_of_data_prepared = $this->wpdb->prepare("SELECT trid, language_code\n\t\t\t\t FROM {$this->wpdb->prefix}icl_translations\n\t\t\t\t WHERE element_id=%d\n\t\t\t\t\tAND element_type=%s\n\t\t\t\t LIMIT 1", $post_vars['icl_translation_of'], 'post_' . $post->post_type);
         list($trid, $source_language) = $this->wpdb->get_row($translation_of_data_prepared, 'ARRAY_N');
     }
     if (isset($post_vars['icl_translation_of']) && $post_vars['icl_translation_of'] == 'none') {
         $trid = null;
         $source_language = $language_code;
     } else {
         $trid = isset($trid) && $trid ? $trid : $this->get_save_post_trid($post_id, $post->post_status);
         // after getting the right trid set the source language from it by referring to the root translation
         // of this trid, in case no proper source language has been set yet
         $source_language = isset($source_language) ? $source_language : $this->get_save_post_source_lang($trid, $language_code, $default_language);
     }
     if (isset($post_vars['icl_tn_note'])) {
         update_post_meta($post_id, '_icl_translator_note', $post_vars['icl_tn_note']);
     }
     $save_filter_action_state = new WPML_WP_Filter_State('save_post');
     $this->after_save_post($trid, $post_vars, $language_code, $source_language);
     $save_filter_action_state->restore();
 }
コード例 #10
0
 function sync_menu_options($options_data)
 {
     foreach ($options_data as $menu_id => $translations) {
         foreach ($translations as $language => $option) {
             $translated_menu_id = $this->term_translations->term_id_in($menu_id, $language);
             if (isset($option['auto_add'])) {
                 $nav_menu_option = (array) get_option('nav_menu_options');
                 $nav_menu_option['auto_add'] = isset($nav_menu_option['auto_add']) ? $nav_menu_option['auto_add'] : array();
                 if ($option['auto_add'] && !in_array($translated_menu_id, $nav_menu_option['auto_add'])) {
                     $nav_menu_option['auto_add'][] = $translated_menu_id;
                 } elseif (!$option['auto_add'] && false !== ($key = array_search($translated_menu_id, $nav_menu_option['auto_add']))) {
                     unset($nav_menu_option['auto_add'][$key]);
                 }
                 $nav_menu_option['auto_add'] = array_intersect($nav_menu_option['auto_add'], wp_get_nav_menus(array('fields' => 'ids')));
                 update_option('nav_menu_options', array_filter($nav_menu_option));
                 wp_defer_term_counting(false);
                 do_action('wp_update_nav_menu', $translated_menu_id);
             }
         }
     }
 }
コード例 #11
0
ファイル: dtd-importer.php プロジェクト: dregula/Annotum
 /**
  * Parses the XML file and prepares us for the task of processing parsed data
  *
  * @param string $file Path to the WXR file for importing
  */
 function import_start($file)
 {
     if (!is_file($file)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'anno') . '</strong><br />';
         echo __('The file does not exist, please try again.', 'anno') . '</p>';
         $this->footer();
         die;
     }
     $import_data = $this->parse($file);
     if (is_wp_error($import_data)) {
         echo '<p><strong>' . __('Sorry, there has been an error.', 'anno') . '</strong><br />';
         echo esc_html($import_data->get_error_message()) . '</p>';
         $this->footer();
         die;
     }
     // Validation error likely
     if (isset($import_data['status']) && $import_data['status'] == 'error') {
         echo '<h3>' . __('There were the following errors while trying to validate your XML. Please correct them and try again.', 'anno') . '</h3>';
         foreach ($import_data['errors'] as $error) {
             $error_lines[] = $error['line'];
             echo '<div class="error">' . $error['fullMessage'] . '.</div>';
         }
         $this->output_XML($import_data['content'], $error_lines);
         $this->footer();
         die;
     }
     $this->version = $import_data['version'];
     $this->get_authors_from_import($import_data);
     $this->posts = $import_data['posts'];
     $this->terms = $import_data['terms'];
     $this->categories = $import_data['categories'];
     $this->tags = $import_data['tags'];
     $this->base_url = esc_url($import_data['base_url']);
     wp_defer_term_counting(true);
     wp_defer_comment_counting(true);
     do_action('import_start');
 }
コード例 #12
0
/**
 * Saves nav menu items
 *
 * @since 3.6.0
 *
 * @param int|string $nav_menu_selected_id (id, slug, or name ) of the currently-selected menu
 * @param string $nav_menu_selected_title Title of the currently-selected menu
 * @return array $messages The menu updated message
 */
function wp_nav_menu_update_menu_items($nav_menu_selected_id, $nav_menu_selected_title)
{
    $unsorted_menu_items = wp_get_nav_menu_items($nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish'));
    $messages = array();
    $menu_items = array();
    // Index menu items by db ID
    foreach ($unsorted_menu_items as $_item) {
        $menu_items[$_item->db_id] = $_item;
    }
    $post_fields = array('menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn');
    wp_defer_term_counting(true);
    // Loop through all the menu items' POST variables
    if (!empty($_POST['menu-item-db-id'])) {
        foreach ((array) $_POST['menu-item-db-id'] as $_key => $k) {
            // Menu item title can't be blank
            if (!isset($_POST['menu-item-title'][$_key]) || '' == $_POST['menu-item-title'][$_key]) {
                continue;
            }
            $args = array();
            foreach ($post_fields as $field) {
                $args[$field] = isset($_POST[$field][$_key]) ? $_POST[$field][$_key] : '';
            }
            $menu_item_db_id = wp_update_nav_menu_item($nav_menu_selected_id, $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key, $args);
            if (is_wp_error($menu_item_db_id)) {
                $messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>';
            } else {
                unset($menu_items[$menu_item_db_id]);
            }
        }
    }
    // Remove menu items from the menu that weren't in $_POST
    if (!empty($menu_items)) {
        foreach (array_keys($menu_items) as $menu_item_id) {
            if (is_nav_menu_item($menu_item_id)) {
                wp_delete_post($menu_item_id);
            }
        }
    }
    // Store 'auto-add' pages.
    $auto_add = !empty($_POST['auto-add-pages']);
    $nav_menu_option = (array) get_option('nav_menu_options');
    if (!isset($nav_menu_option['auto_add'])) {
        $nav_menu_option['auto_add'] = array();
    }
    if ($auto_add) {
        if (!in_array($nav_menu_selected_id, $nav_menu_option['auto_add'])) {
            $nav_menu_option['auto_add'][] = $nav_menu_selected_id;
        }
    } else {
        if (false !== ($key = array_search($nav_menu_selected_id, $nav_menu_option['auto_add']))) {
            unset($nav_menu_option['auto_add'][$key]);
        }
    }
    // Remove nonexistent/deleted menus
    $nav_menu_option['auto_add'] = array_intersect($nav_menu_option['auto_add'], wp_get_nav_menus(array('fields' => 'ids')));
    update_option('nav_menu_options', $nav_menu_option);
    wp_defer_term_counting(false);
    /** This action is documented in wp-includes/nav-menu.php */
    do_action('wp_update_nav_menu', $nav_menu_selected_id);
    $messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf(__('<strong>%1$s</strong> has been updated.'), $nav_menu_selected_title) . '</p></div>';
    unset($menu_items, $unsorted_menu_items);
    return $messages;
}
コード例 #13
0
ファイル: menus-sync.php プロジェクト: Calraiser/flux
 function do_sync($data)
 {
     global $wpdb, $sitepress;
     $current_language = $sitepress->get_current_language();
     $default_language = $sitepress->get_default_language();
     // menu translations
     if (!empty($data['menu_translation'])) {
         foreach ($data['menu_translation'] as $menu_id => $translations) {
             foreach ($translations as $language => $name) {
                 $_POST['icl_translation_of'] = $wpdb->get_var($wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy='nav_menu'", $menu_id));
                 $_POST['icl_nav_menu_language'] = $language;
                 $menu_indentation = '';
                 $menu_increment = 0;
                 do {
                     $new_menu_id = wp_update_nav_menu_object(0, array('menu-name' => $name . $menu_indentation . $menu_increment));
                     $menu_increment = $menu_increment != '' ? $menu_increment + 1 : 2;
                     $menu_indentation = '-';
                 } while (is_wp_error($new_menu_id) && $menu_increment < 10);
                 $this->menus[$menu_id]['translations'][$language] = array('id' => $new_menu_id);
             }
         }
     }
     // menu options
     if (!empty($data['menu_options'])) {
         foreach ($data['menu_options'] as $menu_id => $translations) {
             foreach ($translations as $language => $option) {
                 $translated_menu_id = $this->get_translated_menu_id($menu_id, $language);
                 foreach ($option as $key => $value) {
                     switch ($key) {
                         case 'auto_add':
                             // Store 'auto-add' pages.
                             $auto_add = $value;
                             $nav_menu_option = (array) get_option('nav_menu_options');
                             if (!isset($nav_menu_option['auto_add'])) {
                                 $nav_menu_option['auto_add'] = array();
                             }
                             if ($auto_add) {
                                 if (!in_array($translated_menu_id, $nav_menu_option['auto_add'])) {
                                     $nav_menu_option['auto_add'][] = $translated_menu_id;
                                 }
                             } else {
                                 if (false !== ($key = array_search($translated_menu_id, $nav_menu_option['auto_add']))) {
                                     unset($nav_menu_option['auto_add'][$key]);
                                 }
                             }
                             // Remove nonexistent/deleted menus
                             $nav_menu_option['auto_add'] = array_intersect($nav_menu_option['auto_add'], wp_get_nav_menus(array('fields' => 'ids')));
                             update_option('nav_menu_options', $nav_menu_option);
                             wp_defer_term_counting(false);
                             do_action('wp_update_nav_menu', $translated_menu_id);
                             break;
                     }
                 }
             }
         }
     }
     // deleting items
     if (!empty($data['del'])) {
         foreach ($data['del'] as $languages) {
             foreach ($languages as $items) {
                 foreach ($items as $item_id => $name) {
                     wp_delete_post($item_id, true);
                     $delete_trid = $sitepress->get_element_trid($item_id, 'post_nav_menu_item');
                     if ($delete_trid) {
                         $sitepress->delete_element_translation($delete_trid, 'post_nav_menu_item');
                     }
                 }
             }
         }
     }
     // moving items
     if (!empty($data['mov'])) {
         foreach ($data['mov'] as $menu_id => $items) {
             foreach ($items as $item_id => $changes) {
                 $trid = $sitepress->get_element_trid($item_id, 'post_nav_menu_item');
                 if (!$trid) {
                     $sitepress->set_element_language_details($item_id, 'post_nav_menu_item', false, $default_language);
                     $trid = $sitepress->get_element_trid($item_id, 'post_nav_menu_item');
                 }
                 foreach ($changes as $language => $details) {
                     $translated_item_id = $this->menus[$menu_id]['items'][$item_id]['translations'][$language]['ID'];
                     $new_menu_order = key($details);
                     $this->menus[$menu_id]['items'][$item_id]['translations'][$language]['menu_order'] = $new_menu_order;
                     $wpdb->update($wpdb->posts, array('menu_order' => $new_menu_order), array('ID' => $translated_item_id));
                     $sitepress->set_element_language_details($translated_item_id, 'post_nav_menu_item', $trid, $language);
                 }
             }
         }
         // fix hierarchy
         foreach ($data['mov'] as $menu_id => $items) {
             foreach ($items as $item_id => $changes) {
                 $parent_item = get_post_meta($item_id, '_menu_item_menu_item_parent', true);
                 foreach ($changes as $language => $details) {
                     $translated_item_id = $this->menus[$menu_id]['items'][$item_id]['translations'][$language]['ID'];
                     $translated_parent_menu_item_id = icl_object_id($parent_item, get_post_type($parent_item), false, $language);
                     if ($translated_parent_menu_item_id == $translated_item_id) {
                         $translated_parent_menu_item_id = false;
                     }
                     update_post_meta($translated_item_id, '_menu_item_menu_item_parent', $translated_parent_menu_item_id);
                 }
             }
         }
     }
     // adding items
     if (!empty($data['add'])) {
         foreach ($data['add'] as $menu_id => $items) {
             foreach ($items as $item_id => $translations) {
                 $trid = $sitepress->get_element_trid($item_id, 'post_nav_menu_item');
                 if (!$trid) {
                     $sitepress->set_element_language_details($item_id, 'post_nav_menu_item', false, $default_language);
                     $trid = $sitepress->get_element_trid($item_id, 'post_nav_menu_item');
                 }
                 foreach ($translations as $language => $name) {
                     $translated_object = $this->menus[$menu_id]['items'][$item_id]['translations'][$language];
                     $menu_name = $this->get_menu_name($menu_id);
                     $object_type = $translated_object['object_type'];
                     $object_title = $translated_object['title'];
                     $object_url = $translated_object['url'];
                     $icl_st_label_exists = false;
                     $icl_st_url_exists = false;
                     if ($object_type == 'custom' && (function_exists('icl_t') || !$this->string_translation_default_language_ok())) {
                         if (function_exists('icl_t') && $this->string_translation_default_language_ok()) {
                             $sitepress->switch_lang($language, false);
                             $object_title = icl_t($menu_name . ' menu', 'Menu Item Label ' . $item_id, $object_title, $icl_st_label_exists, false);
                             $object_url = icl_t($menu_name . ' menu', 'Menu Item URL ' . $item_id, $object_url, $icl_st_url_exists, false);
                             $sitepress->switch_lang($current_language, false);
                             if (!$icl_st_label_exists) {
                                 icl_register_string($menu_name . ' menu', 'Menu Item Label ' . $item_id, $object_title);
                             }
                             if (!$icl_st_url_exists) {
                                 icl_register_string($menu_name . ' menu', 'Menu Item URL ' . $item_id, $object_url);
                             }
                         } else {
                             $object_title = $name;
                         }
                     }
                     $menudata = array('menu-item-db-id' => 0, 'menu-item-object-id' => $translated_object['object_id'], 'menu-item-object' => $translated_object['object'], 'menu-item-parent-id' => 0, 'menu-item-position' => 0, 'menu-item-type' => $object_type, 'menu-item-title' => $object_title, 'menu-item-url' => $object_url, 'menu-item-description' => '', 'menu-item-attr-title' => $translated_object['attr-title'], 'menu-item-target' => $translated_object['target'], 'menu-item-classes' => $translated_object['classes'] ? implode(' ', $translated_object['classes']) : '', 'menu-item-xfn' => $translated_object['xfn'], 'menu-item-status' => 'publish');
                     $translated_menu_id = $this->menus[$menu_id]['translations'][$language]['id'];
                     remove_filter('get_term', array($sitepress, 'get_term_adjust_id'));
                     // AVOID filtering to current language
                     $translated_item_id = wp_update_nav_menu_item($translated_menu_id, 0, $menudata);
                     // set language explicitly since the 'wp_update_nav_menu_item' is still TBD
                     $sitepress->set_element_language_details($translated_item_id, 'post_nav_menu_item', $trid, $language);
                     $menu_tax_id_prepared = $wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy='nav_menu'", $translated_menu_id);
                     $menu_tax_id = $wpdb->get_var($menu_tax_id_prepared);
                     if ($translated_item_id && $menu_tax_id) {
                         $rel_prepared = $wpdb->prepare("SELECT object_id FROM {$wpdb->term_relationships} WHERE object_id=%d AND term_taxonomy_id=%d", $translated_item_id, $menu_tax_id);
                         $rel = $wpdb->get_var($rel_prepared);
                         if (!$rel) {
                             $wpdb->insert($wpdb->term_relationships, array('object_id' => $translated_item_id, 'term_taxonomy_id' => $menu_tax_id));
                         }
                     }
                     $this->menus[$menu_id]['items'][$item_id]['translations'][$language]['ID'] = $translated_item_id;
                 }
             }
         }
         // set/fix hierarchy
         foreach ($data['add'] as $menu_id => $items) {
             foreach ($items as $item_id => $translations) {
                 foreach ($translations as $language => $name) {
                     $item_parent = $this->menus[$menu_id]['items'][$item_id]['parent'];
                     if ($item_parent) {
                         $parent_object_id = $this->menus[$menu_id]['items'][$item_parent]['object_id'];
                         $parent_object = $this->menus[$menu_id]['items'][$item_parent]['object'];
                         $element_type = $parent_object;
                         if ($this->menus[$menu_id]['items'][$item_parent]['object_type'] == 'custom') {
                             $element_type = 'nav_menu_item';
                         }
                         $translated_parent_object_id = icl_object_id($parent_object_id, $element_type, false, $language);
                         if ($translated_parent_object_id) {
                             $translated_parent_item_id = $wpdb->get_var($wpdb->prepare("\n                                    SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_menu_item_object_id' AND meta_value=%d ORDER BY meta_id DESC LIMIT 1", $translated_parent_object_id));
                             $translated_item_id = $this->menus[$menu_id]['items'][$item_id]['translations'][$language]['ID'];
                             update_post_meta($translated_item_id, '_menu_item_menu_item_parent', $translated_parent_item_id);
                         }
                     }
                 }
             }
         }
     }
     // update strings: caption
     if (!empty($data['label_changed'])) {
         foreach ($data['label_changed'] as $languages) {
             foreach ($languages as $language => $items) {
                 foreach ($items as $item_id => $name) {
                     $trid = $sitepress->get_element_trid($item_id, 'post_nav_menu_item');
                     if ($trid) {
                         $item_translations = $sitepress->get_element_translations($trid, 'post_nav_menu_item', true);
                         if (isset($item_translations[$language])) {
                             $translated_item_id = $item_translations[$language]->element_id;
                             $translated_item = get_post($translated_item_id);
                             $translated_item->post_title = $name;
                             wp_update_post($translated_item);
                         }
                     }
                 }
             }
         }
     }
     // update strings: url
     if (!empty($data['url_changed'])) {
         foreach ($data['url_changed'] as $languages) {
             foreach ($languages as $language => $items) {
                 foreach ($items as $item_id => $url) {
                     $trid = $sitepress->get_element_trid($item_id, 'post_nav_menu_item');
                     if ($trid) {
                         $item_translations = $sitepress->get_element_translations($trid, 'post_nav_menu_item', true);
                         if (isset($item_translations[$language])) {
                             $translated_item_id = $item_translations[$language]->element_id;
                             if ($url) {
                                 update_post_meta($translated_item_id, '_menu_item_url', $url);
                             }
                         }
                     }
                 }
             }
         }
     }
     // add string to ST: caption
     if (!empty($data['label_missing'])) {
         static $labels_to_add;
         if (!isset($labels_to_add)) {
             $labels_to_add = array();
         }
         foreach ($data['label_missing'] as $menu_id => $languages) {
             foreach ($languages as $items) {
                 foreach ($items as $item_id => $name) {
                     if (!in_array($menu_id . '-' . $item_id, $labels_to_add)) {
                         $item = get_post($item_id);
                         icl_register_string($this->get_menu_name($menu_id) . ' menu', 'Menu Item Label ' . $item_id, $item->post_title);
                         $labels_to_add[] = $menu_id . '-' . $item_id;
                     }
                 }
             }
         }
     }
     // add string to ST: url
     if (!empty($data['url_missing'])) {
         static $urls_to_add;
         if (!isset($urls_to_add)) {
             $urls_to_add = array();
         }
         foreach ($data['url_missing'] as $menu_id => $languages) {
             foreach ($languages as $items) {
                 foreach ($items as $item_id => $url) {
                     if (!in_array($menu_id . '-' . $item_id, $urls_to_add)) {
                         icl_register_string($this->get_menu_name($menu_id) . ' menu', 'Menu Item URL ' . $item_id, $url);
                         $urls_to_add[] = $menu_id . '-' . $item_id;
                     }
                 }
             }
         }
     }
     // set menu order
     foreach ($this->menus as $menu_id => $menu) {
         $menu_index_by_lang = array();
         foreach ($menu['items'] as $item_id => $item) {
             foreach ($item['translations'] as $language => $item_translation) {
                 if ($item_translation['ID']) {
                     $new_menu_order = empty($menu_index_by_lang[$language]) ? 1 : $menu_index_by_lang[$language] + 1;
                     $menu_index_by_lang[$language] = $new_menu_order;
                     if ($new_menu_order != $this->menus[$menu_id]['items'][$item_id]['translations'][$language]['menu_order']) {
                         $this->menus[$menu_id]['items'][$item_id]['translations'][$language]['menu_order'] = $new_menu_order;
                         $wpdb->update($wpdb->posts, array('menu_order' => $this->menus[$menu_id]['items'][$item_id]['translations'][$language]['menu_order']), array('ID' => $item_translation['ID']));
                     }
                 }
             }
         }
     }
     wp_redirect(admin_url('admin.php?page=' . ICL_PLUGIN_FOLDER . '/menu/menus-sync.php&updated=1'));
     exit;
 }
コード例 #14
0
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     wp_import_cleanup($this->id);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     echo '<p>' . __('All done.', 'nav-menu-roles') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'nav-menu-roles') . '</a>' . '</p>';
     do_action('import_end');
 }
                if (!isset($nav_menu_option['auto_add'])) {
                    $nav_menu_option['auto_add'] = array();
                }
                if ($auto_add) {
                    if (!in_array($nav_menu_selected_id, $nav_menu_option['auto_add'])) {
                        $nav_menu_option['auto_add'][] = $nav_menu_selected_id;
                    }
                } else {
                    if (false !== ($key = array_search($nav_menu_selected_id, $nav_menu_option['auto_add']))) {
                        unset($nav_menu_option['auto_add'][$key]);
                    }
                }
                // Remove nonexistent/deleted menus
                $nav_menu_option['auto_add'] = array_intersect($nav_menu_option['auto_add'], wp_get_nav_menus(array('fields' => 'ids')));
                update_option('nav_menu_options', $nav_menu_option);
                wp_defer_term_counting(false);
                do_action('wp_update_nav_menu', $nav_menu_selected_id);
                $messages[] = '<div id="message" class="updated"><p>' . sprintf(__('The <strong>%s</strong> menu has been updated.'), $nav_menu_selected_title) . '</p></div>';
                unset($menu_items, $unsorted_menu_items);
            }
        }
        break;
}
// Get all nav menus
$nav_menus = wp_get_nav_menus(array('orderby' => 'name'));
// Get recently edited nav menu
$recently_edited = (int) get_user_option('nav_menu_recently_edited');
// If there was no recently edited menu, and $nav_menu_selected_id is a nav menu, update recently edited menu.
if (!$recently_edited && is_nav_menu($nav_menu_selected_id)) {
    $recently_edited = $nav_menu_selected_id;
    // Else if $nav_menu_selected_id is not a menu and not requesting that we create a new menu, but $recently_edited is a menu, grab that one.
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     wp_import_cleanup($this->id);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     echo '<p>' . __('All done.', 'wordpress-importer') . '</p>';
     do_action('import_end');
 }
コード例 #17
0
 /**
  * Count terms. These are done at this point so all product props are set in advance.
  *
  * @param WC_Product
  * @since 2.7.0
  */
 protected function update_term_counts(&$product)
 {
     if (!wp_defer_term_counting()) {
         global $wc_allow_term_recount;
         $wc_allow_term_recount = true;
         $post_type = $product->is_type('variation') ? 'product_variation' : 'product';
         // Update counts for the post's terms.
         foreach ((array) get_object_taxonomies($post_type) as $taxonomy) {
             $tt_ids = wc_get_object_terms($product->get_id(), $taxonomy, 'term_taxonomy_id');
             wp_update_term_count($tt_ids, $taxonomy);
         }
     }
 }
コード例 #18
0
 /**
  * Performs post-import cleanup of files and the cache
  */
 protected function import_end()
 {
     // Re-enable stuff in core
     wp_suspend_cache_invalidation(false);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     /**
      * Complete the import.
      *
      * Fires after the import process has finished. If you need to update
      * your cache or re-enable processing, do so here.
      */
     do_action('import_end');
 }
コード例 #19
0
ファイル: class-dfrps-update.php プロジェクト: jimmitjoo/mnh
 function defer_counting($bool)
 {
     wp_defer_term_counting($bool);
     wp_defer_comment_counting($bool);
 }
コード例 #20
0
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     wp_import_cleanup($this->id);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     update_option('cherry_sample_data', 1);
     do_action('import_end');
     $this->log(date('Y-m-d H:i:s'));
     $this->log(PHP_EOL . 'Import end' . PHP_EOL);
 }
コード例 #21
0
 /**
  * Delete table
  *
  * @return bool
  */
 public function delete_table($data)
 {
     if (empty($data)) {
         GW_GoPricing_AdminNotices::add('main', 'error', __('Please select a table!', 'go_pricing_textdomain'));
         return;
     }
     $cnt = 0;
     global $wpdb;
     $data = GW_GoPricing_Helper::clean_input($data);
     wp_defer_term_counting(true);
     wp_defer_comment_counting(true);
     $wpdb->query('SET autocommit = 0;');
     $table_ids = explode(',', $data);
     foreach ((array) $table_ids as $table_id) {
         $result = GW_GoPricing_Data::delete_table((int) $table_id);
         $cnt++;
         if ($result === false) {
             GW_GoPricing_AdminNotices::add('main', 'error', __('Oops, something went wrong!', 'go_pricing_textdomain'));
             break;
         }
     }
     $notices = GW_GoPricing_AdminNotices::get('main', 'error');
     if (empty($notices)) {
         GW_GoPricing_AdminNotices::add('main', 'success', sprintf(__('%1$s pricing table(s) has been successfully deleted.', 'go_pricing_textdomain'), $cnt));
     }
     $wpdb->query('COMMIT;');
     $wpdb->query('SET autocommit = 1;');
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
 }
コード例 #22
0
 function save_post_actions($pidd, $post)
 {
     global $wpdb;
     wp_defer_term_counting(true);
     list($post_type, $post_status) = $wpdb->get_row("SELECT post_type, post_status FROM {$wpdb->posts} WHERE ID = " . $pidd, ARRAY_N);
     // exceptions
     if (!$this->is_translated_post_type($post_type) || isset($post) && $post->post_status == "auto-draft" || isset($_POST['autosave']) || isset($_POST['skip_sitepress_actions']) || isset($_POST['post_ID']) && $_POST['post_ID'] != $pidd || isset($_POST['post_type']) && $_POST['post_type'] == 'revision' || $post_type == 'revision' || get_post_meta($pidd, '_wp_trash_meta_status', true) || isset($_GET['action']) && $_GET['action'] == 'untrash') {
         wp_defer_term_counting(false);
         return;
     }
     $default_language = $this->get_default_language();
     if (!isset($post) && $pidd) {
         $post = get_post($pidd);
     }
     // exception for auto-drafts - setting the right language
     // allow post arguments to be passed via wp_insert_post directly and not be expected on $_POST exclusively
     $post_vars = (array) $_POST;
     foreach ((array) $post as $k => $v) {
         $post_vars[$k] = $v;
     }
     if (!isset($post_vars['post_type'])) {
         $post_vars['post_type'] = $post_type;
     }
     $element_type = 'post_' . $post_type;
     $language_code = false;
     if (isset($post_vars['action']) && $post_vars['action'] == 'post-quickpress-publish') {
         $post_id = $pidd;
         $language_code = $default_language;
     } elseif (isset($_GET['bulk_edit'])) {
         $post_id = $pidd;
     } else {
         $post_id = isset($post_vars['post_ID']) ? $post_vars['post_ID'] : $pidd;
         //latter case for XML-RPC publishing
         if (isset($post_vars['icl_post_language'])) {
             $language_code = $post_vars['icl_post_language'];
         } elseif (isset($_GET['lang'])) {
             $language_code = $_GET['lang'];
         } elseif ($_ldet = $this->get_element_language_details($post_id, $element_type)) {
             $language_code = $_ldet->language_code;
         } elseif (isset($this->this_lang)) {
             $language_code = $this->this_lang;
         } else {
             $language_code = $default_language;
             //latter case for XML-RPC publishing
         }
     }
     if (isset($post_vars['action']) && $post_vars['action'] == 'inline-save' || isset($_GET['bulk_edit']) || isset($_GET['doing_wp_cron']) || isset($_GET['action']) && $_GET['action'] == 'untrash') {
         $res = $this->get_element_language_details($post_id, 'post_' . $post->post_type);
         if (!isset($res) || !$res) {
             return;
         }
         $language_code = $res->language_code;
         $trid = $res->trid;
     } else {
         if (isset($post_vars['icl_trid'])) {
             $trid = @intval($post_vars['icl_trid']);
         } elseif (isset($_GET['trid'])) {
             $trid = @intval($_GET['trid']);
         } else {
             $trid = $this->get_element_trid($post_id, 'post_' . $post->post_type);
         }
         // see if we have a "translation of" setting.
         if (isset($post_vars['icl_translation_of'])) {
             if (is_numeric($post_vars['icl_translation_of'])) {
                 $translation_of_data_prepared = $wpdb->prepare("SELECT trid, language_code FROM {$wpdb->prefix}icl_translations WHERE element_id=%d AND element_type=%s", $post_vars['icl_translation_of'], 'post_' . $post->post_type);
                 list($trid, $source_language) = $wpdb->get_row($translation_of_data_prepared, 'ARRAY_N');
             } else {
                 if (empty($post_vars['icl_trid'])) {
                     $trid = null;
                 }
             }
         }
     }
     if (isset($_POST['action']) && $_POST['action'] == 'inline-save') {
         $trid = $this->get_element_trid($post_id, 'post_' . $post_type);
     } else {
         if (isset($post_vars['icl_translation_of']) && $post_vars['icl_translation_of'] == 'none') {
             $trid = null;
         }
     }
     if (!$trid) {
         $trid_from_referrer = $this->get_trid_from_referer();
         if ($trid_from_referrer) {
             $trid = $trid_from_referrer;
         }
     }
     if (!$this->is_active_language($language_code)) {
         $language_code = $default_language;
     }
     // set trid if front-end translation creating
     $trid = apply_filters('wpml_save_post_trid_value', $trid, $post_status);
     // set post language if front-end translation creating
     $language_code = apply_filters('wpml_save_post_lang', $language_code);
     // after getting the right trid set the source language from it by referring to the root translation
     // of this trid, in case no proper source language is set already
     if (!isset($source_language) || !$source_language || $source_language == $language_code) {
         //if we are in the editor we can get the source language from the http-referer of the ajax request
         $source_language = self::get_source_language_from_referer();
         if (!$source_language) {
             //if getting the source language from the referer fails too, we get that of the first element of the trid
             $source_language = self::get_source_language_by_trid($trid);
         }
     }
     /* Before setting the language of the post to be saved, check if a translation in this language already exists
      * This check is necessary, so that synchronization actions like thrashing or un-trashing of posts, do not lead to
      * database corruption, due to erroneously changing a posts language into a state,
      * where it collides with an existing translation. While the UI prevents this sort of action for the most part,
      * this is not necessarily the case for other plugins like TM.
      * The logic here first of all checks if an existing translation id is present in the desired language_code.
      * If so but this translation is actually not the currently to be saved post,
      * then this post will be saved to its current language. If the translation already exists,
      * the existing translation id will be used. In all other cases a new entry in icl_translations will be created.
      */
     $existing_translations = $this->get_element_translations($trid, $element_type);
     if ($existing_translations && isset($existing_translations[$language_code])) {
         $current_language_details = $this->get_element_language_details($post_id, $element_type);
         $existing_translation = $existing_translations[$language_code];
         if ($current_language_details && isset($current_language_details->language_code) && $existing_translation && isset($existing_translation->element_id) && isset($current_language_details->element_id) && $existing_translation->element_id != $current_language_details->element_id) {
             $translation_id = $existing_translations[$current_language_details->language_code]->translation_id;
             $language_code = $current_language_details->language_code;
         } else {
             $translation_id = $existing_translations[$existing_translation->language_code]->translation_id;
         }
     } else {
         $translation_id = $this->set_element_language_details($post_id, $element_type, $trid, $language_code, $source_language);
     }
     //get trid of $translation_id
     $translated_id_trid = $wpdb->get_var($wpdb->prepare("SELECT trid FROM {$wpdb->prefix}icl_translations WHERE translation_id=%d", array($translation_id)));
     //get all translations
     $translated_element_id = $wpdb->get_col($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d", $translated_id_trid));
     if (!in_array($post_type, array('post', 'page')) && !$this->is_translated_post_type($post_type)) {
         wp_defer_term_counting(false);
         return;
     }
     // synchronize the page order for translations
     if ($trid && $this->settings['sync_page_ordering'] && $translated_element_id && is_array($translated_element_id)) {
         $menu_order = esc_sql($post_vars['menu_order']);
         // Only use non-null element ids for the menu ordering.
         $non_null_eids = array_filter($translated_element_id);
         $wpdb->query("UPDATE {$wpdb->posts} SET menu_order={$menu_order} WHERE ID IN (" . join(',', $non_null_eids) . ")");
     }
     // synchronize the page parent for translations
     if ($trid && $this->settings['sync_page_parent']) {
         $original_id = $this->get_original_element_id($post_id, 'post_' . $post_vars['post_type']);
         if ($original_id == $post_id) {
             $translations = $this->get_element_translations($trid, 'post_' . $post_vars['post_type']);
             foreach ($translations as $target_lang => $target_details) {
                 if ($target_lang != $language_code) {
                     if ($target_details->element_id) {
                         $this->fix_translated_parent($post_id, $target_details->element_id, $target_lang);
                     }
                 }
             }
         }
     }
     // synchronize the page template
     if (isset($post_vars['page_template']) && $trid && $post_vars['post_type'] == 'page' && $this->settings['sync_page_template']) {
         if ($translated_element_id && is_array($translated_element_id)) {
             foreach ($translated_element_id as $tp) {
                 if ($tp != $post_id) {
                     update_post_meta($tp, '_wp_page_template', $post_vars['page_template']);
                 }
             }
         }
     }
     // synchronize comment and ping status
     if ($trid && ($this->settings['sync_ping_status'] || $this->settings['sync_comment_status'])) {
         $arr = array();
         if ($this->settings['sync_comment_status']) {
             $arr['comment_status'] = $post_vars['comment_status'];
         }
         if ($this->settings['sync_ping_status']) {
             $arr['ping_status'] = $post_vars['ping_status'];
         }
         if (!empty($arr) && $translated_element_id && is_array($translated_element_id)) {
             foreach ($translated_element_id as $tp) {
                 if ($tp != $post_id) {
                     $wpdb->update($wpdb->posts, $arr, array('ID' => $tp));
                 }
             }
         }
     }
     // copy custom fields from original
     $translations = $this->get_element_translations($trid, 'post_' . $post_vars['post_type']);
     if (!empty($translations)) {
         $original_post_id = false;
         foreach ($translations as $t) {
             if ($t->original) {
                 $original_post_id = $t->element_id;
                 break;
             }
         }
         // this runs only for translated documents
         if ($post_id != $original_post_id) {
             $this->copy_custom_fields($original_post_id, $post_id);
         } else {
             foreach ($translations as $t) {
                 if ($original_post_id != $t->element_id) {
                     $this->copy_custom_fields($original_post_id, $t->element_id);
                 }
             }
         }
     }
     //sync posts stickiness
     if (isset($post_vars['post_type']) && $post_vars['post_type'] == 'post' && isset($post_vars['action']) && $post_vars['action'] != 'post-quickpress-publish' && $this->settings['sync_sticky_flag']) {
         //not for quick press
         remove_filter('option_sticky_posts', array($this, 'option_sticky_posts'));
         // remove filter used to get language relevant stickies. get them all
         $sticky_posts = get_option('sticky_posts');
         add_filter('option_sticky_posts', array($this, 'option_sticky_posts'));
         // add filter back
         // get ids of the translations
         if ($trid) {
             $translations = $wpdb->get_col($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d", $trid));
         } else {
             $translations = array();
         }
         if (isset($post_vars['sticky']) && $post_vars['sticky'] == 'sticky') {
             $sticky_posts = array_unique(array_merge($sticky_posts, $translations));
         } else {
             //makes sure translations are not set to sticky if this posts switched from sticky to not-sticky
             $sticky_posts = array_diff($sticky_posts, $translations);
         }
         update_option('sticky_posts', $sticky_posts);
     }
     //sync private flag
     if ($this->settings['sync_private_flag']) {
         if ($post_status == 'private' && (empty($post_vars['original_post_status']) || $post_vars['original_post_status'] != 'private')) {
             if ($translated_element_id && is_array($translated_element_id)) {
                 foreach ($translated_element_id as $tp) {
                     if ($tp != $post_id) {
                         $wpdb->update($wpdb->posts, array('post_status' => 'private'), array('ID' => $tp));
                     }
                 }
             }
         } elseif ($post_status != 'private' && isset($post_vars['original_post_status']) && $post_vars['original_post_status'] == 'private') {
             if ($translated_element_id && is_array($translated_element_id)) {
                 foreach ($translated_element_id as $tp) {
                     if ($tp != $post_id) {
                         $wpdb->update($wpdb->posts, array('post_status' => $post_status), array('ID' => $tp));
                     }
                 }
             }
         }
     }
     //sync post format
     if ($this->settings['sync_post_format'] && function_exists('set_post_format')) {
         $format = get_post_format($post_id);
         if ($translated_element_id && is_array($translated_element_id)) {
             foreach ($translated_element_id as $tp) {
                 if ($tp != $post_id) {
                     set_post_format($tp, $format);
                 }
             }
         }
     }
     // sync post dates
     if (!empty($this->settings['sync_post_date'])) {
         if ($language_code == $default_language) {
             if ($translated_element_id && is_array($translated_element_id)) {
                 $post_date = $wpdb->get_var($wpdb->prepare("SELECT post_date FROM {$wpdb->posts} WHERE ID=%d", $post_id));
                 foreach ($translated_element_id as $tp) {
                     if ($tp != $post_id) {
                         $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => get_gmt_from_date($post_date)), array('ID' => $tp));
                     }
                 }
             }
         } else {
             if (!is_null($trid)) {
                 $source_lang = isset($_GET['source_lang']) ? $_GET['source_lang'] : $default_language;
                 $original_id = $wpdb->get_var($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d AND language_code=%s", $trid, $source_lang));
                 if (!$original_id) {
                     global $post;
                     if (isset($post->ID)) {
                         $original_id = $post->ID;
                     }
                 }
                 if (isset($original_id)) {
                     $post_date = $wpdb->get_var($wpdb->prepare("SELECT post_date FROM {$wpdb->posts} WHERE ID=%d", $original_id));
                     $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => get_gmt_from_date($post_date)), array('ID' => $post_id));
                 }
             }
         }
     }
     if (isset($post_vars['icl_tn_note'])) {
         update_post_meta($post_id, '_icl_translator_note', $post_vars['icl_tn_note']);
     }
     //fix guid
     if ($this->settings['language_negotiation_type'] == 2 && $this->get_current_language() != $default_language) {
         $guid = $this->convert_url(get_post_field('guid', $post_id));
         $wpdb->update($wpdb->posts, array('guid' => $guid), array('id' => $post_id));
     }
     require_once ICL_PLUGIN_PATH . '/inc/cache.php';
     icl_cache_clear($post_vars['post_type'] . 's_per_language', true);
     wp_defer_term_counting(false);
 }
コード例 #23
0
function wpsc_convert_variation_combinations()
{
    global $wpdb, $user_ID, $current_version_number;
    $wpsc_update = WPSC_Update::get_instance();
    remove_filter('get_terms', 'wpsc_get_terms_category_sort_filter');
    if (!($offset = get_transient('wpsc_update_variation_comb_offset'))) {
        $offset = 0;
    }
    $limit = 150;
    wp_defer_term_counting(true);
    $sql = "SELECT * FROM {$wpdb->posts} WHERE post_type = 'wpsc-product' AND post_parent = 0 LIMIT %d, %d";
    $total = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'wpsc-product' AND post_parent = 0");
    $progress = new WPSC_Update_Progress($total);
    while (true) {
        // get the posts
        // I use a direct SQL query here because the get_posts function sometimes does not function for a reason that is not clear.
        $posts = $wpdb->get_results($wpdb->prepare($sql, $offset, $limit));
        $i = $offset;
        if (empty($posts)) {
            break;
        }
        foreach ((array) $posts as $post) {
            if (!($child_products = get_transient('wpsc_update_current_child_products'))) {
                $child_products = array();
            }
            $wpsc_update->check_timeout();
            $base_product_terms = array();
            //create a post template
            $child_product_template = array('post_author' => $user_ID, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_title' => $post->post_title, 'post_status' => 'inherit', 'post_type' => "wpsc-product", 'post_name' => $post->post_title, 'post_parent' => $post->ID);
            // select the original product ID
            $original_id = get_post_meta($post->ID, '_wpsc_original_id', true);
            $parent_stock = get_post_meta($post->ID, '_wpsc_stock', true);
            // select the variation set associations
            $variation_set_associations = $wpdb->get_col("SELECT `variation_id` FROM " . WPSC_TABLE_VARIATION_ASSOC . " WHERE `associated_id` = '{$original_id}'");
            // select the variation associations if the count of variation sets is greater than zero
            if ($original_id > 0 && count($variation_set_associations) > 0) {
                $variation_associations = $wpdb->get_col("SELECT `value_id` FROM " . WPSC_TABLE_VARIATION_VALUES_ASSOC . " WHERE `product_id` = '{$original_id}' AND `variation_id` IN(" . implode(", ", $variation_set_associations) . ") AND `visible` IN ('1')");
            } else {
                // otherwise, we have no active variations, skip to the next product
                $i++;
                $progress->update($i);
                set_transient('wpsc_update_variation_comb_offset', $i, 604800);
                continue;
            }
            $variation_set_id_sql = "SELECT meta_value FROM " . WPSC_TABLE_META . " WHERE object_type='wpsc_variation_set' AND object_id IN (" . implode(',', $variation_set_associations) . ") AND meta_key = 'variation_set_id'";
            $variation_set_terms = $wpdb->get_col($variation_set_id_sql);
            $variation_associations_sql = "SELECT meta_value FROM " . WPSC_TABLE_META . " WHERE object_type='wpsc_variation' AND object_id IN (" . implode(',', $variation_associations) . ") AND meta_key = 'variation_id'";
            $variation_associations_terms = $wpdb->get_col($variation_associations_sql);
            $base_product_terms = array_merge($base_product_terms, $variation_set_terms, $variation_associations_terms);
            // Now that we have the term IDs, we need to retrieve the slugs, as wp_set_object_terms will not use IDs in the way we want
            // If we pass IDs into wp_set_object_terms, it creates terms using the ID as the name.
            $parent_product_terms = get_terms('wpsc-variation', array('hide_empty' => 0, 'include' => implode(",", $base_product_terms), 'orderby' => 'parent'));
            $base_product_term_slugs = array();
            foreach ($parent_product_terms as $parent_product_term) {
                $base_product_term_slugs[] = $parent_product_term->slug;
            }
            wp_set_object_terms($post->ID, $base_product_term_slugs, 'wpsc-variation');
            // select all variation "products"
            $variation_items = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_VARIATION_PROPERTIES . " WHERE `product_id` = '{$original_id}'");
            foreach ((array) $variation_items as $variation_item) {
                $wpsc_update->check_timeout();
                // initialize the requisite arrays to empty
                $variation_ids = array();
                $term_data = array('ids' => array(), 'slugs' => array(), 'names' => array());
                // make a temporary copy of the product teplate
                $product_values = $child_product_template;
                // select all values this "product" is associated with, then loop through them, getting the term id of the variation using the value ID
                $variation_associations_combinations = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_VARIATION_COMBINATIONS . " WHERE `priceandstock_id` = '{$variation_item->id}'");
                foreach ((array) $variation_associations_combinations as $association) {
                    $variation_id = (int) wpsc_get_meta($association->value_id, 'variation_id', 'wpsc_variation');
                    // discard any values that are null, as they break the selecting of the terms
                    if ($variation_id > 0 && in_array($association->value_id, $variation_associations)) {
                        $variation_ids[] = $variation_id;
                    }
                }
                // if we have more than zero remaining terms, get the term data, then loop through it to convert it to a more useful set of arrays.
                if (count($variation_ids) > 0 && count($variation_set_associations) == count($variation_ids)) {
                    $combination_terms = get_terms('wpsc-variation', array('hide_empty' => 0, 'include' => implode(",", $variation_ids)));
                    foreach ($combination_terms as $term) {
                        $term_data['ids'][] = $term->term_id;
                        $term_data['slugs'][] = $term->slug;
                        $term_data['names'][] = $term->name;
                    }
                    $product_values['post_title'] .= " (" . implode(", ", $term_data['names']) . ")";
                    $product_values['post_name'] = sanitize_title($product_values['post_title']);
                    $selected_post = get_posts(array('name' => $product_values['post_name'], 'post_parent' => $post->ID, 'post_type' => "wpsc-product", 'post_status' => 'all', 'suppress_filters' => true));
                    $selected_post = array_shift($selected_post);
                    $key = md5($post->ID . ':' . count($term_data['ids']) . ':' . implode(',', $term_data['ids']));
                    $child_product_id = false;
                    if (!empty($child_products[$key])) {
                        $child_product_id = $child_products[$key];
                    }
                    $post_data = array();
                    $post_data['_wpsc_price'] = (double) $variation_item->price;
                    $post_data['_wpsc_stock'] = (double) $variation_item->stock;
                    if (!is_numeric($parent_stock)) {
                        $post_data['_wpsc_stock'] = false;
                    }
                    $post_data['_wpsc_original_variation_id'] = (double) $variation_item->id;
                    // Product Weight
                    $post_data['_wpsc_product_metadata']['weight'] = wpsc_convert_weight($variation_item->weight, $variation_item->weight_unit, "pound", true);
                    $post_data['_wpsc_product_metadata']['display_weight_as'] = $variation_item->weight_unit;
                    $post_data['_wpsc_product_metadata']['weight_unit'] = $variation_item->weight_unit;
                    // Parts of the code (eg wpsc_product_variation_price_from() make the assumption that these meta keys exist
                    $post_data['_wpsc_special_price'] = 0;
                    $post_data['_wpsc_sku'] = '';
                    $already_exists = true;
                    if (!empty($selected_post) && $selected_post->ID != $child_product_id) {
                        $child_product_id = $selected_post->ID;
                    } elseif (empty($child_product_id)) {
                        $child_product_id = wp_insert_post($product_values);
                        $already_exists = false;
                    }
                    if ($child_product_id > 0) {
                        foreach ($post_data as $meta_key => $meta_value) {
                            // prefix all meta keys with _wpsc_
                            update_post_meta($child_product_id, $meta_key, $meta_value);
                        }
                        wp_set_object_terms($child_product_id, $term_data['slugs'], 'wpsc-variation');
                        if (!$already_exists) {
                            $child_products[$key] = $child_product_id;
                            set_transient('wpsc_update_current_child_products', $child_products, 604800);
                        }
                    }
                    unset($term_data);
                }
            }
            $i++;
            $progress->update($i);
            set_transient('wpsc_update_variation_comb_offset', $i, 604800);
            delete_transient('wpsc_update_current_child_products');
        }
        $offset += $limit;
    }
    delete_option("wpsc-variation_children");
    _get_term_hierarchy('wpsc-variation');
    delete_option("wpsc_product_category_children");
    _get_term_hierarchy('wpsc_product_category');
}
コード例 #24
0
ファイル: sitepress.class.php プロジェクト: sedici/wpmu-istec
 function save_post_actions($pidd, $post)
 {
     global $wpdb;
     wp_defer_term_counting(true);
     list($post_type, $post_status) = $wpdb->get_row("SELECT post_type, post_status FROM {$wpdb->posts} WHERE ID = " . $pidd, ARRAY_N);
     // exceptions
     if (!$this->is_translated_post_type($post_type) || isset($post) && $post->post_status == "auto-draft" || isset($_POST['autosave']) || isset($_POST['skip_sitepress_actions']) || isset($_POST['post_ID']) && $_POST['post_ID'] != $pidd || isset($_POST['post_type']) && $_POST['post_type'] == 'revision' || $post_type == 'revision' || get_post_meta($pidd, '_wp_trash_meta_status', true) || isset($_GET['action']) && $_GET['action'] == 'untrash') {
         wp_defer_term_counting(false);
         return;
     }
     $default_language = $this->get_default_language();
     if (!isset($post) && $pidd) {
         $post = get_post($pidd);
     }
     // exception for auto-drafts - setting the right language
     // allow post arguments to be passed via wp_insert_post directly and not be expected on $_POST exclusively
     $post_vars = (array) $_POST;
     foreach ((array) $post as $k => $v) {
         $post_vars[$k] = $v;
     }
     if (!isset($post_vars['post_type'])) {
         $post_vars['post_type'] = $post_type;
     }
     $element_type = 'post_' . $post_type;
     $language_code = false;
     if (isset($post_vars['action']) && $post_vars['action'] == 'post-quickpress-publish') {
         $post_id = $pidd;
         $language_code = $default_language;
     } elseif (isset($_GET['bulk_edit'])) {
         $post_id = $pidd;
     } else {
         $post_id = isset($post_vars['post_ID']) ? $post_vars['post_ID'] : $pidd;
         //latter case for XML-RPC publishing
         if (isset($post_vars['icl_post_language'])) {
             $language_code = $post_vars['icl_post_language'];
         } elseif (isset($_GET['lang'])) {
             $language_code = $_GET['lang'];
         } elseif ($_ldet = $this->get_element_language_details($post_id, $element_type)) {
             $language_code = $_ldet->language_code;
         } else {
             $language_code = $default_language;
             //latter case for XML-RPC publishing
         }
     }
     $source_language = $default_language;
     if (isset($post_vars['action']) && $post_vars['action'] == 'inline-save' || isset($_GET['bulk_edit']) || isset($_GET['doing_wp_cron']) || isset($_GET['action']) && $_GET['action'] == 'untrash') {
         $res = $this->get_element_language_details($post_id, 'post_' . $post->post_type);
         if (!isset($res) || !$res) {
             return;
         }
         $language_code = $res->language_code;
         $trid = $res->trid;
     } else {
         if (isset($post_vars['icl_trid'])) {
             $trid = @intval($post_vars['icl_trid']);
         } elseif (isset($_GET['trid'])) {
             $trid = @intval($_GET['trid']);
         } else {
             $trid = $this->get_element_trid($post_id, 'post_' . $post->post_type);
         }
         // see if we have a "translation of" setting.
         if (isset($post_vars['icl_translation_of'])) {
             if (is_numeric($post_vars['icl_translation_of'])) {
                 $translation_of_data_prepared = $wpdb->prepare("SELECT trid, language_code FROM {$wpdb->prefix}icl_translations WHERE element_id=%d AND element_type=%s", $post_vars['icl_translation_of'], 'post_' . $post->post_type);
                 list($trid, $source_language) = $wpdb->get_row($translation_of_data_prepared, 'ARRAY_N');
             } else {
                 if (empty($post_vars['icl_trid'])) {
                     $trid = null;
                 }
             }
         }
     }
     if (isset($_POST['action']) && $_POST['action'] == 'inline-save') {
         $trid = $this->get_element_trid($post_id, 'post_' . $post_type);
     } else {
         if (isset($post_vars['icl_translation_of']) && $post_vars['icl_translation_of'] == 'none') {
             $trid = null;
         }
     }
     // set trid if front-end translation creating
     $trid = apply_filters('wpml_save_post_trid_value', $trid, $post_status);
     // set post language if front-end translation creating
     $language_code = apply_filters('wpml_save_post_lang', $language_code);
     $translation_id = $this->set_element_language_details($post_id, $element_type, $trid, $language_code, $source_language);
     //get trid of $translation_id
     $translated_id_trid = $wpdb->get_var($wpdb->prepare("SELECT trid FROM {$wpdb->prefix}icl_translations WHERE translation_id=%d", array($translation_id)));
     //get all translations
     $translated_element_id = $wpdb->get_col($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d", $translated_id_trid));
     if (!in_array($post_type, array('post', 'page')) && !$this->is_translated_post_type($post_type)) {
         wp_defer_term_counting(false);
         return;
     }
     // synchronize the page order for translations
     if ($trid && $this->settings['sync_page_ordering'] && $translated_element_id && is_array($translated_element_id)) {
         $menu_order = esc_sql($post_vars['menu_order']);
         $wpdb->query("UPDATE {$wpdb->posts} SET menu_order={$menu_order} WHERE ID IN (" . join(',', $translated_element_id) . ")");
     }
     // synchronize the page parent for translations
     if ($trid && $this->settings['sync_page_parent']) {
         $original_id = $this->get_original_element_id($post_id, 'post_' . $post_vars['post_type']);
         if ($original_id == $post_id) {
             $translations = $this->get_element_translations($trid, 'post_' . $post_vars['post_type']);
             foreach ($translations as $target_lang => $target_details) {
                 if ($target_lang != $language_code) {
                     if ($target_details->element_id) {
                         $this->fix_translated_parent($post_id, $target_details->element_id, $target_lang);
                     }
                 }
             }
         }
     }
     // synchronize the page template
     if (isset($post_vars['page_template']) && $trid && $post_vars['post_type'] == 'page' && $this->settings['sync_page_template']) {
         if ($translated_element_id && is_array($translated_element_id)) {
             foreach ($translated_element_id as $tp) {
                 if ($tp != $post_id) {
                     update_post_meta($tp, '_wp_page_template', $post_vars['page_template']);
                 }
             }
         }
     }
     // synchronize comment and ping status
     if ($trid && ($this->settings['sync_ping_status'] || $this->settings['sync_comment_status'])) {
         $arr = array();
         if ($this->settings['sync_comment_status']) {
             $arr['comment_status'] = $post_vars['comment_status'];
         }
         if ($this->settings['sync_ping_status']) {
             $arr['ping_status'] = $post_vars['ping_status'];
         }
         if (!empty($arr) && $translated_element_id && is_array($translated_element_id)) {
             foreach ($translated_element_id as $tp) {
                 if ($tp != $post_id) {
                     $wpdb->update($wpdb->posts, $arr, array('ID' => $tp));
                 }
             }
         }
     }
     // copy custom fields from original
     $translations = $this->get_element_translations($trid, 'post_' . $post_vars['post_type']);
     if (!empty($translations)) {
         $original_post_id = false;
         foreach ($translations as $t) {
             if ($t->original) {
                 $original_post_id = $t->element_id;
                 break;
             }
         }
         // this runs only for translated documents
         if ($post_id != $original_post_id) {
             $this->copy_custom_fields($original_post_id, $post_id);
         } else {
             foreach ($translations as $t) {
                 if ($original_post_id != $t->element_id) {
                     $this->copy_custom_fields($original_post_id, $t->element_id);
                 }
             }
         }
     }
     //sync posts stickiness
     if (isset($post_vars['post_type']) && $post_vars['post_type'] == 'post' && isset($post_vars['action']) && $post_vars['action'] != 'post-quickpress-publish' && $this->settings['sync_sticky_flag']) {
         //not for quick press
         remove_filter('option_sticky_posts', array($this, 'option_sticky_posts'));
         // remove filter used to get language relevant stickies. get them all
         $sticky_posts = get_option('sticky_posts');
         add_filter('option_sticky_posts', array($this, 'option_sticky_posts'));
         // add filter back
         // get ids of the translations
         if ($trid) {
             $translations = $wpdb->get_col($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d", $trid));
         } else {
             $translations = array();
         }
         if (isset($post_vars['sticky']) && $post_vars['sticky'] == 'sticky') {
             $sticky_posts = array_unique(array_merge($sticky_posts, $translations));
         } else {
             //makes sure translations are not set to sticky if this posts switched from sticky to not-sticky
             $sticky_posts = array_diff($sticky_posts, $translations);
         }
         update_option('sticky_posts', $sticky_posts);
     }
     //sync private flag
     if ($this->settings['sync_private_flag']) {
         if ($post_status == 'private' && (empty($post_vars['original_post_status']) || $post_vars['original_post_status'] != 'private')) {
             if ($translated_element_id && is_array($translated_element_id)) {
                 foreach ($translated_element_id as $tp) {
                     if ($tp != $post_id) {
                         $wpdb->update($wpdb->posts, array('post_status' => 'private'), array('ID' => $tp));
                     }
                 }
             }
         } elseif ($post_status != 'private' && isset($post_vars['original_post_status']) && $post_vars['original_post_status'] == 'private') {
             if ($translated_element_id && is_array($translated_element_id)) {
                 foreach ($translated_element_id as $tp) {
                     if ($tp != $post_id) {
                         $wpdb->update($wpdb->posts, array('post_status' => $post_status), array('ID' => $tp));
                     }
                 }
             }
         }
     }
     //sync post format
     if ($this->settings['sync_post_format'] && function_exists('set_post_format')) {
         $format = get_post_format($post_id);
         if ($translated_element_id && is_array($translated_element_id)) {
             foreach ($translated_element_id as $tp) {
                 if ($tp != $post_id) {
                     set_post_format($tp, $format);
                 }
             }
         }
     }
     // sync taxonomies (ONE WAY)
     if (!empty($this->settings['sync_post_taxonomies']) && $language_code == $default_language) {
         $translatable_taxs = $this->get_translatable_taxonomies(true, $post_vars['post_type']);
         $all_taxs = get_object_taxonomies($post_vars['post_type']);
         if (!empty($all_taxs)) {
             $translations = $this->get_element_translations($trid, 'post_' . $post_vars['post_type']);
             foreach ($all_taxs as $tt) {
                 $terms = get_the_terms($post_id, $tt);
                 if (!empty($terms)) {
                     foreach ($translations as $target_lang => $translation) {
                         if ($target_lang != $language_code) {
                             $tax_sync = array();
                             foreach ($terms as $term) {
                                 if (in_array($tt, $translatable_taxs)) {
                                     $term_id = icl_object_id($term->term_id, $tt, false, $target_lang);
                                 } else {
                                     $term_id = $term->term_id;
                                 }
                                 if ($term_id) {
                                     $tax_sync[] = intval($term_id);
                                 }
                             }
                             //set the fourth parameter in 'true' because we need to add new terms, instead of replacing all
                             wp_set_object_terms($translation->element_id, $tax_sync, $tt, true);
                         }
                     }
                 }
             }
         }
     }
     // sync post dates
     if (!empty($this->settings['sync_post_date'])) {
         if ($language_code == $default_language) {
             if ($translated_element_id && is_array($translated_element_id)) {
                 $post_date = $wpdb->get_var($wpdb->prepare("SELECT post_date FROM {$wpdb->posts} WHERE ID=%d", $post_id));
                 foreach ($translated_element_id as $tp) {
                     if ($tp != $post_id) {
                         $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => get_gmt_from_date($post_date)), array('ID' => $tp));
                     }
                 }
             }
         } else {
             if (!is_null($trid)) {
                 $source_lang = isset($_GET['source_lang']) ? $_GET['source_lang'] : $default_language;
                 $original_id = $wpdb->get_var($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d AND language_code=%s", $trid, $source_lang));
                 $post_date = $wpdb->get_var($wpdb->prepare("SELECT post_date FROM {$wpdb->posts} WHERE ID=%d", $original_id));
                 $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => get_gmt_from_date($post_date)), array('ID' => $post_id));
             }
         }
     }
     // new categories created inline go to the correct language
     if (isset($post_vars['post_category']) && is_array($post_vars['post_category']) && $post_vars['action'] != 'inline-save' && $post_vars['icl_post_language']) {
         foreach ($post_vars['post_category'] as $cat) {
             $ttid = $wpdb->get_var("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id={$cat} AND taxonomy='category'");
             $wpdb->update($wpdb->prefix . 'icl_translations', array('language_code' => $post_vars['icl_post_language']), array('element_id' => $ttid, 'element_type' => 'tax_category'));
         }
     }
     if (isset($post_vars['icl_tn_note'])) {
         update_post_meta($post_id, '_icl_translator_note', $post_vars['icl_tn_note']);
     }
     //fix guid
     if ($this->settings['language_negotiation_type'] == 2 && $this->get_current_language() != $default_language) {
         $guid = $this->convert_url(get_post_field('guid', $post_id));
         $wpdb->update($wpdb->posts, array('guid' => $guid), array('id' => $post_id));
     }
     require_once ICL_PLUGIN_PATH . '/inc/cache.php';
     icl_cache_clear($post_vars['post_type'] . 's_per_language', true);
     wp_defer_term_counting(false);
 }
コード例 #25
0
 public function die_nicer($batch_code, $batch)
 {
     global $woocsv_product;
     //turn stuff back on again
     if (function_exists('wp_suspend_cache_invalidation')) {
         wp_suspend_cache_invalidation(false);
     }
     if (function_exists('wp_defer_term_counting ')) {
         wp_defer_term_counting(false);
     }
     //are we done?
     if ($batch['status'] == 'done') {
         $post_data['done'] = 1;
     } else {
         $post_data['batch_code'] = $batch_code;
         $post_data['status'] = 0;
     }
     woocsv_batches::update($batch_code, $batch);
     //=============================
     // Check if we need to debug
     //=============================
     if ($this->get_debug() == 0) {
         ob_get_clean();
     }
     $post_data['batch'] = $batch;
     echo json_encode($post_data);
     unset($post_data);
     wp_die();
 }
コード例 #26
0
 /**
  * Performs post-import cleanup of files and the cache
  */
 public function import_end()
 {
     wp_cache_flush();
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     do_action('import_end');
 }
コード例 #27
0
 function import_end()
 {
     do_action('import_end');
     // clear the caches after backfilling
     foreach ($this->post_ids_processed as $post_id) {
         clean_post_cache($post_id);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
 }
コード例 #28
0
 /**
  * Performs post-import cleanup of files and the cache
  */
 function import_end()
 {
     wp_import_cleanup($this->id);
     wp_cache_flush();
     foreach (get_taxonomies() as $tax) {
         delete_option("{$tax}_children");
         _get_term_hierarchy($tax);
     }
     wp_defer_term_counting(false);
     wp_defer_comment_counting(false);
     echo '<p>' . __('All done.', 'wordpress-importer') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'wordpress-importer') . '</a></p>';
     echo '<p>' . __('Remember to update the passwords and roles of imported users.', 'wordpress-importer') . '</p>';
     do_action('import_end');
     // deprecated
     do_action('tf_ext_import_end', array('version' => @$this->version, 'authors' => @$this->authors, 'posts' => @$this->posts, 'terms' => @$this->terms, 'categories' => @$this->categories, 'tags' => @$this->tags, 'base_url' => @$this->base_url, 'processed_authors' => @$this->processed_authors, 'author_mapping' => @$this->author_mapping, 'processed_terms' => @$this->processed_terms, 'processed_posts' => @$this->processed_posts, 'post_orphans' => @$this->post_orphans, 'processed_menu_items' => @$this->processed_menu_items, 'menu_item_orphans' => @$this->menu_item_orphans, 'missing_menu_items' => @$this->missing_menu_items, 'fetch_attachments' => @$this->fetch_attachments, 'url_remap' => @$this->url_remap, 'featured_images' => @$this->featured_images, 'old_site_url' => @$this->old_site_url, 'new_site_url' => @$this->new_site_url, 'upload_url_old' => @$this->upload_url_old, 'install_url' => @$this->install_url, 'tfuse_options' => @$this->tfuse_options));
 }
コード例 #29
0
/**
 * Updates the amount of terms in taxonomy.
 *
 * If there is a taxonomy callback applied, then it will be called for updating
 * the count.
 *
 * The default action is to count what the amount of terms have the relationship
 * of term ID. Once that is done, then update the database.
 *
 * @since 2.3.0
 *
 * @staticvar array $_deferred
 *
 * @param int|array $terms    The term_taxonomy_id of the terms.
 * @param string    $taxonomy The context of the term.
 * @return bool If no terms will return false, and if successful will return true.
 */
function wp_update_term_count($terms, $taxonomy, $do_deferred = false)
{
    static $_deferred = array();
    if ($do_deferred) {
        foreach ((array) array_keys($_deferred) as $tax) {
            wp_update_term_count_now($_deferred[$tax], $tax);
            unset($_deferred[$tax]);
        }
    }
    if (empty($terms)) {
        return false;
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    if (wp_defer_term_counting()) {
        if (!isset($_deferred[$taxonomy])) {
            $_deferred[$taxonomy] = array();
        }
        $_deferred[$taxonomy] = array_unique(array_merge($_deferred[$taxonomy], $terms));
        return true;
    }
    return wp_update_term_count_now($terms, $taxonomy);
}
コード例 #30
0
function cherry_plugin_import_end()
{
    wp_cache_flush();
    foreach (get_taxonomies() as $tax) {
        delete_option("{$tax}_children");
        _get_term_hierarchy($tax);
    }
    wp_defer_term_counting(false);
    wp_defer_comment_counting(false);
    update_option('cherry_sample_data', 1);
    cherry_plugin_set_to_draft('hello-world');
    cherry_plugin_set_to_draft('sample-page');
    settings();
    do_action('cherry_plugin_import_end');
    session_name("import_xml");
    session_destroy();
    exit('import_json');
}