/** * Finds any item in any level of an array * * @param string $needle field type to look for * @param array $haystack an array to search the type in * * @return bool whether or not the type is in the provided array */ function bon_find_field_type($needle, $haystack) { foreach ($haystack as $h) { if ($needle != 'repeatable') { if (isset($h['type']) && $h['type'] == $needle || isset($h['repeatable_type']) && $h['repeatable_type'] == $needle) { return true; } } else { if (isset($h['type']) && $h['type'] == 'repeatable') { return bon_find_field_type($needle, $h['repeatable_fields']); } } } return false; }
/** * adds scripts to the head for special fields with extra js requirements */ function admin_head() { global $pagenow; if (in_array(get_post_type(), $this->page) && ($pagenow == 'post-new.php' || $pagenow == 'post.php') && (bon_find_field_type('date', $this->fields) || bon_find_field_type('slider', $this->fields) || bon_find_repeatable('repeatable', $this->fields))) { echo '<script type="text/javascript"> jQuery(function( $) {'; foreach ($this->fields as $field) { $this->custom_script($field); } echo '}); </script>'; } }
/** * Load Admin Stylesheet * * @access public * @return void */ public function load_styles($hook) { if (!in_array($hook, $this->of_page)) { return; } $options = $this->option_data[$hook]; if (bon_find_field_type('color2', $options)) { wp_enqueue_style('farbtastic'); } if (bon_find_field_type('color', $options)) { wp_register_style('wp-color-picker', BON_CSS . '/color-picker.min.css'); wp_enqueue_style('wp-color-picker'); } wp_enqueue_style('bon-cm', BON_URI . '/assets/codemirror/lib/codemirror.css'); wp_enqueue_style('bon-admin', BON_CSS . '/admin.css'); }