Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request 10up#132 from alleyinteractive/refactor
Browse files Browse the repository at this point in the history
Some refactoring
  • Loading branch information
jameswburke authored Jun 11, 2019
2 parents 5494edb + 1290a93 commit 4564674
Show file tree
Hide file tree
Showing 20 changed files with 206 additions and 284 deletions.
2 changes: 1 addition & 1 deletion mu-plugins/alleypack
2 changes: 1 addition & 1 deletion mu-plugins/cpr-load-mu-plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'/wp-components/wp-components.php',
'/wp-irving/wp-irving.php',
'/wp-redis/wp-redis.php',
'/wp-seo/wp-seo.php',
// '/wp-seo/wp-seo.php',
'/wpcom-thumbnail-editor/wpcom-thumbnail-editor.php',
'/wpcom-legacy-redirector/wpcom-legacy-redirector.php',
'/fm-widgets/fm-widgets.php', // Depends on FM.
Expand Down
2 changes: 1 addition & 1 deletion themes/cpr/.scaffold
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"fm:post-show-episode-segments": "98b2a4c492be23dccfeaac45bd1dbba8",
"fm:post-mixed-featured-audio": "ca27603c734b7d165ede8847bd06adde",
"fm:post-podcast-and-show-settings": "b471ea1520bce095cef215caa8565090",
"cpt:press-release": "5b51de183cf8936a90c057275a8e6112",
"cpt:press-release": "b9125a2fd8a7d4d0879a736b5ce93060",
"tax:underwriter-category": "072af0a7a234fd9e1acc6770389678a4",
"fm:post-post-settings": "fd907eabef788c3e10f44bc918eba38a",
"fm:post-tribe_events_section": "90290608888446e92fb31b7e1d3a7e1b",
Expand Down
10 changes: 9 additions & 1 deletion themes/cpr/components/class-content-item.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,21 @@ public function post_has_set() : self {
$this->set_audio();
}

$this->set_byline();
$this->wp_post_set_featured_image( $this->get_config( 'image_size' ) );
$this->merge_config(
[
'permalink' => get_permalink( $this->post->ID ?? 0 ),
]
);

switch ( $this->post->post_type ) {
case 'press-release':
break;
default:
$this->set_byline();
break;
}

