settings = array( 'plugin' => __('ACF Tab & Accordion Title Icons', 'acf_icon_title'), 'this_acf_version' => 0, 'min_acf_version' => '5.6.7', 'version' => '1.0.0', 'url' => plugin_dir_url( __FILE__ ), 'path' => plugin_dir_path( __FILE__ ), 'plugin_path' => 'https://wordpress.org/plugins/acf-tab-accordion-title-icons/' ); // set text domain load_plugin_textdomain( 'acf_icon_title', false, dirname( plugin_basename(__FILE__) ) . '/languages/' ); add_action( 'admin_init', array($this, 'acf_or_die'), 11); // include field add_action('acf/input/admin_enqueue_scripts', array($this, 'acf_title_icon_admin_enqueue_scripts'), 11); add_action('acf/render_field_settings/type=accordion', array($this, 'dhz_title_icon_render_field_settings'), 11); add_action('acf/render_field_settings/type=tab', array($this, 'dhz_title_icon_render_field_settings'), 11); add_filter('acf/prepare_field/type=accordion', array($this, 'dhz_acf_title_icon_prepare_field'), 11); add_filter('acf/prepare_field/type=tab', array($this, 'dhz_acf_title_icon_prepare_field'), 11); if ( DHZ_SHOW_DONATION_LINK == true ) { // add plugin to $plugins array for the metabox add_filter( '_dhz_plugins_list', array($this, '_dhz_meta_box_data') ); // metabox callback for plugins list and donation link add_action( 'add_meta_boxes_acf-field-group', array($this, '_dhz_plugins_list_meta_box') ); } } /** * Let's make sure ACF Pro is installed & activated * If not, we give notice and kill the activation of ACF RGBA Color Picker. * Also works if ACF Pro is deactivated. */ function acf_or_die() { if ( !class_exists('acf') ) { $this->kill_plugin(); } else { $this->settings['this_acf_version'] = acf()->settings['version']; if ( version_compare( $this->settings['this_acf_version'], $this->settings['min_acf_version'], '<' ) ) { $this->kill_plugin(); } } } function kill_plugin() { deactivate_plugins( plugin_basename( __FILE__ ) ); if ( isset( $_GET['activate'] ) ) { unset( $_GET['activate'] ); } add_action( 'admin_notices', array($this, 'acf_dependent_plugin_notice') ); } function acf_dependent_plugin_notice() { echo '

' . sprintf( __('%1$s requires ACF PRO v%2$s or higher to be installed and activated.', 'acf_icon_title'), $this->settings['plugin'], $this->settings['min_acf_version']) . '

'; } /* * Load the javascript and CSS files on the ACF admin pages */ function acf_title_icon_admin_enqueue_scripts() { // globals global $wp_scripts, $wp_styles; $url = $this->settings['url']; $version = $this->settings['version']; if ( file_exists(get_theme_file_path() . '/acf-title-icons/style.css') ) { // register ACF Title Icons CSS from theme folder wp_register_style( 'acf-title-icons', get_theme_file_uri() . '/acf-title-icons/style.css', array(), $version); } else { // register ACF Title Icons CSS from plugin folder wp_register_style( 'acf-title-icons', "{$url}assets/icons/style.css", array(), $version); } // register ACF Title Icons wp_register_style( 'acf-title-icon', "{$url}assets/css/acf-title-icon.css", array(), $version); // enqueue styles & scripts wp_enqueue_style('acf-title-icons'); wp_enqueue_style('acf-title-icon'); } function dhz_title_icon_render_field_settings( $field ) { $url = $this->settings['url']; // $json_file = wp_remote_get( get_theme_file_uri( '/acf-title-icons/' ) . $iconname . '/selection.json'); // $response_code = wp_remote_retrieve_response_code( $json_file ); // if ( $response_code != 200 ) { // $json_file = wp_remote_get( $icondir . 'selection.json'); // } // $json_file = wp_remote_retrieve_body( $json_file ); if ( file_exists(get_theme_file_path() . "/acf-title-icons/selection.json") ) { $json_file = file_get_contents( get_theme_file_uri( "/acf-title-icons/selection.json") ); } else { $json_file = file_get_contents( "{$url}assets/icons/selection.json"); } $json_content = json_decode( $json_file, true ); if ( !isset( $json_content['icons'] ) ) { acf_render_field_setting( $field, array( 'label' => __('Icon',"acf_icon_title"), 'instructions' => '', 'type' => 'message', 'message' => __('No icons found', "acf_icon_title"), 'new_lines' => '' )); return; } $prefix = $json_content['preferences']['fontPref']['prefix']; $iconname = $json_content['preferences']['fontPref']['metadata']['fontFamily']; $icons = array(); foreach ( $json_content['icons'] as $icon ) { $class = $icon['properties']['name']; $name = implode(" ",$icon['icon']['tags']); $icons[$iconname . '-' . $class] = esc_html('' . $name . ''); } // icon select acf_render_field_setting( $field, array( 'label' => __("Icon", "acf_icon_title"), 'instructions' => __("Select an icon you want to show before the title.", "acf_icon_title"), 'type' => 'select', 'id' => $field['ID'] . 'accordion-select', 'name' => 'icon_class', 'choices' => $icons, 'allow_null' => 1, 'multiple' => 0, 'ui' => 1, 'ajax' => 0, )); // icon only acf_render_field_setting( $field, array( 'label' => __("Show icon only", "acf_icon_title"), 'instructions' => __("If set to Yes, you will see only the icon and no title.", "acf_icon_title"), 'name' => 'show_icon_only', 'type' => 'true_false', 'ui' => 1, )); } function dhz_acf_title_icon_prepare_field( $field ) { if ( array_key_exists('icon_class', $field) && !$field['icon_class'] == '') { if ( array_key_exists('show_icon_only', $field) && $field['show_icon_only'] == 1 ) { $field['label'] = ''; } else { $field['label'] = '' . esc_attr( $field["label"] ) . ''; } $field['wrapper']['class'] .= 'acf-title-with-icon'; } return $field; } /* * Add plugin to $plugins array for the metabox */ function _dhz_meta_box_data($plugins=array()) { $plugins[] = array( 'title' => $this->settings['plugin'], 'screens' => array('acf-field-group'), 'doc' => $this->settings['plugin_path'] ); return $plugins; } // end function meta_box /* * Add metabox for plugins list and donation link */ function _dhz_plugins_list_meta_box() { $plugins = apply_filters('_dhz_plugins_list', array()); $id = 'plugins-by-dreihochzwo'; $title = ''.__("Plugins by dreihochzwo", "acf_icon_title").''; $callback = array($this, 'show_dhz_plugins_list_meta_box'); $screens = array(); foreach ($plugins as $plugin) { $screens = array_merge($screens, $plugin['screens']); } $context = 'side'; $priority = 'default'; add_meta_box($id, $title, $callback, $screens, $context, $priority); } // end function _dhz_plugins_list_meta_box /* * Metabox callback for plugins list and donation link */ function show_dhz_plugins_list_meta_box() { $plugins = apply_filters('_dhz_plugins_list', array()); ?>