hchouhan
3/14/2014 - 4:39 PM

Create Pages in WP

Create Pages in WP

/*
 * To run the deployment
 * 1. Login as an administrator
 * 2. Go to http://yourdomain.com/?deploy_changes=1
 */
function deploy_changes() {

  // If the request is not our deployment
  if ( !isset( $_GET['deploy_changes'] ) ) {
    return;
  }

  // Only allow a logged in admin to run the deployment
  if ( !current_user_can( 'install_themes' ) ) {
    echo 'Not logged in.';
    exit;
  }

  // Run script for 5 mins max
  set_time_limit(60*5);

  $pages = array(
    array(
      'content' => '[woocommerce_checkout]',
      'title'   => 'Checkout'
    ),
    array(
      'content' => '[woocommerce_my_account]',
      'title'   => 'My Account'
    )
  );

  foreach ( $pages as $page ) {
    $new_page = array(
      'post_type'   => 'page',
      'post_title'  => $page['title'],
      'post_content'  => $page['content'];
    );

    wp_insert_post( $new_page );
  }

  echo 'Deployment complete.';
  exit;
}
add_action( 'template_redirect', 'deploy_changes' );