Exemple #1
0
function clearbase_move_to_folder($folder_id = null, $post_ids = array())
{
    if (!current_user_can('edit_posts')) {
        return new WP_Error('cannot-edit-posts', __('You do not have permission to move the items.', 'clearbase'));
    }
    $folder = get_post($folder_id);
    if (!isset($folder) || 'clearbase_folder' !== $folder->post_type) {
        return new WP_Error('invalid-folder', __('The specified folder id is invalid: ' . $folder_id, 'clearbase'));
    }
    if (is_numeric($post_ids)) {
        $post_ids = array(absint($post_ids));
    }
    $maxsort = clearbase_get_max_menu_order($folder_id);
    foreach ($post_ids as $key => $postID) {
        wp_update_post(array('ID' => $postID, 'post_parent' => $folder_id, 'menu_order' => ++$maxsort));
    }
    return true;
}
function clearbase_insert_attachment_data($data, $postArr)
{
    //if adding a new attachment...
    if (empty($postArr['ID'])) {
        //...to a clearbase album
        $post_id = isset($data['post_parent']) ? absint($data['post_parent']) : 0;
        $post = $post_id ? get_post($post_id) : false;
        if ($post && 'clearbase_folder' === $post->post_type) {
            //set the menu order in the album
            $max = clearbase_get_max_menu_order($post_id);
            $data['menu_order'] = ++$max;
        }
    }
    return $data;
}