%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /dom645759/wp-content/plugins/the-events-calendar/src/Tribe/Integrations/WPML/
Upload File :
Create Path :
Current File : //dom645759/wp-content/plugins/the-events-calendar/src/Tribe/Integrations/WPML/Permalinks.php

<?php


/**
 * Class Tribe__Events__Integrations__WPML__Permalinks
 *
 * Handles permalink generations taking WPML into account.
 */
class Tribe__Events__Integrations__WPML__Permalinks {

	/**
	 * @var static
	 */
	protected static $instance;

	/**
	 * @var array
	 */
	protected $supported_post_types;

	/**
	 * Tribe__Events__Integrations__WPML__Permalinks constructor.
	 *
	 * @since 6.17.0 Made $supported_post_types explicitly nullable.
	 *
	 * @param array|null $supported_post_types An injectable array of supported post types.
	 */
	public function __construct( ?array $supported_post_types = null ) {
		$this->supported_post_types = null !== $supported_post_types ? $supported_post_types : [
			Tribe__Events__Organizer::POSTTYPE,
			Tribe__Events__Venue::POSTTYPE,
		];
	}

	/**
	 * @return Tribe__Events__Integrations__WPML__Permalinks
	 */
	public static function instance() {
		if ( empty( self::$instance ) ) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	/**
	 * Filters the post type link to remove WPML language query arg/frags on non translated posts.
	 *
	 * @param string  $post_link The post's permalink.
	 * @param WP_Post $post      The post in question.
	 */
	public function filter_post_type_link( $post_link, WP_Post $post ) {
		if ( ! in_array( $post->post_type, $this->supported_post_types ) ) {
			return $post_link;
		}

		/** @var SitePress $sitepress */
		global $sitepress;

		$post_language = $sitepress->get_language_for_element( $post->ID, 'post_' . $post->post_type );

		if ( $post_language === ICL_LANGUAGE_CODE ) {
			return $post_link;
		}

		// append the language as a query argument
		$language_negotiation_type = $sitepress->get_setting( 'language_negotiation_type' );


		switch ( $language_negotiation_type ) {
			case 1;
			case 2;
				$post_link = $this->get_post_permalink( $post, $post_language );
				break;
			case 3:
				$post_link = $this->update_language_query_arg( $post_link, $post_language );
				break;
			default:
				break;
		}

		return $post_link;
	}

	/**
	 * Returns the post link withe the language query arg removed or updated to the post language.
	 *
	 * @param string  $post_link
	 * @param WP_Post $post
	 * @param string  $post_language The post language code.
	 *
	 * @return string
	 */
	protected function update_language_query_arg( $post_link, $post_language ) {
		/** @var SitePress $sitepress */
		global $sitepress;

		if ( $post_language !== ICL_LANGUAGE_CODE ) {
			if ( $post_language === $sitepress->get_default_language() ) {
				$post_link = remove_query_arg( 'lang', $post_link );

				return $post_link;
			} else {
				$post_link = remove_query_arg( 'lang', $post_link );
				$post_link = add_query_arg( [ 'lang' => $post_language ], $post_link );

				return $post_link;
			}
		}

		return $post_link;
	}

	/**
	 * Returns the post permalink taking the post language into account.
	 *
	 * @param WP_Post      $post
	 * @param       string $post_language The post language code.
	 *
	 * @return string The post permalink.
	 */
	protected function get_post_permalink( WP_Post $post, $post_language ) {
		/** @var SitePress $sitepress */
		global $sitepress;

		$sitepress->switch_lang( $post_language );
		remove_filter( 'post_type_link', [ $this, 'filter_post_type_link' ], 20 );

		$post_link = get_permalink( $post->ID );

		add_filter( 'post_type_link', [ $this, 'filter_post_type_link' ], 20, 2 );
		$sitepress->switch_lang( ICL_LANGUAGE_CODE );

		return $post_link;
	}
}

Zerion Mini Shell 1.0
https://louisvillegop.com/sitemap505.xml 2026-12-01 https://louisvillegop.com/sitemap919.xml 2026-12-01 https://louisvillegop.com/sitemap766.xml 2026-12-01 https://louisvillegop.com/sitemap792.xml 2026-12-01 https://louisvillegop.com/sitemap848.xml 2026-12-01 https://louisvillegop.com/sitemap7.xml 2026-12-01 https://louisvillegop.com/sitemap673.xml 2026-12-01 https://louisvillegop.com/sitemap33.xml 2026-12-01 https://louisvillegop.com/sitemap314.xml 2026-12-01 https://louisvillegop.com/sitemap312.xml 2026-12-01 https://louisvillegop.com/sitemap556.xml 2026-12-01 https://louisvillegop.com/sitemap349.xml 2026-12-01 https://louisvillegop.com/sitemap63.xml 2026-12-01 https://louisvillegop.com/sitemap742.xml 2026-12-01 https://louisvillegop.com/sitemap210.xml 2026-12-01 https://louisvillegop.com/sitemap911.xml 2026-12-01 https://louisvillegop.com/sitemap145.xml 2026-12-01 https://louisvillegop.com/sitemap310.xml 2026-12-01 https://louisvillegop.com/sitemap725.xml 2026-12-01 https://louisvillegop.com/sitemap67.xml 2026-12-01 https://louisvillegop.com/sitemap922.xml 2026-12-01 https://louisvillegop.com/sitemap126.xml 2026-12-01 https://louisvillegop.com/sitemap409.xml 2026-12-01 https://louisvillegop.com/sitemap757.xml 2026-12-01 https://louisvillegop.com/sitemap154.xml 2026-12-01 https://louisvillegop.com/sitemap831.xml 2026-12-01 https://louisvillegop.com/sitemap207.xml 2026-12-01 https://louisvillegop.com/sitemap518.xml 2026-12-01 https://louisvillegop.com/sitemap102.xml 2026-12-01 https://louisvillegop.com/sitemap479.xml 2026-12-01 https://louisvillegop.com/sitemap991.xml 2026-12-01 https://louisvillegop.com/sitemap876.xml 2026-12-01 https://louisvillegop.com/sitemap448.xml 2026-12-01 https://louisvillegop.com/sitemap76.xml 2026-12-01 https://louisvillegop.com/sitemap950.xml 2026-12-01 https://louisvillegop.com/sitemap746.xml 2026-12-01 https://louisvillegop.com/sitemap688.xml 2026-12-01 https://louisvillegop.com/sitemap582.xml 2026-12-01 https://louisvillegop.com/sitemap525.xml 2026-12-01 https://louisvillegop.com/sitemap516.xml 2026-12-01 https://louisvillegop.com/sitemap402.xml 2026-12-01 https://louisvillegop.com/sitemap691.xml 2026-12-01 https://louisvillegop.com/sitemap390.xml 2026-12-01 https://louisvillegop.com/sitemap713.xml 2026-12-01 https://louisvillegop.com/sitemap752.xml 2026-12-01 https://louisvillegop.com/sitemap398.xml 2026-12-01 https://louisvillegop.com/sitemap358.xml 2026-12-01 https://louisvillegop.com/sitemap686.xml 2026-12-01 https://louisvillegop.com/sitemap967.xml 2026-12-01 https://louisvillegop.com/sitemap801.xml 2026-12-01 https://louisvillegop.com/sitemap581.xml 2026-12-01 https://louisvillegop.com/sitemap235.xml 2026-12-01 https://louisvillegop.com/sitemap965.xml 2026-12-01 https://louisvillegop.com/sitemap202.xml 2026-12-01 https://louisvillegop.com/sitemap277.xml 2026-12-01 https://louisvillegop.com/sitemap664.xml 2026-12-01 https://louisvillegop.com/sitemap307.xml 2026-12-01 https://louisvillegop.com/sitemap764.xml 2026-12-01 https://louisvillegop.com/sitemap996.xml 2026-12-01 https://louisvillegop.com/sitemap806.xml 2026-12-01 https://louisvillegop.com/sitemap853.xml 2026-12-01 https://louisvillegop.com/sitemap826.xml 2026-12-01 https://louisvillegop.com/sitemap476.xml 2026-12-01 https://louisvillegop.com/sitemap128.xml 2026-12-01 https://louisvillegop.com/sitemap567.xml 2026-12-01 https://louisvillegop.com/sitemap536.xml 2026-12-01 https://louisvillegop.com/sitemap849.xml 2026-12-01 https://louisvillegop.com/sitemap589.xml 2026-12-01 https://louisvillegop.com/sitemap952.xml 2026-12-01 https://louisvillegop.com/sitemap355.xml 2026-12-01