Created
February 17, 2016 09:23
-
-
Save gbyat/39f8fd3c074e703392dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/****************************************** | |
* edit form for new and existing terms | |
* param term_id has no value by default | |
******************************************/ | |
function pppf_term_edit_form( $term_id = '' ) { | |
wp_nonce_field( 'ppp_update_term', 'ppp_update_term_nonce' ); | |
$my_checkbox = $term_id != '' ? get_term_meta( $term_id, 'my_checkbox', true ) : ''; | |
$my_selection = $term_id != '' ? get_term_meta( $term_id, 'my_selection', true ) : ''; | |
$my_text_field = $term_id != '' ? get_term_meta( $term_id, 'my_text_field', true ) : ''; | |
$my_email = $term_id != '' ? get_term_meta( $term_id, 'my_email', true ) : ''; | |
$my_url = $term_id != '' ? get_term_meta( $term_id, 'my_url', true ) : ''; | |
$my_number = $term_id != '' ? get_term_meta( $term_id, 'my_number', true ) : ''; | |
?> | |
<div id="ppp_term_meta" class="postbox"> | |
<div class="inside"> | |
<p> | |
<label for="my_checkbox"><?php esc_html_e( 'My Checkbox', 'my-plugin-textdomain' ); ?></label> | |
<input type="checkbox" <?php echo ( $my_checkbox == 1 ? 'checked="checked" ' : '' ); ?>value="1" name="my_checkbox" id="my_checkbox"> | |
</p> | |
<p> | |
<label for="my_selection"><?php esc_html_e( 'My Selection', 'my-plugin-textdomain' ); ?></label> | |
<select type="text" name="my_selection" id="my_selection"> | |
<option <?php echo ( $my_selection == 'choice-1' ? 'selected="selected" ' : '' ); ?>value="choice-1"><?php esc_html_e( 'My first choice', 'my-plugin-textdomain' ); ?></option> | |
<option <?php echo ( $my_selection == 'choice-2' ? 'selected="selected" ' : '' ); ?>value="choice-2"><?php esc_html_e( 'My second choice', 'my-plugin-textdomain' ); ?></option> | |
</select> | |
</p> | |
<p> | |
<label for="my_text_field"><?php esc_html_e( 'My Textfield', 'my-plugin-textdomain' ); ?></label> | |
<input type="text" name="my_text_field" id="my_text_field" value="<?php echo esc_attr( $my_text_field ); ?>"> | |
</p> | |
<p> | |
<label for="my_email"><?php esc_html_e( 'My Email', 'my-plugin-textdomain' ); ?></label> | |
<input type="email" name="my_email" id="my_email" value="<?php echo esc_attr( $my_email ) ; ?>"> | |
</p> | |
<p> | |
<label for="my_url"><?php esc_html_e( 'My URL', 'my-plugin-textdomain' ); ?></label> | |
<input type="url" placeholder="http://" name="my_url" id="my_url" value="<?php echo ( '' != $my_url ? esc_url( $my_url ) : '' ); ?>"> | |
</p> | |
<p> | |
<label for="my_number"><?php esc_html_e( 'My Number', 'my-plugin-textdomain' ); ?></label> | |
<input type="number" placeholder="EUR" name="my_number" id="my_number" value="<?php echo ( '' != $my_number ? absint( $my_number ) : '' ); ?>"> | |
</p> | |
</div> | |
</div> | |
<?php } | |
/****************************************** | |
* add new term | |
* term_id = '' | |
******************************************/ | |
function pppf_add_term_meta() { | |
pppf_term_edit_form(); | |
} | |
/****************************************** | |
* edit existing term | |
* wrap with table row | |
* fetch term_id | |
******************************************/ | |
function pppf_edit_term_meta( $term ) { | |
$term_id = $term->term_id; | |
echo '<tr class="form-field term-meta-wrap">' . | |
'<th scope="row"><label>' . esc_html( 'Term Meta', 'my-plugin-textdomain' ) . '</label></th>' . | |
'<td>'; | |
pppf_term_edit_form( $term_id ); | |
echo '</td>' . | |
'</tr>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment