Skip to content

Commit

Permalink
Issue 89 (#119)
Browse files Browse the repository at this point in the history
* Fix install a blog. fixes #89 and fixes #90

* uncommend debug code.

* Take into account Pavilion.
  • Loading branch information
bwmarkle authored Jun 10, 2021
1 parent 82d646e commit 0376b33
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 46 deletions.
90 changes: 57 additions & 33 deletions includes/class-boldgrid-inspirations-blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,28 @@
class Boldgrid_Inspirations_Blog {

/**
* The Blog category id.
* Configs.
*
* @since 1.4
* @var int
* @var array
*/
public $category_id;
public $configs;

/**
* Configs.
* The page id of the blog page.
*
* @since 1.4
* @var array
* @since SINCEVERSION
* @var int
*/
public $configs;
public $page_id;

/**
* The title of our blog page.
*
* @since SINCEVERSION
* @var string
*/
public $title;

/**
* Constructor.
Expand All @@ -40,21 +48,7 @@ class Boldgrid_Inspirations_Blog {
*/
public function __construct( $configs = array() ) {
$this->configs = $configs;
}

/**
* Create the blog category.
*
* @since 1.4
*/
public function create_category() {
$category = get_category_by_slug( __( 'Blog', 'boldgrid-inspirations' ) );

if( $category ) {
$this->category_id = $category->term_id;
} else {
$this->category_id = wp_create_category( __( 'Blog', 'boldgrid-inspirations' ) );
}
$this->title = __( 'Blog', 'boldgrid-inspirations' );
}

/**
Expand All @@ -63,24 +57,47 @@ public function create_category() {
* @since 1.4
*
* @param int $menu_id
* @param int $menu_order
* @param int $menu_order Default value is 150. This number was previously in the code without
* any comments.
*/
public function create_menu_item( $menu_id, $menu_order ) {
public function create_menu_item( $menu_id, $menu_order = 150 ) {
$data = array(
'menu-item-title' => __( 'Blog', 'boldgrid-inspirations' ),
'menu-item-object-id' => $this->category_id,
'menu-item-db-id' => 0,
'menu-item-object' => 'category',
'menu-item-object-id' => $this->page_id,
'menu-item-parent-id' => 0,
'menu-item-type' => 'taxonomy',
'menu-item-url' => get_category_link( $this->category_id ),
'menu-item-status' => 'publish',
'menu-item-position' => $menu_order,
'menu-item-object' => 'page',
'menu-item-type' => 'post_type',
'menu-item-status' => 'publish',
'menu-item-position' => $menu_order,
);

return wp_update_nav_menu_item( $menu_id, 0, $data );
}

/**
* Create our blog page.
*
* @since SINCEVERSION
*/
public function create_page() {
$page = get_page_by_title( $this->title );

if ( ! empty( $page->post_status ) && 'published' === $page->post_status ) {
$page_id = $page->ID;
} else {
$page_id = wp_insert_post( array(
'post_title' => $this->title,
'post_name' => sanitize_key( $this->title ),
'post_status' => 'publish',
'post_type' => 'page',
'comment_status' => 'closed',
) );
}

$this->page_id = (int) $page_id;

return ! empty( $this->page_id );
}

/**
* Create widgets.
*
Expand All @@ -90,7 +107,14 @@ public function create_menu_item( $menu_id, $menu_order ) {
* @since 1.4
*/
public function create_sidebar_widgets() {
$sidebar = 'sidebar-1';
/*
* Set our sidebar id.
*
* With v1 themes it used to be 'sidebar-1'. As Inspirations has transitioned to installing
* Crio themes, the sidebar is now 'primary-sidebar'.
*/
$theme = wp_get_theme();
$sidebar = 'Crio' === $theme->get( 'Name' ) ? 'primary-sidebar' : 'sidebar-1';

/**
* Filter the sidebar to add our new widgets to.
Expand Down
16 changes: 3 additions & 13 deletions includes/class-boldgrid-inspirations-deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,6 @@ public function create_new_install() {
// create the new blog
$new_blog_id = wpmu_create_blog( $_SERVER['SERVER_NAME'], '/' . $this->new_path, $blog_title, get_current_user_id() );

if ( is_object( $new_blog_id ) ) {
echo '<pre>' . print_r( $new_blog_id, 1 ) . '</pre>';
}

switch_to_blog( $new_blog_id );

// Set the blog's admin email address using the network admin email address.
Expand Down Expand Up @@ -1217,10 +1213,9 @@ public function deploy_page_sets() {

$this->assign_menu_id_to_all_locations( $menu_id );

if( $this->install_blog ) {
$this->blog->create_category();
$this->set_permalink_structure( '/%category%/%postname%/' );
$this->blog->create_menu_item( $this->primary_menu_id, 150 );
if( $this->install_blog && $this->blog->create_page() ) {
update_option( 'page_for_posts', $this->blog->page_id );
$this->blog->create_menu_item( $this->primary_menu_id );
}

// Determine the release channel:
Expand Down Expand Up @@ -1360,11 +1355,6 @@ public function deploy_page_sets() {
'post_status' => $post['post_status'],
);

// Assign this blog post to our blog category.
if( $is_blog_post && $this->install_blog ) {
wp_set_post_categories( $post_id, array( $this->blog->category_id ) );
}

// add page to menu
if ( '1' == $page_v->in_menu ) {
wp_update_nav_menu_item( $menu_id, 0, array(
Expand Down

0 comments on commit 0376b33

Please sign in to comment.