diff --git a/plugins/osi-features/inc/classes/class-plugin.php b/plugins/osi-features/inc/classes/class-plugin.php index 13adc89..8c536b9 100644 --- a/plugins/osi-features/inc/classes/class-plugin.php +++ b/plugins/osi-features/inc/classes/class-plugin.php @@ -52,7 +52,10 @@ public function load_post_types() { Post_Type_Board_Member::get_instance(); Post_Type_License::get_instance(); Post_Type_Meeting_Minutes::get_instance(); - Post_Type_Press_Mentions::get_instance(); + + // Get instance and initialize Press Mentions + $press_mentions = Post_Type_Press_Mentions::get_instance(); + $press_mentions->init(); } diff --git a/plugins/osi-features/inc/classes/post-types/class-post-type-press-mentions.php b/plugins/osi-features/inc/classes/post-types/class-post-type-press-mentions.php index 1fc4032..bfc988b 100644 --- a/plugins/osi-features/inc/classes/post-types/class-post-type-press-mentions.php +++ b/plugins/osi-features/inc/classes/post-types/class-post-type-press-mentions.php @@ -26,6 +26,15 @@ class Post_Type_Press_Mentions extends Base { */ const LABEL = 'Press mentions'; + /** + * Initialize the class and set up hooks + */ + public function init() { + \add_action( 'add_meta_boxes', array( $this, 'register_custom_fields' ) ); + \add_action( 'save_post_' . self::SLUG, array( $this, 'save_custom_fields' ), 10, 2 ); + \add_action( 'rest_api_init', array( $this, 'register_rest_fields' ) ); + } + /** * To get list of labels for post type. * @@ -33,7 +42,7 @@ class Post_Type_Press_Mentions extends Base { */ public function get_labels() { - return [ + return array( 'name' => __( 'Press mentions', 'osi-features' ), 'singular_name' => __( 'Press mentions', 'osi-features' ), 'all_items' => __( 'Press mentions', 'osi-features' ), @@ -45,8 +54,7 @@ public function get_labels() { 'search_items' => __( 'Search Press mentions', 'osi-features' ), 'not_found' => __( 'No Press mentions found', 'osi-features' ), 'not_found_in_trash' => __( 'No Press mentions found in Trash', 'osi-features' ), - ]; - + ); } /** @@ -56,14 +64,158 @@ public function get_labels() { */ public function get_args() { - return [ + return array( 'show_in_rest' => true, 'public' => true, 'has_archive' => true, 'menu_position' => 6, - 'supports' => [ 'title', 'author', 'excerpt' ], - 'rewrite' => [ 'slug' => 'press-mentions', 'with_front' => false ] - ]; + 'supports' => array( 'title', 'author', 'excerpt' ), + 'rewrite' => array( + 'slug' => 'press-mentions', + 'with_front' => false, + ), + ); + } + + /** + * Register custom fields for press mentions + */ + public function register_custom_fields() { + \add_meta_box( + 'press_mentions_meta_box', + \__( 'Press Mention Details', 'osi-features' ), + array( $this, 'render_meta_box' ), + self::SLUG, + 'normal', + 'high' + ); + } + + /** + * Render the meta box + * + * @param \WP_Post $post The post object + */ + public function render_meta_box( $post ) { + // Add nonce for security + \wp_nonce_field( 'press_mentions_meta_box', 'press_mentions_meta_box_nonce' ); + + // Get existing values + $date_of_publication = \get_post_meta( $post->ID, 'date_of_publication', true ); + // Convert Ymd format to Y-m-d for the input field + if ( ! empty( $date_of_publication ) ) { + $date_of_publication = \DateTime::createFromFormat( 'Ymd', $date_of_publication )->format( 'Y-m-d' ); + } + $article_url = \get_post_meta( $post->ID, 'article_url', true ); + + ?> +
+
+
+
+
+
+