Metadata
- Source
- SNOW-15
- Type
- Task
- Priority
- Major
- Status
- Closed
- Resolution
- Fixed
- Assignee
- N/A
- Reporter
- Eloisa Guerrero
- Created
2018-02-06T16:18:39.679-0500 - Updated
2018-02-09T11:37:22.783-0500 - Versions
- N/A
- Fixed Versions
- N/A
- Component
- N/A
Description
Getting this error (not visible) all over the site
PHP message: PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'snow_featured_content' not found or invalid function name in /home/vagrant/sync/wordpress/wp-includes/class-wp-hook.php on line 286" while reading response header from upstream, client: 10.0.2.2, server: _, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm-wordpress.sock:", host: "localhost:10080", referrer: "http://localhost:10080/alternative-mouse-systems/"
This is coming from functions.php – I believe it is this line that's spitting out the error:
add_action('widgets_init', $panel['id']);
Instead of functions I've put in the snow panels in an array like so:
/* Centralised array for the SNOW panel information */
$snow_panels = array(
'snow_upcoming_workshops' => array(
'id' => 'snow_upcoming_workshops',
'title' => 'Upcoming Workshops',
'category' => '8'
),
'snow_feature_article' => array(
'id' => 'snow_feature_article',
'title' => 'Feature Article',
'category' => '22'
),
'snow_featured_content' => array(
'id' => 'snow_featured_content',
'title' => 'Featured Content',
'category' => '23'
)
);
when it is expecting a function, i.e. snow_upcoming_workshops(), but getting an array instead.
Might have to revert to putting them back into functions so that this error doesn't show up anymore.
Comments
-
Eloisa Guerrero commented
2018-02-07T08:26:17.357-0500 This is line 282-289 in class-wp-hook.php
// Avoid the array_slice if possible. if ( $the_['accepted_args'] == 0 ) { $value = call_user_func_array( $the_['function'], array() ); } elseif ( $the_['accepted_args'] >= $num_args ) { $value = call_user_func_array( $the_['function'], $args ); } else { $value = call_user_func_array( $the_['function'], array_slice( $args, 0, (int)$the_['accepted_args'] ) ); }
-
Eloisa Guerrero commented
2018-02-07T08:27:21.411-0500 Reverting to using functions worked:
function snow_upcoming_workshops() { register_widget( new snow_panel_widget('snow_upcoming_workshops','Upcoming Workshops','8')); } add_action('widgets_init', 'snow_upcoming_workshops'); function snow_feature_article() { register_widget( new snow_panel_widget('snow_feature_article','Feature Article','22')); } add_action('widgets_init', 'snow_feature_article'); function snow_featured_content() { register_widget( new snow_panel_widget('snow_featured_content','Featured Content','23')); } add_action('widgets_init', 'snow_featured_content');
-
Eloisa Guerrero commented
2018-02-09T08:51:53.388-0500 Paired with @@Michelle D'Souza yesterday and to solve the problem instead of rolling back, in the foreach loop we used an anonymous function and assigned it to variable $register_panel and put that in add_action so that it would satisfy the condition of using a function. Important to note that in PHP, functions have a new scope so "use" is required to pass in values from outside of the function. In this case we passed in $new_widget to get its information.
foreach ($snow_panels as $panel) { $new_widget = new snow_panel_widget($panel['id'], $panel['title'], $panel['category']); $register_panel = function() use ($new_widget) { register_widget( $new_widget ); }; add_action('widgets_init', $register_panel); }