diff --git a/admin/class-custom-permalinks-posttypes.php b/admin/class-custom-permalinks-posttypes.php index 1138fa3..8640380 100644 --- a/admin/class-custom-permalinks-posttypes.php +++ b/admin/class-custom-permalinks-posttypes.php @@ -64,6 +64,7 @@ private function post_permalinks() $post_html = ''; $request_uri = ''; $search_permalink = ''; + $site_url = site_url(); if ( isset( $_SERVER['REQUEST_URI'] ) ) { $request_uri = $_SERVER['REQUEST_URI']; @@ -136,7 +137,7 @@ private function post_permalinks() $count_query = "SELECT COUNT(p.ID) AS total_permalinks FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE pm.meta_key = 'custom_permalink' AND pm.meta_value != '' " . $filter_permalink . ""; $count_posts = $wpdb->get_row( $count_query ); - $post_html .= '
' . + $post_html .= '' . '' . '
' . - '
' . + '' . '
' . '
' . '' . @@ -203,22 +204,52 @@ private function post_permalinks() '' . $table_navigation . '' . ''; if ( 0 != $posts && ! empty( $posts ) ) { + $cp_frontend = new Custom_Permalinks_Frontend(); + if ( class_exists( 'SitePress' ) ) { + $wpml_lang_format = apply_filters( 'wpml_setting', 0, + 'language_negotiation_type' + ); + + if ( 1 === intval( $wpml_lang_format ) ) { + $home_url = $site_url; + } + } + foreach ( $posts as $post ) { + $custom_permalink = '/' . $post->meta_value; + $post_type = 'post'; + if ( isset( $post->post_type ) ) { + $post_type = $post->post_type; + } + + $language_code = apply_filters( 'wpml_element_language_code', null, + array( + 'element_id' => $post->ID, + 'element_type' => $post_type + ) + ); + + $permalink = $cp_frontend->wpml_permalink_filter( $custom_permalink, + $language_code + ); + $permalink = $cp_frontend->remove_double_slash( $permalink ); + $perm_text = str_replace( $home_url, '', $permalink ); + $post_html .= '' . '' . '' . '' . '' . '' . - '' . + '' . $post->post_title . '' . '' . '' . '' . ucwords( $post->post_type ) . '' . '' . - 'post_title, "custom-permalinks" ) . '">/' . - urldecode( $post->meta_value ) . + 'post_title, "custom-permalinks" ) . '">' . + $perm_text . '' . '' . ''; diff --git a/admin/class-custom-permalinks-taxonomies.php b/admin/class-custom-permalinks-taxonomies.php index be2271a..16f6cb5 100644 --- a/admin/class-custom-permalinks-taxonomies.php +++ b/admin/class-custom-permalinks-taxonomies.php @@ -64,6 +64,7 @@ private function taxonomies_permalinks() $home_url = home_url(); $page_html = ''; $request_uri = ''; + $site_url = site_url(); if ( isset( $_SERVER['REQUEST_URI'] ) ) { $request_uri = $_SERVER['REQUEST_URI']; @@ -111,14 +112,14 @@ private function taxonomies_permalinks() $pager_offset = 20 * ( $_GET['paged'] - 1 ); $page_limit = $pager_offset + 20; } - $page_html .= '' . + $page_html .= '' . '' . '' . - '
' . + '' . '
' . '
' . '' . @@ -183,6 +184,17 @@ private function taxonomies_permalinks() ''; if ( $table && is_array( $table ) && 0 < $count_tags ) { + $cp_frontend = new Custom_Permalinks_Frontend(); + if ( class_exists( 'SitePress' ) ) { + $wpml_lang_format = apply_filters( 'wpml_setting', 0, + 'language_negotiation_type' + ); + + if ( 1 === intval( $wpml_lang_format ) ) { + $home_url = $site_url; + } + } + uasort( $table, array( $this, 'sort_array' ) ); $loopCount = -1; foreach ( $table as $permalink => $info ) { @@ -200,17 +212,34 @@ private function taxonomies_permalinks() $type = 'post_tag'; } + $language_code = apply_filters( 'wpml_element_language_code', + null, array( + 'element_id' => $info['id'], + 'element_type' => $type + ) + ); + + $permalink = $cp_frontend->wpml_permalink_filter( $permalink, + $language_code + ); + $permalink = $cp_frontend->remove_double_slash( $permalink ); + $perm_text = str_replace( $home_url, '', $permalink ); + $term = get_term( $info['id'], $type ); $page_html .= '' . '' . '' . '' . '' . - '' . $term->name . '' . + '' . + $term->name . + '' . '' . '' . ucwords( $info['kind'] ) . '' . '' . - 'name, "custom-permalinks" ) . '">/' . $permalink . '' . + 'name, "custom-permalinks" ) . '">' . + $perm_text . + '' . '' . ''; } diff --git a/frontend/class-custom-permalinks-frontend.php b/frontend/class-custom-permalinks-frontend.php index ba62bcb..756f8de 100644 --- a/frontend/class-custom-permalinks-frontend.php +++ b/frontend/class-custom-permalinks-frontend.php @@ -50,14 +50,14 @@ public function init() /** * Replace double slash `//` with single slash `/`. * - * @since 2.0.0 - * @access private + * @since 1.6.0 + * @access public * * @param string $permalink URL in which `//` needs to be replaced with `/`. * * @return string URL with single slash. */ - private function remove_double_slash( $permalink = '' ) + public function remove_double_slash( $permalink = '' ) { $protocol = ''; if ( 0 === strpos( $permalink, 'http://' ) @@ -80,15 +80,15 @@ private function remove_double_slash( $permalink = '' ) * Use `wpml_permalink` to add language information to permalinks and * resolve language switcher issue if found. * - * @since 2.0.0 - * @access private + * @since 1.6.0 + * @access public * * @param string $permalink Custom Permalink. * @param string $language_code The language to convert the url into. * * @return string permalink with language information. */ - private function wpml_permalink_filter( $permalink = '', $language_code ) + public function wpml_permalink_filter( $permalink = '', $language_code ) { $custom_permalink = $permalink; $trailing_permalink = trailingslashit( home_url() ) . $custom_permalink; @@ -457,9 +457,10 @@ public function custom_post_link( $permalink, $post ) $permalink = $this->wpml_permalink_filter( $custom_permalink, $language_code ); - $permalink = $this->remove_double_slash( $permalink ); } + $permalink = $this->remove_double_slash( $permalink ); + return $permalink; } @@ -487,9 +488,10 @@ public function custom_page_link( $permalink, $page ) $permalink = $this->wpml_permalink_filter( $custom_permalink, $language_code ); - $permalink = $this->remove_double_slash( $permalink ); } + $permalink = $this->remove_double_slash( $permalink ); + return $permalink; } @@ -529,10 +531,11 @@ public function custom_term_link( $permalink, $term ) $permalink = $this->wpml_permalink_filter( $custom_permalink, $language_code ); - $permalink = $this->remove_double_slash( $permalink ); } } + $permalink = $this->remove_double_slash( $permalink ); + return $permalink; } @@ -651,6 +654,16 @@ public function custom_trailingslash( $url_string ) $trailingslash_string = $url_string; $url = parse_url( get_bloginfo( 'url' ) ); + if ( class_exists( 'SitePress' ) ) { + $wpml_lang_format = apply_filters( 'wpml_setting', 0, + 'language_negotiation_type' + ); + + if ( 1 === intval( $wpml_lang_format ) ) { + $url = parse_url( get_bloginfo( 'wpurl' ) ); + } + } + if ( isset( $url['path'] ) ) { $request = substr( $url_string, strlen( $url['path'] ) ); } else {