add sources meta “tag”
class Custom_Sources_Meta {
public function __construct() {
if ( is_admin() ) {
add_action( 'sources_add_form_fields', array( $this, 'create_screen_fields'), 10, 1 );
add_action( 'sources_edit_form_fields', array( $this, 'edit_screen_fields' ), 10, 2 );
add_action( 'created_sources', array( $this, 'save_data' ), 10, 1 );
add_action( 'edited_sources', array( $this, 'save_data' ), 10, 1 );
}
}
public function create_screen_fields( $taxonomy ) {
// Set default values.
$sources_taxtag = '';
// Form fields.
echo '<div class="form-field term-sources_taxtag-wrap">';
echo ' <label for="sources_taxtag">' . __( 'taxtag', 'text_domain' ) . '</label>';
echo ' <input type="text" id="sources_taxtag" name="sources_taxtag" placeholder="' . esc_attr__( '', 'text_domain' ) . '" value="' . esc_attr( $sources_taxtag ) . '">';
echo '</div>';
}
public function edit_screen_fields( $term, $taxonomy ) {
// Retrieve an existing value from the database.
$sources_taxtag = get_term_meta( $term->term_id, 'sources_taxtag', true );
// Set default values.
if( empty( $sources_taxtag ) ) $sources_taxtag = '';
// Form fields.
echo '<tr class="form-field term-sources_taxtag-wrap">';
echo '<th scope="row">';
echo ' <label for="sources_taxtag">' . __( 'taxtag', 'text_domain' ) . '</label>';
echo '</th>';
echo '<td>';
echo ' <input type="text" id="sources_taxtag" name="sources_taxtag" placeholder="' . esc_attr__( '', 'text_domain' ) . '" value="' . esc_attr( $sources_taxtag ) . '">';
echo '</td>';
echo '</tr>';
}
public function save_data( $term_id ) {
// Sanitize user input.
$sources_new_taxtag = isset( $_POST[ 'sources_taxtag' ] ) ? sanitize_text_field( $_POST[ 'sources_taxtag' ] ) : '';
// Update the meta field in the database.
update_term_meta( $term_id, 'sources_taxtag', $sources_new_taxtag );
}
}
new Custom_Sources_Meta;