这段代码片段过去工作正常,但是更新到PHP8.0之后,当WC订单切换到这种自定义状态时,它就会破坏站点
//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 "{$message}";
}
}这是我得到的错误:
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发布于 2022-07-13 11:25:43
在bulk_process_status_printed()中的这一行:
'ids' => join( $_REQUEST['post'], ',' ),您已经向后显示了参数:应该是连接(分隔符,数组):
'ids' => join( ',', $_REQUEST['post'] ),这实际上是PHP8更改,而不是WordPress 6。
8.0.0 -不再支持数组后传递分隔符。
发布于 2022-07-13 20:52:31
WordPress中的关键错误通常是由于插件、脚本或代码出现故障而导致的,这些插件、脚本或代码妨碍了WordPress正常工作。
除非您解决了此问题,否则WordPress无法加载它所需的其余文件。
https://wordpress.stackexchange.com/questions/407610
复制相似问题