Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1194929
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 2 years ago.
Improve this questionThis snippet used to work fine but with the update to PHP 8.0 it now breaks the site when a WC order is switched to this custom status
//Add custom bulk action in dropdown
add_filter( 'bulk_actions-edit-shop_order', 'register_bulk_action_printed' );
function register_bulk_action_printed( $bulk_actions ) {
$bulk_actions['mark_as_printed'] = 'Change status to Printed';
return $bulk_actions;
}
//Bulk action handler
add_action( 'admin_action_mark_as_printed', 'bulk_process_status_printed' );
function bulk_process_status_printed() {
if( !isset( $_REQUEST['post'] ) && !is_array( $_REQUEST['post'] ) )
return;
foreach( $_REQUEST['post'] as $order_id ) {
$order = new WC_Order( $order_id );
$order_note = 'That\'s what happened by bulk edit:';
$order->update_status( 'wc-printed', $order_note, true );
}
$location = add_query_arg( array(
'post_type' => 'shop_order',
'marked_as_printed' => 1, // marked_as_printed=1 is just the $_GET variable for notices
'changed' => count( $_REQUEST['post'] ), // number of changed orders
'ids' => join( $_REQUEST['post'], ',' ),
'post_status' => 'all'
), 'edit.php' );
wp_redirect( admin_url( $location ) );
exit;
}
/*
* Notices
*/
add_action('admin_notices', 'custom_order_status_notices_printed');
function custom_order_status_notices_printed() {
global $pagenow, $typenow;
if( $typenow == 'shop_order'
&& $pagenow == 'edit.php'
&& isset( $_REQUEST['marked_as_printed'] )
&& $_REQUEST['marked_as_printed'] == 1
&& isset( $_REQUEST['changed'] ) ) {
$message = sprintf( _n( 'Order status changed.', '%s order statuses changed.', $_REQUEST['changed'] ), number_format_i18n( $_REQUEST['changed'] ) );
echo "<div class=\"updated\"><p>{$message}</p></div>";
}
}
This is the error that I get:
PHP Fatal error: Uncaught TypeError: join(): Argument #2 ($array) must be of type ?array, string given in /nas/content/live/allstaruhlmann/wp-content/plugins/code-snippets/php/snippet-ops.php(484) : eval()'d code:32\nStack trace:\n#0 /nas/content/live/allstaruhlmann/wp-content/plugins/code-snippets/php/snippet-ops.php(484) : eval()'d code(32): join(Array, ',')\n#1 /nas/content/live/allstaruhlmann/wp-includes/class-wp-hook.php(307): bulk_process_status_printed('')\n#2 /nas/content/live/allstaruhlmann/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array)\n#3 /nas/content/live/allstaruhlmann/wp-includes/plugin.php(476): WP_Hook->do_action(Array)\n#4 /nas/content/live/allstaruhlmann/wp-admin/admin.php(419): do_action('admin_action_ma...')\n#5 /nas/content/live/allstaruhlmann/wp-admin/edit.php(10): require_once('/nas/content/li...')\n#6 {main}\n thrown in /nas/content/live/allstaruhlmann/wp-content/plugins/code-snippets/php/snippet-ops.php(484) : eval()'d code on line 32, referer: .php?post_type=shop_order
Closed. This question is off-topic. It is not currently accepting answers.
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 2 years ago.
Improve this questionThis snippet used to work fine but with the update to PHP 8.0 it now breaks the site when a WC order is switched to this custom status
//Add custom bulk action in dropdown
add_filter( 'bulk_actions-edit-shop_order', 'register_bulk_action_printed' );
function register_bulk_action_printed( $bulk_actions ) {
$bulk_actions['mark_as_printed'] = 'Change status to Printed';
return $bulk_actions;
}
//Bulk action handler
add_action( 'admin_action_mark_as_printed', 'bulk_process_status_printed' );
function bulk_process_status_printed() {
if( !isset( $_REQUEST['post'] ) && !is_array( $_REQUEST['post'] ) )
return;
foreach( $_REQUEST['post'] as $order_id ) {
$order = new WC_Order( $order_id );
$order_note = 'That\'s what happened by bulk edit:';
$order->update_status( 'wc-printed', $order_note, true );
}
$location = add_query_arg( array(
'post_type' => 'shop_order',
'marked_as_printed' => 1, // marked_as_printed=1 is just the $_GET variable for notices
'changed' => count( $_REQUEST['post'] ), // number of changed orders
'ids' => join( $_REQUEST['post'], ',' ),
'post_status' => 'all'
), 'edit.php' );
wp_redirect( admin_url( $location ) );
exit;
}
/*
* Notices
*/
add_action('admin_notices', 'custom_order_status_notices_printed');
function custom_order_status_notices_printed() {
global $pagenow, $typenow;
if( $typenow == 'shop_order'
&& $pagenow == 'edit.php'
&& isset( $_REQUEST['marked_as_printed'] )
&& $_REQUEST['marked_as_printed'] == 1
&& isset( $_REQUEST['changed'] ) ) {
$message = sprintf( _n( 'Order status changed.', '%s order statuses changed.', $_REQUEST['changed'] ), number_format_i18n( $_REQUEST['changed'] ) );
echo "<div class=\"updated\"><p>{$message}</p></div>";
}
}
This is the error that I get:
PHP Fatal error: Uncaught TypeError: join(): Argument #2 ($array) must be of type ?array, string given in /nas/content/live/allstaruhlmann/wp-content/plugins/code-snippets/php/snippet-ops.php(484) : eval()'d code:32\nStack trace:\n#0 /nas/content/live/allstaruhlmann/wp-content/plugins/code-snippets/php/snippet-ops.php(484) : eval()'d code(32): join(Array, ',')\n#1 /nas/content/live/allstaruhlmann/wp-includes/class-wp-hook.php(307): bulk_process_status_printed('')\n#2 /nas/content/live/allstaruhlmann/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array)\n#3 /nas/content/live/allstaruhlmann/wp-includes/plugin.php(476): WP_Hook->do_action(Array)\n#4 /nas/content/live/allstaruhlmann/wp-admin/admin.php(419): do_action('admin_action_ma...')\n#5 /nas/content/live/allstaruhlmann/wp-admin/edit.php(10): require_once('/nas/content/li...')\n#6 {main}\n thrown in /nas/content/live/allstaruhlmann/wp-content/plugins/code-snippets/php/snippet-ops.php(484) : eval()'d code on line 32, referer: https://allstaruhlmann.com/wp-admin/edit.php?post_type=shop_order
Share
Improve this question
edited Jul 13, 2022 at 11:35
J4G
asked Jul 13, 2022 at 10:25
J4GJ4G
1137 bronze badges
4
本文标签: pluginsWhy does this code snippet create a critical error on my site