You are here

public function InstapageCmsPluginWPConnector::checkPage in Instapage plugin 8.3

Same name and namespace in other branches
  1. 7.3 core/connectors/InstapageCmsPluginWPConnector.php \InstapageCmsPluginWPConnector::checkPage()

Checks (and displays) if a landing page should be displayed instead of normal content served by CMS.

Parameters

string $type Type of page to check ('page', 'home' or '404').:

string $slug Slug to check. Default: ''.:

3 calls to InstapageCmsPluginWPConnector::checkPage()
InstapageCmsPluginWPConnector::check404 in core/connectors/InstapageCmsPluginWPConnector.php
Checks (and displays) if a landing page marked as 404 should be displayed instead of normal CMS 404 page.
InstapageCmsPluginWPConnector::checkCustomUrl in core/connectors/InstapageCmsPluginWPConnector.php
Checks (and displays) if a landing page hould be displayed instead of normal CMS page under current URL.
InstapageCmsPluginWPConnector::checkHomepage in core/connectors/InstapageCmsPluginWPConnector.php
Checks (and displays) if a landing page marked as homepage should be displayed instead of normal CMS homepage.

File

core/connectors/InstapageCmsPluginWPConnector.php, line 538

Class

InstapageCmsPluginWPConnector
Class that utilizes native WordPress functions to perform actions like remote requests and DB operations.

Code

public function checkPage($type, $slug = '') {
  $page = InstapageCmsPluginPageModel::getInstance();
  $result = $page
    ->check($type, $slug);
  $supportLegacy = InstapageCmsPluginHelper::getMetadata('supportLegacy', true);
  if (!$result && $supportLegacy && $this
    ->legacyArePagesPresent()) {
    $result = $this
      ->legacyGetPage($slug);
  }
  if (isset($result->instapage_id) && $result->instapage_id) {

    // we have landing page for given slug,
    // but if in url there are duplicated slashes show 404 page instead
    if (InstaPageCmsPluginHelper::checkIfRequestUriHasDuplicatedSlashes()) {
      self::return404();
      return false;
    }
    if ($type == '404') {
      $page
        ->display($result, 404);
    }
    else {
      $page
        ->display($result);
    }
  }
}