/**
  * Experimental code to parse and process the shortcode very early in the
  * WordPress execution stack. This allows the modification of its attributes
  * before being processed by the WordPress Shortcode API.
  *
  * @access private
  * @since  0.8
  * @static
  * @param  array  $posts
  * @param  object $WP_Query
  *
  * @return array
  */
 public static function parse($posts, $WP_Query)
 {
     $pattern = get_shortcode_regex();
     // Grab the array containing all query vars registered by Connections.
     $registeredQueryVars = cnRewrite::queryVars(array());
     foreach ($posts as $post) {
         // $WP_Query->queried_object_id -- This will only be set on pages, not posts. Why? Good question!
         // If we're in the main query, proceed!
         if (isset($WP_Query->queried_object_id) && $WP_Query->queried_object_id == $post->ID) {
             /*
              * $matches[0] == An array of all shortcodes that were found with its options.
              * $matches[1] == Unknown.
              * $matches[2] == An array of all shortcode tags that were found.
              * $matches[3] == An array of the shortcode options that were found.
              * $matches[4] == Unknown.
              * $matches[5] == Unknown.
              * $matches[6] == Unknown.
              */
             if (preg_match_all('/' . $pattern . '/s', $post->post_content, $matches) && array_key_exists(2, $matches)) {
                 // Build the results in a more usable format.
                 foreach ($matches[2] as $key => $shortcode) {
                     // Parse the shortcode atts.
                     self::$shortcode[$shortcode] = shortcode_parse_atts($matches[3][$key]);
                 }
                 // Show the just the search form w/o showing the intial results?
                 // If a Connections query var is set, show the results instead.
                 // if ( isset( $atts['initial_results'] )
                 // 	&& strtolower( $atts['initial_results'] ) == 'false'
                 // 	&& ! (bool) array_intersect( $registeredQueryVars, array_keys( (array) $WP_Query->query_vars ) )
                 // 	)
                 // {
                 // } else {
                 // 	// Rewrite the $atts array to prep it to be imploded.
                 // 	array_walk( $atts, create_function( '&$i,$k','$i=" $k=\"$i\"";' ) );
                 // 	$replace = '[' . $shortcode . ' ' . implode( ' ', $atts ) . ']';
                 // }
                 // All returns/end of lines and tabs should be removed so wpautop() doesn't insert <p> and <br> tags in the form output.
                 // $replace = str_replace( array( "\r\n", "\r", "\n", "\t" ), array( ' ', ' ', ' ', ' ' ), $replace );
                 // Replace the shortcode in the post with a new one based on the changes to $atts.
                 // $post->post_content = str_replace( $matches[0][ array_search( $shortcode, $matches[2] ) ], $replace, $post->post_content );
             }
         }
     }
     return $posts;
 }
 /**
  * Remove the comment feeds from th directory sub-pages.
  * This is to prevent search engine crawl errors / 404s.
  *
  * @access private
  * @since  0.7.9
  * @static
  *
  * @global $wp_query
  *
  * @return void
  */
 public static function removeCommentFeed()
 {
     global $wp_query;
     $registeredQueryVars = cnRewrite::queryVars(array());
     // var_dump($registeredQueryVars);var_dump($wp_query->query_vars);
     // var_dump( array_intersect( $registeredQueryVars, $wp_query->query_vars ) );
     // var_dump( array_keys( $wp_query->query_vars ) );
     if ((bool) array_intersect($registeredQueryVars, array_keys((array) $wp_query->query_vars))) {
         remove_action('wp_head', 'feed_links_extra', 3);
     }
 }
    }
    /**
     * Disable the canonical redirect when on the front page.
     *
     * NOTE: This is required to allow search queries to be properly redirected to the front page.
     * If this were not in place the user would be redirected to the blog home page.
     *
     * Reference:
     * http://wordpress.stackexchange.com/questions/51530/rewrite-rules-problem-when-rule-includes-homepage-slug
     *
     * @TODO  Perhaps I should check for the existance of any of the Connections query vars before
     * removing canonical redirect of the front page.
     *
     * @access private
     * @since 0.7.6.4
     * @param (string) $redirectURL  The URL to redirect to.
     * @param (string) $requestedURL The original requested URL.
     * @return (string)              URL
     */
    public static function frontPageCanonicalRedirect($redirectURL, $requestedURL)
    {
        // $homeID = cnSettingsAPI::get( 'connections', 'connections_home_page', 'page_id' );
        if (is_front_page() && get_option('show_on_front') == 'page') {
            return $requestedURL;
        }
        return $redirectURL;
    }
}
// Register all valid query variables.
cnRewrite::init();