예제 #1
0
 /**
  * Can the current user switch post parent for the supplied post
  *
  * @param object|int $post post obj or post ID to check move for
  */
 public function can_place_in_section($post, $prev_parent = null)
 {
     $allowed = false;
     if (is_numeric($post)) {
         $post = get_post($post);
     }
     if (!is_object($post)) {
         return false;
     }
     // Need a valid post type to continue
     $pto = get_post_type_object($post->post_type);
     if (!is_object($pto)) {
         return false;
     }
     $can_publish = current_user_can($pto->cap->publish_posts);
     // Top level move
     if (0 == $post->post_parent) {
         // Move is promotion to top level
         if (0 !== $prev_parent) {
             // Top-level moves are okay as long as top level publishing is allowed or the post is excluded from nav menus
             $allow_top = $this->plugin->settings->get('allow_top');
             $excluded_from_nav = bu_navigation_post_excluded($post);
             $allowed = current_user_can($pto->cap->publish_posts) && ($allow_top || $excluded_from_nav);
         } else {
             $allowed = current_user_can($pto->cap->publish_posts);
         }
     } else {
         // Check parent
         $parent = get_post($post->post_parent);
         if (!is_object($parent)) {
             $allowed = false;
         } else {
             // Move under another post -- check if parent is editable
             $allowed = current_user_can('edit_post', $parent->ID);
             // Links can't have children
             if (BU_NAVIGATION_LINK_POST_TYPE == $parent->post_type) {
                 $allowed = false;
             }
         }
     }
     return $allowed;
 }
예제 #2
0
파일: post.php 프로젝트: iamapioneer/sdas
 /**
  * @todo this is redundant with work done in the BU_Navigation_Tree_View class
  * @todo think about refactoring
  */
 public function format_post($post)
 {
     // Get necessary metadata
     $post->excluded = bu_navigation_post_excluded($post);
     $post->protected = !empty($post->post_password);
     // Label
     $post->post_title = bu_navigation_get_label($post);
     $formatted = array('ID' => $post->ID, 'post_title' => $post->post_title, 'post_status' => $post->post_status, 'post_type' => $post->post_type, 'post_parent' => $post->post_parent, 'menu_order' => $post->menu_order, 'post_meta' => array('protected' => $post->protected, 'excluded' => $post->excluded));
     return apply_filters('bu_nav_metabox_format_post', $formatted, $post);
 }
예제 #3
0
파일: admin.php 프로젝트: iamapioneer/sdas
 /**
  * @todo
  *  - needs unit tests (selenium)
  *
  * - prints json formatted data that tells the browser to either show a warning or not
  * - dies.
  */
 public function ajax_check_hidden_page()
 {
     global $wpdb;
     $response = array();
     $post_id = (int) $_POST['post_id'];
     $post = get_post($post_id);
     // case: not a supported post_type
     if (!in_array($post->post_type, $this->plugin->supported_post_types())) {
         echo json_encode(array('ignore' => true));
         die;
     }
     // get post type labels
     $post_type = get_post_type_object($post->post_type);
     // get children pages/links
     $page_children_query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_type='{$post->post_type}'", $post_id);
     $page_children = $wpdb->get_results($page_children_query);
     $link_children_query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_type='" . BU_NAVIGATION_LINK_POST_TYPE . "'", $post_id);
     $link_children = $wpdb->get_results($link_children_query);
     // case no children, output the "ignore" flag
     if (count($page_children) == 0 && count($link_children) == 0) {
         echo json_encode(array('ignore' => true, 'children' => 0));
         die;
     }
     $hidden = bu_navigation_post_excluded($post);
     // case: wasn't hidden, output the "ignore" flag
     if (!$hidden) {
         echo json_encode(array('ignore' => true, 'children' => 0));
         die;
     }
     // case: child pages and/or links exist
     // construct output msg based on how many child pages/links exist
     $msg = sprintf(__('"%s" is a hidden %s with ', 'bu-navigation'), $post->post_title, strtolower($post_type->labels->singular_name));
     $children_msgs = array();
     if (count($page_children) >= 1) {
         $children_msgs['page'] = sprintf(_n('a child ', '%d child ', count($page_children), 'bu-navigation'), count($page_children));
         $children_msgs['page'] .= count($page_children) == 1 ? strtolower($post_type->labels->singular_name) : strtolower($post_type->labels->name);
     }
     if (count($link_children) >= 1) {
         $children_msgs['link'] = sprintf(_n('a child link', '%d child links', count($link_children), 'bu-navigation'), count($link_children));
     }
     $children_msgs_vals = array_values($children_msgs);
     $children_msg = count($children_msgs) > 1 ? implode(__(' and ', 'bu-navigation'), $children_msgs_vals) : current($children_msgs);
     $msg .= $children_msg . ".";
     if (isset($children_msgs['page'])) {
         $msg .= sprintf(__(' If you delete this %1$s, %2$s will move up one node in the %1$s hierarchy, and will automatically be marked as hidden.', 'bu-navigation'), strtolower($post_type->labels->singular_name), $children_msgs['page']);
     }
     if (isset($children_msgs['link'])) {
         $msg .= sprintf(__(' If you delete this %1$s, %2$s will move up one node in the %1$s hierarchy, and will be displayed in navigation menus.', 'bu-navigation'), strtolower($post_type->labels->singular_name), $children_msgs['link']);
     }
     $response = array('ignore' => false, 'msg' => $msg);
     echo json_encode($response);
     die;
 }