| 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'); |
| 100 |
|
| 101 |
|
| 102 |
$admin->display_fields(); |
| 103 |
?> |
| 104 |
</div> |
| 105 |
</div> |
| 106 |
<?php |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
} |
| 111 |
|