public function is_valid_attach()
{
global $pagenow;
if ($pagenow !== 'post.php' && $pagenow !== 'post-new.php') {
return false;
}
// Post types check
if (!empty($this->settings['post_type'])) {
$post_type = '';
if ($this->post_id) {
$post_type = get_post_type($this->post_id);
} elseif (!empty($_GET['post_type'])) {
$post_type = $_GET['post_type'];
} elseif ($pagenow === 'post-new.php') {
$post_type = 'post';
}
if (!$post_type || !in_array($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) {
case 'page_id':
if ($value < 1 || $this->post_id != $value) {
return false;
}
break;
case 'parent_page_id':
// Check if such page exists
if ($value < 1) {
return false;
}
break;
}
}
return true;
}