1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
<?php
namespace hji\geofarms\models;
use \hji\geofarms\GeoFarms;
class CMB
{
public $cmb_prefix = '_cmbgeofarms_';
public $cmb_start_fields = 1;
public $cmb_total_fields = 6;
public function cmb_metaboxes()
{
$tabs = array(
'id' => 'tabs',
'title' => __('Tabs', 'hji_geo_farms'),
'object_types' => array(GeoFarms::$post_type,),
'context' => 'normal',
'priority' => 'default',
'show_names' => true,
'fields' => $this->cmb_metaboxes_create_fields($this->cmb_start_fields, $this->cmb_total_fields),
);
$featured_listings = array(
'id' => 'featured_listings',
'title' => __('Featured Listings', 'hji_geo_farms'),
'object_types' => array(GeoFarms::$post_type,),
'context' => 'normal',
'priority' => 'default',
'show_names' => true,
'fields' => array(
array(
'name' => 'Enter the shortcode to use for generating the featured listings for this area.',
'desc' => 'Anything placed in this box will display below the tabs on the front end, regardless of which tab is selected.',
'id' => $this->cmb_prefix . $this->cmb_featured_listings_name(),
'type' => 'wysiwyg',
'options' => $this->cmb_metaboxes_wysiwyg_options(),
),
),
);
$meta_boxes = array(
'tabs' => $tabs,
'featured_listings' => $featured_listings,
);
return $meta_boxes;
}
public function cmb_metaboxes_create_fields($start, $total)
{
$return = array();
for($i = $start; $i <= $total; $i++)
{
if($i == 1)
{
$name = array(
'name' => __("Tab {$i} Custom Name", 'hji_geo_farms'),
'id' => $this->cmb_prefix . $this->cmb_tab_name($i),
'type' => 'text_medium',
'desc' => '<p>If no tab title is entered into this field, the tab will default to "$Area_Name Info" where $Area_Name is the name from the Area Map section above.</p>'
);
array_push($return, $name);
}
else
{
$name = array(
'name' => __("Tab {$i} Name", 'hji_geo_farms'),
'id' => $this->cmb_prefix . $this->cmb_tab_name($i),
'type' => 'text_medium',
);
$content = array(
'name' => __("Tab {$i} Shortcode", 'hji_geo_farms'),
'id' => $this->cmb_prefix . $this->cmb_tab_shortcode($i),
'type' => 'wysiwyg',
'options' => $this->cmb_metaboxes_wysiwyg_options(),
);
array_push($return, $name, $content);
}
}
return $return;
}
public function cmb_tab_name($i)
{
return "tab_{$i}_name";
}
public function cmb_tab_shortcode($i)
{
return "tab_{$i}_shortcode";
}
public function cmb_featured_listings_name()
{
return 'featured_listings';
}
public function cmb_metaboxes_wysiwyg_options()
{
return array(
'wpautop' => false,
'media_buttons' => false,
'textarea_name' => '',
'textarea_rows' => '2',
'tabindex' => '',
'editor_css' => '',
'editor_class' => '',
'teeny' => false,
'dfw' => false,
'tinymce' => true,
'quicktags' => false,
);
}
public function cmb_metaboxes_wysiwyg_before_init($mceInit, $editor_id)
{
if(substr($editor_id, 0, strlen($this->cmb_prefix)) == $this->cmb_prefix)
{
if (empty($mceInit['toolbar3']) && !empty($mceInit['toolbar4']))
{
$mceInit['toolbar1'] = $mceInit['toolbar4'];
$mceInit['toolbar2'] = '';
$mceInit['toolbar4'] = '';
}
else if (!empty($mceInit['toolbar3']) && empty($mceInit['toolbar4']))
{
$mceInit['toolbar1'] = $mceInit['toolbar3'];
$mceInit['toolbar2'] = '';
$mceInit['toolbar3'] = '';
}
else if (!empty($mceInit['toolbar3']) && !empty( $mceInit['toolbar4']))
{
$mceInit['toolbar1'] = $mceInit['toolbar3'];
$mceInit['toolbar2'] = $mceInit['toolbar4'];
$mceInit['toolbar3'] = '';
$mceInit['toolbar4'] = '';
}
}
return $mceInit;
}
}