<?php

/**
 * Post Planner Plugin Associated Post Metabox
 *
 * Creates the associated post metabox
 * @author C.M. Kendrick <*****@*****.**>
 * @package post-planner
 * @version 1.0
 */
$planner_permission = true;
$associated_post_id = get_post_meta($post->ID, '_pp_postid', true) ? get_post_meta($post->ID, '_pp_postid', true) : false;
$planner_post_type = get_post_meta($post->ID, '_pp_type', true) ? get_post_meta($post->ID, '_pp_type', true) : PostPlanner_Lib::get_default_post_type();
$planner_post_type_object = get_post_type_object($planner_post_type);
if ($associated_post_id != false) {
    // check if associated post still exists
    if (get_post($associated_post_id) == null) {
        $associated_post_id = false;
        delete_post_meta(absint($post->ID), '_pp_postid');
    }
    // check if user can edit associated content
    if ($planner_post_type == 'post') {
        $planner_permission = current_user_can('edit_post', $associated_post_id);
    } elseif ($planner_post_type == 'page') {
        $planner_permission = current_user_can('edit_page', $associated_post_id);
    } else {
        $planner_permission = apply_filters('post_planner_associated_permission', current_user_can('edit_post', $associated_post_id), $planner_post_type);
    }
}
?>
<div class="post-planner-meta-side-control">