public function is_valid_save_conditions($post_id)
{
$valid = true;
$post = get_post($post_id);
// Check post type
if (!in_array($post->post_type, $this->settings['post_type'])) {
return false;
}
// Check show on conditions
foreach ($this->settings['show_on'] as $condition => $value) {
if (is_null($value)) {
continue;
}
switch ($condition) {
// show_on_post_format
case 'post_formats':
if (empty($value) || $post->post_type != 'post') {
break;
}
$current_format = get_post_format($post_id);
if (!in_array($current_format, $value)) {
$valid = false;
break 2;
}
break;
// show_on_taxonomy_term or show_on_category
// show_on_taxonomy_term or show_on_category
case 'category':
$this->show_on_category($value);
/* fall-through intended */
/* fall-through intended */
case 'tax_term_id':
$current_terms = wp_get_object_terms($post_id, $this->settings['show_on']['tax_slug'], array('fields' => 'ids'));
if (!is_array($current_terms) || !in_array($this->settings['show_on']['tax_term_id'], $current_terms)) {
$valid = false;
break 2;
}
break;
// show_on_level
// show_on_level
case 'level_limit':
$post_level = count(get_post_ancestors($post_id)) + 1;
if ($post_level != $value) {
$valid = false;
break 2;
}
break;
// show_on_page
// show_on_page
case 'page_id':
if ($post_id != $value) {
$valid = false;
break 2;
}
break;
// show_on_page_children
// show_on_page_children
case 'parent_page_id':
if ($post->post_parent != $value) {
$valid = false;
break 2;
}
break;
// show_on_template
// show_on_template
case 'template_names':
if (empty($value) || $post->post_type != 'page') {
break;
}
$current_template = get_post_meta($post_id, '_wp_page_template', 1);
if (!in_array($current_template, $value)) {
$valid = false;
break 2;
}
break;
// hide_on_template
// hide_on_template
case 'not_in_template_names':
if (empty($value) || $post->post_type != 'page') {
break;
}
$current_template = get_post_meta($post_id, '_wp_page_template', 1);
if (in_array($current_template, $value)) {
$valid = false;
break 2;
}
break;
}
}
return $valid;
}