/** * Setup the rewrite ids and slugs * * @package WP Idea Stream * @subpackage core/classes * * @since 2.0.0 * * @uses wp_idea_stream_user_rewrite_id() * @uses wp_idea_stream_user_rates_rewrite_id() * @uses wp_idea_stream_user_comments_rewrite_id() * @uses wp_idea_stream_cpage_rewrite_id() * @uses wp_idea_stream_action_rewrite_id() * @uses wp_idea_stream_search_rewrite_id() * @uses wp_idea_stream_user_slug() * @uses wp_idea_stream_user_rates_slug() * @uses wp_idea_stream_user_comments_slug() * @uses wp_idea_stream_cpage_slug() * @uses wp_idea_stream_action_slug() */ private function setup_globals() { /** Rewrite ids ***************************************************************/ $this->page_rid = 'paged'; // WordPress built-in global var $this->user_rid = wp_idea_stream_user_rewrite_id(); $this->user_rates_rid = wp_idea_stream_user_rates_rewrite_id(); $this->user_comments_rid = wp_idea_stream_user_comments_rewrite_id(); $this->cpage_rid = wp_idea_stream_cpage_rewrite_id(); $this->action_rid = wp_idea_stream_action_rewrite_id(); $this->search_rid = wp_idea_stream_search_rewrite_id(); /** Rewrite slugs *************************************************************/ $this->user_slug = wp_idea_stream_user_slug(); $this->user_rates_slug = wp_idea_stream_user_rates_slug(); $this->user_comments_slug = wp_idea_stream_user_comments_slug(); $this->cpage_slug = wp_idea_stream_cpage_slug(); $this->action_slug = wp_idea_stream_action_slug(); }
/** * WordPress requires a post id to allow content to be Embed, As our users are not organized * into a post type, we need to use an utility page to get a post ID, and then filter its permalink * and title so that the ones of the user's profile will be used instead * * @since 2.3.0 * * @global WP_Rewrite $wp_rewrite * @param int $post_id the requested post id (should be empty for our users profiles) * @param string $url the requested url which can contain an IdeaStream user's profile */ function wp_idea_stream_users_oembed_request_post_id($post_id = 0, $url = '') { // The post is not empty leave WordPress deal with it! if (!empty($post_id)) { return $post_id; } $utility_page = wp_idea_stream_is_embed_profile(); // No utility page, stop! if (!$utility_page) { return $post_id; } // Get the WP Rewrites global $wp_rewrite; $extra_rules = $wp_rewrite->extra_rules_top; if (empty($extra_rules)) { return $post_id; } // Parse the url $parse_url = parse_url($url); // Pretty permalinks: Loop through each extra rules to find the username or user id if ($wp_rewrite->using_permalinks() && isset($parse_url['path']) && false !== strpos($parse_url['path'], wp_idea_stream_user_slug())) { // Loop through each extra rules to find the username or user id foreach ((array) $extra_rules as $match => $query) { if (preg_match("#^{$match}#", str_replace(trailingslashit(home_url()), '', $url), $matches)) { if (isset($matches[1])) { $user = $matches[1]; break; } } } // Default permalinks: find the query var containing the user_id } elseif (isset($parse_url['query'])) { // Parse the query string parse_str($parse_url['query'], $query_vars); if (!empty($query_vars[wp_idea_stream_user_rewrite_id()])) { $user = (int) $query_vars[wp_idea_stream_user_rewrite_id()]; } } // No username or user id found stop if (empty($user)) { return $post_id; } if (!is_numeric($user)) { // Get user by his username $user = wp_idea_stream_users_get_user_data('slug', $user); } else { // Get user by his id $user = wp_idea_stream_users_get_user_data('id', $user); } // A user was found globalize it for a latter use and init some filters if (is_a($user, 'WP_User')) { // If the user is a spammer, do not allow his profile to be embed if (true === apply_filters('wp_idea_stream_users_is_spammy', is_multisite() && is_user_spammy($user), $user)) { return $post_id; } // Set the utility page as the post id $post_id = $utility_page; wp_idea_stream_set_idea_var('embed_user_data', $user); // Temporarly only! add_filter('post_type_link', 'wp_idea_stream_users_oembed_link', 10, 2); add_filter('the_title', 'wp_idea_stream_users_oembed_title', 10, 2); } return $post_id; }