/**
         * Extra controls to be displayed between bulk actions and pagination
         *
         * @access protected
         *
         * @param mixed $which Which tablenav the top or bottom.
         */
        protected function extra_tablenav($which)
        {
            $conditions = msa_get_conditions();
            $attributes = msa_get_attributes();
            if ('top' === $which) {
                ?>
<div class="alignleft actions bulkactions"><?php 
                foreach ($conditions as $key => $condition) {
                    if (isset($condition['filter'])) {
                        $value = '';
                        if (isset($_GET[$condition['filter']['name']])) {
                            // Input var okay.
                            $value = sanitize_text_field(wp_unslash($_GET[$condition['filter']['name']]));
                            // Input var okay.
                        }
                        $options = '';
                        $condition = apply_filters('msa_audit_posts_filter_' . $key, $condition);
                        if (1 === $condition['comparison']) {
                            $options .= '<option value="less-' . $condition['min'] . '" ' . selected('less-' . $condition['min'], $value, false) . '>' . __('Less than ', 'msa') . ' ' . $condition['min'] . ' ' . $condition['units'] . '</option>';
                            $options .= '<option value="more-' . $condition['min'] . '" ' . selected('more-' . $condition['min'], $value, false) . '>' . __('More than ', 'msa') . ' ' . $condition['min'] . ' ' . $condition['units'] . '</option>';
                        } else {
                            if (2 === $condition['comparison']) {
                                $options .= '<option value="less-' . $condition['max'] . '" ' . selected('less-' . $condition['max'], $value, false) . '>' . __('Less than ', 'msa') . ' ' . $condition['max'] . ' ' . $condition['units'] . '</option>';
                                $options .= '<option value="more-' . $condition['max'] . '" ' . selected('more-' . $condition['max'], $value, false) . '>' . __('More than ', 'msa') . ' ' . $condition['max'] . ' ' . $condition['units'] . '</option>';
                            } else {
                                if (3 === $condition['comparison']) {
                                    $options .= '<option value="less-' . $condition['max'] . '" ' . selected('less-' . $condition['max'], $value, false) . '>' . __('Less than ', 'msa') . ' ' . $condition['max'] . ' ' . $condition['units'] . '</option>';
                                    $options .= '<option value="more-' . $condition['max'] . '" ' . selected('more-' . $condition['max'], $value, false) . '>' . __('More than ', 'msa') . ' ' . $condition['max'] . ' ' . $condition['units'] . '</option>';
                                }
                            }
                        }
                        ?>
<div class="msa-filter-container msa-filter-conditions-container filter-<?php 
                        esc_attr_e($key);
                        ?>
">
			<!-- <label class="msa-filter-label"><?php 
                        esc_attr_e($condition['filter']['label']);
                        ?>
</label> -->
			<select class="msa-filter" name="<?php 
                        esc_attr_e($condition['filter']['name']);
                        ?>
">
				<option value="" <?php 
                        selected('', $value, true);
                        ?>
><?php 
                        esc_attr_e('All ' . $condition['filter']['label'], 'msa');
                        ?>
</option>
				<?php 
                        echo $options;
                        // WPCS: XSS ok.
                        ?>
			</select>
		</div> <?php 
                    }
                }
                foreach ($attributes as $key => $attribute) {
                    if (isset($attribute['filter'])) {
                        $value = '';
                        if (isset($_GET[$attribute['filter']['name']])) {
                            // Input var okay.
                            $value = sanitize_text_field(wp_unslash($_GET[$attribute['filter']['name']]));
                            // Input var okay.
                        }
                        $attribute['filter']['options'] = apply_filters('msa_filter_attribute_' . $key, $attribute['filter']['options'], $key);
                        ?>

		<div class="msa-filter-container msa-filter-attributes-container filter-<?php 
                        esc_attr_e($key);
                        ?>
">
			<!-- <label class="msa-filter-label"><?php 
                        esc_attr_e($attribute['filter']['label']);
                        ?>
</label> -->
			<select class="msa-filter" name="<?php 
                        esc_attr_e($attribute['filter']['name']);
                        ?>
">
				<option value="" <?php 
                        selected('', $value, true);
                        ?>
><?php 
                        esc_attr_e('All ' . $attribute['filter']['label'], 'msa');
                        ?>
</option>
				<?php 
                        foreach ($attribute['filter']['options'] as $option) {
                            ?>
					<option value="<?php 
                            esc_attr_e($option['value']);
                            ?>
" <?php 
                            selected($option['value'], $value, true);
                            ?>
><?php 
                            esc_attr_e($option['name']);
                            ?>
</option>
				<?php 
                        }
                        ?>
			</select>
		</div>

	<?php 
                    }
                }
                ?>
<button class="msa-filter-button button"><?php 
                esc_attr_e('Filter', 'msa');
                ?>
</button>
				<button class="msa-clear-filters-button button"><?php 
                esc_attr_e('Clear Filters', 'msa');
                ?>
</button>
				</div><?php 
            }
            // Output stlying for the condition categories.
            $condition_categories = msa_get_condition_categories();
            ?>
<style>
			<?php 
            foreach ($condition_categories as $key => $condition_category) {
                ?>
th#<?php 
                esc_attr_e($key);
                ?>
.manage-column.column-<?php 
                esc_attr_e($key);
                ?>
,
				.<?php 
                esc_attr_e($key);
                ?>
.column-<?php 
                esc_attr_e($key);
                ?>
 {
					font-weight: bold;
					border-left: 1px solid #dfdfdf;
					background: linear-gradient(rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0.02));
				}
			<?php 
            }
            ?>
			</style><?php 
        }
