builder
2 years ago
plugin-updates
8 years ago
settings
2 years ago
views
2 years ago
class-evf-admin-addons.php
4 years ago
class-evf-admin-assets.php
2 years ago
class-evf-admin-builder.php
7 years ago
class-evf-admin-deactivation-feedback.php
3 years ago
class-evf-admin-editor.php
4 years ago
class-evf-admin-entries-table-list.php
3 years ago
class-evf-admin-entries.php
4 years ago
class-evf-admin-form-templates.php
3 years ago
class-evf-admin-forms-table-list.php
3 years ago
class-evf-admin-forms.php
3 years ago
class-evf-admin-import-export.php
4 years ago
class-evf-admin-menus.php
2 years ago
class-evf-admin-notices.php
3 years ago
class-evf-admin-settings.php
2 years ago
class-evf-admin-tools.php
4 years ago
class-evf-admin-welcome.php
2 years ago
class-evf-admin.php
2 years ago
evf-admin-functions.php
3 years ago
class-evf-admin-editor.php
112 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Functionality related to the admin TinyMCE editor. |
| 4 | * |
| 5 | * @package EverestForms/Admin |
| 6 | * @version 1.2.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | if ( ! class_exists( 'EVF_Admin_Editor', false ) ) { |
| 12 | return new EVF_Admin_Editor(); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * EVF_Admin_Editor Class. |
| 17 | */ |
| 18 | class EVF_Admin_Editor { |
| 19 | |
| 20 | /** |
| 21 | * Constructor. |
| 22 | */ |
| 23 | public function __construct() { |
| 24 | add_action( 'media_buttons', array( $this, 'media_button' ), 15 ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Allow easy shortcode insertion via a custom media button. |
| 29 | * |
| 30 | * @param string $editor_id Unique editor identifier, e.g. 'content'. |
| 31 | */ |
| 32 | public function media_button( $editor_id ) { |
| 33 | if ( ! apply_filters( 'everest_forms_show_media_button', is_admin(), $editor_id ) ) { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | // Setup the svg icon. |
| 38 | printf( |
| 39 | '<a href="#" class="button evf-insert-form-button" data-editor="%s" title="%s"><span class="wp-media-buttons-icon">%s</span> %s</a>', |
| 40 | esc_attr( $editor_id ), |
| 41 | esc_attr__( 'Add Everest Form', 'everest-forms' ), |
| 42 | '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g><path fill="#82878c" d="M18.1 4h-3.8l1.2 2h3.9zM20.6 8h-3.9l1.2 2h3.9zM20.6 18H5.8L12 7.9l2.5 4.1H12l-1.2 2h7.3L12 4.1 2.2 20h19.6z"/></g></svg>', |
| 43 | esc_html__( 'Add Form', 'everest-forms' ) |
| 44 | ); |
| 45 | |
| 46 | // If we have made it, then load the JS. |
| 47 | wp_enqueue_script( 'everest-forms-editor' ); |
| 48 | |
| 49 | add_action( 'admin_footer', array( $this, 'shortcode_modal' ) ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Modal window for inserting the form shortcode into TinyMCE. |
| 54 | */ |
| 55 | public function shortcode_modal() { |
| 56 | ?> |
| 57 | <div id="evf-modal-backdrop" style="display: none"></div> |
| 58 | <div id="evf-modal-wrap" style="display: none"> |
| 59 | <form id="evf-modal" tabindex="-1"> |
| 60 | <div id="evf-modal-title"> |
| 61 | <?php esc_html_e( 'Insert Form', 'everest-forms' ); ?> |
| 62 | <button type="button" id="evf-modal-close"><span class="screen-reader-text"><?php esc_html_e( 'Close', 'everest-forms' ); ?></span></button> |
| 63 | </div> |
| 64 | <div id="evf-modal-inner"> |
| 65 | <div id="evf-modal-options"> |
| 66 | <?php |
| 67 | $forms = evf_get_all_forms(); |
| 68 | |
| 69 | if ( ! empty( $forms ) ) { |
| 70 | printf( '<p><label for="evf-modal-select-form">%s</label></p>', esc_html__( 'Select a form below to insert', 'everest-forms' ) ); |
| 71 | echo '<select id="evf-modal-select-form">'; |
| 72 | foreach ( $forms as $form_id => $form_value ) { |
| 73 | printf( '<option value="%d">%s</option>', esc_attr( $form_id ), esc_html( $form_value ) ); |
| 74 | } |
| 75 | echo '</select>'; |
| 76 | } else { |
| 77 | echo '<p>'; |
| 78 | printf( |
| 79 | wp_kses( |
| 80 | /* translators: %s - Everest Builder page. */ |
| 81 | __( 'Whoops, you haven\'t created a form yet. Want to <a href="%s">give it a go</a>?', 'everest-forms' ), |
| 82 | array( |
| 83 | 'a' => array( |
| 84 | 'href' => array(), |
| 85 | ), |
| 86 | ) |
| 87 | ), |
| 88 | esc_url( admin_url( 'admin.php?page=evf-builder' ) ) |
| 89 | ); |
| 90 | echo '</p>'; |
| 91 | } |
| 92 | ?> |
| 93 | </div> |
| 94 | </div> |
| 95 | <div class="submitbox"> |
| 96 | <div id="evf-modal-cancel"> |
| 97 | <a class="submitdelete deletion" href="#"><?php esc_html_e( 'Cancel', 'everest-forms' ); ?></a> |
| 98 | </div> |
| 99 | <?php if ( ! empty( $forms ) ) : ?> |
| 100 | <div id="evf-modal-update"> |
| 101 | <button class="button button-primary" id="evf-modal-submit"><?php esc_html_e( 'Add Form', 'everest-forms' ); ?></button> |
| 102 | </div> |
| 103 | <?php endif; ?> |
| 104 | </div> |
| 105 | </form> |
| 106 | </div> |
| 107 | <?php |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return new EVF_Admin_Editor(); |
| 112 |