settings.php
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * Settings |
| 5 | * |
| 6 | * @description: All the functionality for ACF Settings |
| 7 | * @since 3.2.6 |
| 8 | * @created: 23/06/12 |
| 9 | */ |
| 10 | |
| 11 | |
| 12 | class acf_settings |
| 13 | { |
| 14 | |
| 15 | var $parent; |
| 16 | |
| 17 | |
| 18 | /* |
| 19 | * __construct |
| 20 | * |
| 21 | * @description: |
| 22 | * @since 3.1.8 |
| 23 | * @created: 23/06/12 |
| 24 | */ |
| 25 | |
| 26 | function __construct($parent) |
| 27 | { |
| 28 | |
| 29 | // vars |
| 30 | $this->parent = $parent; |
| 31 | |
| 32 | |
| 33 | // actions |
| 34 | add_action('admin_menu', array($this,'admin_menu'), 11); |
| 35 | |
| 36 | } |
| 37 | |
| 38 | |
| 39 | /* |
| 40 | * admin_menu |
| 41 | * |
| 42 | * @description: |
| 43 | * @since 3.1.8 |
| 44 | * @created: 23/06/12 |
| 45 | */ |
| 46 | |
| 47 | function admin_menu() |
| 48 | { |
| 49 | $page = add_submenu_page('edit.php?post_type=acf', __('Settings','acf'), __('Settings','acf'), 'manage_options','acf-settings',array($this,'html')); |
| 50 | |
| 51 | add_action('admin_head-' . $page, array($this,'admin_head')); |
| 52 | |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /* |
| 57 | * admin_head |
| 58 | * |
| 59 | * @description: |
| 60 | * @since 3.1.8 |
| 61 | * @created: 23/06/12 |
| 62 | */ |
| 63 | |
| 64 | function admin_head() |
| 65 | { |
| 66 | |
| 67 | // Activate / Deactivate Add-ons |
| 68 | if( isset($_POST['acf_field_deactivate']) ) |
| 69 | { |
| 70 | // vars |
| 71 | $message = ""; |
| 72 | $field = $_POST['acf_field_deactivate']; |
| 73 | |
| 74 | // delete field |
| 75 | delete_option('acf_'.$field.'_ac'); |
| 76 | |
| 77 | //set message |
| 78 | if($field == "repeater") |
| 79 | { |
| 80 | $message = '<p>' . __("Repeater field deactivated",'acf') . '</p>'; |
| 81 | } |
| 82 | elseif($field == "options_page") |
| 83 | { |
| 84 | $message = '<p>' . __("Options page deactivated",'acf') . '</p>'; |
| 85 | } |
| 86 | elseif($field == "flexible_content") |
| 87 | { |
| 88 | $message = '<p>' . __("Flexible Content field deactivated",'acf') . '</p>'; |
| 89 | } |
| 90 | elseif($field == "gallery") |
| 91 | { |
| 92 | $message = '<p>' . __("Gallery field deactivated",'acf') . '</p>'; |
| 93 | } |
| 94 | |
| 95 | // show message on page |
| 96 | $this->parent->admin_message($message); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | if( isset($_POST['acf_field_activate']) && isset($_POST['key']) ) |
| 101 | { |
| 102 | // vars |
| 103 | $message = ""; |
| 104 | $field = $_POST['acf_field_activate']; |
| 105 | $key = trim($_POST['key']); |
| 106 | |
| 107 | // update option |
| 108 | update_option('acf_'.$field.'_ac', $key); |
| 109 | |
| 110 | // did it unlock? |
| 111 | if($this->parent->is_field_unlocked($field)) |
| 112 | { |
| 113 | //set message |
| 114 | if($field == "repeater") |
| 115 | { |
| 116 | $message = '<p>' . __("Repeater field activated",'acf') . '</p>'; |
| 117 | } |
| 118 | elseif($field == "options_page") |
| 119 | { |
| 120 | $message = '<p>' . __("Options page activated",'acf') . '</p>'; |
| 121 | } |
| 122 | elseif($field == "flexible_content") |
| 123 | { |
| 124 | $message = '<p>' . __("Flexible Content field activated",'acf') . '</p>'; |
| 125 | } |
| 126 | elseif($field == "gallery") |
| 127 | { |
| 128 | $message = '<p>' . __("Gallery field activated",'acf') . '</p>'; |
| 129 | } |
| 130 | } |
| 131 | else |
| 132 | { |
| 133 | $message = '<p>' . __("License key unrecognised",'acf') . '</p>'; |
| 134 | } |
| 135 | |
| 136 | $this->parent->admin_message($message); |
| 137 | } |
| 138 | |
| 139 | |
| 140 | |
| 141 | // Style |
| 142 | ?> |
| 143 | <link rel="stylesheet" type="text/css" href="<?php echo $this->parent->dir ?>/css/global.css" /> |
| 144 | <link rel="stylesheet" type="text/css" href="<?php echo $this->parent->dir ?>/css/acf.css" /> |
| 145 | <?php |
| 146 | } |
| 147 | |
| 148 | |
| 149 | /* |
| 150 | * html |
| 151 | * |
| 152 | * @description: |
| 153 | * @since 3.1.8 |
| 154 | * @created: 23/06/12 |
| 155 | */ |
| 156 | |
| 157 | function html() |
| 158 | { |
| 159 | |
| 160 | // vars |
| 161 | $action = isset($_POST['action']) ? $_POST['action'] : ""; |
| 162 | |
| 163 | ?> |
| 164 | <div class="wrap"> |
| 165 | |
| 166 | <div class="icon32" id="icon-acf"><br></div> |
| 167 | <h2 style="margin: 0 0 25px;"><?php _e("Advanced Custom Fields Settings",'acf'); ?></h2> |
| 168 | |
| 169 | <?php |
| 170 | |
| 171 | if($action == ""): |
| 172 | |
| 173 | /** |
| 174 | * Action: Settings Home Page |
| 175 | */ |
| 176 | |
| 177 | ?> |
| 178 | |
| 179 | <form method="post"> |
| 180 | |
| 181 | <!-- Settings --> |
| 182 | <div class="wp-box"> |
| 183 | <div class="inner"> |
| 184 | <h2><?php _e("Activate Add-ons.",'acf'); ?></h2> |
| 185 | <table class="acf_activate widefat"> |
| 186 | <thead> |
| 187 | <tr> |
| 188 | <th><?php _e("Field Type",'acf'); ?></th> |
| 189 | <th><?php _e("Status",'acf'); ?></th> |
| 190 | <th><?php _e("Activation Code",'acf'); ?></th> |
| 191 | </tr> |
| 192 | </thead> |
| 193 | <tbody> |
| 194 | <tr> |
| 195 | <td><?php _e("Repeater Field",'acf'); ?></td> |
| 196 | <td><?php echo $this->parent->is_field_unlocked('repeater') ? __("Active",'acf') : __("Inactive",'acf'); ?></td> |
| 197 | <td> |
| 198 | <form action="" method="post"> |
| 199 | <?php if($this->parent->is_field_unlocked('repeater')){ |
| 200 | echo '<span class="activation_code">XXXX-XXXX-XXXX-'.substr($this->parent->get_license_key('repeater'),-4) .'</span>'; |
| 201 | echo '<input type="hidden" name="acf_field_deactivate" value="repeater" />'; |
| 202 | echo '<input type="submit" class="button" value="Deactivate" />'; |
| 203 | } |
| 204 | else |
| 205 | { |
| 206 | echo '<input type="text" name="key" value="" />'; |
| 207 | echo '<input type="hidden" name="acf_field_activate" value="repeater" />'; |
| 208 | echo '<input type="submit" class="button" value="Activate" />'; |
| 209 | } ?> |
| 210 | </form> |
| 211 | </td> |
| 212 | </tr> |
| 213 | <tr> |
| 214 | <td><?php _e("Flexible Content Field",'acf'); ?></td> |
| 215 | <td><?php echo $this->parent->is_field_unlocked('flexible_content') ? __("Active",'acf') : __("Inactive",'acf'); ?></td> |
| 216 | <td> |
| 217 | <form action="" method="post"> |
| 218 | <?php if($this->parent->is_field_unlocked('flexible_content')){ |
| 219 | echo '<span class="activation_code">XXXX-XXXX-XXXX-'.substr($this->parent->get_license_key('flexible_content'),-4) .'</span>'; |
| 220 | echo '<input type="hidden" name="acf_field_deactivate" value="flexible_content" />'; |
| 221 | echo '<input type="submit" class="button" value="Deactivate" />'; |
| 222 | } |
| 223 | else |
| 224 | { |
| 225 | echo '<input type="text" name="key" value="" />'; |
| 226 | echo '<input type="hidden" name="acf_field_activate" value="flexible_content" />'; |
| 227 | echo '<input type="submit" class="button" value="Activate" />'; |
| 228 | } ?> |
| 229 | </form> |
| 230 | </td> |
| 231 | </tr> |
| 232 | <tr> |
| 233 | <td><?php _e("Gallery Field",'acf'); ?></td> |
| 234 | <td><?php echo $this->parent->is_field_unlocked('gallery') ? __("Active",'acf') : __("Inactive",'acf'); ?></td> |
| 235 | <td> |
| 236 | <form action="" method="post"> |
| 237 | <?php if($this->parent->is_field_unlocked('gallery')){ |
| 238 | echo '<span class="activation_code">XXXX-XXXX-XXXX-'.substr($this->parent->get_license_key('gallery'),-4) .'</span>'; |
| 239 | echo '<input type="hidden" name="acf_field_deactivate" value="gallery" />'; |
| 240 | echo '<input type="submit" class="button" value="Deactivate" />'; |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | echo '<input type="text" name="key" value="" />'; |
| 245 | echo '<input type="hidden" name="acf_field_activate" value="gallery" />'; |
| 246 | echo '<input type="submit" class="button" value="Activate" />'; |
| 247 | } ?> |
| 248 | </form> |
| 249 | </td> |
| 250 | </tr> |
| 251 | <tr> |
| 252 | <td><?php _e("Options Page",'acf'); ?></td> |
| 253 | <td><?php echo $this->parent->is_field_unlocked('options_page') ? __("Active",'acf') : __("Inactive",'acf'); ?></td> |
| 254 | <td> |
| 255 | <form action="" method="post"> |
| 256 | <?php if($this->parent->is_field_unlocked('options_page')){ |
| 257 | echo '<span class="activation_code">XXXX-XXXX-XXXX-'.substr($this->parent->get_license_key('options_page'),-4) .'</span>'; |
| 258 | echo '<input type="hidden" name="acf_field_deactivate" value="options_page" />'; |
| 259 | echo '<input type="submit" class="button" value="Deactivate" />'; |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | echo '<input type="text" name="key" value="" />'; |
| 264 | echo '<input type="hidden" name="acf_field_activate" value="options_page" />'; |
| 265 | echo '<input type="submit" class="button" value="Activate" />'; |
| 266 | } ?> |
| 267 | </form> |
| 268 | </td> |
| 269 | </tr> |
| 270 | </tbody> |
| 271 | </table> |
| 272 | </div> |
| 273 | <div class="footer"> |
| 274 | <ul class="hl left"> |
| 275 | <li><?php _e("Add-ons can be unlocked by purchasing a license key. Each key can be used on multiple sites.",'acf'); ?> <a href="http://www.advancedcustomfields.com/add-ons/"><?php _e("Find Add-ons",'acf'); ?></a></li> |
| 276 | </ul> |
| 277 | <ul class="hl right"> |
| 278 | <li></li> |
| 279 | </ul> |
| 280 | </div> |
| 281 | </div> |
| 282 | <!-- Settings --> |
| 283 | |
| 284 | <br /> |
| 285 | <br /> |
| 286 | <br /> |
| 287 | |
| 288 | <!-- Export / Import --> |
| 289 | <form method="post" action="<?php echo $this->parent->dir; ?>/core/actions/export.php"> |
| 290 | <div class="wp-box"> |
| 291 | <div class="wp-box-half left"> |
| 292 | <div class="inner"> |
| 293 | <h2><?php _e("Export Field Groups to XML",'acf'); ?></h2> |
| 294 | |
| 295 | <?php |
| 296 | $acfs = get_pages(array( |
| 297 | 'numberposts' => -1, |
| 298 | 'post_type' => 'acf', |
| 299 | 'sort_column' => 'menu_order', |
| 300 | 'order' => 'ASC', |
| 301 | )); |
| 302 | |
| 303 | // blank array to hold acfs |
| 304 | $acf_posts = array(); |
| 305 | |
| 306 | if($acfs) |
| 307 | { |
| 308 | foreach($acfs as $acf) |
| 309 | { |
| 310 | $acf_posts[$acf->ID] = $acf->post_title; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | $this->parent->create_field(array( |
| 315 | 'type' => 'select', |
| 316 | 'name' => 'acf_posts', |
| 317 | 'value' => '', |
| 318 | 'choices' => $acf_posts, |
| 319 | 'multiple' => '1', |
| 320 | )); |
| 321 | ?> |
| 322 | |
| 323 | </div> |
| 324 | <div class="footer"> |
| 325 | <ul class="hl left"> |
| 326 | <li><?php _e("ACF will create a .xml export file which is compatible with the native WP import plugin.",'acf'); ?></li> |
| 327 | </ul> |
| 328 | <ul class="hl right"> |
| 329 | <li><input type="submit" class="acf-button" value="<?php _e("Export XML",'acf'); ?>" /></li> |
| 330 | </ul> |
| 331 | </div> |
| 332 | </div> |
| 333 | <div class="wp-box-half right"> |
| 334 | <div class="inner"> |
| 335 | <h2><?php _e("Import Field Groups",'acf'); ?></h2> |
| 336 | <ol> |
| 337 | <li><?php _e("Navigate to the",'acf'); ?> <a href="<?php echo admin_url(); ?>import.php"><?php _e("Import Tool",'acf'); ?></a> <?php _e("and select WordPress",'acf'); ?></li> |
| 338 | <li><?php _e("Install WP import plugin if prompted",'acf'); ?></li> |
| 339 | <li><?php _e("Upload and import your exported .xml file",'acf'); ?></li> |
| 340 | <li><?php _e("Select your user and ignore Import Attachments",'acf'); ?></li> |
| 341 | <li><?php _e("That's it! Happy WordPressing",'acf'); ?></li> |
| 342 | </ol> |
| 343 | </div> |
| 344 | </div> |
| 345 | <div class="clear"></div> |
| 346 | </div> |
| 347 | </form> |
| 348 | <!-- / Export / Import --> |
| 349 | |
| 350 | <br /> |
| 351 | <br /> |
| 352 | <br /> |
| 353 | |
| 354 | <!-- Export / Import PHP --> |
| 355 | <form method="post"> |
| 356 | <input type="hidden" name="action" value="export_php" /> |
| 357 | <div class="wp-box"> |
| 358 | <div class="wp-box-half left"> |
| 359 | <div class="inner"> |
| 360 | <h2><?php _e("Export Field Groups to PHP",'acf'); ?></h2> |
| 361 | |
| 362 | <?php |
| 363 | $acfs = get_pages(array( |
| 364 | 'numberposts' => -1, |
| 365 | 'post_type' => 'acf', |
| 366 | 'sort_column' => 'menu_order', |
| 367 | 'order' => 'ASC', |
| 368 | )); |
| 369 | |
| 370 | // blank array to hold acfs |
| 371 | $acf_posts = array(); |
| 372 | |
| 373 | if($acfs) |
| 374 | { |
| 375 | foreach($acfs as $acf) |
| 376 | { |
| 377 | $acf_posts[$acf->ID] = $acf->post_title; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | $this->parent->create_field(array( |
| 382 | 'type' => 'select', |
| 383 | 'name' => 'acf_posts', |
| 384 | 'value' => '', |
| 385 | 'choices' => $acf_posts, |
| 386 | 'multiple' => '1', |
| 387 | )); |
| 388 | ?> |
| 389 | |
| 390 | </div> |
| 391 | <div class="footer"> |
| 392 | <ul class="hl left"> |
| 393 | <li><?php _e("ACF will create the PHP code to include in your theme",'acf'); ?></li> |
| 394 | </ul> |
| 395 | <ul class="hl right"> |
| 396 | <li><input type="submit" class="acf-button" value="<?php _e("Create PHP",'acf'); ?>" /></li> |
| 397 | </ul> |
| 398 | </div> |
| 399 | </div> |
| 400 | <div class="wp-box-half right"> |
| 401 | <div class="inner"> |
| 402 | <h2><?php _e("Register Field Groups with PHP",'acf'); ?></h2> |
| 403 | <ol> |
| 404 | <li><?php _e("Copy the PHP code generated",'acf'); ?></li> |
| 405 | <li><?php _e("Paste into your functions.php file",'acf'); ?></li> |
| 406 | <li><?php _e("To activate any Add-ons, edit and use the code in the first few lines.",'acf'); ?></li> |
| 407 | </ol> |
| 408 | </div> |
| 409 | </div> |
| 410 | <div class="clear"></div> |
| 411 | </div> |
| 412 | </form> |
| 413 | <!-- / Export / Import PHP --> |
| 414 | |
| 415 | </form> |
| 416 | |
| 417 | <?php |
| 418 | |
| 419 | elseif($action == "export_php"): |
| 420 | |
| 421 | /** |
| 422 | * Action: Export PHP |
| 423 | */ |
| 424 | |
| 425 | ?> |
| 426 | |
| 427 | <p><a href="">« <?php _e("Back to settings",'acf'); ?></a></p> |
| 428 | <div class="wp-box"> |
| 429 | <div class="inner"> |
| 430 | <h2><?php _e("Register Field Groups with PHP",'acf'); ?></h2> |
| 431 | <ol> |
| 432 | <li><?php _e("Copy the PHP code generated",'acf'); ?></li> |
| 433 | <li><?php _e("Paste into your functions.php file",'acf'); ?></li> |
| 434 | <li><?php _e("To activate any Add-ons, edit and use the code in the first few lines.",'acf'); ?></li> |
| 435 | </ol> |
| 436 | </div> |
| 437 | <div class="footer"> |
| 438 | <pre><?php |
| 439 | |
| 440 | $acfs = array(); |
| 441 | |
| 442 | if(isset($_POST['acf_posts'])) |
| 443 | { |
| 444 | $acfs = get_pages(array( |
| 445 | 'numberposts' => -1, |
| 446 | 'post_type' => 'acf', |
| 447 | 'sort_column' => 'menu_order', |
| 448 | 'order' => 'ASC', |
| 449 | 'include' => $_POST['acf_posts'] |
| 450 | )); |
| 451 | } |
| 452 | if($acfs) |
| 453 | { |
| 454 | ?> |
| 455 | <?php _e("/** |
| 456 | * Activate Add-ons |
| 457 | * Here you can enter your activation codes to unlock Add-ons to use in your theme. |
| 458 | * Since all activation codes are multi-site licenses, you are allowed to include your key in premium themes. |
| 459 | * Use the commented out code to update the database with your activation code. |
| 460 | * You may place this code inside an IF statement that only runs on theme activation. |
| 461 | */",'acf'); ?> |
| 462 | |
| 463 | // if(!get_option('acf_repeater_ac')) update_option('acf_repeater_ac', "xxxx-xxxx-xxxx-xxxx"); |
| 464 | // if(!get_option('acf_options_page_ac')) update_option('acf_options_page_ac', "xxxx-xxxx-xxxx-xxxx"); |
| 465 | // if(!get_option('acf_flexible_content_ac')) update_option('acf_flexible_content_ac', "xxxx-xxxx-xxxx-xxxx"); |
| 466 | |
| 467 | |
| 468 | <?php _e("/** |
| 469 | * Register field groups |
| 470 | * The register_field_group function accepts 1 array which holds the relevant data to register a field group |
| 471 | * You may edit the array as you see fit. However, this may result in errors if the array is not compatible with ACF |
| 472 | * This code must run every time the functions.php file is read |
| 473 | */",'acf'); ?> |
| 474 | |
| 475 | if(function_exists("register_field_group")) |
| 476 | { |
| 477 | <?php |
| 478 | foreach($acfs as $acf) |
| 479 | { |
| 480 | $var = array( |
| 481 | 'id' => uniqid(), |
| 482 | 'title' => get_the_title($acf->ID), |
| 483 | 'fields' => $this->parent->get_acf_fields($acf->ID), |
| 484 | 'location' => $this->parent->get_acf_location($acf->ID), |
| 485 | 'options' => $this->parent->get_acf_options($acf->ID), |
| 486 | 'menu_order' => $acf->menu_order, |
| 487 | ); |
| 488 | |
| 489 | ?>register_field_group(<?php var_export($var); ?>); |
| 490 | <?php |
| 491 | } |
| 492 | ?> |
| 493 | } |
| 494 | <?php |
| 495 | } |
| 496 | else |
| 497 | { |
| 498 | _e("No field groups were selected",'acf'); |
| 499 | } |
| 500 | ?></pre> |
| 501 | </div> |
| 502 | </div> |
| 503 | <?php |
| 504 | |
| 505 | endif; |
| 506 | |
| 507 | ?> |
| 508 | </div> |
| 509 | <!-- / Wrap --> |
| 510 | <?php |
| 511 | |
| 512 | } |
| 513 | |
| 514 | |
| 515 | } |
| 516 | |
| 517 | ?> |