예제 #2
0
/**
 * Add all the screen option columns
 *
 * @access public
 * @param mixed $columns  The original columns.
 * @return array $columns The modified columns.
 */
function msa_all_audits_add_column($columns)
{
    /**
     * Conditions
     */
    $condition_categories = msa_get_condition_categories();
    foreach ($condition_categories as $key => $condition_category) {
        $conditions = msa_get_conditions_from_category($key);
        foreach ($conditions as $key => $condition) {
            $columns[$key] = $condition['name'];
        }
    }
    /**
     * Attributes
     */
    $attributes = msa_get_attributes();
    foreach ($attributes as $slug => $attribute) {
        if (isset($attribute['name'])) {
            $columns[$slug] = $attribute['name'];
        }
    }
    return $columns;
}
예제 #3
0
} else {
    if (isset($_GET['audit']) && check_admin_referer('msa-single-audit')) {
        // Input var okay.
        $audit_id = sanitize_text_field(wp_unslash($_GET['audit']));
        // Input var okay.
        // Get the Audit.
        $audit_model = new MSA_Audits_Model();
        $audit = $audit_model->get_data_from_id($audit_id);
        $form_fields = json_decode($audit['args']['form_fields'], true);
        // Get the posts for an audit.
        $audit_posts_model = new MSA_Audit_Posts_Model();
        $posts = $audit_posts_model->get_data($audit_id);
        // Get all the current filters.
        $current_filters = '';
        $conditions = msa_get_conditions();
        $attributes = msa_get_attributes();
        foreach ($conditions as $key => $condition) {
            if (isset($condition['filter']['name']) && isset($_GET[$condition['filter']['name']])) {
                // Input var okay.
                $current_filters .= '&' . $condition['filter']['name'] . '=' . sanitize_text_field(wp_unslash($_GET[$condition['filter']['name']]));
                // Input var okay.
            }
        }
        foreach ($attributes as $key => $attribute) {
            if (isset($attribute['filter']['name']) && isset($_GET[$attribute['filter']['name']])) {
                // Input var okay.
                $current_filters .= '&' . $attribute['filter']['name'] . '=' . sanitize_text_field(wp_unslash($_GET[$attribute['filter']['name']]));
                // Input var okay.
            }
        }
        $post_type_labels = array();
예제 #4
0
/**
 * Filter the posts for the all posts table
 *
 * @access public
 * @param mixed $posts  The original array of WP_Post objects.
 * @return mixed $posts The filtered array of WP_Post objects.
 */
function msa_filter_posts($posts)
{
    // Score.
    if (isset($_GET['score-low']) && '' !== $_GET['score-low'] && isset($_GET['score-high']) && '' !== $_GET['score-high']) {
        // Input var okay.
        $score_low = floatval(sanitize_text_field(wp_unslash($_GET['score-low'])));
        // Input var okay.
        $score_high = floatval(sanitize_text_field(wp_unslash($_GET['score-high'])));
        // Input var okay.
        foreach ($posts as $key => $item) {
            if ($item['data']['values']['score'] < $score_low || $item['data']['values']['score'] > $score_high) {
                unset($posts[$key]);
            }
        }
    }
    // Conditions.
    $conditions = msa_get_conditions();
    foreach ($conditions as $condition) {
        if (isset($condition['filter']) && isset($_GET[$condition['filter']['name']]) && '' !== $_GET[$condition['filter']['name']]) {
            // Input var okay.
            $name = $condition['filter']['name'];
            $atts = array();
            if (isset($_GET[$name])) {
                // Input var okay.
                $atts = explode('-', sanitize_text_field(wp_unslash($_GET[$name])));
                // Input var okay.
            }
            $compare = $atts[0];
            $value = $atts[1];
            foreach ($posts as $key => $item) {
                $post_value = $item['data']['values'][$name];
                // Compare.
                if ('more' === $compare) {
                    if (isset($post_value) && $post_value < $value) {
                        unset($posts[$key]);
                    }
                } else {
                    if ('less' === $compare) {
                        if (isset($post_value) && $post_value > $value) {
                            unset($posts[$key]);
                        }
                    } else {
                        if ('equal' === $compare) {
                            if (isset($post_value) && $post_value !== $value) {
                                unset($posts[$key]);
                            }
                        } else {
                            if ('notequal' === $compare) {
                                if (isset($post_value) && $post_value === $value) {
                                    unset($posts[$key]);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Attributes.
    $attributes = msa_get_attributes();
    foreach ($attributes as $attribute) {
        if (isset($attribute['filter']) && isset($_GET[$attribute['filter']['name']]) && '' !== $_GET[$attribute['filter']['name']]) {
            // Input var okay.
            $name = $attribute['filter']['name'];
            $get_name = null;
            if (isset($_GET[$name])) {
                // Input var okay.
                $get_name = sanitize_text_field(wp_unslash($_GET[$name]));
                // Input var okay.
            }
            $posts = apply_filters('msa_filter_by_attribute', $posts, $name, $get_name);
        }
    }
    return $posts;
}