File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33namespace OWC \OpenPub \Base \Models ;
44
55use OWC \OpenPub \Base \Settings \SettingsPageOptions ;
6+ use WP_Term ;
67
78class 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 ())) {
You can’t perform that action at this time.
0 commit comments