Skip to content

Commit

Permalink
See pewresearch/pewresearch-org@de358c6 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 27, 2024
1 parent 255a8b9 commit d681eb3
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 80 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
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;
}
}
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 d681eb3

Please sign in to comment.