Skip to content

Commit

Permalink
See pewresearch/pewresearch-org@6ad8f52 from refs/heads/release/5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
prcdevgitbot committed Mar 1, 2024
1 parent c126f4d commit c3890de
Show file tree
Hide file tree
Showing 10 changed files with 8,346 additions and 167 deletions.
66 changes: 66 additions & 0 deletions includes/datasets/class-datasets.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace PRC\Platform;
use TDS\Invalid_Input_Exception;
use TDS\get_related_post;
use TDS\get_related_term;
use WP_Error;
use WP_REST_Request;
use WP_REST_Response;
Expand Down Expand Up @@ -136,6 +138,9 @@ public function init($loader) {
$loader->add_filter( 'prc_api_endpoints', $this, 'register_dataset_endpoints' );
$loader->add_filter( 'prc_platform_rewrite_rules', $this, 'archive_rewrites' );

$loader->add_filter( 'post_type_link', $this, 'modify_dataset_permalink', 20, 2 );
$loader->add_action( 'admin_bar_menu', $this, 'modify_admin_bar_edit_link', 100 );

$download_logger = new Datasets_Download_Logger();
$loader->add_action( 'init', $download_logger, 'register_meta' );
$loader->add_action( 'rest_api_init', $download_logger, 'register_field' );
Expand Down Expand Up @@ -188,6 +193,67 @@ public function archive_rewrites($rewrite_rules) {
);
}

/**
* Modifies the dataset permalink to point to the datasets term archive permalink.
*
* @hook post_link
* @param string $url
* @param WP_Post $post
* @return string
*/
public function modify_dataset_permalink( $url, $post ) {
if ( 'publish' !== $post->post_status ) {
return $url;
}
if ( self::$post_object_name === $post->post_type ) {
// Get the matching term...
$dataset_term = \TDS\get_related_term( $post->ID );
if (!$dataset_term) {
return $url;
}
// get the term link
$matched_url = get_term_link( $dataset_term, self::$taxonomy_object_name );
if ( !is_wp_error( $matched_url ) ) {
return $matched_url;
}
}
return $url;
}

/**
* @hook admin_bar_menu
* @param mixed $admin_bar
* @return void
*/
public function modify_admin_bar_edit_link( $admin_bar ) {
if ( ! is_tax( self::$taxonomy_object_name ) ) {
return;
}

$term_id = get_queried_object()->term_id;
// get the associated post id...
$dataset_id = \TDS\get_related_post( $term_id, self::$taxonomy_object_name );

if ( is_wp_error( $dataset_id ) ) {
return;
}

$admin_bar->remove_menu( 'edit' );

$link = get_edit_post_link( $dataset_id );
$admin_bar->add_menu(
array(
'parent' => false,
'id' => 'edit_dataset',
'title' => __( 'Edit Dataset' ),
'href' => $link,
'meta' => array(
'title' => __( 'Edit Dataset' ),
),
)
);
}

/**
* Registers the download endpoint. Checks the nonce against user credentials and
* @return void
Expand Down
27 changes: 26 additions & 1 deletion includes/embeds/class-embeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Embeds {
'prc-block/tabs',
'prc-block/accordion-controller',
'prc-block/chart',
'prc-block/quiz'
'prc-block/audio-player',
'prc-block/quiz',
);

public static $handle = 'prc-platform-iframe-embeds';
Expand Down Expand Up @@ -344,6 +345,30 @@ public function template_default() {
html {
margin: 0!important;
}
.prc-platform__iframe__content {
container-type: inline-size;
container-name: prcIframeContent;
}
@container prcIframeContent (width < 480px) {
.wp-block-image.alignright,
.wp-block-image.alignleft {
float: none!important;
margin: auto!important;
margin-inline-start: auto!important;
margin-inline-end: auto!important;
}
}
@container prcIframeContent (width > 480px) {
.wp-block-image.alignright {
float: right!important;
margin: 5px 0px 15px 15px!important;
}

.wp-block-image.alignleft {
float: left!important;
margin: 5px 15px 15px 0px!important;
}
}
</style>
<?php
wp_footer();
Expand Down
Loading

0 comments on commit c3890de

Please sign in to comment.