AnsPress_Admin::check_pages_exists()

Description #

Check if AnsPress pages are exists.

Changelog #

VersionDescription
4.1.0Introduced.

Source #

File: admin/anspress-admin.php

	private static function check_pages_exists() {
		$cache = get_transient( 'ap_pages_check' );

		if ( false === $cache ) {
			$opt        = ap_opt();
			$pages_slug = array_keys( ap_main_pages() );

			$pages_in = array();
			foreach ( $pages_slug as $slug ) {
				if ( ! empty( $opt[ $slug ] ) ) {
					$pages_in[] = $opt[ $slug ];
				}
			}

			$args = array(
				'include'     => $pages_in,
				'post_type'   => 'page',
				'post_status' => 'publish',
			);

			$pages = get_posts( $args );

			if ( count( $pages ) < count( $pages_slug ) ) {
				$cache = '0';
				set_transient( 'ap_pages_check', '0', HOUR_IN_SECONDS );
			} else {
				set_transient( 'ap_pages_check', '1', HOUR_IN_SECONDS );
				$cache = '1';
			}
		}

		return '0' === $cache ? false : true;
	}

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