Parameter must be an array or an object metaboxes-framework/init.php - wordpress

Need help please!
metaboxes-framework/init.php
// if it's an array of one, extract it
elseif ( is_array( $meta_box['pages'] ) && count( $meta_box['pages'] === 1 ) )
$type = is_string( end( $meta_box['pages'] ) ) ? end( $meta_box['pages'] ) : false;
Parameter must be an array or an object metaboxes-framework/init.php
How can I correct this so that I don't get this error?

This is the correct way:
// if it's an array of one, extract it
elseif ( is_array( $meta_box['pages'] ) && count( $meta_box['pages']) === 1 )
$type = is_string( end( $meta_box['pages'] ) ) ? end( $meta_box['pages'] ) : false;
The closing parenthesis needs to be after the closing bracket, the way it's written originally means that it tries to count a boolean because the argument passed to count is $meta_box['pages] === 1
Funny thing is that I had exactly the same error in a WP plugin I installed and I didn't see it in my code editor so came across this question and immediately spotted the mistake :D

Related

My wordpress site suddenly displays this error for 2 days: Parse error: syntax error, unexpected '?' in ..../Module/ModuleViewAbstract.php

My wordpress site suddenly displays this error for 2 days: Parse error: syntax error, unexpected '?' on line 5 of this code :
protected function random_ads_position( $count ) {
$position = - 1;
$attr = $this->attribute;
if ( isset( $attr['ads_type'] ) && $attr['ads_type'] !== 'disable' ) {
$position = $attr['ads_random'] ? rand( $attr['ads_position']['size'] ?? $attr['ads_position'], ( $count - 2 ) ) : $position = $attr['ads_position'];
}
if ( is_array( $position ) && isset( $position['size'] ) ) { /* check ads position for Elementor */
$position = $position['size'];
}
return (int) $position;
}
As you write
$position = $attr['ads_random'] ? rand( $attr['ads_position']['size'] ?? $attr['ads_position'], ( $count - 2 ) ) : $position = $attr['ads_position'];
Seems the problem is in this line of code.
Thank you

Woocommerce - update_order_review become 502 after add_discount programmatically

I need some help. I want to implement, add existing coupon to cart when some conditions are fulfilled. I've got nothing wrong with the condition. But, when the function are going to add discount to coupon, the wc-ajax=update_order_review become 502.
However, if I do another things like changing address or something that can re-run update_order_review, it become 200. update_order_review successfully running and coupon is added to cart.
This is my function code so far, and I've copied some code from stackoverflow forum too
add_action('woocommerce_before_calculate_totals', 'discount_based_on_weight_threshold');
function discount_based_on_weight_threshold( $cart ) {
if ( ! defined( 'DOING_AJAX' ) )
return;
// Your settings
$coupon_code = 'freeongkir8krpx'; // Coupon code
// Initializing variables
$applied_coupons = $cart->get_applied_coupons();
$coupon_code = sanitize_text_field( $coupon_code );
$methods = WC()->session->get( 'chosen_shipping_methods' );
$method = isset( $methods[ 0 ] ) ? $methods[ 0 ] : false;
$kupon = new WC_Coupon('freeongkir10k');
if($method !== 'jne_shipping_test'){
if($cart->get_subtotal() <= $kupon->get_minimum_amount()){
$user = wp_get_current_user();
error_log( 'CHECK USER ROLES');
error_log( print_r($user->roles, TRUE) );
if(in_array( 'administrator', (array) $user->roles )){
// Applying coupon
if( ! in_array($coupon_code, $applied_coupons) ){
$cart->add_discount( $coupon_code );
wc_clear_notices();
}
}
} else {
if( in_array($coupon_code, $applied_coupons) ){
$cart->remove_coupon( $coupon_code );
}
}
} else {
if( in_array($coupon_code, $applied_coupons) ){
$cart->remove_coupon( $coupon_code );
}
}
}
When I disable $cart->add_discount( $coupon_code );, it running successfully, so I pretty sure that adding discount is the trigger.
And the flow that I used is
Go to checkout, conditions fulfilled, add_discount error, another function re-run update_order_review, coupon applied.
Change shipping methods, conditions not fulfilled, applied coupon is deleted
Change shipping methods, conditions fulfilled, add_discount error, update_order_review become 502, no other function re-run update_order_review, infinite loading in checkout order review
So any wrong code or flow do I have? or there are any ways to trick the error since it will applied the code if the update_order_review are re-run
Thank you
Do you get any helpful information in your browser console or the wp error log?
If I remember right 502 on AJAX request means the code fails to give you a valid response.
Hm, I don't yet have a helpful answer.
I refactored your code a bit to improve readability.
This should do exactly what your code does.
add_discount() has been renamed apply_coupon() - maybe try that.
<?php
add_action('woocommerce_before_calculate_totals', 'discount_based_on_weight_threshold');
function discount_based_on_weight_threshold( $cart ) {
if ( ! defined( 'DOING_AJAX' ) )
return;
// Your settings
$coupon_code = 'freeongkir8krpx'; // Coupon code
// Initializing variables
$applied_coupons = $cart->get_applied_coupons();
$coupon_code = sanitize_text_field( $coupon_code );
$methods = WC()->session->get( 'chosen_shipping_methods' );
$method = isset( $methods[ 0 ] ) ? $methods[ 0 ] : false;
$kupon = new WC_Coupon('freeongkir10k');
// remove code if already applied
if( in_array($coupon_code, $applied_coupons) ){
$cart->remove_coupon( $coupon_code );
}
if(
$method !== 'jne_shipping_test') &&
$cart->get_subtotal() <= $kupon->get_minimum_amount()
){
$user = wp_get_current_user();
error_log( 'CHECK USER ROLES');
error_log( print_r($user->roles, TRUE) );
if( in_array( 'administrator', (array) $user->roles ) ){
// Applying coupon
$cart->apply_coupon( $coupon_code );
wc_clear_notices();
}
}
}

