Getting error call_user_func_array() expects parameter 1 - wordpress

Currently i install wordpress in local system with jupitex theme . But after add sales price value i am getting below error in "class-wp-hook.php" file.
"call_user_func_array() expects parameter 1 to be a valid callback, function 'jupiterx_wc_product_page_custom_sale_badge' not found or invalid function name in";
frondend working fine . but in elementor backend i am getting this error.
If anyone have idea then let me know what is exact issue.

I checked the theme code the issue is with the theme. Actually they are not passing any parameters in this filter
add_filter( 'woocommerce_sale_flash', 'jupiterx_wc_product_page_custom_sale_badge' );
But on woocommerce.php template they have added $output as function parameter which doesn't exist
function jupiterx_wc_product_page_custom_sale_badge( $output ) {
$output = str_replace( 'onsale', 'onsale jupiterx-sale-badge', $output );
return $output;
}
You can ask the theme developer to resolve the issue because even if i resolve the issue it will be gone once you update the theme.
Reinstall theme to the latest version & check as well

Related

WooCommerce: Wrong Order Status Updated [duplicate]

When I try to programmatically update an order during a WP_Ajax hook. IE.
$order = wc_create_order($order_data);
$order->add_product( get_product( $membership_product_ids[0] ), 1 );
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order_id = $order->id;
$order->update_status('completed');
I get the following errors:
Warning: DOMXPath::query(): Invalid expression in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 299
Warning: DOMXPath::query(): Invalid expression in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 299
Warning: Invalid argument supplied for foreach() in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 302
Warning: DOMXPath::query(): Invalid expression in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 299
Warning: DOMXPath::query(): Invalid expression in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 299
Warning: Invalid argument supplied for foreach() in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 302
If I remove that update_status function it does not errors.
The errors you are seeing are coming from the notification system. Your code appears able to update the status just fine. The Emogrify Class is used to generate inline CSS in an HTML template. You are likely seeing these errors because either A) you have overridden the "Completed order" email template and have created a parsing error or B) there is a WooCommerce add-on that is conflicting in some way with what you are doing.
To correct the issue, the first step will be to verify that it is the notification system by going into the admin under WooCommerce->Settings->Email->Completed order and un-checking the "Enable this email notification" box. Then save that and retest.
If your error goes away, then check your theme directory for an override of that template. It would be in <themename>/woocommerce/emails/customer-completed-order.php. If you have one, them rename it so it will not override anymore and reactivate the "Completed order" notification and see if using the default template corrects the issue.
If the issue persists with the default email notification template, then disable all of the WooCommerce add-ons you might have installed and retest. At this point, if it is working, you can re-enable them one-by-one until the issue returns. Once you have found the offending add-on, you will need to either adjust your code to allow for the add-on to not cause an issue or contact the add-on developer to address you issue.
I am not sure but you could try this trick using new WC_Order( $order_id );, to avoid the error:
// global $woocommerce; // in case of need…
$order = wc_create_order($order_data);
$order_id = $order->id; // moving this here
$_order = new WC_Order( $order_id ); // here
$_order->add_product( get_product( $membership_product_ids[0] ), 1 );
$_order->set_address( $address, 'billing' );
$_order->set_address( $address, 'shipping' );
$_order->update_status('completed');
I agree this is a strange issue.
As it is rare issue, you'd better manually open:
/wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php
and before line 299, insert these lines, and see what you will get:
var_dump($value);
var_dump($this->translateCssToXpath($value['selector']));
var_dump($xpath->query($this->translateCssToXpath($value['selector'])));
I figured this out by trying a range of different hooks, the issue was that the hook I was using to create the order happened before woocommerce initialized that what caused this issue.

Wordpress BO post.php - button Publish/Update not working (error : GET 400 bad request, rest_invalid_param, orderby=menu_order)

I'm facing a weird issue on Wordpress…
I have to do some minor content updates on a Wordpress online since 2020, running perfectly.
But for only one of the CPT, when I want to add/modify a post, the publish/update (and save as draft) buttons not working. I can click on them but nothing happens…
In my console, I spot the following errors :
400 Bad Request GET https://mywebsite/wp-json/wp/v2/challenges?per_page=100&exclude=1921&parent_exclude=1921&orderby=menu_order&order=asc&_fields=id%2Ctitle%2Cparent&context=edit&_locale=user
Uncaught (in promise)
Object { code: "rest_invalid_param", message: "Paramètre(s) non valide(s) : orderby", data: {…} } in data.min.js:2:32702
I can update content without any problem with the quick edit…
Has anyone ever encountered this error?
I found a fix here :
Tim Ross webdevelopment
I had to add to functions.php the following code :
// This enables the orderby=menu_order for Posts
add_filter( 'rest_post_collection_params', 'filter_add_rest_orderby_params', 10, 1 );
// And this for a custom post type called 'portfolio'
add_filter( 'rest_challenges_collection_params', 'filter_add_rest_orderby_params', 10, 1 );
//Add menu_order to the list of permitted orderby values function filter_add_rest_orderby_params( $params ) {
$params['orderby']['enum'][] = 'menu_order';
return $params;
}
The filter hook is called rest_{post_type}_collection_params.
In my case, the post_type is "challenges".

