"; echo $html; } /* Save Slider Options to database */ add_action('save_post', 'crud_saveDownloadInfo'); function crud_saveDownloadInfo($post_id) {
// verify nonce if (!wp_verify_nonce($_POST['crud_custom_fields_nonce'], basename(__FILE__))) { return $post_id; } // check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // check permissions if ('download_items' == $_POST['post_type'] && current_user_can('edit_download_items', $post_id)) { $download_price = (isset($_POST['crud_download_price']) ? $_POST['crud_download_price'] : ''); $categories = (isset($_POST['crud_category']) ? $_POST['crud_category'] : ''); $categories = strip_tags(json_encode($categories)); update_post_meta($post_id, "download_price", $download_price); update_post_meta($post_id, "crud_category", $categories); } else { return $post_id; } } // Callback function to show fields in meta box add_filter('map_meta_cap', 'crud_downloadItemMetaCap', 10, 4); function crud_downloadItemMetaCap($primitive_caps, $meta_cap, $user_id, $args) { // If meta-capability is not download_item based do nothing. if (!in_array($meta_cap, array('edit_download_item', 'delete_download_item', 'read_download_item'))) { return $primitive_caps; } // Check post is of post type. $post = get_post($args[0]); $post_type = get_post_type_object($post->post_type); if ('download_items' != $post_type) { return $primitive_caps; } $primitive_caps = array(); switch ($meta_cap): case 'edit_download_item': if ($post->post_author == $user_id) { // User is post author if ('publish' == $post->post_status) { // download_item is published: require 'edit_published_download_items' capability $primitive_caps[] = $post_type->cap->edit_published_posts; } elseif ('trash' == $post->post_status) { if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true)) { // download_item is a trashed published post require 'edit_published_download_items' capability $primitive_caps[] = $post_type->cap->edit_published_posts; } } else { $primitive_caps[] = $post_type->cap->edit_posts; } } else { // The user is trying to edit a post belonging to someone else. $primitive_caps[] = $post_type->cap->edit_others_posts; // If the post is published or private, extra caps are required. if ('publish' == $post->post_status) { $primitive_caps[] = $post_type->cap->edit_published_posts; } elseif ('private' == $post->post_status) { $primitive_caps[] = $post_type->cap->edit_private_posts; } } break; case 'read_download_item': if ('private' != $post->post_status) { // If the post is not private, just require read capability $primitive_caps[] = $post_type->cap->read; } elseif ($post->post_author == $user_id) { // Post is private, but current user is author $primitive_caps[] = $post_type->cap->read; } else { // Post is private, and current user is not the author $primitive_caps[] = $post_type->cap->read_private_post; } break; case 'delete_download_item': if ($post->post_author == $user_id) { // Current user is author, require delete_download_items capability $primitive_caps[] = $post_type->cap->delete_posts; } else { // Current user is no the author, require delete_others_download_items capability $primitive_caps[] = $post_type->cap->delete_others_posts; } // If post is published, require delete_published_posts capability too if ('publish' == $post->post_status) { $primitive_caps[] = $post_type->cap->delete_published_posts; } break; endswitch; return $primitive_caps; } function crud_frontendDeleteLink() { if (!current_user_can('delete_download_items')) { echo ' '; return; } $url = add_query_arg( array( 'action' => 'frontend_delete', 'post' => get_the_ID() ) ); echo "Delete"; } if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'frontend_delete') { add_action('init', 'crud_FrontendDeletePost'); } function crud_FrontendDeletePost() { if (!current_user_can('delete_download_items')) return; $post_id = (isset($_REQUEST['post']) ? (int) $_REQUEST['post'] : 0); if (empty($post_id)) return; wp_trash_post($post_id); } add_shortcode('downloadItem', crud_downloadItemFun); function crud_downloadItemFun() { set_caps(); global $post ; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'posts_per_page' => 10, 'post_type' => 'download_items', 'paged' => $paged ); $newsObj = new WP_Query($args); if ($newsObj->have_posts()): ?>
No comments:
Post a Comment