-
-
Save jswebschmiede/3c2c8464ed0919f2030c1d94a20475fa to your computer and use it in GitHub Desktop.
Wordpress Hooks to add coustom term Options
This file contains hidden or 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 | |
/** | |
* | |
* Add only for parents coustom term Options | |
* @author rene reimann | |
* @home http://www.rene-reimann.de | |
* | |
* @hook category_add_form_fields Hooks into the category edit page | |
* @hook edit_tag_form_fields Hooks into the category frontpage | |
* | |
* @function custom_term_options() add a custom formfield only to a parent | |
* | |
*/ | |
add_action( 'category_add_form_fields', 'custom_term_options'); | |
add_action( 'edit_tag_form_fields', 'custom_term_options' ); // Hook in the category page | |
function custom_term_options(){ | |
$label = 'My new Option'; | |
$description = 'Here is a Description'; | |
if(get_category($_GET['tag_ID'])->parent == 0){ | |
if(isset($_GET['action'])){ | |
$form = catSortOptionLoop(get_option("categorySort_".$_GET['tag_ID'])); | |
$html = '<tr class="form-field"><th scope="row" valign="top"><label for="slug">'.$label.'</label></th><td>'.$form.'<p class="description">'.$description.'</p></td></tr>'; | |
}else{ | |
$html = '<div class="form-field form-required"><label for="tag-name">'.$label.'</label>'.catSortOptionLoop().'<p>'.$description.'</p></div>'; | |
} | |
echo $html; | |
}else{ | |
return false; | |
} | |
} | |
/** | |
* | |
* Saving coustom term Options | |
* @author rene reimann | |
* @home http://www.rene-reimann.de | |
* | |
* @hook edited_category Hooks before saving into the category edit page | |
* @hook create_category Hook before saving the new category | |
* | |
* @function customTermOptionsSaveCategory() add a custom formfield | |
* | |
*/ | |
add_action( 'edited_category', 'customTermOptionsSaveCategory' ); | |
add_action( 'create_category', 'customTermOptionsSaveCategory' ); | |
function customTermOptionsSaveCategory($catId){ | |
if($_POST['positon'] == 0){ | |
update_option("categorySort_$catId", $_POST['positon'] ); | |
} | |
} | |
/** | |
* Create the option slectform | |
* @author rene reimann | |
* | |
* @param $aktOp int the activ option | |
* @param $countOp int number of loops for selections | |
* @return html selectform | |
* | |
*/ | |
function catSortOptionLoop($aktOp = false, $countOp = 5){ | |
$form = '<select class="postform" id="positon" name="positon" style="width:100px;"><option value="-1">Keine</option>'; | |
for($i = 1;$i <= $countOp;$i++){ | |
if($aktOp == $i){ | |
$form .= '<option value="'.$i.'" selected="selected">'.$i.'</option>'; | |
}else{ | |
$form .= '<option value="'.$i.'">'.$i.'</option>'; | |
} | |
} | |
$form .= '</select>'; | |
return $form; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment