class-wpel-admin-fields.php
7 years ago
class-wpel-exceptions-fields.php
7 years ago
class-wpel-excluded-link-fields.php
7 years ago
class-wpel-external-link-fields.php
7 years ago
class-wpel-internal-link-fields.php
7 years ago
class-wpel-link-fields-base.php
7 years ago
class-wpel-admin-fields.php
79 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class WPEL_Admin_Fields |
| 4 | * |
| 5 | * @package WPEL |
| 6 | * @category WordPress Plugin |
| 7 | * @version 2.3 |
| 8 | * @link https://www.webfactoryltd.com/ |
| 9 | * @license Dual licensed under the MIT and GPLv2+ licenses |
| 10 | */ |
| 11 | final class WPEL_Admin_Fields extends FWP_Settings_Section_Base_1x0x0 |
| 12 | { |
| 13 | |
| 14 | /** |
| 15 | * Initialize |
| 16 | */ |
| 17 | protected function init() |
| 18 | { |
| 19 | $this->set_settings( array( |
| 20 | 'section_id' => 'wpel-admin-fields', |
| 21 | 'page_id' => 'wpel-admin-fields', |
| 22 | 'option_name' => 'wpel-admin-settings', |
| 23 | 'option_group' => 'wpel-admin-settings', |
| 24 | 'title' => __( 'Admin Settings', 'wp-external-links' ), |
| 25 | 'fields' => array( |
| 26 | 'own_admin_menu' => array( |
| 27 | 'label' => __( 'Main Admin Menu:', 'wp-external-links' ), |
| 28 | 'default_value' => '1', |
| 29 | ), |
| 30 | ), |
| 31 | ) ); |
| 32 | |
| 33 | parent::init(); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Show field methods |
| 38 | */ |
| 39 | |
| 40 | protected function show_own_admin_menu( array $args ) |
| 41 | { |
| 42 | $this->get_html_fields()->check_with_label( |
| 43 | $args[ 'key' ] |
| 44 | , __( 'Create own admin menu for this plugin', 'wp-external-links' ) |
| 45 | , '1' |
| 46 | , '' |
| 47 | ); |
| 48 | |
| 49 | echo ' <p class="description">' |
| 50 | . __( 'Or else it will be added to the "Settings" menu', 'wp-external-links' ) |
| 51 | .'</p>'; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Validate and sanitize user input before saving to databse |
| 56 | * @param array $new_values |
| 57 | * @param array $old_values |
| 58 | * @return array |
| 59 | */ |
| 60 | protected function before_update( array $new_values, array $old_values ) |
| 61 | { |
| 62 | $update_values = $new_values; |
| 63 | $is_valid = true; |
| 64 | |
| 65 | $is_valid = $is_valid && in_array( $new_values[ 'own_admin_menu' ], array( '', '1' ) ); |
| 66 | |
| 67 | if ( false === $is_valid ) { |
| 68 | // error when user input is not valid conform the UI, probably tried to "hack" |
| 69 | $this->add_error( __( 'Something went wrong. One or more values were invalid.', 'wp-external-links' ) ); |
| 70 | return $old_values; |
| 71 | } |
| 72 | |
| 73 | return $update_values; |
| 74 | } |
| 75 | |
| 76 | } |
| 77 | |
| 78 | /*?>*/ |
| 79 |