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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / admin / class-wc-admin-meta-boxes.php
woocommerce / includes / admin Last commit date
helper 5 years ago importers 5 years ago list-tables 5 years ago marketplace-suggestions 5 years ago meta-boxes 5 years ago notes 5 years ago plugin-updates 5 years ago reports 5 years ago settings 5 years ago views 5 years ago class-wc-admin-addons.php 5 years ago class-wc-admin-api-keys-table-list.php 5 years ago class-wc-admin-api-keys.php 5 years ago class-wc-admin-assets.php 5 years ago class-wc-admin-attributes.php 5 years ago class-wc-admin-customize.php 5 years ago class-wc-admin-dashboard.php 5 years ago class-wc-admin-duplicate-product.php 5 years ago class-wc-admin-exporters.php 5 years ago class-wc-admin-help.php 5 years ago class-wc-admin-importers.php 5 years ago class-wc-admin-log-table-list.php 5 years ago class-wc-admin-menus.php 5 years ago class-wc-admin-meta-boxes.php 5 years ago class-wc-admin-notices.php 5 years ago class-wc-admin-permalink-settings.php 5 years ago class-wc-admin-pointers.php 5 years ago class-wc-admin-post-types.php 5 years ago class-wc-admin-profile.php 5 years ago class-wc-admin-reports.php 5 years ago class-wc-admin-settings.php 5 years ago class-wc-admin-setup-wizard.php 5 years ago class-wc-admin-status.php 5 years ago class-wc-admin-taxonomies.php 5 years ago class-wc-admin-webhooks-table-list.php 5 years ago class-wc-admin-webhooks.php 5 years ago class-wc-admin.php 5 years ago wc-admin-functions.php 5 years ago wc-meta-box-functions.php 5 years ago
class-wc-admin-meta-boxes.php
228 lines
1 <?php
2 /**
3 * WooCommerce Meta Boxes
4 *
5 * Sets up the write panels used by products and orders (custom post types).
6 *
7 * @package WooCommerce/Admin/Meta Boxes
8 */
9
10 use Automattic\Jetpack\Constants;
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * WC_Admin_Meta_Boxes.
16 */
17 class WC_Admin_Meta_Boxes {
18
19 /**
20 * Is meta boxes saved once?
21 *
22 * @var boolean
23 */
24 private static $saved_meta_boxes = false;
25
26 /**
27 * Meta box error messages.
28 *
29 * @var array
30 */
31 public static $meta_box_errors = array();
32
33 /**
34 * Constructor.
35 */
36 public function __construct() {
37 add_action( 'add_meta_boxes', array( $this, 'remove_meta_boxes' ), 10 );
38 add_action( 'add_meta_boxes', array( $this, 'rename_meta_boxes' ), 20 );
39 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 30 );
40 add_action( 'save_post', array( $this, 'save_meta_boxes' ), 1, 2 );
41
42 /**
43 * Save Order Meta Boxes.
44 *
45 * In order:
46 * Save the order items.
47 * Save the order totals.
48 * Save the order downloads.
49 * Save order data - also updates status and sends out admin emails if needed. Last to show latest data.
50 * Save actions - sends out other emails. Last to show latest data.
51 */
52 add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Items::save', 10 );
53 add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Downloads::save', 30, 2 );
54 add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40 );
55 add_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Actions::save', 50, 2 );
56
57 // Save Product Meta Boxes.
58 add_action( 'woocommerce_process_product_meta', 'WC_Meta_Box_Product_Data::save', 10, 2 );
59 add_action( 'woocommerce_process_product_meta', 'WC_Meta_Box_Product_Images::save', 20, 2 );
60
61 // Save Coupon Meta Boxes.
62 add_action( 'woocommerce_process_shop_coupon_meta', 'WC_Meta_Box_Coupon_Data::save', 10, 2 );
63
64 // Save Rating Meta Boxes.
65 add_filter( 'wp_update_comment_data', 'WC_Meta_Box_Product_Reviews::save', 1 );
66
67 // Error handling (for showing errors from meta boxes on next page load).
68 add_action( 'admin_notices', array( $this, 'output_errors' ) );
69 add_action( 'shutdown', array( $this, 'save_errors' ) );
70 }
71
72 /**
73 * Add an error message.
74 *
75 * @param string $text Error to add.
76 */
77 public static function add_error( $text ) {
78 self::$meta_box_errors[] = $text;
79 }
80
81 /**
82 * Save errors to an option.
83 */
84 public function save_errors() {
85 update_option( 'woocommerce_meta_box_errors', self::$meta_box_errors );
86 }
87
88 /**
89 * Show any stored error messages.
90 */
91 public function output_errors() {
92 $errors = array_filter( (array) get_option( 'woocommerce_meta_box_errors' ) );
93
94 if ( ! empty( $errors ) ) {
95
96 echo '<div id="woocommerce_errors" class="error notice is-dismissible">';
97
98 foreach ( $errors as $error ) {
99 echo '<p>' . wp_kses_post( $error ) . '</p>';
100 }
101
102 echo '</div>';
103
104 // Clear.
105 delete_option( 'woocommerce_meta_box_errors' );
106 }
107 }
108
109 /**
110 * Add WC Meta boxes.
111 */
112 public function add_meta_boxes() {
113 $screen = get_current_screen();
114 $screen_id = $screen ? $screen->id : '';
115
116 // Products.
117 add_meta_box( 'postexcerpt', __( 'Product short description', 'woocommerce' ), 'WC_Meta_Box_Product_Short_Description::output', 'product', 'normal' );
118 add_meta_box( 'woocommerce-product-data', __( 'Product data', 'woocommerce' ), 'WC_Meta_Box_Product_Data::output', 'product', 'normal', 'high' );
119 add_meta_box( 'woocommerce-product-images', __( 'Product gallery', 'woocommerce' ), 'WC_Meta_Box_Product_Images::output', 'product', 'side', 'low' );
120
121 // Orders.
122 foreach ( wc_get_order_types( 'order-meta-boxes' ) as $type ) {
123 $order_type_object = get_post_type_object( $type );
124 /* Translators: %s order type name. */
125 add_meta_box( 'woocommerce-order-data', sprintf( __( '%s data', 'woocommerce' ), $order_type_object->labels->singular_name ), 'WC_Meta_Box_Order_Data::output', $type, 'normal', 'high' );
126 add_meta_box( 'woocommerce-order-items', __( 'Items', 'woocommerce' ), 'WC_Meta_Box_Order_Items::output', $type, 'normal', 'high' );
127 /* Translators: %s order type name. */
128 add_meta_box( 'woocommerce-order-notes', sprintf( __( '%s notes', 'woocommerce' ), $order_type_object->labels->singular_name ), 'WC_Meta_Box_Order_Notes::output', $type, 'side', 'default' );
129 add_meta_box( 'woocommerce-order-downloads', __( 'Downloadable product permissions', 'woocommerce' ) . wc_help_tip( __( 'Note: Permissions for order items will automatically be granted when the order status changes to processing/completed.', 'woocommerce' ) ), 'WC_Meta_Box_Order_Downloads::output', $type, 'normal', 'default' );
130 /* Translators: %s order type name. */
131 add_meta_box( 'woocommerce-order-actions', sprintf( __( '%s actions', 'woocommerce' ), $order_type_object->labels->singular_name ), 'WC_Meta_Box_Order_Actions::output', $type, 'side', 'high' );
132 }
133
134 // Coupons.
135 add_meta_box( 'woocommerce-coupon-data', __( 'Coupon data', 'woocommerce' ), 'WC_Meta_Box_Coupon_Data::output', 'shop_coupon', 'normal', 'high' );
136
137 // Comment rating.
138 if ( 'comment' === $screen_id && isset( $_GET['c'] ) && metadata_exists( 'comment', wc_clean( wp_unslash( $_GET['c'] ) ), 'rating' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
139 add_meta_box( 'woocommerce-rating', __( 'Rating', 'woocommerce' ), 'WC_Meta_Box_Product_Reviews::output', 'comment', 'normal', 'high' );
140 }
141 }
142
143 /**
144 * Remove bloat.
145 */
146 public function remove_meta_boxes() {
147 remove_meta_box( 'postexcerpt', 'product', 'normal' );
148 remove_meta_box( 'product_shipping_classdiv', 'product', 'side' );
149 remove_meta_box( 'commentsdiv', 'product', 'normal' );
150 remove_meta_box( 'commentstatusdiv', 'product', 'side' );
151 remove_meta_box( 'commentstatusdiv', 'product', 'normal' );
152 remove_meta_box( 'woothemes-settings', 'shop_coupon', 'normal' );
153 remove_meta_box( 'commentstatusdiv', 'shop_coupon', 'normal' );
154 remove_meta_box( 'slugdiv', 'shop_coupon', 'normal' );
155
156 foreach ( wc_get_order_types( 'order-meta-boxes' ) as $type ) {
157 remove_meta_box( 'commentsdiv', $type, 'normal' );
158 remove_meta_box( 'woothemes-settings', $type, 'normal' );
159 remove_meta_box( 'commentstatusdiv', $type, 'normal' );
160 remove_meta_box( 'slugdiv', $type, 'normal' );
161 remove_meta_box( 'submitdiv', $type, 'side' );
162 }
163 }
164
165 /**
166 * Rename core meta boxes.
167 */
168 public function rename_meta_boxes() {
169 global $post;
170
171 // Comments/Reviews.
172 if ( isset( $post ) && ( 'publish' === $post->post_status || 'private' === $post->post_status ) && post_type_supports( 'product', 'comments' ) ) {
173 remove_meta_box( 'commentsdiv', 'product', 'normal' );
174 add_meta_box( 'commentsdiv', __( 'Reviews', 'woocommerce' ), 'post_comment_meta_box', 'product', 'normal' );
175 }
176 }
177
178 /**
179 * Check if we're saving, the trigger an action based on the post type.
180 *
181 * @param int $post_id Post ID.
182 * @param object $post Post object.
183 */
184 public function save_meta_boxes( $post_id, $post ) {
185 $post_id = absint( $post_id );
186
187 // $post_id and $post are required
188 if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
189 return;
190 }
191
192 // Dont' save meta boxes for revisions or autosaves.
193 if ( Constants::is_true( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
194 return;
195 }
196
197 // Check the nonce.
198 if ( empty( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['woocommerce_meta_nonce'] ), 'woocommerce_save_data' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
199 return;
200 }
201
202 // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
203 if ( empty( $_POST['post_ID'] ) || absint( $_POST['post_ID'] ) !== $post_id ) {
204 return;
205 }
206
207 // Check user has permission to edit.
208 if ( ! current_user_can( 'edit_post', $post_id ) ) {
209 return;
210 }
211
212 // We need this save event to run once to avoid potential endless loops. This would have been perfect:
213 // remove_action( current_filter(), __METHOD__ );
214 // But cannot be used due to https://github.com/woocommerce/woocommerce/issues/6485
215 // When that is patched in core we can use the above.
216 self::$saved_meta_boxes = true;
217
218 // Check the post type.
219 if ( in_array( $post->post_type, wc_get_order_types( 'order-meta-boxes' ), true ) ) {
220 do_action( 'woocommerce_process_shop_order_meta', $post_id, $post );
221 } elseif ( in_array( $post->post_type, array( 'product', 'shop_coupon' ), true ) ) {
222 do_action( 'woocommerce_process_' . $post->post_type . '_meta', $post_id, $post );
223 }
224 }
225 }
226
227 new WC_Admin_Meta_Boxes();
228