@@ -64,20 +64,27 @@ private function get_label() {
6464 */
6565 private function get_page_uri () {
6666
67- $ terms_page_id = woo_additional_terms ()->service ( 'options ' )->get ( 'page ' , 0 );
68- $ terms_page = get_post ( $ terms_page_id );
67+ $ terms_page_id = woo_additional_terms ()->service ( 'options ' )->get ( 'page ' , false );
6968
70- // Check if the terms page exists.
71- if ( ! $ terms_page instanceof WP_Post ) {
69+ if ( ! is_numeric ( $ terms_page_id ) ) {
7270 return '' ;
7371 }
7472
75- // Check if the terms page is published.
76- if ( 'publish ' !== $ terms_page ->post_status ) {
73+ $ terms_page = get_post ( $ terms_page_id );
74+
75+ // Check if the terms page exists, and is a page.
76+ if ( ! ( $ terms_page instanceof WP_Post ) || 'page ' !== $ terms_page ->post_type ) {
77+ return '' ;
78+ }
79+
80+ $ display_action = woo_additional_terms ()->service ( 'options ' )->get ( 'action ' , 'embed ' );
81+
82+ // Bail early, in case the display action is set to "New Tab", and the terms page is not published.
83+ if ( 'publish ' !== $ terms_page ->post_status && 'newtab ' === $ display_action ) {
7784 return '' ;
7885 }
7986
80- return get_permalink ( $ terms_page_id );
87+ return get_permalink ( $ terms_page );
8188 }
8289
8390 /**
@@ -141,32 +148,17 @@ private function get_content() {
141148 return '' ;
142149 }
143150
144- // Check if get_post() function exists.
145- if ( ! function_exists ( 'get_post ' ) ) {
146- return '' ;
147- }
148-
149- $ terms_page_id = woo_additional_terms ()->service ( 'options ' )->get ( 'page ' , 0 );
151+ $ terms_page_id = woo_additional_terms ()->service ( 'options ' )->get ( 'page ' , false );
150152
151- // Bail early, in case the terms page ID is empty .
152- if ( empty ( $ terms_page_id ) ) {
153+ // Bail early, in case the terms page ID is not valid .
154+ if ( empty ( $ terms_page_id ) || ! function_exists ( ' get_post ' ) ) {
153155 return '' ;
154156 }
155157
156158 $ terms_page = get_post ( $ terms_page_id );
157159
158- // Check if the terms page exists.
159- if ( ! $ terms_page instanceof WP_Post ) {
160- return '' ;
161- }
162-
163- // Check if the terms page is published.
164- if ( 'publish ' !== $ terms_page ->post_status ) {
165- return '' ;
166- }
167-
168- // Check if the terms page has content.
169- if ( empty ( $ terms_page ->post_content ) ) {
160+ // Check if the terms page exists, and has content.
161+ if ( ! ( $ terms_page instanceof WP_Post ) || empty ( $ terms_page ->post_content ) ) {
170162 return '' ;
171163 }
172164
0 commit comments