AdminPageSetting.Image.class.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Register, display and save an image field setting in the admin menu |
| 5 | * |
| 6 | * @since 1.0 |
| 7 | * @package Simple Admin Pages |
| 8 | */ |
| 9 | |
| 10 | class sapAdminPageSettingImage_2_6_19 extends sapAdminPageSetting_2_6_19 { |
| 11 | |
| 12 | public $sanitize_callback = 'absint'; |
| 13 | |
| 14 | /** |
| 15 | * Scripts that must be loaded for this component |
| 16 | * @since 2.1.0 |
| 17 | */ |
| 18 | public $scripts = array( |
| 19 | 'sap-image' => array( |
| 20 | 'path' => 'js/image.js', |
| 21 | 'dependencies' => array( 'jquery' ), |
| 22 | 'version' => SAP_VERSION, |
| 23 | 'footer' => true, |
| 24 | ), |
| 25 | ); |
| 26 | |
| 27 | /** |
| 28 | * Translateable strings required for this component |
| 29 | * @since 2.1.0 |
| 30 | */ |
| 31 | public $strings = array( |
| 32 | 'add_image' => null, // __( 'Add Image', 'textdomain' ), |
| 33 | 'change_image' => null, // __( 'Change Image', 'textdomain' ), |
| 34 | 'remove_image' => null, // __( 'Remove Image', 'textdomain' ), |
| 35 | ); |
| 36 | |
| 37 | /** |
| 38 | * Display this setting |
| 39 | * @since 1.0 |
| 40 | */ |
| 41 | public function display_setting() { |
| 42 | $image_url = $this->value ? wp_get_attachment_url( $this->value ) : ''; |
| 43 | ?> |
| 44 | |
| 45 | <fieldset <?php $this->print_conditional_data(); ?>> |
| 46 | <div class="sap-image-wrapper <?php echo $this->value ? 'sap-image-wrapper-has-image' : 'sap-image-wrapper-no-image'; ?>" data-id="sap-<?php echo esc_attr( $this->id ); ?>"> |
| 47 | <input name="<?php echo esc_attr( $this->get_input_name() ); ?>" type="hidden" id="sap-<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $this->value ); ?>"> |
| 48 | <img src="<?php echo esc_attr( $image_url ); ?>"> |
| 49 | <button class="button sap-image-btn-add" id="sap-<?php echo esc_attr( $this->id ); ?>-add"><?php echo esc_html( $this->strings['add_image'] ); ?></button> |
| 50 | <button class="button sap-image-btn-change" id="sap-<?php echo esc_attr( $this->id ); ?>-change"><?php echo esc_html( $this->strings['change_image'] ); ?></button> |
| 51 | <button class="button sap-image-btn-remove" id="sap-<?php echo esc_attr( $this->id ); ?>-remove"><?php echo esc_html( $this->strings['remove_image'] ); ?></button> |
| 52 | </div> |
| 53 | </fieldset> |
| 54 | |
| 55 | <?php |
| 56 | |
| 57 | // global $wp_scripts; |
| 58 | // print_r( $wp_scripts ); |
| 59 | |
| 60 | $this->display_description(); |
| 61 | |
| 62 | } |
| 63 | |
| 64 | } |
| 65 |