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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-permalink-settings.php
woocommerce / includes / admin Last commit date
helper 2 years ago importers 2 years ago list-tables 2 years ago marketplace-suggestions 2 years ago meta-boxes 2 years ago notes 2 years ago plugin-updates 2 years ago reports 2 years ago settings 2 years ago views 2 years ago class-wc-admin-addons.php 2 years ago class-wc-admin-api-keys-table-list.php 2 years ago class-wc-admin-api-keys.php 2 years ago class-wc-admin-assets.php 2 years ago class-wc-admin-attributes.php 3 years ago class-wc-admin-customize.php 5 years ago class-wc-admin-dashboard-setup.php 2 years ago class-wc-admin-dashboard.php 2 years ago class-wc-admin-duplicate-product.php 5 years ago class-wc-admin-exporters.php 3 years ago class-wc-admin-help.php 2 years ago class-wc-admin-importers.php 2 years ago class-wc-admin-log-table-list.php 2 years ago class-wc-admin-marketplace-promotions.php 2 years ago class-wc-admin-menus.php 2 years ago class-wc-admin-meta-boxes.php 2 years ago class-wc-admin-notices.php 2 years ago class-wc-admin-permalink-settings.php 5 years ago class-wc-admin-pointers.php 3 years ago class-wc-admin-post-types.php 2 years ago class-wc-admin-profile.php 2 years ago class-wc-admin-reports.php 5 years ago class-wc-admin-settings.php 2 years ago class-wc-admin-setup-wizard.php 2 years ago class-wc-admin-status.php 2 years ago class-wc-admin-taxonomies.php 3 years ago class-wc-admin-upload-downloadable-product.php 2 years ago class-wc-admin-webhooks-table-list.php 2 years ago class-wc-admin-webhooks.php 2 years ago class-wc-admin.php 2 years ago wc-admin-functions.php 2 years ago wc-meta-box-functions.php 2 years ago
class-wc-admin-permalink-settings.php
216 lines
1 <?php
2 /**
3 * Adds settings to the permalinks admin settings page
4 *
5 * @class WC_Admin_Permalink_Settings
6 * @package WooCommerce\Admin
7 * @version 2.3.0
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 if ( class_exists( 'WC_Admin_Permalink_Settings', false ) ) {
15 return new WC_Admin_Permalink_Settings();
16 }
17
18 /**
19 * WC_Admin_Permalink_Settings Class.
20 */
21 class WC_Admin_Permalink_Settings {
22
23 /**
24 * Permalink settings.
25 *
26 * @var array
27 */
28 private $permalinks = array();
29
30 /**
31 * Hook in tabs.
32 */
33 public function __construct() {
34 $this->settings_init();
35 $this->settings_save();
36 }
37
38 /**
39 * Init our settings.
40 */
41 public function settings_init() {
42 add_settings_section( 'woocommerce-permalink', __( 'Product permalinks', 'woocommerce' ), array( $this, 'settings' ), 'permalink' );
43
44 add_settings_field(
45 'woocommerce_product_category_slug',
46 __( 'Product category base', 'woocommerce' ),
47 array( $this, 'product_category_slug_input' ),
48 'permalink',
49 'optional'
50 );
51 add_settings_field(
52 'woocommerce_product_tag_slug',
53 __( 'Product tag base', 'woocommerce' ),
54 array( $this, 'product_tag_slug_input' ),
55 'permalink',
56 'optional'
57 );
58 add_settings_field(
59 'woocommerce_product_attribute_slug',
60 __( 'Product attribute base', 'woocommerce' ),
61 array( $this, 'product_attribute_slug_input' ),
62 'permalink',
63 'optional'
64 );
65
66 $this->permalinks = wc_get_permalink_structure();
67 }
68
69 /**
70 * Show a slug input box.
71 */
72 public function product_category_slug_input() {
73 ?>
74 <input name="woocommerce_product_category_slug" type="text" class="regular-text code" value="<?php echo esc_attr( $this->permalinks['category_base'] ); ?>" placeholder="<?php echo esc_attr_x( 'product-category', 'slug', 'woocommerce' ); ?>" />
75 <?php
76 }
77
78 /**
79 * Show a slug input box.
80 */
81 public function product_tag_slug_input() {
82 ?>
83 <input name="woocommerce_product_tag_slug" type="text" class="regular-text code" value="<?php echo esc_attr( $this->permalinks['tag_base'] ); ?>" placeholder="<?php echo esc_attr_x( 'product-tag', 'slug', 'woocommerce' ); ?>" />
84 <?php
85 }
86
87 /**
88 * Show a slug input box.
89 */
90 public function product_attribute_slug_input() {
91 ?>
92 <input name="woocommerce_product_attribute_slug" type="text" class="regular-text code" value="<?php echo esc_attr( $this->permalinks['attribute_base'] ); ?>" /><code>/attribute-name/attribute/</code>
93 <?php
94 }
95
96 /**
97 * Show the settings.
98 */
99 public function settings() {
100 /* translators: %s: Home URL */
101 echo wp_kses_post( wpautop( sprintf( __( 'If you like, you may enter custom structures for your product URLs here. For example, using <code>shop</code> would make your product links like <code>%sshop/sample-product/</code>. This setting affects product URLs only, not things such as product categories.', 'woocommerce' ), esc_url( home_url( '/' ) ) ) ) );
102
103 $shop_page_id = wc_get_page_id( 'shop' );
104 $base_slug = urldecode( ( $shop_page_id > 0 && get_post( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : _x( 'shop', 'default-slug', 'woocommerce' ) );
105 $product_base = _x( 'product', 'default-slug', 'woocommerce' );
106
107 $structures = array(
108 0 => '',
109 1 => '/' . trailingslashit( $base_slug ),
110 2 => '/' . trailingslashit( $base_slug ) . trailingslashit( '%product_cat%' ),
111 );
112 ?>
113 <table class="form-table wc-permalink-structure">
114 <tbody>
115 <tr>
116 <th><label><input name="product_permalink" type="radio" value="<?php echo esc_attr( $structures[0] ); ?>" class="wctog" <?php checked( $structures[0], $this->permalinks['product_base'] ); ?> /> <?php esc_html_e( 'Default', 'woocommerce' ); ?></label></th>
117 <td><code class="default-example"><?php echo esc_html( home_url() ); ?>/?product=sample-product</code> <code class="non-default-example"><?php echo esc_html( home_url() ); ?>/<?php echo esc_html( $product_base ); ?>/sample-product/</code></td>
118 </tr>
119 <?php if ( $shop_page_id ) : ?>
120 <tr>
121 <th><label><input name="product_permalink" type="radio" value="<?php echo esc_attr( $structures[1] ); ?>" class="wctog" <?php checked( $structures[1], $this->permalinks['product_base'] ); ?> /> <?php esc_html_e( 'Shop base', 'woocommerce' ); ?></label></th>
122 <td><code><?php echo esc_html( home_url() ); ?>/<?php echo esc_html( $base_slug ); ?>/sample-product/</code></td>
123 </tr>
124 <tr>
125 <th><label><input name="product_permalink" type="radio" value="<?php echo esc_attr( $structures[2] ); ?>" class="wctog" <?php checked( $structures[2], $this->permalinks['product_base'] ); ?> /> <?php esc_html_e( 'Shop base with category', 'woocommerce' ); ?></label></th>
126 <td><code><?php echo esc_html( home_url() ); ?>/<?php echo esc_html( $base_slug ); ?>/product-category/sample-product/</code></td>
127 </tr>
128 <?php endif; ?>
129 <tr>
130 <th><label><input name="product_permalink" id="woocommerce_custom_selection" type="radio" value="custom" class="tog" <?php checked( in_array( $this->permalinks['product_base'], $structures, true ), false ); ?> />
131 <?php esc_html_e( 'Custom base', 'woocommerce' ); ?></label></th>
132 <td>
133 <input name="product_permalink_structure" id="woocommerce_permalink_structure" type="text" value="<?php echo esc_attr( $this->permalinks['product_base'] ? trailingslashit( $this->permalinks['product_base'] ) : '' ); ?>" class="regular-text code"> <span class="description"><?php esc_html_e( 'Enter a custom base to use. A base must be set or WordPress will use default instead.', 'woocommerce' ); ?></span>
134 </td>
135 </tr>
136 </tbody>
137 </table>
138 <?php wp_nonce_field( 'wc-permalinks', 'wc-permalinks-nonce' ); ?>
139 <script type="text/javascript">
140 jQuery( function() {
141 jQuery('input.wctog').on( 'change', function() {
142 jQuery('#woocommerce_permalink_structure').val( jQuery( this ).val() );
143 });
144 jQuery('.permalink-structure input').on( 'change', function() {
145 jQuery('.wc-permalink-structure').find('code.non-default-example, code.default-example').hide();
146 if ( jQuery(this).val() ) {
147 jQuery('.wc-permalink-structure code.non-default-example').show();
148 jQuery('.wc-permalink-structure input').prop('disabled', false);
149 } else {
150 jQuery('.wc-permalink-structure code.default-example').show();
151 jQuery('.wc-permalink-structure input:eq(0)').trigger( 'click' );
152 jQuery('.wc-permalink-structure input').attr('disabled', 'disabled');
153 }
154 });
155 jQuery('.permalink-structure input:checked').trigger( 'change' );
156 jQuery('#woocommerce_permalink_structure').on( 'focus', function(){
157 jQuery('#woocommerce_custom_selection').trigger( 'click' );
158 } );
159 } );
160 </script>
161 <?php
162 }
163
164 /**
165 * Save the settings.
166 */
167 public function settings_save() {
168 if ( ! is_admin() ) {
169 return;
170 }
171
172 // We need to save the options ourselves; settings api does not trigger save for the permalinks page.
173 if ( isset( $_POST['permalink_structure'], $_POST['wc-permalinks-nonce'], $_POST['woocommerce_product_category_slug'], $_POST['woocommerce_product_tag_slug'], $_POST['woocommerce_product_attribute_slug'] ) && wp_verify_nonce( wp_unslash( $_POST['wc-permalinks-nonce'] ), 'wc-permalinks' ) ) { // WPCS: input var ok, sanitization ok.
174 wc_switch_to_site_locale();
175
176 $permalinks = (array) get_option( 'woocommerce_permalinks', array() );
177 $permalinks['category_base'] = wc_sanitize_permalink( wp_unslash( $_POST['woocommerce_product_category_slug'] ) ); // WPCS: input var ok, sanitization ok.
178 $permalinks['tag_base'] = wc_sanitize_permalink( wp_unslash( $_POST['woocommerce_product_tag_slug'] ) ); // WPCS: input var ok, sanitization ok.
179 $permalinks['attribute_base'] = wc_sanitize_permalink( wp_unslash( $_POST['woocommerce_product_attribute_slug'] ) ); // WPCS: input var ok, sanitization ok.
180
181 // Generate product base.
182 $product_base = isset( $_POST['product_permalink'] ) ? wc_clean( wp_unslash( $_POST['product_permalink'] ) ) : ''; // WPCS: input var ok, sanitization ok.
183
184 if ( 'custom' === $product_base ) {
185 if ( isset( $_POST['product_permalink_structure'] ) ) { // WPCS: input var ok.
186 $product_base = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', trim( wp_unslash( $_POST['product_permalink_structure'] ) ) ) ); // WPCS: input var ok, sanitization ok.
187 } else {
188 $product_base = '/';
189 }
190
191 // This is an invalid base structure and breaks pages.
192 if ( '/%product_cat%/' === trailingslashit( $product_base ) ) {
193 $product_base = '/' . _x( 'product', 'slug', 'woocommerce' ) . $product_base;
194 }
195 } elseif ( empty( $product_base ) ) {
196 $product_base = _x( 'product', 'slug', 'woocommerce' );
197 }
198
199 $permalinks['product_base'] = wc_sanitize_permalink( $product_base );
200
201 // Shop base may require verbose page rules if nesting pages.
202 $shop_page_id = wc_get_page_id( 'shop' );
203 $shop_permalink = ( $shop_page_id > 0 && get_post( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : _x( 'shop', 'default-slug', 'woocommerce' );
204
205 if ( $shop_page_id && stristr( trim( $permalinks['product_base'], '/' ), $shop_permalink ) ) {
206 $permalinks['use_verbose_page_rules'] = true;
207 }
208
209 update_option( 'woocommerce_permalinks', $permalinks );
210 wc_restore_locale();
211 }
212 }
213 }
214
215 return new WC_Admin_Permalink_Settings();
216