Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Base/Models/PortalLinkGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace OWC\OpenPub\Base\Models;

use OWC\OpenPub\Base\Settings\SettingsPageOptions;
use WP_Term;

class PortalLinkGenerator
{
Expand Down Expand Up @@ -43,6 +44,11 @@ public function generateBasePortalLink(): string
private function createPortalSlug(): self
{
$portalURL = $this->pubSettings->getPortalURL();

if ($this->pubSettings->useShowOn()) {
$portalURL = $this->getShowOnPortalURL();
}

$portalSlug = $this->pubSettings->getPortalItemSlug();

$this->updatePortalURL($portalURL);
Expand All @@ -51,6 +57,28 @@ private function createPortalSlug(): self
return $this;
}

private function getShowOnPortalURL(): string
{
$terms = wp_get_object_terms($this->post->getID(), 'openpub-show-on');

if (! is_array($terms) || empty($terms)) {
return '';
}

$portalURL = reset($terms);
if (isset($_GET['source'])) {
foreach( $terms as $term ) {
if ($term->slug === $_GET['source']) {
$portalURL = $term;
break;
}
}
}
$portalURL = $portalURL instanceof WP_Term ? $portalURL->name : '';

return wp_http_validate_url($portalURL) ? $portalURL : '/';
}

private function appendPostSlug(): self
{
if (! empty($this->post->getPostName())) {
Expand Down
Loading