Woocommerce: How can I use Stripe ONLY for single payments? I want to turn it off for subscriptions payments

I am trying to disable Stripe for subscription payments and show it for ONLY single payments, as in one time payments only.
I came across the below code, but this does the opposite. I need it doing so it hides for subscriptions and shows for single payments (one time payments)
function so23120782_maybe_remove_stripe( $available_gateways ) {
if ( class_exists( 'WC_Subscriptions_Cart' ) && ( ! WC_Subscriptions_Cart::cart_contains_subscription() || ( isset( $_GET['order_id'] ) && ! WC_Subscriptions_Order::order_contains_subscription( $_GET['order_id'] ) ) ) ) {
if ( isset( $available_gateways['stripe'] ) ) {
unset( $available_gateways['stripe'] );
}
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'so23120782_maybe_remove_stripe', 11 );
Maybe just change the condition when to unset stripe:
if ( class_exists( 'WC_Subscriptions_Cart' ) && ( WC_Subscriptions_Cart::cart_contains_subscription() || ( isset( $_GET['order_id'] ) && WC_Subscriptions_Order::order_contains_subscription( $_GET['order_id'] ) ) ) ) {
(I have removed the "not" -- ! -- from the conditions, which should be fine)

WordPress search not working for particular word / It is working when I am manually add in URL

Wordpress Search
1). www.example.com/?s=perticularword - Not Working
example particular word:"booking"
2). www.example.com/blog/?s=booking - Entered manually in URL it is working
3). If I am using the code - It returns too many redirections - Not Working
function fb_change_search_url_rewrite() {
if ( is_search() && ! empty( $_GET['s'] ) ) {
wp_redirect( home_url( "/blog/?s=" ) . urlencode( get_query_var( 's' ) ) );
exit();
}
}
add_action( 'template_redirect', 'fb_change_search_url_rewrite' );
I want www.example.com/blog/?s=booking this search results how to get results ??
Your if condition is also true for your redirected url. Use
if ( ( is_search() && ! empty( $_GET['s'] ) && stripos( $_SERVER['REQUEST_URI'], 'blog' ) === false ) {
to make the condition false on your redirected url.

Compare 3 custom fields and sort by oldest

I am building a movie archive. For each movie I am filling out the release dates for 3 countries, they're stored as custom fields (added via Pods)
Now, when listing the movies I would like to build an array and loop through each post to check if the fields have values, then compare the values and sort by the first date (oldest or least recent date). If none of the fields have values the posted date should be used for sorting. I am using this code for something similar
function orderby_additionaldate($query) {
if (! is_admin() && $query->is_main_query() && is_category( array( 2,57,530 ) ) || cat_is_ancestor_of(2, get_query_var('cat') ) && $query->is_main_query() && ! is_admin() || cat_is_ancestor_of(57, get_query_var('cat') ) && $query->is_main_query() && ! is_admin() || cat_is_ancestor_of(530, get_query_var('cat') ) && $query->is_main_query() && ! is_admin() ) {
if ( $query->query_vars ) {
$query->set( 'order', 'DESC' );
$query->set( 'meta_key', 'additional_date' );
$query->set( 'orderby', 'meta_value' );
}
}
}
add_action( 'pre_get_posts', 'orderby_additionaldate' );
Two things are missing from this:
It's not comparing 3 meta key values (release_f, release_uk, and release_us).
It doesn't check if one of them is empty and use the posted date instead (it just sets the value of the empty ones to Jan 1 1970).
Check if there is a value first putting $mykey_values in a condition
http://codex.wordpress.org/Function_Reference/get_post_custom_values
$mykey_values = get_post_custom_values('additional_date');

Resources