| 1 |
<?php |
| 2 |
namespace MBSocial; |
| 3 |
defined('ABSPATH') or die('No direct access permitted'); |
| 4 |
|
| 5 |
use \MaxButtons\maxField as maxField; |
| 6 |
use \MaxButtons\maxBlocks as maxBlocks; |
| 7 |
|
| 8 |
$collectionBlock["general"] = array('class' => "generalBlock", |
| 9 |
'order' => 5); |
| 10 |
|
| 11 |
|
| 12 |
class generalBlock extends block |
| 13 |
{ |
| 14 |
protected $blockname = 'general'; |
| 15 |
protected $fields = array( |
| 16 |
'name' => array('default' => ''), |
| 17 |
'active' => array('default' => 1), |
| 18 |
); |
| 19 |
|
| 20 |
function save_fields($data, $post) |
| 21 |
{ |
| 22 |
$data = parent::save_fields($data, $post); |
| 23 |
if (! isset($post['active']) && ! is_null($post) ) |
| 24 |
{ |
| 25 |
$data[$this->blockname]['active'] = 0; |
| 26 |
} |
| 27 |
|
| 28 |
return $data; |
| 29 |
} |
| 30 |
|
| 31 |
public function do_meta_boxes($content, $post) |
| 32 |
{ |
| 33 |
|
| 34 |
$admin = mbSocial()->admin(); |
| 35 |
|
| 36 |
$metadata = $this->get_block_meta_data($post->ID); |
| 37 |
|
| 38 |
$is_hidden = isset($metadata['hide']) ? $metadata['hide']: 0; |
| 39 |
|
| 40 |
$active = new maxField('switch'); |
| 41 |
$active->label = __('Hide', 'mbsocial'); |
| 42 |
$active->id = 'mbsocial_hide'; |
| 43 |
$active->name = $active->id; |
| 44 |
$active->value = '1'; |
| 45 |
$active->note = __('This option can be used to hide the social share only here', 'mb-social'); |
| 46 |
$active->checked = checked( $is_hidden , 1, false); |
| 47 |
|
| 48 |
$admin->addField($active, 'start','end'); |
| 49 |
|
| 50 |
$fields = $admin->display_fields(true, true, false); |
| 51 |
|
| 52 |
$content['display'] = array('title' => __('Display Options', 'mbsocial'), |
| 53 |
'icon' => 'display', |
| 54 |
'content' => $fields, |
| 55 |
); |
| 56 |
|
| 57 |
return $content; |
| 58 |
} |
| 59 |
|
| 60 |
public function save_meta_boxes($metadata, $post_id, $post) |
| 61 |
{ |
| 62 |
$is_active = isset($post['mbsocial_hide']) ? intval($post['mbsocial_hide']) : 0; |
| 63 |
$metadata[$this->blockname]['hide'] = $is_active; |
| 64 |
|
| 65 |
return $metadata; |
| 66 |
|
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
public function admin() |
| 71 |
{ |
| 72 |
$admin = MBSocial()->admin(); |
| 73 |
|
| 74 |
?> |
| 75 |
<div class='option-container general' id='generalBlock' > |
| 76 |
<div class='title'><?php _e('General','mbsocial'); ?></div> |
| 77 |
<div class='inside'> |
| 78 |
<?php |
| 79 |
|
| 80 |
$field_name = new maxField() ; |
| 81 |
$field_name->label = __('Name', 'mbsocial'); |
| 82 |
// $field_name->note = __('Something that you can quickly identify the button with.', 'maxbuttons'); |
| 83 |
$field_name->value = $this->getValue('name'); |
| 84 |
$field_name->id = 'name'; |
| 85 |
$field_name->name = $field_name->id; |
| 86 |
$field_name->placeholder = __("Name","mbsocial"); |
| 87 |
$field_name->output('start','end'); |
| 88 |
|
| 89 |
// until multi-collection done not in use |
| 90 |
//$admin->addField($field_name, 'start','end'); |
| 91 |
|
| 92 |
$active = new maxField('switch'); |
| 93 |
$active->label = __('Active', 'mbsocial'); |
| 94 |
$active->id = 'active'; |
| 95 |
$active->name = $active->id; |
| 96 |
$active->value = '1'; |
| 97 |
$active->checked = checked( $this->getValue('active'), 1, false); |
| 98 |
|
| 99 |
$admin->addField($active, 'start','end', false); |
| 100 |
|
| 101 |
if ( Install::isPRO() ) { |
| 102 |
$deskhide = new maxField('spacer'); |
| 103 |
$deskhide->id = 'deskhide'; |
| 104 |
$deskhide->name = $deskhide->id; |
| 105 |
$deskhide->label = __('Desktop', 'mbsocial'); |
| 106 |
$deskhide->content = 'Shown'; |
| 107 |
$deskhide->conditional = htmlentities(json_encode(array('target' => 'show_desktop', 'values' => 'checked'))); |
| 108 |
|
| 109 |
$deskshow = new maxField('spacer'); |
| 110 |
$deskshow->id = 'deskshow'; |
| 111 |
$deskshow->name = $deskshow->id; |
| 112 |
$deskshow->label = __('Desktop', 'mbsocial'); |
| 113 |
$deskshow->content = 'Hidden'; |
| 114 |
$deskshow->conditional = htmlentities(json_encode(array('target' => 'show_desktop', 'values' => 'unchecked'))); |
| 115 |
|
| 116 |
$admin->addField($deskhide, 'start', '', false ); |
| 117 |
$admin->addField($deskshow, '', 'end', false); |
| 118 |
|
| 119 |
$mobhide = new maxField('spacer'); |
| 120 |
$mobhide->id = 'mobhide'; |
| 121 |
$mobhide->name = $mobhide->id; |
| 122 |
$mobhide->label = __('Mobile', 'mbsocial'); |
| 123 |
$mobhide->content = 'Shown'; |
| 124 |
$mobhide->conditional = htmlentities(json_encode(array('target' => 'show_mobile', 'values' => 'checked'))); |
| 125 |
|
| 126 |
$mobshow = new maxField('spacer'); |
| 127 |
$mobshow->id = 'mobshow'; |
| 128 |
$mobshow->name = $mobshow->id; |
| 129 |
$mobshow->label = __('Mobile', 'mbsocial'); |
| 130 |
$mobshow->content = 'Hidden'; |
| 131 |
$mobshow->conditional = htmlentities(json_encode(array('target' => 'show_mobile', 'values' => 'unchecked'))); |
| 132 |
|
| 133 |
$admin->addField($mobhide, 'start', '', false); |
| 134 |
$admin->addField($mobshow, '', 'end', false); |
| 135 |
} // IsPro |
| 136 |
|
| 137 |
$admin->display_fields(); |
| 138 |
?> |
| 139 |
</div> |
| 140 |
</div> |
| 141 |
<?php |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
} |
| 146 |
|