Skip to content

Commit

Permalink
Merge pull request #1 from yasglobal/develop
Browse files Browse the repository at this point in the history
Fixed PolyLang Conflicts
  • Loading branch information
samiahmedsiddiqui authored Jul 21, 2017
2 parents d99821e + d5e8add commit 28a7a08
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
39 changes: 22 additions & 17 deletions custom-permalinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin URI: https://wordpress.org/plugins/custom-permalinks/
* Donate link: https://www.paypal.me/yasglobal
* Description: Set custom permalinks on a per-post basis
* Version: 0.9.2
* Version: 0.9.3
* Author: Michael Tyson
* Author URI: http://atastypixel.com/blog
* Text Domain: custom-permalinks
Expand Down Expand Up @@ -42,48 +42,54 @@

/**
* Filter to replace the post permalink with the custom one
*
* @package CustomPermalinks
* @since 0.1
*/
function custom_permalinks_post_link($permalink, $post) {
$custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true );
if ( $custom_permalink ) {
return apply_filters( 'wpml_permalink', home_url()."/".$custom_permalink );
$post_type = isset($post->post_type) ? $post->post_type : 'post';
$language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $post->ID, 'element_type' => $post_type ) );
if ( $language_code )
return apply_filters( 'wpml_permalink', home_url()."/".$custom_permalink, $language_code );
else
return apply_filters( 'wpml_permalink', home_url()."/".$custom_permalink );
}

return $permalink;
}

/**
* Filter to replace the page permalink with the custom one
*
* @package CustomPermalinks
* @since 0.4
*/
function custom_permalinks_page_link($permalink, $page) {
$custom_permalink = get_post_meta( $page, 'custom_permalink', true );
if ( $custom_permalink ) {
return apply_filters( 'wpml_permalink', home_url()."/".$custom_permalink );
if ( $custom_permalink ) {
$language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $page, 'element_type' => 'page' ) );
if ( $language_code )
return apply_filters( 'wpml_permalink', home_url()."/".$custom_permalink, $language_code );
else
return apply_filters( 'wpml_permalink', home_url()."/".$custom_permalink );
}

return $permalink;
}

/**
* Filter to replace the term permalink with the custom one
*
* @package CustomPermalinks
* @since 0.1
*/
function custom_permalinks_term_link($permalink, $term) {
$table = get_option('custom_permalink_table');
if ( is_object($term) ) $term = $term->term_id;

$custom_permalink = custom_permalinks_permalink_for_term($term);

if ( $custom_permalink ) {
return apply_filters( 'wpml_permalink', home_url()."/".$custom_permalink );
$taxonomy = get_term($term);
if ( isset($taxonomy) && isset($taxonomy->term_taxonomy_id) ) {
$term_type = isset($taxonomy->taxonomy) ? $taxonomy->taxonomy : 'category';
$language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $taxonomy->term_taxonomy_id, 'element_type' => $term_type ) );
return apply_filters( 'wpml_permalink', home_url()."/".$custom_permalink, $language_code );
} else {
return apply_filters( 'wpml_permalink', home_url()."/".$custom_permalink );
}
}

return $permalink;
Expand Down Expand Up @@ -811,8 +817,7 @@ function custom_permalinks_check_conflicts($requested_url = '') {
if ($requested_url == '') return;

// Check if the Polylang Plugin is installed so, make changes in the URL
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if (is_plugin_active("polylang/polylang.php")) {
if (defined( 'POLYLANG_VERSION' )) {
$polylang_config = get_option('polylang');
if ($polylang_config['force_lang'] == 1) {

Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Donate link: https://www.paypal.me/yasglobal
Tags: permalink, url, link, address, custom, redirect, custom post type
Requires at least: 2.6
Tested up to: 4.8
Stable tag: 0.9.2
Stable tag: 0.9.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -34,6 +34,10 @@ within that category.

== Changelog ==

= 0.9.3 =

* Fixed PolyLang Conflicts

= 0.9.2 =

* Fixed WPML Conflicts
Expand Down

0 comments on commit 28a7a08

Please sign in to comment.