Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
93 changes: 88 additions & 5 deletions dustpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Comment on lines +667 to +669

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this create problems in installs that are not done on the root of a domain? If the home url was https://www.domain.com/subfolder and $request_uri was /subfolder/some-page this method would return https://www.domain.com/subfolder/subfolder/some-page.


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
*
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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' );
}

Expand Down Expand Up @@ -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' );
}
Expand Down