Skip to content

Commit

Permalink
See pewresearch/pewresearch-org@e817c77 from refs/heads/release/5.0-b…
Browse files Browse the repository at this point in the history
…w-templates
  • Loading branch information
prcdevgitbot committed Feb 28, 2024
1 parent 964ca66 commit d9dc2f1
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 149 deletions.
2 changes: 2 additions & 0 deletions includes/class-platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ private function load_dependencies() {
$this->include('post-report-package/class-post-report-package.php');
$this->include('post-visibility/class-post-visibility.php');
$this->include('press-releases/class-press-releases.php');
$this->include('decoded/class-decoded.php');
$this->include('related-posts/class-related-posts.php');
$this->include('rest-api/class-rest-api.php');
$this->include('rss/class-rss.php');
Expand Down Expand Up @@ -188,6 +189,7 @@ function() {
new Post_Report_Package( $this->get_version(), $this->get_loader() );
new Post_Visibility( $this->get_version(), $this->get_loader() );
new Press_Releases( $this->get_version(), $this->get_loader() );
new Decoded( $this->get_version(), $this->get_loader() );
new Related_Posts( $this->get_version(), $this->get_loader() );
new Rest_API( $this->get_version(), $this->get_loader() );
new RSS_Feeds( $this->get_version(), $this->get_loader() );
Expand Down
66 changes: 0 additions & 66 deletions includes/datasets/class-datasets.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?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 @@ -138,9 +136,6 @@ 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 @@ -193,67 +188,6 @@ 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
1 change: 1 addition & 0 deletions includes/decoded/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Decoded Blog
117 changes: 117 additions & 0 deletions includes/decoded/class-decoded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
namespace PRC\Platform;
use WP_Error;

class Decoded {
/**
* Post type name.
*
* @var string
*/
protected static $post_type = 'decoded';

/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;

public static $handle = 'prc-platform-decoded-post-type';

/**
* Initialize the class and set its properties.
* @param mixed $version
* @param mixed $loader
* @return void
*/
public function __construct( $version, $loader ) {
$this->version = $version;
$this->init($loader);
}

public function init($loader) {
if ( null !== $loader ) {
$loader->add_action( 'init', $this, 'register_type' );
$loader->add_filter( 'prc_load_gutenberg', $this, 'enable_gutenberg_ramp' );
$loader->add_filter( 'post_type_link', $this, 'get_decoded_permalink', 10, 3);
}
}

public function register_type() {
$labels = array(
'name' => _x( 'Decoded Posts', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Decoded Post', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Decoded', 'text_domain' ),
'name_admin_bar' => __( 'Decoded', 'text_domain' ),
'archives' => __( 'Decoded Archives', 'text_domain' ),
'parent_item_colon' => __( 'Parent Decoded Post:', 'text_domain' ),
'all_items' => __( 'All Decoded Posts', 'text_domain' ),
'add_new_item' => __( 'Add New Decoded Post', 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'new_item' => __( 'New Decoded Post', 'text_domain' ),
'edit_item' => __( 'Edit Decoded Post', 'text_domain' ),
'update_item' => __( 'Update Decoded Post', 'text_domain' ),
'view_item' => __( 'View Decoded Post', 'text_domain' ),
'search_items' => __( 'Search Decoded Posts', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into Decoded Post', 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this Decoded Post', 'text_domain' ),
'items_list' => __( 'Decoded Posts List', 'text_domain' ),
'items_list_navigation' => __( 'Decoded Posts List Navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter Decoded Posts List', 'text_domain' ),
);

$rewrite = array(
'slug' => 'decoded/%year%/%monthnum%',
'with_front' => true,
'pages' => true,
'feeds' => true,
);

$args = array(
'label' => __( 'Decoded', 'text_domain' ),
'description' => __( 'A post type for Decoded blog posts.', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions' ),
'taxonomies' => array( 'formats' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'show_in_rest' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'post',
);

register_post_type( self::$post_type, $args );
}

public function enable_gutenberg_ramp($post_types) {
array_push($post_types, self::$post_type);
return $post_types;
}

// Convert the %year% and %monthnum% placeholders in the post type's rewrite slug to the actual year and month.
public function get_decoded_permalink($url, $post) {
if ( self::$post_type == get_post_type($post) ) {
$url = str_replace( "%year%", get_the_date('Y'), $url );
$url = str_replace( "%monthnum%", get_the_date('m'), $url );
}
return $url;
}
}
5 changes: 4 additions & 1 deletion includes/interactives/blocks/loader-block/loader-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ public function render_interactive_loader_callback($attributes, $content, $block
));

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

$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: 20 additions & 0 deletions includes/interactives/blocks/loader-block/src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@
"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: 1 addition & 2 deletions includes/interactives/class-interactives.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,13 @@ 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'] : false;
$app_name = array_key_exists( 'appname', $args ) ? $args['appname'] : $args['appName'];

if ( ! $app_name ) {
return false;
Expand Down
64 changes: 0 additions & 64 deletions includes/user-permissions/class-user-permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ 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 @@ -80,66 +78,4 @@ 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: 0 additions & 16 deletions includes/user-permissions/user-roles.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@
"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 d9dc2f1

Please sign in to comment.