settings-addons.php
| 1 | <?php |
| 2 | |
| 3 | class acf_settings_addons { |
| 4 | |
| 5 | var $view; |
| 6 | |
| 7 | |
| 8 | /* |
| 9 | * __construct |
| 10 | * |
| 11 | * Initialize filters, action, variables and includes |
| 12 | * |
| 13 | * @type function |
| 14 | * @date 23/06/12 |
| 15 | * @since 5.0.0 |
| 16 | * |
| 17 | * @param n/a |
| 18 | * @return n/a |
| 19 | */ |
| 20 | |
| 21 | function __construct() { |
| 22 | |
| 23 | // actions |
| 24 | add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
| 25 | } |
| 26 | |
| 27 | |
| 28 | /* |
| 29 | * admin_menu |
| 30 | * |
| 31 | * This function will add the ACF menu item to the WP admin |
| 32 | * |
| 33 | * @type action (admin_menu) |
| 34 | * @date 28/09/13 |
| 35 | * @since 5.0.0 |
| 36 | * |
| 37 | * @param n/a |
| 38 | * @return n/a |
| 39 | */ |
| 40 | |
| 41 | function admin_menu() { |
| 42 | |
| 43 | // bail early if no show_admin |
| 44 | if( !acf_get_setting('show_admin') ) |
| 45 | { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | |
| 50 | // add page |
| 51 | $page = add_submenu_page('edit.php?post_type=acf-field-group', __('Add-ons','acf'), __('Add-ons','acf'), acf_get_setting('capability'),'acf-settings-addons', array($this,'html') ); |
| 52 | |
| 53 | |
| 54 | // actions |
| 55 | add_action('load-' . $page, array($this,'load')); |
| 56 | |
| 57 | } |
| 58 | |
| 59 | |
| 60 | /* |
| 61 | * load |
| 62 | * |
| 63 | * description |
| 64 | * |
| 65 | * @type function |
| 66 | * @date 7/01/2014 |
| 67 | * @since 5.0.0 |
| 68 | * |
| 69 | * @param $post_id (int) |
| 70 | * @return $post_id (int) |
| 71 | */ |
| 72 | |
| 73 | function load() { |
| 74 | |
| 75 | // vars |
| 76 | $this->view = array( |
| 77 | 'json' => array(), |
| 78 | ); |
| 79 | |
| 80 | |
| 81 | // load json |
| 82 | $request = wp_remote_post( 'https://assets.advancedcustomfields.com/add-ons/add-ons.json' ); |
| 83 | |
| 84 | // validate |
| 85 | if( is_wp_error($request) || wp_remote_retrieve_response_code($request) != 200) |
| 86 | { |
| 87 | acf_add_admin_notice(__('<b>Error</b>. Could not load add-ons list', 'acf'), 'error'); |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | $this->view['json'] = json_decode( $request['body'], true ); |
| 92 | } |
| 93 | |
| 94 | } |
| 95 | |
| 96 | |
| 97 | /* |
| 98 | * html |
| 99 | * |
| 100 | * description |
| 101 | * |
| 102 | * @type function |
| 103 | * @date 7/01/2014 |
| 104 | * @since 5.0.0 |
| 105 | * |
| 106 | * @param $post_id (int) |
| 107 | * @return $post_id (int) |
| 108 | */ |
| 109 | |
| 110 | function html() { |
| 111 | |
| 112 | // load view |
| 113 | acf_get_view('settings-addons', $this->view); |
| 114 | |
| 115 | } |
| 116 | |
| 117 | } |
| 118 | |
| 119 | |
| 120 | // initialize |
| 121 | new acf_settings_addons(); |
| 122 | |
| 123 | ?> |