function attachment_access() { global $post, $wpdb; if (empty($post)) { global $wp_query; if (!empty($wp_query->query_vars['attachment_id'])) { $post = scoper_get_row("SELECT * FROM {$wpdb->posts} WHERE post_type = 'attachment' AND ID = '{$wp_query->query_vars['attachment_id']}'"); } elseif (!empty($wp_query->query_vars['attachment'])) { $post = scoper_get_row("SELECT * FROM {$wpdb->posts} WHERE post_type = 'attachment' AND post_name = '{$wp_query->query_vars['attachment']}'"); } } if (!empty($post)) { $object_type = scoper_get_var("SELECT post_type FROM {$wpdb->posts} WHERE ID = '{$post->post_parent}'"); // default to 'post' object type if retrieval failed for some reason if (empty($object_type)) { $object_type = 'post'; } if ($post->post_parent) { if (!current_user_can("read_{$object_type}", $post->post_parent)) { if (scoper_get_otype_option('do_teaser', 'post')) { if ($use_teaser_type = scoper_get_otype_option('use_teaser', 'post', $object_type)) { AttachmentTemplate_RS::impose_post_teaser($post, $object_type, $use_teaser_type); } else { unset($post); } } else { unset($post); } // WordPress generates 404 if teaser is not enabled } } elseif (defined('SCOPER_BLOCK_UNATTACHED_UPLOADS') && SCOPER_BLOCK_UNATTACHED_UPLOADS) { unset($post); } } }