Error 500 Call to undefined function thrive_get_theme_options() when trying to get to customize in WP

My site uninstalled all plugins so I reactivated and since then I have been greeted by Error 500 everytime I try to get to Customise (WP).
I checked out error_log and it's pointing to the funtions.php line 659 (starts 3rd line down):
function thrive_exclude_category($query)
{
$hide_cat_option = thrive_get_theme_options('hide_cats_from_blog');
if (!is_string($hide_cat_option)) {
$hide_cat_option = "";
}
$hide_categories = is_array(json_decode($hide_cat_option)) ? json_decode($hide_cat_option) : array();
$temp_query_string_part = "";
foreach ($hide_categories as $temp_cat_id) {
$temp_query_string_part .= "-" . $temp_cat_id . " ";
}
This is probably simple stuff, however, I suck. I have been lumbered with maintaining the sites and really have no say in the matter. Thanks in advance
In one of the projects I found this problem too. After study logs and debug project I find this function don't know about another function which used in theme PHP message: PHP Fatal error: Uncaught Error: Call to undefined function thrive_get_theme_options(). The main problem here in filter which running before all files will be included in theme. So function thrive_exclude_category don't find where declared thrive_get_theme_options because pre_get_posts running before we included files:
add_filter('pre_get_posts', 'thrive_exclude_category')
We need run this filter after use after_setup_theme
function run_func(){
add_filter('pre_get_posts', 'thrive_exclude_category', 999);
}
add_action('after_setup_theme', 'run_func`);
After this you not get any error and you can use your filter.
Try reactivate all plugins required by Thrive theme because of Fatal: Call to undefined function thrive_get_theme_options()

Load textdomain from global languages directory [Wordpress]

I am creating translations for my plugin.
To fetch .mo files from my-plugin/languages directory , I use the function
//Load translation
function load_plugin_textdomain() {
load_plugin_textdomain( 'my-plugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'load_plugin_textdomain' );
How can i set the location to wp-content/languages
Setting the location to ABSPATH.'/wp-content/languages' doesn't work.
I'm aware you've accepted your own answer, but although it will work it's against WordPress standards.
The load_plugin_textdomain will load from the global languages directory without modification and should be used for bootstrapping plugin translations. The path you specify as the third argument is a fallback to be used in case the global language file is not installed.
To clarify how it works: WordPress will look in the global languages directory strictly at <WP_LANG_DIR>/plugins/my-plugin-<locale>.mo. So as long your text domain and locale code are correct, it will be loaded.
If it isn't found, WordPress will look at the path you've specified which must be relative to the wp-content/plugins directory.
Historically (prior to WP 4.6) the third argument was loaded first, but WordPress decided to swap the order, favouring community translations (globally installed) over author-provided translations (shipped with plugin ).
If anybody else is looking for the anwser , Here it is
function load_txtdomain() {
$locale = apply_filters( 'plugin_locale', determine_locale(), 'my-plugin' );
load_textdomain( 'my-plugin', WP_LANG_DIR . '/my-plugin-' . $locale . '.mo' );
}
add_action('plugins_loaded','load_txtdomain');

How can I initialize wpdb class in a php file?

i am new in wordpress. i want to run a sql from a php file and this file is calling from a plugin file. my plugin file code is:
if (confirm('Are You Sure You Want to Delete?')){
window.location.href = '../wp-content/plugins/delete_data.php?id=<?php echo $db_data['dynamicmenu_id']; ?>';
} else{
}
and this code is running from script.
my delete_data.php file code is given below:
dlt_opt();
function dlt_opt(){
global $wpdb;
var_dump($wpdb);
$dlt_id = $_GET['id'];
$result = $wpdb->query( $wpdb->prepare( "DELETE FROM ".$wpdb->prefix."dynamicmenu WHERE dynamicmenu_id=".$dlt_id ) );
}
but in delete_data.php is creating error because it is not finding $wpdb and is null. So wpdb is not initializing and it can't find wpdb class. how can i add wpdb class?
Error message is:
Fatal error: Call to a member function query() on a non-object in ...\htdocs\wordpress\wp-content\plugins\delete_data.php on line 7
Need help
Better to use require_once(ABSPATH . '/wp-load.php');
I found my own answer. I need to include wp-load.php in that file.
require_once('../../wp-load.php');
although it's not a good practice to delete like this.

Resources