Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default listings to one-column-wide.php post template #77

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions includes/class-newspack-listings-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function __construct() {
add_action( 'admin_menu', [ __CLASS__, 'add_plugin_page' ] );
add_action( 'init', [ __CLASS__, 'register_post_types' ] );
add_action( 'admin_init', [ __CLASS__, 'convert_legacy_taxonomies' ] );
add_action( 'wp_insert_post', [ __CLASS__, 'set_default_template' ], 10, 3 );
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' ] );
Expand Down Expand Up @@ -270,6 +269,26 @@ public static function get_meta_fields( $post_type = null, $field_names_only = f
}

$all_meta_fields = [
'_wp_page_template' => [
'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' => __( 'Template', 'newspack-listings' ),
'settings' => [
'object_subtype' => $post_type,
'default' => get_theme_mod( 'newspack_listing_default_template', 'single-wide.php' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'single' => true,
'show_in_rest' => true,
'auth_callback' => function() {
return current_user_can( 'edit_posts' );
},
],
],
'newspack_listings_contact_email' => [
'post_types' => [
self::NEWSPACK_LISTINGS_POST_TYPES['event'],
Expand Down Expand Up @@ -770,23 +789,6 @@ public static function hide_publish_date( $hide_publish_dates = false ) {
return $hide_publish_dates;
}

/**
* If using a Newspack theme, respect the "default template" option setting in the Customizer.
*
* @param string $post_id Post ID.
* @param object $post Post object of the post being created or updated.
* @param boolean $update Whether this is an existing post being updated.
*/
public static function set_default_template( $post_id, $post, $update ) {
if ( ! $update && self::is_listing() ) {
$post_template_default = get_theme_mod( 'post_template_default', 'default' );

if ( 'default' !== $post_template_default ) {
update_post_meta( $post_id, '_wp_page_template', $post_template_default );
}
}
}

/**
* If using the single-featured or wide templates, apply a body class to listing posts
* so that they inherit theme styles for that template.
Expand Down
1 change: 0 additions & 1 deletion includes/newspack-listings-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ function sanitize_array( $array ) {
return $array;
}


/**
* Loads a template with given data in scope.
*
Expand Down