true ), 'names' );
foreach ( $taxonomies as $taxonomy ) {
// Fields on the "Add new term" form.
add_action( "{$taxonomy}_add_form_fields", array( $this, 'add_form_fields' ) );
// Fields on the "Edit term" form.
add_action( "{$taxonomy}_edit_form_fields", array( $this, 'edit_form_fields' ), 10, 2 );
// Save on create.
add_action( "created_{$taxonomy}", array( $this, 'save_term_meta' ), 10, 2 );
// Save on update.
add_action( "edited_{$taxonomy}", array( $this, 'save_term_meta' ), 10, 2 );
}
}
/**
* Render fields on the "Add new term" screen.
*
* @param string $taxonomy Current taxonomy slug.
*/
public function add_form_fields( $taxonomy ) {
wp_nonce_field( 's1_seo_term_save', 's1_seo_term_nonce' );
?>
term_id, self::META_TITLE, true );
$seo_desc = get_term_meta( $term->term_id, self::META_DESC, true );
?>
|
|
|
|
/60
|
|
|
false,
'textarea_rows' => 5,
'teeny' => true,
'tinymce' => array(
'toolbar1' => 'bold,italic,underline,link,unlink',
'toolbar2' => '',
),
);
wp_editor( $seo_desc, 's1_seo_description', $settings );
?>
/160
|
array(
'href' => array(),
'title' => array(),
'target' => array(),
),
'b' => array(),
'strong' => array(),
'i' => array(),
'em' => array(),
'br' => array(),
'p' => array(),
'span' => array(),
'ul' => array(),
'ol' => array(),
'li' => array(),
);
// Для администраторов разрешаем все теги, для остальных - только безопасные
if ( current_user_can( 'unfiltered_html' ) ) {
$sanitized = $description;
} else {
$sanitized = wp_kses( $description, $allowed_tags );
}
update_term_meta(
$term_id,
self::META_DESC,
$sanitized
);
}
}
/**
* Static helper: retrieve SEO title for a term.
*
* @param int $term_id Term ID.
* @return string
*/
public static function get_title( $term_id ) {
return (string) get_term_meta( $term_id, self::META_TITLE, true );
}
/**
* Static helper: retrieve SEO description for a term.
*
* @param int $term_id Term ID.
* @return string
*/
public static function get_description( $term_id ) {
return (string) get_term_meta( $term_id, self::META_DESC, true );
}
}