builder
3 weeks ago
form-migrator
3 weeks ago
plugin-updates
8 years ago
settings
3 weeks ago
views
3 weeks ago
class-evf-admin-addons.php
4 months ago
class-evf-admin-assets.php
4 days ago
class-evf-admin-builder.php
2 months ago
class-evf-admin-dashboard.php
3 weeks ago
class-evf-admin-editor.php
4 years ago
class-evf-admin-embed-wizard.php
2 years ago
class-evf-admin-entries-table-list.php
2 months ago
class-evf-admin-entries.php
2 months ago
class-evf-admin-form-templates.php
3 weeks ago
class-evf-admin-forms-table-list.php
4 months ago
class-evf-admin-forms.php
4 months ago
class-evf-admin-import-export.php
3 weeks ago
class-evf-admin-menus.php
3 weeks ago
class-evf-admin-notices.php
4 months ago
class-evf-admin-preview-confirmation.php
11 months ago
class-evf-admin-settings.php
3 weeks ago
class-evf-admin-tools.php
2 months ago
class-evf-admin-welcome.php
2 years ago
class-evf-admin.php
2 months ago
class-evf-base-list-table.php
4 months ago
evf-admin-functions.php
3 weeks ago
class-evf-admin-forms.php
247 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Admin Forms Class |
| 4 | * |
| 5 | * @package EverestForms\Admin |
| 6 | * @since 1.2.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * EVF_Admin_Forms class. |
| 13 | */ |
| 14 | class EVF_Admin_Forms { |
| 15 | |
| 16 | /** |
| 17 | * Initialize the forms admin actions. |
| 18 | */ |
| 19 | public function __construct() { |
| 20 | add_action( 'admin_init', array( $this, 'actions' ) ); |
| 21 | add_action( 'deleted_post', array( $this, 'delete_entries' ) ); |
| 22 | add_filter( 'wp_untrash_post_status', array( $this, 'untrash_form_status' ), 10, 2 ); |
| 23 | add_action( 'trashed_post', array( $this, 'remove_post_from_import_tracker' ), 10, 2 ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Check if is forms page. |
| 28 | * |
| 29 | * @return bool |
| 30 | */ |
| 31 | private function is_forms_page() { |
| 32 | return isset( $_GET['page'] ) && 'evf-builder' === $_GET['page']; // phpcs:ignore WordPress.Security.NonceVerification |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Page output. |
| 37 | */ |
| 38 | public static function page_output() { |
| 39 | global $current_tab; |
| 40 | |
| 41 | if ( isset( $_GET['form_id'] ) && $current_tab ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 42 | $form = evf()->form->get( absint( $_GET['form_id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 43 | $form_id = is_object( $form ) ? absint( $form->ID ) : absint( $_GET['form_id'] ); // phpcs:ignore WordPress.Security.NonceVerification |
| 44 | $form_data = is_object( $form ) ? evf_decode( $form->post_content ) : false; |
| 45 | |
| 46 | include 'views/html-admin-page-builder.php'; |
| 47 | } elseif ( isset( $_GET['create-form'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 48 | EVF_Admin_Form_Templates::load_template_view(); |
| 49 | } else { |
| 50 | self::table_list_output(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Table list output. |
| 56 | */ |
| 57 | public static function table_list_output() { |
| 58 | global $forms_table_list; |
| 59 | |
| 60 | $forms_table_list->process_bulk_action(); |
| 61 | $forms_table_list->prepare_items(); |
| 62 | |
| 63 | $use_react_header = apply_filters( 'everest_forms_use_react_header', true, 'forms' ); |
| 64 | if ( $use_react_header ) { |
| 65 | ?> |
| 66 | <div id="evf-react-header-root" data-active-menu="forms"></div> |
| 67 | <?php |
| 68 | } |
| 69 | ?> |
| 70 | |
| 71 | <div class="wrap"> |
| 72 | <?php settings_errors(); ?> |
| 73 | |
| 74 | <form id="form-list" method="post"> |
| 75 | <input type="hidden" name="page" value="everest-forms"/> |
| 76 | |
| 77 | <div class="everest-forms-base-list-table-heading"> |
| 78 | <div style="display: flex; align-items: center; gap: 16px; flex: 0 0 auto;"> |
| 79 | <span class="evf-forms-title"> |
| 80 | <?php esc_html_e( 'All Forms', 'everest-forms' ); ?> |
| 81 | </span> |
| 82 | <?php if ( current_user_can( 'everest_forms_create_forms' ) ) : ?> |
| 83 | <a href="<?php echo esc_url( admin_url( 'admin.php?page=evf-builder&create-form=1' ) ); ?>" class="page-title-action" style="margin: 0;"> |
| 84 | <?php esc_html_e( 'Add New', 'everest-forms' ); ?> |
| 85 | </a> |
| 86 | <?php endif; ?> |
| 87 | </div> |
| 88 | |
| 89 | <div class="search-box" style="flex: 0 0 auto; margin: 0; right: 0;"> |
| 90 | <?php $forms_table_list->search_box( esc_html__( 'Search Forms', 'everest-forms' ), 'everest-forms' ); ?> |
| 91 | </div> |
| 92 | </div> |
| 93 | |
| 94 | <?php |
| 95 | $forms_table_list->views(); |
| 96 | $forms_table_list->display(); |
| 97 | wp_nonce_field( 'save', 'everest-forms_nonce' ); |
| 98 | ?> |
| 99 | </form> |
| 100 | </div> |
| 101 | <?php |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Forms admin actions. |
| 106 | */ |
| 107 | public function actions() { |
| 108 | if ( $this->is_forms_page() ) { |
| 109 | // Empty trash. |
| 110 | if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 111 | $this->empty_trash(); |
| 112 | } |
| 113 | |
| 114 | // Duplicate form. |
| 115 | if ( isset( $_REQUEST['action'] ) && 'duplicate_form' === $_REQUEST['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 116 | $this->duplicate_form(); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Empty Trash. |
| 123 | */ |
| 124 | private function empty_trash() { |
| 125 | check_admin_referer( 'bulk-forms' ); |
| 126 | |
| 127 | $count = 0; |
| 128 | $form_ids = get_posts( |
| 129 | array( |
| 130 | 'post_type' => 'everest_form', |
| 131 | 'ignore_sticky_posts' => true, |
| 132 | 'nopaging' => true, |
| 133 | 'post_status' => 'trash', |
| 134 | 'fields' => 'ids', |
| 135 | ) |
| 136 | ); |
| 137 | |
| 138 | foreach ( $form_ids as $form_id ) { |
| 139 | if ( wp_delete_post( $form_id, true ) ) { |
| 140 | ++$count; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | add_settings_error( |
| 145 | 'empty_trash', |
| 146 | 'empty_trash', |
| 147 | /* translators: %d: number of forms */ |
| 148 | sprintf( _n( '%d form permanently deleted.', '%d forms permanently deleted.', $count, 'everest-forms' ), $count ), |
| 149 | 'updated' |
| 150 | ); |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Duplicate form. |
| 155 | */ |
| 156 | private function duplicate_form() { |
| 157 | if ( empty( $_REQUEST['form_id'] ) ) { |
| 158 | wp_die( esc_html__( 'No form to duplicate has been supplied!', 'everest-forms' ) ); |
| 159 | } |
| 160 | |
| 161 | $form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : ''; |
| 162 | |
| 163 | check_admin_referer( 'everest-forms-duplicate-form_' . $form_id ); |
| 164 | |
| 165 | $duplicate_id = evf()->form->duplicate( $form_id ); |
| 166 | |
| 167 | // Redirect to the edit screen for the new form page. |
| 168 | wp_safe_redirect( admin_url( 'admin.php?page=evf-builder&tab=fields&form_id=' . $duplicate_id ) ); |
| 169 | exit; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Remove entry and its associated meta. |
| 174 | * |
| 175 | * When form is deleted then it also deletes its entries meta. |
| 176 | * |
| 177 | * @param int $postid Post ID. |
| 178 | */ |
| 179 | public function delete_entries( $postid ) { |
| 180 | global $wpdb; |
| 181 | |
| 182 | $entries = evf_get_entries_ids( $postid ); |
| 183 | |
| 184 | // Delete entry. |
| 185 | if ( ! empty( $entries ) ) { |
| 186 | foreach ( $entries as $entry_id ) { |
| 187 | $wpdb->delete( $wpdb->prefix . 'evf_entries', array( 'entry_id' => $entry_id ), array( '%d' ) ); |
| 188 | $wpdb->delete( $wpdb->prefix . 'evf_entrymeta', array( 'entry_id' => $entry_id ), array( '%d' ) ); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Untrash form status. |
| 195 | * |
| 196 | * @since 1.7.5 |
| 197 | * |
| 198 | * @param string $new_status The new status of the post being restored. |
| 199 | * @param int $post_id The ID of the post being restored. |
| 200 | * @return string |
| 201 | */ |
| 202 | public function untrash_form_status( $new_status, $post_id ) { |
| 203 | return current_user_can( 'everest_forms_edit_forms', $post_id ) ? 'publish' : $new_status; |
| 204 | } |
| 205 | /** |
| 206 | * Remove the post from form migrator import tracker. |
| 207 | * |
| 208 | * @param [int] $form_id The form ID. |
| 209 | * @param [string] $previous_status The previous status. |
| 210 | * @since 2.0.8 |
| 211 | */ |
| 212 | public function remove_post_from_import_tracker( $form_id, $previous_status = '' ) { |
| 213 | $form = evf()->form->get( |
| 214 | absint( $form_id ), |
| 215 | array( |
| 216 | 'content_only' => true, |
| 217 | ) |
| 218 | ); |
| 219 | |
| 220 | if ( empty( $form ) ) { |
| 221 | return; |
| 222 | } |
| 223 | $imported_from = get_post_meta( $form_id, 'evf_fm_imported_from' ); |
| 224 | |
| 225 | if ( empty( $imported_from ) ) { |
| 226 | return; |
| 227 | } |
| 228 | if ( ! isset( $imported_from[0]['form_from'] ) || ! isset( $imported_from[0]['form_from'] ) ) { |
| 229 | return; |
| 230 | } |
| 231 | $form_slug = $imported_from[0]['form_from']; |
| 232 | $imported_from_form_id = $imported_from[0]['form_id']; |
| 233 | $imported_form_list = get_option( 'evf_fm_' . $form_slug . '_imported_form_list', array() ); |
| 234 | |
| 235 | $is_form_imported = array_search( $imported_from_form_id, $imported_form_list ); |
| 236 | |
| 237 | if ( ! $is_form_imported ) { |
| 238 | return; |
| 239 | } |
| 240 | |
| 241 | unset( $imported_form_list[ $is_form_imported ] ); |
| 242 | update_option( 'evf_fm_' . $form_slug . '_imported_form_list', $imported_form_list ); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | new EVF_Admin_Forms(); |
| 247 |