Noptin_Form::_can_show()

Contains the logic for Noptin_Form::can_show()


Return Return

(bool)


Top ↑

Source Source

File: includes/class-noptin-form.php

	protected function _can_show() {

		// Abort early if the form is not published...
		if ( ! $this->exists() || ! $this->is_published() ) {
			return false;
		}

		// Always display click triggered popups.
		if ( 'popup' === $this->optinType && 'after_click' === $this->triggerPopup ) {
			return true;
		}

		// ... or the user wants to hide all forms.
		if ( ! noptin_should_show_optins() ) {
			return false;
		}

		// Maybe hide on mobile.
		if ( $this->hideSmallScreens && wp_is_mobile() ) {
			return false;
		}

		// Maybe hide on desktops.
		if ( $this->hideLargeScreens && ! wp_is_mobile() ) {
			return false;
		}

		// User roles.
		if ( 'users' == $this->whoCanSee && ! is_user_logged_in() ) {
			return false;
		}

		if ( 'guests' == $this->whoCanSee && is_user_logged_in() ) {
			return false;
		}

		if ( 'roles' == $this->whoCanSee ) {
			$role = $this->get_user_role();

			if ( empty( $role ) || ! is_array( $this->userRoles ) || ! in_array( $role, $this->userRoles ) ) {
				return false;
			}

		}

		// Has the user restricted this to a few posts?
		if ( ! empty( $this->onlyShowOn ) ) {
			return noptin_is_singular( $this->onlyShowOn );
		}

		// or maybe forbidden it on this post?
		if ( ! empty( $this->neverShowOn ) && noptin_is_singular( $this->neverShowOn ) ) {
			return false;
		}

		// Is this form set to be shown everywhere?
		if ( $this->showEverywhere ) {
			return true;
		}

		$places = is_array( $this->showPlaces ) ? $this->showPlaces : array();

		// frontpage.
		if ( is_front_page() ) {
			return ( ! empty( $this->showHome ) || in_array( 'showHome', $places ) );
		}

		// blog page.
		if ( is_home() ) {
			return ( ! empty( $this->showBlog ) || in_array( 'showBlog', $places ) );
		}

		// search.
		if ( is_search() ) {
			return ( ! empty( $this->showSearch ) || in_array( 'showSearch', $places ) );
		}

		// other archive pages.
		if ( is_archive() ) {
			return ( ! empty( $this->showArchives ) || in_array( 'showArchives', $places ) );
		}

		// Single posts.
		return is_singular( $places );

	}


Top ↑

User Contributed Notes User Contributed Notes

30 day money back guarantee
Safe & Secure online payment
Custom CSS Slide Example
Custom Animation Example
Default Animation