load_dashicons(); } /** * @since 1.0 */ function init( $cpac ) { $this->cpac = $cpac; } /** * Enqueue admin styles and scripts * * @since 1.0 */ public function admin_scripts() { wp_register_style( 'cpacic-admin-cpac-settings', plugins_url( 'assets/css/admin/cpac-settings.css', __FILE__ ) ); wp_register_script( 'cpacic-admin-cpac-settings', plugins_url( 'assets/js/admin/cpac-settings.js', __FILE__ ), array( 'jquery' ) ); if ( $this->cpac && $this->cpac->is_settings_screen() ) { wp_enqueue_style( 'cpacic-admin-cpac-settings' ); wp_enqueue_script( 'cpacic-admin-cpac-settings' ); wp_enqueue_media(); } } /** * @since 1.0 */ public function column_default_options( $options ) { $options['label_icon_dashicon_name'] = ''; $options['label_icon_custom_url'] = ''; $options['label_icon_attachment_id'] = ''; $options['label_icon_type'] = ''; return $options; } /** * @since 1.1 */ public function load_dashicons() { if ( empty( $this->dashicons ) ) { $fname = plugin_dir_path( __FILE__ ) . 'data/icons.json'; $fh = fopen( $fname, 'r' ); $contents = ''; while ( ! feof( $fh ) ) { $line = fgets( $fh ); $contents .= $line; } $this->dashicons = json_decode( $contents ); } } /** * @since 1.0 */ public function column_settings_fields( $column_instance ) { $type = $column_instance->options->label_icon_type; $icon_dashicon_name = $column_instance->options->label_icon_dashicon_name; $icon_custom_url = $column_instance->options->label_icon_custom_url; $icon_attachment_id = $column_instance->options->label_icon_attachment_id; // Backwards compatibility with 1.0 // In 1.0, a single column setting was used to store the custom URL and the attachment ID, dependent on // the column type. In 1.1, this was replaced by storing all separately if ( ! empty( $column_instance->options->label_icon ) ) { if ( $type == 'attachment' && ! $icon_attachment_id ) { $icon_attachment_id = $column_instance->options->label_icon; } if ( $type == 'custom' && ! $icon_custom_url ) { $icon_custom_url = $column_instance->options->label_icon; } } ?> label_view( __( 'Header Icon', 'cpac' ), __( 'This icon will replace the label text in the column header.', 'cpacic' ), 'label_icon_type-attachment' ); ?>
>
>
>
load_dashicons(); add_thickbox(); ?>
dashicons as $dashicon => $dashicon_label ) : ?> &#x;
'', 'label_icon_dashicon_name' => '', 'label_icon_custom_url' => '', 'label_icon_attachment_id' => '', // Backwards compatibility with 1.0 // In 1.0, a single column setting was used to store the custom URL and the attachment ID, dependent on // the column type. In 1.1, this was replaced by storing all separately 'label_icon' => '' ) ); // Backwards compatibility with 1.0 if ( ! $args['label_icon_custom_url'] ) { $args['label_icon_custom_url'] = $args['label_icon']; } if ( ! $args['label_icon_attachment_id'] ) { $args['label_icon_attachment_id'] = $args['label_icon']; } // Display icon dependent on icon type if ( ! empty( $args['label_icon_type'] ) ) { if ( $args['label_icon_type'] == 'attachment' ) { if ( $args['label_icon_attachment_id'] ) { if ( $image = wp_get_attachment_image_src( $args['label_icon_attachment_id'], 'full' ) ) { $label = '' . esc_attr( $label ) . ''; } } } else if ( $args['label_icon_type'] == 'custom' ) { if ( $args['label_icon_custom_url'] ) { $label = '' . esc_attr( $label ) . ''; } } else if ( $args['label_icon_type'] == 'dashicon' ) { if ( $args['label_icon_dashicon_name'] ) { $label = '
&#x' . esc_html( $args['label_icon_dashicon_name'] ) . '
'; } } } return $label; } /** * Allow other plugins to hook into this plugin * Should be called on the plugins_loaded action * * @see action:plugins_loaded * @since 1.0 */ public function after_setup() { /** * Fires after this plugin is setup, which should be on plugins_loaded * Should be used to access the main plugin class instance, possibly store a reference to it for later use * and remove any plugin action and filter hooks * * @since 1.0 * * @param CPACIC Main plugin class instance */ do_action( 'cpacic/after_setup', $this ); } } new CPACIC();