| @@ -1,16 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * Manages links filters needed on both frontend and admin | |
| 4 | + * manages links filters needed on both frontend and admin | |
| 5 | 5 | * |
| 6 | 6 | * @since 1.8 |
| 7 | 7 | */ |
| 8 | 8 | class PLL_Filters_Links { |
| 9 | - public $links, $links_model, $model, $options, $curlang; | |
| 9 | + public $links, $links_model, $model, $options; | |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * Constructor | |
| 12 | + * constructor | |
| 13 | 13 | * |
| 14 | 14 | * @since 1.8 |
| 15 | 15 | * |
| 16 | 16 | * @param object $polylang |
| @@ -19,11 +19,10 @@ | ||
| 19 | 19 | $this->links = &$polylang->links; |
| 20 | 20 | $this->links_model = &$polylang->links_model; |
| 21 | 21 | $this->model = &$polylang->model; |
| 22 | 22 | $this->options = &$polylang->options; |
| 23 | - $this->curlang = &$polylang->curlang; | |
| 24 | 23 | |
| 25 | - // Low priority on links filters to come after any other modifications. | |
| 24 | + // low priority on links filters to come after any other modifications | |
| 26 | 25 | if ( $this->options['force_lang'] ) { |
| 27 | 26 | add_filter( 'post_link', array( $this, 'post_type_link' ), 20, 2 ); |
| 28 | 27 | add_filter( '_get_page_link', array( $this, '_get_page_link' ), 20, 2 ); |
| 29 | 28 | } |
| @@ -34,19 +33,15 @@ | ||
| 34 | 33 | if ( $this->options['force_lang'] > 0 ) { |
| 35 | 34 | add_filter( 'attachment_link', array( $this, 'attachment_link' ), 20, 2 ); |
| 36 | 35 | } |
| 37 | 36 | |
| 38 | - // Keeps the preview post link on default domain when using multiple domains and SSO is not available. | |
| 39 | - if ( 3 === $this->options['force_lang'] && ! class_exists( 'PLL_Xdata_Domain' ) ) { | |
| 37 | + if ( 3 === $this->options['force_lang'] ) { | |
| 40 | 38 | add_filter( 'preview_post_link', array( $this, 'preview_post_link' ), 20 ); |
| 41 | 39 | } |
| 42 | - | |
| 43 | - // Rewrites post types archives links to filter them by language. | |
| 44 | - add_filter( 'post_type_archive_link', array( $this, 'post_type_archive_link' ), 20, 2 ); | |
| 45 | 40 | } |
| 46 | 41 | |
| 47 | 42 | /** |
| 48 | - * Modifies page links | |
| 43 | + * modifies page links | |
| 49 | 44 | * |
| 50 | 45 | * @since 1.7 |
| 51 | 46 | * |
| 52 | 47 | * @param string $link post link |
| @@ -54,13 +49,13 @@ | ||
| 54 | 49 | * @return string modified post link |
| 55 | 50 | */ |
| 56 | 51 | public function _get_page_link( $link, $post_id ) { |
| 57 | 52 | // /!\ WP does not use pretty permalinks for preview |
| 58 | - return false !== strpos( $link, 'preview=true' ) && false !== strpos( $link, 'page_id=' ) ? $link : $this->links_model->switch_language_in_link( $link, $this->model->post->get_language( $post_id ) ); | |
| 53 | + return false !== strpos( $link, 'preview=true' ) && false !== strpos( $link, 'page_id=' ) ? $link : $this->links_model->add_language_to_link( $link, $this->model->post->get_language( $post_id ) ); | |
| 59 | 54 | } |
| 60 | 55 | |
| 61 | 56 | /** |
| 62 | - * Modifies attachment links | |
| 57 | + * modifies attachment links | |
| 63 | 58 | * |
| 64 | 59 | * @since 1.6.2 |
| 65 | 60 | * |
| 66 | 61 | * @param string $link attachment link |
| @@ -67,13 +62,13 @@ | ||
| 67 | 62 | * @param int $post_id attachment link |
| 68 | 63 | * @return string modified attachment link |
| 69 | 64 | */ |
| 70 | 65 | public function attachment_link( $link, $post_id ) { |
| 71 | - return wp_get_post_parent_id( $post_id ) ? $link : $this->links_model->switch_language_in_link( $link, $this->model->post->get_language( $post_id ) ); | |
| 66 | + return wp_get_post_parent_id( $post_id ) ? $link : $this->links_model->add_language_to_link( $link, $this->model->post->get_language( $post_id ) ); | |
| 72 | 67 | } |
| 73 | 68 | |
| 74 | 69 | /** |
| 75 | - * Modifies custom posts links | |
| 70 | + * modifies custom posts links | |
| 76 | 71 | * |
| 77 | 72 | * @since 1.6 |
| 78 | 73 | * |
| 79 | 74 | * @param string $link post link |
| @@ -83,9 +78,9 @@ | ||
| 83 | 78 | public function post_type_link( $link, $post ) { |
| 84 | 79 | // /!\ WP does not use pretty permalinks for preview |
| 85 | 80 | if ( ( false === strpos( $link, 'preview=true' ) || false === strpos( $link, 'p=' ) ) && $this->model->is_translated_post_type( $post->post_type ) ) { |
| 86 | 81 | $lang = $this->model->post->get_language( $post->ID ); |
| 87 | - $link = $this->options['force_lang'] ? $this->links_model->switch_language_in_link( $link, $lang ) : $link; | |
| 82 | + $link = $this->options['force_lang'] ? $this->links_model->add_language_to_link( $link, $lang ) : $link; | |
| 88 | 83 | |
| 89 | 84 | /** |
| 90 | 85 | * Filter a post or custom post type link |
| 91 | 86 | * |
| @@ -101,9 +96,9 @@ | ||
| 101 | 96 | return $link; |
| 102 | 97 | } |
| 103 | 98 | |
| 104 | 99 | /** |
| 105 | - * Modifies term link | |
| 100 | + * modifies term link | |
| 106 | 101 | * |
| 107 | 102 | * @since 0.7 |
| 108 | 103 | * |
| 109 | 104 | * @param string $link term link |
| @@ -113,9 +108,9 @@ | ||
| 113 | 108 | */ |
| 114 | 109 | public function term_link( $link, $term, $tax ) { |
| 115 | 110 | if ( $this->model->is_translated_taxonomy( $tax ) ) { |
| 116 | 111 | $lang = $this->model->term->get_language( $term->term_id ); |
| 117 | - $link = $this->options['force_lang'] ? $this->links_model->switch_language_in_link( $link, $lang ) : $link; | |
| 112 | + $link = $this->options['force_lang'] ? $this->links_model->add_language_to_link( $link, $lang ) : $link; | |
| 118 | 113 | |
| 119 | 114 | /** |
| 120 | 115 | * Filter a term link |
| 121 | 116 | * |
| @@ -136,9 +131,9 @@ | ||
| 136 | 131 | return $link; |
| 137 | 132 | } |
| 138 | 133 | |
| 139 | 134 | /** |
| 140 | - * Keeps the preview post link on default domain when using multiple domains | |
| 135 | + * FIXME: keeps the preview post link on default domain when using multiple domains | |
| 141 | 136 | * |
| 142 | 137 | * @since 1.6.1 |
| 143 | 138 | * |
| 144 | 139 | * @param string $url |
| @@ -145,24 +140,7 @@ | ||
| 145 | 140 | * @return string modified url |
| 146 | 141 | */ |
| 147 | 142 | public function preview_post_link( $url ) { |
| 148 | 143 | return $this->links_model->remove_language_from_link( $url ); |
| 149 | - } | |
| 150 | - | |
| 151 | - /** | |
| 152 | - * Modifies the post type archive links to add the language parameter | |
| 153 | - * only if the post type is translated | |
| 154 | - * | |
| 155 | - * The filter was originally only on frontend but is needed on admin too for | |
| 156 | - * compatibility with the archive link of the ACF link field since ACF 5.4.0 | |
| 157 | - * | |
| 158 | - * @since 1.7.6 | |
| 159 | - * | |
| 160 | - * @param string $link | |
| 161 | - * @param string $post_type | |
| 162 | - * @return string modified link | |
| 163 | - */ | |
| 164 | - public function post_type_archive_link( $link, $post_type ) { | |
| 165 | - return $this->model->is_translated_post_type( $post_type ) && 'post' !== $post_type ? $this->links_model->switch_language_in_link( $link, $this->curlang ) : $link; | |
| 166 | 144 | } |
| 167 | 145 | } |
| 168 | 146 | |