/** * 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')); }
/** * Verify a users age against collection age limit. * * <code class="php"> * if ( is_null( verify_webcomic_age() ) ) { * // the current user's age has not be checked * } elseif ( verify_webcomic_age() ) { * // the current user is old enough to view content in the current collection * } else { * // the current user is not old enough to view content in the current collection * } * * if ( verify_webcomic_age( 'webcomic42' ) ) { * // the current user is old enough to view content in webcomic collection 42 * } * * if ( verify_webcomic_age( 'webcomic42', 2 ) ) { * // the user with an ID of 2 is old enough to view content in webcomic collection 42 * } * </code> * * <code class="bbcode"> * [verify_webcomic_age] * // the current user is old enough to view content in the current collection * [/verify_webcomic_age] * * [verify_webcomic_age collection="webcomic42"] * // the current user is old enough to view content in webcomic collection 42 * [/verify_webcomic_age] * * [verify_webcomic_age collection="webcomic42" user="******"] * // the user with an ID of 2 is old enough to view content in webcomic collection 42 * [/verify_webcomic_age] * </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 integer $age Age (in years) to verify against. Overrides the collection age setting, or forces use of the collection age if -1. * @return mixed * @uses WebcomicTag::verify_webcomic_age() */ function verify_webcomic_age($collection = '', $user = false, $age = 0) { return WebcomicTag::verify_webcomic_age($collection, $user, $age); }
/** * Handle verify_webcomic_age shortcode. * * @param array $atts Shortcode attributes. * @param string $content Shortcode content. * @return string * @uses WebcomicTag::verify_webcomic_age() * @uses WebcomicTag::get_webcomic_collection() * @filter string webcomic_verify_age_inline Filters the output of the `verify_webcomic_age` shortcode. Defaults to a generic age verification message. */ public function verify_webcomic_age($atts, $content) { extract(shortcode_atts(array('collection' => '', 'age' => 0), $atts)); $age = $age ? $age : -1; $collection = $collection ? $collection : WebcomicTag::get_webcomic_collection(); if ($clear = WebcomicTag::verify_webcomic_age($collection, false, $age)) { return do_shortcode($content); } else { return apply_filters('webcomic_verify_age_inline', is_null($clear) ? __('Please verify your age to view this content:', 'webcomic') . '<form method="post"><label>' . __('Birthday', 'webcomic') . ' <input type="date" name="webcomic_birthday"></label><input type="submit"></form>' : __("You don't have permission to view this content.", 'webcomic'), $clear, $collection, $age, $content); } }