add_custom_status(
sanitize_key( wp_unslash( $_POST['new_status'] ) ), // phpcs:ignore WordPress.Security.NonceVerification
sanitize_text_field( wp_unslash( $_POST['new_status_label'] ) ), // phpcs:ignore WordPress.Security.NonceVerification
sanitize_text_field( wp_unslash( $_POST['new_status_icon_content'] ) ), // phpcs:ignore WordPress.Security.NonceVerification
sanitize_text_field( wp_unslash( $_POST['new_status_icon_color'] ) ), // phpcs:ignore WordPress.Security.NonceVerification
sanitize_text_field( wp_unslash( $_POST['new_status_text_color'] ) ) // phpcs:ignore WordPress.Security.NonceVerification
);
} elseif ( isset( $_POST['alg_edit_custom_status'], $_POST['new_status'], $_POST['new_status_label'], $_POST['new_status_icon_content'], $_POST['new_status_icon_color'], $_POST['new_status_text_color'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$result_message = $this->edit_custom_status(
sanitize_key( wp_unslash( $_POST['new_status'] ) ), // phpcs:ignore WordPress.Security.NonceVerification
sanitize_text_field( wp_unslash( $_POST['new_status_label'] ) ), // phpcs:ignore WordPress.Security.NonceVerification
sanitize_text_field( wp_unslash( $_POST['new_status_icon_content'] ) ), // phpcs:ignore WordPress.Security.NonceVerification
sanitize_text_field( wp_unslash( $_POST['new_status_icon_color'] ) ), // phpcs:ignore WordPress.Security.NonceVerification
sanitize_text_field( wp_unslash( $_POST['new_status_text_color'] ) ) // phpcs:ignore WordPress.Security.NonceVerification
);
} elseif ( isset( $_GET['delete'] ) && ( '' !== $_GET['delete'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$result_message = $this->delete_custom_status( sanitize_text_field( wp_unslash( $_GET['delete'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification
}
echo wp_kses_post( $result_message );
}
/**
* Get_status_table_html.
*
* @version 1.4.0
* @since 1.3.0
*/
public function get_status_table_html() {
$table_data = array();
$table_data[] = array(
__( 'Slug', 'custom-order-statuses-woocommerce' ),
__( 'Label', 'custom-order-statuses-woocommerce' ),
__( 'Icon Code', 'custom-order-statuses-woocommerce' ),
__( 'Color', 'custom-order-statuses-woocommerce' ),
__( 'Text Color', 'custom-order-statuses-woocommerce' ),
__( 'Actions', 'custom-order-statuses-woocommerce' ),
);
$statuses = function_exists( 'wc_get_order_statuses' ) ? wc_get_order_statuses() : array();
$default_statuses = $this->get_default_order_statuses();
$plugin_statuses = alg_get_custom_order_statuses();
foreach ( $statuses as $status => $status_name ) {
if ( array_key_exists( $status, $default_statuses ) || ! array_key_exists( $status, $plugin_statuses ) ) {
$icon_and_actions = array( '', '', '', '' );
} else {
$icon_data = get_option( 'alg_orders_custom_status_icon_data_' . substr( $status, 3 ), '' );
if ( '' !== $icon_data ) {
$content = $icon_data['content'];
$color = $icon_data['color'];
$text_color = ( isset( $icon_data['text_color'] ) ? $icon_data['text_color'] : '#000000' );
} else {
$content = 'e011';
$color = '#999999';
$text_color = '#000000';
}
$fallback_status_without_wc_prefix = get_option( 'alg_orders_custom_statuses_fallback_delete_status', 'on-hold' );
$delete_button_ending = ' href="' . add_query_arg( 'delete', $status, remove_query_arg( array( 'edit', 'fallback' ) ) ) .
'" onclick="return confirm(\'' . __( 'Are you sure?', 'custom-order-statuses-woocommerce' ) . '\')">';
$delete_with_fallback_button_ending = ( substr( $status, 3 ) !== $fallback_status_without_wc_prefix ?
' href="' . add_query_arg(
array(
'delete' => $status,
'fallback' => 'yes',
),
remove_query_arg( 'edit' )
) .
'" onclick="return confirm(\'' . __( 'Are you sure?', 'custom-order-statuses-woocommerce' ) . '\')" title="' .
sprintf(
// translators: New status.
__( 'Status for orders with this status will be changed to \'%s\'.' ),
$this->get_status_title( 'wc-' . $fallback_status_without_wc_prefix )
)
. '">'
:
' disabled title="' .
__( 'This status can not be deleted as it\'s set to be the fallback status. Change \'Fallback Delete Order Status\' to some other value in plugin\'s settings to delete this status.', 'custom-order-statuses-woocommerce' )
. '">'
);
$edit_button_ending = ' href="' . add_query_arg( 'edit', $status, remove_query_arg( array( 'delete', 'fallback' ) ) ) . '">';
$delete_button = '';
$delete_with_fallback_button = '';
$edit_button = '';
$icon_and_actions = array(
$content,
'',
'',
$delete_button . ' ' . $delete_with_fallback_button . ' ' . $edit_button,
);
}
$table_data[] = array_merge( array( esc_attr( $status ), esc_html( $status_name ) ), $icon_and_actions );
}
return ' * ' . sprintf(
// translators: plugin settings link.
__( '"Delete with fallback" button will delete custom status and change status for every order with that status to "fallback status". Fallback status can be set in plugin\'s general settings. Please note - if you have large number of orders this may take longer.', 'custom-order-statuses-woocommerce' ),
admin_url( 'admin.php?page=wc-settings&tab=alg_wc_custom_order_statuses' )
) .
'' . __( 'Status Table', 'custom-order-statuses-woocommerce' ) . '
' .
alg_get_table_html( $table_data, array( 'table_class' => 'wc_status_table widefat striped' ) ) .
'wc-
' );
$icon_input .= "
$icon_desc";
$slug_input .= "
$slug_desc";
$add_edit_button = '';
$clear_button = ( $is_editing ?
'' . __( 'Clear form', 'custom-order-statuses-woocommerce' ) . '' : '' );
$table_data = array(
array( __( 'Slug', 'custom-order-statuses-woocommerce' ), $slug_input ),
array( __( 'Label', 'custom-order-statuses-woocommerce' ), $label_input ),
array( __( 'Icon Code', 'custom-order-statuses-woocommerce' ), $icon_input ),
array( __( 'Color', 'custom-order-statuses-woocommerce' ), $icon_color_input ),
array( __( 'Text Color', 'custom-order-statuses-woocommerce' ), $text_color_input ),
array( $add_edit_button, '' ),
);
if ( '' !== $clear_button ) {
$table_data[] = array( $clear_button, '' );
}
return '
' . __( 'Status slug is empty. Status was not added!', 'custom-order-statuses-woocommerce' ) . '
'; } else { global $wpdb; $terms_list = $wpdb->get_col( 'SELECT DISTINCT slug FROM `' . $wpdb->prefix . 'terms`' ); //phpcs:ignore if ( is_array( $terms_list ) && in_array( $new_status, $terms_list, true ) ) { return '' . __( 'Status slug is already present. Please use another slug name.', 'custom-order-statuses-woocommerce' ) . '
' . __( 'The length of status slug must be 17 or less characters. Status was not added!', 'custom-order-statuses-woocommerce' ) . '
' . __( 'Status label is empty. Status was not added!', 'custom-order-statuses-woocommerce' ) . '
' . __( 'Duplicate slug. Status was not added!', 'custom-order-statuses-woocommerce' ) . '
' . __( 'Duplicate slug (default WooCommerce status). Status was not added!', 'custom-order-statuses-woocommerce' ) . '
' . __( 'New status has been successfully added!', 'custom-order-statuses-woocommerce' ) . '
' . __( 'Status was not added!', 'custom-order-statuses-woocommerce' ) . '
' . __( 'Status label is empty. Status was not edited!', 'custom-order-statuses-woocommerce' ) . '
' . __( 'Status has been successfully edited!', 'custom-order-statuses-woocommerce' ) . '
' . __( 'Status was not edited!', 'custom-order-statuses-woocommerce' ) . '
' . __( 'Status has been successfully deleted.', 'custom-order-statuses-woocommerce' ) . '
' . sprintf( __( 'Status has been changed for %d orders.', 'custom-order-statuses-woocommerce' ), $total_orders_changed ) . '
' . __( 'Delete failed.', 'custom-order-statuses-woocommerce' ) . '
' . __( 'Delete failed (status not found).', 'custom-order-statuses-woocommerce' ) . '