'Uncaught TypeError: call_user_func_array(): Argument #1 ($function) must be a valid callback
https://i.stack.imgur.com/HdkBR.png
Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($function) must be a valid callback, class Wcore_Admin does not have a method "sitemap_exclude_post_type" in /var/www/html/wp-includes/class-wp-hook.php:292 Stack trace: #0 /var/www/html/wp-includes/plugin.php(212): WP_Hook->apply_filters() #1 /var/www/html/wp-content/plugins/wordpress-seo/inc/sitemaps/class-post-type-sitemap-provider.php(276): apply_filters() #2 /var/www/html/wp-content/plugins/wordpress-seo/inc/sitemaps/class-post-type-sitemap-provider.php(253): WPSEO_Post_Type_Sitemap_Provider->is_valid_post_type() #3 /var/www/html/wp-includes/class-wp-hook.php(294): WPSEO_Post_Type_Sitemap_Provider->save_post() #4 /var/www/html/wp-includes/class-wp-hook.php(316): WP_Hook->apply_filters() #5 /var/www/html/wp-includes/plugin.php(484): WP_Hook->do_action() #6 /var/www/html/wp-includes/post.php(4384): do_action() #7 /var/www/html/wp-admin/includes/post.php(690): wp_insert_post() #8 /var/www/html/wp-admin/post-new.php(66): get_default_post_to_edit() #9 {main} thrown in /var/www/html/wp-includes/class-wp-hook.php on line 292 There has been a critical error on this website. Please check your site admin email inbox for instructions.
My server has been upgraded from PHP 7.4 to 8.0.8. I know it causes because of one of the plugins named wcore admin which was developed by custom. And It's required plugin to do our jobs. I'm looking for a way to fix the issues and maintain the script myself since I'm very happy with it.
Solution 1:[1]
You should try
call_user_func_array([new $this->controller, $this->action], array $args);
Solution 2:[2]
I faced same issue on upgrade to php8.0, the error shows steps to debug
'class Wcore_Admin does not have a method "sitemap_exclude_post_type"'
the plugin or file class name Wcore_Admin does not have a function named sitemap_exclude_post_type. Remove the line calling a missing function, and it should work
Solution 3:[3]
Here are some examples of callback functions that do not use anonymous functions, with PHPUnit tests.
<?php
namespace App\Calculator;
class SimpleAddition
{
protected $operands = [];
public function setOperands(array $operands)
{
$this->operands = $operands;
}
function callThisOne($a, $b){
return $a + $b;
}
function returnCallThisTwo(){
$callThis = function ($a, $b){
return $a + $b;
};
return $callThis;
}
public function callbackMethodOne()
{
$callable = array($this, 'callThisOne');
return array_reduce($this->operands, $callable, null);
}
public function callbackMethodTwo()
{
$callable = $this->returnCallThisTwo();
return array_reduce($this->operands, $callable, null);
}
public function callbackMethodThree()
{
$callable = function ($a, $b){
return $a + $b;
};
return array_reduce($this->operands, $callable, null);
}
}
?>
Here's the unit tests:
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
use App\Calculator\Exceptons\NoOperandsException;
class SimpleAdditionTest extends TestCase
{
/**
* This will test the SimpleAddition class
*
* @return void
*/
public function test_addition_with_callback_method_one()
{
$mathObject = new \App\Calculator\SimpleAddition;
$mathObject->setOperands([2,2]);
$this->assertEquals(4, $mathObject->callbackMethodOne());
}
public function test_addition_with_callback_method_two()
{
$mathObject = new \App\Calculator\SimpleAddition;
$mathObject->setOperands([2,2]);
$this->assertEquals(4, $mathObject->callbackMethodTwo());
}
public function test_addition_with_callback_method_three()
{
$mathObject = new \App\Calculator\SimpleAddition;
$mathObject->setOperands([2,2]);
$this->assertEquals(4, $mathObject->callbackMethodThree());
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | m4n0 |
| Solution 2 | shawndfernandes |
| Solution 3 | Adam Winter |
