ap_create_base_page()

Description #

Create base page for AnsPress.

This function is called in plugin activation. This function checks if base page already exists, if not then it create a new one and update the option.

Changelog #

VersionDescription
4.1.0Creates all other AnsPress pages if not exists.
2.3Introduced.

Source #

File: includes/functions.php

function ap_create_base_page() {
	$opt = ap_opt();

	$pages = ap_main_pages();

	foreach ( $pages as $slug => $page ) {
		// Check if page already exists.
		$_post = get_page( ap_opt( $slug ) );

		if ( ! $_post || 'trash' === $_post->post_status ) {
			$args = wp_parse_args(
				$page,
				array(
					'post_type'      => 'page',
					'post_content'   => '[anspress]',
					'post_status'    => 'publish',
					'comment_status' => 'closed',
				)
			);

			if ( 'base_page' !== $slug ) {
				$args['post_parent'] = ap_opt( 'base_page' );
			}

			// Now create post.
			$new_page_id = wp_insert_post( $args );

			if ( $new_page_id ) {
				$page = get_page( $new_page_id );

				ap_opt( $slug, $page->ID );
				ap_opt( $slug . '_id', $page->post_name );
			}
		}
	}
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment