File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 3
3
namespace OWC \OpenPub \Base \Models ;
4
4
5
5
use OWC \OpenPub \Base \Settings \SettingsPageOptions ;
6
+ use WP_Term ;
6
7
7
8
class PortalLinkGenerator
8
9
{
@@ -43,6 +44,11 @@ public function generateBasePortalLink(): string
43
44
private function createPortalSlug (): self
44
45
{
45
46
$ portalURL = $ this ->pubSettings ->getPortalURL ();
47
+
48
+ if ($ this ->pubSettings ->useShowOn ()) {
49
+ $ portalURL = $ this ->getShowOnPortalURL ();
50
+ }
51
+
46
52
$ portalSlug = $ this ->pubSettings ->getPortalItemSlug ();
47
53
48
54
$ this ->updatePortalURL ($ portalURL );
@@ -51,6 +57,28 @@ private function createPortalSlug(): self
51
57
return $ this ;
52
58
}
53
59
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
+
54
82
private function appendPostSlug (): self
55
83
{
56
84
if (! empty ($ this ->post ->getPostName ())) {
You can’t perform that action at this time.
0 commit comments