| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly. |
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
class Flipbox_Post_Meta |
| 9 |
{ |
| 10 |
public function __construct() |
| 11 |
{ |
| 12 |
// `init` is an action, not a filter. add_filter() happened to work because both |
| 13 |
// share one callback registry, but the callback returns null and would blank the |
| 14 |
// value for anything that ever treats `init` as a filter. |
| 15 |
add_action('init', array($this, 'register_meta')); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Register meta |
| 20 |
*/ |
| 21 |
public function register_meta() |
| 22 |
{ |
| 23 |
register_meta( |
| 24 |
'post', |
| 25 |
'_eb_attr', |
| 26 |
array( |
| 27 |
'show_in_rest' => true, |
| 28 |
'single' => true, |
| 29 |
'auth_callback' => [$this, 'auth_callback'], |
| 30 |
) |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Determine if the current user can edit posts |
| 36 |
* |
| 37 |
* @return bool True when can edit posts, else false. |
| 38 |
*/ |
| 39 |
public function auth_callback() |
| 40 |
{ |
| 41 |
return current_user_can('edit_posts'); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
new Flipbox_Post_Meta(); |
| 46 |
|