public function media_lang_choice() { check_ajax_referer('pll_language', '_pll_nonce'); preg_match('#([0-9]+)#', $_POST['post_id'], $matches); $post_id = $matches[1]; $lang = $this->model->get_language($_POST['lang']); ob_start(); if ($lang) { include PLL_ADMIN_INC . '/view-translations-media.php'; $data = ob_get_contents(); } $x = new WP_Ajax_Response(array('what' => 'translations', 'data' => $data)); ob_end_clean(); // flag $x->Add(array('what' => 'flag', 'data' => empty($lang->flag) ? esc_html($lang->slug) : $lang->flag)); $x->send(); }
public function term_lang_choice() { $lang = $this->model->get_language($_POST['lang']); $term_id = isset($_POST['term_id']) ? $_POST['term_id'] : null; $taxonomy = $_POST['taxonomy']; $post_type = $_POST['post_type']; ob_start(); if ($lang) { include PLL_ADMIN_INC . '/view-translations-term.php'; } $x = new WP_Ajax_Response(array('what' => 'translations', 'data' => ob_get_contents())); ob_end_clean(); // parent dropdown list (only for hierarchical taxonomies) // $args copied from edit_tags.php except echo if (is_taxonomy_hierarchical($taxonomy)) { $args = array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'), 'echo' => 0); $x->Add(array('what' => 'parent', 'data' => wp_dropdown_categories($args))); } else { $tax = get_taxonomy($taxonomy); if (!is_null($tax->labels->popular_items)) { $args = array('taxonomy' => $taxonomy, 'echo' => false); if (current_user_can($tax->cap->edit_terms)) { $args = array_merge($args, array('link' => 'edit')); } if ($tag_cloud = wp_tag_cloud($args)) { $x->Add(array('what' => 'tag_cloud', 'data' => '<h3>' . $tax->labels->popular_items . '</h3>' . $tag_cloud)); } } } $x->send(); }
public function save_options() { check_ajax_referer('pll_options', '_pll_nonce'); if (!current_user_can('manage_options')) { wp_die(-1); } if ($this->module === $_POST['module'] && !empty($_POST['licenses'])) { $x = new WP_Ajax_Response(); foreach ($this->items as $item) { $updated_item = $item->activate_license(sanitize_text_field($_POST['licenses'][$item->id])); $x->Add(array('what' => 'license-update', 'data' => $item->id, 'supplemental' => array('html' => $this->get_row($updated_item)))); } // updated message add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated'); ob_start(); settings_errors(); $x->Add(array('what' => 'success', 'data' => ob_get_clean())); $x->send(); } }
public function post_lang_choice() { check_ajax_referer('pll_language', '_pll_nonce'); global $post_ID; // obliged to use the global variable for wp_popular_terms_checklist $post_ID = (int) $_POST['post_id']; $post_type = get_post_type($post_ID); $lang = $this->model->get_language($_POST['lang']); $post_type_object = get_post_type_object($post_type); if (!current_user_can($post_type_object->cap->edit_post, $post_ID)) { wp_die(-1); } $this->model->set_post_language($post_ID, $lang); // save language, useful to set the language when uploading media from post ob_start(); if ($lang) { include PLL_ADMIN_INC . '/view-translations-post.php'; } $x = new WP_Ajax_Response(array('what' => 'translations', 'data' => ob_get_contents())); ob_end_clean(); // categories if (isset($_POST['taxonomies'])) { // not set for pages foreach ($_POST['taxonomies'] as $taxname) { $taxonomy = get_taxonomy($taxname); ob_start(); $popular_ids = wp_popular_terms_checklist($taxonomy->name); $supplemental['populars'] = ob_get_contents(); ob_end_clean(); ob_start(); // use $post_ID to remember ckecked terms in case we come back to the original language wp_terms_checklist($post_ID, array('taxonomy' => $taxonomy->name, 'popular_cats' => $popular_ids)); $supplemental['all'] = ob_get_contents(); ob_end_clean(); $supplemental['dropdown'] = wp_dropdown_categories(array('taxonomy' => $taxonomy->name, 'hide_empty' => 0, 'name' => 'new' . $taxonomy->name . '_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', 'echo' => 0)); $x->Add(array('what' => 'taxonomy', 'data' => $taxonomy->name, 'supplemental' => $supplemental)); } } // parent dropdown list (only for hierarchical post types) if (in_array($post_type, get_post_types(array('hierarchical' => true)))) { require_once ABSPATH . 'wp-admin/includes/meta-boxes.php'; ob_start(); page_attributes_meta_box(get_post($post_ID)); $x->Add(array('what' => 'pages', 'data' => ob_get_contents())); ob_end_clean(); } // flag $x->Add(array('what' => 'flag', 'data' => empty($lang->flag) ? esc_html($lang->slug) : $lang->flag)); $x->send(); }
/** * Ajax response for edit term form * * @since 0.2 */ public function term_lang_choice() { check_ajax_referer('pll_language', '_pll_nonce'); $lang = $this->model->get_language($_POST['lang']); $term_id = isset($_POST['term_id']) ? (int) $_POST['term_id'] : null; $taxonomy = $_POST['taxonomy']; $post_type = $_POST['post_type']; if (!post_type_exists($post_type) || !taxonomy_exists($taxonomy)) { die(0); } ob_start(); if ($lang) { include PLL_ADMIN_INC . '/view-translations-term.php'; } $x = new WP_Ajax_Response(array('what' => 'translations', 'data' => ob_get_contents())); ob_end_clean(); // Parent dropdown list ( only for hierarchical taxonomies ) // $args copied from edit_tags.php except echo if (is_taxonomy_hierarchical($taxonomy)) { $args = array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'), 'echo' => 0); $x->Add(array('what' => 'parent', 'data' => wp_dropdown_categories($args))); } else { $tax = get_taxonomy($taxonomy); if (!is_null($tax->labels->popular_items)) { $args = array('taxonomy' => $taxonomy, 'echo' => false); if (current_user_can($tax->cap->edit_terms)) { $args = array_merge($args, array('link' => 'edit')); } if ($tag_cloud = wp_tag_cloud($args)) { $html = sprintf('<div class="tagcloud"><h2>%1$s</h2>%2$s</div>', esc_html($tax->labels->popular_items), $tag_cloud); $x->Add(array('what' => 'tag_cloud', 'data' => $html)); } } } // Flag $x->Add(array('what' => 'flag', 'data' => empty($lang->flag) ? esc_html($lang->slug) : $lang->flag)); $x->send(); }
/** * Ajax response for changing the language in the post metabox * * @since 0.2 */ public function post_lang_choice() { check_ajax_referer('pll_language', '_pll_nonce'); global $post_ID; // Obliged to use the global variable for wp_popular_terms_checklist $post_id = $post_ID = (int) $_POST['post_id']; $lang = $this->model->get_language($_POST['lang']); $post_type = $_POST['post_type']; $post_type_object = get_post_type_object($post_type); if (!current_user_can($post_type_object->cap->edit_post, $post_ID)) { wp_die(-1); } $this->model->post->set_language($post_ID, $lang); // Save language, useful to set the language when uploading media from post ob_start(); if ($lang) { include PLL_ADMIN_INC . '/view-translations-' . ('attachment' == $post_type ? 'media' : 'post') . '.php'; } $x = new WP_Ajax_Response(array('what' => 'translations', 'data' => ob_get_contents())); ob_end_clean(); // Categories if (isset($_POST['taxonomies'])) { // Not set for pages foreach ($_POST['taxonomies'] as $taxname) { $taxonomy = get_taxonomy($taxname); ob_start(); $popular_ids = wp_popular_terms_checklist($taxonomy->name); $supplemental['populars'] = ob_get_contents(); ob_end_clean(); ob_start(); // Use $post_ID to remember ckecked terms in case we come back to the original language wp_terms_checklist($post_ID, array('taxonomy' => $taxonomy->name, 'popular_cats' => $popular_ids)); $supplemental['all'] = ob_get_contents(); ob_end_clean(); $supplemental['dropdown'] = wp_dropdown_categories(array('taxonomy' => $taxonomy->name, 'hide_empty' => 0, 'name' => 'new' . $taxonomy->name . '_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', 'echo' => 0)); $x->Add(array('what' => 'taxonomy', 'data' => $taxonomy->name, 'supplemental' => $supplemental)); } } // Parent dropdown list ( only for hierarchical post types ) if (in_array($post_type, get_post_types(array('hierarchical' => true)))) { $post = get_post($post_ID); // Args and filter from 'page_attributes_meta_box' in wp-admin/includes/meta-boxes.php of WP 4.2.1 $dropdown_args = array('post_type' => $post->post_type, 'exclude_tree' => $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)'), 'sort_column' => 'menu_order, post_title', 'echo' => 0); /** This filter is documented in wp-admin/includes/meta-boxes.php */ $dropdown_args = apply_filters('page_attributes_dropdown_pages_args', $dropdown_args, $post); // Since WP 3.3 $x->Add(array('what' => 'pages', 'data' => wp_dropdown_pages($dropdown_args))); } // Flag $x->Add(array('what' => 'flag', 'data' => empty($lang->flag) ? esc_html($lang->slug) : $lang->flag)); // Sample permalink $x->Add(array('what' => 'permalink', 'data' => get_sample_permalink_html($post_ID))); $x->send(); }
function term_lang_choice() { $lang = $this->get_language($_POST['lang']); $term_id = isset($_POST['term_id']) ? $_POST['term_id'] : null; $taxonomy = $_POST['taxonomy']; $listlanguages = $this->get_languages_list(); ob_start(); if ($lang && !is_wp_error($lang)) { include PLL_INC . '/term-translations.php'; } $x = new WP_Ajax_Response(array('what' => 'translations', 'data' => ob_get_contents())); ob_end_clean(); // parent dropdown list (only for hierarchical taxonomies) // $args copied from edit_tags.php except echo if (is_taxonomy_hierarchical($taxonomy)) { $args = array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'), 'echo' => 0); $x->Add(array('what' => 'parent', 'data' => wp_dropdown_categories($args))); } $x->send(); }