Changeset 12067 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/taxonomy.php
- Timestamp:
- 09/15/2022 09:23:21 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/taxonomy.php
r11966 r12067 565 565 register_taxonomy( 'wporg_included_content', $post_types, $args ); 566 566 } 567 568 /** 569 * Add icon field for Category and Audience 570 */ 571 function register_custom_fields( $taxonomy ) { 572 echo '<div class="form-field"> 573 <label for="dashicon-class">Dashicon ID</label> 574 <input type="text" name="dashicon-class" id="dashicon-class" /> 575 <p>Enter the id of a <a href="https://developer.wordpress.org/resource/dashicons/#wordpress" target="_blank">Dashicon</a>. Example: <code>wordpress</code></p> 576 </div> 577 <div class="form-field"> 578 <label for="sticky"> 579 <input type="checkbox" name="sticky" id="sticky" />Sticky topic</label> 580 <p>Check to show on landing page</p> 581 </div> 582 '; 583 } 584 585 add_action( 'audience_add_form_fields', __NAMESPACE__ . '\register_custom_fields' ); 586 add_action( 'wporg_lesson_category_add_form_fields', __NAMESPACE__ . '\register_custom_fields' ); 587 588 /** 589 * Icon field on edit screen. 590 * 591 * @param object $term the term data. 592 * @param array $taxonomy the taxonomy array. 593 */ 594 function tax_edit_term_fields( $term, $taxonomy ) { 595 $value = get_term_meta( $term->term_id, 'dashicon-class', true ); 596 $sticky = get_term_meta( $term->term_id, 'sticky', true ); 597 598 echo '<tr class="form-field"> 599 <th> 600 <label for="dashicon-class">Dashicon ID</label> 601 </th> 602 <td> 603 <input name="dashicon-class" id="dashicon-class" type="text" value="' . esc_attr( $value ) . '" /> 604 <p>Enter the id of a <a href="https://developer.wordpress.org/resource/dashicons/#wordpress" target="_blank">Dashicon</a>. Example: <code>wordpress</code></p> 605 </td> 606 </tr> 607 <tr class="form-field"> 608 <th> 609 <label for="sticky">Sticky topic</label> 610 </th> 611 <td> 612 <input name="sticky" id="sticky" type="checkbox" ' . esc_html( $sticky ? ' checked' : '' ) . ' /> 613 <p>Check to show on landing page</p> 614 </td> 615 </tr> 616 '; 617 } 618 619 add_action( 'audience_edit_form_fields', __NAMESPACE__ . '\tax_edit_term_fields', 10, 2 ); 620 add_action( 'wporg_lesson_category_edit_form_fields', __NAMESPACE__ . '\tax_edit_term_fields', 10, 2 ); 621 622 /** 623 * Save icon field. 624 * 625 * @param int $term_id the term id to update. 626 */ 627 function tax_save_term_fields( $term_id ) { 628 $wp_list_table = _get_list_table( 'WP_Terms_List_Table' ); 629 630 if ( 'add-tag' === $wp_list_table->current_action() ) { 631 check_admin_referer( 'add-tag', '_wpnonce_add-tag' ); 632 } else { 633 check_admin_referer( 'update-tag_' . $term_id ); 634 } 635 636 update_term_meta( 637 $term_id, 638 'dashicon-class', 639 sanitize_text_field( $_POST['dashicon-class'] ) 640 ); 641 642 $is_sticky = $_POST['sticky'] ?? 0; 643 update_term_meta( 644 $term_id, 645 'sticky', 646 rest_sanitize_boolean( $is_sticky ) 647 ); 648 } 649 650 add_action( 'created_audience', __NAMESPACE__ . '\tax_save_term_fields' ); 651 add_action( 'edited_audience', __NAMESPACE__ . '\tax_save_term_fields' ); 652 add_action( 'created_wporg_lesson_category', __NAMESPACE__ . '\tax_save_term_fields' ); 653 add_action( 'edited_wporg_lesson_category', __NAMESPACE__ . '\tax_save_term_fields' );
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)