From 251eaf8ac51cccb74c73c576bfe6af8b2f4cf209 Mon Sep 17 00:00:00 2001 From: Hoang Huu Date: Thu, 26 Sep 2019 14:06:11 +0700 Subject: [PATCH] Update --- .../custom-fields/iconpicker/iconpicker.php | 38 +++++++++++-------- inc/vendors/cmb2-plugins/init.php | 1 + 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/inc/vendors/cmb2-plugins/custom-fields/iconpicker/iconpicker.php b/inc/vendors/cmb2-plugins/custom-fields/iconpicker/iconpicker.php index 063a0011..561df76a 100755 --- a/inc/vendors/cmb2-plugins/custom-fields/iconpicker/iconpicker.php +++ b/inc/vendors/cmb2-plugins/custom-fields/iconpicker/iconpicker.php @@ -11,11 +11,6 @@ if ( ! defined( 'ABSPATH' ) ) { } class Opalestate_Field_Iconpicker { - /** - * @var array - */ - protected static $icon_data = []; - /** * Current version number */ @@ -24,22 +19,35 @@ class Opalestate_Field_Iconpicker { /** * Initialize the plugin by hooking into CMB2 */ - public static function init() { - $icons = new Fontawesome(); - static::$icon_data[] = $icons->get_icons(); + public function __construct() { + add_filter( 'cmb2_render_opal_iconpicker', [ $this, 'render_iconpicker' ], 10, 5 ); + add_filter( 'cmb2_sanitize_opal_iconpicker', [ $this, 'sanitize' ], 10, 4 ); + } - add_filter( 'cmb2_render_opal_iconpicker', [ __CLASS__, 'render_iconpicker' ], 10, 5 ); - add_filter( 'cmb2_sanitize_opal_iconpicker', [ __CLASS__, 'sanitize' ], 10, 4 ); + public function get_icons() { + $fontawesome_key = 'opalestate_fontawesome_data'; + + $icon_data = []; + if ( false === ( $fontawesome_icons = get_transient( $fontawesome_key ) ) ) { + $fontawesome = new Opalestate_Iconpicker_Fontawesome(); + $fontawesome_icons = $fontawesome->get_icons(); + set_transient( $fontawesome_key, $fontawesome_icons, 24 * 7 * HOUR_IN_SECONDS ); + $icon_data[] = $fontawesome_icons; + } + var_dump($icon_data); + return $icon_data; } /** * Render field. */ - public static function render_iconpicker( $field, $field_escaped_value, $field_object_id, $field_object_type, $field_type_object ) { - self::setup_admin_scripts(); + public function render_iconpicker( $field, $field_escaped_value, $field_object_id, $field_object_type, $field_type_object ) { + $this->setup_admin_scripts(); $users = $field->value; +var_dump($this->get_icons()); + // $output = sprintf( // '