Astra_Addon_Theme_Builder::get_template_preview_link( $post,  $post_preview_link,  $layout_value,  $template_type )

Gets the specific preview link for the template.


Description


Return

(string) Preview link.


Source

File: addons/advanced-hooks/classes/class-astra-addon-theme-builder.php

		public function get_template_preview_link( $post, $post_preview_link, $layout_value, $template_type ) {

			if ( 'template' === $layout_value ) {

				/**
				 * Get the display conditions.
				 * Based on the display conditions get the appropriate preview link.
				 * Return the preview link.
				 */

				$display_conditions = get_post_meta( $post->ID, 'ast-advanced-hook-location', true );

				if ( 'single' === $template_type ) {
					if ( isset( $display_conditions['rule'] ) ) {
						$display_rule = $display_conditions['rule'];
						if ( isset( $display_rule ) && isset( $display_rule[0] ) ) {
							$ruleParts = explode( '|', $display_rule[0] );
							if ( isset( $ruleParts ) && $ruleParts[0] ) {
								$pageValue = $ruleParts[0];
								if ( isset( $pageValue ) ) {
									if ( 'basic-global' === $pageValue || 'basic-singulars' === $pageValue ) {
										$pageValue = 'post';
									} elseif ( 'specifics' === $pageValue ) {
										$specific_post = $display_conditions['specific'];
										if ( isset( $specific_post ) && isset( $specific_post[0] ) ) {
											$specific_post = explode( '-', $specific_post[0] );
											if ( isset( $specific_post[1] ) ) {
												$specific_post_id = (int) $specific_post[1];
												$args             = array(
													'p' => $specific_post_id,
												);
												$specific_post    = get_posts( $args );
												if ( isset( $specific_post ) && isset( $specific_post[0] ) ) {
													$post_preview_link = get_preview_post_link( $specific_post[0]->ID );
												}
											}
										}
									} else {
										$args        = array(
											'posts_per_page' => 1,
											'orderby'   => 'rand',
											'post_type' => $pageValue,
										);
										$random_post = get_posts( $args );
										if ( isset( $random_post ) && isset( $random_post[0] ) ) {
											$post_preview_link = get_preview_post_link( $random_post[0]->ID );
										}
									}
								}
							}
						}
					}
				} elseif ( 'archive' === $template_type ) {
					$display_rule = $display_conditions['rule'];
					if ( isset( $display_rule ) && isset( $display_rule[0] ) ) {
						$display_rule = $display_rule[0];
					
						if ( 'basic-global' === $display_rule || 'basic-archives' === $display_rule || 'special-blog' === $display_rule ) {

							// URL for the entire site
							$post_preview_link = home_url();
						} elseif ( 'special-404' === $display_rule ) {

							// URL for the 404 Page
							$post_preview_link = home_url( '/hshsh' );
						} elseif ( 'special-search' === $display_rule ) {

							// URL for the Search Page
							$post_preview_link = home_url( '/?s=' );
						} elseif ( 'special-front' === $display_rule ) {

							// URL for the Front Page
							$post_preview_link = home_url();
						} elseif ( 'special-date' === $display_rule ) {

							// URL for the Date Archive
							$year  = date( 'Y' );
							$month = date( 'm' );
							if ( isset( $year ) && isset( $month ) ) {
								$post_preview_link = get_month_link( $year, $month );
							} else {
								$post_preview_link = get_preview_post_link( $post );
							}
						} elseif ( 'special-author' === $display_rule ) {

							// URL for the Author Archive
							$author_id = 1;
							$author    = get_userdata( $author_id );
							if ( isset( $author ) ) {
								$author_slug       = $author->user_nicename;
								$post_preview_link = home_url( '/author/' . $author_slug );
							} else {
								$post_preview_link = get_preview_post_link( $post );
							}
						} elseif ( 'post|all|archive' === $display_rule ) {

							// URL for All Posts Archive
							$post_preview_link = get_post_type_archive_link( 'post' );
						} elseif ( 'post|all|taxarchive|category' === $display_rule ) {

							// URL for All Categories Archive
							$categories = get_categories( array( 'number' => 1 ) );
							if ( ! empty( $categories ) ) {
								$category_slug     = $categories[0]->slug;
								$post_preview_link = get_term_link( $category_slug, 'category' );
							}
						} elseif ( 'post|all|taxarchive|post_tag' === $display_rule ) {

							// URL for All Tags Archive
							$tags = get_tags( array( 'number' => 1 ) );
							if ( ! empty( $tags ) ) {
								$tag_slug          = $tags[0]->slug;
								$post_preview_link = get_term_link( $tag_slug, 'post_tag' );
							}
						}
					}
				}
			}

			return $post_preview_link;
		}

Changelog

Changelog
Version Description
4.5.0 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.