function kapost_is_protected_meta($protected_fields, $field)
{
    if (!in_array($field, $protected_fields)) {
        return false;
    }
    if (function_exists('is_protected_meta')) {
        return is_protected_meta($field, 'post');
    }
    return $field[0] == '_';
}
Exemplo n.º 2
0
    /**
     * Display the options form on admin.
     *
     * @see WP_Widget::form()
     *
     * @param array $instance Previously saved values from database.
     * @since 1.0
     */
    public function form($instance)
    {
        $defaults = array('title' => __('Posts', 'posts-in-sidebar'), 'title_link' => '', 'intro' => '', 'post_type' => 'post', 'posts_id' => '', 'author' => '', 'author_in' => '', 'cat' => '', 'tag' => '', 'post_parent_in' => '', 'post_format' => '', 'number' => get_option('posts_per_page'), 'orderby' => 'date', 'order' => 'DESC', 'offset_number' => '', 'post_status' => 'publish', 'post_meta_key' => '', 'post_meta_val' => '', 'search' => NULL, 'ignore_sticky' => false, 'get_from_same_cat' => false, 'title_same_cat' => '', 'relation' => '', 'taxonomy_aa' => '', 'field_aa' => 'slug', 'terms_aa' => '', 'operator_aa' => 'IN', 'relation_a' => '', 'taxonomy_ab' => '', 'field_ab' => 'slug', 'terms_ab' => '', 'operator_ab' => 'IN', 'taxonomy_ba' => '', 'field_ba' => 'slug', 'terms_ba' => '', 'operator_ba' => 'IN', 'relation_b' => '', 'taxonomy_bb' => '', 'field_bb' => 'slug', 'terms_bb' => '', 'operator_bb' => 'IN', 'date_year' => '', 'date_month' => '', 'date_week' => '', 'date_day' => '', 'date_hour' => '', 'date_minute' => '', 'date_second' => '', 'date_after_year' => '', 'date_after_month' => '', 'date_after_day' => '', 'date_before_year' => '', 'date_before_month' => '', 'date_before_day' => '', 'date_inclusive' => false, 'date_column' => '', 'author_not_in' => '', 'exclude_current_post' => false, 'post_not_in' => '', 'cat_not_in' => '', 'tag_not_in' => '', 'post_parent_not_in' => '', 'display_title' => true, 'link_on_title' => true, 'title_tooltip' => __('Permalink to', 'posts-in-sidebar'), 'arrow' => false, 'display_image' => false, 'image_size' => 'thumbnail', 'image_align' => 'no_change', 'image_before_title' => false, 'image_link' => '', 'custom_image_url' => '', 'custom_img_no_thumb' => true, 'excerpt' => 'excerpt', 'exc_length' => 20, 'the_more' => __('Read more…', 'posts-in-sidebar'), 'exc_arrow' => false, 'display_author' => false, 'author_text' => __('By', 'posts-in-sidebar'), 'linkify_author' => false, 'gravatar_display' => false, 'gravatar_size' => 32, 'gravatar_default' => '', 'gravatar_position' => 'next_author', 'display_date' => false, 'date_text' => __('Published on', 'posts-in-sidebar'), 'linkify_date' => false, 'display_mod_date' => false, 'mod_date_text' => __('Modified on', 'posts-in-sidebar'), 'linkify_mod_date' => false, 'comments' => false, 'comments_text' => __('Comments:', 'posts-in-sidebar'), 'linkify_comments' => true, 'utility_sep' => '|', 'utility_after_title' => false, 'categories' => false, 'categ_text' => __('Category:', 'posts-in-sidebar'), 'categ_sep' => ',', 'tags' => false, 'tags_text' => __('Tags:', 'posts-in-sidebar'), 'hashtag' => '#', 'tag_sep' => '', 'display_custom_tax' => false, 'term_hashtag' => '', 'term_sep' => ',', 'custom_field' => false, 'custom_field_txt' => '', 'meta' => '', 'custom_field_key' => false, 'custom_field_sep' => ':', 'archive_link' => false, 'link_to' => 'category', 'tax_name' => '', 'tax_term_name' => '', 'archive_text' => __('Display all posts', 'posts-in-sidebar'), 'nopost_text' => __('No posts yet.', 'posts-in-sidebar'), 'hide_widget' => false, 'margin_unit' => 'px', 'intro_margin' => NULL, 'title_margin' => NULL, 'side_image_margin' => NULL, 'bottom_image_margin' => NULL, 'excerpt_margin' => NULL, 'utility_margin' => NULL, 'categories_margin' => NULL, 'tags_margin' => NULL, 'terms_margin' => NULL, 'custom_field_margin' => NULL, 'archive_margin' => NULL, 'noposts_margin' => NULL, 'custom_styles' => '', 'container_class' => '', 'list_element' => 'ul', 'remove_bullets' => false, 'cached' => false, 'cache_time' => '', 'debug_query' => false, 'debug_params' => false, 'debug_query_number' => false);
        $instance = wp_parse_args((array) $instance, $defaults);
        $ignore_sticky = (bool) $instance['ignore_sticky'];
        $get_from_same_cat = (bool) $instance['get_from_same_cat'];
        $date_inclusive = (bool) $instance['date_inclusive'];
        $exclude_current_post = (bool) $instance['exclude_current_post'];
        $display_title = (bool) $instance['display_title'];
        $link_on_title = (bool) $instance['link_on_title'];
        $display_image = (bool) $instance['display_image'];
        $image_before_title = (bool) $instance['image_before_title'];
        $arrow = (bool) $instance['arrow'];
        $custom_img_no_thumb = (bool) $instance['custom_img_no_thumb'];
        $exc_arrow = (bool) $instance['exc_arrow'];
        $utility_after_title = (bool) $instance['utility_after_title'];
        $display_author = (bool) $instance['display_author'];
        $linkify_author = (bool) $instance['linkify_author'];
        $gravatar_display = (bool) $instance['gravatar_display'];
        $display_date = (bool) $instance['display_date'];
        $linkify_date = (bool) $instance['linkify_date'];
        $display_mod_date = (bool) $instance['display_mod_date'];
        $linkify_mod_date = (bool) $instance['linkify_mod_date'];
        $comments = (bool) $instance['comments'];
        $linkify_comments = (bool) $instance['linkify_comments'];
        $categories = (bool) $instance['categories'];
        $tags = (bool) $instance['tags'];
        $display_custom_tax = (bool) $instance['display_custom_tax'];
        $custom_field = (bool) $instance['custom_field'];
        $custom_field_key = (bool) $instance['custom_field_key'];
        $archive_link = (bool) $instance['archive_link'];
        $hide_widget = (bool) $instance['hide_widget'];
        $remove_bullets = (bool) $instance['remove_bullets'];
        $cached = (bool) $instance['cached'];
        $debug_query = (bool) $instance['debug_query'];
        $debug_params = (bool) $instance['debug_params'];
        $debug_query_number = (bool) $instance['debug_query_number'];
        /**
         * When upgrading from old version, $author, $cat, and $tag could be 'NULL' (as string).
         * See above for more informations (the long note on function update).
         *
         * @since 2.0.3
         */
        if ('NULL' == $instance['author']) {
            $instance['author'] = '';
        }
        if ('NULL' == $instance['cat']) {
            $instance['cat'] = '';
        }
        if ('NULL' == $instance['tag']) {
            $instance['tag'] = '';
        }
        ?>

		<!-- Widget title -->
		<div class="pis-section">

			<h4 class="pis-widget-title"><?php 
        _e('The title of the widget', 'posts-in-sidebar');
        ?>
</h4>

			<div class="pis-container pis-container-open">

				<?php 
        pis_form_input_text(__('Title', 'posts-in-sidebar'), $this->get_field_id('title'), $this->get_field_name('title'), esc_attr($instance['title']), __('From the archive', 'posts-in-sidebar'));
        ?>

				<?php 
        pis_form_input_text(__('Link the title of the widget to this URL', 'posts-in-sidebar'), $this->get_field_id('title_link'), $this->get_field_name('title_link'), esc_url(strip_tags($instance['title_link'])), 'http://example.com/readings-series/');
        ?>

				<?php 
        pis_form_textarea(__('Place this text after the title', 'posts-in-sidebar'), $this->get_field_id('intro'), $this->get_field_name('intro'), $instance['intro'], __('These posts are part of my Readings series.', 'posts-in-sidebar'), $style = 'resize: vertical; width: 100%; height: 80px;', $comment = sprintf(__('Allowed HTML: %s. Other tags will be stripped.', 'posts-in-sidebar'), '<code>a</code>, <code>strong</code>, <code>em</code>'));
        ?>

			</div>

		</div>

		<!-- Getting posts -->
		<div class="pis-section">

			<h4 class="pis-widget-title"><?php 
        _e('Getting posts', 'posts-in-sidebar');
        ?>
</h4>

			<div class="pis-container">

				<p><em><?php 
        _e('In this section you can define which type of posts you want to retrieve and which taxonomy the plugin will use. Other parameters are available to better define the query.', 'posts-in-sidebar');
        ?>
</em></p>

				<p><em><?php 
        printf(__('If a field requires one or more IDs, install %1$sthis plugin%2$s to easily find the IDs.', 'posts-in-sidebar'), '<a href="http://wordpress.org/plugins/reveal-ids-for-wp-admin-25/" target="_blank">', '</a>');
        ?>
</em></p>

				<div class="pis-column-container">

					<div class="pis-column">

						<?php 
        // ================= Post types
        $args = array('public' => true);
        $post_types = (array) get_post_types($args, 'objects', 'and');
        $options = array(array('value' => 'any', 'desc' => __('Any', 'posts-in-sidebar')));
        foreach ($post_types as $post_type) {
            $options[] = array('value' => $post_type->name, 'desc' => $post_type->labels->singular_name);
        }
        pis_form_select(__('Post type', 'posts-in-sidebar'), $this->get_field_id('post_type'), $this->get_field_name('post_type'), $options, $instance['post_type']);
        ?>

						<?php 
        // ================= Posts ID
        pis_form_input_text(__('Get these posts exactly', 'posts-in-sidebar'), $this->get_field_id('posts_id'), $this->get_field_name('posts_id'), esc_attr($instance['posts_id']), '5, 29, 523, 4519', __('Enter IDs separated by commas.', 'posts-in-sidebar'));
        ?>

					</div>

					<div class="pis-column">

						<?php 
        // ================= Category
        pis_form_input_text(__('Get posts with these categories', 'posts-in-sidebar'), $this->get_field_id('cat'), $this->get_field_name('cat'), esc_attr($instance['cat']), __('books, ebooks', 'posts-in-sidebar'), sprintf(__('Enter slugs separated by commas. To display posts that have all of the categories, use %1$s (a plus) between terms, for example:%2$s.', 'posts-in-sidebar'), '<code>+</code>', '<br /><code>staff+news+our-works</code>'));
        ?>

					</div>

					<div class="pis-column">

						<?php 
        // ================= Tag
        pis_form_input_text(__('Get posts with these tags', 'posts-in-sidebar'), $this->get_field_id('tag'), $this->get_field_name('tag'), esc_attr($instance['tag']), __('best-sellers', 'posts-in-sidebar'), sprintf(__('Enter slugs separated by commas. To display posts that have all of the tags, use %1$s (a plus) between terms, for example:%2$s.', 'posts-in-sidebar'), '<code>+</code>', '<br /><code>staff+news+our-works</code>'));
        ?>

					</div>

				</div>

				<div class="pis-column-container">

					<div class="pis-column">

						<?php 
        // ================= Author
        $options = array(array('value' => '', 'desc' => __('Any', 'posts-in-sidebar')));
        $authors = (array) get_users('who=authors');
        // If set to 'authors', only authors (user level greater than 0) will be returned.
        foreach ($authors as $author) {
            $options[] = array('value' => $author->user_nicename, 'desc' => $author->display_name);
        }
        pis_form_select(__('Get posts by this author', 'posts-in-sidebar'), $this->get_field_id('author'), $this->get_field_name('author'), $options, $instance['author']);
        ?>

						<?php 
        // ================= Multiple authors
        pis_form_input_text(__('Get posts by these authors', 'posts-in-sidebar'), $this->get_field_id('author_in'), $this->get_field_name('author_in'), esc_attr($instance['author_in']), __('1, 23, 45', 'posts-in-sidebar'), __('Enter IDs separated by commas. Note that if you fill this field, the previous one will be ignored.', 'posts-in-sidebar'));
        ?>

					</div>

					<div class="pis-column">

						<?php 
        // ================= Post parent
        pis_form_input_text(__('Get posts whose parent is in these IDs', 'posts-in-sidebar'), $this->get_field_id('post_parent_in'), $this->get_field_name('post_parent_in'), esc_attr($instance['post_parent_in']), __('2, 5, 12, 14, 20', 'posts-in-sidebar'), __('Enter IDs separated by commas.', 'posts-in-sidebar'));
        ?>

						<?php 
        // ================= Post format
        $options = array(array('value' => '', 'desc' => __('Any', 'posts-in-sidebar')));
        $post_formats = get_terms('post_format');
        foreach ($post_formats as $post_format) {
            $options[] = array('value' => $post_format->slug, 'desc' => $post_format->name);
        }
        pis_form_select(__('Get posts with this post format', 'posts-in-sidebar'), $this->get_field_id('post_format'), $this->get_field_name('post_format'), $options, $instance['post_format']);
        ?>

						<?php 
        // ================= Post status
        $options = array(array('value' => 'any', 'desc' => 'Any'));
        $statuses = get_post_stati(array(), 'objects');
        foreach ($statuses as $status) {
            $options[] = array('value' => $status->name, 'desc' => $status->label);
        }
        pis_form_select(__('Get posts with this post status', 'posts-in-sidebar'), $this->get_field_id('post_status'), $this->get_field_name('post_status'), $options, $instance['post_status']);
        ?>

					</div>

					<div class="pis-column">

						<?php 
        // ================= Post meta key
        pis_form_input_text(__('Get posts with this meta key', 'posts-in-sidebar'), $this->get_field_id('post_meta_key'), $this->get_field_name('post_meta_key'), esc_attr($instance['post_meta_key']), __('meta-key', 'posts-in-sidebar'));
        ?>

						<?php 
        // ================= Post meta value
        pis_form_input_text(__('Get posts with this meta value', 'posts-in-sidebar'), $this->get_field_id('post_meta_val'), $this->get_field_name('post_meta_val'), esc_attr($instance['post_meta_val']), __('meta-value', 'posts-in-sidebar'));
        ?>

						<?php 
        // ================= Search
        pis_form_input_text(__('Get posts from this search', 'posts-in-sidebar'), $this->get_field_id('search'), $this->get_field_name('search'), esc_attr($instance['search']), __('words to search', 'posts-in-sidebar'));
        ?>

					</div>

				</div>

				<div class="pis-column-container pis-2col">

					<div class="pis-column">

						<?php 
        // ================= Posts quantity
        pis_form_input_text(__('Get this number of posts', 'posts-in-sidebar'), $this->get_field_id('number'), $this->get_field_name('number'), esc_attr($instance['number']), '3', sprintf(__('The value %s shows all the posts.', 'posts-in-sidebar'), '<code>-1</code>'));
        ?>

						<?php 
        // ================= Ignore sticky post
        pis_form_checkbox(__('Do not display sticky posts on top of other posts', 'posts-in-sidebar'), $this->get_field_id('ignore_sticky'), $this->get_field_name('ignore_sticky'), checked($ignore_sticky, true, false), __('If you activate this option, sticky posts will be managed as other posts. Sticky post status will be automatically ignored if you set up an author or a taxonomy in this widget.', 'posts-in-sidebar'));
        ?>

					</div>

					<div class="pis-column">

						<?php 
        // ================= Post order by
        $options = array('none' => array('value' => 'none', 'desc' => __('None', 'posts-in-sidebar')), 'id' => array('value' => 'id', 'desc' => __('ID', 'posts-in-sidebar')), 'author' => array('value' => 'author', 'desc' => __('Author', 'posts-in-sidebar')), 'title' => array('value' => 'title', 'desc' => __('Title', 'posts-in-sidebar')), 'name' => array('value' => 'name', 'desc' => __('Name (post slug)', 'posts-in-sidebar')), 'date' => array('value' => 'date', 'desc' => __('Date', 'posts-in-sidebar')), 'modified' => array('value' => 'modified', 'desc' => __('Modified', 'posts-in-sidebar')), 'parent' => array('value' => 'parent', 'desc' => __('Parent', 'posts-in-sidebar')), 'rand' => array('value' => 'rand', 'desc' => __('Random', 'posts-in-sidebar')), 'comment_count' => array('value' => 'comment_count', 'desc' => __('Comment count', 'posts-in-sidebar')), 'menu_order' => array('value' => 'menu_order', 'desc' => __('Menu order', 'posts-in-sidebar')), 'meta_value' => array('value' => 'meta_value', 'desc' => __('Meta value', 'posts-in-sidebar')), 'meta_value_num' => array('value' => 'meta_value_num', 'desc' => __('Meta value number', 'posts-in-sidebar')), 'post__in' => array('value' => 'post__in', 'desc' => __('Preserve ID order', 'posts-in-sidebar')));
        pis_form_select(__('Order posts by', 'posts-in-sidebar'), $this->get_field_id('orderby'), $this->get_field_name('orderby'), $options, $instance['orderby']);
        ?>

						<?php 
        // ================= Post order
        $options = array('asc' => array('value' => 'ASC', 'desc' => __('Ascending', 'posts-in-sidebar')), 'desc' => array('value' => 'DESC', 'desc' => __('Descending', 'posts-in-sidebar')));
        pis_form_select(__('The order will be', 'posts-in-sidebar'), $this->get_field_id('order'), $this->get_field_name('order'), $options, $instance['order']);
        ?>

						<?php 
        // ================= Number of posts to skip
        pis_form_input_text(__('Skip this number of posts', 'posts-in-sidebar'), $this->get_field_id('offset_number'), $this->get_field_name('offset_number'), esc_attr($instance['offset_number']), '5');
        ?>

					</div>

				</div>

				<hr>

				<div class="pis-column-container pis-2col">

					<div class="pis-column">

						<?php 
        // ================= Get posts from same category
        pis_form_checkbox(__('When on single posts, get posts from the current category', 'posts-in-sidebar'), $this->get_field_id('get_from_same_cat'), $this->get_field_name('get_from_same_cat'), checked($get_from_same_cat, true, false), __('When activated, this function will get posts from the first category of the post, ignoring other parameters like tags, date, post formats, etc. If the post has multiple categories, the plugin will use the first category in the array of categories (the category with the lowest ID). Custom post types are excluded from this feature.', 'posts-in-sidebar'));
        ?>

					</div>

					<div class="pis-column">

						<?php 
        // ================= The custom widget title when on single posts
        pis_form_input_text(__('When on single posts, use this widget title', 'posts-in-sidebar'), $this->get_field_id('title_same_cat'), $this->get_field_name('title_same_cat'), esc_attr($instance['title_same_cat']), __('Posts under %s', 'posts-in-sidebar'), sprintf(__('Use %s to display the name of the category.', 'posts-in-sidebar'), '<code>%s</code>'));
        ?>

					</div>

				</div>

				<!-- Excluding posts -->
				<div class="pis-section">

					<h4 class="pis-widget-title"><?php 
        _e('Excluding posts', 'posts-in-sidebar');
        ?>
</h4>

					<div class="pis-container">

						<p><em><?php 
        _e('Define here which posts must be excluded from the query.', 'posts-in-sidebar');
        ?>
</em></p>

						<p><em><?php 
        printf(__('If a field requires one or more IDs, install %1$sthis plugin%2$s to easily find the IDs.', 'posts-in-sidebar'), '<a href="http://wordpress.org/plugins/reveal-ids-for-wp-admin-25/" target="_blank">', '</a>');
        ?>
</em></p>

						<div class="pis-column-container">

							<div class="pis-column">

								<?php 
        // ================= Exclude posts by these authors
        if (is_array($instance['author_not_in'])) {
            $var = implode(',', $instance['author_not_in']);
        } else {
            $var = $instance['author_not_in'];
        }
        pis_form_input_text(__('Exclude posts by these authors', 'posts-in-sidebar'), $this->get_field_id('author_not_in'), $this->get_field_name('author_not_in'), esc_attr($var), '1, 23, 45', __('Enter IDs separated by commas.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Exclude posts from categories
        if (is_array($instance['cat_not_in'])) {
            $var = implode(',', $instance['cat_not_in']);
        } else {
            $var = $instance['cat_not_in'];
        }
        pis_form_input_text(__('Exclude posts from these categories', 'posts-in-sidebar'), $this->get_field_id('cat_not_in'), $this->get_field_name('cat_not_in'), esc_attr($var), '3, 31', __('Enter IDs separated by commas.', 'posts-in-sidebar'));
        ?>

							</div>

							<div class="pis-column">

								<?php 
        // ================= Exclude posts from tags
        if (is_array($instance['tag_not_in'])) {
            $var = implode(',', $instance['tag_not_in']);
        } else {
            $var = $instance['tag_not_in'];
        }
        pis_form_input_text(__('Exclude posts from these tags', 'posts-in-sidebar'), $this->get_field_id('tag_not_in'), $this->get_field_name('tag_not_in'), esc_attr($var), '7, 11', __('Enter IDs separated by commas.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Exclude posts that have these ids.
        pis_form_input_text(__('Exclude posts with these IDs', 'posts-in-sidebar'), $this->get_field_id('post_not_in'), $this->get_field_name('post_not_in'), esc_attr($instance['post_not_in']), '5, 29, 523, 4519', __('Enter IDs separated by commas.', 'posts-in-sidebar'));
        ?>

							</div>

							<div class="pis-column">

								<?php 
        // ================= Exclude posts whose parent is in these IDs.
        pis_form_input_text(__('Exclude posts whose parent is in these IDs', 'posts-in-sidebar'), $this->get_field_id('post_parent_not_in'), $this->get_field_name('post_parent_not_in'), esc_attr($instance['post_parent_not_in']), '5, 29, 523, 4519', __('Enter IDs separated by commas.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Exclude current post
        pis_form_checkbox(__('Automatically exclude the current post in single post or the current page in single page', 'posts-in-sidebar'), $this->get_field_id('exclude_current_post'), $this->get_field_name('exclude_current_post'), checked($exclude_current_post, true, false));
        ?>

							</div>

						</div>

					</div>

				</div>

				<!-- Custom taxonomy query -->
				<div class="pis-section pis-2col">

					<h4 class="pis-widget-title"><?php 
        _e('Custom taxonomy query', 'posts-in-sidebar');
        ?>
</h4>

					<div class="pis-container">

						<p><em><?php 
        _e('This section lets you retrieve posts from any taxonomy (category, tags, and custom taxonomies). If you want to use only one taxonomy, use the "Taxonomy A1" field. If you have to put in relation two taxonomies (e.g., display posts that are in the "quotes" category but not in the "wisdom" tag), then use also the "Taxonomy B1" field. If you have to put in relation more taxonomies, start using also the "A2" and "B2" fields (e.g., display posts that are in the "quotes" category [A1] OR both have the "Quote" post format [B1] AND are in the "wisdom" category [B2]).', 'posts-in-sidebar');
        ?>
</em></p>

						<p><em><?php 
        printf(__('If a field requires one or more IDs, install %1$sthis plugin%2$s to easily find the IDs.', 'posts-in-sidebar'), '<a href="http://wordpress.org/plugins/reveal-ids-for-wp-admin-25/" target="_blank">', '</a>');
        ?>
</em></p>

						<div class="pis-column-container">

							<div class="pis-column">
								<?php 
        // ================= Taxonomy relation between aa and bb
        $options = array('empty' => array('value' => '', 'desc' => ''), 'and' => array('value' => 'AND', 'desc' => 'AND'), 'or' => array('value' => 'OR', 'desc' => 'OR'));
        pis_form_select(__('Relation between Column A and Column B', 'posts-in-sidebar'), $this->get_field_id('relation'), $this->get_field_name('relation'), $options, $instance['relation'], __('The logical relationship between each inner taxonomy array when there is more than one. Do not use with a single inner taxonomy array.', 'posts-in-sidebar'));
        ?>

							</div>

						</div>

						<hr />

						<div class="pis-column-container">

							<div class="pis-column">

								<h4 class="pis-title-center"><?php 
        _e('Column A', 'posts-in-sidebar');
        ?>
</h4>

								<?php 
        // ================= Taxonomy aa
        pis_form_input_text(sprintf(__('%1$sTaxonomy A1%2$s', 'posts-in-sidebar'), '<strong>', '</strong>'), $this->get_field_id('taxonomy_aa'), $this->get_field_name('taxonomy_aa'), esc_attr($instance['taxonomy_aa']), __('category', 'posts-in-sidebar'), __('Enter the slug of the taxonomy.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Field aa
        $options = array('term_id' => array('value' => 'term_id', 'desc' => __('Term ID', 'posts-in-sidebar')), 'slug' => array('value' => 'slug', 'desc' => __('Slug', 'posts-in-sidebar')), 'name' => array('value' => 'name', 'desc' => __('Name', 'posts-in-sidebar')));
        pis_form_select(__('Field', 'posts-in-sidebar'), $this->get_field_id('field_aa'), $this->get_field_name('field_aa'), $options, $instance['field_aa'], __('Select taxonomy term by this field.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Terms aa
        pis_form_input_text(__('Terms', 'posts-in-sidebar'), $this->get_field_id('terms_aa'), $this->get_field_name('terms_aa'), esc_attr($instance['terms_aa']), __('gnu-linux,kde', 'posts-in-sidebar'), __('Enter terms, separated by comma.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Operator aa
        $options = array('in' => array('value' => 'IN', 'desc' => 'IN'), 'not_in' => array('value' => 'NOT IN', 'desc' => 'NOT IN'), 'and' => array('value' => 'AND', 'desc' => 'AND'));
        pis_form_select(__('Operator', 'posts-in-sidebar'), $this->get_field_id('operator_aa'), $this->get_field_name('operator_aa'), $options, $instance['operator_aa'], __('Operator to test for terms.', 'posts-in-sidebar'));
        ?>

								<hr />

								<?php 
        // ================= Taxonomy relation between aa and ab
        $options = array('empty' => array('value' => '', 'desc' => ''), 'and' => array('value' => 'AND', 'desc' => 'AND'), 'or' => array('value' => 'OR', 'desc' => 'OR'));
        pis_form_select(__('Relation between A1 and A2 taxonomies', 'posts-in-sidebar'), $this->get_field_id('relation_a'), $this->get_field_name('relation_a'), $options, $instance['relation_a']);
        ?>

								<hr />

								<?php 
        // ================= Taxonomy ab
        pis_form_input_text(sprintf(__('%1$sTaxonomy A2%2$s', 'posts-in-sidebar'), '<strong>', '</strong>'), $this->get_field_id('taxonomy_ab'), $this->get_field_name('taxonomy_ab'), esc_attr($instance['taxonomy_ab']), __('movie-genre', 'posts-in-sidebar'), __('Enter the slug of the taxonomy.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Field ab
        $options = array('term_id' => array('value' => 'term_id', 'desc' => __('Term ID', 'posts-in-sidebar')), 'slug' => array('value' => 'slug', 'desc' => __('Slug', 'posts-in-sidebar')), 'name' => array('value' => 'name', 'desc' => __('Name', 'posts-in-sidebar')));
        pis_form_select(__('Field', 'posts-in-sidebar'), $this->get_field_id('field_ab'), $this->get_field_name('field_ab'), $options, $instance['field_ab'], __('Select taxonomy term by this field.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Terms ab
        pis_form_input_text(__('Terms', 'posts-in-sidebar'), $this->get_field_id('terms_ab'), $this->get_field_name('terms_ab'), esc_attr($instance['terms_ab']), __('action,sci-fi', 'posts-in-sidebar'), __('Enter terms, separated by comma.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Operator ab
        $options = array('in' => array('value' => 'IN', 'desc' => 'IN'), 'not_in' => array('value' => 'NOT IN', 'desc' => 'NOT IN'), 'and' => array('value' => 'AND', 'desc' => 'AND'));
        pis_form_select(__('Operator', 'posts-in-sidebar'), $this->get_field_id('operator_ab'), $this->get_field_name('operator_ab'), $options, $instance['operator_ab'], __('Operator to test for terms.', 'posts-in-sidebar'));
        ?>

							</div>

							<div class="pis-column">

								<h4 class="pis-title-center"><?php 
        _e('Column B', 'posts-in-sidebar');
        ?>
</h4>

								<?php 
        // ================= Taxonomy ba
        pis_form_input_text(sprintf(__('%1$sTaxonomy B1%2$s', 'posts-in-sidebar'), '<strong>', '</strong>'), $this->get_field_id('taxonomy_ba'), $this->get_field_name('taxonomy_ba'), esc_attr($instance['taxonomy_ba']), __('post_tag', 'posts-in-sidebar'), __('Enter the slug of the taxonomy.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Field ba
        $options = array('term_id' => array('value' => 'term_id', 'desc' => __('Term ID', 'posts-in-sidebar')), 'slug' => array('value' => 'slug', 'desc' => __('Slug', 'posts-in-sidebar')), 'name' => array('value' => 'name', 'desc' => __('Name', 'posts-in-sidebar')));
        pis_form_select(__('Field', 'posts-in-sidebar'), $this->get_field_id('field_ba'), $this->get_field_name('field_ba'), $options, $instance['field_ba'], __('Select taxonomy term by this field.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Terms ba
        pis_form_input_text(__('Terms', 'posts-in-sidebar'), $this->get_field_id('terms_ba'), $this->get_field_name('terms_ba'), esc_attr($instance['terms_ba']), __('system,apache', 'posts-in-sidebar'), __('Enter terms, separated by comma.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Operator ba
        $options = array('in' => array('value' => 'IN', 'desc' => 'IN'), 'not_in' => array('value' => 'NOT IN', 'desc' => 'NOT IN'), 'and' => array('value' => 'AND', 'desc' => 'AND'));
        pis_form_select(__('Operator', 'posts-in-sidebar'), $this->get_field_id('operator_ba'), $this->get_field_name('operator_ba'), $options, $instance['operator_ba'], __('Operator to test for terms.', 'posts-in-sidebar'));
        ?>

								<hr />

								<?php 
        // ================= Taxonomy relation between ba and bb
        $options = array('empty' => array('value' => '', 'desc' => ''), 'and' => array('value' => 'AND', 'desc' => 'AND'), 'or' => array('value' => 'OR', 'desc' => 'OR'));
        pis_form_select(__('Relation between B1 and B2 taxonomies', 'posts-in-sidebar'), $this->get_field_id('relation_b'), $this->get_field_name('relation_b'), $options, $instance['relation_b']);
        ?>

								<hr />

								<?php 
        // ================= Taxonomy bb
        pis_form_input_text(sprintf(__('%1$sTaxonomy B2%2$s', 'posts-in-sidebar'), '<strong>', '</strong>'), $this->get_field_id('taxonomy_bb'), $this->get_field_name('taxonomy_bb'), esc_attr($instance['taxonomy_bb']), __('post_format', 'posts-in-sidebar'), __('Enter the slug of the taxonomy.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Field bb
        $options = array('term_id' => array('value' => 'term_id', 'desc' => __('Term ID', 'posts-in-sidebar')), 'slug' => array('value' => 'slug', 'desc' => __('Slug', 'posts-in-sidebar')), 'name' => array('value' => 'name', 'desc' => __('Name', 'posts-in-sidebar')));
        pis_form_select(__('Field', 'posts-in-sidebar'), $this->get_field_id('field_bb'), $this->get_field_name('field_bb'), $options, $instance['field_bb'], __('Select taxonomy term by this field.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Terms bb
        pis_form_input_text(__('Terms', 'posts-in-sidebar'), $this->get_field_id('terms_bb'), $this->get_field_name('terms_bb'), esc_attr($instance['terms_bb']), __('post-format-quote', 'posts-in-sidebar'), __('Enter terms, separated by comma.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Operator bb
        $options = array('in' => array('value' => 'IN', 'desc' => 'IN'), 'not_in' => array('value' => 'NOT IN', 'desc' => 'NOT IN'), 'and' => array('value' => 'AND', 'desc' => 'AND'));
        pis_form_select(__('Operator', 'posts-in-sidebar'), $this->get_field_id('operator_bb'), $this->get_field_name('operator_bb'), $options, $instance['operator_bb'], __('Operator to test for terms.', 'posts-in-sidebar'));
        ?>

							</div>

						</div>

					</div>

				</div>

				<!-- Date query -->
				<div class="pis-section pis-2col">

					<h4 class="pis-widget-title"><?php 
        _e('Date query', 'posts-in-sidebar');
        ?>
</h4>

					<div class="pis-container">

						<p><em><?php 
        _e('Define the date period within posts are published.', 'posts-in-sidebar');
        ?>
</em></p>

						<div class="pis-column-container">

							<div class="pis-column">

								<?php 
        pis_form_input_text(__('Year', 'posts-in-sidebar'), $this->get_field_id('date_year'), $this->get_field_name('date_year'), esc_attr($instance['date_year']), '2015', __('4 digits year (e.g. 2015).', 'posts-in-sidebar'));
        ?>

								<?php 
        pis_form_input_text(__('Month', 'posts-in-sidebar'), $this->get_field_id('date_month'), $this->get_field_name('date_month'), esc_attr($instance['date_month']), '06', __('Month number (from 1 to 12).', 'posts-in-sidebar'));
        ?>

								<?php 
        pis_form_input_text(__('Week', 'posts-in-sidebar'), $this->get_field_id('date_week'), $this->get_field_name('date_week'), esc_attr($instance['date_week']), '32', __('Week of the year (from 0 to 53).', 'posts-in-sidebar'));
        ?>

								<?php 
        pis_form_input_text(__('Day', 'posts-in-sidebar'), $this->get_field_id('date_day'), $this->get_field_name('date_day'), esc_attr($instance['date_day']), '12', __('Day of the month (from 1 to 31).', 'posts-in-sidebar'));
        ?>

							</div>

							<div class="pis-column">

								<?php 
        pis_form_input_text(__('Hour', 'posts-in-sidebar'), $this->get_field_id('date_hour'), $this->get_field_name('date_hour'), esc_attr($instance['date_hour']), '09', __('Hour (from 0 to 23).', 'posts-in-sidebar'));
        ?>

								<?php 
        pis_form_input_text(__('Minute', 'posts-in-sidebar'), $this->get_field_id('date_minute'), $this->get_field_name('date_minute'), esc_attr($instance['date_minute']), '24', __('Minute (from 0 to 59).', 'posts-in-sidebar'));
        ?>

								<?php 
        pis_form_input_text(__('Second', 'posts-in-sidebar'), $this->get_field_id('date_second'), $this->get_field_name('date_second'), esc_attr($instance['date_second']), '32', __('Second (from 0 to 59).', 'posts-in-sidebar'));
        ?>

							</div>

						</div>

						<div class="pis-column-container">

							<div class="pis-column">

								<h5 class="pis-title-center"><?php 
        _e('Get posts after this date', 'posts-in-sidebar');
        ?>
</h5>

								<?php 
        pis_form_input_text(__('Year', 'posts-in-sidebar'), $this->get_field_id('date_after_year'), $this->get_field_name('date_after_year'), esc_attr($instance['date_after_year']), '2011', __('Accepts any four-digit year.', 'posts-in-sidebar'));
        ?>

								<?php 
        pis_form_input_text(__('Month', 'posts-in-sidebar'), $this->get_field_id('date_after_month'), $this->get_field_name('date_after_month'), esc_attr($instance['date_after_month']), '10', __('The month of the year. Accepts numbers 1-12.', 'posts-in-sidebar'));
        ?>

								<?php 
        pis_form_input_text(__('Day', 'posts-in-sidebar'), $this->get_field_id('date_after_day'), $this->get_field_name('date_after_day'), esc_attr($instance['date_after_day']), '10', __('The day of the month. Accepts numbers 1-31.', 'posts-in-sidebar'));
        ?>

							</div>

							<div class="pis-column">

								<h5 class="pis-title-center"><?php 
        _e('Get posts before this date', 'posts-in-sidebar');
        ?>
</h5>

								<?php 
        pis_form_input_text(__('Year', 'posts-in-sidebar'), $this->get_field_id('date_before_year'), $this->get_field_name('date_before_year'), esc_attr($instance['date_before_year']), '2011', __('Accepts any four-digit year.', 'posts-in-sidebar'));
        ?>

								<?php 
        pis_form_input_text(__('Month', 'posts-in-sidebar'), $this->get_field_id('date_before_month'), $this->get_field_name('date_before_month'), esc_attr($instance['date_before_month']), '10', __('The month of the year. Accepts numbers 1-12.', 'posts-in-sidebar'));
        ?>

								<?php 
        pis_form_input_text(__('Day', 'posts-in-sidebar'), $this->get_field_id('date_before_day'), $this->get_field_name('date_before_day'), esc_attr($instance['date_before_day']), '10', __('The day of the month. Accepts numbers 1-31.', 'posts-in-sidebar'));
        ?>

							</div>

						</div>

						<div class="pis-column-container">

							<h5 class="pis-title-center"><?php 
        _e('Other options', 'posts-in-sidebar');
        ?>
</h5>

							<div class="pis-column">

								<?php 
        pis_form_checkbox(__('Inclusive', 'posts-in-sidebar'), $this->get_field_id('date_inclusive'), $this->get_field_name('date_inclusive'), checked($date_inclusive, true, false), __('For after/before, whether exact value should be matched or not', 'posts-in-sidebar'));
        ?>

							</div>

							<div class="pis-column">

								<?php 
        $options = array('empty' => array('value' => '', 'desc' => ''), 'post_date' => array('value' => 'post_date', 'desc' => __('Post date', 'posts-in-sidebar')), 'post_date_gmt' => array('value' => 'post_date_gmt', 'desc' => __('Post date GMT', 'posts-in-sidebar')), 'post_modified' => array('value' => 'post_modified', 'desc' => __('Post modified', 'posts-in-sidebar')), 'post_modified_gmt' => array('value' => 'post_modified_gmt', 'desc' => __('Post modified GMT', 'posts-in-sidebar')));
        pis_form_select(__('Column', 'posts-in-sidebar'), $this->get_field_id('date_column'), $this->get_field_name('date_column'), $options, $instance['date_column'], __('Column to query against.', 'posts-in-sidebar'));
        ?>

							</div>

						</div>

					</div>

				</div>

			</div>

		</div>

		<!-- Displaying posts -->
		<div class="pis-section">

			<h4 class="pis-widget-title"><?php 
        _e('Displaying posts', 'posts-in-sidebar');
        ?>
</h4>

			<div class="pis-container">

				<p><em><?php 
        _e('Define here which elements you want to display in the widget.', 'posts-in-sidebar');
        ?>
</em></p>

				<div class="pis-section pis-2col">

					<div class="pis-column-container">

						<div class="pis-column">

							<h4><?php 
        _e('The title of the post', 'posts-in-sidebar');
        ?>
</h4>

							<?php 
        // ================= Title of the post
        pis_form_checkbox(__('Display the title of the post', 'posts-in-sidebar'), $this->get_field_id('display_title'), $this->get_field_name('display_title'), checked($display_title, true, false));
        ?>

							<?php 
        // ================= Link to the title
        pis_form_checkbox(__('Link the title to the post', 'posts-in-sidebar'), $this->get_field_id('link_on_title'), $this->get_field_name('link_on_title'), checked($link_on_title, true, false));
        ?>

							<?php 
        // ================= Title tooltip
        pis_form_input_text(__('Use this text in the tooltip', 'posts-in-sidebar'), $this->get_field_id('title_tooltip'), $this->get_field_name('title_tooltip'), esc_attr($instance['title_tooltip']), '', __('The title of the post will be added after this text. Also note that this text will be used for the image tooltip.', 'posts-in-sidebar'));
        ?>

							<?php 
        // ================= Arrow after the title
        pis_form_checkbox(__('Show an arrow after the title', 'posts-in-sidebar'), $this->get_field_id('arrow'), $this->get_field_name('arrow'), checked($arrow, true, false));
        ?>

						</div>

						<div class="pis-column">
							<h4><?php 
        _e('The text of the post', 'posts-in-sidebar');
        ?>
</h4>

							<?php 
        // ================= Type of text
        $options = array('full_content' => array('value' => 'full_content', 'desc' => __('The full content', 'posts-in-sidebar')), 'rich_content' => array('value' => 'rich_content', 'desc' => __('The rich content', 'posts-in-sidebar')), 'content' => array('value' => 'content', 'desc' => __('The simple text', 'posts-in-sidebar')), 'more_excerpt' => array('value' => 'more_excerpt', 'desc' => __('The excerpt up to "more" tag', 'posts-in-sidebar')), 'excerpt' => array('value' => 'excerpt', 'desc' => __('The excerpt', 'posts-in-sidebar')), 'only_read_more' => array('value' => 'only_read_more', 'desc' => __('Display only the Read more link', 'posts-in-sidebar')), 'none' => array('value' => 'none', 'desc' => __('Do not show any text', 'posts-in-sidebar')));
        pis_form_select(__('Display this type of text', 'posts-in-sidebar'), $this->get_field_id('excerpt'), $this->get_field_name('excerpt'), $options, $instance['excerpt']);
        ?>

							<?php 
        // ================= Excerpt length
        pis_form_input_text(__('The WordPress generated excerpt length will be (in words)', 'posts-in-sidebar'), $this->get_field_id('exc_length'), $this->get_field_name('exc_length'), esc_attr($instance['exc_length']), '20');
        ?>

							<?php 
        // ================= More link text
        pis_form_input_text(__('Use this text for More link', 'posts-in-sidebar'), $this->get_field_id('the_more'), $this->get_field_name('the_more'), esc_attr($instance['the_more']), __('Read more&hellip;', 'posts-in-sidebar'));
        ?>

							<?php 
        // ================= Arrow after the excerpt
        pis_form_checkbox(__('Display an arrow after the "Read more" link', 'posts-in-sidebar'), $this->get_field_id('exc_arrow'), $this->get_field_name('exc_arrow'), checked($exc_arrow, true, false));
        ?>

						</div>

					</div>

				</div>

				<div class="pis-section pis-2col">
					<h4 class="pis-widget-title"><?php 
        _e('The featured image of the post', 'posts-in-sidebar');
        ?>
</h4>

					<div class="pis-container">

						<div class="pis-column-container">

							<div class="pis-column">

								<?php 
        if (!current_theme_supports('post-thumbnails')) {
            ?>
									<p class="pis-alert"><?php 
            _e('Your theme does not support the Post Thumbnail feature. No image will be displayed.', 'posts-in-sidebar');
            ?>
</p>
								<?php 
        }
        ?>

								<?php 
        // ================= Featured image
        pis_form_checkbox(__('Display the featured image of the post', 'posts-in-sidebar'), $this->get_field_id('display_image'), $this->get_field_name('display_image'), checked($display_image, true, false));
        ?>

								<?php 
        // ================= Image sizes
        $options = array();
        $sizes = (array) get_intermediate_image_sizes();
        $sizes[] = 'full';
        foreach ($sizes as $size) {
            $options[] = array('value' => $size, 'desc' => $size);
        }
        pis_form_select(__('The size of the thumbnail will be', 'posts-in-sidebar'), $this->get_field_id('image_size'), $this->get_field_name('image_size'), $options, $instance['image_size']);
        ?>

								<?php 
        // ================= Image align
        $options = array('nochange' => array('value' => 'nochange', 'desc' => __('Do not change', 'posts-in-sidebar')), 'left' => array('value' => 'left', 'desc' => __('Left', 'posts-in-sidebar')), 'right' => array('value' => 'right', 'desc' => __('Right', 'posts-in-sidebar')), 'center' => array('value' => 'center', 'desc' => __('Center', 'posts-in-sidebar')));
        pis_form_select(__('Align the image to', 'posts-in-sidebar'), $this->get_field_id('image_align'), $this->get_field_name('image_align'), $options, $instance['image_align']);
        ?>

								<p>
									<em>
										<?php 
        printf(__('Note that in order to use image sizes different from the WordPress standards, add them to your theme\'s %3$sfunctions.php%4$s file. See the %1$sCodex%2$s for further information.', 'posts-in-sidebar'), '<a href="http://codex.wordpress.org/Function_Reference/add_image_size" target="_blank">', '</a>', '<code>', '</code>');
        ?>
										<?php 
        printf(__('You can also use %1$sa plugin%2$s that could help you in doing it.', 'posts-in-sidebar'), '<a href="http://wordpress.org/plugins/simple-image-sizes/" target="_blank">', '</a>');
        ?>
									</em>
								</p>

								<?php 
        // ================= Positioning image before title
        pis_form_checkbox(__('Display the image before the title of the post', 'posts-in-sidebar'), $this->get_field_id('image_before_title'), $this->get_field_name('image_before_title'), checked($image_before_title, true, false));
        ?>

								<?php 
        // ================= Image link
        pis_form_input_text(__('Link the image to this URL', 'posts-in-sidebar'), $this->get_field_id('image_link'), $this->get_field_name('image_link'), esc_url(strip_tags($instance['image_link'])), 'http://example.com/mypage', __('By default the featured image is linked to the post. Use this field to link the image to a URL of your choice. Please, note that every featured image of this widget will be linked to the same URL.', 'posts-in-sidebar'));
        ?>

							</div>

							<div class="pis-column">

								<h4><?php 
        _e('Customized featured image', 'posts-in-sidebar');
        ?>
</h4>

								<?php 
        // ================= Custom image URL
        pis_form_input_text(__('Use this image instead of the standard featured image', 'posts-in-sidebar'), $this->get_field_id('custom_image_url'), $this->get_field_name('custom_image_url'), esc_url(strip_tags($instance['custom_image_url'])), 'http://example.com/image.jpg', __('Paste here the URL of the image. Note that the same image will be used for all the posts in the widget, unless you active the checkbox below.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Use custom image URL only if the post thumbnail is not defined.
        pis_form_checkbox(__('Use custom image URL only if the post has not a featured image.', 'posts-in-sidebar'), $this->get_field_id('custom_img_no_thumb'), $this->get_field_name('custom_img_no_thumb'), checked($custom_img_no_thumb, true, false));
        ?>

							</div>

						</div>

					</div>

				</div>

				<div class="pis-section">

					<h4 class="pis-widget-title"><?php 
        _e('Author, date and comments', 'posts-in-sidebar');
        ?>
</h4>

					<div class="pis-container">

						<div class="pis-column-container">

							<div class="pis-column">

								<?php 
        // ================= Author
        pis_form_checkbox(__('Display the author of the post', 'posts-in-sidebar'), $this->get_field_id('display_author'), $this->get_field_name('display_author'), checked($display_author, true, false));
        ?>

								<?php 
        // ================= Author text
        pis_form_input_text(__('Use this text before author\'s name', 'posts-in-sidebar'), $this->get_field_id('author_text'), $this->get_field_name('author_text'), esc_attr($instance['author_text']), __('By', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Author archive
        pis_form_checkbox(__('Link the author to his archive', 'posts-in-sidebar'), $this->get_field_id('linkify_author'), $this->get_field_name('linkify_author'), checked($linkify_author, true, false));
        ?>

							</div>

							<div class="pis-column">

								<?php 
        // ================= Date
        pis_form_checkbox(__('Display the date of the post', 'posts-in-sidebar'), $this->get_field_id('display_date'), $this->get_field_name('display_date'), checked($display_date, true, false));
        ?>

								<?php 
        // ================= Date text
        pis_form_input_text(__('Use this text before date', 'posts-in-sidebar'), $this->get_field_id('date_text'), $this->get_field_name('date_text'), esc_attr($instance['date_text']), __('Published on', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Date link
        pis_form_checkbox(__('Link the date to the post', 'posts-in-sidebar'), $this->get_field_id('linkify_date'), $this->get_field_name('linkify_date'), checked($linkify_date, true, false));
        ?>

							</div>

							<div class="pis-column">

								<?php 
        // ================= Number of comments
        pis_form_checkbox(__('Display the number of comments', 'posts-in-sidebar'), $this->get_field_id('comments'), $this->get_field_name('comments'), checked($comments, true, false));
        ?>

								<?php 
        // ================= Comments text
        pis_form_input_text(__('Use this text before comments', 'posts-in-sidebar'), $this->get_field_id('comments_text'), $this->get_field_name('comments_text'), esc_attr($instance['comments_text']), __('Comments:', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Comments link
        pis_form_checkbox(__('Link the comments to post\'s comments', 'posts-in-sidebar'), $this->get_field_id('linkify_comments'), $this->get_field_name('linkify_comments'), checked($linkify_comments, true, false));
        ?>

							</div>

						</div>

						<div class="pis-column-container">

							<div class="pis-column">

								<?php 
        // ================= Author gravatar
        pis_form_checkbox(__('Display author\'s Gravatar', 'posts-in-sidebar'), $this->get_field_id('gravatar_display'), $this->get_field_name('gravatar_display'), checked($gravatar_display, true, false), '', 'pis-gravatar');
        ?>

								<?php 
        // ================= Gravatar size
        pis_form_input_text(__('Gravatar size', 'posts-in-sidebar'), $this->get_field_id('gravatar_size'), $this->get_field_name('gravatar_size'), esc_attr($instance['gravatar_size']), '32');
        ?>

								<?php 
        // ================= Gravatar default image
        pis_form_input_text(__('URL of the default Gravatar image', 'posts-in-sidebar'), $this->get_field_id('gravatar_default'), $this->get_field_name('gravatar_default'), esc_attr($instance['gravatar_default']), 'http://example.com/image.jpg');
        ?>

								<?php 
        // ================= Gravatar position
        $options = array('next_title' => array('value' => 'next_title', 'desc' => __('Next to the post title', 'posts-in-sidebar')), 'next_post' => array('value' => 'next_post', 'desc' => __('Next to the post content', 'posts-in-sidebar')), 'next_author' => array('value' => 'next_author', 'desc' => __('Next to the author name', 'posts-in-sidebar')));
        pis_form_select(__('Gravatar position', 'posts-in-sidebar'), $this->get_field_id('gravatar_position'), $this->get_field_name('gravatar_position'), $options, $instance['gravatar_position']);
        ?>

							</div>

							<div class="pis-column">

								<?php 
        // ================= Modification Date
        pis_form_checkbox(__('Display the modification date of the post', 'posts-in-sidebar'), $this->get_field_id('display_mod_date'), $this->get_field_name('display_mod_date'), checked($display_mod_date, true, false));
        ?>

								<?php 
        // ================= Modification Date text
        pis_form_input_text(__('Use this text before modification date', 'posts-in-sidebar'), $this->get_field_id('mod_date_text'), $this->get_field_name('mod_date_text'), esc_attr($instance['mod_date_text']), __('Modified on', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Modification Date link
        pis_form_checkbox(__('Link the modification date to the post', 'posts-in-sidebar'), $this->get_field_id('linkify_mod_date'), $this->get_field_name('linkify_mod_date'), checked($linkify_mod_date, true, false));
        ?>

							</div>

							<div class="pis-column">

								<?php 
        // ================= Utility separator
        pis_form_input_text(__('Use this separator between author, date and comments', 'posts-in-sidebar'), $this->get_field_id('utility_sep'), $this->get_field_name('utility_sep'), esc_attr($instance['utility_sep']), '|', __('A space will be added before and after the separator.', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Section position
        pis_form_checkbox(__('Display this section after the title of the post', 'posts-in-sidebar'), $this->get_field_id('utility_after_title'), $this->get_field_name('utility_after_title'), checked($utility_after_title, true, false));
        ?>

							</div>

						</div>

					</div>

				</div>

				<div class="pis-section">

					<h4 class="pis-widget-title"><?php 
        _e('Taxonomies', 'posts-in-sidebar');
        ?>
</h4>

					<div class="pis-container">

						<div class="pis-column-container">

							<div class="pis-column">

								<h4><?php 
        _e('Categories', 'posts-in-sidebar');
        ?>
</h4>

								<?php 
        // ================= Post categories
        pis_form_checkbox(__('Show the categories', 'posts-in-sidebar'), $this->get_field_id('categories'), $this->get_field_name('categories'), checked($categories, true, false));
        ?>

								<?php 
        // ================= Categories text
        pis_form_input_text(__('Use this text before categories list', 'posts-in-sidebar'), $this->get_field_id('categ_text'), $this->get_field_name('categ_text'), esc_attr($instance['categ_text']), __('Category:', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Categories separator
        pis_form_input_text(__('Use this separator between categories', 'posts-in-sidebar'), $this->get_field_id('categ_sep'), $this->get_field_name('categ_sep'), esc_attr($instance['categ_sep']), ',', __('A space will be added after the separator.', 'posts-in-sidebar'));
        ?>

							</div>

							<div class="pis-column">

								<h4><?php 
        _e('Tags', 'posts-in-sidebar');
        ?>
</h4>

								<?php 
        // ================= Post tags
        pis_form_checkbox(__('Show the tags', 'posts-in-sidebar'), $this->get_field_id('tags'), $this->get_field_name('tags'), checked($tags, true, false));
        ?>

								<?php 
        // ================= Tags text
        pis_form_input_text(__('Use this text before tags list', 'posts-in-sidebar'), $this->get_field_id('tags_text'), $this->get_field_name('tags_text'), esc_attr($instance['tags_text']), __('Tags:', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Hashtag
        pis_form_input_text(__('Use this hashtag', 'posts-in-sidebar'), $this->get_field_id('hashtag'), $this->get_field_name('hashtag'), esc_attr($instance['hashtag']), '#');
        ?>

								<?php 
        // ================= Tags separator
        pis_form_input_text(__('Use this separator between tags', 'posts-in-sidebar'), $this->get_field_id('tag_sep'), $this->get_field_name('tag_sep'), esc_attr($instance['tag_sep']), ',', __('A space will be added after the separator.', 'posts-in-sidebar'));
        ?>

							</div>

							<div class="pis-column">

								<h4><?php 
        _e('Custom taxonomies', 'posts-in-sidebar');
        ?>
</h4>

								<?php 
        // ================= Custom taxonomies
        pis_form_checkbox(__('Show the custom taxonomies', 'posts-in-sidebar'), $this->get_field_id('display_custom_tax'), $this->get_field_name('display_custom_tax'), checked($display_custom_tax, true, false));
        ?>

								<?php 
        // ================= Terms hashtag
        pis_form_input_text(__('Use this hashtag for terms', 'posts-in-sidebar'), $this->get_field_id('term_hashtag'), $this->get_field_name('term_hashtag'), esc_attr($instance['term_hashtag']), '#');
        ?>

								<?php 
        // ================= Terms separator
        pis_form_input_text(__('Use this separator between terms', 'posts-in-sidebar'), $this->get_field_id('term_sep'), $this->get_field_name('term_sep'), esc_attr($instance['term_sep']), ',', __('A space will be added after the separator.', 'posts-in-sidebar'));
        ?>

							</div>

						</div>
					</div>

				</div>

				<div class="pis-section pis-2col">

					<h4 class="pis-widget-title"><?php 
        _e('The custom field', 'posts-in-sidebar');
        ?>
</h4>

					<div class="pis-container">

						<div class="pis-column-container">

							<div class="pis-column">

								<?php 
        // ================= Display custom field
        pis_form_checkbox(__('Display the custom field of the post', 'posts-in-sidebar'), $this->get_field_id('custom_field'), $this->get_field_name('custom_field'), checked($custom_field, true, false));
        ?>

								<?php 
        // ================= Custom fields text
        pis_form_input_text(__('Use this text before the custom field', 'posts-in-sidebar'), $this->get_field_id('custom_field_txt'), $this->get_field_name('custom_field_txt'), esc_attr($instance['custom_field_txt']), __('Custom field:', 'posts-in-sidebar'));
        ?>

								<?php 
        // ================= Which custom field
        $options = array();
        $metas = (array) pis_meta();
        foreach ($metas as $meta) {
            if (!is_protected_meta($meta, 'post')) {
                $options[] = array('value' => $meta, 'desc' => $meta);
            }
        }
        pis_form_select(__('Display this custom field', 'posts-in-sidebar'), $this->get_field_id('meta'), $this->get_field_name('meta'), $options, $instance['meta']);
        ?>

							</div>

							<div class="pis-column">

								<?php 
        // ================= Custom field key
        pis_form_checkbox(__('Also display the key of the custom field', 'posts-in-sidebar'), $this->get_field_id('custom_field_key'), $this->get_field_name('custom_field_key'), checked($custom_field_key, true, false));
        ?>

								<?php 
        // ================= Custom field separator
        pis_form_input_text(__('Use this separator between meta key and value', 'posts-in-sidebar'), $this->get_field_id('custom_field_sep'), $this->get_field_name('custom_field_sep'), esc_attr($instance['custom_field_sep']), ':');
        ?>

							</div>

						</div>

					</div>

				</div>

				<div class="pis-section pis-2col">

					<h4 class="pis-widget-title"><?php 
        _e('The link to the archive', 'posts-in-sidebar');
        ?>
</h4>

					<div class="pis-container">

						<div class="pis-column-container">

							<div class="pis-column">

								<?php 
        // ================= Taxonomy archive link
        pis_form_checkbox(__('Display the link to the taxonomy archive', 'posts-in-sidebar'), $this->get_field_id('archive_link'), $this->get_field_name('archive_link'), checked($archive_link, true, false));
        ?>

								<?php 
        // ================= Which taxonomy
        $options = array('author' => array('value' => 'author', 'desc' => __('Author', 'posts-in-sidebar')), 'category' => array('value' => 'category', 'desc' => __('Category', 'posts-in-sidebar')), 'tag' => array('value' => 'tag', 'desc' => __('Tag', 'posts-in-sidebar')));
        /* Custom post type */
        $custom_post_types = get_post_types(array('_builtin' => false));
        if ($custom_post_types) {
            $options[] = array('value' => 'custom_post_type', 'desc' => __('Custom post type', 'posts-in-sidebar'));
        }
        /* Custom taxonomy */
        $custom_taxonomy = get_taxonomies(array('public' => true, '_builtin' => false));
        if ($custom_taxonomy) {
            $options[] = array('value' => 'custom_taxonomy', 'desc' => __('Custom taxonomy', 'posts-in-sidebar'));
        }
        /* Post format */
        if ($post_formats) {
            // $post_formats has been already declared (search above).
            foreach ($post_formats as $post_format) {
                $options[] = array('value' => $post_format->slug, 'desc' => sprintf(__('Post format: %s', 'posts-in-sidebar'), $post_format->name));
            }
        }
        pis_form_select(__('Link to the archive of', 'posts-in-sidebar'), $this->get_field_id('link_to'), $this->get_field_name('link_to'), $options, $instance['link_to'], '', 'pis-linkto-form');
        ?>

							</div>

							<div class="pis-column">

								<div class="pis-linkto-tax-name">
									<?php 
        // ================= Taxonomy name for archive link
        pis_form_input_text(__('Taxonomy name', 'posts-in-sidebar'), $this->get_field_id('tax_name'), $this->get_field_name('tax_name'), esc_attr($instance['tax_name']), __('genre', 'posts-in-sidebar'), sprintf(__('Enter the term name of the custom taxonomy (e.g., %1$sgenre%2$s).', 'posts-in-sidebar'), '<code>', '</code>'), 'margin: 0; padding: 0.5em;');
        ?>
								</div>

								<div class="pis-linkto-term-name">
									<?php 
        // ================= Taxonomy term name for archive link
        pis_form_input_text(__('Taxonomy term name', 'posts-in-sidebar'), $this->get_field_id('tax_term_name'), $this->get_field_name('tax_term_name'), esc_attr($instance['tax_term_name']), __('science', 'posts-in-sidebar'), sprintf(__('Enter the name of the taxonomy term (e.g., %1$sscience%2$s if the taxonomy is "genre").%3$sIf you selected "Author" in "Link to the archive of" field, enter the author slug; if you selected "Category", enter the category slug, and so on.', 'posts-in-sidebar'), '<code>', '</code>', '<br />'), 'margin: 0; padding: 0.5em;');
        ?>
								</div>

							</div>

						</div>

						<?php 
        // ================= Archive link text
        pis_form_input_text(__('Use this text for archive link', 'posts-in-sidebar'), $this->get_field_id('archive_text'), $this->get_field_name('archive_text'), esc_attr($instance['archive_text']), __('Display all posts by %s', 'posts-in-sidebar'), sprintf(__('Use %s to display the name of the taxonomy.', 'posts-in-sidebar'), '<code>%s</code>'));
        ?>

					</div>

				</div>

				<div class="pis-section">

					<h4 class="pis-widget-title"><?php 
        _e('When no posts are found', 'posts-in-sidebar');
        ?>
</h4>

					<div class="pis-container">

							<?php 
        // ================= When no posts are found
        // Text when no posts found
        pis_form_input_text(__('Use this text when there are no posts', 'posts-in-sidebar'), $this->get_field_id('nopost_text'), $this->get_field_name('nopost_text'), esc_attr($instance['nopost_text']), __('No posts yet.', 'posts-in-sidebar'));
        ?>

							<?php 
        // Hide the widget if no posts found
        pis_form_checkbox(__('Completely hide the widget if no posts are found', 'posts-in-sidebar'), $this->get_field_id('hide_widget'), $this->get_field_name('hide_widget'), checked($hide_widget, true, false));
        ?>

					</div>

				</div>

			</div>

		</div>

		<!-- Styles -->
		<div class="pis-section">

			<h4 class="pis-widget-title"><?php 
        _e('Styles', 'posts-in-sidebar');
        ?>
</h4>

			<div class="pis-container">

				<p><em><?php 
        _e('This section defines the margin for each line of the widget. Leave blank if you don\'t want to add any local style.', 'posts-in-sidebar');
        ?>
</em></p>

				<div class="pis-column-container">

					<div class="pis-column">

						<?php 
        // ================= Margin unit
        $options = array('px' => array('value' => 'px', 'desc' => 'px'), '%' => array('value' => '%', 'desc' => '%'), 'em' => array('value' => 'em', 'desc' => 'em'), 'rem' => array('value' => 'rem', 'desc' => 'rem'));
        pis_form_select(__('Unit for margins', 'posts-in-sidebar'), $this->get_field_id('margin_unit'), $this->get_field_name('margin_unit'), $options, $instance['margin_unit']);
        ?>

						<p><?php 
        printf(__('Enter here only the value without any unit, e.g. enter %1$s if you want a space of 10px or enter %2$s if you don\'t want any space.', 'posts-in-sidebar'), '<code>10</code>', '<code>0</code>');
        ?>
</p>

					</div>

				</div>

				<div class="pis-column-container">

					<?php 
        // ================= Margins
        ?>

					<div class="pis-column">
						<?php 
        pis_form_input_text(__('Introduction bottom margin', 'posts-in-sidebar'), $this->get_field_id('intro_margin'), $this->get_field_name('intro_margin'), esc_attr($instance['intro_margin']));
        ?>
						<?php 
        pis_form_input_text(__('Title bottom margin', 'posts-in-sidebar'), $this->get_field_id('title_margin'), $this->get_field_name('title_margin'), esc_attr($instance['title_margin']));
        ?>
						<?php 
        pis_form_input_text(__('Image left &amp; right margin', 'posts-in-sidebar'), $this->get_field_id('side_image_margin'), $this->get_field_name('side_image_margin'), esc_attr($instance['side_image_margin']));
        ?>
						<?php 
        pis_form_input_text(__('Image bottom margin', 'posts-in-sidebar'), $this->get_field_id('bottom_image_margin'), $this->get_field_name('bottom_image_margin'), esc_attr($instance['bottom_image_margin']));
        ?>
					</div>

					<div class="pis-column">
						<?php 
        pis_form_input_text(__('Excerpt bottom margin', 'posts-in-sidebar'), $this->get_field_id('excerpt_margin'), $this->get_field_name('excerpt_margin'), esc_attr($instance['excerpt_margin']));
        ?>
						<?php 
        pis_form_input_text(__('Utility bottom margin', 'posts-in-sidebar'), $this->get_field_id('utility_margin'), $this->get_field_name('utility_margin'), esc_attr($instance['utility_margin']));
        ?>
						<?php 
        pis_form_input_text(__('Categories bottom margin', 'posts-in-sidebar'), $this->get_field_id('categories_margin'), $this->get_field_name('categories_margin'), esc_attr($instance['categories_margin']));
        ?>
						<?php 
        pis_form_input_text(__('Tags bottom margin', 'posts-in-sidebar'), $this->get_field_id('tags_margin'), $this->get_field_name('tags_margin'), esc_attr($instance['tags_margin']));
        ?>
					</div>

					<div class="pis-column">
						<?php 
        pis_form_input_text(__('Terms bottom margin', 'posts-in-sidebar'), $this->get_field_id('terms_margin'), $this->get_field_name('terms_margin'), esc_attr($instance['terms_margin']));
        ?>
						<?php 
        pis_form_input_text(__('Custom field bottom margin', 'posts-in-sidebar'), $this->get_field_id('custom_field_margin'), $this->get_field_name('custom_field_margin'), esc_attr($instance['custom_field_margin']));
        ?>
						<?php 
        pis_form_input_text(__('Archive bottom margin', 'posts-in-sidebar'), $this->get_field_id('archive_margin'), $this->get_field_name('archive_margin'), esc_attr($instance['archive_margin']));
        ?>
						<?php 
        pis_form_input_text(__('No-posts bottom margin', 'posts-in-sidebar'), $this->get_field_id('noposts_margin'), $this->get_field_name('noposts_margin'), esc_attr($instance['noposts_margin']));
        ?>
					</div>

				</div>

				<!-- Custom styles -->
				<div class="pis-section">

					<h4 class="pis-widget-title"><?php 
        _e('Custom styles', 'posts-in-sidebar');
        ?>
</h4>

					<div class="pis-container">

						<p><em>
							<?php 
        printf(__('In this field you can add your own styles, for example: %s', 'posts-in-sidebar'), '<code>.pis-excerpt { color: green; }</code>');
        ?>
							<br>
							<?php 
        printf(__('To apply a style only to elements of this widget, prefix every style with this ID selector: %s', 'posts-in-sidebar'), '<code>#' . $this->id . '</code>');
        ?>
							<br>
							<?php 
        printf(__('For example: %s', 'posts-in-sidebar'), '<pre><code>#' . $this->id . ' .pis-title { font-size: 18px !important; }</code></pre>');
        ?>
						</em></p>

						<?php 
        // ================= Custom styles
        pis_form_textarea(__('Custom styles', 'posts-in-sidebar'), $this->get_field_id('custom_styles'), $this->get_field_name('custom_styles'), $instance['custom_styles'], __('Enter here your CSS styles', 'posts-in-sidebar'), $style = 'resize: vertical; width: 100%; height: 80px;');
        ?>

					</div>

				</div>

				<!-- Extras -->
				<div class="pis-section">

					<h4 class="pis-widget-title"><?php 
        _e('Extras', 'posts-in-sidebar');
        ?>
</h4>

					<div class="pis-container">

						<?php 
        // ================= Container Class
        pis_form_input_text(__('Add a global container with this CSS class', 'posts-in-sidebar'), $this->get_field_id('container_class'), $this->get_field_name('container_class'), esc_attr($instance['container_class']), 'posts-container', sprintf(__('Enter the name of your container (for example, %1$s). The plugin will add a new %2$s container with this class. You can enter only one class and the name may contain only letters, hyphens and underscores. The new container will enclose all the widget, from the title to the last line.', 'posts-in-sidebar'), '<code>my-container</code>', '<code>div</code>'));
        ?>

						<?php 
        // ================= Type of HTML for list of posts
        $options = array('ul' => array('value' => 'ul', 'desc' => __('Unordered list', 'posts-in-sidebar')), 'ol' => array('value' => 'ol', 'desc' => __('Ordered list', 'posts-in-sidebar')));
        pis_form_select(__('Use this type of list for the posts', 'posts-in-sidebar'), $this->get_field_id('list_element'), $this->get_field_name('list_element'), $options, $instance['list_element']);
        ?>

						<?php 
        // ================= Remove bullets and left space
        pis_form_checkbox(__('Try to remove the bullets and the extra left space from the list elements', 'posts-in-sidebar'), $this->get_field_id('remove_bullets'), $this->get_field_name('remove_bullets'), checked($remove_bullets, true, false), sprintf(__('If the plugin doesn\'t remove the bullets and/or the extra left space, you have to %1$sedit your CSS file%2$s manually.', 'posts-in-sidebar'), '<a href="' . admin_url('theme-editor.php') . '" target="_blank">', '</a>'));
        ?>

					</div>

				</div>

			</div>

		</div>

		<!-- Cache -->
		<div class="pis-section">

			<h4 class="pis-widget-title"><?php 
        _e('Cache', 'posts-in-sidebar');
        ?>
</h4>

			<div class="pis-container pis-2col">

				<div class="pis-column-container">

					<div class="pis-column">

						<?php 
        // ================= Cache for the query
        pis_form_checkbox(__('Use a cache to serve the output', 'posts-in-sidebar'), $this->get_field_id('cached'), $this->get_field_name('cached'), checked($cached, true, false), __('This option, if activated, will increase the performance but will show the same output during the defined cache time.', 'posts-in-sidebar'));
        ?>

					</div>

					<div class="pis-column">

						<?php 
        // ================= Cache duration
        pis_form_input_text(__('The cache will be used for (in seconds)', 'posts-in-sidebar'), $this->get_field_id('cache_time'), $this->get_field_name('cache_time'), esc_attr($instance['cache_time']), '3600', sprintf(__('For example, %1$s for one hour of cache. To reset the cache, enter %2$s and save the widget.', 'posts-in-sidebar'), '<code>3600</code>', '<code>0</code>'));
        ?>
					</div>

				</div>

			</div>

		</div>

		<!-- Debugging -->
		<div class="pis-section">

			<h4 class="pis-widget-title"><?php 
        _e('Debugging', 'posts-in-sidebar');
        ?>
</h4>

			<div class="pis-container">

				<p><?php 
        printf(__('You are using Posts in Sidebar version %s.', 'posts-in-sidebar'), '<strong>' . PIS_VERSION . '</strong>');
        ?>
</p>

				<p class="pis-alert"><strong><?php 
        _e('Use this options for debugging purposes only. Please note that the informations will be displayed publicly on your site.', 'posts-in-sidebar');
        ?>
</strong></p>

				<?php 
        // ================= Debug: display the query for the widget
        pis_form_checkbox(__('Display the query for the widget', 'posts-in-sidebar'), $this->get_field_id('debug_query'), $this->get_field_name('debug_query'), checked($debug_query, true, false));
        ?>

				<?php 
        // ================= Debug: display the complete set of parameters for the widget
        pis_form_checkbox(__('Display the complete set of parameters for the widget', 'posts-in-sidebar'), $this->get_field_id('debug_params'), $this->get_field_name('debug_params'), checked($debug_params, true, false));
        ?>

				<?php 
        // ================= Debug: display the total number of queries
        pis_form_checkbox(__('Display the total number of queries, including WordPress, current theme and all active plugins', 'posts-in-sidebar'), $this->get_field_id('debug_query_number'), $this->get_field_name('debug_query_number'), checked($debug_query_number, true, false));
        ?>

			</div>

		</div>

		<?php 
    }
Exemplo n.º 3
0
/**
 * Ajax handler for adding meta.
 *
 * @since 3.1.0
 */
function wp_ajax_add_meta()
{
    check_ajax_referer('add-meta', '_ajax_nonce-add-meta');
    $c = 0;
    $pid = (int) $_POST['post_id'];
    $post = get_post($pid);
    if (isset($_POST['metakeyselect']) || isset($_POST['metakeyinput'])) {
        if (!current_user_can('edit_post', $pid)) {
            wp_die(-1);
        }
        if (isset($_POST['metakeyselect']) && '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput'])) {
            wp_die(1);
        }
        // If the post is an autodraft, save the post as a draft and then attempt to save the meta.
        if ($post->post_status == 'auto-draft') {
            $post_data = array();
            $post_data['action'] = 'draft';
            // Warning fix
            $post_data['post_ID'] = $pid;
            $post_data['post_type'] = $post->post_type;
            $post_data['post_status'] = 'draft';
            $now = current_time('timestamp', 1);
            $post_data['post_title'] = sprintf(__('Draft created on %1$s at %2$s'), date(get_option('date_format'), $now), date(get_option('time_format'), $now));
            $pid = edit_post($post_data);
            if ($pid) {
                if (is_wp_error($pid)) {
                    $x = new WP_Ajax_Response(array('what' => 'meta', 'data' => $pid));
                    $x->send();
                }
                if (!($mid = add_meta($pid))) {
                    wp_die(__('Please provide a custom field value.'));
                }
            } else {
                wp_die(0);
            }
        } elseif (!($mid = add_meta($pid))) {
            wp_die(__('Please provide a custom field value.'));
        }
        $meta = get_metadata_by_mid('post', $mid);
        $pid = (int) $meta->post_id;
        $meta = get_object_vars($meta);
        $x = new WP_Ajax_Response(array('what' => 'meta', 'id' => $mid, 'data' => _list_meta_row($meta, $c), 'position' => 1, 'supplemental' => array('postid' => $pid)));
    } else {
        // Update?
        $mid = (int) key($_POST['meta']);
        $key = wp_unslash($_POST['meta'][$mid]['key']);
        $value = wp_unslash($_POST['meta'][$mid]['value']);
        if ('' == trim($key)) {
            wp_die(__('Please provide a custom field name.'));
        }
        if ('' == trim($value)) {
            wp_die(__('Please provide a custom field value.'));
        }
        if (!($meta = get_metadata_by_mid('post', $mid))) {
            wp_die(0);
        }
        // if meta doesn't exist
        if (is_protected_meta($meta->meta_key, 'post') || is_protected_meta($key, 'post') || !current_user_can('edit_post_meta', $meta->post_id, $meta->meta_key) || !current_user_can('edit_post_meta', $meta->post_id, $key)) {
            wp_die(-1);
        }
        if ($meta->meta_value != $value || $meta->meta_key != $key) {
            if (!($u = update_metadata_by_mid('post', $mid, $value, $key))) {
                wp_die(0);
            }
            // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
        }
        $x = new WP_Ajax_Response(array('what' => 'meta', 'id' => $mid, 'old_id' => $mid, 'data' => _list_meta_row(array('meta_key' => $key, 'meta_value' => $value, 'meta_id' => $mid), $c), 'position' => 0, 'supplemental' => array('postid' => $meta->post_id)));
    }
    $x->send();
}
/**
 * Display list of post custom fields.
 *
 * @since 1.2.0
 *
 * @internal This will probably change at some point...
 *
 */
function the_meta()
{
    if ($keys = get_post_custom_keys()) {
        echo "<ul class='post-meta'>\n";
        foreach ((array) $keys as $key) {
            $keyt = trim($key);
            if (is_protected_meta($keyt, 'post')) {
                continue;
            }
            $values = array_map('trim', get_post_custom_values($key));
            $value = implode($values, ', ');
            /**
             * Filters the HTML output of the li element in the post custom fields list.
             *
             * @since 2.2.0
             *
             * @param string $html  The HTML output for the li element.
             * @param string $key   Meta key.
             * @param string $value Meta value.
             */
            echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>{$key}:</span> {$value}</li>\n", $key, $value);
        }
        echo "</ul>\n";
    }
}
        function insertPages_handleShortcode_insert($atts, $content = null)
        {
            global $wp_query, $post, $wp_current_filter;
            // Shortcode attributes.
            $attributes = shortcode_atts(array('page' => '0', 'display' => 'all', 'class' => '', 'inline' => false), $atts);
            // Validation checks.
            if ($attributes['page'] === '0') {
                return $content;
            }
            // Trying to embed same page in itself.
            if (!is_null($post) && property_exists($post, 'ID') && ($attributes['page'] == $post->ID || $attributes['page'] == $post->post_name)) {
                return $content;
            }
            // Get options set in WordPress dashboard (Settings > Insert Pages).
            $options = get_option('wpip_settings');
            if ($options === FALSE || !is_array($options) || !array_key_exists('wpip_format', $options) || !array_key_exists('wpip_wrapper', $options) || !array_key_exists('wpip_insert_method', $options)) {
                $options = wpip_set_defaults();
            }
            $attributes['inline'] = $attributes['inline'] !== false && $attributes['inline'] !== 'false' || array_search('inline', $atts) === 0 || array_key_exists('wpip_wrapper', $options) && $options['wpip_wrapper'] === 'inline';
            /**
             * Filter the flag indicating whether to wrap the inserted content in inline tags (span).
             *
             * @param bool $use_inline_wrapper Indicates whether to wrap the content in span tags.
             */
            $attributes['inline'] = apply_filters('insert_pages_use_inline_wrapper', $attributes['inline']);
            $attributes['wrapper_tag'] = $attributes['inline'] ? 'span' : 'div';
            $attributes['should_apply_the_content_filter'] = true;
            /**
             * Filter the flag indicating whether to apply the_content filter to post
             * contents and excerpts that are being inserted.
             *
             * @param bool $apply_the_content_filter Indicates whether to apply the_content filter.
             */
            $attributes['should_apply_the_content_filter'] = apply_filters('insert_pages_apply_the_content_filter', $attributes['should_apply_the_content_filter']);
            // Disable the_content filter if using inline tags, since wpautop
            // inserts p tags and we can't have any inside inline elements.
            if ($attributes['inline']) {
                $attributes['should_apply_the_content_filter'] = false;
            }
            $attributes['should_apply_nesting_check'] = true;
            /**
             * Filter the flag indicating whether to apply deep nesting check
             * that can prevent circular loops. Note that some use cases rely
             * on inserting pages that themselves have inserted pages, so this
             * check should be disabled for those individuals.
             *
             * @param bool $apply_the_content_filter Indicates whether to apply the_content filter.
             */
            $attributes['should_apply_nesting_check'] = apply_filters('insert_pages_apply_nesting_check', $attributes['should_apply_nesting_check']);
            // Don't allow inserted pages to be added to the_content more than once (prevent infinite loops).
            if ($attributes['should_apply_nesting_check']) {
                $done = false;
                foreach ($wp_current_filter as $filter) {
                    if ('the_content' == $filter) {
                        if ($done) {
                            return $content;
                        } else {
                            $done = true;
                        }
                    }
                }
            }
            // Get the WP_Post object from the provided slug or ID.
            if (!is_numeric($attributes['page'])) {
                // Get list of post types that can be inserted (page, post, custom
                // types), excluding builtin types (nav_menu_item, attachment).
                $insertable_post_types = array_filter(get_post_types(), create_function('$type', 'return ! in_array( $type, array( "nav_menu_item", "attachment" ) );'));
                $inserted_page = get_page_by_path($attributes['page'], OBJECT, $insertable_post_types);
                $attributes['page'] = $inserted_page ? $inserted_page->ID : $attributes['page'];
            } else {
                $inserted_page = get_post(intval($attributes['page']));
            }
            // Use "Normal" insert method (get_post()).
            if ($options['wpip_insert_method'] !== 'legacy') {
                // If we couldn't retrieve the page, fire the filter hook showing a not-found message.
                if ($inserted_page === null) {
                    /**
                     * Filter the html that should be displayed if an inserted page was not found.
                     *
                     * @param string $content html to be displayed. Defaults to an empty string.
                     */
                    $content = apply_filters('insert_pages_not_found_message', $content);
                    // Short-circuit since we didn't find the page.
                    return $content;
                }
                // Start output buffering so we can save the output to a string.
                ob_start();
                // If Beaver Builder plugin is enabled, load any cached styles associated with the inserted page.
                // Note: Temporarily set the global $post->ID to the inserted page ID,
                // since Beaver Builder relies on it to load the appropriate styles.
                if (class_exists('FLBuilder')) {
                    // If we're not in The Loop (i.e., global $post isn't assigned),
                    // temporarily populate it with the post to be inserted so we can
                    // retrieve Beaver Builder styles for that post. Reset $post to null
                    // after we're done.
                    if (is_null($post)) {
                        $old_post_id = null;
                        $post = $inserted_page;
                    } else {
                        $old_post_id = $post->ID;
                        $post->ID = $inserted_page->ID;
                    }
                    FLBuilder::enqueue_layout_styles_scripts($inserted_page->ID);
                    if (is_null($old_post_id)) {
                        $post = null;
                    } else {
                        $post->ID = $old_post_id;
                    }
                }
                // Show either the title, link, content, everything, or everything via a custom template
                // Note: if the sharing_display filter exists, it means Jetpack is installed and Sharing is enabled;
                // This plugin conflicts with Sharing, because Sharing assumes the_content and the_excerpt filters
                // are only getting called once. The fix here is to disable processing of filters on the_content in
                // the inserted page. @see https://codex.wordpress.org/Function_Reference/the_content#Alternative_Usage
                switch ($attributes['display']) {
                    case "title":
                        $title_tag = $attributes['inline'] ? 'span' : 'h1';
                        echo "<{$title_tag} class='insert-page-title'>";
                        echo get_the_title($inserted_page->ID);
                        echo "</{$title_tag}>";
                        break;
                    case "link":
                        ?>
<a href="<?php 
                        echo esc_url(get_permalink($inserted_page->ID));
                        ?>
"><?php 
                        echo get_the_title($inserted_page->ID);
                        ?>
</a><?php 
                        break;
                    case "excerpt":
                        ?>
<h1><a href="<?php 
                        echo esc_url(get_permalink($inserted_page->ID));
                        ?>
"><?php 
                        echo get_the_title($inserted_page->ID);
                        ?>
</a></h1><?php 
                        echo $this->insertPages_trim_excerpt(get_post_field('post_excerpt', $inserted_page->ID), $inserted_page->ID, $attributes['should_apply_the_content_filter']);
                        break;
                    case "excerpt-only":
                        echo $this->insertPages_trim_excerpt(get_post_field('post_excerpt', $inserted_page->ID), $inserted_page->ID, $attributes['should_apply_the_content_filter']);
                        break;
                    case "content":
                        $content = get_post_field('post_content', $inserted_page->ID);
                        if ($attributes['should_apply_the_content_filter']) {
                            $content = apply_filters('the_content', $content);
                        }
                        echo $content;
                        break;
                    case "all":
                        // Title.
                        $title_tag = $attributes['inline'] ? 'span' : 'h1';
                        echo "<{$title_tag} class='insert-page-title'>";
                        echo get_the_title($inserted_page->ID);
                        echo "</{$title_tag}>";
                        // Content.
                        $content = get_post_field('post_content', $inserted_page->ID);
                        if ($attributes['should_apply_the_content_filter']) {
                            $content = apply_filters('the_content', $content);
                        }
                        echo $content;
                        // Meta.
                        // @ref https://core.trac.wordpress.org/browser/tags/4.4/src/wp-includes/post-template.php#L968
                        if ($keys = get_post_custom_keys($inserted_page->ID)) {
                            echo "<ul class='post-meta'>\n";
                            foreach ((array) $keys as $key) {
                                $keyt = trim($key);
                                if (is_protected_meta($keyt, 'post')) {
                                    continue;
                                }
                                $values = array_map('trim', get_post_custom_values($key));
                                $value = implode($values, ', ');
                                /**
                                 * Filter the HTML output of the li element in the post custom fields list.
                                 *
                                 * @since 2.2.0
                                 *
                                 * @param string $html  The HTML output for the li element.
                                 * @param string $key   Meta key.
                                 * @param string $value Meta value.
                                 */
                                echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>{$key}:</span> {$value}</li>\n", $key, $value);
                            }
                            echo "</ul>\n";
                        }
                        break;
                    default:
                        // display is either invalid, or contains a template file to use
                        // Legacy/compatibility code: In order to use custom templates,
                        // we use query_posts() to provide the template with the global
                        // state it requires for the inserted page (in other words, all
                        // template tags will work with respect to the inserted page
                        // instead of the parent page / main loop). Note that this may
                        // cause some compatibility issues with other plugins.
                        // @ref https://codex.wordpress.org/Function_Reference/query_posts
                        if (is_numeric($attributes['page'])) {
                            $args = array('p' => intval($attributes['page']), 'post_type' => get_post_types());
                        } else {
                            $args = array('name' => esc_attr($attributes['page']), 'post_type' => get_post_types());
                        }
                        $inserted_page = query_posts($args);
                        if (have_posts()) {
                            $template = locate_template($attributes['display']);
                            if (strlen($template) > 0) {
                                include $template;
                                // execute the template code
                            } else {
                                // Couldn't find template, so fall back to printing a link to the page.
                                the_post();
                                ?>
<a href="<?php 
                                the_permalink();
                                ?>
"><?php 
                                the_title();
                                ?>
</a><?php 
                            }
                        }
                        wp_reset_query();
                }
                // Save output buffer contents.
                $content = ob_get_clean();
                // Use "Legacy" insert method (query_posts()).
            } else {
                // Construct query_posts arguments.
                if (is_numeric($attributes['page'])) {
                    $args = array('p' => intval($attributes['page']), 'post_type' => get_post_types());
                } else {
                    $args = array('name' => esc_attr($attributes['page']), 'post_type' => get_post_types());
                }
                $posts = query_posts($args);
                if (have_posts()) {
                    // Start output buffering so we can save the output to string
                    ob_start();
                    // If Beaver Builder plugin is enabled, load any cached styles associated with the inserted page.
                    // Note: Temporarily set the global $post->ID to the inserted page ID,
                    // since Beaver Builder relies on it to load the appropriate styles.
                    if (class_exists('FLBuilder')) {
                        // If we're not in The Loop (i.e., global $post isn't assigned),
                        // temporarily populate it with the post to be inserted so we can
                        // retrieve Beaver Builder styles for that post. Reset $post to null
                        // after we're done.
                        if (is_null($post)) {
                            $old_post_id = null;
                            $post = $inserted_page;
                        } else {
                            $old_post_id = $post->ID;
                            $post->ID = $inserted_page->ID;
                        }
                        FLBuilder::enqueue_layout_styles_scripts($inserted_page->ID);
                        if (is_null($old_post_id)) {
                            $post = null;
                        } else {
                            $post->ID = $old_post_id;
                        }
                    }
                    // Show either the title, link, content, everything, or everything via a custom template
                    // Note: if the sharing_display filter exists, it means Jetpack is installed and Sharing is enabled;
                    // This plugin conflicts with Sharing, because Sharing assumes the_content and the_excerpt filters
                    // are only getting called once. The fix here is to disable processing of filters on the_content in
                    // the inserted page. @see https://codex.wordpress.org/Function_Reference/the_content#Alternative_Usage
                    switch ($attributes['display']) {
                        case "title":
                            the_post();
                            $title_tag = $attributes['inline'] ? 'span' : 'h1';
                            echo "<{$title_tag} class='insert-page-title'>";
                            the_title();
                            echo "</{$title_tag}>";
                            break;
                        case "link":
                            the_post();
                            ?>
<a href="<?php 
                            the_permalink();
                            ?>
"><?php 
                            the_title();
                            ?>
</a><?php 
                            break;
                        case "excerpt":
                            the_post();
                            ?>
<h1><a href="<?php 
                            the_permalink();
                            ?>
"><?php 
                            the_title();
                            ?>
</a></h1><?php 
                            if ($attributes['should_apply_the_content_filter']) {
                                the_excerpt();
                            } else {
                                echo get_the_excerpt();
                            }
                            break;
                        case "excerpt-only":
                            the_post();
                            if ($attributes['should_apply_the_content_filter']) {
                                the_excerpt();
                            } else {
                                echo get_the_excerpt();
                            }
                            break;
                        case "content":
                            the_post();
                            if ($attributes['should_apply_the_content_filter']) {
                                the_content();
                            } else {
                                echo get_the_content();
                            }
                            break;
                        case "all":
                            the_post();
                            $title_tag = $attributes['inline'] ? 'span' : 'h1';
                            echo "<{$title_tag} class='insert-page-title'>";
                            the_title();
                            echo "</{$title_tag}>";
                            if ($attributes['should_apply_the_content_filter']) {
                                the_content();
                            } else {
                                echo get_the_content();
                            }
                            the_meta();
                            break;
                        default:
                            // display is either invalid, or contains a template file to use
                            $template = locate_template($attributes['display']);
                            if (strlen($template) > 0) {
                                include $template;
                                // execute the template code
                            } else {
                                // Couldn't find template, so fall back to printing a link to the page.
                                the_post();
                                ?>
<a href="<?php 
                                the_permalink();
                                ?>
"><?php 
                                the_title();
                                ?>
</a><?php 
                            }
                            break;
                    }
                    // Save output buffer contents.
                    $content = ob_get_clean();
                } else {
                    /**
                     * Filter the html that should be displayed if an inserted page was not found.
                     *
                     * @param string $content html to be displayed. Defaults to an empty string.
                     */
                    $content = apply_filters('insert_pages_not_found_message', $content);
                }
                wp_reset_query();
            }
            /**
             * Filter the markup generated for the inserted page.
             *
             * @param string $content The post content of the inserted page.
             * @param object $inserted_page The post object returned from querying the inserted page.
             * @param array $attributes Extra parameters modifying the inserted page.
             *   page: Page ID or slug of page to be inserted.
             *   display: Content to display from inserted page.
             *   class: Extra classes to add to inserted page wrapper element.
             *   inline: Boolean indicating wrapper element should be a span.
             *   should_apply_nesting_check: Whether to disable nested inserted pages.
             *   should_apply_the_content_filter: Whether to apply the_content filter to post contents and excerpts.
             *   wrapper_tag: Tag to use for the wrapper element (e.g., div, span).
             */
            $content = apply_filters('insert_pages_wrap_content', $content, $inserted_page, $attributes);
            return $content;
        }
Exemplo n.º 6
0
/**
 * Add post meta data defined in $_POST superglobal for post with given ID.
 *
 * @since 1.2.0
 *
 * @param int $post_ID
 * @return int|bool
 */
function add_meta($post_ID)
{
    $post_ID = (int) $post_ID;
    $metakeyselect = isset($_POST['metakeyselect']) ? wp_unslash(trim($_POST['metakeyselect'])) : '';
    $metakeyinput = isset($_POST['metakeyinput']) ? wp_unslash(trim($_POST['metakeyinput'])) : '';
    $metavalue = isset($_POST['metavalue']) ? $_POST['metavalue'] : '';
    if (is_string($metavalue)) {
        $metavalue = trim($metavalue);
    }
    if (('0' === $metavalue || !empty($metavalue)) && ('#NONE#' != $metakeyselect && !empty($metakeyselect) || !empty($metakeyinput))) {
        /*
         * We have a key/value pair. If both the select and the input
         * for the key have data, the input takes precedence.
         */
        if ('#NONE#' != $metakeyselect) {
            $metakey = $metakeyselect;
        }
        if ($metakeyinput) {
            $metakey = $metakeyinput;
        }
        // default
        if (is_protected_meta($metakey, 'post') || !current_user_can('add_post_meta', $post_ID, $metakey)) {
            return false;
        }
        $metakey = wp_slash($metakey);
        return add_post_meta($post_ID, $metakey, $metavalue);
    }
    return false;
}
/**
 * Map meta capabilities to primitive capabilities.
 *
 * This does not actually compare whether the user ID has the actual capability,
 * just what the capability or capabilities are. Meta capability list value can
 * be 'delete_user', 'edit_user', 'remove_user', 'promote_user', 'delete_post',
 * 'delete_page', 'edit_post', 'edit_page', 'read_post', or 'read_page'.
 *
 * @since 2.0.0
 *
 * @param string $cap Capability name.
 * @param int $user_id User ID.
 * @return array Actual capabilities for meta capability.
 */
function map_meta_cap($cap, $user_id)
{
    $args = array_slice(func_get_args(), 2);
    $caps = array();
    switch ($cap) {
        case 'remove_user':
            $caps[] = 'remove_users';
            break;
        case 'promote_user':
            $caps[] = 'promote_users';
            break;
        case 'edit_user':
        case 'edit_users':
            // Allow user to edit itself
            if ('edit_user' == $cap && isset($args[0]) && $user_id == $args[0]) {
                break;
            }
            // In multisite the user must have manage_network_users caps. If editing a super admin, the user must be a super admin.
            if (is_multisite() && (!is_super_admin($user_id) && 'edit_user' === $cap && is_super_admin($args[0]) || !user_can($user_id, 'manage_network_users'))) {
                $caps[] = 'do_not_allow';
            } else {
                $caps[] = 'edit_users';
                // edit_user maps to edit_users.
            }
            break;
        case 'delete_post':
        case 'delete_page':
            $post = get_post($args[0]);
            if ('revision' == $post->post_type) {
                $post = get_post($post->post_parent);
            }
            $post_type = get_post_type_object($post->post_type);
            if (!$post_type) {
                /* translators: 1: post type, 2: capability name */
                _doing_it_wrong(__FUNCTION__, sprintf(__('The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.'), $post->post_type, $cap), '4.4.0');
                $caps[] = 'edit_others_posts';
                break;
            }
            if (!$post_type->map_meta_cap) {
                $caps[] = $post_type->cap->{$cap};
                // Prior to 3.1 we would re-call map_meta_cap here.
                if ('delete_post' == $cap) {
                    $cap = $post_type->cap->{$cap};
                }
                break;
            }
            // If the post author is set and the user is the author...
            if ($post->post_author && $user_id == $post->post_author) {
                // If the post is published...
                if ('publish' == $post->post_status) {
                    $caps[] = $post_type->cap->delete_published_posts;
                } elseif ('trash' == $post->post_status) {
                    if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true)) {
                        $caps[] = $post_type->cap->delete_published_posts;
                    }
                } else {
                    // If the post is draft...
                    $caps[] = $post_type->cap->delete_posts;
                }
            } else {
                // The user is trying to edit someone else's post.
                $caps[] = $post_type->cap->delete_others_posts;
                // The post is published, extra cap required.
                if ('publish' == $post->post_status) {
                    $caps[] = $post_type->cap->delete_published_posts;
                } elseif ('private' == $post->post_status) {
                    $caps[] = $post_type->cap->delete_private_posts;
                }
            }
            break;
            // edit_post breaks down to edit_posts, edit_published_posts, or
            // edit_others_posts
        // edit_post breaks down to edit_posts, edit_published_posts, or
        // edit_others_posts
        case 'edit_post':
        case 'edit_page':
            $post = get_post($args[0]);
            if (empty($post)) {
                $caps[] = 'do_not_allow';
                break;
            }
            if ('revision' == $post->post_type) {
                $post = get_post($post->post_parent);
            }
            $post_type = get_post_type_object($post->post_type);
            if (!$post_type) {
                /* translators: 1: post type, 2: capability name */
                _doing_it_wrong(__FUNCTION__, sprintf(__('The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.'), $post->post_type, $cap), '4.4.0');
                $caps[] = 'edit_others_posts';
                break;
            }
            if (!$post_type->map_meta_cap) {
                $caps[] = $post_type->cap->{$cap};
                // Prior to 3.1 we would re-call map_meta_cap here.
                if ('edit_post' == $cap) {
                    $cap = $post_type->cap->{$cap};
                }
                break;
            }
            // If the post author is set and the user is the author...
            if ($post->post_author && $user_id == $post->post_author) {
                // If the post is published...
                if ('publish' == $post->post_status) {
                    $caps[] = $post_type->cap->edit_published_posts;
                } elseif ('trash' == $post->post_status) {
                    if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true)) {
                        $caps[] = $post_type->cap->edit_published_posts;
                    }
                } else {
                    // If the post is draft...
                    $caps[] = $post_type->cap->edit_posts;
                }
            } else {
                // The user is trying to edit someone else's post.
                $caps[] = $post_type->cap->edit_others_posts;
                // The post is published, extra cap required.
                if ('publish' == $post->post_status) {
                    $caps[] = $post_type->cap->edit_published_posts;
                } elseif ('private' == $post->post_status) {
                    $caps[] = $post_type->cap->edit_private_posts;
                }
            }
            break;
        case 'read_post':
        case 'read_page':
            $post = get_post($args[0]);
            if ('revision' == $post->post_type) {
                $post = get_post($post->post_parent);
            }
            $post_type = get_post_type_object($post->post_type);
            if (!$post_type) {
                /* translators: 1: post type, 2: capability name */
                _doing_it_wrong(__FUNCTION__, sprintf(__('The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.'), $post->post_type, $cap), '4.4.0');
                $caps[] = 'edit_others_posts';
                break;
            }
            if (!$post_type->map_meta_cap) {
                $caps[] = $post_type->cap->{$cap};
                // Prior to 3.1 we would re-call map_meta_cap here.
                if ('read_post' == $cap) {
                    $cap = $post_type->cap->{$cap};
                }
                break;
            }
            $status_obj = get_post_status_object($post->post_status);
            if ($status_obj->public) {
                $caps[] = $post_type->cap->read;
                break;
            }
            if ($post->post_author && $user_id == $post->post_author) {
                $caps[] = $post_type->cap->read;
            } elseif ($status_obj->private) {
                $caps[] = $post_type->cap->read_private_posts;
            } else {
                $caps = map_meta_cap('edit_post', $user_id, $post->ID);
            }
            break;
        case 'publish_post':
            $post = get_post($args[0]);
            $post_type = get_post_type_object($post->post_type);
            if (!$post_type) {
                /* translators: 1: post type, 2: capability name */
                _doing_it_wrong(__FUNCTION__, sprintf(__('The post type %1$s is not registered, so it may not be reliable to check the capability "%2$s" against a post of that type.'), $post->post_type, $cap), '4.4.0');
                $caps[] = 'edit_others_posts';
                break;
            }
            $caps[] = $post_type->cap->publish_posts;
            break;
        case 'edit_post_meta':
        case 'delete_post_meta':
        case 'add_post_meta':
            $post = get_post($args[0]);
            $caps = map_meta_cap('edit_post', $user_id, $post->ID);
            $meta_key = isset($args[1]) ? $args[1] : false;
            if ($meta_key && has_filter("auth_post_meta_{$meta_key}")) {
                /**
                 * Filter whether the user is allowed to add post meta to a post.
                 *
                 * The dynamic portion of the hook name, `$meta_key`, refers to the
                 * meta key passed to {@see map_meta_cap()}.
                 *
                 * @since 3.3.0
                 *
                 * @param bool   $allowed  Whether the user can add the post meta. Default false.
                 * @param string $meta_key The meta key.
                 * @param int    $post_id  Post ID.
                 * @param int    $user_id  User ID.
                 * @param string $cap      Capability name.
                 * @param array  $caps     User capabilities.
                 */
                $allowed = apply_filters("auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps);
                if (!$allowed) {
                    $caps[] = $cap;
                }
            } elseif ($meta_key && is_protected_meta($meta_key, 'post')) {
                $caps[] = $cap;
            }
            break;
        case 'edit_comment':
            $comment = get_comment($args[0]);
            if (empty($comment)) {
                break;
            }
            $post = get_post($comment->comment_post_ID);
            /*
             * If the post doesn't exist, we have an orphaned comment.
             * Fall back to the edit_posts capability, instead.
             */
            if ($post) {
                $caps = map_meta_cap('edit_post', $user_id, $post->ID);
            } else {
                $caps = map_meta_cap('edit_posts', $user_id);
            }
            break;
        case 'unfiltered_upload':
            if (defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && (!is_multisite() || is_super_admin($user_id))) {
                $caps[] = $cap;
            } else {
                $caps[] = 'do_not_allow';
            }
            break;
        case 'unfiltered_html':
            // Disallow unfiltered_html for all users, even admins and super admins.
            if (defined('DISALLOW_UNFILTERED_HTML') && DISALLOW_UNFILTERED_HTML) {
                $caps[] = 'do_not_allow';
            } elseif (is_multisite() && !is_super_admin($user_id)) {
                $caps[] = 'do_not_allow';
            } else {
                $caps[] = $cap;
            }
            break;
        case 'edit_files':
        case 'edit_plugins':
        case 'edit_themes':
            // Disallow the file editors.
            if (defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) {
                $caps[] = 'do_not_allow';
            } elseif (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) {
                $caps[] = 'do_not_allow';
            } elseif (is_multisite() && !is_super_admin($user_id)) {
                $caps[] = 'do_not_allow';
            } else {
                $caps[] = $cap;
            }
            break;
        case 'update_plugins':
        case 'delete_plugins':
        case 'install_plugins':
        case 'upload_plugins':
        case 'update_themes':
        case 'delete_themes':
        case 'install_themes':
        case 'upload_themes':
        case 'update_core':
            // Disallow anything that creates, deletes, or updates core, plugin, or theme files.
            // Files in uploads are excepted.
            if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) {
                $caps[] = 'do_not_allow';
            } elseif (is_multisite() && !is_super_admin($user_id)) {
                $caps[] = 'do_not_allow';
            } elseif ('upload_themes' === $cap) {
                $caps[] = 'install_themes';
            } elseif ('upload_plugins' === $cap) {
                $caps[] = 'install_plugins';
            } else {
                $caps[] = $cap;
            }
            break;
        case 'activate_plugins':
            $caps[] = $cap;
            if (is_multisite()) {
                // update_, install_, and delete_ are handled above with is_super_admin().
                $menu_perms = get_site_option('menu_items', array());
                if (empty($menu_perms['plugins'])) {
                    $caps[] = 'manage_network_plugins';
                }
            }
            break;
        case 'delete_user':
        case 'delete_users':
            // If multisite only super admins can delete users.
            if (is_multisite() && !is_super_admin($user_id)) {
                $caps[] = 'do_not_allow';
            } else {
                $caps[] = 'delete_users';
            }
            // delete_user maps to delete_users.
            break;
        case 'create_users':
            if (!is_multisite()) {
                $caps[] = $cap;
            } elseif (is_super_admin($user_id) || get_site_option('add_new_users')) {
                $caps[] = $cap;
            } else {
                $caps[] = 'do_not_allow';
            }
            break;
        case 'manage_links':
            if (get_option('link_manager_enabled')) {
                $caps[] = $cap;
            } else {
                $caps[] = 'do_not_allow';
            }
            break;
        case 'customize':
            $caps[] = 'edit_theme_options';
            break;
        case 'delete_site':
            $caps[] = 'manage_options';
            break;
        default:
            // Handle meta capabilities for custom post types.
            $post_type_meta_caps = _post_type_meta_capabilities();
            if (isset($post_type_meta_caps[$cap])) {
                $args = array_merge(array($post_type_meta_caps[$cap], $user_id), $args);
                return call_user_func_array('map_meta_cap', $args);
            }
            // If no meta caps match, return the original cap.
            $caps[] = $cap;
    }
    /**
     * Filter a user's capabilities depending on specific context and/or privilege.
     *
     * @since 2.8.0
     *
     * @param array  $caps    Returns the user's actual capabilities.
     * @param string $cap     Capability name.
     * @param int    $user_id The user ID.
     * @param array  $args    Adds the context to the cap. Typically the object ID.
     */
    return apply_filters('map_meta_cap', $caps, $cap, $user_id, $args);
}
Exemplo n.º 8
0
/**
 * {@internal Missing Short Description}}
 *
 * @since 2.5.0
 *
 * @param unknown_type $entry
 * @param unknown_type $count
 * @return unknown
 */
function _list_meta_row($entry, &$count)
{
    static $update_nonce = false;
    if (is_protected_meta($entry['meta_key'], 'post')) {
        return;
    }
    if (!$update_nonce) {
        $update_nonce = wp_create_nonce('add-meta');
    }
    $r = '';
    ++$count;
    if ($count % 2) {
        $style = 'alternate';
    } else {
        $style = '';
    }
    if (is_serialized($entry['meta_value'])) {
        if (is_serialized_string($entry['meta_value'])) {
            // this is a serialized string, so we should display it
            $entry['meta_value'] = maybe_unserialize($entry['meta_value']);
        } else {
            // this is a serialized array/object so we should NOT display it
            --$count;
            return;
        }
    }
    $entry['meta_key'] = esc_attr($entry['meta_key']);
    $entry['meta_value'] = esc_textarea($entry['meta_value']);
    // using a <textarea />
    $entry['meta_id'] = (int) $entry['meta_id'];
    $delete_nonce = wp_create_nonce('delete-meta_' . $entry['meta_id']);
    $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='{$style}'>";
    $r .= "\n\t\t<td class='left'><label class='screen-reader-text' for='meta[{$entry['meta_id']}][key]'>" . __('Key') . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' />";
    $r .= "\n\t\t<div class='submit'>";
    $r .= get_submit_button(__('Delete'), "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce={$delete_nonce} deletemeta", "deletemeta[{$entry['meta_id']}]", false, array('tabindex' => '6'));
    $r .= "\n\t\t";
    $r .= get_submit_button(__('Update'), "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta={$update_nonce} updatemeta", 'updatemeta', false, array('tabindex' => '6'));
    $r .= "</div>";
    $r .= wp_nonce_field('change-meta', '_ajax_nonce', false, false);
    $r .= "</td>";
    $r .= "\n\t\t<td><label class='screen-reader-text' for='meta[{$entry['meta_id']}][value]'>" . __('Value') . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>";
    return $r;
}
 /**
  * paypal_ipn_for_wordpress_display_ipn_custome_fields helper function used for display raw dump in html format
  * @since    1.0.0
  * @access   public
  */
 public static function paypal_ipn_for_wordpress_display_ipn_custome_fields()
 {
     if ($keys = get_post_custom_keys()) {
         echo "<div class='wrap'>";
         echo "<table class='widefat'><thead>\n                        <tr>\n                            <th>" . __('IPN Field Name', 'paypal-ipn') . "</th>\n                            <th>" . __('IPN Field Value', 'paypal-ipn') . "</th>\n                        </tr>\n                    </thead>\n                    <tfoot>\n                        <tr>\n                            <th>" . __('IPN Field Name', 'paypal-ipn') . "</th>\n                            <th>" . __('IPN Field Value', 'paypal-ipn') . "</th>\n\n                        </tr>\n                    </tfoot>";
         foreach ((array) $keys as $key) {
             $keyt = trim($key);
             if (is_protected_meta($keyt, 'post')) {
                 continue;
             }
             $values = array_map('trim', get_post_custom_values($key));
             $value = implode($values, ', ');
             /**
              * Filter the HTML output of the li element in the post custom fields list.
              *
              * @since 1.0.0
              *
              * @param string $html  The HTML output for the li element.
              * @param string $key   Meta key.
              * @param string $value Meta value.
              */
             echo apply_filters('paypal_ipn_for_wordpress_the_meta_key', "<tr><th class='post-meta-key'>{$key}:</th> <td>{$value}</td></tr>", $key, $value);
         }
         echo "</table>";
         echo "</div>";
     }
 }
Exemplo n.º 10
0
     } else {
         // Update?
         $mid = (int) key($_POST['meta']);
         $key = stripslashes($_POST['meta'][$mid]['key']);
         $value = stripslashes($_POST['meta'][$mid]['value']);
         if ('' == trim($key)) {
             die(__('Please provide a custom field name.'));
         }
         if ('' == trim($value)) {
             die(__('Please provide a custom field value.'));
         }
         if (!($meta = get_metadata_by_mid('post', $mid))) {
             die('0');
         }
         // if meta doesn't exist
         if (is_protected_meta($meta->meta_key, 'post') || is_protected_meta($key, 'post') || !current_user_can('edit_post_meta', $meta->post_id, $meta->meta_key) || !current_user_can('edit_post_meta', $meta->post_id, $key)) {
             die('-1');
         }
         if ($meta->meta_value != $value || $meta->meta_key != $key) {
             if (!($u = update_metadata_by_mid('post', $mid, $value, $key))) {
                 die('0');
             }
             // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
         }
         $x = new WP_Ajax_Response(array('what' => 'meta', 'id' => $mid, 'old_id' => $mid, 'data' => _list_meta_row(array('meta_key' => $key, 'meta_value' => $value, 'meta_id' => $mid), $c), 'position' => 0, 'supplemental' => array('postid' => $meta->post_id)));
     }
     $x->send();
     break;
 case 'add-user':
     check_ajax_referer($action);
     if (!current_user_can('create_users')) {
 function __construct($post_id)
 {
     $cleaned_metas = array();
     if (!empty($post_id)) {
         $meta_values = get_post_meta($post_id);
         foreach ($meta_values as $key => $values) {
             if (!is_protected_meta($key, 'wpsc-product')) {
                 if (is_array($values)) {
                     foreach ($values as $value) {
                         $cleaned_metas[] = array('meta_key' => $key, 'meta_value' => $value);
                     }
                 }
             }
         }
     }
     $this->custom_meta = $cleaned_metas;
     $this->custom_meta_count = count($this->custom_meta);
 }
Exemplo n.º 12
0
 /**
  * Delete meta from a post
  *
  * @param int $id Post ID
  * @param int $mid Metadata ID
  * @return array|WP_Error Message on success, WP_Error otherwise
  */
 public function delete_meta($id, $mid)
 {
     $id = (int) $id;
     if (empty($id)) {
         return new WP_Error('json_post_invalid_id', __('Invalid post ID.'), array('status' => 404));
     }
     $post = get_post($id, ARRAY_A);
     if (empty($post['ID'])) {
         return new WP_Error('json_post_invalid_id', __('Invalid post ID.'), array('status' => 404));
     }
     if (!$this->check_edit_permission($post)) {
         return new WP_Error('json_cannot_edit', __('Sorry, you cannot edit this post'), array('status' => 403));
     }
     $current = get_metadata_by_mid('post', $mid);
     if (empty($current)) {
         return new WP_Error('json_meta_invalid_id', __('Invalid meta ID.'), array('status' => 404));
     }
     if (absint($current->post_id) !== $id) {
         return new WP_Error('json_meta_post_mismatch', __('Meta does not belong to this post'), array('status' => 400));
     }
     // for now let's not allow updating of arrays, objects or serialized values.
     if (!$this->is_valid_meta_data($current->meta_value)) {
         return new WP_Error('json_post_invalid_action', __('Invalid existing meta data for action.'), array('status' => 400));
     }
     if (is_protected_meta($current->meta_key)) {
         return new WP_Error('json_meta_protected', sprintf(__('%s is marked as a protected field.'), $current->meta_key), array('status' => 403));
     }
     if (!delete_metadata_by_mid('post', $mid)) {
         return new WP_Error('json_meta_could_not_add', __('Could not delete post meta.'), array('status' => 500));
     }
     return array('message' => __('Deleted meta'));
 }
Exemplo n.º 13
0
 public function copy_post_metas($from, $to, $lang, $sync = false)
 {
     // copy or synchronize terms
     // FIXME quite a lot of query in foreach
     foreach ($this->get_taxonomies_to_copy($sync) as $tax) {
         $terms = get_the_terms($from, $tax);
         // translated taxonomy
         if ($this->model->is_translated_taxonomy($tax)) {
             $newterms = array();
             if (is_array($terms)) {
                 foreach ($terms as $term) {
                     if ($term_id = $this->model->get_translation('term', $term->term_id, $lang)) {
                         $newterms[] = (int) $term_id;
                     }
                     // cast is important otherwise we get 'numeric' tags
                 }
             }
             // for some reasons, the user may have untranslated terms in the translation. don't forget them.
             if ($sync) {
                 $tr_terms = get_the_terms($to, $tax);
                 if (is_array($tr_terms)) {
                     foreach ($tr_terms as $term) {
                         if (!$this->model->get_translation('term', $term->term_id, $this->model->get_post_language($from))) {
                             $newterms[] = (int) $term->term_id;
                         }
                     }
                 }
             }
             if (!empty($newterms) || $sync) {
                 wp_set_object_terms($to, $newterms, $tax);
             }
             // replace terms in translation
         } else {
             wp_set_object_terms($to, is_array($terms) ? array_map('intval', wp_list_pluck($terms, 'term_id')) : null, $tax);
         }
     }
     // copy or synchronize post metas and allow plugins to do the same
     $metas = get_post_custom($from);
     // get public meta keys (including from translated post in case we just deleted a custom field)
     if (!$sync || in_array('post_meta', $this->options['sync'])) {
         foreach ($keys = array_unique(array_merge(array_keys($metas), array_keys(get_post_custom($to)))) as $k => $meta_key) {
             if (is_protected_meta($meta_key)) {
                 unset($keys[$k]);
             }
         }
     }
     // add page template and featured image
     foreach (array('_wp_page_template', '_thumbnail_id') as $meta) {
         if (!$sync || in_array($meta, $this->options['sync'])) {
             $keys[] = $meta;
         }
     }
     $keys = array_unique(apply_filters('pll_copy_post_metas', empty($keys) ? array() : $keys, $sync));
     // and now copy / synchronize
     foreach ($keys as $key) {
         delete_post_meta($to, $key);
         // the synchronization process of multiple values custom fields is easier if we delete all metas first
         if (isset($metas[$key])) {
             foreach ($metas[$key] as $value) {
                 // important: always maybe_unserialize value coming from get_post_custom. See codex.
                 // thanks to goncalveshugo http://wordpress.org/support/topic/plugin-polylang-pll_copy_post_meta
                 $value = maybe_unserialize($value);
                 // special case for featured images which can be translated
                 add_post_meta($to, $key, $key == '_thumbnail_id' && ($tr_value = $this->model->get_translation('post', $value, $lang)) ? $tr_value : $value);
             }
         }
     }
 }
Exemplo n.º 14
0
 /**
  * Prepare post meta to send to ES
  *
  * @param object $post
  *
  * @since 0.1.0
  * @return array
  */
 public function prepare_meta($post)
 {
     $meta = (array) get_post_meta($post->ID);
     if (empty($meta)) {
         return array();
     }
     $prepared_meta = array();
     foreach ($meta as $key => $value) {
         if (!is_protected_meta($key)) {
             $prepared_meta[$key] = maybe_unserialize($value);
         }
     }
     return $prepared_meta;
 }
/**
 * Map meta capabilities to primitive capabilities.
 *
 * This does not actually compare whether the user ID has the actual capability,
 * just what the capability or capabilities are. Meta capability list value can
 * be 'delete_user', 'edit_user', 'remove_user', 'promote_user', 'delete_post',
 * 'delete_page', 'edit_post', 'edit_page', 'read_post', or 'read_page'.
 *
 * @since 2.0.0
 *
 * @param string $cap Capability name.
 * @param int $user_id User ID.
 * @return array Actual capabilities for meta capability.
 */
function map_meta_cap($cap, $user_id)
{
    $args = array_slice(func_get_args(), 2);
    $caps = array();
    switch ($cap) {
        case 'remove_user':
            $caps[] = 'remove_users';
            break;
        case 'promote_user':
            $caps[] = 'promote_users';
            break;
        case 'edit_user':
            // Allow user to edit itself
            if (isset($args[0]) && $user_id == $args[0]) {
                break;
            }
            // Fall through
        // Fall through
        case 'edit_users':
            // If multisite these caps are allowed only for super admins.
            if (is_multisite() && !is_super_admin($user_id)) {
                $caps[] = 'do_not_allow';
            } else {
                $caps[] = 'edit_users';
            }
            // Explicit due to primitive fall through
            break;
        case 'delete_post':
        case 'delete_page':
            $author_data = get_userdata($user_id);
            $post = get_post($args[0]);
            if ('revision' == $post->post_type) {
                $post = get_post($post->post_parent);
            }
            $post_type = get_post_type_object($post->post_type);
            if (!$post_type->map_meta_cap) {
                $caps[] = $post_type->cap->{$cap};
                // Prior to 3.1 we would re-call map_meta_cap here.
                if ('delete_post' == $cap) {
                    $cap = $post_type->cap->{$cap};
                }
                break;
            }
            if ('' != $post->post_author) {
                $post_author_data = get_userdata($post->post_author);
            } else {
                // No author set yet, so default to current user for cap checks.
                $post_author_data = $author_data;
            }
            // If the user is the author...
            if (is_object($post_author_data) && $user_id == $post_author_data->ID) {
                // If the post is published...
                if ('publish' == $post->post_status) {
                    $caps[] = $post_type->cap->delete_published_posts;
                } elseif ('trash' == $post->post_status) {
                    if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true)) {
                        $caps[] = $post_type->cap->delete_published_posts;
                    }
                } else {
                    // If the post is draft...
                    $caps[] = $post_type->cap->delete_posts;
                }
            } else {
                // The user is trying to edit someone else's post.
                $caps[] = $post_type->cap->delete_others_posts;
                // The post is published, extra cap required.
                if ('publish' == $post->post_status) {
                    $caps[] = $post_type->cap->delete_published_posts;
                } elseif ('private' == $post->post_status) {
                    $caps[] = $post_type->cap->delete_private_posts;
                }
            }
            break;
            // edit_post breaks down to edit_posts, edit_published_posts, or
            // edit_others_posts
        // edit_post breaks down to edit_posts, edit_published_posts, or
        // edit_others_posts
        case 'edit_post':
        case 'edit_page':
            $author_data = get_userdata($user_id);
            $post = get_post($args[0]);
            if ('revision' == $post->post_type) {
                $post = get_post($post->post_parent);
            }
            $post_type = get_post_type_object($post->post_type);
            if (!$post_type->map_meta_cap) {
                $caps[] = $post_type->cap->{$cap};
                // Prior to 3.1 we would re-call map_meta_cap here.
                if ('edit_post' == $cap) {
                    $cap = $post_type->cap->{$cap};
                }
                break;
            }
            if ('' != $post->post_author) {
                $post_author_data = get_userdata($post->post_author);
            } else {
                // No author set yet, so default to current user for cap checks.
                $post_author_data = $author_data;
            }
            //echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br />";
            // If the user is the author...
            if (is_object($post_author_data) && $user_id == $post_author_data->ID) {
                // If the post is published...
                if ('publish' == $post->post_status) {
                    $caps[] = $post_type->cap->edit_published_posts;
                } elseif ('trash' == $post->post_status) {
                    if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true)) {
                        $caps[] = $post_type->cap->edit_published_posts;
                    }
                } else {
                    // If the post is draft...
                    $caps[] = $post_type->cap->edit_posts;
                }
            } else {
                // The user is trying to edit someone else's post.
                $caps[] = $post_type->cap->edit_others_posts;
                // The post is published, extra cap required.
                if ('publish' == $post->post_status) {
                    $caps[] = $post_type->cap->edit_published_posts;
                } elseif ('private' == $post->post_status) {
                    $caps[] = $post_type->cap->edit_private_posts;
                }
            }
            break;
        case 'read_post':
        case 'read_page':
            $author_data = get_userdata($user_id);
            $post = get_post($args[0]);
            if ('revision' == $post->post_type) {
                $post = get_post($post->post_parent);
            }
            $post_type = get_post_type_object($post->post_type);
            if (!$post_type->map_meta_cap) {
                $caps[] = $post_type->cap->{$cap};
                // Prior to 3.1 we would re-call map_meta_cap here.
                if ('read_post' == $cap) {
                    $cap = $post_type->cap->{$cap};
                }
                break;
            }
            $status_obj = get_post_status_object($post->post_status);
            if ($status_obj->public) {
                $caps[] = $post_type->cap->read;
                break;
            }
            if ('' != $post->post_author) {
                $post_author_data = get_userdata($post->post_author);
            } else {
                // No author set yet, so default to current user for cap checks.
                $post_author_data = $author_data;
            }
            if (is_object($post_author_data) && $user_id == $post_author_data->ID) {
                $caps[] = $post_type->cap->read;
            } elseif ($status_obj->private) {
                $caps[] = $post_type->cap->read_private_posts;
            } else {
                $caps = map_meta_cap('edit_post', $user_id, $post->ID);
            }
            break;
        case 'edit_post_meta':
        case 'delete_post_meta':
        case 'add_post_meta':
            $post = get_post($args[0]);
            $post_type_object = get_post_type_object($post->post_type);
            $caps = map_meta_cap($post_type_object->cap->edit_post, $user_id, $post->ID);
            $meta_key = isset($args[1]) ? $args[1] : false;
            if ($meta_key && has_filter("auth_post_meta_{$meta_key}")) {
                $allowed = apply_filters("auth_post_meta_{$meta_key}", false, $meta_key, $post->ID, $user_id, $cap, $caps);
                if (!$allowed) {
                    $caps[] = $cap;
                }
            } elseif ($meta_key && is_protected_meta($meta_key, 'post')) {
                $caps[] = $cap;
            }
            break;
        case 'edit_comment':
            $comment = get_comment($args[0]);
            $post = get_post($comment->comment_post_ID);
            $post_type_object = get_post_type_object($post->post_type);
            $caps = map_meta_cap($post_type_object->cap->edit_post, $user_id, $post->ID);
            break;
        case 'unfiltered_upload':
            if (defined('ALLOW_UNFILTERED_UPLOADS') && ALLOW_UNFILTERED_UPLOADS && (!is_multisite() || is_super_admin($user_id))) {
                $caps[] = $cap;
            } else {
                $caps[] = 'do_not_allow';
            }
            break;
        case 'edit_files':
        case 'edit_plugins':
        case 'edit_themes':
            if (defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT) {
                $caps[] = 'do_not_allow';
                break;
            }
            // Fall through if not DISALLOW_FILE_EDIT.
        // Fall through if not DISALLOW_FILE_EDIT.
        case 'update_plugins':
        case 'delete_plugins':
        case 'install_plugins':
        case 'update_themes':
        case 'delete_themes':
        case 'install_themes':
        case 'update_core':
            // Disallow anything that creates, deletes, or edits core, plugin, or theme files.
            // Files in uploads are excepted.
            if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) {
                $caps[] = 'do_not_allow';
                break;
            }
            // Fall through if not DISALLOW_FILE_MODS.
        // Fall through if not DISALLOW_FILE_MODS.
        case 'unfiltered_html':
            // Disallow unfiltered_html for all users, even admins and super admins.
            if (defined('DISALLOW_UNFILTERED_HTML') && DISALLOW_UNFILTERED_HTML) {
                $caps[] = 'do_not_allow';
                break;
            }
            // Fall through if not DISALLOW_UNFILTERED_HTML
        // Fall through if not DISALLOW_UNFILTERED_HTML
        case 'delete_user':
        case 'delete_users':
            // If multisite these caps are allowed only for super admins.
            if (is_multisite() && !is_super_admin($user_id)) {
                $caps[] = 'do_not_allow';
            } else {
                if ('delete_user' == $cap) {
                    $cap = 'delete_users';
                }
                $caps[] = $cap;
            }
            break;
        case 'create_users':
            if (!is_multisite()) {
                $caps[] = $cap;
            } elseif (is_super_admin() || get_site_option('add_new_users')) {
                $caps[] = $cap;
            } else {
                $caps[] = 'do_not_allow';
            }
            break;
        default:
            // Handle meta capabilities for custom post types.
            $post_type_meta_caps = _post_type_meta_capabilities();
            if (isset($post_type_meta_caps[$cap])) {
                $args = array_merge(array($post_type_meta_caps[$cap], $user_id), $args);
                return call_user_func_array('map_meta_cap', $args);
            }
            // If no meta caps match, return the original cap.
            $caps[] = $cap;
    }
    return apply_filters('map_meta_cap', $caps, $cap, $user_id, $args);
}
 /**
  * Delete meta from an object.
  *
  * @param WP_REST_Request $request
  * @return WP_REST_Response|WP_Error Message on success, WP_Error otherwise
  */
 public function delete_item($request)
 {
     $parent_id = (int) $request['parent_id'];
     $mid = (int) $request['id'];
     $force = isset($request['force']) ? (bool) $request['force'] : false;
     // We don't support trashing for this type, error out
     if (!$force) {
         return new WP_Error('rest_trash_not_supported', __('Meta does not support trashing.'), array('status' => 501));
     }
     $parent_column = $this->get_parent_column();
     $current = get_metadata_by_mid($this->parent_type, $mid);
     if (empty($current)) {
         return new WP_Error('rest_meta_invalid_id', __('Invalid meta id.'), array('status' => 404));
     }
     if (absint($current->{$parent_column}) !== (int) $parent_id) {
         return new WP_Error('rest_meta_' . $this->parent_type . '_mismatch', __('Meta does not belong to this object'), array('status' => 400));
     }
     // for now let's not allow updating of arrays, objects or serialized values.
     if (!$this->is_valid_meta_data($current->meta_value)) {
         $code = $this->parent_type === 'post' ? 'rest_post_invalid_action' : 'rest_meta_invalid_action';
         return new WP_Error($code, __('Invalid existing meta data for action.'), array('status' => 400));
     }
     if (is_protected_meta($current->meta_key)) {
         return new WP_Error('rest_meta_protected', sprintf(__('%s is marked as a protected field.'), $current->meta_key), array('status' => 403));
     }
     if (!delete_metadata_by_mid($this->parent_type, $mid)) {
         return new WP_Error('rest_meta_could_not_delete', __('Could not delete meta.'), array('status' => 500));
     }
     /**
      * Fires after a meta value is deleted via the REST API.
      *
      * @param WP_REST_Request $request The request sent to the API.
      */
     do_action('rest_delete_meta', $request);
     return rest_ensure_response(array('message' => __('Deleted meta')));
 }
 function callback($path = '', $blog_id = 0)
 {
     $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
     if (is_wp_error($blog_id)) {
         return $blog_id;
     }
     $args = $this->query_args();
     $is_eligible_for_page_handle = true;
     if ($args['number'] < 1) {
         $args['number'] = 20;
     } elseif (100 < $args['number']) {
         return new WP_Error('invalid_number', 'The NUMBER parameter must be less than or equal to 100.', 400);
     }
     if (isset($args['type']) && !$this->is_post_type_allowed($args['type'])) {
         return new WP_Error('unknown_post_type', 'Unknown post type', 404);
     }
     // Normalize post_type
     if (isset($args['type']) && 'any' == $args['type']) {
         if (version_compare($this->api->version, '1.1', '<')) {
             $args['type'] = array('post', 'page');
         } else {
             // 1.1+
             $args['type'] = $this->_get_whitelisted_post_types();
         }
     }
     // determine statuses
     $status = $args['status'];
     $status = $status ? explode(',', $status) : array('publish');
     if (is_user_logged_in()) {
         $statuses_whitelist = array('publish', 'pending', 'draft', 'future', 'private', 'trash', 'any');
         $status = array_intersect($status, $statuses_whitelist);
     } else {
         // logged-out users can see only published posts
         $statuses_whitelist = array('publish', 'any');
         $status = array_intersect($status, $statuses_whitelist);
         if (empty($status)) {
             // requested only protected statuses? nothing for you here
             return array('found' => 0, 'posts' => array());
         }
         // clear it (AKA published only) because "any" includes protected
         $status = array();
     }
     if (isset($args['type']) && !in_array($args['type'], array('post', 'page', 'revision', 'any')) && defined('IS_WPCOM') && IS_WPCOM) {
         $this->load_theme_functions();
     }
     // let's be explicit about defaulting to 'post'
     $args['type'] = isset($args['type']) ? $args['type'] : 'post';
     // make sure the user can read or edit the requested post type(s)
     if (is_array($args['type'])) {
         $allowed_types = array();
         foreach ($args['type'] as $post_type) {
             if ($this->current_user_can_access_post_type($post_type, $args['context'])) {
                 $allowed_types[] = $post_type;
             }
         }
         if (empty($allowed_types)) {
             return array('found' => 0, 'posts' => array());
         }
         $args['type'] = $allowed_types;
     } else {
         if (!$this->current_user_can_access_post_type($args['type'], $args['context'])) {
             return array('found' => 0, 'posts' => array());
         }
     }
     $query = array('posts_per_page' => $args['number'], 'order' => $args['order'], 'orderby' => $args['order_by'], 'post_type' => $args['type'], 'post_status' => $status, 'post_parent' => isset($args['parent_id']) ? $args['parent_id'] : null, 'author' => isset($args['author']) && 0 < $args['author'] ? $args['author'] : null, 's' => isset($args['search']) ? $args['search'] : null, 'fields' => 'ids');
     if (!is_user_logged_in()) {
         $query['has_password'] = false;
     }
     if (isset($args['meta_key'])) {
         $show = false;
         if ($this->is_metadata_public($args['meta_key'])) {
             $show = true;
         }
         if (current_user_can('edit_post_meta', $query['post_type'], $args['meta_key'])) {
             $show = true;
         }
         if (is_protected_meta($args['meta_key'], 'post') && !$show) {
             return new WP_Error('invalid_meta_key', 'Invalid meta key', 404);
         }
         $meta = array('key' => $args['meta_key']);
         if (isset($args['meta_value'])) {
             $meta['value'] = $args['meta_value'];
         }
         $query['meta_query'] = array($meta);
     }
     if ($args['sticky'] === 'include') {
         $query['ignore_sticky_posts'] = 1;
     } else {
         if ($args['sticky'] === 'exclude') {
             $sticky = get_option('sticky_posts');
             if (is_array($sticky)) {
                 $query['post__not_in'] = $sticky;
             }
         } else {
             if ($args['sticky'] === 'require') {
                 $sticky = get_option('sticky_posts');
                 if (is_array($sticky) && !empty($sticky)) {
                     $query['post__in'] = $sticky;
                 } else {
                     // no sticky posts exist
                     return array('found' => 0, 'posts' => array());
                 }
             }
         }
     }
     if (isset($args['exclude'])) {
         $excluded_ids = (array) $args['exclude'];
         $query['post__not_in'] = isset($query['post__not_in']) ? array_merge($query['post__not_in'], $excluded_ids) : $excluded_ids;
     }
     if (isset($args['exclude_tree']) && is_post_type_hierarchical($args['type'])) {
         // get_page_children is a misnomer; it supports all hierarchical post types
         $page_args = array('child_of' => $args['exclude_tree'], 'post_type' => $args['type'], 'post_status' => 'publish,draft,pending,private,future,trash');
         $post_descendants = get_pages($page_args);
         $exclude_tree = array($args['exclude_tree']);
         foreach ($post_descendants as $child) {
             $exclude_tree[] = $child->ID;
         }
         $query['post__not_in'] = isset($query['post__not_in']) ? array_merge($query['post__not_in'], $exclude_tree) : $exclude_tree;
     }
     if (isset($args['category'])) {
         $category = get_term_by('slug', $args['category'], 'category');
         if ($category === false) {
             $query['category_name'] = $args['category'];
         } else {
             $query['cat'] = $category->term_id;
         }
     }
     if (isset($args['tag'])) {
         $query['tag'] = $args['tag'];
     }
     if (isset($args['page'])) {
         if ($args['page'] < 1) {
             $args['page'] = 1;
         }
         $query['paged'] = $args['page'];
         if ($query['paged'] !== 1) {
             $is_eligible_for_page_handle = false;
         }
     } else {
         if ($args['offset'] < 0) {
             $args['offset'] = 0;
         }
         $query['offset'] = $args['offset'];
         if ($query['offset'] !== 0) {
             $is_eligible_for_page_handle = false;
         }
     }
     if (isset($args['before'])) {
         $this->date_range['before'] = $args['before'];
     }
     if (isset($args['after'])) {
         $this->date_range['after'] = $args['after'];
     }
     if (isset($args['modified_before_gmt'])) {
         $this->modified_range['before'] = $args['modified_before_gmt'];
     }
     if (isset($args['modified_after_gmt'])) {
         $this->modified_range['after'] = $args['modified_after_gmt'];
     }
     if ($this->date_range) {
         add_filter('posts_where', array($this, 'handle_date_range'));
     }
     if ($this->modified_range) {
         add_filter('posts_where', array($this, 'handle_modified_range'));
     }
     if (isset($args['page_handle'])) {
         $page_handle = wp_parse_args($args['page_handle']);
         if (isset($page_handle['value']) && isset($page_handle['id'])) {
             // we have a valid looking page handle
             $this->page_handle = $page_handle;
             add_filter('posts_where', array($this, 'handle_where_for_page_handle'));
         }
     }
     /**
      * 'column' necessary for the me/posts endpoint (which extends sites/$site/posts).
      * Would need to be added to the sites/$site/posts definition if we ever want to
      * use it there.
      */
     $column_whitelist = array('post_modified_gmt');
     if (isset($args['column']) && in_array($args['column'], $column_whitelist)) {
         $query['column'] = $args['column'];
     }
     $this->performed_query = $query;
     add_filter('posts_orderby', array($this, 'handle_orderby_for_page_handle'));
     $wp_query = new WP_Query($query);
     remove_filter('posts_orderby', array($this, 'handle_orderby_for_page_handle'));
     if ($this->date_range) {
         remove_filter('posts_where', array($this, 'handle_date_range'));
         $this->date_range = array();
     }
     if ($this->modified_range) {
         remove_filter('posts_where', array($this, 'handle_modified_range'));
         $this->modified_range = array();
     }
     if ($this->page_handle) {
         remove_filter('posts_where', array($this, 'handle_where_for_page_handle'));
     }
     $return = array();
     $excluded_count = 0;
     foreach (array_keys($this->response_format) as $key) {
         switch ($key) {
             case 'found':
                 $return[$key] = (int) $wp_query->found_posts;
                 break;
             case 'posts':
                 $posts = array();
                 foreach ($wp_query->posts as $post_ID) {
                     $the_post = $this->get_post_by('ID', $post_ID, $args['context']);
                     if ($the_post && !is_wp_error($the_post)) {
                         $posts[] = $the_post;
                     } else {
                         $excluded_count++;
                     }
                 }
                 if ($posts) {
                     /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
                     do_action('wpcom_json_api_objects', 'posts', count($posts));
                 }
                 $return[$key] = $posts;
                 break;
             case 'meta':
                 if (!is_array($args['type'])) {
                     $return[$key] = (object) array('links' => (object) array('counts' => (string) $this->get_site_link($blog_id, 'post-counts/' . $args['type'])));
                 }
                 if ($is_eligible_for_page_handle && $return['posts']) {
                     $last_post = end($return['posts']);
                     reset($return['posts']);
                     if ($return['found'] > count($return['posts']) && $last_post) {
                         if (!isset($return[$key])) {
                             $return[$key] = (object) array();
                         }
                         $return[$key]->next_page = $this->build_page_handle($last_post, $query);
                     }
                 }
                 break;
         }
     }
     $return['found'] -= $excluded_count;
     return $return;
 }
Exemplo n.º 18
0
 function callback($path = '', $blog_id = 0)
 {
     $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
     if (is_wp_error($blog_id)) {
         return $blog_id;
     }
     $args = $this->query_args();
     if ($args['number'] < 1) {
         $args['number'] = 20;
     } elseif (100 < $args['number']) {
         return new WP_Error('invalid_number', 'The NUMBER parameter must be less than or equal to 100.', 400);
     }
     if (!$this->is_post_type_allowed($args['type'])) {
         return new WP_Error('unknown_post_type', 'Unknown post type', 404);
     }
     $query = array('posts_per_page' => $args['number'], 'order' => $args['order'], 'orderby' => $args['order_by'], 'post_type' => 'any' == $args['type'] ? array('post', 'page') : $args['type'], 'post_status' => $args['status'], 'author' => isset($args['author']) && 0 < $args['author'] ? $args['author'] : null, 's' => isset($args['search']) ? $args['search'] : null);
     if (isset($args['meta_key'])) {
         $show = false;
         if ($this->is_metadata_public($args['meta_key'])) {
             $show = true;
         }
         if (current_user_can('edit_post_meta', $query['post_type'], $args['meta_key'])) {
             $show = true;
         }
         if (is_protected_meta($args['meta_key'], 'post') && !$show) {
             return new WP_Error('invalid_meta_key', 'Invalid meta key', 404);
         }
         $meta = array('key' => $args['meta_key']);
         if (isset($args['meta_value'])) {
             $meta['value'] = $args['meta_value'];
         }
         $query['meta_query'] = array($meta);
     }
     if (isset($args['sticky']) && ($sticky = get_option('sticky_posts')) && is_array($sticky)) {
         if ($args['sticky']) {
             $query['post__in'] = $sticky;
         } else {
             $query['post__not_in'] = $sticky;
             $query['ignore_sticky_posts'] = 1;
         }
     }
     if (isset($args['category'])) {
         $category = get_term_by('slug', $args['category'], 'category');
         if ($category === false) {
             $query['category_name'] = $args['category'];
         } else {
             $query['cat'] = $category->term_id;
         }
     }
     if (isset($args['tag'])) {
         $query['tag'] = $args['tag'];
     }
     if (isset($args['page'])) {
         if ($args['page'] < 1) {
             $args['page'] = 1;
         }
         $query['paged'] = $args['page'];
     } else {
         if ($args['offset'] < 0) {
             $args['offset'] = 0;
         }
         $query['offset'] = $args['offset'];
     }
     if (isset($args['before'])) {
         $this->date_range['before'] = $args['before'];
     }
     if (isset($args['after'])) {
         $this->date_range['after'] = $args['after'];
     }
     if ($this->date_range) {
         add_filter('posts_where', array($this, 'handle_date_range'));
     }
     $wp_query = new WP_Query($query);
     if ($this->date_range) {
         remove_filter('posts_where', array($this, 'handle_date_range'));
         $this->date_range = array();
     }
     $return = array();
     foreach (array_keys($this->response_format) as $key) {
         switch ($key) {
             case 'found':
                 $return[$key] = (int) $wp_query->found_posts;
                 break;
             case 'posts':
                 $posts = array();
                 foreach ($wp_query->posts as $post) {
                     $the_post = $this->get_post_by('ID', $post->ID, $args['context']);
                     if ($the_post && !is_wp_error($the_post)) {
                         $posts[] = $the_post;
                     }
                 }
                 if ($posts) {
                     do_action('wpcom_json_api_objects', 'posts', count($posts));
                 }
                 $return[$key] = $posts;
                 break;
         }
     }
     return $return;
 }
/**
 * Prints the form in the Custom Fields meta box.
 *
 * @since 1.2.0
 *
 * @param WP_Post $post Optional. The post being edited.
 */
function meta_form($post = null)
{
    global $wpdb;
    $post = get_post($post);
    /**
     * Filter the number of custom fields to retrieve for the drop-down
     * in the Custom Fields meta box.
     *
     * @since 2.1.0
     *
     * @param int $limit Number of custom fields to retrieve. Default 30.
     */
    $limit = (int) apply_filters('postmeta_form_limit', 30);
    $keys = $wpdb->get_col("\n\t\tSELECT meta_key\n\t\tFROM {$wpdb->postmeta}\n\t\tGROUP BY meta_key\n\t\tHAVING meta_key NOT LIKE '\\_%'\n\t\tORDER BY meta_key\n\t\tLIMIT {$limit}");
    if ($keys) {
        natcasesort($keys);
        $meta_key_input_id = 'metakeyselect';
    } else {
        $meta_key_input_id = 'metakeyinput';
    }
    ?>
<p><strong><?php 
    _e('Add New Custom Field:');
    ?>
</strong></p>
<table id="newmeta">
<thead>
<tr>
<th class="left"><label for="<?php 
    echo $meta_key_input_id;
    ?>
"><?php 
    _ex('Name', 'meta name');
    ?>
</label></th>
<th><label for="metavalue"><?php 
    _e('Value');
    ?>
</label></th>
</tr>
</thead>

<tbody>
<tr>
<td id="newmetaleft" class="left">
<?php 
    if ($keys) {
        ?>
<select id="metakeyselect" name="metakeyselect">
<option value="#NONE#"><?php 
        _e('&mdash; Select &mdash;');
        ?>
</option>
<?php 
        foreach ($keys as $key) {
            if (is_protected_meta($key, 'post') || !current_user_can('add_post_meta', $post->ID, $key)) {
                continue;
            }
            echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
        }
        ?>
</select>
<input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" />
<a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
<span id="enternew"><?php 
        _e('Enter new');
        ?>
</span>
<span id="cancelnew" class="hidden"><?php 
        _e('Cancel');
        ?>
</span></a>
<?php 
    } else {
        ?>
<input type="text" id="metakeyinput" name="metakeyinput" value="" />
<?php 
    }
    ?>
</td>
<td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td>
</tr>

<tr><td colspan="2">
<div class="submit">
<?php 
    submit_button(__('Add Custom Field'), 'secondary', 'addmeta', false, array('id' => 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta'));
    ?>
</div>
<?php 
    wp_nonce_field('add-meta', '_ajax_nonce-add-meta', false);
    ?>
</td></tr>
</tbody>
</table>
<?php 
}
Exemplo n.º 20
0
    function form($instance)
    {
        $defaults = array('title' => __('Posts', 'pis'), 'title_link' => '', 'intro' => '', 'post_type' => 'post', 'posts_id' => '', 'author' => '', 'cat' => '', 'tag' => '', 'post_format' => '', 'number' => get_option('posts_per_page'), 'orderby' => 'date', 'order' => 'DESC', 'exclude_current_post' => false, 'post_not_in' => '', 'cat_not_in' => '', 'tag_not_in' => '', 'offset_number' => '', 'post_status' => 'publish', 'post_meta_key' => '', 'post_meta_val' => '', 'ignore_sticky' => false, 'display_title' => true, 'link_on_title' => true, 'arrow' => false, 'display_image' => false, 'image_size' => 'thumbnail', 'image_align' => 'no_change', 'image_before_title' => false, 'side_image_margin' => NULL, 'bottom_image_margin' => NULL, 'excerpt' => 'excerpt', 'exc_length' => 20, 'the_more' => __('Read more&hellip;', 'pis'), 'exc_arrow' => false, 'utility_after_title' => false, 'display_author' => false, 'author_text' => __('By', 'pis'), 'linkify_author' => false, 'display_date' => false, 'date_text' => __('Published on', 'pis'), 'linkify_date' => false, 'comments' => false, 'comments_text' => __('Comments:', 'pis'), 'utility_sep' => '|', 'categories' => false, 'categ_text' => __('Category:', 'pis'), 'categ_sep' => ',', 'tags' => false, 'tags_text' => __('Tags:', 'pis'), 'hashtag' => '#', 'tag_sep' => '', 'custom_field' => false, 'custom_field_txt' => '', 'meta' => '', 'custom_field_key' => false, 'custom_field_sep' => ':', 'archive_link' => false, 'link_to' => 'category', 'archive_text' => __('Display all posts', 'pis'), 'nopost_text' => __('No posts yet.', 'pis'), 'container_class' => '', 'list_element' => 'ul', 'remove_bullets' => false, 'margin_unit' => 'px', 'intro_margin' => NULL, 'title_margin' => NULL, 'excerpt_margin' => NULL, 'utility_margin' => NULL, 'categories_margin' => NULL, 'tags_margin' => NULL, 'custom_field_margin' => NULL, 'archive_margin' => NULL, 'noposts_margin' => NULL, 'custom_styles' => '', 'cached' => false, 'cache_time' => '');
        $instance = wp_parse_args((array) $instance, $defaults);
        $ignore_sticky = (bool) $instance['ignore_sticky'];
        $exclude_current_post = (bool) $instance['exclude_current_post'];
        $display_title = (bool) $instance['display_title'];
        $link_on_title = (bool) $instance['link_on_title'];
        $display_image = (bool) $instance['display_image'];
        $image_before_title = (bool) $instance['image_before_title'];
        $arrow = (bool) $instance['arrow'];
        $exc_arrow = (bool) $instance['exc_arrow'];
        $utility_after_title = (bool) $instance['utility_after_title'];
        $display_author = (bool) $instance['display_author'];
        $linkify_author = (bool) $instance['linkify_author'];
        $display_date = (bool) $instance['display_date'];
        $linkify_date = (bool) $instance['linkify_date'];
        $comments = (bool) $instance['comments'];
        $categories = (bool) $instance['categories'];
        $tags = (bool) $instance['tags'];
        $custom_field = (bool) $instance['custom_field'];
        $custom_field_key = (bool) $instance['custom_field_key'];
        $archive_link = (bool) $instance['archive_link'];
        $remove_bullets = (bool) $instance['remove_bullets'];
        $cached = (bool) $instance['cached'];
        ?>

		<style>
			.pis-gray-title {
				background-color: #ddd; padding: 3px 5px;
			}
			.pis-column {
				float: left; width: 31%; margin-right: 2%;
			}
			.pis-column-last {
				float: left; width: 31%;
			}
			.pis-alert {
				color: #777;
				font-weight: bold;
			}
		</style>

		<div class="pis-column">

			<h4 class="pis-gray-title"><?php 
        _e('The title of the widget', 'pis');
        ?>
</h4>

			<?php 
        pis_form_input_text(__('Title', 'pis'), $this->get_field_id('title'), $this->get_field_name('title'), esc_attr($instance['title']));
        ?>

			<?php 
        pis_form_input_text(__('Link the title of the widget to this URL', 'pis'), $this->get_field_id('title_link'), $this->get_field_name('title_link'), esc_url($instance['title_link']));
        ?>

			<?php 
        pis_form_textarea(__('Place this text after the title', 'pis'), $this->get_field_id('intro'), $this->get_field_name('intro'), $instance['intro'], $style = 'resize: vertical; width: 100%; height: 80px;', $comment = sprintf(__('Allowed HTML: %s. Other tags will be stripped.', 'pis'), '<code>a</code>, <code>strong</code>, <code>em</code>'));
        ?>

			<hr />

			<h4 class="pis-gray-title"><?php 
        _e('Posts retrieving', 'pis');
        ?>
</h4>

			<?php 
        // ================= Post types
        $args = array('public' => true);
        $post_types = (array) get_post_types($args, 'objects', 'and');
        $options = array(array('value' => 'any', 'desc' => __('Any', 'pis')));
        foreach ($post_types as $post_type) {
            $options[] = array('value' => $post_type->name, 'desc' => $post_type->labels->singular_name);
        }
        pis_form_select(__('Post type', 'pis'), $this->get_field_id('post_type'), $this->get_field_name('post_type'), $options, $instance['post_type']);
        ?>

			<?php 
        // ================= Posts ID
        pis_form_input_text(__('Get these posts exactly', 'pis'), $this->get_field_id('posts_id'), $this->get_field_name('posts_id'), esc_attr($instance['posts_id']), sprintf(__('Insert IDs separated by commas. To easily find the IDs, install %1$sthis plugin%2$s.', 'pis'), '<a href="http://wordpress.org/plugins/reveal-ids-for-wp-admin-25/" target="_blank">', '</a>'));
        ?>

			<?php 
        // ================= Author
        $options = array(array('value' => 'NULL', 'desc' => __('Any', 'pis')));
        $authors = (array) get_users('who=authors');
        // If set to 'authors', only authors (user level greater than 0) will be returned.
        foreach ($authors as $author) {
            $options[] = array('value' => $author->user_nicename, 'desc' => $author->display_name);
        }
        pis_form_select(__('Get posts by this author', 'pis'), $this->get_field_id('author'), $this->get_field_name('author'), $options, $instance['author']);
        ?>


			<?php 
        // ================= Category
        pis_form_input_text(__('Get posts with these categories', 'pis'), $this->get_field_id('cat'), $this->get_field_name('cat'), esc_attr($instance['cat']), sprintf(__('Insert slugs separated by commas. To display posts that have all of the categories, use %1$s (a plus) between terms, for example:%2$s%3$s.', 'pis'), '<code>+</code>', '<br />', '<code>staff+news+our-works</code>'));
        ?>

			<?php 
        // ================= Tag
        pis_form_input_text(__('Get posts with these tags', 'pis'), $this->get_field_id('tag'), $this->get_field_name('tag'), esc_attr($instance['tag']), sprintf(__('Insert slugs separated by commas. To display posts that have all of the tags, use %1$s (a plus) between terms, for example:%2$s%3$s.', 'pis'), '<code>+</code>', '<br />', '<code>staff+news+our-works</code>'));
        ?>

			<?php 
        // ================= Post format
        $options = array(array('value' => '', 'desc' => __('Any', 'pis')));
        $post_formats = get_terms('post_format');
        foreach ($post_formats as $post_format) {
            $options[] = array('value' => $post_format->slug, 'desc' => $post_format->name);
        }
        pis_form_select(__('Get posts with this post format', 'pis'), $this->get_field_id('post_format'), $this->get_field_name('post_format'), $options, $instance['post_format']);
        ?>

			<?php 
        // ================= Posts quantity
        pis_form_input_text(__('Display this number of posts', 'pis'), $this->get_field_id('number'), $this->get_field_name('number'), esc_attr($instance['number']), sprintf(__('The value %s shows all the posts.', 'pis'), '<code>-1</code>'));
        ?>

			<?php 
        // ================= Post order by
        $options = array('none' => array('value' => 'none', 'desc' => __('None', 'pis')), 'id' => array('value' => 'id', 'desc' => __('ID', 'pis')), 'author' => array('value' => 'author', 'desc' => __('Author', 'pis')), 'title' => array('value' => 'title', 'desc' => __('Title', 'pis')), 'name' => array('value' => 'name', 'desc' => __('Name (post slug)', 'pis')), 'date' => array('value' => 'date', 'desc' => __('Date', 'pis')), 'modified' => array('value' => 'modified', 'desc' => __('Modified', 'pis')), 'parent' => array('value' => 'parent', 'desc' => __('Parent', 'pis')), 'rand' => array('value' => 'rand', 'desc' => __('Random', 'pis')), 'comment_count' => array('value' => 'comment_count', 'desc' => __('Comment count', 'pis')), 'menu_order' => array('value' => 'menu_order', 'desc' => __('Menu order', 'pis')), 'meta_value' => array('value' => 'meta_value', 'desc' => __('Meta value', 'pis')), 'meta_value_num' => array('value' => 'meta_value_num', 'desc' => __('Meta value number', 'pis')), 'post__in' => array('value' => 'post__in', 'desc' => __('Preserve ID order', 'pis')));
        pis_form_select(__('Order posts by', 'pis'), $this->get_field_id('orderby'), $this->get_field_name('orderby'), $options, $instance['orderby']);
        ?>

			<?php 
        // ================= Post order
        $options = array('asc' => array('value' => 'ASC', 'desc' => __('Ascending', 'pis')), 'desc' => array('value' => 'DESC', 'desc' => __('Descending', 'pis')));
        pis_form_select(__('The order will be', 'pis'), $this->get_field_id('order'), $this->get_field_name('order'), $options, $instance['order']);
        ?>

			<?php 
        // ================= Number of posts to skip
        pis_form_input_text(__('Skip this number of posts', 'pis'), $this->get_field_id('offset_number'), $this->get_field_name('offset_number'), esc_attr($instance['offset_number']));
        ?>

			<?php 
        // ================= Post status
        $options = array();
        $statuses = get_post_stati('', 'objects');
        foreach ($statuses as $status) {
            $options[] = array('value' => $status->name, 'desc' => $status->label);
        }
        pis_form_select(__('Get posts with this post status', 'pis'), $this->get_field_id('post_status'), $this->get_field_name('post_status'), $options, $instance['post_status']);
        ?>

			<?php 
        // ================= Post meta key
        pis_form_input_text(__('Get post with this meta key', 'pis'), $this->get_field_id('post_meta_key'), $this->get_field_name('post_meta_key'), esc_attr($instance['post_meta_key']));
        ?>

			<?php 
        // ================= Post meta value
        pis_form_input_text(__('Get post with this meta value', 'pis'), $this->get_field_id('post_meta_val'), $this->get_field_name('post_meta_val'), esc_attr($instance['post_meta_val']));
        ?>

			<?php 
        // ================= Ignore sticky post
        pis_form_checkbox(__('Ignore sticky posts status', 'pis'), $this->get_field_id('ignore_sticky'), $this->get_field_name('ignore_sticky'), checked($ignore_sticky, true, false), __('Sticky posts are automatically ignored if you set up an author or a taxonomy in this widget.', 'pis'));
        ?>

			<hr />

			<h4 class="pis-gray-title"><?php 
        _e('Posts exclusion', 'pis');
        ?>
</h4>

			<?php 
        // ================= Ignore sticky post
        pis_form_checkbox(__('Automatically exclude the current post in single post or the current page in single page', 'pis'), $this->get_field_id('exclude_current_post'), $this->get_field_name('exclude_current_post'), checked($exclude_current_post, true, false));
        ?>

			<?php 
        // ================= Exclude posts that have these ids.
        pis_form_input_text(__('Exclude posts with these IDs', 'pis'), $this->get_field_id('post_not_in'), $this->get_field_name('post_not_in'), esc_attr($instance['post_not_in']), sprintf(__('Insert IDs separated by commas. To easily find the IDs, install %1$sthis plugin%2$s.', 'pis'), '<a href="http://wordpress.org/plugins/reveal-ids-for-wp-admin-25/" target="_blank">', '</a>'));
        ?>

			<?php 
        // ================= Exclude posts from categories
        if (is_array($instance['cat_not_in'])) {
            $var = implode(',', $instance['cat_not_in']);
        } else {
            $var = $instance['cat_not_in'];
        }
        pis_form_input_text(__('Exclude posts from these categories', 'pis'), $this->get_field_id('cat_not_in'), $this->get_field_name('cat_not_in'), esc_attr($var), __('Insert IDs separated by commas.', 'pis'));
        ?>

			<?php 
        // ================= Exclude posts from tags
        if (is_array($instance['tag_not_in'])) {
            $var = implode(',', $instance['tag_not_in']);
        } else {
            $var = $instance['tag_not_in'];
        }
        pis_form_input_text(__('Exclude posts from these tags', 'pis'), $this->get_field_id('tag_not_in'), $this->get_field_name('tag_not_in'), esc_attr($var), __('Insert IDs separated by commas.', 'pis'));
        ?>

		</div>

		<div class="pis-column">

			<h4 class="pis-gray-title"><?php 
        _e('The title of the post', 'pis');
        ?>
</h4>

			<?php 
        // ================= Title of the post
        pis_form_checkbox(__('Display the title of the post', 'pis'), $this->get_field_id('display_title'), $this->get_field_name('display_title'), checked($display_title, true, false));
        ?>

			<?php 
        // ================= Link to the title
        pis_form_checkbox(__('Link the title to the post', 'pis'), $this->get_field_id('link_on_title'), $this->get_field_name('link_on_title'), checked($link_on_title, true, false));
        ?>

			<?php 
        // ================= Arrow after the title
        pis_form_checkbox(__('Show an arrow after the title', 'pis'), $this->get_field_id('arrow'), $this->get_field_name('arrow'), checked($arrow, true, false));
        ?>

			<hr />

			<h4 class="pis-gray-title"><?php 
        _e('The featured image of the post', 'pis');
        ?>
</h4>

			<?php 
        if (!current_theme_supports('post-thumbnails')) {
            ?>
				<p class="pis-alert"><?php 
            _e('Your theme does not support the Post Thumbnail feature. No image will be displayed.', 'pis');
            ?>
</p>
			<?php 
        }
        ?>

			<?php 
        // ================= Featured image
        pis_form_checkbox(__('Display the featured image of the post', 'pis'), $this->get_field_id('display_image'), $this->get_field_name('display_image'), checked($display_image, true, false));
        ?>

			<?php 
        // ================= Image sizes
        $options = array();
        $sizes = (array) get_intermediate_image_sizes();
        foreach ($sizes as $size) {
            $options[] = array('value' => $size, 'desc' => $size);
        }
        pis_form_select(__('The size of the thumbnail will be', 'pis'), $this->get_field_id('image_size'), $this->get_field_name('image_size'), $options, $instance['image_size']);
        ?>

			<?php 
        // ================= Image align
        $options = array('nochange' => array('value' => 'nochange', 'desc' => __('Do not change', 'pis')), 'left' => array('value' => 'left', 'desc' => __('Left', 'pis')), 'right' => array('value' => 'right', 'desc' => __('Right', 'pis')), 'center' => array('value' => 'center', 'desc' => __('Center', 'pis')));
        pis_form_select(__('Align the image to', 'pis'), $this->get_field_id('image_align'), $this->get_field_name('image_align'), $options, $instance['image_align']);
        ?>

			<p>
				<em>
					<?php 
        printf(__('Note that in order to use image sizes different from the WordPress standards, add them to your %3$sfunctions.php%4$s file. See the %1$sCodex%2$s for further information.', 'pis'), '<a href="http://codex.wordpress.org/Function_Reference/add_image_size" target="_blank">', '</a>', '<code>', '</code>');
        ?>
					<?php 
        printf(__('You can also use %1$sa plugin%2$s that could help you in doing it.', 'pis'), '<a href="http://wordpress.org/plugins/simple-image-sizes/" target="_blank">', '</a>');
        ?>
				</em>
			</p>

			<?php 
        // ================= Positioning image bfore title
        pis_form_checkbox(__('Display the image before the title of the post', 'pis'), $this->get_field_id('image_before_title'), $this->get_field_name('image_before_title'), checked($image_before_title, true, false));
        ?>

			<hr />

			<h4 class="pis-gray-title"><?php 
        _e('The text of the post', 'pis');
        ?>
</h4>

			<?php 
        // ================= Type of text
        $options = array('full_content' => array('value' => 'full_content', 'desc' => __('The full content', 'pis')), 'rich_content' => array('value' => 'rich_content', 'desc' => __('The rich content', 'pis')), 'content' => array('value' => 'content', 'desc' => __('The simple text', 'pis')), 'more_excerpt' => array('value' => 'more_excerpt', 'desc' => __('The excerpt up to "more" tag', 'pis')), 'excerpt' => array('value' => 'excerpt', 'desc' => __('The excerpt', 'pis')), 'none' => array('value' => 'none', 'desc' => __('Do not show any text', 'pis')));
        pis_form_select(__('Display this type of text', 'pis'), $this->get_field_id('excerpt'), $this->get_field_name('excerpt'), $options, $instance['excerpt']);
        ?>

			<?php 
        // ================= Excerpt length
        pis_form_input_text(__('The WordPress generated excerpt length will be (in words)', 'pis'), $this->get_field_id('exc_length'), $this->get_field_name('exc_length'), esc_attr($instance['exc_length']));
        ?>

			<?php 
        // ================= More link text
        pis_form_input_text(__('Use this text for More link', 'pis'), $this->get_field_id('the_more'), $this->get_field_name('the_more'), esc_attr($instance['the_more']));
        ?>

			<?php 
        // ================= Arrow after the excerpt
        pis_form_checkbox(__('Display an arrow after the "Read more" link', 'pis'), $this->get_field_id('exc_arrow'), $this->get_field_name('exc_arrow'), checked($exc_arrow, true, false));
        ?>

			<hr />

			<h4 class="pis-gray-title"><?php 
        _e('Author, date and comments', 'pis');
        ?>
</h4>

			<?php 
        // ================= Author
        pis_form_checkbox(__('Display the author of the post', 'pis'), $this->get_field_id('display_author'), $this->get_field_name('display_author'), checked($display_author, true, false));
        ?>

			<?php 
        // ================= Author text
        pis_form_input_text(__('Use this text before author\'s name', 'pis'), $this->get_field_id('author_text'), $this->get_field_name('author_text'), esc_attr($instance['author_text']));
        ?>

			<?php 
        // ================= Author archive
        pis_form_checkbox(__('Link the author to his archive', 'pis'), $this->get_field_id('linkify_author'), $this->get_field_name('linkify_author'), checked($linkify_author, true, false));
        ?>

			<?php 
        // ================= Date
        pis_form_checkbox(__('Display the date of the post', 'pis'), $this->get_field_id('display_date'), $this->get_field_name('display_date'), checked($display_date, true, false));
        ?>

			<?php 
        // ================= Date text
        pis_form_input_text(__('Use this text before date', 'pis'), $this->get_field_id('date_text'), $this->get_field_name('date_text'), esc_attr($instance['date_text']));
        ?>

			<?php 
        // ================= Date link
        pis_form_checkbox(__('Link the date to the post', 'pis'), $this->get_field_id('linkify_date'), $this->get_field_name('linkify_date'), checked($linkify_date, true, false));
        ?>

			<?php 
        // ================= Number of comments
        pis_form_checkbox(__('Display the number of comments', 'pis'), $this->get_field_id('comments'), $this->get_field_name('comments'), checked($comments, true, false));
        ?>

			<?php 
        // ================= Comments text
        pis_form_input_text(__('Use this text before comments number', 'pis'), $this->get_field_id('comments_text'), $this->get_field_name('comments_text'), esc_attr($instance['comments_text']));
        ?>

			<?php 
        // ================= Utility separator
        pis_form_input_text(__('Use this separator between author, date and comments', 'pis'), $this->get_field_id('utility_sep'), $this->get_field_name('utility_sep'), esc_attr($instance['utility_sep']), __('A space will be added before and after the separator.', 'pis'));
        ?>

			<?php 
        // ================= Author
        pis_form_checkbox(__('Display this section after the title of the post', 'pis'), $this->get_field_id('utility_after_title'), $this->get_field_name('utility_after_title'), checked($utility_after_title, true, false));
        ?>

		</div>

		<div class="pis-column">

			<h4 class="pis-gray-title"><?php 
        _e('The categories of the post', 'pis');
        ?>
</h4>

			<?php 
        // ================= Post categories
        pis_form_checkbox(__('Display the categories of the post', 'pis'), $this->get_field_id('categories'), $this->get_field_name('categories'), checked($categories, true, false));
        ?>

			<?php 
        // ================= Categories text
        pis_form_input_text(__('Use this text before categories list', 'pis'), $this->get_field_id('categ_text'), $this->get_field_name('categ_text'), esc_attr($instance['categ_text']));
        ?>

			<?php 
        // ================= Categories separator
        pis_form_input_text(__('Use this separator between categories', 'pis'), $this->get_field_id('categ_sep'), $this->get_field_name('categ_sep'), esc_attr($instance['categ_sep']), __('A space will be added after the separator.', 'pis'));
        ?>

			<hr />

			<h4 class="pis-gray-title"><?php 
        _e('The tags of the post', 'pis');
        ?>
</h4>

			<?php 
        // ================= Post tags
        pis_form_checkbox(__('Show the tags of the post', 'pis'), $this->get_field_id('tags'), $this->get_field_name('tags'), checked($tags, true, false));
        ?>

			<?php 
        // ================= Tags text
        pis_form_input_text(__('Use this text before tags list', 'pis'), $this->get_field_id('tags_text'), $this->get_field_name('tags_text'), esc_attr($instance['tags_text']));
        ?>

			<?php 
        // ================= Hashtag
        pis_form_input_text(__('Use this hashtag', 'pis'), $this->get_field_id('hashtag'), $this->get_field_name('hashtag'), esc_attr($instance['hashtag']));
        ?>

			<?php 
        // ================= Tags separator
        pis_form_input_text(__('Use this separator between tags', 'pis'), $this->get_field_id('tag_sep'), $this->get_field_name('tag_sep'), esc_attr($instance['tag_sep']), __('A space will be added after the separator.', 'pis'));
        ?>

			<hr />

			<h4 class="pis-gray-title"><?php 
        _e('The custom field', 'pis');
        ?>
</h4>

			<?php 
        // ================= Display custom field
        pis_form_checkbox(__('Display the custom field of the post', 'pis'), $this->get_field_id('custom_field'), $this->get_field_name('custom_field'), checked($custom_field, true, false));
        ?>

			<?php 
        // ================= Custom fields text
        pis_form_input_text(__('Use this text before the custom field', 'pis'), $this->get_field_id('custom_field_txt'), $this->get_field_name('custom_field_txt'), esc_attr($instance['custom_field_txt']));
        ?>

			<?php 
        // ================= Which custom field
        $options = array();
        $metas = (array) pis_meta();
        foreach ($metas as $meta) {
            if (!is_protected_meta($meta, 'post')) {
                $options[] = array('value' => $meta, 'desc' => $meta);
            }
        }
        pis_form_select(__('Display this custom field', 'pis'), $this->get_field_id('meta'), $this->get_field_name('meta'), $options, $instance['meta']);
        ?>

			<?php 
        // ================= Custom field key
        pis_form_checkbox(__('Also display the key of the custom field', 'pis'), $this->get_field_id('custom_field_key'), $this->get_field_name('custom_field_key'), checked($custom_field_key, true, false));
        ?>

			<?php 
        // ================= Custom field separator
        pis_form_input_text(__('Use this separator between meta key and value', 'pis'), $this->get_field_id('custom_field_sep'), $this->get_field_name('custom_field_sep'), esc_attr($instance['custom_field_sep']));
        ?>

			<hr />

			<h4 class="pis-gray-title"><?php 
        _e('The link to the archive', 'pis');
        ?>
</h4>

			<?php 
        // ================= Taxonomy archive link
        pis_form_checkbox(__('Display the link to the taxonomy archive', 'pis'), $this->get_field_id('archive_link'), $this->get_field_name('archive_link'), checked($archive_link, true, false));
        ?>

			<?php 
        // ================= Which taxonomy
        $options = array('author' => array('value' => 'author', 'desc' => __('Author', 'pis')), 'category' => array('value' => 'category', 'desc' => __('Category', 'pis')), 'tag' => array('value' => 'tag', 'desc' => __('Tag', 'pis')));
        $custom_post_types = (array) get_post_types(array('_builtin' => false, 'exclude_from_search' => false), 'objects');
        foreach ($custom_post_types as $custom_post_type) {
            $options[] = array('value' => $custom_post_type->name, 'desc' => sprintf(__('Post type: %s', 'pis'), $custom_post_type->labels->singular_name));
        }
        if ($post_formats) {
            foreach ($post_formats as $post_format) {
                $options[] = array('value' => $post_format->slug, 'desc' => sprintf(__('Post format: %s', 'pis'), $post_format->name));
            }
        }
        pis_form_select(__('Link to the archive of', 'pis'), $this->get_field_id('link_to'), $this->get_field_name('link_to'), $options, $instance['link_to']);
        ?>


			<?php 
        // ================= Archive link text
        pis_form_input_text(__('Use this text for archive link', 'pis'), $this->get_field_id('archive_text'), $this->get_field_name('archive_text'), esc_attr($instance['archive_text']), __('Please, note that if you don\'t select any taxonomy, the link won\'t appear.', 'pis'));
        ?>

			<?php 
        // ================= No posts text
        pis_form_input_text(__('Use this text when there are no posts', 'pis'), $this->get_field_id('nopost_text'), $this->get_field_name('nopost_text'), esc_attr($instance['nopost_text']));
        ?>

			<hr />

			<h4 class="pis-gray-title"><?php 
        _e('Extras', 'pis');
        ?>
</h4>

			<?php 
        // ================= Container Class
        pis_form_input_text(__('Add a global container with this CSS class', 'pis'), $this->get_field_id('container_class'), $this->get_field_name('container_class'), esc_attr($instance['container_class']), sprintf(__('The plugin will add a new %s container with this class. You can enter only one class and the name could contain only letters, hyphens and underscores. The new container will enclose all the widget, from the title up to the last line.', 'pis'), '<code>div</code>'));
        ?>

			<?php 
        // ================= Type of HTML for list of posts
        $options = array('ul' => array('value' => 'ul', 'desc' => __('Unordered list', 'pis')), 'ol' => array('value' => 'ol', 'desc' => __('Ordered list', 'pis')));
        pis_form_select(__('Use this type of list for the posts', 'pis'), $this->get_field_id('list_element'), $this->get_field_name('list_element'), $options, $instance['list_element']);
        ?>

			<?php 
        // ================= Remove bullets and left space
        pis_form_checkbox(__('Try to remove the bullets and the extra left space from the list elements', 'pis'), $this->get_field_id('remove_bullets'), $this->get_field_name('remove_bullets'), checked($remove_bullets, true, false), sprintf(__('If the plugin doesn\'t remove the bullets and/or the extra left space, you have to %1$sedit your CSS file%2$s manually.', 'pis'), '<a href="' . admin_url('theme-editor.php') . '" target="_blank">', '</a>'));
        ?>

			<hr />

			<h4 class="pis-gray-title"><?php 
        _e('Cache', 'pis');
        ?>
</h4>

			<?php 
        // ================= Cache for the query
        pis_form_checkbox(__('Use a cache to serve the output', 'pis'), $this->get_field_id('cached'), $this->get_field_name('cached'), checked($cached, true, false), __('This option, if activated, will increase the performance.', 'pis'));
        ?>

			<?php 
        // ================= Cache duration
        pis_form_input_text(__('The cache will be used for (in seconds)', 'pis'), $this->get_field_id('cache_time'), $this->get_field_name('cache_time'), esc_attr($instance['cache_time']), sprintf(__('For example, %1$s for one hour of cache. To reset the cache, enter %2$s and save the widget.', 'pis'), '<code>3600</code>', '<code>0</code>'));
        ?>

		</div>

		<div class="clear"></div>

		<hr />

		<h4 class="pis-gray-title"><?php 
        _e('Elements margins', 'pis');
        ?>
</h4>

		<p><em><?php 
        _e('This section defines the margin for each line of the widget. Leave blank if you don\'t want to add any local style.', 'pis');
        ?>
</em></p>

		<?php 
        // ================= Margin unit
        $options = array('px' => array('value' => 'px', 'desc' => 'px'), '%' => array('value' => '%', 'desc' => '%'), 'em' => array('value' => 'em', 'desc' => 'em'), 'rem' => array('value' => 'rem', 'desc' => 'rem'));
        pis_form_select(__('Unit for margins', 'pis'), $this->get_field_id('margin_unit'), $this->get_field_name('margin_unit'), $options, $instance['margin_unit']);
        ?>

		<p><strong><?php 
        printf(__('Enter here only the value without any unit, e.g. enter %1$s if you want a space of 10px or enter %2$s if you don\'t want any space.', 'pis'), '<code>10</code>', '<code>0</code>');
        ?>
</strong></p>

		<?php 
        // ================= Margins
        ?>

		<div class="pis-column">
			<?php 
        pis_form_input_text(__('Introduction margin', 'pis'), $this->get_field_id('intro_margin'), $this->get_field_name('intro_margin'), esc_attr($instance['intro_margin']));
        ?>
			<?php 
        pis_form_input_text(__('Title margin', 'pis'), $this->get_field_id('title_margin'), $this->get_field_name('title_margin'), esc_attr($instance['title_margin']));
        ?>
			<?php 
        pis_form_input_text(__('Left/Right image margin', 'pis'), $this->get_field_id('side_image_margin'), $this->get_field_name('side_image_margin'), esc_attr($instance['side_image_margin']));
        ?>
			<?php 
        pis_form_input_text(__('Bottom image margin', 'pis'), $this->get_field_id('bottom_image_margin'), $this->get_field_name('bottom_image_margin'), esc_attr($instance['bottom_image_margin']));
        ?>
		</div>

		<div class="pis-column">
			<?php 
        pis_form_input_text(__('Excerpt margin', 'pis'), $this->get_field_id('excerpt_margin'), $this->get_field_name('excerpt_margin'), esc_attr($instance['excerpt_margin']));
        ?>
			<?php 
        pis_form_input_text(__('Utility margin', 'pis'), $this->get_field_id('utility_margin'), $this->get_field_name('utility_margin'), esc_attr($instance['utility_margin']));
        ?>
			<?php 
        pis_form_input_text(__('Categories margin', 'pis'), $this->get_field_id('categories_margin'), $this->get_field_name('categories_margin'), esc_attr($instance['categories_margin']));
        ?>
			<?php 
        pis_form_input_text(__('Tags margin', 'pis'), $this->get_field_id('tags_margin'), $this->get_field_name('tags_margin'), esc_attr($instance['tags_margin']));
        ?>
		</div>

		<div class="pis-column-last">
			<?php 
        pis_form_input_text(__('Custom field margin', 'pis'), $this->get_field_id('custom_field_margin'), $this->get_field_name('custom_field_margin'), esc_attr($instance['custom_field_margin']));
        ?>
			<?php 
        pis_form_input_text(__('Archive margin', 'pis'), $this->get_field_id('archive_margin'), $this->get_field_name('archive_margin'), esc_attr($instance['archive_margin']));
        ?>
			<?php 
        pis_form_input_text(__('No-posts margin', 'pis'), $this->get_field_id('noposts_margin'), $this->get_field_name('noposts_margin'), esc_attr($instance['noposts_margin']));
        ?>
		</div>

		<div class="clear"></div>

		<hr />

		<h4 class="pis-gray-title"><?php 
        _e('Custom styles', 'pis');
        ?>
</h4>

		<p><em><?php 
        printf(__('In this field you can add your own styles, for example: %s', 'pis'), '<code>.pis-excerpt { color: green; }</code>');
        ?>
</em></p>

		<?php 
        // ================= Custom styles
        pis_form_textarea(__('Custom styles', 'pis'), $this->get_field_id('custom_styles'), $this->get_field_name('custom_styles'), $instance['custom_styles'], $style = 'resize: vertical; width: 100%; height: 80px;');
        ?>

		<div class="clear"></div>

		<?php 
    }
Exemplo n.º 21
0
/**
 * Display custom fields form fields.
 *
 * @since 2.6.0
 *
 * @param object $post
 */
function post_custom_meta_box($post)
{
    ?>
<div id="postcustomstuff">
<div id="ajax-response"></div>
<?php 
    $metadata = has_meta($post->ID);
    foreach ($metadata as $key => $value) {
        if (is_protected_meta($metadata[$key]['meta_key'], 'post') || !current_user_can('edit_post_meta', $post->ID, $metadata[$key]['meta_key'])) {
            unset($metadata[$key]);
        }
    }
    list_meta($metadata);
    meta_form($post);
    ?>
</div>
<p><?php 
    _e('Custom fields can be used to add extra metadata to a post that you can <a href="https://codex.wordpress.org/Using_Custom_Fields" target="_blank">use in your theme</a>.');
    ?>
</p>
<?php 
}
Exemplo n.º 22
0
 function wpml_get_copied_fields_for_post_edit()
 {
     if (empty($_GET['from_post'])) {
         return array();
     }
     // don't know what WPML does but Polylang does copy all public meta keys by default
     foreach ($keys = array_unique(array_keys(get_post_custom((int) $_GET['from_post']))) as $k => $meta_key) {
         if (is_protected_meta($meta_key)) {
             unset($keys[$k]);
         }
     }
     // apply our filter and fill the expected output ( see /types/embedded/includes/fields-post.php )
     /** This filter is documented in modules/sync/admin-sync.php */
     $arr['fields'] = array_unique(apply_filters('pll_copy_post_metas', empty($keys) ? array() : $keys, false));
     $arr['original_post_id'] = (int) $_GET['from_post'];
     return $arr;
 }
 /**
  * Helper method to add/update meta data, with two restrictions:
  *
  * 1) Only non-protected meta (no leading underscore) can be set
  * 2) Meta values must be scalar (int, string, bool)
  *
  * @param int $order_id Order ID.
  * @param array $meta_data Meta data in array( 'meta_key' => 'meta_value' ) format.
  */
 protected function update_meta_data($order_id, $meta_data)
 {
     foreach ($meta_data as $meta_key => $meta_value) {
         if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) {
             update_post_meta($order_id, $meta_key, $meta_value);
         }
     }
 }
Exemplo n.º 24
0
/**
 * Registers a meta key.
 *
 * @since 3.3.0
 * @since 4.6.0 {@link https://make.wordpress.org/core/2016/07/08/enhancing-register_meta-in-4-6/ Modified
 *              to support an array of data to attach to registered meta keys}. Previous arguments for
 *              `$sanitize_callback` and `$auth_callback` have been folded into this array.
 *
 * @param string $object_type    Type of object this meta is registered to.
 * @param string $meta_key       Meta key to register.
 * @param array  $args {
 *     Data used to describe the meta key when registered.
 *
 *     @type string $object_subtype    A subtype; e.g. if the object type is "post", the post type.
 *     @type string $type              The type of data associated with this meta key.
 *     @type string $description       A description of the data attached to this meta key.
 *     @type bool   $single            Whether the meta key has one value per object, or an array of values per object.
 *     @type string $sanitize_callback A function or method to call when sanitizing `$meta_key` data.
 *     @type string $auth_callback     Optional. A function or method to call when performing edit_post_meta, add_post_meta, and delete_post_meta capability checks.
 *     @type bool   $show_in_rest      Whether data associated with this meta key can be considered public.
 * }
 * @param string|array $deprecated Deprecated. Use `$args` instead.
 *
 * @return bool|WP_error True if the meta key was successfully registered in the global array, WP_Error if not.
 *                       Registering a meta key with distinct sanitize and auth callbacks will fire those
 *                       callbacks, but will not add to the global registry as it requires a subtype.
 */
function register_meta($object_type, $meta_key, $args, $deprecated = null)
{
    global $wp_meta_keys;
    if (!is_array($wp_meta_keys)) {
        $wp_meta_keys = array();
    }
    if (!wp_object_type_exists($object_type)) {
        return new WP_Error('register_meta_failed', __('Meta can only be registered against a core object type.'));
    }
    $defaults = array('object_subtype' => '', 'type' => 'string', 'description' => '', 'single' => false, 'sanitize_callback' => null, 'auth_callback' => null, 'show_in_rest' => false);
    // There used to be individual args for sanitize and auth callbacks
    $has_old_sanitize_cb = false;
    $has_old_auth_cb = false;
    if (is_callable($args)) {
        $args = array('sanitize_callback' => $args);
        $has_old_sanitize_cb = true;
    } else {
        $args = (array) $args;
    }
    if (is_callable($deprecated)) {
        $args['auth_callback'] = $deprecated;
        $has_old_auth_cb = true;
    }
    $args = wp_parse_args($args, $defaults);
    /**
     * Filters the registration arguments when registering meta.
     *
     * @since 4.6.0
     *
     * @param array  $args        Array of meta registration arguments.
     * @param array  $defaults    Array of default arguments.
     * @param string $object_type Object type.
     * @param string $meta_key    Meta key.
     */
    $args = apply_filters('register_meta_args', $args, $defaults, $object_type, $meta_key);
    // Object subtype is required if using the args style of registration
    if (!$has_old_sanitize_cb && !$has_old_auth_cb && empty($args['object_subtype'])) {
        return new WP_Error('register_meta_failed', __('Meta must be registered against an object subtype.'));
    }
    // If `auth_callback` is not provided, fall back to `is_protected_meta()`.
    if (empty($args['auth_callback'])) {
        if (is_protected_meta($meta_key, $object_type)) {
            $args['auth_callback'] = '__return_false';
        } else {
            $args['auth_callback'] = '__return_true';
        }
    }
    $object_subtype = '';
    if (!empty($args['object_subtype'])) {
        $object_subtype = $args['object_subtype'];
    }
    // Back-compat: old sanitize and auth callbacks are applied to all of an object type.
    if ($has_old_sanitize_cb && is_callable($args['sanitize_callback'])) {
        add_filter("sanitize_{$object_type}_meta_{$meta_key}", $args['sanitize_callback'], 10, 4);
    }
    if ($has_old_auth_cb && is_callable($args['auth_callback'])) {
        add_filter("auth_{$object_type}_meta_{$meta_key}", $args['auth_callback'], 10, 6);
    }
    if (!$has_old_auth_cb && !$has_old_sanitize_cb) {
        if (is_callable($args['sanitize_callback'])) {
            add_filter("sanitize_{$object_type}_{$object_subtype}_meta_{$meta_key}", $args['sanitize_callback'], 10, 4);
        }
        if (is_callable($args['auth_callback'])) {
            add_filter("auth_{$object_type}_{$object_subtype}_meta_{$meta_key}", $args['auth_callback'], 10, 6);
        }
    }
    // Global registry only contains meta keys registered in the new way with a subtype.
    if (!empty($object_subtype)) {
        $wp_meta_keys[$object_type][$object_subtype][$meta_key] = $args;
        return true;
    }
    return new WP_Error('register_meta_failed', __('Sanitize and auth callbacks registered; meta key not registered.'));
}
Exemplo n.º 25
0
/**
 * Display list of post custom fields.
 *
 * @internal This will probably change at some point...
 * @since 1.2.0
 * @uses apply_filters() Calls 'the_meta_key' on list item HTML content, with key and value as separate parameters.
 */
function the_meta()
{
    if ($keys = get_post_custom_keys()) {
        echo "<ul class='post-meta'>\n";
        foreach ((array) $keys as $key) {
            $keyt = trim($key);
            if (is_protected_meta($keyt, 'post')) {
                continue;
            }
            $values = array_map('trim', get_post_custom_values($key));
            $value = implode($values, ', ');
            echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>{$key}:</span> {$value}</li>\n", $key, $value);
        }
        echo "</ul>\n";
    }
}
 public function add_meta($id, $data)
 {
     $id = (int) $id;
     if (empty($id)) {
         $this->set_status(404);
         return array('message' => __('Invalid post ID.'));
     }
     $post = get_post($id, ARRAY_A);
     if (empty($post['ID'])) {
         $this->set_status(404);
         return array('message' => __('Invalid post ID.'));
     }
     if (!array_key_exists('key', $data)) {
         $this->set_status(400);
         return array('message' => __('Missing meta key.'));
     }
     if (!array_key_exists('value', $data)) {
         $this->set_status(400);
         return array('message' => __('Missing meta value.'));
     }
     if (empty($data['key'])) {
         $this->set_status(400);
         return array('message' => __('Invalid meta key.'));
     }
     if (!$this->is_valid_meta_data($data['value'])) {
         // for now let's not allow updating of arrays, objects or serialized values.
         $this->set_status(400);
         return array('message' => __('Invalid provided meta data for action.'));
     }
     if (is_protected_meta($data['key'])) {
         $this->set_status(403);
         return array('message' => __('Forbidden Error.'));
     }
     $meta_key = wp_slash($data['key']);
     $value = wp_slash($data['value']);
     $result = add_post_meta($id, $meta_key, $value);
     if (!$result) {
         $this->set_status(400);
         return array('message' => __('Could not add post meta.'));
     }
     $response = json_ensure_response($this->get_meta($id, $result));
     if (is_wp_error($response)) {
         return $response;
     }
     $response->set_status(201);
     $response->header('Location', json_url('/posts/' . $id . '/meta/' . $result));
     return $response;
 }
Exemplo n.º 27
0
/**
 * Prints the form in the Custom Fields meta box.
 *
 * @since 1.2.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param WP_Post $post Optional. The post being edited.
 */
function meta_form($post = null)
{
    global $wpdb;
    $post = get_post($post);
    /**
     * Filters values for the meta key dropdown in the Custom Fields meta box.
     *
     * Returning a non-null value will effectively short-circuit and avoid a
     * potentially expensive query against postmeta.
     *
     * @since 4.4.0
     *
     * @param array|null $keys Pre-defined meta keys to be used in place of a postmeta query. Default null.
     * @param WP_Post    $post The current post object.
     */
    $keys = apply_filters('postmeta_form_keys', null, $post);
    if (null === $keys) {
        /**
         * Filters the number of custom fields to retrieve for the drop-down
         * in the Custom Fields meta box.
         *
         * @since 2.1.0
         *
         * @param int $limit Number of custom fields to retrieve. Default 30.
         */
        $limit = apply_filters('postmeta_form_limit', 30);
        $sql = "SELECT DISTINCT meta_key\n\t\t\tFROM {$wpdb->postmeta}\n\t\t\tWHERE meta_key NOT BETWEEN '_' AND '_z'\n\t\t\tHAVING meta_key NOT LIKE %s\n\t\t\tORDER BY meta_key\n\t\t\tLIMIT %d";
        $keys = $wpdb->get_col($wpdb->prepare($sql, $wpdb->esc_like('_') . '%', $limit));
    }
    if ($keys) {
        natcasesort($keys);
        $meta_key_input_id = 'metakeyselect';
    } else {
        $meta_key_input_id = 'metakeyinput';
    }
    ?>
<p><strong><?php 
    _e('Add New Custom Field:');
    ?>
</strong></p>
<table id="newmeta">
<thead>
<tr>
<th class="left"><label for="<?php 
    echo $meta_key_input_id;
    ?>
"><?php 
    _ex('Name', 'meta name');
    ?>
</label></th>
<th><label for="metavalue"><?php 
    _e('Value');
    ?>
</label></th>
</tr>
</thead>

<tbody>
<tr>
<td id="newmetaleft" class="left">
<?php 
    if ($keys) {
        ?>
<select id="metakeyselect" name="metakeyselect">
<option value="#NONE#"><?php 
        _e('&mdash; Select &mdash;');
        ?>
</option>
<?php 
        foreach ($keys as $key) {
            if (is_protected_meta($key, 'post') || !current_user_can('add_post_meta', $post->ID, $key)) {
                continue;
            }
            echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
        }
        ?>
</select>
<input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" />
<a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
<span id="enternew"><?php 
        _e('Enter new');
        ?>
</span>
<span id="cancelnew" class="hidden"><?php 
        _e('Cancel');
        ?>
</span></a>
<?php 
    } else {
        ?>
<input type="text" id="metakeyinput" name="metakeyinput" value="" />
<?php 
    }
    ?>
</td>
<td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td>
</tr>

<tr><td colspan="2">
<div class="submit">
<?php 
    submit_button(__('Add Custom Field'), 'secondary', 'addmeta', false, array('id' => 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta'));
    ?>
</div>
<?php 
    wp_nonce_field('add-meta', '_ajax_nonce-add-meta', false);
    ?>
</td></tr>
</tbody>
</table>
<?php 
}
Exemplo n.º 28
0
 /**
  * Add meta to resources when requested by the client. Meta is added as a top-level
  * `<resource_name>_meta` attribute (e.g. `order_meta`) as a list of key/value pairs
  *
  * @since 2.1
  * @param array $data the resource data
  * @param object $resource the resource object (e.g WC_Order)
  * @return mixed
  */
 public function maybe_add_meta($data, $resource)
 {
     if (isset($this->server->params['GET']['filter']['meta']) && 'true' === $this->server->params['GET']['filter']['meta'] && is_object($resource)) {
         // don't attempt to add meta more than once
         if (preg_grep('/[a-z]+_meta/', array_keys($data))) {
             return $data;
         }
         // define the top-level property name for the meta
         switch (get_class($resource)) {
             case 'WC_Order':
                 $meta_name = 'order_meta';
                 break;
             case 'WC_Coupon':
                 $meta_name = 'coupon_meta';
                 break;
             case 'WP_User':
                 $meta_name = 'customer_meta';
                 break;
             default:
                 $meta_name = 'product_meta';
                 break;
         }
         if (is_a($resource, 'WP_User')) {
             // customer meta
             $meta = (array) get_user_meta($resource->ID);
         } elseif (is_a($resource, 'WC_Product_Variation')) {
             // product variation meta
             $meta = (array) get_post_meta($resource->get_variation_id());
         } else {
             // coupon/order/product meta
             $meta = (array) get_post_meta($resource->id);
         }
         foreach ($meta as $meta_key => $meta_value) {
             // don't add hidden meta by default
             if (!is_protected_meta($meta_key)) {
                 $data[$meta_name][$meta_key] = maybe_unserialize($meta_value[0]);
             }
         }
     }
     return $data;
 }
Exemplo n.º 29
0
/**
 * Register meta key
 *
 * @since 3.3.0
 *
 * @param string $meta_type Type of meta
 * @param string $meta_key Meta key
 * @param string|array $sanitize_callback A function or method to call when sanitizing the value of $meta_key.
 * @param string|array $auth_callback Optional. A function or method to call when performing edit_post_meta, add_post_meta, and delete_post_meta capability checks.
 */
function register_meta($meta_type, $meta_key, $sanitize_callback, $auth_callback = null)
{
    if (is_callable($sanitize_callback)) {
        add_filter("sanitize_{$meta_type}_meta_{$meta_key}", $sanitize_callback, 10, 3);
    }
    if (empty($auth_callback)) {
        if (is_protected_meta($meta_key, $meta_type)) {
            $auth_callback = '__return_false';
        } else {
            $auth_callback = '__return_true';
        }
    }
    if (is_callable($auth_callback)) {
        add_filter("auth_{$meta_type}_meta_{$meta_key}", $auth_callback, 10, 6);
    }
}
Exemplo n.º 30
0
/**
 * {@internal Missing Short Description}}
 *
 * @since 1.2.0
 *
 * @param unknown_type $meta_id
 * @param unknown_type $meta_key Expect Slashed
 * @param unknown_type $meta_value Expect Slashed
 * @return unknown
 */
function update_meta($meta_id, $meta_key, $meta_value)
{
    global $wpdb;
    $meta_key = stripslashes($meta_key);
    if (is_protected_meta($meta_key)) {
        return false;
    }
    if ('' === trim($meta_value)) {
        return false;
    }
    $post_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_id = %d", $meta_id));
    $meta_value = maybe_serialize(stripslashes_deep($meta_value));
    $meta_id = (int) $meta_id;
    $data = compact('meta_key', 'meta_value');
    $where = compact('meta_id');
    do_action('update_postmeta', $meta_id, $post_id, $meta_key, $meta_value);
    $rval = $wpdb->update($wpdb->postmeta, $data, $where);
    wp_cache_delete($post_id, 'post_meta');
    do_action('updated_postmeta', $meta_id, $post_id, $meta_key, $meta_value);
    return $rval;
}