* @license GPL-2.0+ * @link http://rahularyan.com * @copyright 2014 Rahul Aryan */ class AP_labels { /** * Instance of this class. */ protected static $instance = null; /** * Return an instance of this class. * @return object A single instance of this class. */ public static function get_instance() { // If the single instance hasn't been set, set it now. if (null == self::$instance) { self::$instance = new self; } return self::$instance; } /** * Initialize the plugin by setting localization and loading public scripts * and styles. */ public function __construct() { global $current_screen; //Register Custom Post types and taxonomy add_action('init', array($this, 'create_cpt_tax'), 1); add_action ( 'question_label_edit_form_fields', array($this, 'question_label_edit_fields')); add_action( 'question_label_add_form_fields', array($this, 'question_label_fields') ); // save extra category extra fields hook add_action ( 'edited_question_label', array($this, 'save_question_label')); add_action( 'created_question_label', array($this, 'save_question_label') ); add_action('admin_enqueue_scripts', array($this, 'colorpicker')); add_filter('manage_edit-question_label_columns', array($this, 'add_question_label_columns')); add_filter('manage_question_label_custom_column', array($this, 'add_question_label_column_content'), 10, 3); add_filter('wp_ajax_ap_save_labels', array($this, 'ap_save_labels')); add_filter('ap_after_inserting_question', array($this, 'default_label')); } public function colorpicker(){ $screen = get_current_screen(); if($screen->taxonomy == 'question_label'){ wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker'); wp_enqueue_script( 'ap-colorpicker-handle', ANSPRESS_URL.'assets/colorpicker.js', array( 'wp-color-picker' ), false, true ); } } // Register Custom Post Type public function create_cpt_tax() { $question_labels = array( 'name' => __('Question Label', 'ap'), 'singular_name' => _x('Label', 'ap'), 'all_items' => __('All Label', 'ap'), 'add_new_item' => _x('Add New Label', 'ap'), 'edit_item' => __('Edit Label', 'ap'), 'new_item' => __('New Label', 'ap'), 'view_item' => __('View Label', 'ap'), 'search_items' => __('Search Label', 'ap'), 'not_found' => __('Nothing Found', 'ap'), 'not_found_in_trash' => __('Nothing found in Trash', 'ap'), 'parent_item_colon' => '' ); register_taxonomy('question_label', array('question'), array( 'hierarchical' => true, 'labels' => $question_labels, 'rewrite' => false )); } public function question_label_edit_fields( $tax ) { $t_id = $tax->term_id; $tax_meta = get_option( "question_label_$t_id"); ?>