Exemplo n.º 1
0
 /**
  * Delete a language
  *
  * @since 1.2
  *
  * @param int $lang_id language term_id
  */
 public function delete_language($lang_id)
 {
     $lang = $this->get_language((int) $lang_id);
     if (empty($lang)) {
         return;
     }
     // Oops ! we are deleting the default language...
     // Need to do this before loosing the information for default category translations
     if ($this->options['default_lang'] == $lang->slug) {
         $slugs = $this->get_languages_list(array('fields' => 'slug'));
         $slugs = array_diff($slugs, array($lang->slug));
         if (!empty($slugs)) {
             $this->update_default_lang(reset($slugs));
             // Arbitrary choice...
         } else {
             unset($this->options['default_lang']);
         }
     }
     // Delete the translations
     $this->update_translations($lang->slug);
     // Delete language option in widgets
     foreach ($GLOBALS['wp_registered_widgets'] as $widget) {
         if (!empty($widget['callback'][0]) && !empty($widget['params'][0]['number'])) {
             $obj = $widget['callback'][0];
             $number = $widget['params'][0]['number'];
             if (is_object($obj) && method_exists($obj, 'get_settings') && method_exists($obj, 'save_settings')) {
                 $settings = $obj->get_settings();
                 if (isset($settings[$number]['pll_lang']) && $settings[$number]['pll_lang'] == $lang->slug) {
                     unset($settings[$number]['pll_lang']);
                     $obj->save_settings($settings);
                 }
             }
         }
     }
     // Delete menus locations
     if (!empty($this->options['nav_menus'])) {
         foreach ($this->options['nav_menus'] as $theme => $locations) {
             foreach ($locations as $location => $languages) {
                 unset($this->options['nav_menus'][$theme][$location][$lang->slug]);
             }
         }
     }
     // Delete users options
     foreach (get_users(array('fields' => 'ID')) as $user_id) {
         delete_user_meta($user_id, 'pll_filter_content', $lang->slug);
         delete_user_meta($user_id, 'description_' . $lang->slug);
     }
     // Delete the string translations
     $post = wpcom_vip_get_page_by_title('polylang_mo_' . $lang->term_id, OBJECT, 'polylang_mo');
     if (!empty($post)) {
         wp_delete_post($post->ID);
     }
     // Delete domain
     unset($this->options['domains'][$lang->slug]);
     // Delete the language itself
     wp_delete_term($lang->term_id, 'language');
     wp_delete_term($lang->tl_term_id, 'term_language');
     // Update languages list
     $this->clean_languages_cache();
     update_option('polylang', $this->options);
     flush_rewrite_rules();
     // refresh rewrite rules
     add_settings_error('general', 'pll_languages_deleted', __('Language deleted.', 'polylang'), 'updated');
 }
 /**
  * A function used to programmatically create a page needed for Scout. The slug, author ID, and title
  * are defined within the context of the function.
  *
  * @returns -1 if the post was never created, -2 if a post with the same title exists, or the ID
  *          of the post if successful.
  */
 private function create_scout_page()
 {
     // never run this on public facing pages
     if (!is_admin()) {
         return;
     }
     // -1 = No action has been taken.
     $post_id = -1;
     // Our specific settings
     $slug = 'scout-from-sailthru';
     $title = 'Recommended for You';
     $post_type = 'page';
     $post_content = '<div id="sailthru-scout"><div class="loading">Loading, please wait...</div></div>';
     // If the page doesn't already exist, then create it
     $create_page = function_exists('wpcom_vip_get_page_by_title') ? null == wpcom_vip_get_page_by_title($title) : null == get_page_by_title($title);
     if ($create_page) {
         // Set the post ID so that we know the post was created successfully
         $post_id = wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_name' => $slug, 'post_title' => $title, 'post_status' => 'publish', 'post_type' => $post_type, 'post_content' => $post_content));
     } else {
         $post_id = -2;
     }
     // end if
     return $post_id;
 }