ADD_TO___CPT_FAQ___FOR_TERM_META
class ADD_TO___CPT_FAQ___FOR_TERM_META {
public function __construct() {
if ( is_admin() ) {
add_action( 'gilad-faq-tax-topic_add_form_fields', array( $this, 'create_screen_fields'), 10, 1 );
add_action( 'gilad-faq-tax-topic_edit_form_fields', array( $this, 'edit_screen_fields' ), 10, 2 );
add_action( 'created_gilad-faq-tax-topic', array( $this, 'save_data' ), 10, 1 );
add_action( 'edited_gilad-faq-tax-topic', array( $this, 'save_data' ), 10, 1 );
}
}
public function create_screen_fields( $taxonomy ) {
// Set default values.
$gilad_enumerate_or_not = '';
// Form fields.
echo '<div class="form-field term-gilad_enumerate_or_not-wrap">';
echo ' <label for="gilad_enumerate_or_not">' . __( 'Enumerate FAQ Titles?', 'gilad-ehven' ) . '</label>';
echo ' <select id="gilad_enumerate_or_not" name="gilad_enumerate_or_not">';
echo ' <option value="yes" ' . selected( $gilad_enumerate_or_not, 'yes', false ) . '> ' . __( 'Enumerate', 'gilad-ehven' ) . '</option>';
echo ' <option value="no" ' . selected( $gilad_enumerate_or_not, 'no', false ) . '> ' . __( 'Do NOT Enumerate', 'gilad-ehven' ) . '</option>';
echo ' </select>';
echo ' <p class="description">' . __( 'Specify whether to list a few FAQ titles in this topic in preview boxes.', 'gilad-ehven' ) . '</p>';
echo '</div>';
}
public function edit_screen_fields( $term, $taxonomy ) {
// Retrieve an existing value from the database.
$gilad_enumerate_or_not = get_term_meta( $term->term_id, 'gilad_enumerate_or_not', true );
// Set default values.
if( empty( $gilad_enumerate_or_not ) ) $gilad_enumerate_or_not = '';
// Form fields.
echo '<tr class="form-field term-gilad_enumerate_or_not-wrap">';
echo '<th scope="row">';
echo ' <label for="gilad_enumerate_or_not">' . __( 'Enumerate FAQ Titles?', 'gilad-ehven' ) . '</label>';
echo '</th>';
echo '<td>';
echo ' <select id="gilad_enumerate_or_not" name="gilad_enumerate_or_not">';
echo ' <option value="yes" ' . selected( $gilad_enumerate_or_not, 'yes', false ) . '> ' . __( 'Enumerate', 'gilad-ehven' ) . '</option>';
echo ' <option value="no" ' . selected( $gilad_enumerate_or_not, 'no', false ) . '> ' . __( 'Do NOT Enumerate', 'gilad-ehven' ) . '</option>';
echo ' </select>';
echo ' <p class="description">' . __( 'Specify whether to list a few FAQ titles in this topic in preview boxes.', 'gilad-ehven' ) . '</p>';
echo '</td>';
echo '</tr>';
}
public function save_data( $term_id ) {
// Sanitize user input.
$gilad_new_enumerate_or_not = isset( $_POST[ 'gilad_enumerate_or_not' ] ) ? $_POST[ 'gilad_enumerate_or_not' ] : '';
// Update the meta field in the database.
update_term_meta( $term_id, 'gilad_enumerate_or_not', $gilad_new_enumerate_or_not );
}
}
new ADD_TO___CPT_FAQ___FOR_TERM_META;