query_vars['name'] ) ) return; // shoot the full archives if we're looking for that if ( $wp_query->query_vars['name'] == 'archives-json' || $wp_query->query_vars['name'] == 'newsletter_list-json' ) { $this->archive_output(); exit(); } // bail on non nd-archives file if ( !isset( $wp_query->query_vars['nd-archives'] ) ) return; // bail if we do have the post type included as just a json URL (bad URL) if ( isset( $wp_query->query_vars['name'] ) && $wp_query->query_vars['name'] == 'json' ) return; // do a quick check to ensure we have a json extension $query_base = $wp_query->query_vars['name']; // check the slug to make sure it's a parent. $base_check = preg_match( '/^n20/', $query_base ); if ( !$base_check ) return; // check slug to make sure we are calling json $name_check = preg_match( '/-json/', $query_base ); if ( !$name_check ) return; $query_name = str_replace( '-json', '', $query_base ); // passed all our checks, we're gold if ( isset( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'nd-archives' ) { $this->single_output( $query_name ); exit; } return; } /** * output JSON data for archive page */ public function archive_output() { header( 'HTTP/1.1 200' ); header( 'Content-type: application/json; charset=utf-8' ); $data = $this->archive_data(); $data = str_replace('\\/', '/', json_encode( $data ) ); echo $data; } /** * output JSON data for single issue page */ public function single_output( $query_name ) { header( 'HTTP/1.1 200' ); header( 'Content-type: application/json; charset=utf-8' ); $data = $this->single_data( $query_name ); $data = str_replace('\\/', '/', json_encode( $data ) ); echo $data; } /** * create our endpoints * */ public function json_endpoint() { // register our "json" endpoint add_rewrite_endpoint( '.json', EP_NONE ); } /** * add JSON into our vars */ public function json_vars( $vars ) { $vars[] = 'json'; return $vars; }