Display forms only on default post types

[MAILPOET-2639]
This commit is contained in:
Pavel Dohnal
2020-01-29 16:04:18 +01:00
committed by Jack Kitterhing
parent bdfd488ae4
commit fd1e8ee915
3 changed files with 31 additions and 8 deletions

View File

@ -25,7 +25,7 @@ class DisplayFormInWPContent {
$forms = $this->getForms();
if (count($forms) === 0) {
$this->wp->setTransient(DisplayFormInWPContent::NO_FORM_TRANSIENT_KEY, true);
$this->saveNoPosts();
return $content;
}
@ -39,10 +39,18 @@ class DisplayFormInWPContent {
private function shouldDisplay():bool {
if (!$this->wp->isSingle()) return false;
if ($this->wp->getTransient(DisplayFormInWPContent::NO_FORM_TRANSIENT_KEY)) return false;
$cache = $this->wp->getTransient(DisplayFormInWPContent::NO_FORM_TRANSIENT_KEY);
if (isset($cache[$this->wp->getPostType()])) return false;
return true;
}
private function saveNoPosts() {
$stored = $this->wp->getTransient(DisplayFormInWPContent::NO_FORM_TRANSIENT_KEY);
if (!is_array($stored)) $stored = [];
$stored[$this->wp->getPostType()] = true;
$this->wp->setTransient(DisplayFormInWPContent::NO_FORM_TRANSIENT_KEY, $stored);
}
/**
* @return FormEntity[]
*/
@ -66,7 +74,7 @@ class DisplayFormInWPContent {
if (!isset($settings['placeFormBellowAllPosts'])) return false;
if (
($settings['placeFormBellowAllPosts'] === '1')
&& !$this->wp->isPage()
&& $this->wp->isSingular('post')
) return true;
if (
($settings['placeFormBellowAllPages'] === '1')