return $this;
}
}
15 changes: 15 additions & 0 deletions themes/cpr/components/class-sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
class Sidebar extends \WP_Components\Component {

use \WP_Components\WP_Post;
use \WP_Components\WP_Widget_Sidebar;

/**
Expand All @@ -32,4 +33,18 @@ public function default_config() : array {
'has_ad' => false,
];
}

/**
* Hook into post being set.
*
* @return self
*/
public function post_has_set() : self {
$sections = wp_get_post_terms( $this->get_post_id(), 'section' );
if ( ! empty( $sections[0] ) && $sections[0] instanceof \WP_Term ) {
$sidebar_slug = "{$sections[0]->slug}-sidebar";
$this->set_sidebar( $sidebar_slug );
}
return $this;
}
}
2 changes: 0 additions & 2 deletions themes/cpr/components/content/class-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ public function post_has_set() : self {
break;

case 'press-release':
$this->set_publish_date();

$this->set_config( 'eyebrow_label', __( '‹‹ All Press Releases', 'cpr' ) );
$this->set_config( 'eyebrow_link', home_url( '/press-releases/' ) );
break;
Expand Down
40 changes: 17 additions & 23 deletions themes/cpr/components/events/class-body.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,23 @@ public function post_has_set() : self {

( new \CPR\Components\Sidebar() )
->set_config( 'position', 'right' )
->append_children(
[
/**
* Social sharing.
*/
( new \WP_Components\Social_Sharing() )
->merge_config(
[
'services' => [
'facebook' => true,
'twitter' => true,
'email' => true,
],
'text' => __( 'Share: ', 'cpr' ),
]
)
->set_post( $this->post ),

/**
* Content List of 4 upcoming events.
*/
$this->get_more_events_component(),
]
->set_post( $this->post )
->prepend_child(
/**
* Social sharing.
*/
( new \WP_Components\Social_Sharing() )
->merge_config(
[
'services' => [
'facebook' => true,
'twitter' => true,
'email' => true,
],
'text' => __( 'Share: ', 'cpr' ),
]
)
->set_post( $this->post )
),
]
);
Expand Down
137 changes: 74 additions & 63 deletions themes/cpr/components/header/class-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
class Header extends \WP_Components\Component {

use \WP_Components\WP_Post;
use \WP_Components\WP_Term;
use \WP_Components\WP_Query;

/**
Expand Down Expand Up @@ -39,76 +41,85 @@ public function default_children() : array {
}

/**
* Hook into query being set.
*
* @return self
* Set the component to use the main logo and nav menu.
*/
public function query_has_set() : self {
public function set_cpr_header() : self {
return $this->set_header( 'main' );
}

// Override with alternate children on certain pages.
switch ( true ) {
case 'landing-page' === $this->query->get( 'dispatch' ):
$type = $this->query->get( 'landing-page-type' );
if ( 'homepage' !== $type ) {
$this->children = [
( new \CPR\Components\Logo() )
->set_config( 'type', $type )
->set_theme( 'primary' ),
( new \WP_Components\Menu() )
->set_menu( $type )
->parse_wp_menu()
->set_theme( 'header' )
->set_child_themes( [ 'menu-item' => 'header' ] ),
];
return $this;
}
break;
/**
* Set the component to use the news logo and nav menu.
*/
public function set_news_header() : self {
return $this->set_header( 'news' );
}

case $this->query->is_post_type_archive( 'top-30' ):
case $this->query->is_singular( 'top-30' ):
$this->children = [
( new \CPR\Components\Logo() )
->set_config( 'type', 'indie' )
->set_theme( 'primary' ),
( new \WP_Components\Menu() )
->set_menu( 'indie' )
->parse_wp_menu()
->set_theme( 'header' )
->set_child_themes( [ 'menu-item' => 'header' ] ),
];
return $this;
/**
* Set the component to use the classical logo and nav menu.
*/
public function set_classical_header() : self {
return $this->set_header( 'classical' );
}

case $this->query->is_single():
$sections = wp_get_post_terms( ( $this->query->post->ID ?? 0 ), 'section' );
if ( ! empty( $sections[0] ) && $sections[0] instanceof \WP_Term ) {
$this->children = [
( new \CPR\Components\Logo() )
->set_config( 'type', $sections[0]->slug ?? '' )
->set_theme( 'primary' ),
( new \WP_Components\Menu() )
->set_menu( $sections[0]->slug ?? '' )
->parse_wp_menu()
->set_theme( 'header' )
->set_child_themes( [ 'menu-item' => 'header' ] ),
];
}
return $this;
/**
* Set the component to use the indie logo and nav menu.
*/
public function set_indie_header() : self {
return $this->set_header( 'indie' );
}

case $this->query->is_tax( 'section' ):
$term = $this->query->get_queried_object();
$this->children = [
( new \CPR\Components\Logo() )
->set_config( 'type', $term->slug ?? '' )
->set_theme( 'primary' ),
( new \WP_Components\Menu() )
->set_menu( $term->slug ?? '' )
->parse_wp_menu()
->set_theme( 'header' )
->set_child_themes( [ 'menu-item' => 'header' ] ),
];
return $this;
/**
* Set the component to use the logo and nav menu.
*
* @param string $type Type to set.
*/
public function set_header( string $type ) : self {
$this->set_children(
[
/**
* Logo.
*/
( new \CPR\Components\Logo() )
->set_config( 'type', $type )
->set_theme( 'primary' ),

/**
* Menu.
*/
( new \WP_Components\Menu() )
->set_menu( $type )
->parse_wp_menu()
->set_theme( 'header' )
->set_child_themes( [ 'menu-item' => 'header' ] ),
]
);
return $this;
}

/**
* Hook into post being set.
*
* @return self
*/
public function post_has_set() : self {
$sections = wp_get_post_terms( $this->get_post_id(), 'section' );
$section = $sections[0]->slug ?? 'header';
if ( ! in_array( $section, [ 'news', 'classical', 'indie' ], true ) ) {
$this->set_cpr_header();
} else {
$this->set_header( $section );
}
return $this;
}

/**
* Hook into term being set.
*
* @return self
*/
public function term_has_set() : self {
$term = $this->query->get_queried_object();
$this->set_header( $term->slug );
return $this;
}
}
1 change: 0 additions & 1 deletion themes/cpr/components/modules/class-grid-group-item.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function post_has_set() : self {
)
);

$this->set_eyebrow();
$this->wp_post_set_permalink();

return $this;
Expand Down
Loading

0 comments on commit 4564674

Please sign in to comment.