module-performance-connector.php
1 month ago
module-performance-functions.php
1 month ago
module-performance-ui.php
3 years ago
module-performance-ultra-fields.php
2 years ago
module-performance-ultra-revisions.php
1 month ago
module-performance-ultra.php
1 month ago
module-performance-upgrades.php
2 years ago
module-performance.php
1 month ago
module-performance-ui.php
227 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_performance_ui')): |
| 8 | |
| 9 | class acfe_performance_ui{ |
| 10 | |
| 11 | /** |
| 12 | * construct |
| 13 | */ |
| 14 | function __construct(){ |
| 15 | |
| 16 | add_action('acfe/dev/add_meta_boxes', array($this, 'add_meta_boxes'), 10, 3); |
| 17 | add_filter('acfe/dev/meta_ref', array($this, 'meta_ref'), 10, 6); |
| 18 | add_filter('acfe/modules/performance/config', array($this, 'get_config'), 99); |
| 19 | |
| 20 | } |
| 21 | |
| 22 | |
| 23 | /** |
| 24 | * add_meta_boxes |
| 25 | * |
| 26 | * @param $post_id |
| 27 | * @param $screen |
| 28 | * @param $type |
| 29 | */ |
| 30 | function add_meta_boxes($post_id, $screen, $type){ |
| 31 | |
| 32 | // bail early |
| 33 | if(!acfe_is_object_performance_enabled($post_id)){ |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | // check ui |
| 38 | if(!acfe_get_performance_config('ui')){ |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | // enable filters to force sidebar on list screen |
| 43 | acf_enable_filter('acfe/post_type_list/side'); |
| 44 | acf_enable_filter('acfe/taxonomy_list/side'); |
| 45 | |
| 46 | // add meta box |
| 47 | add_meta_box('acfe-performance', __('Performance Mode', 'acfe'), array($this, 'render_metabox'), $screen, 'side', 'core', array('post_id' => $post_id)); |
| 48 | |
| 49 | } |
| 50 | |
| 51 | |
| 52 | /** |
| 53 | * render_metabox |
| 54 | * |
| 55 | * @param $post |
| 56 | * @param $metabox |
| 57 | */ |
| 58 | function render_metabox($post, $metabox){ |
| 59 | |
| 60 | // post id |
| 61 | $post_id = $metabox['args']['post_id']; |
| 62 | $config = acfe_get_performance_config(); |
| 63 | |
| 64 | $fields = array( |
| 65 | |
| 66 | array( |
| 67 | 'key' => 'field_mode', |
| 68 | 'label' => '', |
| 69 | 'name' => 'options', |
| 70 | 'prefix' => 'acfe_performance', |
| 71 | 'aria-label' => '', |
| 72 | 'type' => 'radio', |
| 73 | 'value' => $config['mode'], |
| 74 | 'instructions' => '', |
| 75 | 'required' => 0, |
| 76 | 'conditional_logic' => 0, |
| 77 | 'wrapper' => array( |
| 78 | 'width' => '', |
| 79 | 'class' => '', |
| 80 | 'id' => '', |
| 81 | ), |
| 82 | 'default_value' => 0, |
| 83 | 'choices' => array( |
| 84 | 'test' => __('Test Drive', 'acfe'), |
| 85 | 'production' => __('Production', 'acfe'), |
| 86 | 'rollback' => __('Rollback', 'acfe'), |
| 87 | ), |
| 88 | ), |
| 89 | |
| 90 | ); |
| 91 | |
| 92 | // vars |
| 93 | $status = acfe_get_object_performance_status($post_id); |
| 94 | $conflict = acfe_get_object_performance_conflict($post_id); |
| 95 | ?> |
| 96 | <style> |
| 97 | .acf-field-mode{ |
| 98 | padding:8px 12px !important; |
| 99 | } |
| 100 | </style> |
| 101 | |
| 102 | <div class="misc-pub-section misc-pub-acfe-object misc-pub-acfe-dashboard" style="padding-top:11px; padding-bottom:0px;"> |
| 103 | <?php _e('Engine', 'acfe'); ?>: <strong><?php echo ucfirst($config['engine']); ?></strong> |
| 104 | </div> |
| 105 | |
| 106 | <?php if(!empty($status)): ?> |
| 107 | <div class="misc-pub-section misc-pub-acfe-object misc-pub-acfe-<?php echo $status['name'] === 'active' ? 'yes' : 'info'; ?> acf-js-tooltip" title="<?php echo $status['message']; ?>" style="padding-top:6px; padding-bottom:0px;"> |
| 108 | <?php _e('Status', 'acfe'); ?>: <strong><?php echo $status['title']; ?></strong> |
| 109 | </div> |
| 110 | <?php endif; ?> |
| 111 | |
| 112 | <?php if(!empty($conflict)): ?> |
| 113 | <div class="misc-pub-section misc-pub-acfe-object misc-pub-acfe-info acf-js-tooltip" title="<?php echo $conflict['message']; ?>" style="padding-top:6px; padding-bottom:0px;"> |
| 114 | <strong><?php echo $conflict['title']; ?></strong> |
| 115 | </div> |
| 116 | <?php endif; ?> |
| 117 | |
| 118 | <div style="padding-bottom:11px;"></div> |
| 119 | |
| 120 | <?php acf_render_fields($fields, false); ?> |
| 121 | |
| 122 | <script type="text/javascript"> |
| 123 | if(typeof acf !== 'undefined'){ |
| 124 | acf.newPostbox(<?php echo json_encode(array( |
| 125 | 'id' => 'acfe-performance', |
| 126 | 'key' => '', |
| 127 | 'style' => '', |
| 128 | 'label' => '', |
| 129 | 'editLink' => '', |
| 130 | 'editTitle' => '', |
| 131 | 'visibility' => true, |
| 132 | )); ?>); |
| 133 | } |
| 134 | </script> |
| 135 | <?php |
| 136 | |
| 137 | } |
| 138 | |
| 139 | |
| 140 | /** |
| 141 | * meta_ref |
| 142 | * |
| 143 | * @param $ref |
| 144 | * @param $wp_meta |
| 145 | * @param $type |
| 146 | * @param $key |
| 147 | * @param $id |
| 148 | * @param $post_id |
| 149 | * |
| 150 | * @return mixed |
| 151 | */ |
| 152 | function meta_ref($ref, $wp_meta, $type, $key, $id, $post_id){ |
| 153 | |
| 154 | // check enabled |
| 155 | if(acfe_get_object_performance_engine_name($post_id) !== 'hybrid'){ |
| 156 | return $ref; |
| 157 | } |
| 158 | |
| 159 | // engine |
| 160 | $engine = acfe_get_performance_engine('hybrid'); |
| 161 | |
| 162 | // meta key |
| 163 | $meta_key = $engine->get_meta_key($post_id); |
| 164 | |
| 165 | // meta ref |
| 166 | if(isset($wp_meta[ $meta_key ])){ |
| 167 | |
| 168 | $_key = $meta_key; // '_acf' or '_options_acf' |
| 169 | $_f_key = "_$key"; // '_my_field' |
| 170 | |
| 171 | if($type === 'option'){ |
| 172 | |
| 173 | // convert 'options_my_field' > '_my_field' |
| 174 | $_f_key = substr_replace($key, '_', 0, strlen($id) + 1); |
| 175 | |
| 176 | } |
| 177 | |
| 178 | $_acf = maybe_unserialize($wp_meta[ $_key ]['value']); |
| 179 | |
| 180 | if(isset($_acf[ $_f_key ])){ |
| 181 | |
| 182 | $ref = $wp_meta[ $_key ]; |
| 183 | $ref['key'] = $_f_key; |
| 184 | $ref['value'] = $_acf[ $_f_key ]; |
| 185 | |
| 186 | if($type === 'option'){ |
| 187 | $ref['key'] = "_$id" . $ref['key']; |
| 188 | } |
| 189 | |
| 190 | } |
| 191 | |
| 192 | } |
| 193 | |
| 194 | return $ref; |
| 195 | |
| 196 | } |
| 197 | |
| 198 | |
| 199 | /** |
| 200 | * get_config |
| 201 | * |
| 202 | * @param $config |
| 203 | * |
| 204 | * @return mixed |
| 205 | */ |
| 206 | function get_config($config){ |
| 207 | |
| 208 | if($config['ui']){ |
| 209 | |
| 210 | $post_config = acf_maybe_get_POST('acfe_performance'); |
| 211 | |
| 212 | if(!empty($post_config)){ |
| 213 | $config['mode'] = $post_config['field_mode']; |
| 214 | } |
| 215 | |
| 216 | } |
| 217 | |
| 218 | return $config; |
| 219 | |
| 220 | |
| 221 | } |
| 222 | |
| 223 | } |
| 224 | |
| 225 | acf_new_instance('acfe_performance_ui'); |
| 226 | |
| 227 | endif; |