Last active
October 15, 2019 04:42
-
-
Save gaupoit/fae92e6e0a140b833a63b68881dcecf8 to your computer and use it in GitHub Desktop.
Filter the URLs protected by Prevent Direct Access plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'post_type' => 'attachment', | |
'post_status' => 'any', | |
'meta_query' => array( | |
array( | |
'key' => '_pda_protection', | |
'value' => '1' | |
) | |
) | |
); | |
$query = new WP_Query( $args ); | |
// Here, you can get the array of posts by $query->posts | |
$attachments = get_attachment_urls( $query->posts ); | |
// Or display the result in theme | |
if ( $query->have_posts() ) { | |
while ( $query->have_posts() ) { | |
$query->the_post(); | |
// Post data goes here. | |
?> | |
<h2><?php the_title(); ?></h2> | |
<p> | |
<?php the_content(); ?> | |
</p> | |
<?php | |
} | |
} | |
/** | |
* Get user roles in settings | |
* @param array Query's result from WP_Query | |
* | |
* return array | |
*/ | |
function get_attachment_urls( $query_result ) { | |
return array_map( function ( $attachment ) { | |
$attachment->url = wp_get_attachment_url( $attachment->ID ); | |
return $attachment; | |
}, $query_result ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment