[wp-trac] [WordPress Trac] #54353: Snippet gives 403 code
WordPress Trac
noreply at wordpress.org
Sun Oct 31 16:28:16 UTC 2021
#54353: Snippet gives 403 code
--------------------------+-----------------------------
Reporter: younachk | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version:
Severity: blocker | Keywords:
Focuses: |
--------------------------+-----------------------------
I want to put in this snippet but it does not work. can someone help me
with this?
it are multiple snippets but only snipet doesn't work and gives me the
403 code.
The 4th snippet doesn't work
snippet 1
add_action( 'init', 'inno_product_cat_register_meta' );
/**
* Register details product_cat meta.
*
* Register the details metabox for WooCommerce product categories.
*
* Snippet via INNONET WooCommerce Academy
*
*/
function inno_product_cat_register_meta() {
register_meta( 'term', 'details', 'inno_sanitize_details' );
}
/**
* Sanitize the details custom meta field.
*
* @param string $details The existing details field.
* @return string The sanitized details field
*/
function inno_sanitize_details( $details ) {
return wp_kses_post( $details );
}
snippet 2
add_action( 'product_cat_add_form_fields',
'inno_product_cat_add_details_meta' );
/**
* Add a details metabox to the Add New Product Category page.
*
* Snippet via INNONET WooCommerce Academy
*
*/
function inno_product_cat_add_details_meta() {
wp_nonce_field( basename( __FILE__ ),
'inno_product_cat_details_nonce' );
?>
<div class="form-field">
<label for="inno-product-cat-details"><?php esc_html_e(
'Omschrijving 2', 'inno' ); ?></label>
<textarea name="inno-product-cat-details" id="inno-
product-cat-details" rows="5" cols="40"></textarea>
<p class="description"><?php esc_html_e( 'Extra content
die onder de producten verschijnt', 'inno' ); ?></p>
</div>
<?php
}
Code snippet 3
snippet 3
add_action( 'product_cat_edit_form_fields',
'inno_product_cat_edit_details_meta' );
/**
* Add a details metabox to the Edit Product Category page.
*
* Snippet via INNONET WooCommerce Academy
*
* @param object $term The existing term object.
*/
function inno_product_cat_edit_details_meta( $term ) {
$product_cat_details = get_term_meta( $term->term_id, 'details',
true );
if ( ! $product_cat_details ) {
$product_cat_details = '';
}
$settings = array( 'textarea_name' => 'inno-product-cat-details'
);
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="inno-product-cat-
details"><?php esc_html_e( 'Omschrijving 2', 'inno' ); ?></label></th>
<td>
<?php wp_nonce_field( basename( __FILE__ ),
'inno_product_cat_details_nonce' ); ?>
<?php wp_editor( inno_sanitize_details(
$product_cat_details ), 'product_cat_details', $settings ); ?>
<p class="description"><?php esc_html_e( 'Extra
content die onder de producten verschijnt','inno' ); ?></p>
</td>
</tr>
<?php
}
Code snippet 4
add_action( 'create_product_cat', 'inno_product_cat_details_meta_save' );
add_action( 'edit_product_cat', 'inno_product_cat_details_meta_save' );
/**
* Save Product Category details meta.
*
* Snippet via INNONET WooCommerce Academy
*
* @param int $term_id The term ID of the term to update.
*/
function inno_product_cat_details_meta_save( $term_id ) {
if ( ! isset( $_POST['inno_product_cat_details_nonce'] ) || !
wp_verify_nonce( $_POST['inno_product_cat_details_nonce'], basename(
__FILE__ ) ) ) {
return;
}
$old_details = get_term_meta( $term_id, 'details', true );
$new_details = isset( $_POST['inno-product-cat-details'] ) ?
$_POST['inno-product-cat-details'] : '';
if ( $old_details && '' === $new_details ) {
delete_term_meta( $term_id, 'details' );
} else if ( $old_details !== $new_details ) {
update_term_meta(
$term_id,
'details',
inno_sanitize_details( $new_details )
);
}
}
Code snippet 5
add_action( 'woocommerce_after_shop_loop',
'inno_product_cat_display_details_meta' );
/**
* Display details meta on Product Category archives.
*
* Snippet via INNONET WooCommerce Academy
*
*/
function inno_product_cat_display_details_meta() {
if ( ! is_tax( 'product_cat' ) ) {
return;
}
$t_id = get_queried_object()->term_id;
$details = get_term_meta( $t_id, 'details', true );
if ( '' !== $details ) {
?>
<div class="product-cat-details">
<?php echo apply_filters( 'the_content',
wp_kses_post( $details ) ); ?>
</div>
<?php
}
}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54353>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list