*/ class Aarambha_Kits_Admin_Term { /** * Instance * * @access private * @var object */ private static $instance; /** * Returns the instance. * * @access public * @return object */ public static function get_instance() { if (! isset(self::$instance)) { self::$instance = new self(); } return self::$instance; } /** * Constructor method. * * @access private * @return void */ private function __construct() { // Add form filds add_action('category_add_form_fields', array($this, 'add_term_meta'), 10, 2); // Edit form filds add_action('category_edit_form_fields', array($this, 'edit_term_meta'), 10, 2); // Save extra taxonomy fields callback function. add_action('edited_category', array($this, 'update_term_meta'), 10, 2); add_action('create_category', array($this, 'update_term_meta'), 10, 2); // Load scripts for the meta-box add_action('admin_enqueue_scripts', array($this, 'load_scripts')); } /** * Add term page * * this will add the custom meta field to the add new term page */ public function add_term_meta() { ?>
term_id, '_term_image', true); $term_bg = get_term_meta($term->term_id, '_term_bg_color', true); ?>
sanitize_color($_POST['_term_bg_color']) ); } } /** * Loads the required media files for the media manager and scripts for media widgets. */ public function load_scripts() { wp_enqueue_media(); // Enqueue Style wp_enqueue_style('aarambha-kits-term', AARAMBHA_KITS_URL . 'assets/build/css/term.css', array('wp-color-picker'), AARAMBHA_KITS_VERSION, 'all'); // Enqueue Script wp_enqueue_script('wp-color-picker-alpha', AARAMBHA_KITS_URL . 'assets/build/library/wp-color-picker-alpha/wp-color-picker-alpha.js', array('jquery', 'wp-color-picker'), '3.0.2', true); wp_enqueue_script('aarambha-kits-term', AARAMBHA_KITS_URL . 'assets/build/js/term.js', array('wp-color-picker-alpha'), AARAMBHA_KITS_VERSION, true); $locale = apply_filters( 'aarambha_kits_term_var', array( 'upload_image' => esc_html__('Choose Image', 'aarambha-kits'), 'use_image' => esc_html__('Select', 'aarambha-kits'), ) ); wp_localize_script('aarambha-kits-term', 'AARAMBHA_KITS', $locale); } /** * Sanitize the color. * * @param string $color Input from the term colorpicker field * * @return string */ public function sanitize_color($color) { if ('' === $color) { return ''; } // To allow hex, rgba(), and var() values or custom values like transparent run through custom preg_replace to remove most special characters and spaces. if (strpos($color, '#') === 0) { return sanitize_hex_color($color); } else { return preg_replace('/[^A-Za-z0-9_)(\-,.]/', '', $color); } } } // Class needed only in the admin if (is_admin()) { Aarambha_Kits_Admin_Term::get_instance(); }