Skip to content

Commit

Permalink
See pewresearch/pewresearch-org@769e9bd from refs/heads/main
Browse files Browse the repository at this point in the history
  • Loading branch information
prcdevgitbot committed May 20, 2024
1 parent 82d0029 commit 7c01953
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
13 changes: 4 additions & 9 deletions includes/permalink-rewrites/class-permalink-rewrites.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
use WP_Error;
use WP_REST_Request;

/**
* @NOTE: This class is used to filter and structure rewrite rules, tags, and query vars for the PRC Platform.
* You will find most of the rewrite rules in taxonomies/research-teams, as this taxonomy drives most of the custom permalink structure for objects on PRC-Platform.
*/
class Permalink_Rewrites {
/**
* The version of this plugin.
Expand Down Expand Up @@ -30,22 +34,13 @@ public function __construct( $version, $loader ) {

public function init($loader = null) {
if ( null !== $loader ) {
$loader->add_filter( 'robots_txt', $this, 'manage_robots_txt', 10, 2 );
$loader->add_action( 'init', $this, 'register_rewrites' );
$loader->add_action( 'init', $this, 'register_tags' );
$loader->add_filter( 'query_vars', $this, 'register_query_vars' );
$loader->add_filter( 'prc_api_endpoints', $this, 'register_endpoint' );
}
}

function manage_robots_txt( $output, $public ) {
// Blocking search pages from googlebot
$output .= 'Disallow: /search/' . PHP_EOL;
$output .= 'Disallow: /search' . PHP_EOL;
$output .= 'Disallow: /?s=' . PHP_EOL;
return $output;
}

/**
* Registers the rewrite rules for PRC Platform with WordPress.
* @hook init
Expand Down
7 changes: 4 additions & 3 deletions includes/taxonomies/class-research-teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,23 @@ public function add_rewrite_rules($rules) {
$new_rules[$term_name . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)(?:/([0-9]+))?/embed/?$'] = 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&iframe=true';
$new_rules[$term_name . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)(?:/([0-9]+))?/iframe/?$'] = 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&iframe=true';
// Add attachment rule:
$new_rules[$term_name . '/[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/?[^/iframe]$'] = 'index.php?attachment=$matches[1]';
$new_rules[$term_name . '/[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/([^/]+)/?$'] = 'index.php?attachment=$matches[1]';
} else if ( 'fact-sheet' === $post_type ) {
$new_rules[$term_name . '/fact-sheet/([^/]+)/?$'] = 'index.php?post_type=fact-sheet&name=$matches[1]';
// Add attachment rule:
$new_rules[$term_name . '/fact-sheet/[^/]+/([^/]+)/?$'] = 'index.php?attachment=$matches[1]';
} else if ( 'quiz' === $post_type ) {
// Add /quiz rules:
$new_rules[$term_name . '/quiz/([^/]+)/?$'] = 'index.php?post_type=quiz&name=$matches[1]';
// Add attachment rule:
$new_rules[$term_name . '/quiz/[^/]+/([^/]+)/?[^/iframe]$'] = 'index.php?attachment=$matches[1]';
// Add /results rules:
$new_rules[$term_name . '/quiz/([^/]+)/results/?$'] = 'index.php?post_type=quiz&name=$matches[1]&showResults=1';
// A new, cacheable, results archetype rule.
$new_rules[$term_name . '/quiz/([^/]+)/results/([^/]+)/?$'] = 'index.php?post_type=quiz&name=$matches[1]&showResults=1&archetype=$matches[2]';
// Add iframe and embed rules:
$new_rules[$term_name . '/quiz/([^/]+)/embed/?$'] = 'index.php?post_type=quiz&name=$matches[1]&iframe=true';
$new_rules[$term_name . '/quiz/([^/]+)/iframe/?$'] = 'index.php?post_type=quiz&name=$matches[1]&iframe=true';
// Add attachment rule:
$new_rules[$term_name . '/quiz/[^/]+/([^/]+)/?$'] = 'index.php?attachment=$matches[1]';
} else if ( 'feature' === $post_type ) {
$new_rules[$term_name . '/feature/([^/]+)/?$'] = 'index.php?post_type=feature&name=$matches[1]';
// Add attachment rule, very, very specific. This will only hit for attachment names that are 5 or more characters long.
Expand Down

0 comments on commit 7c01953

Please sign in to comment.