Skip to content

Commit

Permalink
PHP deprecation fixes for strlen and substr
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0ttkclark committed Sep 19, 2023
1 parent 107adf3 commit c30862a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 5 additions & 1 deletion classes/Pods.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,11 @@ public function field( $name, $single = null, $raw = false ) {
$use_meta_fallback = apply_filters( 'pods_field_wp_object_use_meta_fallback', $use_meta_fallback, $pod_type );

if ( in_array( $params->name, $permalink_fields, true ) ) {
if ( 0 < strlen( $this->detail_page ) && false === strpos( $params->name, 'permalink' ) ) {
if (
is_string( $this->detail_page )
&& 0 < strlen( $this->detail_page )
&& false === strpos( $params->name, 'permalink' )
) {
// ACT Pods. Prevent tag loop by not parsing `permalink`.
$value = get_home_url() . '/' . $this->do_magic_tags( $this->detail_page );
} else {
Expand Down
12 changes: 6 additions & 6 deletions classes/fields/pick.php
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ public function data( $name, $value = null, $options = null, $pod = null, $id =
public function simple_value( $name, $value = null, $options = null, $pod = null, $id = null, $raw = false ) {

if ( in_array( pods_v( static::$type . '_object', $options ), $this->simple_objects(), true ) ) {
if ( ! is_array( $value ) && 0 < strlen( $value ) ) {
if ( ! is_array( $value ) && 0 < strlen( (string) $value ) ) {
$simple = @json_decode( $value, true );

if ( is_array( $simple ) ) {
Expand Down Expand Up @@ -2258,7 +2258,7 @@ public function simple_value( $name, $value = null, $options = null, $pod = null
} else {
$value = array_slice( $value, 0, $limit, true );
}
} elseif ( ! is_array( $value ) && null !== $value && 0 < strlen( $value ) ) {
} elseif ( ! is_array( $value ) && null !== $value && 0 < strlen( (string) $value ) ) {
if ( 1 !== $limit || ( true === $raw && 'multi' === $single_multi ) ) {
$value = array(
$key => $value,
Expand Down Expand Up @@ -2580,7 +2580,7 @@ public function get_object_data( $object_params = null ) {
$related_pod = $pod->pod_data;
} elseif ( is_array( $pod ) ) {
$pick_val = $pod['name'];
} elseif ( 0 < strlen( $pod ) ) {
} elseif ( is_string( $pod ) && 0 < strlen( $pod ) ) {
$pick_val = $pod;
}
}
Expand Down Expand Up @@ -2668,7 +2668,7 @@ public function get_object_data( $object_params = null ) {
$display_field_name = $search_data->field_index;
$display_field_alias = false;

if ( 0 < strlen( $display ) ) {
if ( is_string( $display ) && 0 < strlen( $display ) ) {
if ( ! empty( $table_info['pod'] ) ) {
/** @var Pod $related_pod */
$related_pod = $table_info['pod'];
Expand Down Expand Up @@ -2793,7 +2793,7 @@ public function get_object_data( $object_params = null ) {

$pick_orderby = pods_v( static::$type . '_orderby', $options, null, true );

if ( 0 < strlen( $pick_orderby ) ) {
if ( is_string( $pick_orderby ) && 0 < strlen( $pick_orderby ) ) {
$orderby[] = $pick_orderby;
}

Expand Down Expand Up @@ -2961,7 +2961,7 @@ public function get_object_data( $object_params = null ) {

$display_filter = pods_v( 'display_filter', $field_index_data_to_use );

if ( 0 < strlen( $display_filter ) ) {
if ( is_string( $display_filter ) && 0 < strlen( $display_filter ) ) {
$display_filter_args = pods_v( 'display_filter_args', $field_index_data_to_use );

$filter_args = array(
Expand Down
6 changes: 3 additions & 3 deletions components/Templates/includes/functions-view_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ function frontier_if_block( $attributes, $code ) {
return frontier_do_shortcode( $template );
}

$first_character = substr( $attributes['value'], 0, 1 );
$first_character = $attributes['value'] ? substr( (string) $attributes['value'], 0, 1 ) : null;

// check if + or - are present
if ( '+' === $first_character ) {
// is greater
$attributes['value'] = (float) substr( $attributes['value'], 1 ) + 1;
$attributes['value'] = (float) substr( (string) $attributes['value'], 1 ) + 1;
$attributes['compare'] = '>';
} elseif ( '-' === $first_character ) {
// is smaller
$attributes['value'] = (float) substr( $attributes['value'], 1 ) - 1;
$attributes['value'] = (float) substr( (string) $attributes['value'], 1 ) - 1;
$attributes['compare'] = '<';
}

Expand Down

0 comments on commit c30862a

Please sign in to comment.