# woo-additional-terms/1.6.3/src/WooCommerce/Terms.php

Additional Terms Lite for WooCommerce, version 1.6.3. 169 lines.

- Page: https://pluginprobe.com/plugins/woo-additional-terms/1.6.3/code/src/WooCommerce/Terms.php
- Raw: https://pluginprobe.com/plugins/woo-additional-terms/1.6.3/raw/src/WooCommerce/Terms.php
- Modified: 2023-08-23T18:48:52+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/woo-additional-terms/1.6.3/code/src/WooCommerce/Terms.php#L10-L20`.

```php
<?php
/**
 * Additional terms utility functions.
 *
 * @author MyPreview (Github: @mahdiyazdani, @gooklani, @mypreview)
 *
 * @since 1.6.0
 *
 * @package woo-additional-terms
 */

namespace Woo_Additional_Terms\WooCommerce;

use WP_Post;

/**
 * Terms class.
 */
class Terms {

	/**
	 * Get the internal function.
	 *
	 * @since 1.6.0
	 *
	 * @param string $name The function name.
	 *
	 * @return array|bool
	 */
	public function get( $name ) {

		// Call the internal function if exists.
		if ( method_exists( $this, "get_{$name}" ) ) {
			return call_user_func( array( $this, "get_{$name}" ) );
		}

		return false;
	}

	/**
	 * Get the terms page checkbox label.
	 *
	 * @since 1.6.0
	 *
	 * @return string
	 */
	private function get_label() {

		$notice = woo_additional_terms()->service( 'options' )->get( 'notice', '' );

		if ( preg_match( '/{{additional-terms}}|\[additional-terms\]/', $notice ) ) {
			$notice = str_replace( array( '{{additional-terms}}', '[additional-terms]' ), $this->get_page_link(), $notice );
		}

		return $notice;
	}

	/**
	 * Get the terms page URI.
	 *
	 * @since 1.6.0
	 *
	 * @return string
	 */
	private function get_page_uri() {

		$terms_page_id = woo_additional_terms()->service( 'options' )->get( 'page', false );

		if ( ! is_numeric( $terms_page_id ) ) {
			return '';
		}

		$terms_page = get_post( $terms_page_id );

		// Check if the terms page exists, and is a page.
		if ( ! ( $terms_page instanceof WP_Post ) || 'page' !== $terms_page->post_type ) {
			return '';
		}

		$display_action = woo_additional_terms()->service( 'options' )->get( 'action', 'embed' );

		// Bail early, in case the display action is set to "New Tab", and the terms page is not published.
		if ( 'publish' !== $terms_page->post_status && 'newtab' === $display_action ) {
			return '';
		}

		return get_permalink( $terms_page );
	}

	/**
	 * Get the terms page hyperlink.
	 *
	 * @since 1.6.0
	 *
	 * @return string
	 */
	private function get_page_link() {

		$terms_page_uri = $this->get_page_uri();

		// Check if the terms page URI is empty.
		if ( empty( $terms_page_uri ) ) {
			return '';
		}

		$display_action    = woo_additional_terms()->service( 'options' )->get( 'action', 'embed' );
		$anchor_attributes = array(
			'href'        => esc_url( $terms_page_uri ),
			'class'       => 'woo-additional-terms__link',
			'target'      => '_blank',
			'data-action' => $display_action,
		);

		// Append additional attributes in case the display action is set to "Modal".
		if ( 'modal' === $display_action ) {

			// Enqueue the scripts and styles.
			wp_enqueue_style( 'jquery.fancybox' );
			wp_enqueue_script( 'jquery.fancybox' );

			$anchor_attributes['data-fancybox']         = '';
			$anchor_attributes['data-animation-effect'] = 'fade';
			$anchor_attributes['data-width']            = '1000';
			$anchor_attributes['data-height']           = '500';
			$anchor_attributes['data-src']              = '#woo-additional-terms-content';
		}

		return sprintf(
			'<a %s>%s</a>',
			wc_implode_html_attributes( $anchor_attributes ),
			esc_html( get_the_title( woo_additional_terms()->service( 'options' )->get( 'page', 0 ) ) )
		);
	}

	/**
	 * Get the terms page content.
	 *
	 * @since 1.6.0
	 *
	 * @return string
	 */
	private function get_content() {

		$display_action = woo_additional_terms()->service( 'options' )->get( 'action', 'embed' );

		// Bail early, in case the display action is set to "New Tab".
		if ( 'newtab' === $display_action ) {
			return '';
		}

		$terms_page_id = woo_additional_terms()->service( 'options' )->get( 'page', false );

		// Bail early, in case the terms page ID is not valid.
		if ( empty( $terms_page_id ) || ! function_exists( 'get_post' ) ) {
			return '';
		}

		$terms_page = get_post( $terms_page_id );

		// Check if the terms page exists, and has content.
		if ( ! ( $terms_page instanceof WP_Post ) || empty( $terms_page->post_content ) ) {
			return '';
		}

		// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
		return apply_filters( 'the_content', $terms_page->post_content );
	}
}

```
