Adopt reusable CI standard + PHPUnit conversion (#22)
Squash-merge of PR #22: adopt shared reusable CI workflow, convert PHPUnit to stubs, update branch-protection contexts.
QA-approved at 05d8094a1d. All required CI checks green.
Agent-Session: 2026-06-17-prcore-ci-deploy
This commit is contained in:
@@ -1,6 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Peptide Cpt.
|
||||
*
|
||||
* @package Peptide_Repo_Core
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Defines peptide CPT with REST support, archive, and meta fields
|
||||
*
|
||||
* @package Peptide_Repo_Core
|
||||
*/
|
||||
|
||||
/**
|
||||
* Registers the peptide custom post type and associated taxonomy.
|
||||
*
|
||||
@@ -17,13 +29,25 @@ declare(strict_types=1);
|
||||
*/
|
||||
class PR_Core_Peptide_CPT {
|
||||
|
||||
/** @var string Post type slug (owned by PR Core since v0.2.0; PSA previously registered this). */
|
||||
/**
|
||||
* Post type slug (owned by PR Core since v0.2.0; PSA previously registered this).
|
||||
*
|
||||
* @var string Post type slug (owned by PR Core since v0.2.0; PSA previously registered this).
|
||||
*/
|
||||
public const POST_TYPE = 'peptide';
|
||||
|
||||
/** @var string Taxonomy: category (e.g., GLP-1 agonist). */
|
||||
/**
|
||||
* Taxonomy: category (e.g., GLP-1 agonist).
|
||||
*
|
||||
* @var string Taxonomy: category (e.g., GLP-1 agonist).
|
||||
*/
|
||||
public const TAX_CATEGORY = 'peptide_category';
|
||||
|
||||
/** @var string Capability required for editing peptide data. */
|
||||
/**
|
||||
* Capability required for editing peptide data.
|
||||
*
|
||||
* @var string Capability required for editing peptide data.
|
||||
*/
|
||||
public const CAPABILITY = 'manage_peptide_content';
|
||||
|
||||
/**
|
||||
@@ -31,26 +55,26 @@ class PR_Core_Peptide_CPT {
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public const EVIDENCE_STRENGTHS = [
|
||||
public const EVIDENCE_STRENGTHS = array(
|
||||
'preclinical',
|
||||
'case-series',
|
||||
'observational',
|
||||
'rct-small',
|
||||
'rct-large',
|
||||
'meta-analysis',
|
||||
];
|
||||
);
|
||||
|
||||
/**
|
||||
* Editorial review status enum values.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public const REVIEW_STATUSES = [
|
||||
public const REVIEW_STATUSES = array(
|
||||
'draft',
|
||||
'in-review',
|
||||
'published',
|
||||
'retired',
|
||||
];
|
||||
);
|
||||
|
||||
/**
|
||||
* Post-meta field definitions (1:1 with peptide).
|
||||
@@ -59,115 +83,7 @@ class PR_Core_Peptide_CPT {
|
||||
* @return array<string, array<string, mixed>>
|
||||
*/
|
||||
public static function get_meta_fields(): array {
|
||||
return [
|
||||
'display_name' => [
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
],
|
||||
'aliases' => [
|
||||
'type' => 'string',
|
||||
'default' => '[]',
|
||||
'sanitize' => [ PR_Core_Schema_Sanitizers::class, 'sanitize_json_array' ],
|
||||
],
|
||||
'molecular_formula' => [
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
],
|
||||
'molecular_weight' => [
|
||||
'type' => 'number',
|
||||
'default' => 0,
|
||||
'sanitize' => 'floatval',
|
||||
],
|
||||
'cas_number' => [
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
],
|
||||
'drugbank_id' => [
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
],
|
||||
'chembl_id' => [
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
],
|
||||
'evidence_strength' => [
|
||||
'type' => 'string',
|
||||
'default' => 'preclinical',
|
||||
'sanitize' => [ __CLASS__, 'sanitize_evidence_strength' ],
|
||||
],
|
||||
'editorial_review_status' => [
|
||||
'type' => 'string',
|
||||
'default' => 'draft',
|
||||
'sanitize' => [ __CLASS__, 'sanitize_review_status' ],
|
||||
],
|
||||
'last_editorial_review_at' => [
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
],
|
||||
'medical_editor_id' => [
|
||||
'type' => 'integer',
|
||||
'default' => 0,
|
||||
'sanitize' => 'absint',
|
||||
],
|
||||
'_pr_last_source_verified' => [
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
],
|
||||
'_pr_last_reviewed' => [
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
],
|
||||
'_pr_next_review_by' => [
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
],
|
||||
'_pr_verification_velocity' => [
|
||||
'type' => 'string',
|
||||
'default' => 'medium',
|
||||
'sanitize' => [ PR_Core_Verification_Sanitizers::class, 'sanitize_velocity' ],
|
||||
],
|
||||
'_pr_verification_notes' => [
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_textarea_field',
|
||||
],
|
||||
'_pr_verification_status' => [
|
||||
'type' => 'string',
|
||||
'default' => 'current',
|
||||
'sanitize' => [ PR_Core_Verification_Sanitizers::class, 'sanitize_status' ],
|
||||
],
|
||||
// Schema-input meta (v0.6.0): molecular data sourced from PSA psa_* keys via migration 0004.
|
||||
'_pr_molecular_formula' => [
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => [ PR_Core_Schema_Sanitizers::class, 'sanitize_molecular_formula' ],
|
||||
],
|
||||
'_pr_molecular_weight' => [
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => [ PR_Core_Schema_Sanitizers::class, 'sanitize_molecular_weight_string' ],
|
||||
],
|
||||
'_pr_aliases' => [
|
||||
'type' => 'string',
|
||||
'default' => '[]',
|
||||
'sanitize' => [ PR_Core_Schema_Sanitizers::class, 'sanitize_json_array' ],
|
||||
],
|
||||
// FAQ items (v0.6.0): [{question, answer}] JSON for FAQPage schema. Populated by CMO content sprint.
|
||||
'_pr_faq_items' => [
|
||||
'type' => 'string',
|
||||
'default' => '[]',
|
||||
'sanitize' => [ PR_Core_Schema_Sanitizers::class, 'sanitize_faq_items' ],
|
||||
],
|
||||
];
|
||||
return PR_Core_Peptide_Meta_Schema::get_fields();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,9 +92,9 @@ class PR_Core_Peptide_CPT {
|
||||
* @return void
|
||||
*/
|
||||
public function register_hooks(): void {
|
||||
add_action( 'init', [ __CLASS__, 'register_peptide_post_type' ] );
|
||||
add_action( 'init', [ __CLASS__, 'register_taxonomies' ] );
|
||||
add_action( 'init', [ __CLASS__, 'register_meta_fields' ] );
|
||||
add_action( 'init', array( __CLASS__, 'register_peptide_post_type' ) );
|
||||
add_action( 'init', array( __CLASS__, 'register_taxonomies' ) );
|
||||
add_action( 'init', array( __CLASS__, 'register_meta_fields' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,7 +109,7 @@ class PR_Core_Peptide_CPT {
|
||||
return;
|
||||
}
|
||||
|
||||
$labels = [
|
||||
$labels = array(
|
||||
'name' => __( 'Peptides', 'peptide-repo-core' ),
|
||||
'singular_name' => __( 'Peptide', 'peptide-repo-core' ),
|
||||
'add_new_item' => __( 'Add New Peptide', 'peptide-repo-core' ),
|
||||
@@ -205,11 +121,11 @@ class PR_Core_Peptide_CPT {
|
||||
'not_found_in_trash' => __( 'No peptides found in trash', 'peptide-repo-core' ),
|
||||
'all_items' => __( 'All Peptides', 'peptide-repo-core' ),
|
||||
'menu_name' => __( 'Peptides', 'peptide-repo-core' ),
|
||||
];
|
||||
);
|
||||
|
||||
// Args harmonized superset of PR Core + PSA for 89 existing posts.
|
||||
// Supports union, capability/role perms preserved, slugs unchanged.
|
||||
$args = [
|
||||
$args = array(
|
||||
'labels' => $labels,
|
||||
'public' => true,
|
||||
'publicly_queryable' => true,
|
||||
@@ -218,9 +134,9 @@ class PR_Core_Peptide_CPT {
|
||||
'show_in_nav_menus' => true,
|
||||
'show_in_rest' => true,
|
||||
'rest_base' => 'peptides',
|
||||
// Note: 'rest_namespace' is deliberately omitted. Custom namespaces prevent
|
||||
// Gutenberg's block editor from loading posts for editing (it fetches the
|
||||
// hardcoded wp/v2 REST route). WordPress defaults to wp/v2 — appropriate for
|
||||
// Note: 'rest_namespace' is deliberately omitted. Custom namespaces prevent.
|
||||
// Gutenberg's block editor from loading posts for editing (it fetches the.
|
||||
// hardcoded wp/v2 REST route). WordPress defaults to wp/v2 — appropriate for.
|
||||
// this CPT — and keeps the REST endpoint at /wp-json/wp/v2/peptides/.
|
||||
'menu_position' => 25,
|
||||
'menu_icon' => 'dashicons-database',
|
||||
@@ -228,9 +144,12 @@ class PR_Core_Peptide_CPT {
|
||||
'map_meta_cap' => true,
|
||||
'hierarchical' => false,
|
||||
'has_archive' => true,
|
||||
'rewrite' => [ 'slug' => 'peptides', 'with_front' => false ],
|
||||
'supports' => [ 'title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'custom-fields' ],
|
||||
];
|
||||
'rewrite' => array(
|
||||
'slug' => 'peptides',
|
||||
'with_front' => false,
|
||||
),
|
||||
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'custom-fields' ),
|
||||
);
|
||||
register_post_type( self::POST_TYPE, $args );
|
||||
}
|
||||
|
||||
@@ -246,19 +165,26 @@ class PR_Core_Peptide_CPT {
|
||||
return;
|
||||
}
|
||||
|
||||
register_taxonomy( self::TAX_CATEGORY, self::POST_TYPE, [
|
||||
'labels' => [
|
||||
'name' => __( 'Peptide Categories', 'peptide-repo-core' ),
|
||||
'singular_name' => __( 'Peptide Category', 'peptide-repo-core' ),
|
||||
],
|
||||
'public' => true,
|
||||
'publicly_queryable' => true,
|
||||
'show_in_rest' => true,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'hierarchical' => true,
|
||||
'rewrite' => [ 'slug' => 'peptide-category', 'with_front' => false ],
|
||||
] );
|
||||
register_taxonomy(
|
||||
self::TAX_CATEGORY,
|
||||
self::POST_TYPE,
|
||||
array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Peptide Categories', 'peptide-repo-core' ),
|
||||
'singular_name' => __( 'Peptide Category', 'peptide-repo-core' ),
|
||||
),
|
||||
'public' => true,
|
||||
'publicly_queryable' => true,
|
||||
'show_in_rest' => true,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'hierarchical' => true,
|
||||
'rewrite' => array(
|
||||
'slug' => 'peptide-category',
|
||||
'with_front' => false,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -268,26 +194,40 @@ class PR_Core_Peptide_CPT {
|
||||
*/
|
||||
public static function register_meta_fields(): void {
|
||||
foreach ( self::get_meta_fields() as $key => $config ) {
|
||||
register_post_meta( self::POST_TYPE, $key, [
|
||||
'type' => $config['type'],
|
||||
'single' => true,
|
||||
'default' => $config['default'],
|
||||
'show_in_rest' => true,
|
||||
'sanitize_callback' => $config['sanitize'],
|
||||
'auth_callback' => static function () {
|
||||
return current_user_can( self::CAPABILITY );
|
||||
},
|
||||
] );
|
||||
register_post_meta(
|
||||
self::POST_TYPE,
|
||||
$key,
|
||||
array(
|
||||
'type' => $config['type'],
|
||||
'single' => true,
|
||||
'default' => $config['default'],
|
||||
'show_in_rest' => true,
|
||||
'sanitize_callback' => $config['sanitize'],
|
||||
'auth_callback' => static function () {
|
||||
return current_user_can( self::CAPABILITY );
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** Sanitize evidence_strength to allowed enum values. */
|
||||
/**
|
||||
* Sanitize evidence_strength to allowed enum values.
|
||||
*
|
||||
* @param mixed $value Raw input value.
|
||||
* @return string
|
||||
*/
|
||||
public static function sanitize_evidence_strength( $value ): string {
|
||||
$value = sanitize_text_field( (string) $value );
|
||||
return in_array( $value, self::EVIDENCE_STRENGTHS, true ) ? $value : 'preclinical';
|
||||
}
|
||||
|
||||
/** Sanitize editorial_review_status to allowed enum values. */
|
||||
/**
|
||||
* Sanitize editorial_review_status to allowed enum values.
|
||||
*
|
||||
* @param mixed $value Raw input value.
|
||||
* @return string
|
||||
*/
|
||||
public static function sanitize_review_status( $value ): string {
|
||||
$value = sanitize_text_field( (string) $value );
|
||||
return in_array( $value, self::REVIEW_STATUSES, true ) ? $value : 'draft';
|
||||
|
||||
144
includes/cpt/class-pr-core-peptide-meta-schema.php
Normal file
144
includes/cpt/class-pr-core-peptide-meta-schema.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* Peptide Meta Schema.
|
||||
*
|
||||
* @package Peptide_Repo_Core
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Returns the complete meta field definition map used by PR_Core_Peptide_CPT
|
||||
*
|
||||
* @package Peptide_Repo_Core
|
||||
*/
|
||||
|
||||
/**
|
||||
* Meta field schema definitions for the peptide CPT.
|
||||
*
|
||||
* What: Returns the complete meta field definition map used by PR_Core_Peptide_CPT.
|
||||
* Who calls it: PR_Core_Peptide_CPT::get_meta_fields() delegates here.
|
||||
* Dependencies: PR_Core_Peptide_CPT (for sanitize callbacks), PR_Core_Schema_Sanitizers,
|
||||
* PR_Core_Verification_Sanitizers.
|
||||
*
|
||||
* @see cpt/class-pr-core-peptide-cpt.php — Consumer of this schema.
|
||||
*/
|
||||
class PR_Core_Peptide_Meta_Schema {
|
||||
|
||||
/**
|
||||
* Return the full meta field definition array for the peptide CPT.
|
||||
*
|
||||
* Keys map to meta_key strings; values are arrays with type, default, and sanitize.
|
||||
*
|
||||
* @return array<string, array<string, mixed>>
|
||||
*/
|
||||
public static function get_fields(): array {
|
||||
return array(
|
||||
'display_name' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
),
|
||||
'aliases' => array(
|
||||
'type' => 'string',
|
||||
'default' => '[]',
|
||||
'sanitize' => array( PR_Core_Schema_Sanitizers::class, 'sanitize_json_array' ),
|
||||
),
|
||||
'molecular_formula' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
),
|
||||
'molecular_weight' => array(
|
||||
'type' => 'number',
|
||||
'default' => 0,
|
||||
'sanitize' => 'floatval',
|
||||
),
|
||||
'cas_number' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
),
|
||||
'drugbank_id' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
),
|
||||
'chembl_id' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
),
|
||||
'evidence_strength' => array(
|
||||
'type' => 'string',
|
||||
'default' => 'preclinical',
|
||||
'sanitize' => array( PR_Core_Peptide_CPT::class, 'sanitize_evidence_strength' ),
|
||||
),
|
||||
'editorial_review_status' => array(
|
||||
'type' => 'string',
|
||||
'default' => 'draft',
|
||||
'sanitize' => array( PR_Core_Peptide_CPT::class, 'sanitize_review_status' ),
|
||||
),
|
||||
'last_editorial_review_at' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
),
|
||||
'medical_editor_id' => array(
|
||||
'type' => 'integer',
|
||||
'default' => 0,
|
||||
'sanitize' => 'absint',
|
||||
),
|
||||
'_pr_last_source_verified' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
),
|
||||
'_pr_last_reviewed' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
),
|
||||
'_pr_next_review_by' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_text_field',
|
||||
),
|
||||
'_pr_verification_velocity' => array(
|
||||
'type' => 'string',
|
||||
'default' => 'medium',
|
||||
'sanitize' => array( PR_Core_Verification_Sanitizers::class, 'sanitize_velocity' ),
|
||||
),
|
||||
'_pr_verification_notes' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => 'sanitize_textarea_field',
|
||||
),
|
||||
'_pr_verification_status' => array(
|
||||
'type' => 'string',
|
||||
'default' => 'current',
|
||||
'sanitize' => array( PR_Core_Verification_Sanitizers::class, 'sanitize_status' ),
|
||||
),
|
||||
'_pr_molecular_formula' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => array( PR_Core_Schema_Sanitizers::class, 'sanitize_molecular_formula' ),
|
||||
),
|
||||
'_pr_molecular_weight' => array(
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
'sanitize' => array( PR_Core_Schema_Sanitizers::class, 'sanitize_molecular_weight_string' ),
|
||||
),
|
||||
'_pr_aliases' => array(
|
||||
'type' => 'string',
|
||||
'default' => '[]',
|
||||
'sanitize' => array( PR_Core_Schema_Sanitizers::class, 'sanitize_json_array' ),
|
||||
),
|
||||
'_pr_faq_items' => array(
|
||||
'type' => 'string',
|
||||
'default' => '[]',
|
||||
'sanitize' => array( PR_Core_Schema_Sanitizers::class, 'sanitize_faq_items' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Repo Daily Cpt.
|
||||
*
|
||||
* @package Peptide_Repo_Core
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Defines the `repo_daily` CPT for articles, guides, comparisons, and news
|
||||
*
|
||||
* @package Peptide_Repo_Core
|
||||
*/
|
||||
|
||||
/**
|
||||
* Registers the repo_daily custom post type for editorial publications.
|
||||
*
|
||||
@@ -18,7 +30,11 @@ declare(strict_types=1);
|
||||
*/
|
||||
class PR_Core_Repo_Daily_CPT {
|
||||
|
||||
/** @var string Post type slug (repo_daily). */
|
||||
/**
|
||||
* Post type slug (repo_daily).
|
||||
*
|
||||
* @var string Post type slug (repo_daily).
|
||||
*/
|
||||
public const POST_TYPE = 'repo_daily';
|
||||
|
||||
/**
|
||||
@@ -27,7 +43,7 @@ class PR_Core_Repo_Daily_CPT {
|
||||
* @return void
|
||||
*/
|
||||
public function register_hooks(): void {
|
||||
add_action( 'init', [ __CLASS__, 'register_post_type' ] );
|
||||
add_action( 'init', array( __CLASS__, 'register_post_type' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +58,7 @@ class PR_Core_Repo_Daily_CPT {
|
||||
return;
|
||||
}
|
||||
|
||||
$labels = [
|
||||
$labels = array(
|
||||
'name' => __( 'Repo Daily', 'peptide-repo-core' ),
|
||||
'singular_name' => __( 'Repo Daily', 'peptide-repo-core' ),
|
||||
'add_new_item' => __( 'Add New Article', 'peptide-repo-core' ),
|
||||
@@ -54,9 +70,9 @@ class PR_Core_Repo_Daily_CPT {
|
||||
'not_found_in_trash' => __( 'No articles found in trash', 'peptide-repo-core' ),
|
||||
'all_items' => __( 'All Articles', 'peptide-repo-core' ),
|
||||
'menu_name' => __( 'Repo Daily', 'peptide-repo-core' ),
|
||||
];
|
||||
);
|
||||
|
||||
$args = [
|
||||
$args = array(
|
||||
'labels' => $labels,
|
||||
'public' => true,
|
||||
'publicly_queryable' => true,
|
||||
@@ -71,9 +87,12 @@ class PR_Core_Repo_Daily_CPT {
|
||||
'map_meta_cap' => true,
|
||||
'hierarchical' => false,
|
||||
'has_archive' => true,
|
||||
'rewrite' => [ 'slug' => 'daily', 'with_front' => false ],
|
||||
'supports' => [ 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields' ],
|
||||
];
|
||||
'rewrite' => array(
|
||||
'slug' => 'daily',
|
||||
'with_front' => false,
|
||||
),
|
||||
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields' ),
|
||||
);
|
||||
|
||||
register_post_type( self::POST_TYPE, $args );
|
||||
}
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema Sanitizers.
|
||||
*
|
||||
* @package Peptide_Repo_Core
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Static sanitizer methods for _pr_molecular_formula, _pr_molecular_weight,
|
||||
*
|
||||
* @package Peptide_Repo_Core
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sanitizers for v0.6.0 schema-input meta fields.
|
||||
*
|
||||
@@ -67,8 +79,8 @@ class PR_Core_Schema_Sanitizers {
|
||||
return '';
|
||||
}
|
||||
// 3. Extract the maximal leading run of valid element tokens and separators.
|
||||
// A valid run must start with an element token ([A-Z][a-z]?\d*), not a separator.
|
||||
$pattern = '/^((?:' . self::FORMULA_TOKEN . '|' . self::FORMULA_SEP . ')+)/u';
|
||||
// A valid run must start with an element token ([A-Z][a-z]?\d*), not a separator.
|
||||
$pattern = '/^((?:' . self::FORMULA_TOKEN . '|' . self::FORMULA_SEP . ')+)/u'; // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
|
||||
if ( preg_match( $pattern, $value, $m ) ) {
|
||||
return $m[1];
|
||||
}
|
||||
@@ -132,7 +144,7 @@ class PR_Core_Schema_Sanitizers {
|
||||
return '[]';
|
||||
}
|
||||
|
||||
$clean = [];
|
||||
$clean = array();
|
||||
foreach ( $value as $item ) {
|
||||
if ( ! is_array( $item ) ) {
|
||||
continue;
|
||||
@@ -140,13 +152,13 @@ class PR_Core_Schema_Sanitizers {
|
||||
$question = sanitize_text_field( (string) ( $item['question'] ?? '' ) );
|
||||
$answer = sanitize_textarea_field( (string) ( $item['answer'] ?? '' ) );
|
||||
if ( '' !== $question && '' !== $answer ) {
|
||||
$clean[] = [
|
||||
$clean[] = array(
|
||||
'question' => $question,
|
||||
'answer' => $answer,
|
||||
];
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return wp_json_encode( $clean, JSON_UNESCAPED_UNICODE ) ?: '[]';
|
||||
return wp_json_encode( $clean, JSON_UNESCAPED_UNICODE ) ?: '[]'; // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Topic Taxonomy.
|
||||
*
|
||||
* @package Peptide_Repo_Core
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Defines the `peptide_topic` taxonomy attached to the post CPT
|
||||
*
|
||||
* @package Peptide_Repo_Core
|
||||
*/
|
||||
|
||||
/**
|
||||
* Registers the peptide_topic taxonomy for linking blog posts to peptides.
|
||||
*
|
||||
@@ -18,7 +30,11 @@ declare(strict_types=1);
|
||||
*/
|
||||
class PR_Core_Topic_Taxonomy {
|
||||
|
||||
/** @var string Taxonomy: topic (links blog posts to peptides by slug). */
|
||||
/**
|
||||
* Taxonomy: topic (links blog posts to peptides by slug).
|
||||
*
|
||||
* @var string Taxonomy: topic (links blog posts to peptides by slug).
|
||||
*/
|
||||
public const TAX_TOPIC = 'peptide_topic';
|
||||
|
||||
/**
|
||||
@@ -27,7 +43,7 @@ class PR_Core_Topic_Taxonomy {
|
||||
* @return void
|
||||
*/
|
||||
public function register_hooks(): void {
|
||||
add_action( 'init', [ __CLASS__, 'register_topic_taxonomy' ] );
|
||||
add_action( 'init', array( __CLASS__, 'register_topic_taxonomy' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,18 +61,25 @@ class PR_Core_Topic_Taxonomy {
|
||||
return;
|
||||
}
|
||||
|
||||
register_taxonomy( self::TAX_TOPIC, 'post', [
|
||||
'labels' => [
|
||||
'name' => __( 'Peptide Topics', 'peptide-repo-core' ),
|
||||
'singular_name' => __( 'Peptide Topic', 'peptide-repo-core' ),
|
||||
],
|
||||
'public' => true,
|
||||
'publicly_queryable' => true,
|
||||
'show_in_rest' => true,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'hierarchical' => false,
|
||||
'rewrite' => [ 'slug' => 'peptide-topic', 'with_front' => false ],
|
||||
] );
|
||||
register_taxonomy(
|
||||
self::TAX_TOPIC,
|
||||
'post',
|
||||
array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Peptide Topics', 'peptide-repo-core' ),
|
||||
'singular_name' => __( 'Peptide Topic', 'peptide-repo-core' ),
|
||||
),
|
||||
'public' => true,
|
||||
'publicly_queryable' => true,
|
||||
'show_in_rest' => true,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'hierarchical' => false,
|
||||
'rewrite' => array(
|
||||
'slug' => 'peptide-topic',
|
||||
'with_front' => false,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Verification Sanitizers.
|
||||
*
|
||||
* @package Peptide_Repo_Core
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Standalone sanitization functions for verification_velocity and verification_status fields
|
||||
*
|
||||
* @package Peptide_Repo_Core
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sanitizers for verification meta fields.
|
||||
*
|
||||
@@ -19,7 +31,7 @@ class PR_Core_Verification_Sanitizers {
|
||||
* @return string Valid enum value (low, medium, high).
|
||||
*/
|
||||
public static function sanitize_velocity( string $value ): string {
|
||||
return in_array( $value, [ 'low', 'medium', 'high' ], true ) ? $value : 'medium';
|
||||
return in_array( $value, array( 'low', 'medium', 'high' ), true ) ? $value : 'medium';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,6 +41,6 @@ class PR_Core_Verification_Sanitizers {
|
||||
* @return string Valid enum value (current, due, overdue).
|
||||
*/
|
||||
public static function sanitize_status( string $value ): string {
|
||||
return in_array( $value, [ 'current', 'due', 'overdue' ], true ) ? $value : 'current';
|
||||
return in_array( $value, array( 'current', 'due', 'overdue' ), true ) ? $value : 'current';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user