diff --git a/includes/class-newspack-listings-core.php b/includes/class-newspack-listings-core.php index 9d5a8246..6dd0b22b 100644 --- a/includes/class-newspack-listings-core.php +++ b/includes/class-newspack-listings-core.php @@ -72,6 +72,7 @@ public function __construct() { add_filter( 'body_class', [ __CLASS__, 'set_template_class' ] ); add_action( 'save_post', [ __CLASS__, 'sync_post_meta' ], 10, 2 ); add_filter( 'newspack_listings_hide_author', [ __CLASS__, 'hide_author' ] ); + add_filter( 'newspack_listings_hide_publish_date', [ __CLASS__, 'hide_publish_date' ] ); add_filter( 'newspack_theme_featured_image_post_types', [ __CLASS__, 'support_featured_image_options' ] ); register_activation_hook( NEWSPACK_LISTINGS_FILE, [ __CLASS__, 'activation_hook' ] ); } @@ -267,7 +268,7 @@ public static function get_meta_fields( $post_type = null, $field_names_only = f } $all_meta_fields = [ - 'newspack_listings_contact_email' => [ + 'newspack_listings_contact_email' => [ 'post_types' => [ self::NEWSPACK_LISTINGS_POST_TYPES['event'], self::NEWSPACK_LISTINGS_POST_TYPES['generic'], @@ -299,7 +300,7 @@ public static function get_meta_fields( $post_type = null, $field_names_only = f }, ], ], - 'newspack_listings_contact_phone' => [ + 'newspack_listings_contact_phone' => [ 'post_types' => [ self::NEWSPACK_LISTINGS_POST_TYPES['event'], self::NEWSPACK_LISTINGS_POST_TYPES['generic'], @@ -331,7 +332,7 @@ public static function get_meta_fields( $post_type = null, $field_names_only = f }, ], ], - 'newspack_listings_contact_address' => [ + 'newspack_listings_contact_address' => [ 'post_types' => [ self::NEWSPACK_LISTINGS_POST_TYPES['event'], self::NEWSPACK_LISTINGS_POST_TYPES['generic'], @@ -380,7 +381,7 @@ public static function get_meta_fields( $post_type = null, $field_names_only = f ], ], ], - 'newspack_listings_business_hours' => [ + 'newspack_listings_business_hours' => [ 'post_types' => [ self::NEWSPACK_LISTINGS_POST_TYPES['event'], self::NEWSPACK_LISTINGS_POST_TYPES['marketplace'], @@ -427,7 +428,7 @@ public static function get_meta_fields( $post_type = null, $field_names_only = f ], ], ], - 'newspack_listings_locations' => [ + 'newspack_listings_locations' => [ 'post_types' => [ self::NEWSPACK_LISTINGS_POST_TYPES['event'], self::NEWSPACK_LISTINGS_POST_TYPES['generic'], @@ -484,7 +485,7 @@ public static function get_meta_fields( $post_type = null, $field_names_only = f }, ], ], - 'newspack_listings_event_start_date' => [ + 'newspack_listings_event_start_date' => [ 'post_types' => [ self::NEWSPACK_LISTINGS_POST_TYPES['event'], ], @@ -507,7 +508,7 @@ public static function get_meta_fields( $post_type = null, $field_names_only = f }, ], ], - 'newspack_listings_price' => [ + 'newspack_listings_price' => [ 'post_types' => [ self::NEWSPACK_LISTINGS_POST_TYPES['marketplace'], ], @@ -530,7 +531,7 @@ public static function get_meta_fields( $post_type = null, $field_names_only = f }, ], ], - 'newspack_listings_hide_author' => [ + 'newspack_listings_hide_author' => [ 'post_types' => [ self::NEWSPACK_LISTINGS_POST_TYPES['event'], self::NEWSPACK_LISTINGS_POST_TYPES['generic'], @@ -551,7 +552,7 @@ public static function get_meta_fields( $post_type = null, $field_names_only = f }, ], ], - 'newspack_listings_image_ids' => [ + 'newspack_listings_image_ids' => [ 'post_types' => [ self::NEWSPACK_LISTINGS_POST_TYPES['event'], self::NEWSPACK_LISTINGS_POST_TYPES['generic'], @@ -579,7 +580,28 @@ public static function get_meta_fields( $post_type = null, $field_names_only = f }, ], ], - 'newspack_listings_hide_parents' => [ + 'newspack_listings_hide_publish_date' => [ + 'post_types' => [ + self::NEWSPACK_LISTINGS_POST_TYPES['event'], + self::NEWSPACK_LISTINGS_POST_TYPES['generic'], + self::NEWSPACK_LISTINGS_POST_TYPES['marketplace'], + self::NEWSPACK_LISTINGS_POST_TYPES['place'], + ], + 'label' => __( 'Hide publish date', 'newspack-listings' ), + 'settings' => [ + 'object_subtype' => $post_type, + 'default' => boolval( Settings::get_settings( 'newspack_listings_hide_publish_date' ) ), // Configurable in plugin-wide settings. + 'description' => __( 'Hide publish and updated dates for this listing', 'newspack-listings' ), + 'type' => 'boolean', + 'sanitize_callback' => 'rest_sanitize_boolean', + 'single' => true, + 'show_in_rest' => true, + 'auth_callback' => function() { + return current_user_can( 'edit_posts' ); + }, + ], + ], + 'newspack_listings_hide_parents' => [ 'post_types' => [ 'page', 'post', @@ -602,7 +624,7 @@ public static function get_meta_fields( $post_type = null, $field_names_only = f }, ], ], - 'newspack_listings_hide_children' => [ + 'newspack_listings_hide_children' => [ 'post_types' => [ 'page', 'post', @@ -729,6 +751,23 @@ public static function hide_author( $hide_author = false ) { return $hide_author; } + /** + * Filter callback to decide whether to show the publish and updated dates for the current singular post. + * Can be used from other plugins and/or themes to modify default template behavior. + * + * @param boolean $hide_publish_dates Whether or not to hide the publish and updated dates. + * @return boolean If the current post a.) is a listing and b.) has enabled the option to hide publish and updated dates. + */ + public static function hide_publish_date( $hide_publish_dates = false ) { + $post_id = get_the_ID(); + + if ( self::is_listing() && ! empty( get_post_meta( $post_id, 'newspack_listings_hide_publish_date', true ) ) ) { + return true; + } + + return $hide_publish_dates; + } + /** * If using a Newspack theme, respect the "default template" option setting in the Customizer. * diff --git a/includes/class-newspack-listings-settings.php b/includes/class-newspack-listings-settings.php index 2f3a089d..9c27490c 100644 --- a/includes/class-newspack-listings-settings.php +++ b/includes/class-newspack-listings-settings.php @@ -71,6 +71,13 @@ public static function get_default_settings() { 'type' => 'checkbox', 'value' => true, ], + [ + 'description' => __( 'This setting can be overridden per listing.', 'newspack-listings' ), + 'key' => 'newspack_listings_hide_publish_date', + 'label' => __( 'Hide publish and updated dates for listings by default', 'newpack-listings' ), + 'type' => 'checkbox', + 'value' => true, + ], [ 'description' => __( 'This setting can be overridden per listing, post, or page.', 'newspack-listings' ), 'key' => 'newspack_listings_hide_parents', diff --git a/src/editor/sidebar/index.js b/src/editor/sidebar/index.js index c86d0dc0..9fb461c4 100644 --- a/src/editor/sidebar/index.js +++ b/src/editor/sidebar/index.js @@ -15,7 +15,7 @@ import './style.scss'; const SidebarComponent = ( { meta, updateMetaValue } ) => { const { post_type_label: postTypeLabel, post_types: postTypes } = window.newspack_listings_data; - const { newspack_listings_hide_author } = meta; + const { newspack_listings_hide_author, newspack_listings_hide_publish_date } = meta; if ( ! postTypes ) { return null; @@ -30,22 +30,42 @@ const SidebarComponent = ( { meta, updateMetaValue } ) => { isListing() ? postTypeLabel : __( 'Newspack Listings', 'newspack-listings' ) ) } > +

+ + { __( 'Overrides ', 'newspack-listings' ) } + + { __( 'global settings', 'newspack-listings' ) } + + +

( -

- { __( 'Overrides ', 'newspack-listings' ) } - - { __( 'global settings', 'newspack-listings' ) } - -

+ help={ sprintf( + __( '%s the author byline for this listing.', 'newspack-listings' ), + newspack_listings_hide_author + ? __( 'Hide', 'newspack-listings' ) + : __( 'Show', 'newspack-listings' ) ) } checked={ newspack_listings_hide_author } onChange={ value => updateMetaValue( 'newspack_listings_hide_author', value ) } />
+ + updateMetaValue( 'newspack_listings_hide_publish_date', value ) } + /> + ); };