Browse Source

Add migration from Pressbooks Publisher (fix #53). (#55)

pull/61/head
Ned Zimmerman 7 years ago committed by GitHub
parent
commit
b3b9317588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      inc/activation/namespace.php

43
inc/activation/namespace.php

@ -6,8 +6,28 @@
namespace Aldine\Activation;
/**
* Create default page content, importing from Pressbooks Publisher, if possible.
*/
function create_default_content() {
if ( ! get_option( 'pb_aldine_activated' ) ) {
$mods = get_option( 'theme_mods_pressbooks-publisher' );
if ( $mods === false ) {
$mods = get_option( 'mods_pressbooks-publisher' );
}
if ( $mods && isset( $mods['pressbooks_publisher_intro_textbox'] ) ) {
$home_content = apply_filters( 'the_content', $mods['pressbooks_publisher_intro_textbox'] );
} else {
$home_content = apply_filters(
'pb_root_home_page_content',
sprintf(
'<h2>%1$s</h2><p>%2$s</p><p><a class="call-to-action" href="/about/">%3$s</a></p>',
__( 'About Pressbooks', 'pressbooks-aldine' ),
__( 'Pressbooks is easy-to-use book writing software that lets you create a book in all the formats you need to publish.', 'pressbooks-aldine' ),
__( 'Learn More', 'pressbooks-aldine' )
)
);
}
$default_pages = [
'about' => [
@ -49,14 +69,9 @@ function create_default_content() {
],
'home' => [
'post_title' => __( 'Home', 'pressbooks-aldine' ),
'post_content' => apply_filters(
'pb_root_home_page_content',
sprintf(
'<div class="block block--standard"><h2>%1$s</h2><p>%2$s</p><p><a class="button" href="/about/">%3$s</a></p></div>',
__( 'About Pressbooks', 'pressbooks-aldine' ),
__( 'Pressbooks is easy-to-use book writing software that lets you create a book in all the formats you need to publish.', 'pressbooks-aldine' ),
__( 'Learn More', 'pressbooks-aldine' )
)
'post_content' => sprintf(
'<div class="page-section">%s</div>',
$home_content
),
],
];
@ -78,15 +93,9 @@ function create_default_content() {
update_option( 'page_on_front', $pages['home'] );
// Remove content generated by wp_install_defaults
if ( ! wp_delete_post( 1, true ) ) {
return;
}
if ( ! wp_delete_post( 2, true ) ) {
return;
}
if ( ! wp_delete_comment( 1, true ) ) {
return;
}
wp_delete_post( 1, true );
wp_delete_post( 2, true );
wp_delete_comment( 1, true );
// Add "pb_aldine_activated" option to enable check above
add_option( 'pb_aldine_activated', 1 );

Loading…
Cancel
Save