Skip to content

Commit

Permalink
Bump version to 2.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
keesiemeijer committed Jan 26, 2020
2 parents 93a10ad + 4bde74d commit 43ede8f
Show file tree
Hide file tree
Showing 35 changed files with 553 additions and 253 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ matrix:
- php: 7.2
env: WP_VERSION=latest WP_MULTISITE=1
- php: 7.2
env: WP_VERSION=5.1 WP_MULTISITE=0 RPBT_WP_TS_VERSION=version
env: WP_VERSION=5.2 WP_MULTISITE=0 RPBT_WP_TS_VERSION=version
- php: 7.2
env: WP_VERSION=5.0 WP_MULTISITE=0 RPBT_WP_TS_VERSION=version
env: WP_VERSION=5.1 WP_MULTISITE=0 RPBT_WP_TS_VERSION=version
- php: 7.1
env: WP_VERSION=latest WP_MULTISITE=0
- php: 7.0
Expand Down
2 changes: 1 addition & 1 deletion includes/assets/js/lazy-loading.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Ajax query for related posts
*
*
* @since 2.6.0
*/

Expand Down
4 changes: 2 additions & 2 deletions includes/assets/js/lazy-loading.min.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* related-posts-by-taxonomy
* v2.7.2
* 2019-12-23
* v2.7.3
* 2020-01-26
**/

