builder
6 years ago
plugin-updates
8 years ago
settings
6 years ago
views
6 years ago
class-evf-admin-addons.php
6 years ago
class-evf-admin-assets.php
6 years ago
class-evf-admin-builder.php
8 years ago
class-evf-admin-editor.php
6 years ago
class-evf-admin-entries-table-list.php
6 years ago
class-evf-admin-entries.php
6 years ago
class-evf-admin-forms-table-list.php
6 years ago
class-evf-admin-forms.php
6 years ago
class-evf-admin-import-export.php
6 years ago
class-evf-admin-menus.php
6 years ago
class-evf-admin-notices.php
6 years ago
class-evf-admin-settings.php
6 years ago
class-evf-admin-tools.php
6 years ago
class-evf-admin-welcome.php
6 years ago
class-evf-admin.php
6 years ago
evf-admin-functions.php
6 years ago
class-evf-admin-menus.php
309 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Setup menus in WP admin. |
| 4 | * |
| 5 | * @package EverestForms\Admin |
| 6 | * @version 1.2.0 |
| 7 | * @since 1.0.0 |
| 8 | */ |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | if ( class_exists( 'EVF_Admin_Menus', false ) ) { |
| 13 | return new EVF_Admin_Menus(); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * EVF_Admin_Menus Class. |
| 18 | */ |
| 19 | class EVF_Admin_Menus { |
| 20 | |
| 21 | /** |
| 22 | * Hook in tabs. |
| 23 | */ |
| 24 | public function __construct() { |
| 25 | // Add menus. |
| 26 | add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 ); |
| 27 | add_action( 'admin_menu', array( $this, 'builder_menu' ), 20 ); |
| 28 | add_action( 'admin_menu', array( $this, 'entries_menu' ), 30 ); |
| 29 | add_action( 'admin_menu', array( $this, 'settings_menu' ), 50 ); |
| 30 | add_action( 'admin_menu', array( $this, 'tools_menu' ), 60 ); |
| 31 | |
| 32 | if ( apply_filters( 'everest_forms_show_addons_page', true ) ) { |
| 33 | add_action( 'admin_menu', array( $this, 'addons_menu' ), 70 ); |
| 34 | } |
| 35 | |
| 36 | add_action( 'admin_head', array( $this, 'menu_highlight' ) ); |
| 37 | add_action( 'admin_head', array( $this, 'custom_menu_count' ) ); |
| 38 | add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) ); |
| 39 | add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 11, 3 ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Returns a base64 URL for the SVG for use in the menu. |
| 44 | * |
| 45 | * @param bool $base64 Whether or not to return base64-encoded SVG. |
| 46 | * @return string |
| 47 | */ |
| 48 | private function get_icon_svg( $base64 = true ) { |
| 49 | $svg = '<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>'; |
| 50 | |
| 51 | if ( $base64 ) { |
| 52 | return 'data:image/svg+xml;base64,' . base64_encode( $svg ); |
| 53 | } |
| 54 | |
| 55 | return $svg; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Add menu items. |
| 60 | */ |
| 61 | public function admin_menu() { |
| 62 | add_menu_page( esc_html__( 'Everest Forms', 'everest-forms' ), esc_html__( 'Everest Forms', 'everest-forms' ), 'manage_everest_forms', 'everest-forms', null, $this->get_icon_svg(), '55.5' ); |
| 63 | |
| 64 | // Backward compatibility for builder page redirects. |
| 65 | if ( ! empty( $_GET['page'] ) && in_array( wp_unslash( $_GET['page'] ), array( 'everest-forms', 'edit-evf-form', 'evf-status' ), true ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 66 | if ( 'edit-evf-form' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 67 | $redirect_url = admin_url( 'admin.php?page=evf-builder&create-form=1' ); |
| 68 | |
| 69 | if ( isset( $_GET['tab'], $_GET['form_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 70 | $redirect_url = add_query_arg( |
| 71 | array( |
| 72 | 'tab' => evf_clean( wp_unslash( $_GET['tab'] ) ), // phpcs:ignore WordPress.Security.NonceVerification |
| 73 | 'form_id' => absint( wp_unslash( $_GET['form_id'] ) ), // phpcs:ignore WordPress.Security.NonceVerification |
| 74 | ), |
| 75 | admin_url( 'admin.php?page=evf-builder' ) |
| 76 | ); |
| 77 | } |
| 78 | } elseif ( 'evf-status' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 79 | $redirect_url = str_replace( sanitize_text_field( wp_unslash( $_GET['page'] ) ), 'evf-tools', wp_unslash( $_SERVER['REQUEST_URI'] ) ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
| 80 | } else { |
| 81 | $redirect_url = str_replace( sanitize_text_field( wp_unslash( $_GET['page'] ) ), 'evf-builder', wp_unslash( $_SERVER['REQUEST_URI'] ) ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.InputNotValidated |
| 82 | } |
| 83 | |
| 84 | wp_safe_redirect( $redirect_url ); |
| 85 | exit; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Add menu items. |
| 91 | */ |
| 92 | public function builder_menu() { |
| 93 | $builder_page = add_submenu_page( 'everest-forms', esc_html__( 'Everest Forms Builder', 'everest-forms' ), esc_html__( 'All Forms', 'everest-forms' ), 'manage_everest_forms', 'evf-builder', array( $this, 'builder_page' ) ); |
| 94 | |
| 95 | add_submenu_page( 'everest-forms', esc_html__( 'Everest Forms Setup', 'everest-forms' ), esc_html__( 'Add New', 'everest-forms' ), 'manage_everest_forms', 'evf-builder&create-form=1', array( $this, 'builder_page' ) ); |
| 96 | |
| 97 | add_action( 'load-' . $builder_page, array( $this, 'builder_page_init' ) ); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Loads builder page. |
| 102 | */ |
| 103 | public function builder_page_init() { |
| 104 | global $current_tab, $forms_table_list; |
| 105 | |
| 106 | evf()->form_fields(); |
| 107 | |
| 108 | // Include builder pages. |
| 109 | EVF_Admin_Builder::get_builder_pages(); |
| 110 | |
| 111 | // Get current tab/section. |
| 112 | $current_tab = empty( $_GET['tab'] ) ? 'fields' : sanitize_title( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 113 | |
| 114 | if ( ! isset( $_GET['tab'], $_GET['form_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 115 | $forms_table_list = new EVF_Admin_Forms_Table_List(); |
| 116 | |
| 117 | // Add screen option. |
| 118 | add_screen_option( |
| 119 | 'per_page', |
| 120 | array( |
| 121 | 'default' => 20, |
| 122 | 'option' => 'evf_forms_per_page', |
| 123 | ) |
| 124 | ); |
| 125 | } |
| 126 | |
| 127 | do_action( 'everest_forms_builder_page_init' ); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Add menu item. |
| 132 | */ |
| 133 | public function entries_menu() { |
| 134 | $entries_page = add_submenu_page( 'everest-forms', esc_html__( 'Everest Forms Entries', 'everest-forms' ), esc_html__( 'Entries', 'everest-forms' ), 'manage_everest_forms', 'evf-entries', array( $this, 'entries_page' ) ); |
| 135 | |
| 136 | add_action( 'load-' . $entries_page, array( $this, 'entries_page_init' ) ); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Loads entries into memory. |
| 141 | */ |
| 142 | public function entries_page_init() { |
| 143 | global $entries_table_list; |
| 144 | |
| 145 | if ( ! isset( $_GET['view-entry'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 146 | $entries_table_list = new EVF_Admin_Entries_Table_List(); |
| 147 | |
| 148 | // Add screen option. |
| 149 | add_screen_option( |
| 150 | 'per_page', |
| 151 | array( |
| 152 | 'default' => 20, |
| 153 | 'option' => 'evf_entries_per_page', |
| 154 | ) |
| 155 | ); |
| 156 | } |
| 157 | |
| 158 | do_action( 'everest_forms_entries_page_init' ); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Add menu item. |
| 163 | */ |
| 164 | public function settings_menu() { |
| 165 | $settings_page = add_submenu_page( 'everest-forms', esc_html__( 'Everest Forms settings', 'everest-forms' ), esc_html__( 'Settings', 'everest-forms' ), 'manage_everest_forms', 'evf-settings', array( $this, 'settings_page' ) ); |
| 166 | |
| 167 | add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) ); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Loads settings page. |
| 172 | */ |
| 173 | public function settings_page_init() { |
| 174 | global $current_tab, $current_section; |
| 175 | |
| 176 | // Include settings pages. |
| 177 | EVF_Admin_Settings::get_settings_pages(); |
| 178 | |
| 179 | // Get current tab/section. |
| 180 | $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 181 | $current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( wp_unslash( $_REQUEST['section'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 182 | |
| 183 | // Save settings if data has been posted. |
| 184 | if ( apply_filters( '' !== $current_section ? "everest_forms_save_settings_{$current_tab}_{$current_section}" : "everest_forms_save_settings_{$current_tab}", ! empty( $_POST ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 185 | EVF_Admin_Settings::save(); |
| 186 | } |
| 187 | |
| 188 | // Add any posted messages. |
| 189 | if ( ! empty( $_GET['evf_error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 190 | EVF_Admin_Settings::add_error( wp_kses_post( wp_unslash( $_GET['evf_error'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 191 | } |
| 192 | |
| 193 | if ( ! empty( $_GET['evf_message'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 194 | EVF_Admin_Settings::add_message( wp_kses_post( wp_unslash( $_GET['evf_message'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 195 | } |
| 196 | |
| 197 | do_action( 'everest_forms_settings_page_init' ); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Add menu item. |
| 202 | */ |
| 203 | public function tools_menu() { |
| 204 | add_submenu_page( 'everest-forms', esc_html__( 'Everest Forms tools', 'everest-forms' ), esc_html__( 'Tools', 'everest-forms' ), 'manage_everest_forms', 'evf-tools', array( $this, 'tools_page' ) ); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Addons menu item. |
| 209 | */ |
| 210 | public function addons_menu() { |
| 211 | add_submenu_page( 'everest-forms', esc_html__( 'Everest Forms Add-ons', 'everest-forms' ), esc_html__( 'Add-ons', 'everest-forms' ), 'manage_everest_forms', 'evf-addons', array( $this, 'addons_page' ) ); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Highlights the correct top level admin menu item. |
| 216 | */ |
| 217 | public function menu_highlight() { |
| 218 | global $parent_file, $submenu_file; |
| 219 | |
| 220 | $screen = get_current_screen(); |
| 221 | $screen_id = $screen ? $screen->id : ''; |
| 222 | |
| 223 | // Check to make sure we're on a EverestForms builder setup page. |
| 224 | if ( isset( $_GET['create-form'] ) && in_array( $screen_id, array( 'everest-forms_page_evf-builder' ), true ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 225 | $parent_file = 'everest-forms'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride |
| 226 | $submenu_file = 'evf-builder&create-form=1'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Adds the custom count to the menu. |
| 232 | */ |
| 233 | public function custom_menu_count() { |
| 234 | global $submenu; |
| 235 | |
| 236 | if ( isset( $submenu['everest-forms'] ) ) { |
| 237 | // Remove 'Everest Forms' sub menu item. |
| 238 | unset( $submenu['everest-forms'][0] ); |
| 239 | |
| 240 | // Add count if user has access. |
| 241 | if ( apply_filters( 'everest_forms_include_count_in_menu', true ) && current_user_can( 'manage_everest_forms' ) ) { |
| 242 | do_action( 'everest_forms_custom_menu_count', $submenu ); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Custom menu order. |
| 249 | * |
| 250 | * @param bool $enabled Whether custom menu ordering is already enabled. |
| 251 | * @return bool |
| 252 | */ |
| 253 | public function custom_menu_order( $enabled ) { |
| 254 | return $enabled || current_user_can( 'manage_everest_forms' ); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Validate screen options on update. |
| 259 | * |
| 260 | * @param bool|int $status Screen option value. Default false to skip. |
| 261 | * @param string $option The option name. |
| 262 | * @param int $value The number of rows to use. |
| 263 | */ |
| 264 | public function set_screen_option( $status, $option, $value ) { |
| 265 | if ( in_array( $option, array( 'evf_forms_per_page', 'evf_entries_per_page' ), true ) ) { |
| 266 | return $value; |
| 267 | } |
| 268 | |
| 269 | return $status; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Init the settings page. |
| 274 | */ |
| 275 | public function builder_page() { |
| 276 | EVF_Admin_Forms::page_output(); |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Init the entries page. |
| 281 | */ |
| 282 | public function entries_page() { |
| 283 | EVF_Admin_Entries::page_output(); |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Init the settings page. |
| 288 | */ |
| 289 | public function settings_page() { |
| 290 | EVF_Admin_Settings::output(); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Init the status page. |
| 295 | */ |
| 296 | public function tools_page() { |
| 297 | EVF_Admin_Tools::output(); |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Init the addons page. |
| 302 | */ |
| 303 | public function addons_page() { |
| 304 | EVF_Admin_Addons::output(); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | return new EVF_Admin_Menus(); |
| 309 |