Skip to content

Commit

Permalink
See pewresearch/pewresearch-org@279d2d4 from refs/heads/main
Browse files Browse the repository at this point in the history
  • Loading branch information
prcdevgitbot committed Jun 12, 2024
1 parent 76c3943 commit b1c57e0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
2 changes: 2 additions & 0 deletions includes/class-platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private function load_dependencies() {
$this->include('mailchimp/class-mailchimp.php');
$this->include('media/class-media.php');
$this->include('multisite-post-migration/class-multisite-post-migration.php');
$this->include('newrelic/class-newrelic.php');
$this->include('newsletter/class-newsletter.php');
$this->include('permalink-rewrites/class-permalink-rewrites.php');
$this->include('post-publish-pipeline/class-post-publish-pipeline.php');
Expand Down Expand Up @@ -190,6 +191,7 @@ function() {
}
);
new Multisite_Post_Migration( $this->get_version(), $this->get_loader() );
new Newrelic( $this->get_version(), $this->get_loader() );
new Newsletter( $this->get_version(), $this->get_loader() );
new Permalink_Rewrites( $this->version, $this->get_loader() );
new Post_Publish_Pipeline( $this->get_version(), $this->get_loader() );
Expand Down
33 changes: 33 additions & 0 deletions includes/newrelic/class-newrelic.php

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions includes/newrelic/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Silence is golden
27 changes: 26 additions & 1 deletion includes/taxonomies/class-research-teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct($loader) {
$loader->add_filter( 'post_link', $this, 'modify_post_permalinks', 10, 2 );
$loader->add_filter( 'post_type_link', $this, 'modify_post_permalinks', 10, 2 );
$loader->add_filter( 'rewrite_rules_array', $this, 'add_rewrite_rules', 10, 1 );
$loader->add_filter( 'facetwp_preload_url_vars', $this, 'rewrite_datasets_archives', 10, 1 );
}

/**
Expand Down Expand Up @@ -134,7 +135,7 @@ public function add_rewrite_rules($rules) {
$new_rules[$term_name . '/feature/[^/]+/([^/]{5,})/?$'] = 'index.php?attachment=$matches[1]';
// $new_rules[$term_name . '/feature/([^/]+)/([^/]{5,})/?$'] = 'index.php?attachment=$matches[1]';
} else if ( 'dataset' === $post_type ) {
$new_rules[$term_name . '/datasets'] = 'index.php?post_type=dataset&research-teams=' . $term_name;
$new_rules[$term_name . '/datasets'] = 'index.php?post_type=dataset';
$new_rules[$term_name . '/dataset/([^/]+)/?$'] = 'index.php?datasets=$matches[1]';
// Add attachment rule:
$new_rules[$term_name . '/dataset/[^/]+/([^/]+)/?$'] = 'index.php?attachment=$matches[1]';
Expand All @@ -144,6 +145,30 @@ public function add_rewrite_rules($rules) {
return array_merge($new_rules, $rules);
}

/**
* Rewrites pewresearch.org/{research-team-name}/datasets to preload the selected facet
* @hook facetwp_preload_url_vars
*/
public function rewrite_datasets_archives($url_vars) {
$current_url = FWP()->helper->get_uri();
if ( strpos( $current_url, 'datasets' ) === false ) {
return $url_vars;
}
$terms = get_terms(array(
'taxonomy' => self::$taxonomy,
'hide_empty' => false,
));
$term_names = array_map(function ($term) {
return $term->slug;
}, $terms);
foreach($term_names as $term_name) {
if ( strpos( $current_url, $term_name . '/datasets' ) !== false && empty( $url_vars['research_teams'] ) ){
$url_vars['research_teams'] = [ $term_name ];
}
}
return $url_vars;
}

/**
* Add rewrite tag to post permalinks.
* @hook post_link
Expand Down

0 comments on commit b1c57e0

Please sign in to comment.