From 99d2efae9ad450e21b37cc16e234f63427c22947 Mon Sep 17 00:00:00 2001 From: Peter Rodgath Date: Wed, 16 Jan 2019 06:45:09 +0300 Subject: [PATCH] Add files via upload --- assets/js/scripts.js | 6 ++-- dilaz-mb-fonts.php | 65 ++++++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/assets/js/scripts.js b/assets/js/scripts.js index e8ae387..b03118a 100644 --- a/assets/js/scripts.js +++ b/assets/js/scripts.js @@ -3,12 +3,12 @@ || WebFonts JS || -------------------------------------------------------------------------------------------- || -|| @package Dilaz Metaboxes +|| @package Dilaz Metabox || @subpackage Metabox WebFonts -|| @since Dilaz Metaboxes 1.0 +|| @since Dilaz Metabox 2.0 || @author WebDilaz Team, http://webdilaz.com, http://themedilaz.com || @copyright Copyright (C) 2017, WebDilaz LTD -|| @link http://webdilaz.com/metaboxes +|| @link http://webdilaz.com/metabox || @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html || */ diff --git a/dilaz-mb-fonts.php b/dilaz-mb-fonts.php index c246b93..f2f062d 100644 --- a/dilaz-mb-fonts.php +++ b/dilaz-mb-fonts.php @@ -1,18 +1,20 @@ prefix = array('my_prefix_'); + # init add_action('init', array($this, 'webfont_init')); - } @@ -46,12 +47,12 @@ function __construct() { public function webfont_init() { $this->constants(); + $this->prefixes(); - add_action('dilaz_mb_before_main_style_enqueue', array($this, 'enqueue_scripts'), 10, 2); + add_action('dilaz_mb_before_main_style_enqueue', array($this, 'enqueue_scripts'), 10, 3); add_action('dilaz_mb_field_webfont_hook', array($this, 'register_webfont_field'), 99, 1); - add_filter('dilaz_meta_box_filter', array($this, 'insert_webfont_fields'), 99, 2); + add_filter('dilaz_meta_box_filter', array($this, 'insert_webfont_fields'), 99, 3); add_filter('dilaz_mb_sanitize_field_webfont_hook', array($this, 'sanitize_webfont_field'), 99, 2); - } @@ -61,11 +62,23 @@ public function webfont_init() { * @since 2.0 */ public function constants() { - - # Set constant path to the plugin directory define('DILAZ_MB_FONTS_DIR', trailingslashit(plugin_dir_path(__FILE__))); define('DILAZ_MB_FONTS_URL', trailingslashit(plugin_dir_url(__FILE__))); + } + + /** + * Prefixes for the target metaboxes + * + * @since 2.1 + */ + public function prefixes() { + + # target metabox options prefixes as array + $prefixes = apply_filters('dilaz_metabox_fonts_target_prefix', $prefixes = []); + + # prepare all the prefixes + $this->prefixes = array_map('DilazMetaboxFunction::preparePrefix', $prefixes); } @@ -77,11 +90,11 @@ public function constants() { * * @return array */ - function enqueue_scripts($prefix, $dilaz_meta_boxes) { + function enqueue_scripts($prefix, $dilaz_meta_boxes, $parameters) { - if (isset($this->prefix) and in_array($prefix, $this->prefix)) { - - $meta_box_class = new Dilaz_Meta_Box($prefix, $dilaz_meta_boxes); + if (isset($this->prefixes) and in_array($prefix, $this->prefixes)) { + + $meta_box_class = new Dilaz_Meta_Box($prefix, $dilaz_meta_boxes, $parameters); # Webfont styles if ($meta_box_class->has_field('webfont')) { @@ -326,10 +339,10 @@ function register_webfont_field($field) { * * @return array */ - function insert_webfont_fields($dilaz_meta_boxes, $prefix) { + function insert_webfont_fields($dilaz_meta_boxes, $prefix, $parameters) { # insert only in required metabox options - if (!in_array($prefix, $this->prefix)) return; + if (!in_array($prefix, $this->prefixes)) return $dilaz_meta_boxes; # array data to be inserted $dilaz_font_metaboxes = []; @@ -475,9 +488,9 @@ function insert_webfont_fields($dilaz_meta_boxes, $prefix) { 'args' => array('fonts' => array('linea-weather')), ); - $new = DilazMetaboxFunction::insert_field($dilaz_meta_boxes, $prefix .'box-simple-fields', $prefix .'conditionals', $dilaz_font_metaboxes, 'last'); + $insert = DilazMetaboxFunction::insert_field($dilaz_meta_boxes, $prefix .'box-simple-fields', $prefix .'conditionals', $dilaz_font_metaboxes, 'last'); - return ($new != false) ? array_merge($dilaz_meta_boxes, $new) : $dilaz_meta_boxes; + return ($insert != false) ? array_merge($dilaz_meta_boxes, $insert) : $dilaz_meta_boxes; } @@ -494,4 +507,4 @@ function sanitize_webfont_field($input, $field) { } } -new DilazMetaboxFonts; +new DilazMetaboxFonts; \ No newline at end of file