1 <?php
2 3 4 5 6 7 8 9 10 11 12
13
14
15 if ( ! defined( 'ABSPATH' ) ) exit;
16
17 18 19 20 21 22 23
24 function edd_query_vars( $vars ) {
25 $vars[] = 'edd_action';
26 $vars[] = 'cart_item';
27 return $vars;
28 }
29 add_filter( 'query_vars', 'edd_query_vars' );
30
31 32 33 34 35 36
37 function edd_block_attachments() {
38 if ( ! is_attachment() )
39 return;
40
41 $parent = get_post_field( 'post_parent', get_the_ID() );
42 $uri = wp_get_attachment_url( get_the_ID() );
43 $edd_file = strpos( $uri, '/edd/' );
44
45 if ( ! $parent && false === $edd_file )
46 return;
47
48 if ( 'download' != get_post_type( $parent ) && false === $edd_file )
49 return;
50
51 wp_die( __( 'You do not have permission to view this file.', 'edd' ), __( 'Error', 'edd' ) );
52 }
53 add_action( 'template_redirect', 'edd_block_attachments' );