Skip to content

Commit

Permalink
Adds automatic settings when activating the theme to set the start page
Browse files Browse the repository at this point in the history
  • Loading branch information
everaldomatias committed Mar 2, 2018
1 parent e2dc79d commit 587239b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ function coletivo_setup() {
endif;
add_action( 'after_setup_theme', 'coletivo_setup' );

/**
* Set the initial configs in theme activation
*/
add_action( 'after_setup_theme', 'coletivo_initial_config' );

/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
Expand Down
26 changes: 26 additions & 0 deletions inc/extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,29 @@ function coletivo_get_actions_required( ) {
function coletivo_reset_actions_required () {
delete_option('coletivo_actions_dismiss');
}

/**
* Set the initial configs in theme activation
* Add in hook 'after_setup_theme' in functions.php
*/
function coletivo_initial_config() {
$coletivo_initial_config = get_option( 'coletivo_initial_config' );
if ( isset( $_GET['activated'] ) && is_admin() && $coletivo_initial_config == false ) {
$page_title = 'Página Inicial';
$page_template = 'template-frontpage.php';
$page_check = get_page_by_title( $page_title );
$page = array(
'post_type' => 'page',
'post_title' => $page_title,
'post_status' => 'publish',
'post_author' => 1,
);
if ( ! isset( $page_check->ID ) ) {
$page_id = wp_insert_post( $page );
update_post_meta( $page_id, '_wp_page_template', $page_template );
update_option( 'page_on_front', $page_id );
update_option( 'show_on_front', 'page' );
update_option( 'coletivo_initial_config', true );
}
}
}

0 comments on commit 587239b

Please sign in to comment.