/** * gallery shortcode sort fix * - get the gallery shortcode * - extract the ids * - save the ids as menu_order for the current images. * * @link http://wordpress.org/support/topic/when-is-menu_order-set-for-attachments#post-3816412 * * @param int $id * * @access public */ public function galleryMenuOrderFix($id) { //$regex_pattern = get_shortcode_regex(); $regex_matches = array(); $content = Filter::post_var('content'); preg_match('/\\[gallery[^\\]]*\\](.*)/', stripslashes($content), $regex_matches); if (substr($regex_matches[0], 1, 7) == 'gallery') { $attributes = array(); preg_match('/"([^"]+)"/', $regex_matches[0], $attributes); $attributes = $attributes[1]; } $ids = explode(',', $attributes); $images = get_posts(array('post_parent' => $id, 'numberposts' => '-1', 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order ID', 'order' => 'ASC')); if (!empty($images)) { foreach ($images as $attachment_id => $attachment) { if (\in_array($attachment->ID, $ids)) { $update_post = array(); $update_post['ID'] = $attachment->ID; $update_post['menu_order'] = \array_search($attachment->ID, $ids); \wp_update_post($update_post); } } } }
/** * Add like by Anonymous user * * @param int $post_like_count * * @access private */ private function userAnonymousLike($post_like_count) { // get user IP address if (($ip = Filter::ip()) !== false) { // stored IP addresses $liked_ips = $this->getPostMeta(self::POST_LIKED_USERS_IP_KEY, true); if (!$liked_ips || array_search($ip, $liked_ips) === false) { // if IP not in array $liked_ips[] = $ip; // add IP to array } // unlike the post if (self::isAlreadyLiked($this->post_id)) { // find the key $ip_key = array_search($ip, $liked_ips); // remove user IP from array unset($liked_ips[$ip_key]); // Remove user IP from post meta // -1 count post meta $post_like_count = $this->subtractionLikeCount($post_like_count); $this->updatePostLikeMeta($liked_ips, $post_like_count); // generate response $this->response(0, $post_like_count); } else { //like the post // Add user IP to post meta // +1 count post meta $this->updatePostLikeMeta($liked_ips, ++$post_like_count); // generate response // update count on frontend $this->response(1, $post_like_count); } } else { $this->response('ip', 'error'); } }
/** * * request is $_POST data * * @access private * @return boolean if the request is $_GET return true else false */ private function isPost($name) { //TODO has_var if (\is_null(Filter::post_var($name))) { return false; } return true; }
/** * * get current usr ip address * * @return string|boolean if the ip addrss is bad return false else return ip address * @access private */ private function getUserIp() { $ip = Filter::ip(); return $ip; }
/** * Add taxonomy filter to the admin page in post type lists * * @link https://pippinsplugins.com/post-list-filters-for-custom-taxonomies-in-manage-posts/ * @access public * @return void */ public function filterAdminPostsTypeList() { global $typenow; // An array of all the taxonomyies you want to display. Use the taxonomy name or slug // must set this to the post type you want the filter(s) displayed on foreach ($this->getPostsTypesNames() as $post_type_name) { if ($typenow == $post_type_name) { $taxonomies = \get_object_taxonomies($typenow); foreach ($taxonomies as $tax_slug) { $tax_obj = \get_taxonomy($tax_slug); if (\wp_count_terms($tax_slug)) { \wp_dropdown_categories(array('show_option_all' => Translate::translate('Show All ' . $tax_obj->label), 'taxonomy' => $tax_slug, 'name' => $tax_obj->name, 'orderby' => 'name', 'selected' => Filter::get_var($tax_slug), 'hierarchical' => $tax_obj->hierarchical, 'show_count' => false, 'hide_empty' => true)); } } } } }