term_icon_name = 'term_icon_id';
// Icon fields and actions
add_action( $this->slug . '_add_form_fields', [ $this, 'add_taxonomy_icon' ] );
add_action( 'created_' . $this->slug, [ $this, 'save_taxonomy_icon' ] );
add_action( $this->slug . '_edit_form_fields', [ $this, 'update_taxonomy_icon' ] );
add_action( 'edited_' . $this->slug, [ $this, 'updated_taxonomy_icon' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'load_icon_scripts' ] );
}
/**
* Add a form field in the new taxonomy page
*
* @since 1.0.0
*/
public function add_taxonomy_icon() {
wp_nonce_field( 'tax_nonce_action', 'tax_nonce' );
?>
term_icon_name ] ) && ( '' !== $_POST[ $this->term_icon_name ] ) ) {
add_term_meta( $term_id, $this->term_icon_name, sanitize_text_field( $_POST[ $this->term_icon_name ] ), true );
}
}
/**
* Edit the form field
*
* @since 1.0.0
*/
public function update_taxonomy_icon( $term ) {
wp_nonce_field( 'tax_nonce_action', 'tax_nonce' );
?>
|
|
term_id, $this->term_icon_name, true );
?>
|
term_icon_name ] ) && ( '' !== $_POST[ $this->term_icon_name ] ) ) {
update_term_meta( $term_id, $this->term_icon_name, sanitize_text_field( $_POST[ $this->term_icon_name ] ) );
} else {
update_term_meta( $term_id, $this->term_icon_name, '' );
}
}
/**
* Add scripts
*
* @since 1.0.0
*/
public function load_icon_scripts() {
// Check if we're on a taxonomy page
if ( ! isset( $_GET['taxonomy'] ) ) {
return;
}
// Check if the current taxonomy is one of our dynamic taxonomies
$current_taxonomy = sanitize_text_field( $_GET['taxonomy'] );
$is_dynamic_taxonomy = strpos( $current_taxonomy, 'adqs_' ) === 0 &&
( strpos( $current_taxonomy, '_categories' ) !== false ||
strpos( $current_taxonomy, '_locations' ) !== false ||
strpos( $current_taxonomy, '_tags' ) !== false );
// Also check for our specific taxonomy patterns
if ( ! $is_dynamic_taxonomy ) {
$is_dynamic_taxonomy = preg_match( '/^[a-z0-9_-]+_(category|location|tag)$/', $current_taxonomy );
}
if ( ! $is_dynamic_taxonomy ) {
return;
}
// Load Js
wp_enqueue_script( 'tax-icon-picker', ADQS_DIRECTORY_ASSETS_URL . '/admin/extra/icon-picker/js/universal-icon-picker.js', [], ADQS_DIRECTORY_VERSION, true );
wp_add_inline_script( 'tax-icon-picker', $this->add_icon_inline_script() );
wp_localize_script(
'tax-icon-picker',
'iconPickerLibUrl',
[
'url' => ADQS_DIRECTORY_ASSETS_URL . '/admin/extra/icon-picker',
]
);
// Load Css
wp_enqueue_style( 'fontawesome', ADQS_DIRECTORY_ASSETS_URL . '/admin/css/fontawesome-all.min.css', [], ADQS_DIRECTORY_VERSION );
wp_enqueue_style( 'tabler-icons', ADQS_DIRECTORY_ASSETS_URL . '/admin/extra/icon-picker/stylesheets/tabler-icons.min.css', [], ADQS_DIRECTORY_VERSION );
wp_enqueue_style( 'tax-icon-picker', ADQS_DIRECTORY_ASSETS_URL . '/admin/extra/icon-picker/stylesheets/icon-picker.custom.css', [], ADQS_DIRECTORY_VERSION );
}
/**
* Add inline scripts
*
* @since 1.0.0
*/
public function add_icon_inline_script() {
ob_start();
?>
', '' ], [ '', '' ], ob_get_clean() );
}
}