示例#1
0
 /**
  * Return Webcomic attachments for a post.
  * 
  * @param integer $id Post ID to retrieve attachments for.
  * @return array
  */
 protected static function get_attachments($id = 0)
 {
     if (!current_user_can('edit_post', $id) and (!WebcomicTag::verify_webcomic_role(get_post_type($id)) or !WebcomicTag::verify_webcomic_age(get_post_type($id)))) {
         return array();
     }
     return get_children(array('order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'attachment', 'post_parent' => $id, 'post_mime_type' => 'image'));
 }
示例#2
0
文件: tags.php 项目: ecerta/webcomic
 /**
  * Verify a users role against allowed collection roles.
  * 
  * <code class="php">
  * if ( is_null( verify_webcomic_role() ) ) {
  * 	// the current user is not logged in
  * } elseif ( verify_webcomic_role() ) {
  * 	// the current user has permission to view content in the current collection
  * } else {
  * 	// the current user does not have permission to view content in the current collection
  * }
  * 
  * if ( verify_webcomic_role( 'webcomic42' ) ) {
  * 	// the current user has permission  to view content in webcomic collection 42
  * }
  * 
  * if ( verify_webcomic_role( 'webcomic42', 2 ) ) {
  * 	// the user with an ID of 2 has permission to view content in webcomic collection 42
  * }
  * </code>
  * 
  * <code class="bbcode">
  * [verify_webcomic_role]
  * // the current user has permission to view content in the current collection
  * [/verify_webcomic_role]
  * 
  * [verify_webcomic_role collection="webcomic42"]
  * // the current user has permission  to view content in webcomic collection 42
  * [/verify_webcomic_role]
  * 
  * [verify_webcomic_role collection="webcomic42" user="******"]
  * // the user with an ID of 2 has permission to view content in webcomic collection 42
  * [/verify_webcomic_role]
  * </code>
  * 
  * @package Webcomic
  * @param string $collection The collection to verify against.
  * @param object $user The user to verify with (defaults to the current user).
  * @param array $roles The role or roles users must belong to. Overrides the collection role setting, or forces use of the collection role setting if -1.
  * @return mixed
  * @uses WebcomicTag::verify_webcomic_role()
  */
 function verify_webcomic_role($collection = '', $user = false, $roles = array())
 {
     return WebcomicTag::verify_webcomic_role($collection, $user, $roles);
 }
示例#3
0
 /**
  * Handle verify_webcomic_role shortcode.
  * 
  * @param array $atts Shortcode attributes.
  * @param string $content Shortcode content.
  * @return string
  * @uses WebcomicTag::verify_webcomic_role()
  * @filter string webcomic_verify_role_inline Filters the output of the `verify_webcomic_role` shortcode. Defaults to a generic role verification message.
  */
 public function verify_webcomic_role($atts, $content)
 {
     extract(shortcode_atts(array('collection' => '', 'roles' => array()), $atts));
     $collection = $collection ? $collection : WebcomicTag::get_webcomic_collection();
     if (WebcomicTag::verify_webcomic_role($collection, false, $roles)) {
         return do_shortcode($content);
     } else {
         $loggedin = is_user_logged_in();
         return apply_filters('webcomic_verify_role_inline', $loggedin ? __("You don't have permission to view this content.", 'webcomic') : sprintf(__('Please <a href="%s">log in</a> to view this content.', 'webcomic'), wp_login_url($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])), $loggedin, $collection, $roles, $content);
     }
 }