diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fbd1e4a..a3ed7d57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [data-collection-permalink] - 2019-10-1 + +### Fixed +- Fixes permalink data on WP object in archive views. + ## [1.27.1] - 2019-12-13 ### Added diff --git a/dustpress.php b/dustpress.php index 14be53d1..0301d522 100644 --- a/dustpress.php +++ b/dustpress.php @@ -124,7 +124,8 @@ protected function __construct() { add_filter( 'posts_request', function( $request, \WP_Query $query ) { // Target main home query if ( $query->is_main_query() ) { - $request = str_replace( '1=1', '0=1', $request ); + $request = str_replace( '1=1', '0=1', $request ); + $query->query['disable_redipress'] = true; } return $request; @@ -643,7 +644,7 @@ private function populate_data_collection() { $wp_data['admin_ajax_url'] = admin_url( 'admin-ajax.php' ); // Insert current page permalink - $wp_data['permalink'] = get_permalink(); + $wp_data['permalink'] = $this->dp_get_permalink(); // Insert body classes $wp_data['body_class'] = get_body_class(); @@ -652,6 +653,76 @@ private function populate_data_collection() { return apply_filters( 'dustpress/data/wp', $wp_data ); } + /** + * Gets permalink. + * + * @type function + * @date 11/1/2019 + * @since 1.24.2 + * + * @return string Permalink. + */ + public function dp_get_permalink() { + + // Get request uri safely. + $request_uri = filter_var( $_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL ); + $permalink = $this->dp_get_home_url() . $request_uri; + + return $permalink; + } + + /** + * This has been copied from the WordPress core. + * WPML does filter the home_url so we cannot use the original function get_home_url() here. + * + * Original doc block: + * Retrieves the URL for a given site where the front end is accessible. + * + * Returns the 'home' option with the appropriate protocol. The protocol will be 'https' + * if is_ssl() evaluates to true; otherwise, it will be the same as the 'home' option. + * If `$scheme` is 'http' or 'https', is_ssl() is overridden. + * + * @since 3.0.0 + * + * @global string $pagenow + * + * @param int $blog_id Optional. Site ID. Default null (current site). + * @param string $path Optional. Path relative to the home URL. Default empty. + * @param string|null $scheme Optional. Scheme to give the home URL context. Accepts + * 'http', 'https', 'relative', 'rest', or null. Default null. + * @return string Home URL link with optional path appended. + */ + public function dp_get_home_url( $blog_id = null, $path = '', $scheme = null ) { + + global $pagenow; + + $orig_scheme = $scheme; + + if ( empty( $blog_id ) || ! is_multisite() ) { + $url = get_option( 'home' ); + } else { + switch_to_blog( $blog_id ); + $url = get_option( 'home' ); + restore_current_blog(); + } + + if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { + if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow ) { + $scheme = 'https'; + } else { + $scheme = parse_url( $url, PHP_URL_SCHEME ); + } + } + + $url = set_url_scheme( $url, $scheme ); + + if ( $path && is_string( $path ) ) { + $url .= '/' . ltrim( $path, '/' ); + } + + return $url; + } + /** * This function will render the given data in selected format * @@ -1171,7 +1242,11 @@ public function create_ajax_instance() { $response = [ 'success' => $html ]; } - if ( method_exists( '\DustPress\Debugger', 'use_debugger' ) && \DustPress\Debugger::use_debugger() ) { + if ( + method_exists( '\DustPress\Debugger', 'use_debugger' ) && + method_exists( '\DustPress\Debugger', 'get_data' ) && + \DustPress\Debugger::use_debugger() + ) { $response[ 'data' ] = $data; $response[ 'debug' ] = \DustPress\Debugger::get_data( 'Debugs'); } @@ -1249,7 +1324,11 @@ public function create_ajax_instance() { $output[ 'data' ] = $instance->data; } - if ( method_exists( '\DustPress\Debugger', 'use_debugger' ) && \DustPress\Debugger::use_debugger() ) { + if ( + method_exists( '\DustPress\Debugger', 'use_debugger' ) && + method_exists( '\DustPress\Debugger', 'get_data' ) && + \DustPress\Debugger::use_debugger() + ) { $output[ 'debug' ] = \DustPress\Debugger::get_data( 'Debugs' ); } @@ -1278,7 +1357,11 @@ public function create_ajax_instance() { $response = [ 'success' => $html ]; } - if ( method_exists( '\DustPress\Debugger', 'use_debugger' ) && \DustPress\Debugger::use_debugger() ) { + if ( + method_exists( '\DustPress\Debugger', 'use_debugger' ) && + method_exists( '\DustPress\Debugger', 'get_data' ) && + \DustPress\Debugger::use_debugger() + ) { $response[ 'data' ] = $data; $response[ 'debug' ] = \DustPress\Debugger::get_data( 'Debugs' ); }