Add download_file capability and security check
This commit is contained in:
parent
0a7137e747
commit
3c22c486f8
|
@ -72,7 +72,7 @@ class WC_Download_Handler {
|
||||||
if ( ! is_user_logged_in() )
|
if ( ! is_user_logged_in() )
|
||||||
wp_die( __( 'You must be logged in to download files.', 'woocommerce' ) . ' <a href="' . wp_login_url( get_permalink( woocommerce_get_page_id( 'myaccount' ) ) ) . '">' . __( 'Login →', 'woocommerce' ) . '</a>', __( 'Log in to Download Files', 'woocommerce' ) );
|
wp_die( __( 'You must be logged in to download files.', 'woocommerce' ) . ' <a href="' . wp_login_url( get_permalink( woocommerce_get_page_id( 'myaccount' ) ) ) . '">' . __( 'Login →', 'woocommerce' ) . '</a>', __( 'Log in to Download Files', 'woocommerce' ) );
|
||||||
|
|
||||||
elseif ( $user_id != get_current_user_id() )
|
elseif ( !current_user_can( 'download_file', $download_result ) )
|
||||||
wp_die( __( 'This is not your download link.', 'woocommerce' ) );
|
wp_die( __( 'This is not your download link.', 'woocommerce' ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,6 +309,15 @@ function woocommerce_customer_has_capability( $allcaps, $caps, $args ) {
|
||||||
$allcaps['cancel_order'] = true;
|
$allcaps['cancel_order'] = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'download_file':
|
||||||
|
$user_id = $args[1];
|
||||||
|
$download = $args[2]
|
||||||
|
|
||||||
|
if ( $user_id == $download->user_id )
|
||||||
|
$allcaps['download_file'] = true;
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $allcaps;
|
return $allcaps;
|
||||||
|
|
Loading…
Reference in New Issue