Skip to content

Commit cbd520d

Browse files
richardkorthuismvdhoek1
authored andcommitted
Use the correct portal URL if the Show On functionality is used. (Partly copied from PDC Base).
1 parent 3147475 commit cbd520d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: src/Base/Models/PortalLinkGenerator.php

+28
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace OWC\OpenPub\Base\Models;
44

55
use OWC\OpenPub\Base\Settings\SettingsPageOptions;
6+
use WP_Term;
67

78
class PortalLinkGenerator
89
{
@@ -43,6 +44,11 @@ public function generateBasePortalLink(): string
4344
private function createPortalSlug(): self
4445
{
4546
$portalURL = $this->pubSettings->getPortalURL();
47+
48+
if ($this->pubSettings->useShowOn()) {
49+
$portalURL = $this->getShowOnPortalURL();
50+
}
51+
4652
$portalSlug = $this->pubSettings->getPortalItemSlug();
4753

4854
$this->updatePortalURL($portalURL);
@@ -51,6 +57,28 @@ private function createPortalSlug(): self
5157
return $this;
5258
}
5359

60+
private function getShowOnPortalURL(): string
61+
{
62+
$terms = wp_get_object_terms($this->post->getID(), 'openpub-show-on');
63+
64+
if (! is_array($terms) || empty($terms)) {
65+
return '';
66+
}
67+
68+
$portalURL = reset($terms);
69+
if (isset($_GET['source'])) {
70+
foreach( $terms as $term ) {
71+
if ($term->slug === $_GET['source']) {
72+
$portalURL = $term;
73+
break;
74+
}
75+
}
76+
}
77+
$portalURL = $portalURL instanceof WP_Term ? $portalURL->name : '';
78+
79+
return wp_http_validate_url($portalURL) ? $portalURL : '/';
80+
}
81+
5482
private function appendPostSlug(): self
5583
{
5684
if (! empty($this->post->getPostName())) {

0 commit comments

Comments
 (0)