diff --git a/README.md b/README.md index 5d2978c..7ba6893 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ within that category. ## Filters -If you want to exclude some Permalink to processed with the plugin so, just add the filter looks like this: +To exclude any Permalink to processed with the plugin so, just add the filter looks like this: ``` function check_xml_sitemap_url( $permalink ) { if ( false !== strpos( $permalink, 'sitemap.xml' )) { @@ -28,9 +28,7 @@ function check_xml_sitemap_url( $permalink ) { add_filter( 'custom_permalinks_request_ignore', 'check_xml_sitemap_url' ); ``` -If you want to exclude permalink from any post type so, use `custom_permalinks_exclude_post_type` filter. - -`custom_permalinks_exclude_post_type` filter looks like this: +To exclude permalink from any post type so, just add the filter looks like this: ``` function yasglobal_exclude_post_types( $post_type ) { if ( $post_type == 'custompost' ) { @@ -42,6 +40,12 @@ add_filter( 'custom_permalinks_exclude_post_type', 'yasglobal_exclude_post_types ``` Note: `custom_permalinks_exclude_post_type` doesn't work on the posts permalink which has been created previously. +To make the like query works as it was before so, just add this line in your theme's functions.php: +``` +add_filter( 'custom_permalinks_like_query', '__return_true'); +``` +Note: Use `custom_permalinks_like_query` filter if the URLs doesn't works for you after upgrading to v1.2.9 + ## Thanks for the Support! The support from the users that love Custom Permalinks is huge. You can support Custom Permalinks's future development and help to make it even better by donating or even giving a 5 star rating with a nice message to me :) diff --git a/custom-permalinks-main.php b/custom-permalinks-main.php index ddce97c..abfecb9 100644 --- a/custom-permalinks-main.php +++ b/custom-permalinks-main.php @@ -9,13 +9,13 @@ exit; } -if ( ! function_exists( "add_action" ) || ! function_exists( "add_filter" ) ) { +if ( ! function_exists( 'add_action' ) || ! function_exists( 'add_filter' ) ) { header( 'Status: 403 Forbidden' ); header( 'HTTP/1.1 403 Forbidden' ); exit(); } -define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.8' ); +define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.9' ); if ( ! defined( 'CUSTOM_PERMALINKS_PATH' ) ) { define( 'CUSTOM_PERMALINKS_PATH', plugin_dir_path( __FILE__ ) ); diff --git a/custom-permalinks.php b/custom-permalinks.php index 73e63d8..922d8b5 100644 --- a/custom-permalinks.php +++ b/custom-permalinks.php @@ -4,9 +4,9 @@ * Plugin Name: Custom Permalinks * Plugin URI: https://wordpress.org/plugins/custom-permalinks/ * Description: Set custom permalinks on a per-post basis - * Version: 1.2.8 + * Version: 1.2.9 * Author: Sami Ahmed Siddiqui - * Author URI: https://www.yasglobal.com/web-design-development/wordpress/custom-permalinks/ + * Author URI: https://www.custompermalinks.com * Donate link: https://www.paypal.me/yasglobal * License: GPLv2 or later * @@ -18,7 +18,7 @@ /** * Custom Permalinks Plugin - * Copyright 2008-2017 Sami Ahmed Siddiqui + * Copyright 2008-2018 Sami Ahmed Siddiqui * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,12 +41,6 @@ exit; } -if ( ! function_exists( "add_action" ) || ! function_exists( "add_filter" ) ) { - header( 'Status: 403 Forbidden' ); - header( 'HTTP/1.1 403 Forbidden' ); - exit(); -} - if ( ! defined( 'CUSTOM_PERMALINKS_FILE' ) ) { define( 'CUSTOM_PERMALINKS_FILE', __FILE__ ); } diff --git a/frontend/class-custom-permalinks-frontend.php b/frontend/class-custom-permalinks-frontend.php index a05720d..3c3f0b4 100644 --- a/frontend/class-custom-permalinks-frontend.php +++ b/frontend/class-custom-permalinks-frontend.php @@ -48,16 +48,19 @@ public function custom_permalinks_request( $query ) { return $query; } - $ignore = apply_filters( 'custom_permalinks_request_ignore', $request ); + $ignore = apply_filters( 'custom_permalinks_request_ignore', $request ); + $def_query = apply_filters( 'custom_permalinks_like_query', '__false' ); if ( '__true' === $ignore ) { return $query; } if ( defined( 'POLYLANG_VERSION' ) ) { - require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' ); - $custom_permalinks_form = new Custom_Permalinks_Form(); - $request = $custom_permalinks_form->custom_permalinks_check_conflicts( $request ); + require_once( + CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' + ); + $cp_form = new Custom_Permalinks_Form(); + $request = $cp_form->custom_permalinks_check_conflicts( $request ); } $request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) ); @@ -71,7 +74,8 @@ public function custom_permalinks_request( $query ) { $posts = $wpdb->get_results( $sql ); - if ( ! $posts ) { + if ( ! $posts && ( defined( 'POLYLANG_VERSION' ) + || defined( 'AMP__VERSION' ) || '__true' === $def_query ) ) { $sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " . " LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " . " meta_key = 'custom_permalink' AND meta_value != '' AND " . @@ -135,11 +139,13 @@ public function custom_permalinks_request( $query ) { if ( $term['kind'] == 'category' ) { $category_link = $this->custom_permalinks_original_category_link( $term['id'] ); - $original_url = str_replace( trim( $permalink, '/' ), $category_link, trim( $request, '/' ) ); } else { $category_link = $this->custom_permalinks_original_tag_link( $term['id'] ); - $original_url = str_replace( trim( $permalink, '/' ), $category_link, trim( $request, '/' ) ); } + + $original_url = str_replace( + trim( $permalink, '/' ), $category_link, trim( $request, '/' ) + ); } } } @@ -148,14 +154,18 @@ public function custom_permalinks_request( $query ) { $original_url = str_replace( '//', '/', $original_url ); if ( ( $pos = strpos( $_SERVER['REQUEST_URI'], '?' ) ) !== false ) { - $query_vars = substr( $_SERVER['REQUEST_URI'], $pos + 1); + $query_vars = substr( $_SERVER['REQUEST_URI'], $pos + 1); $original_url .= ( strpos( $original_url, '?' ) === false ? '?' : '&' ) . $query_vars; } // Now we have the original URL, run this back through WP->parse_request, in order to // parse parameters properly. We set $_SERVER variables to fool the function. - $old_request_uri = $_SERVER['REQUEST_URI']; $old_query_string = $_SERVER['QUERY_STRING']; - $_SERVER['REQUEST_URI'] = '/' . ltrim( $original_url, '/' ); + $old_request_uri = $_SERVER['REQUEST_URI']; + $old_query_string = ''; + if ( isset( $_SERVER['QUERY_STRING'] ) ) { + $old_query_string = $_SERVER['QUERY_STRING']; + } + $_SERVER['REQUEST_URI'] = '/' . ltrim( $original_url, '/' ); $_SERVER['QUERY_STRING'] = ( ( $pos = strpos( $original_url, '?' ) ) !== false ? substr( $original_url, $pos + 1 ) : '' ); parse_str( $_SERVER['QUERY_STRING'], $query_array ); $old_values = array(); @@ -174,7 +184,8 @@ public function custom_permalinks_request( $query ) { add_filter( 'request', array( $this, 'custom_permalinks_request' ), 10, 1 ); // Restore values - $_SERVER['REQUEST_URI'] = $old_request_uri; $_SERVER['QUERY_STRING'] = $old_query_string; + $_SERVER['REQUEST_URI'] = $old_request_uri; + $_SERVER['QUERY_STRING'] = $old_query_string; foreach ( $old_values as $key => $value ) { $_REQUEST[$key] = $value; } @@ -203,8 +214,8 @@ public function custom_permalinks_redirect() { if ( defined( 'POLYLANG_VERSION' ) ) { require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' ); - $custom_permalinks_form = new Custom_Permalinks_Form(); - $request = $custom_permalinks_form->custom_permalinks_check_conflicts( $request ); + $cp_form = new Custom_Permalinks_Form(); + $request = $cp_form->custom_permalinks_check_conflicts( $request ); } $request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) ); diff --git a/readme.txt b/readme.txt index 0180781..e7fa853 100644 --- a/readme.txt +++ b/readme.txt @@ -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.9 -Stable tag: 1.2.8 +Stable tag: 1.2.9 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -28,7 +28,9 @@ within that category. == Filters == -If you want to exclude some Permalink to processed with the plugin so, just add the filter looks like this: +Plugin provides some filter which maybe used according to your needs. + +To exclude any Permalink to processed with the plugin so, just add the filter looks like this: ` function check_xml_sitemap_url( $permalink ) { if ( false !== strpos( $permalink, 'sitemap.xml' )) { @@ -39,9 +41,7 @@ function check_xml_sitemap_url( $permalink ) { add_filter( 'custom_permalinks_request_ignore', 'check_xml_sitemap_url' ); ` -If you want to exclude permalink from any post type so, use `custom_permalinks_exclude_post_type` filter. - -custom_permalinks_exclude_post_type filter looks like this: +To exclude permalink from any post type so, just add the filter looks like this: ` function yasglobal_exclude_post_types( $post_type ) { if ( $post_type == 'custompost' ) { @@ -51,8 +51,16 @@ function yasglobal_exclude_post_types( $post_type ) { } add_filter( 'custom_permalinks_exclude_post_type', 'yasglobal_exclude_post_types'); ` + Note: custom_permalinks_exclude_post_type doesn't work on the posts permalink which has been created previously. +To make the like query works as it was before so, just add this line in your theme's functions.php: +` +add_filter( 'custom_permalinks_like_query', '__return_true'); +` + +Note: Use `custom_permalinks_like_query` filter if the URLs doesn't works for you after upgrading to v1.2.9 + == Thanks for the Support! == The support from the users that love Custom Permalinks is huge. You can support Custom Permalinks's future development and help to make it even better by donating or even giving a 5 star rating with a nice message to me :) @@ -67,6 +75,15 @@ The support from the users that love Custom Permalinks is huge. You can support == Changelog == += 1.2.9 = + + * Enhancements + * Added Filter to enable the like query + * Bugs + * PHP error displayed on all pages using custom permalinks + * Removed LIKE Query in default. It only works if the site uses PolyLang, + AMP Plugins or separately enabled using the provided filter. + = 1.2.8 = * Add Order by in request query