!function(e){if("undefined"!=typeof rpbt_lazy_loading){var t="Related Posts by Taxonomy Ajax Error: ";e(document).ready(function(){e(".rpbt-related-posts-lazy-loading").each(function(){var n=e(this),a=e(this).data("rpbt_args")||{},o={action:"rpbt_lazy_loading",nonce:rpbt_lazy_loading.nonce,args:a};e.post(rpbt_lazy_loading.ajaxurl,o).done(function(a){var o=a.hasOwnProperty("success"),e=a.hasOwnProperty("data");o&&e?!0===a.success?a.data.length?n.replaceWith(a.data):n.remove():console.log(t+"failed request "):console.log(t+"missing properties")}).fail(function(a){console.log(t+"failed response")})})})}}(jQuery);
6 changes: 3 additions & 3 deletions includes/back-compat/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function km_rpbt_get_shortcode_atts() {
* @since 2.1
* @param array $related_posts Array with related post objects.
* @param array $rpbt_args Shortcode arguments.
* See km_rpbt_related_posts_by_taxonomy_shortcode() for for more
* See km_rpbt_related_posts_by_taxonomy_shortcode() for more
* information on accepted arguments.
* @return string Shortcode output.
*/
Expand Down Expand Up @@ -175,12 +175,12 @@ function km_rpbt_related_posts_by_taxonomy_widget() {
* Use the {@see 'related_posts_by_taxonomy_post_class'} filter to add post classes on a
* post per post basis
*
* @since 2.4.0
* @since 2.4.0
* @deprecated 2.6.0
*
* @param array $related_posts Array with (related) post objects.
* @param array|string $args Widget or shortcode arguments.
* See km_rpbt_get_related_posts() for for more
* See km_rpbt_get_related_posts() for more
* information on accepted arguments.
* @return array Array with related post objects with classes added.
*/
Expand Down
20 changes: 10 additions & 10 deletions includes/class-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Class to manage the persistent cache feature.
*
* @since 2.0.0
* @since 2.0.0
*/
class Related_Posts_By_Taxonomy_Cache {

Expand Down Expand Up @@ -132,7 +132,7 @@ private function get_cache_settings() {
*
* @since 2.0.1
* @param array $args Array with widget or shortcode args.
* See km_rpbt_get_related_posts() for for more
* See km_rpbt_get_related_posts() for more
* information on accepted arguments.
* @return array Array with widget or shortcode args.
*/
Expand All @@ -146,7 +146,7 @@ public function add_cache( $args ) {
*
* @since 2.0.1
* @param array $args Array with widget or shortcode args.
* See km_rpbt_get_related_posts() for for more
* See km_rpbt_get_related_posts() for more
* information on accepted arguments.
* @return array Array with related post objects .
*/
Expand Down Expand Up @@ -217,7 +217,7 @@ public function update_cache( $args ) {
*
* @since 2.0.1
* @param array $args Array with Widget or shortcode arguments.
* See km_rpbt_get_related_posts() for for more
* See km_rpbt_get_related_posts() for more
* information on accepted arguments.
* @return array Array with related post objects that are cached.
*/
Expand Down Expand Up @@ -275,7 +275,7 @@ private function set_cache( $args ) {
*
* @since 2.0.1
* @param array $args Array with sanitized widget or shortcode arguments.
* See km_rpbt_get_related_posts() for for more
* See km_rpbt_get_related_posts() for more
* information on accepted arguments.
* @param array $cache Array with cached post ids.
* @return array Array with related post objects.
Expand Down Expand Up @@ -364,7 +364,7 @@ private function get_cache( $args, $cache ) {
*
* @since 2.1.2
* @param array $args Widget or Shortcode arguments.
* See km_rpbt_get_related_posts() for for more
* See km_rpbt_get_related_posts() for more
* information on accepted arguments.
* @return boolean True if post_id and taxonomies are set.
*/
Expand All @@ -382,7 +382,7 @@ public function is_valid_cache_args( $args ) {
*
* @since 2.1
* @param array $args Array with widget or shortcode argument.
* See km_rpbt_get_related_posts() for for more
* See km_rpbt_get_related_posts() for more
* information on accepted arguments.
* @return array Array with sanitized widget or shortcode arguments.
*/
Expand Down Expand Up @@ -426,7 +426,7 @@ public function order_cache_args( $args ) {
*
* @since 2.0.1
* @param array $args Array with widget or shortcode arguments.
* See km_rpbt_get_related_posts() for for more
* See km_rpbt_get_related_posts() for more
* information on accepted arguments.
* @return array Array with Related posts ids, empty string, or empty array.
*/
Expand All @@ -440,7 +440,7 @@ public function get_post_meta( $args ) {
*
* @since 2.0.1
* @param array $args Array with widget or shortcode arguments.
* See km_rpbt_get_related_posts() for for more
* See km_rpbt_get_related_posts() for more
* information on accepted arguments.
* @return string Meta key created from sanitized args.
*/
Expand All @@ -457,7 +457,7 @@ public function get_post_meta_key( $args ) {
* @param int $post_id Post id used to get the related posts.
* @param array $taxonomies Taxonomies used to get the related posts.
* @param array $args Query arguments used to get the related posts.
* See km_rpbt_get_related_posts() for for more
* See km_rpbt_get_related_posts() for more
* information on accepted arguments.
* @return array Array with widget or shortcode args.
*/
Expand Down
87 changes: 65 additions & 22 deletions includes/class-debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function debug_setup() {
* @since 2.0.0
*
* @param array $args Widget or shortcode arguments.
* @param array $widget Widget args.
* @param array $widget Widget arguments.
* @return array Array with widget or shortcode arguments.
*/
function debug_start( $args, $widget = '' ) {
Expand All @@ -119,7 +119,7 @@ function debug_start( $args, $widget = '' ) {

if ( 'related_posts_by_taxonomy_widget_args' === current_filter() ) {
$this->debug['type'] = 'widget';
$this->debug['widget args'] = $args;
$this->debug['widget arguments'] = $args;
$this->debug['widget'] = $widget;

} else {
Expand Down Expand Up @@ -217,14 +217,20 @@ function debug_link( $type = 'widget' ) {
* @since 2.6.0
*/
function pre_related_posts( $posts, $args ) {
$post_id = $args['post_id'];
$taxonomies = $args['taxonomies'];
$related = $args['related'];
$post_id = $args['post_id'];
$taxonomies = $args['taxonomies'];
$back_compat = is_bool( $args['related'] );
$include_terms = ( $args['include_terms'] || $args['terms'] );

$terms = get_terms( array( 'fields' => 'names', 'object_ids' => array( $post_id ) ) );
$terms = ! is_wp_error( $terms ) ? $terms : array();

$taxonomies = ! $related && $args['terms'] ? 'No taxonomies used in query (unrelated terms)' : $taxonomies;
if ( $back_compat && $include_terms && ! $args['related'] ) {
$taxonomies = 'No taxonomies used in query (related - false)';
} elseif ( ! $back_compat && $include_terms ) {
$taxonomies = 'No taxonomies used in query (related - null)';
}

$taxonomies = is_array( $taxonomies ) ? implode( ', ', $taxonomies ) : $taxonomies;

$this->debug['current post id'] = $post_id;
Expand Down Expand Up @@ -270,8 +276,14 @@ function posts_clauses( $pieces, $post_id, $taxonomies, $args ) {

$query = "SELECT {$select_sql} FROM $wpdb->posts {$join_sql} {$where_sql} {$group_by_sql} {$order_by_sql} {$limit_sql}";

// Remove prefix
$query = str_replace( $wpdb->prefix , '' , $query );

// Format query
$query = preg_replace( "/ INNER JOIN /", " \nINNER JOIN ", $query );
$query = preg_replace( "/ WHERE /", " \nWHERE ", $query );
$query = preg_replace( "/ AND /", " \nAND ", $query );

$term_names = $this->get_terms_names( $args['related_terms'] );

$this->debug['terms used for query'] = $term_names;
Expand Down Expand Up @@ -369,7 +381,7 @@ function get_terms_names( $term_ids ) {
/**
* Returns a fancy header for the debug information.
*
* @since 2.3.1
* @since 2.3.1
*
* @param string $type Type of debug.
* @return string Fancy header.
Expand Down Expand Up @@ -420,6 +432,47 @@ function get_supports() {
return $supports;
}

/**
* Get inline style for HTML pre tag.
*
* @since 2.7.3
*
* @return string Inline styles.
*/
function get_style() {
$style = 'border:0 none;outline:0 none;padding:20px;margin:0;';
$style .= 'color: #333;background: #f5f5f5;font-family: monospace;font-size: 16px;font-style: normal;font-weight: normal;line-height: 1.5;white-space: pre;overflow:auto;';
$style .= 'width:100%;display:block;float:none;clear:both;text-align:left;z-index: 999;position:relative;';
return $style;
}

/**
* Get formatted debug section HTML.
*
* @since 2.7.3
*
* @param string|array $value Debug section value.
* @return string Formatted debug section HTML.
*/
function get_section_html( $value ) {
$section = '';
if ( is_array( $value ) ) {
$style = $this->get_style();
// create string from array
$value = var_export( $value, true );
// clean up arrays
$value = preg_replace( "/\=>\s*array\s*\(/", '=> array(', $value );
$value = preg_replace( "/array\s*\(\s*\),/", 'array(),', $value );
// convert spaces to tabs
$value = preg_replace( "/(?<![^\s]{2}) /", "\t", $value );
$section = "<pre style='{$style}'>" . htmlspecialchars( $value ) . '</pre>';
} else {
$section = "{$value}\n";
}

return "{$section}\n";
}

/**
* Displays the results in the footer
*/
Expand All @@ -431,18 +484,16 @@ function wp_footer() {
'taxonomies used for query', 'cached taxonomies',
'terms used for query', 'cached terms',
'related post ids found', 'cached post ids',
'widget args', 'shortcode args', 'function args',
'widget arguments', 'shortcode args', 'function args',
'related posts query',
'requested template', 'widget'
);
$order = array_fill_keys( $order , '' );
$style = 'border:0 none;outline:0 none;padding:20px;margin:0;';
$style .= 'color: #333;background: #f5f5f5;font-family: monospace;font-size: 16px;font-style: normal;font-weight: normal;line-height: 1.5;white-space: pre;overflow:auto;';
$style .= 'width:100%;display:block;float:none;clear:both;text-align:left;z-index: 999;position:relative;';
$style = $this->get_style();

echo "<pre style='{$style}'>" . $this->get_header( 'General Debug Information' ) . "\n\n";
echo "Plugin Supports \n\n";
echo htmlspecialchars( print_r( $this->get_supports(), true ) );
echo $this->get_section_html( $this->get_supports() );
echo $seperator;
echo "All post types found (public and private)\n\n";
$post_types = implode( ', ', $this->post_types );
Expand Down Expand Up @@ -473,7 +524,7 @@ function wp_footer() {
}

if ( 'shortcode' === $debug_arr['type'] ) {
unset( $_order['widget args'], $_order['widget'] );
unset( $_order['widget arguments'], $_order['widget'] );
}

// reorder debug array.
Expand Down Expand Up @@ -506,15 +557,7 @@ function wp_footer() {
}

echo $title . ":\n\n";
if ( is_array( $value ) ) {
echo '<pre>';
echo htmlspecialchars( print_r( $value, true ) );
echo '</pre>';
} else {
echo $value . "\n";
}

echo "\n";
echo $this->get_section_html( $value );
echo $seperator;
}
echo '</pre>';
Expand Down
10 changes: 2 additions & 8 deletions includes/class-defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,15 @@ public function _setup() {
*/
public function get_post_types() {
$post_types = array();
$post_types_obj = get_post_types( array( 'public' => true, '_builtin' => false ), 'objects', 'and' );
$post_types_obj = get_post_types( array( 'public' => true ), 'objects', 'and' );

$post_types_obj = array( 'post' => get_post_type_object( 'post' ) ) + $post_types_obj;
foreach ( (array) $post_types_obj as $key => $value ) {
// Use only post types that have taxonomies.
if ( $this->has_taxonomies( $key ) ) {
$post_types[ $key ] = esc_attr( $value->labels->menu_name );
}
}

if ( $this->has_taxonomies( 'page' ) ) {
// Post type page has taxonomies.
$page = get_post_type_object( 'page' );
$post_types['page'] = esc_attr( $page->labels->menu_name );
}

// Default to post.
if ( empty( $post_types ) ) {
$post_types = array( 'post' => __( 'Post', 'related-posts-by-taxonomy' ) );
Expand Down
4 changes: 2 additions & 2 deletions includes/class-lazy-loading.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* Lazy loading feature
*
*
* Query related posts after the page has loaded (with Ajax).
*
* @since 2.6.0
Expand Down Expand Up @@ -76,7 +76,7 @@ public function lazy_loading_query() {
$args['fields'] = km_rpbt_get_template_fields( $args );

$related_posts = km_rpbt_get_related_posts( $args['post_id'], $args );
$hide_empty = (bool) km_rpbt_plugin_supports( "{$type}_hide_empty" );
$hide_empty = (bool) km_rpbt_plugin_supports( "{$type}_hide_empty", $args );

$html = '';
if ( ! $hide_empty || ! empty( $related_posts ) ) {
Expand Down
Loading

0 comments on commit 43ede8f

Please sign in to comment.