Skip to content

Commit

Permalink
See pewresearch/pewresearch-org@0b44e99 from refs/heads/release/5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
prcdevgitbot committed Feb 28, 2024
1 parent 5af4c90 commit 014c89a
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 26 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
5 changes: 1 addition & 4 deletions includes/interactives/blocks/loader-block/loader-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ public function render_interactive_loader_callback($attributes, $content, $block
));

$is_legacy_wpackio = array_key_exists('legacyWpackIo', $attributes) && $attributes['legacyWpackIo'];
$is_legacy_s3 = array_key_exists('legacyAssetsS3', $attributes) && $attributes['legacyAssetsS3'];
// We are purposefully not looking for s3 legacy interactives. We're going to let those break.

$enqueued_handles = array();
if ( $is_legacy_wpackio ) {
wp_enqueue_script('firebase');
$enqueued_handles = $this->load_legacy_wpackIO($attributes['legacyWpackIo']);
} else if ( $is_legacy_s3 ) {
// Do nothing for now...
// @TODO: Build out the legacy assets S3 loader.
} else {
$enqueued_handles = $this->load($attributes['slug']);
}
Expand Down
20 changes: 0 additions & 20 deletions includes/interactives/blocks/loader-block/src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,6 @@
"type": "string"
},
"deps":{
"type": "array",
"items": {
"type": "string"
}
}
}
},
"legacyAssetsS3": {
"type": "object",
"properties": {
"path": {
"type": "string"
},
"react": {
"type": "string"
},
"libraries": {
"type": "string"
},
"styles": {
"type": "string"
}
}
Expand Down
3 changes: 2 additions & 1 deletion includes/interactives/class-interactives.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,14 @@ public function load_legacy_wpackIO($args) {
'version' => '1.0',
)
);
$args = \array_change_key_case($args, CASE_LOWER);
$enqueued = array();

if ( is_admin() ) {
return;
}

$app_name = array_key_exists( 'appname', $args ) ? $args['appname'] : $args['appName'];
$app_name = array_key_exists( 'appname', $args ) ? $args['appname'] : false;

if ( ! $app_name ) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion includes/staff-bylines/staff-info-panel/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function StaffInfoPanel() {
<ToggleControl
label={__('Display Byline Link')}
help={__(
'All staff are assigned a byline tem, however not all staff have a link to a byline archive "staff bio" page. If this staff member has a bio page, enable this option to link their byline to their bio page.',
'All staff are assigned a byline tem, however not all staff have a link to a byline archive "staff bio" page. If this staff member has a bio page, enable this option to link their byline to their bio page.'
)}
checked={bylineLinkEnabled}
onChange={() => {
Expand Down
64 changes: 64 additions & 0 deletions includes/user-permissions/class-user-permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public function init($loader = null) {
if ( null !== $loader ) {
$loader->add_filter( 'wpcom_vip_enable_two_factor', $this, 'enforce_two_factor', 10, 1 );
$loader->add_action( 'admin_init', $this, 'autoload_user_roles' );
$loader->add_action( 'init', $this, 'register_common_user_meta' );
$loader->add_action( 'register_new_user', $this, 'set_default_meta_on_new_user_creation', 10, 1 );
}
}

Expand Down Expand Up @@ -78,4 +80,66 @@ public function autoload_user_roles() {
public function enforce_two_factor($value) {
return defined('VIP_GO_APP_ENVIRONMENT') && 'production' === \VIP_GO_APP_ENVIRONMENT;
}

/**
* @hook init
* @return void
*/
public function register_common_user_meta() {
register_meta(
'user',
'prc_copilot_settings',
array(
'type' => 'object',
'description' => 'Settings for PRC Copilot plugin',
'single' => true,
'show_in_rest' => true,
)
);
register_meta(
'user',
'prc_staff_id',
array(
'type' => 'number',
'description' => 'Links a staff record to a user record. When a name is updated for a user the staff name is updated as well and vice versa.',
'single' => true,
'show_in_rest' => true,
)
);
register_meta(
'user',
'prc_user_beneficiary_id',
array(
'type' => 'number',
'description' => 'When a user is deleted this user is the benefeciary of their db records',
'single' => true,
'show_in_rest' => true,
)
);
}

/**
* Fires after a new user has been registered, checks for the existence of default meta and if none
* sets accordingly.
*
* @hook register_new_user
* @return void
*/
public function set_default_meta_on_new_user_creation($user_id) {
if ( ! $user_id ) {
return;
}
$copilot_defaults = array(
'allowed' => true,
'tokenBudget' => 1000,
'allowances' => array(
'excerpt' => true, // Do we allow the user to use the copilot excerpt generation function
'title' => true, // Do we allow the user to use the copilot title generation function
'content' => false, // Do we allow the user to use the copilot content generation function
)
);
if ( ! get_user_meta( $user_id, 'prc_copilot_settings', true ) ) {
add_user_meta( $user_id, 'prc_copilot_settings', $copilot_defaults, true );
}
}
}
16 changes: 16 additions & 0 deletions includes/user-permissions/user-roles.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@
"wpseo_edit_advanced_metadata": true,
"wpseo_bulk_edit": true
}
},
"comms-editor": {
"name": "Communications Editor",
"inherits": "editor",
"capabilities": {
"wpseo_manage_options": true,
"wpseo_edit_advanced_metadata": true,
"wpseo_bulk_edit": true
}
},
"designer": {
"name": "Designer",
"inherits": "editor",
"capabilities": {
"edit_theme_options": true
}
}
}
}

0 comments on commit 014c89a

Please sign in to comment.