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
9 changes: 6 additions & 3 deletions inc/admin/metabox/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,13 @@ private function get_post_elements_default_order() {
$default_order = $this->get_v4_defaults( 'neve_layout_single_post_elements_order', $this->post_ordering() );

$content_order = get_theme_mod( 'neve_layout_single_post_elements_order', wp_json_encode( $default_order ) );
if ( ! is_string( $content_order ) ) {
$content_order = wp_json_encode( $default_order );
if ( is_string( $content_order ) ) {
$content_order = json_decode( $content_order, true );
}

if ( ! is_array( $content_order ) ) {
$content_order = $default_order;
}
$content_order = json_decode( $content_order, true );
if ( empty( $content_order ) ) {
return wp_json_encode( $content_order );
}
Expand Down
2 changes: 1 addition & 1 deletion inc/customizer/controls/ordering.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function get_component_status_class( $component ) {
if ( empty( $value ) ) {
return ' enabled';
}
$value = json_decode( $value, true );
$value = is_string( $value ) ? json_decode( $value, true ) : $value;

if ( ! is_array( $value ) ) {
$value = array();
Expand Down
10 changes: 9 additions & 1 deletion inc/customizer/options/layout_blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,15 @@ public function should_show_masonry() {
return false;
}

$columns = json_decode( get_theme_mod( 'neve_grid_layout', $this->grid_columns_default() ), true );
$columns = get_theme_mod( 'neve_grid_layout', $this->grid_columns_default() );
if ( is_string( $columns ) ) {
$columns = json_decode( $columns, true );
}

if ( ! is_array( $columns ) ) {
return false;
}

$columns = array_filter(
array_values( $columns ),
function ( $value ) {
Expand Down
17 changes: 14 additions & 3 deletions inc/customizer/options/layout_single_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,14 @@ public function element_is_enabled( $element ) {
);

$content_order = get_theme_mod( 'neve_layout_single_post_elements_order', wp_json_encode( $default_order ) );
$content_order = json_decode( $content_order, true );
if ( is_string( $content_order ) ) {
$content_order = json_decode( $content_order, true );
}

if ( ! is_array( $content_order ) ) {
$content_order = $default_order;
}

if ( ! in_array( $element, $content_order, true ) ) {
return false;
}
Expand Down Expand Up @@ -906,15 +913,19 @@ public function sanitize_post_elements_ordering( $value ) {
return wp_json_encode( $allowed );
}

$decoded = json_decode( $value, true );
$decoded = is_string( $value ) ? json_decode( $value, true ) : $value;

if ( ! is_array( $decoded ) ) {
return wp_json_encode( $allowed );
}

foreach ( $decoded as $val ) {
if ( ! in_array( $val, $allowed, true ) ) {
return wp_json_encode( $allowed );
}
}

return $value;
return wp_json_encode( array_values( $decoded ) );
}

/**
Expand Down
6 changes: 5 additions & 1 deletion inc/views/pluggable/metabox_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,11 @@ public function filter_post_elements( $elements_order ) {
return $elements_order;
}

return json_decode( $meta_elements_order, true );
if ( is_string( $meta_elements_order ) ) {
$meta_elements_order = json_decode( $meta_elements_order, true );
}

return is_array( $meta_elements_order ) ? $meta_elements_order : $elements_order;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions inc/views/post_layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,13 @@ private function get_content_order() {
$default_order = $this->get_v4_defaults( 'neve_layout_single_post_elements_order', $this->post_ordering() );

$content_order = get_theme_mod( 'neve_layout_single_post_elements_order', wp_json_encode( $default_order ) );
if ( ! is_string( $content_order ) ) {
$content_order = wp_json_encode( $default_order );
if ( is_string( $content_order ) ) {
$content_order = json_decode( $content_order, true );
}

if ( ! is_array( $content_order ) ) {
$content_order = $default_order;
}
Comment thread
girishpanchal30 marked this conversation as resolved.
$content_order = json_decode( $content_order, true );
if ( apply_filters( 'neve_filter_toggle_content_parts', true, 'title' ) !== true ) {
$title_key = array_search( 'title-meta', $content_order, true );
if ( $title_key !== false ) {
Expand Down
27 changes: 27 additions & 0 deletions tests/stubs/woocommerce-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,30 @@ function is_checkout() {
return false;
}
}

if ( ! function_exists( 'is_shop' ) ) {
/**
* Stand-in for the shop page conditional.
*
* The `WooCommerce` class above stays declared for the rest of the run, so any code
* gated on `class_exists( 'WooCommerce' )` reaches this too.
*
* @return bool
*/
function is_shop() {
return false;
}
}

if ( ! function_exists( 'wc_get_page_id' ) ) {
/**
* Stand-in for the WooCommerce page id lookup.
*
* @param string $page the page slug.
*
* @return int
*/
function wc_get_page_id( $page ) {
return -1;
}
}
177 changes: 0 additions & 177 deletions tests/test-neve-content-ordering.php

This file was deleted.

Loading
Loading