wpforms-lite.php
1166 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WPForms_Lite class file. |
| 4 | */ |
| 5 | |
| 6 | // phpcs:disable Generic.Commenting.DocComment.MissingShort |
| 7 | /** @noinspection PhpIllegalPsrClassPathInspection */ |
| 8 | /** @noinspection AutoloadingIssuesInspection */ |
| 9 | // phpcs:enable Generic.Commenting.DocComment.MissingShort |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | use WPForms\Admin\Builder\TemplatesCache; |
| 16 | use WPForms\Db\Payments\Meta as PaymentsMeta; |
| 17 | use WPForms\Db\Payments\Payment; |
| 18 | use WPForms\Lite\Integrations\LiteConnect\Integration as LiteConnectIntegration; |
| 19 | use WPForms\Lite\Integrations\LiteConnect\LiteConnect; |
| 20 | use WPForms\Logger\Repository; |
| 21 | use WPForms\Tasks\Meta as TasksMeta; |
| 22 | |
| 23 | /** |
| 24 | * WPForms Lite. Load Lite-specific features/functionality. |
| 25 | * |
| 26 | * @since 1.2.0 |
| 27 | */ |
| 28 | class WPForms_Lite { |
| 29 | |
| 30 | /** |
| 31 | * Custom tables and their handlers. |
| 32 | * |
| 33 | * @since 1.9.0 |
| 34 | */ |
| 35 | public const CUSTOM_TABLES = [ |
| 36 | 'wpforms_payments' => Payment::class, |
| 37 | 'wpforms_payment_meta' => PaymentsMeta::class, |
| 38 | 'wpforms_tasks_meta' => TasksMeta::class, |
| 39 | 'wpforms_logs' => Repository::class, |
| 40 | ]; |
| 41 | |
| 42 | /** |
| 43 | * Primary class constructor. |
| 44 | * |
| 45 | * @since 1.2.2 |
| 46 | */ |
| 47 | public function __construct() { |
| 48 | |
| 49 | $this->hooks(); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Register hooks. |
| 54 | * |
| 55 | * @since 1.8.9 |
| 56 | */ |
| 57 | private function hooks() { |
| 58 | |
| 59 | add_action( 'wpforms_install', [ $this, 'install' ] ); |
| 60 | add_action( 'wpforms_form_settings_notifications', [ $this, 'form_settings_notifications' ], 8 ); |
| 61 | add_action( 'wpforms_form_settings_confirmations', [ $this, 'form_settings_confirmations' ] ); |
| 62 | add_action( 'wpforms_builder_enqueues_before', [ $this, 'builder_enqueues' ] ); |
| 63 | add_action( 'wpforms_admin_page', [ $this, 'entries_page' ] ); |
| 64 | add_action( 'wpforms_admin_settings_after', [ $this, 'settings_cta' ] ); |
| 65 | add_action( 'wp_ajax_wpforms_lite_settings_upgrade', [ $this, 'settings_cta_dismiss' ] ); |
| 66 | add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueues' ] ); |
| 67 | add_filter( 'wpforms_helpers_templates_get_theme_template_paths', [ $this, 'add_templates' ] ); |
| 68 | |
| 69 | // Entries count logging for WPForms Lite. |
| 70 | add_action( 'wpforms_process_entry_saved', [ $this, 'entry_submit' ], 10, 5 ); |
| 71 | add_action( 'wpforms_process_entry_saved', [ $this, 'update_entry_count' ], 10, 5 ); |
| 72 | |
| 73 | // Upgrade to Pro WPForms menu bar item. |
| 74 | add_action( 'admin_bar_menu', [ $this, 'upgrade_to_pro_menu' ], 1000 ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Form notification settings, supports multiple notifications. |
| 79 | * |
| 80 | * @since 1.2.3 |
| 81 | * |
| 82 | * @param object $settings Settings. |
| 83 | * |
| 84 | * @noinspection HtmlUnknownTarget |
| 85 | */ |
| 86 | public function form_settings_notifications( $settings ) { |
| 87 | |
| 88 | $cc = wpforms_setting( 'email-carbon-copy' ); |
| 89 | $from_email = '{admin_email}'; |
| 90 | $from_name = sanitize_text_field( get_option( 'blogname' ) ); |
| 91 | |
| 92 | // phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName |
| 93 | /** |
| 94 | * Allow filtering of text after the `From Name` field. |
| 95 | * |
| 96 | * @since 1.2.3 |
| 97 | * @since 1.7.6 Added $form_data and $id arguments. |
| 98 | * |
| 99 | * @param string $value Value to be filtered. |
| 100 | * @param array $form_data Form data. |
| 101 | * @param int $id Notification ID. |
| 102 | */ |
| 103 | $from_name_after = apply_filters( 'wpforms_builder_notifications_from_name_after', '', $settings->form_data, 1 ); |
| 104 | |
| 105 | /** |
| 106 | * Allow filtering of a text after the `From Email` field. |
| 107 | * |
| 108 | * @since 1.2.3 |
| 109 | * @since 1.7.6 Added $form_data and $id arguments. |
| 110 | * |
| 111 | * @param array $value Value to be filtered. |
| 112 | * @param array $form_data Form data. |
| 113 | * @param int $id Notification ID. |
| 114 | */ |
| 115 | $from_email_after = apply_filters( 'wpforms_builder_notifications_from_email_after', '', $settings->form_data, 1 ); |
| 116 | // phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName |
| 117 | |
| 118 | // Handle backwards compatibility. |
| 119 | if ( empty( $settings->form_data['settings']['notifications'] ) ) { |
| 120 | $settings->form_data['settings']['notifications'][1]['subject'] = ! empty( $settings->form_data['settings']['notification_subject'] ) ? |
| 121 | $settings->form_data['settings']['notification_subject'] : |
| 122 | sprintf( /* translators: %s - form name. */ |
| 123 | esc_html__( 'New %s Entry', 'wpforms-lite' ), |
| 124 | $settings->form->post_title |
| 125 | ); |
| 126 | $settings->form_data['settings']['notifications'][1]['email'] = ! empty( $settings->form_data['settings']['notification_email'] ) ? $settings->form_data['settings']['notification_email'] : '{admin_email}'; |
| 127 | $settings->form_data['settings']['notifications'][1]['sender_name'] = ! empty( $settings->form_data['settings']['notification_fromname'] ) ? $settings->form_data['settings']['notification_fromname'] : $from_name; |
| 128 | $settings->form_data['settings']['notifications'][1]['sender_address'] = ! empty( $settings->form_data['settings']['notification_fromaddress'] ) ? $settings->form_data['settings']['notification_fromaddress'] : $from_email; |
| 129 | $settings->form_data['settings']['notifications'][1]['replyto'] = ! empty( $settings->form_data['settings']['notification_replyto'] ) ? $settings->form_data['settings']['notification_replyto'] : ''; |
| 130 | } |
| 131 | |
| 132 | $id = 1; |
| 133 | |
| 134 | echo '<div class="wpforms-panel-content-section-title">'; |
| 135 | echo '<span id="wpforms-builder-settings-notifications-title">'; |
| 136 | esc_html_e( 'Notifications', 'wpforms-lite' ); |
| 137 | echo '</span>'; |
| 138 | echo '<button class="wpforms-builder-settings-block-add education-modal" |
| 139 | data-utm-content="Multiple notifications" |
| 140 | data-name="' . esc_attr__( 'Multiple notifications', 'wpforms-lite' ) . '">'; |
| 141 | esc_html_e( 'Add New Notification', 'wpforms-lite' ); |
| 142 | echo '</button>'; |
| 143 | echo '</div>'; |
| 144 | |
| 145 | $dismissed = get_user_meta( get_current_user_id(), 'wpforms_dismissed', true ); |
| 146 | |
| 147 | if ( empty( $dismissed['edu-builder-notifications-description'] ) ) { |
| 148 | echo '<div class="wpforms-panel-content-section-description wpforms-dismiss-container wpforms-dismiss-out">'; |
| 149 | echo '<button type="button" class="wpforms-dismiss-button" title="' . esc_attr__( 'Dismiss this message.', 'wpforms-lite' ) . '" data-section="builder-notifications-description"></button>'; |
| 150 | echo '<p>'; |
| 151 | printf( |
| 152 | wp_kses( /* translators: %s - link to the WPForms.com doc article. */ |
| 153 | __( 'Notifications are emails sent when a form is submitted. By default, these emails include entry details. For setup and customization options, including a video overview, please <a href="%s" target="_blank" rel="noopener noreferrer">see our tutorial</a>.', 'wpforms-lite' ), |
| 154 | [ |
| 155 | 'a' => [ |
| 156 | 'href' => [], |
| 157 | 'rel' => [], |
| 158 | 'target' => [], |
| 159 | ], |
| 160 | ] |
| 161 | ), |
| 162 | esc_url( wpforms_utm_link( 'https://wpforms.com/docs/setup-form-notification-wpforms/', 'Builder Notifications', 'Form Notifications Documentation' ) ) |
| 163 | ); |
| 164 | echo '</p>'; |
| 165 | echo '<p>'; |
| 166 | printf( |
| 167 | wp_kses( /* translators: 1$s, %2$s - links to the WPForms.com doc articles. */ |
| 168 | __( 'After saving these settings, be sure to <a href="%1$s" target="_blank" rel="noopener noreferrer">test a form submission</a>. This lets you see how emails will look, and to ensure that they <a href="%2$s" target="_blank" rel="noopener noreferrer">are delivered successfully</a>.', 'wpforms-lite' ), |
| 169 | [ |
| 170 | 'a' => [ |
| 171 | 'href' => [], |
| 172 | 'rel' => [], |
| 173 | 'target' => [], |
| 174 | ], |
| 175 | 'br' => [], |
| 176 | ] |
| 177 | ), |
| 178 | esc_url( wpforms_utm_link( 'https://wpforms.com/docs/how-to-properly-test-your-wordpress-forms-before-launching-checklist/', 'Builder Notifications', 'Testing A Form Documentation' ) ), |
| 179 | esc_url( wpforms_utm_link( 'https://wpforms.com/docs/troubleshooting-email-notifications/', 'Builder Notifications', 'Troubleshoot Notifications Documentation' ) ) |
| 180 | ); |
| 181 | echo '</p>'; |
| 182 | echo '</div>'; |
| 183 | } |
| 184 | |
| 185 | wpforms_panel_field( |
| 186 | 'toggle', |
| 187 | 'settings', |
| 188 | 'notification_enable', |
| 189 | $settings->form_data, |
| 190 | esc_html__( 'Enable Notifications', 'wpforms-lite' ) |
| 191 | ); |
| 192 | ?> |
| 193 | |
| 194 | <div class="wpforms-notification wpforms-builder-settings-block"> |
| 195 | |
| 196 | <div class="wpforms-builder-settings-block-header"> |
| 197 | <span><?php esc_html_e( 'Default Notification', 'wpforms-lite' ); ?></span> |
| 198 | </div> |
| 199 | |
| 200 | <div class="wpforms-builder-settings-block-content"> |
| 201 | |
| 202 | <?php |
| 203 | wpforms_panel_field( |
| 204 | 'text', |
| 205 | 'notifications', |
| 206 | 'email', |
| 207 | $settings->form_data, |
| 208 | esc_html__( 'Send To Email Address', 'wpforms-lite' ), |
| 209 | [ |
| 210 | 'default' => '{admin_email}', |
| 211 | 'tooltip' => esc_html__( 'Enter the email address to receive form entry notifications. For multiple notifications, separate email addresses with a comma.', 'wpforms-lite' ), |
| 212 | 'smarttags' => [ |
| 213 | 'type' => 'all', |
| 214 | 'fields' => 'email', |
| 215 | 'allowed' => 'admin_email,user_email', |
| 216 | ], |
| 217 | 'parent' => 'settings', |
| 218 | 'subsection' => $id, |
| 219 | 'class' => 'email-recipient', |
| 220 | 'input_class' => 'wpforms-smart-tags-enabled', |
| 221 | ] |
| 222 | ); |
| 223 | if ( $cc ) : |
| 224 | wpforms_panel_field( |
| 225 | 'text', |
| 226 | 'notifications', |
| 227 | 'carboncopy', |
| 228 | $settings->form_data, |
| 229 | esc_html__( 'CC', 'wpforms-lite' ), |
| 230 | [ |
| 231 | 'smarttags' => [ |
| 232 | 'type' => 'all', |
| 233 | 'fields' => 'email', |
| 234 | 'allowed' => 'admin_email,user_email', |
| 235 | ], |
| 236 | 'parent' => 'settings', |
| 237 | 'subsection' => $id, |
| 238 | 'input_class' => 'wpforms-smart-tags-enabled', |
| 239 | ] |
| 240 | ); |
| 241 | endif; |
| 242 | wpforms_panel_field( |
| 243 | 'text', |
| 244 | 'notifications', |
| 245 | 'subject', |
| 246 | $settings->form_data, |
| 247 | esc_html__( 'Email Subject Line', 'wpforms-lite' ), |
| 248 | [ |
| 249 | 'default' => sprintf( /* translators: %s - form name. */ |
| 250 | esc_html__( 'New Entry: %s', 'wpforms-lite' ), |
| 251 | $settings->form->post_title |
| 252 | ), |
| 253 | 'smarttags' => [ |
| 254 | 'type' => 'all', |
| 255 | ], |
| 256 | 'parent' => 'settings', |
| 257 | 'subsection' => $id, |
| 258 | 'input_class' => 'wpforms-smart-tags-enabled', |
| 259 | ] |
| 260 | ); |
| 261 | wpforms_panel_field( |
| 262 | 'text', |
| 263 | 'notifications', |
| 264 | 'sender_name', |
| 265 | $settings->form_data, |
| 266 | esc_html__( 'From Name', 'wpforms-lite' ), |
| 267 | // phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName |
| 268 | /** |
| 269 | * Allow modifying the "From Name" field settings in the builder on Settings > Notifications panel. |
| 270 | * |
| 271 | * @since 1.7.6 |
| 272 | * |
| 273 | * @param array $args Field settings. |
| 274 | * @param array $form_data Form data. |
| 275 | * @param int $id Notification ID. |
| 276 | */ |
| 277 | apply_filters( |
| 278 | 'wpforms_builder_notifications_sender_name_settings', |
| 279 | [ |
| 280 | 'default' => $from_name, |
| 281 | 'smarttags' => [ |
| 282 | 'type' => 'fields', |
| 283 | 'fields' => 'name,text', |
| 284 | ], |
| 285 | 'parent' => 'settings', |
| 286 | 'subsection' => $id, |
| 287 | 'input_class' => 'wpforms-smart-tags-enabled', |
| 288 | ], |
| 289 | $settings->form_data, |
| 290 | $id |
| 291 | ) |
| 292 | // phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName |
| 293 | ); |
| 294 | wpforms_panel_field( |
| 295 | 'text', |
| 296 | 'notifications', |
| 297 | 'sender_address', |
| 298 | $settings->form_data, |
| 299 | esc_html__( 'From Email', 'wpforms-lite' ), |
| 300 | // phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName |
| 301 | /** |
| 302 | * Allow modifying the "From Email" field settings in the builder on the Settings > Notifications panel. |
| 303 | * |
| 304 | * @since 1.7.6 |
| 305 | * |
| 306 | * @param array $args Field settings. |
| 307 | * @param array $form_data Form data. |
| 308 | * @param int $id Notification ID. |
| 309 | */ |
| 310 | apply_filters( |
| 311 | 'wpforms_builder_notifications_sender_address_settings', |
| 312 | [ |
| 313 | 'default' => $from_email, |
| 314 | 'smarttags' => [ |
| 315 | 'type' => 'all', |
| 316 | 'fields' => 'email', |
| 317 | 'allowed' => 'admin_email,user_email', |
| 318 | ], |
| 319 | 'parent' => 'settings', |
| 320 | 'subsection' => $id, |
| 321 | 'input_class' => 'wpforms-smart-tags-enabled', |
| 322 | ], |
| 323 | $settings->form_data, |
| 324 | $id |
| 325 | ) |
| 326 | // phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName |
| 327 | ); |
| 328 | wpforms_panel_field( |
| 329 | 'text', |
| 330 | 'notifications', |
| 331 | 'replyto', |
| 332 | $settings->form_data, |
| 333 | esc_html__( 'Reply-To', 'wpforms-lite' ), |
| 334 | [ |
| 335 | 'tooltip' => esc_html( |
| 336 | sprintf( /* translators: %s - <email@example.com>. */ |
| 337 | __( 'Enter the email address or email address with recipient\'s name in "First Last %s" format.', 'wpforms-lite' ), |
| 338 | // ​ is a zero-width space character. Without it, Tooltipster thinks it's an HTML tag |
| 339 | // and closes it at the end of the string, hiding everything after this value. |
| 340 | '<​email@example.com​>' |
| 341 | ) |
| 342 | ), |
| 343 | 'smarttags' => [ |
| 344 | 'type' => 'all', |
| 345 | 'fields' => 'email,name', |
| 346 | 'allowed' => 'admin_email,user_email', |
| 347 | ], |
| 348 | 'parent' => 'settings', |
| 349 | 'subsection' => $id, |
| 350 | 'input_class' => 'wpforms-smart-tags-enabled', |
| 351 | ] |
| 352 | ); |
| 353 | wpforms_panel_field( |
| 354 | 'textarea', |
| 355 | 'notifications', |
| 356 | 'message', |
| 357 | $settings->form_data, |
| 358 | esc_html__( 'Email Message', 'wpforms-lite' ), |
| 359 | [ |
| 360 | 'rows' => 6, |
| 361 | 'default' => '{all_fields}', |
| 362 | 'smarttags' => [ |
| 363 | 'type' => 'all', |
| 364 | ], |
| 365 | 'parent' => 'settings', |
| 366 | 'subsection' => $id, |
| 367 | 'class' => 'email-msg', |
| 368 | 'input_class' => 'wpforms-smart-tags-enabled', |
| 369 | 'after' => '<p class="note">' . |
| 370 | sprintf( |
| 371 | /* translators: %s - {all_fields} Smart Tag. */ |
| 372 | esc_html__( 'To display all form fields, use the %s Smart Tag.', 'wpforms-lite' ), |
| 373 | '<code>{all_fields}</code>' |
| 374 | ) . |
| 375 | '</p>', |
| 376 | ] |
| 377 | ); |
| 378 | |
| 379 | /** |
| 380 | * Fires after notification block content on the lite version. |
| 381 | * |
| 382 | * @since 1.7.7 |
| 383 | * |
| 384 | * @param array $settings Current confirmation data. |
| 385 | * @param int $id Notification id. |
| 386 | */ |
| 387 | do_action( 'wpforms_lite_form_settings_notifications_block_content_after', $settings, $id ); |
| 388 | ?> |
| 389 | </div> |
| 390 | </div> |
| 391 | |
| 392 | <?php |
| 393 | /** |
| 394 | * Fires after settings notification block. |
| 395 | * |
| 396 | * @since 1.5.8 |
| 397 | * |
| 398 | * @param string $type Settings block type. |
| 399 | * @param array $settings Settings. |
| 400 | */ |
| 401 | do_action( 'wpforms_builder_settings_notifications_after', 'notifications', $settings ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName |
| 402 | |
| 403 | // phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName |
| 404 | |
| 405 | /** |
| 406 | * Fires after notification block. |
| 407 | * |
| 408 | * @since 1.7.6 |
| 409 | * |
| 410 | * @param array $settings Current confirmation data. |
| 411 | * @param int $id Notification id. |
| 412 | */ |
| 413 | do_action( 'wpforms_form_settings_notifications_single_after', $settings, 1 ); |
| 414 | |
| 415 | // phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * Lite admin scripts and styles. |
| 420 | * |
| 421 | * @since 1.5.7 |
| 422 | */ |
| 423 | public function admin_enqueues() { |
| 424 | |
| 425 | if ( ! wpforms_is_admin_page() ) { |
| 426 | return; |
| 427 | } |
| 428 | |
| 429 | $min = wpforms_get_min_suffix(); |
| 430 | |
| 431 | // Admin styles. |
| 432 | wp_enqueue_style( |
| 433 | 'wpforms-lite-admin', |
| 434 | WPFORMS_PLUGIN_URL . "assets/lite/css/admin{$min}.css", |
| 435 | [], |
| 436 | WPFORMS_VERSION |
| 437 | ); |
| 438 | |
| 439 | // Entries assets. |
| 440 | wp_register_style( |
| 441 | 'wpforms-admin-entry-list', |
| 442 | WPFORMS_PLUGIN_URL . "assets/lite/css/admin/entries/entry-list{$min}.css", |
| 443 | [], |
| 444 | WPFORMS_VERSION |
| 445 | ); |
| 446 | |
| 447 | wp_register_script( |
| 448 | 'wpforms-admin-entry-list', |
| 449 | WPFORMS_PLUGIN_URL . "assets/lite/js/admin/entries/entry-list{$min}.js", |
| 450 | [ 'jquery' ], |
| 451 | WPFORMS_VERSION, |
| 452 | true |
| 453 | ); |
| 454 | |
| 455 | wp_register_style( |
| 456 | 'wpforms-admin-view-entry', |
| 457 | WPFORMS_PLUGIN_URL . "assets/lite/css/admin/entries/view-entry{$min}.css", |
| 458 | [], |
| 459 | WPFORMS_VERSION |
| 460 | ); |
| 461 | |
| 462 | wp_register_script( |
| 463 | 'wpforms-admin-view-entry', |
| 464 | WPFORMS_PLUGIN_URL . "assets/lite/js/admin/entries/view-entry{$min}.js", |
| 465 | [ 'jquery' ], |
| 466 | WPFORMS_VERSION, |
| 467 | true |
| 468 | ); |
| 469 | } |
| 470 | |
| 471 | /** |
| 472 | * Form confirmation settings, supports multiple confirmations. |
| 473 | * |
| 474 | * @since 1.4.8 |
| 475 | * |
| 476 | * @param WPForms_Builder_Panel_Settings $settings Builder panel settings. |
| 477 | */ |
| 478 | public function form_settings_confirmations( $settings ) { |
| 479 | |
| 480 | wp_enqueue_editor(); |
| 481 | |
| 482 | // Handle backwards compatibility. |
| 483 | if ( empty( $settings->form_data['settings']['confirmations'] ) ) { |
| 484 | $settings->form_data['settings']['confirmations'][1]['type'] = ! empty( $settings->form_data['settings']['confirmation_type'] ) ? $settings->form_data['settings']['confirmation_type'] : 'message'; |
| 485 | $settings->form_data['settings']['confirmations'][1]['message'] = ! empty( $settings->form_data['settings']['confirmation_message'] ) ? $settings->form_data['settings']['confirmation_message'] : esc_html__( 'Thanks for contacting us! We will be in touch with you shortly.', 'wpforms-lite' ); |
| 486 | $settings->form_data['settings']['confirmations'][1]['message_scroll'] = ! empty( $settings->form_data['settings']['confirmation_message_scroll'] ) ? $settings->form_data['settings']['confirmation_message_scroll'] : 1; |
| 487 | $settings->form_data['settings']['confirmations'][1]['page'] = ! empty( $settings->form_data['settings']['confirmation_page'] ) ? $settings->form_data['settings']['confirmation_page'] : ''; |
| 488 | $settings->form_data['settings']['confirmations'][1]['redirect'] = ! empty( $settings->form_data['settings']['confirmation_redirect'] ) ? $settings->form_data['settings']['confirmation_redirect'] : ''; |
| 489 | } |
| 490 | $field_id = 1; |
| 491 | |
| 492 | echo '<div class="wpforms-panel-content-section-title">'; |
| 493 | esc_html_e( 'Confirmations', 'wpforms-lite' ); |
| 494 | echo '<button class="wpforms-builder-settings-block-add education-modal" |
| 495 | data-utm-content="Multiple confirmations" |
| 496 | data-name="' . esc_attr__( 'Multiple confirmations', 'wpforms-lite' ) . '">'; |
| 497 | esc_html_e( 'Add New Confirmation', 'wpforms-lite' ); |
| 498 | echo '</button>'; |
| 499 | echo '</div>'; |
| 500 | ?> |
| 501 | |
| 502 | <div class="wpforms-confirmation wpforms-builder-settings-block"> |
| 503 | |
| 504 | <div class="wpforms-builder-settings-block-header"> |
| 505 | <span><?php esc_html_e( 'Default Confirmation', 'wpforms-lite' ); ?></span> |
| 506 | </div> |
| 507 | |
| 508 | <div class="wpforms-builder-settings-block-content"> |
| 509 | |
| 510 | <?php |
| 511 | /** |
| 512 | * Fires before each confirmation to add custom fields. |
| 513 | * |
| 514 | * @since 1.6.9 |
| 515 | * |
| 516 | * @param WPForms_Builder_Panel_Settings $settings Builder panel settings. |
| 517 | * @param int $field_id Field ID. |
| 518 | */ |
| 519 | do_action( 'wpforms_lite_form_settings_confirmations_single_before', $settings, $field_id ); |
| 520 | |
| 521 | wpforms_panel_field( |
| 522 | 'select', |
| 523 | 'confirmations', |
| 524 | 'type', |
| 525 | $settings->form_data, |
| 526 | esc_html__( 'Confirmation Type', 'wpforms-lite' ), |
| 527 | [ |
| 528 | 'default' => 'message', |
| 529 | 'options' => [ |
| 530 | 'message' => esc_html__( 'Message', 'wpforms-lite' ), |
| 531 | 'page' => esc_html__( 'Show Page', 'wpforms-lite' ), |
| 532 | 'redirect' => esc_html__( 'Go to URL (Redirect)', 'wpforms-lite' ), |
| 533 | ], |
| 534 | 'class' => 'wpforms-panel-field-confirmations-type-wrap', |
| 535 | 'input_class' => 'wpforms-panel-field-confirmations-type', |
| 536 | 'parent' => 'settings', |
| 537 | 'subsection' => $field_id, |
| 538 | ] |
| 539 | ); |
| 540 | wpforms_panel_field( |
| 541 | 'textarea', |
| 542 | 'confirmations', |
| 543 | 'message', |
| 544 | $settings->form_data, |
| 545 | esc_html__( 'Confirmation Message', 'wpforms-lite' ), |
| 546 | [ |
| 547 | 'default' => esc_html__( 'Thanks for contacting us! We will be in touch with you shortly.', 'wpforms-lite' ), |
| 548 | 'tinymce' => [ |
| 549 | 'editor_height' => '200', |
| 550 | ], |
| 551 | 'input_id' => 'wpforms-panel-field-confirmations-message-' . $field_id, |
| 552 | 'input_class' => 'wpforms-panel-field-confirmations-message', |
| 553 | 'parent' => 'settings', |
| 554 | 'subsection' => $field_id, |
| 555 | 'class' => 'wpforms-panel-field-tinymce', |
| 556 | 'smarttags' => [ |
| 557 | 'type' => 'all', |
| 558 | ], |
| 559 | ] |
| 560 | ); |
| 561 | wpforms_panel_field( |
| 562 | 'toggle', |
| 563 | 'confirmations', |
| 564 | 'message_scroll', |
| 565 | $settings->form_data, |
| 566 | esc_html__( 'Automatically scroll to the confirmation message', 'wpforms-lite' ), |
| 567 | [ |
| 568 | 'input_class' => 'wpforms-panel-field-confirmations-message_scroll', |
| 569 | 'parent' => 'settings', |
| 570 | 'subsection' => $field_id, |
| 571 | ] |
| 572 | ); |
| 573 | |
| 574 | wpforms_panel_field( |
| 575 | 'select', |
| 576 | 'confirmations', |
| 577 | 'page', |
| 578 | $settings->form_data, |
| 579 | esc_html__( 'Confirmation Page', 'wpforms-lite' ), |
| 580 | [ |
| 581 | 'class' => 'wpforms-panel-field-confirmations-page-choicesjs', |
| 582 | 'options' => wpforms_builder_form_settings_confirmation_get_pages( $settings->form_data, $field_id ), |
| 583 | 'input_class' => 'wpforms-panel-field-confirmations-page', |
| 584 | 'parent' => 'settings', |
| 585 | 'subsection' => $field_id, |
| 586 | 'choicesjs' => [ |
| 587 | 'use_ajax' => true, |
| 588 | 'callback_fn' => 'select_pages', |
| 589 | ], |
| 590 | ] |
| 591 | ); |
| 592 | |
| 593 | wpforms_panel_field( |
| 594 | 'text', |
| 595 | 'confirmations', |
| 596 | 'page_url_parameters', |
| 597 | $settings->form_data, |
| 598 | esc_html__( 'URL Parameters', 'wpforms-lite' ), |
| 599 | [ |
| 600 | 'input_id' => 'wpforms-panel-field-confirmations-page-url-parameters-' . $field_id, |
| 601 | 'input_class' => 'wpforms-panel-field-confirmations-page-url-parameters', |
| 602 | 'parent' => 'settings', |
| 603 | 'subsection' => $field_id, |
| 604 | 'tooltip' => esc_html__( 'Add query string parameters to append to the URL when the form is submitted. Separate multiple parameters with an ampersand (&).', 'wpforms-lite' ), |
| 605 | ] |
| 606 | ); |
| 607 | |
| 608 | wpforms_panel_field( |
| 609 | 'text', |
| 610 | 'confirmations', |
| 611 | 'redirect', |
| 612 | $settings->form_data, |
| 613 | esc_html__( 'Confirmation Redirect URL', 'wpforms-lite' ) . ' <span class="required">*</span>', |
| 614 | [ |
| 615 | 'input_class' => 'wpforms-panel-field-confirmations-redirect', |
| 616 | 'parent' => 'settings', |
| 617 | 'subsection' => $field_id, |
| 618 | ] |
| 619 | ); |
| 620 | |
| 621 | wpforms_panel_field( |
| 622 | 'toggle', |
| 623 | 'confirmations', |
| 624 | 'redirect_new_tab', |
| 625 | $settings->form_data, |
| 626 | esc_html__( 'Open confirmation in new tab', 'wpforms-lite' ), |
| 627 | [ |
| 628 | 'input_id' => 'wpforms-panel-field-confirmations-redirect_new_tab-' . $field_id, |
| 629 | 'input_class' => 'wpforms-panel-field-confirmations-redirect_new_tab', |
| 630 | 'parent' => 'settings', |
| 631 | 'subsection' => $field_id, |
| 632 | ] |
| 633 | ); |
| 634 | |
| 635 | /** |
| 636 | * Fires after each confirmation to add custom fields. |
| 637 | * |
| 638 | * @since 1.6.9 |
| 639 | * |
| 640 | * @param WPForms_Builder_Panel_Settings $settings Builder panel settings. |
| 641 | * @param int $field_id Field ID. |
| 642 | */ |
| 643 | do_action( 'wpforms_lite_form_settings_confirmations_single_after', $settings, $field_id ); |
| 644 | ?> |
| 645 | </div> |
| 646 | </div> |
| 647 | |
| 648 | <?php |
| 649 | /** |
| 650 | * Fires after builder settings confirmation block. |
| 651 | * |
| 652 | * @since 1.5.8 |
| 653 | * |
| 654 | * @param string $type Settings block type. |
| 655 | * @param array $settings Settings. |
| 656 | */ |
| 657 | do_action( 'wpforms_builder_settings_confirmations_after', 'confirmations', $settings ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * Load assets for the lite version with the admin builder. |
| 662 | * |
| 663 | * @since 1.0.0 |
| 664 | * |
| 665 | * @noinspection HtmlUnknownTarget |
| 666 | */ |
| 667 | public function builder_enqueues() { |
| 668 | |
| 669 | $min = wpforms_get_min_suffix(); |
| 670 | |
| 671 | wp_enqueue_script( |
| 672 | 'wpforms-builder-lite', |
| 673 | WPFORMS_PLUGIN_URL . "assets/lite/js/admin/builder/admin-builder-lite{$min}.js", |
| 674 | [ 'jquery', 'jquery-confirm' ], |
| 675 | WPFORMS_VERSION, |
| 676 | false |
| 677 | ); |
| 678 | |
| 679 | $strings = [ |
| 680 | 'disable_notifications' => sprintf( |
| 681 | wp_kses( /* translators: %s - WPForms.com docs page URL. */ |
| 682 | __( 'You\'ve just turned off notification emails for this form. Since entries are not stored in WPForms Lite, notification emails are recommended for collecting entry details. For setup steps, <a href="%s" target="_blank" rel="noopener noreferrer">please see our notification tutorial</a>.', 'wpforms-lite' ), |
| 683 | [ |
| 684 | 'a' => [ |
| 685 | 'href' => [], |
| 686 | 'target' => [], |
| 687 | 'rel' => [], |
| 688 | ], |
| 689 | ] |
| 690 | ), |
| 691 | esc_url( wpforms_utm_link( 'https://wpforms.com/docs/setup-form-notification-wpforms/', 'Builder Notifications', 'Disable Notifications Alert' ) ) |
| 692 | ), |
| 693 | ]; |
| 694 | |
| 695 | $strings = apply_filters( 'wpforms_lite_builder_strings', $strings ); |
| 696 | |
| 697 | wp_localize_script( |
| 698 | 'wpforms-builder-lite', |
| 699 | 'wpforms_builder_lite', |
| 700 | $strings |
| 701 | ); |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * Display upgrade notice at the bottom on the plugin settings pages. |
| 706 | * |
| 707 | * @since 1.4.7 |
| 708 | * |
| 709 | * @param string $view Current view inside the plugin settings page. |
| 710 | */ |
| 711 | public function settings_cta( $view ) { |
| 712 | |
| 713 | if ( get_option( 'wpforms_lite_settings_upgrade', false ) || apply_filters( 'wpforms_lite_settings_upgrade', false ) ) { |
| 714 | return; |
| 715 | } |
| 716 | ?> |
| 717 | <div class="settings-lite-cta"> |
| 718 | <a href="#" class="dismiss" title="<?php esc_attr_e( 'Dismiss this message', 'wpforms-lite' ); ?>"><i class="fa fa-times-circle" aria-hidden="true"></i></a> |
| 719 | <h5><?php esc_html_e( 'Get WPForms Pro and Unlock all the Powerful Features', 'wpforms-lite' ); ?></h5> |
| 720 | <p><?php esc_html_e( 'Thanks for being a loyal WPForms Lite user. Upgrade to WPForms Pro to unlock all the awesome features and experience why WPForms is consistently rated the best WordPress form builder.', 'wpforms-lite' ); ?></p> |
| 721 | <p> |
| 722 | <?php |
| 723 | printf( |
| 724 | wp_kses( /* translators: %s - star icons. */ |
| 725 | __( 'We know that you will truly love WPForms. It has over 13,000+ five star ratings (%s) and is active on over 6 million websites.', 'wpforms-lite' ), |
| 726 | [ |
| 727 | 'i' => [ |
| 728 | 'class' => [], |
| 729 | 'aria-hidden' => [], |
| 730 | ], |
| 731 | ] |
| 732 | ), |
| 733 | str_repeat( '<i class="fa fa-star" aria-hidden="true"></i>', 5 ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 734 | ); |
| 735 | ?> |
| 736 | </p> |
| 737 | <h6><?php esc_html_e( 'Pro Features:', 'wpforms-lite' ); ?></h6> |
| 738 | <div class="list"> |
| 739 | <ul> |
| 740 | <li> |
| 741 | <?php |
| 742 | printf( /* translators: %s - number of templates. */ |
| 743 | esc_html__( '%s customizable form templates', 'wpforms-lite' ), |
| 744 | '2100+' |
| 745 | ); |
| 746 | ?> |
| 747 | </li> |
| 748 | <li><?php esc_html_e( 'Store and manage form entries in WordPress', 'wpforms-lite' ); ?></li> |
| 749 | <li><?php esc_html_e( 'Unlock all fields & features, including smart conditional logic', 'wpforms-lite' ); ?></li> |
| 750 | <li><?php esc_html_e( 'Create powerful custom calculation forms', 'wpforms-lite' ); ?></li> |
| 751 | <li><?php esc_html_e( 'Make surveys and generate reports', 'wpforms-lite' ); ?></li> |
| 752 | <li><?php esc_html_e( 'Accept user-submitted content with the Post Submissions addon', 'wpforms-lite' ); ?></li> |
| 753 | </ul> |
| 754 | <ul> |
| 755 | <li><?php esc_html_e( '9000+ integrations with marketing and payment services', 'wpforms-lite' ); ?></li> |
| 756 | <li><?php esc_html_e( 'Let users save & resume submissions to prevent abandonment', 'wpforms-lite' ); ?></li> |
| 757 | <li><?php esc_html_e( 'Take payments with Stripe, PayPal, Square, & Authorize.Net', 'wpforms-lite' ); ?></li> |
| 758 | <li><?php esc_html_e( 'Export entries to Google Sheets, Excel, and CSV', 'wpforms-lite' ); ?></li> |
| 759 | <li><?php esc_html_e( 'Collect signatures, geolocation data, and file uploads', 'wpforms-lite' ); ?></li> |
| 760 | <li><?php esc_html_e( 'Create user registration and login forms', 'wpforms-lite' ); ?></li> |
| 761 | </ul> |
| 762 | </div> |
| 763 | <p> |
| 764 | <?php $utm_content = ucwords( $view ) . ' Tab'; ?> |
| 765 | <a href="<?php echo esc_url( wpforms_admin_upgrade_link( 'settings-upgrade', $utm_content ) ); ?>" target="_blank" rel="noopener noreferrer"> |
| 766 | <?php esc_html_e( 'Get WPForms Pro Today and Unlock all the Powerful Features »', 'wpforms-lite' ); ?> |
| 767 | </a> |
| 768 | </p> |
| 769 | <p> |
| 770 | <?php |
| 771 | echo wp_kses( |
| 772 | __( '<strong>Bonus:</strong> WPForms Lite users get <span class="green">50% off regular price</span>, automatically applied at checkout.', 'wpforms-lite' ), |
| 773 | [ |
| 774 | 'strong' => [], |
| 775 | 'span' => [ |
| 776 | 'class' => [], |
| 777 | ], |
| 778 | ] |
| 779 | ); |
| 780 | ?> |
| 781 | </p> |
| 782 | </div> |
| 783 | <script type="text/javascript"> |
| 784 | jQuery( function ( $ ) { |
| 785 | $( document ).on( 'click', '.settings-lite-cta .dismiss', function ( event ) { |
| 786 | event.preventDefault(); |
| 787 | $.post( ajaxurl, { |
| 788 | action: 'wpforms_lite_settings_upgrade', |
| 789 | nonce: '<?php echo esc_html( wp_create_nonce( 'wpforms_settings_cta_dismiss' ) ); ?>' |
| 790 | } ); |
| 791 | $( '.settings-lite-cta' ).remove(); |
| 792 | } ); |
| 793 | } ); |
| 794 | </script> |
| 795 | <?php |
| 796 | } |
| 797 | |
| 798 | /** |
| 799 | * Dismiss upgrade notice at the bottom on the plugin settings pages. |
| 800 | * |
| 801 | * @since 1.4.7 |
| 802 | */ |
| 803 | public function settings_cta_dismiss() { |
| 804 | |
| 805 | if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'wpforms_settings_cta_dismiss' ) ) { |
| 806 | wp_send_json_error( esc_html__( 'Security check failed. Please try again.', 'wpforms-lite' ) ); |
| 807 | } |
| 808 | |
| 809 | if ( ! wpforms_current_user_can() ) { |
| 810 | wp_send_json_error(); |
| 811 | } |
| 812 | |
| 813 | update_option( 'wpforms_lite_settings_upgrade', time() ); |
| 814 | |
| 815 | wp_send_json_success(); |
| 816 | } |
| 817 | |
| 818 | /** |
| 819 | * Display sample data and notify user that entries is a pro feature. |
| 820 | * |
| 821 | * @since 1.0.0 |
| 822 | */ |
| 823 | public function entries_page() { |
| 824 | |
| 825 | if ( wpforms_is_admin_page( 'entries', 'sample' ) ) { |
| 826 | $this->entry_single_page(); |
| 827 | |
| 828 | return; |
| 829 | } |
| 830 | |
| 831 | if ( wpforms_is_admin_page( 'entries' ) ) { |
| 832 | $this->entries_list_page(); |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | /** |
| 837 | * Display the Entries List page with sample data. |
| 838 | * |
| 839 | * @since 1.8.9 |
| 840 | */ |
| 841 | private function entries_list_page() { |
| 842 | |
| 843 | $is_lite_connect_enabled = LiteConnect::is_enabled(); |
| 844 | $is_lite_connect_allowed = LiteConnect::is_allowed(); |
| 845 | |
| 846 | wp_enqueue_style( 'wpforms-admin-entry-list' ); |
| 847 | wp_enqueue_script( 'wpforms-admin-entry-list' ); |
| 848 | |
| 849 | echo wpforms_render( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 850 | 'admin/entries/overview/entry-list', |
| 851 | [ |
| 852 | 'is_lite_connect_enabled' => $is_lite_connect_enabled, |
| 853 | 'is_lite_connect_allowed' => $is_lite_connect_allowed, |
| 854 | 'entries_count' => LiteConnectIntegration::get_new_entries_count(), |
| 855 | 'enabled_since' => LiteConnectIntegration::get_enabled_since(), |
| 856 | 'sample_entries' => $this->get_entries_list_data(), |
| 857 | 'utm' => $this->get_entries_utm(), |
| 858 | ], |
| 859 | true |
| 860 | ); |
| 861 | } |
| 862 | |
| 863 | /** |
| 864 | * Display the Single Entry page with sample data. |
| 865 | * |
| 866 | * @since 1.8.9 |
| 867 | */ |
| 868 | private function entry_single_page() { |
| 869 | |
| 870 | wp_enqueue_style( 'wpforms-admin-view-entry' ); |
| 871 | wp_enqueue_script( 'wpforms-admin-view-entry' ); |
| 872 | |
| 873 | echo wpforms_render( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 874 | 'admin/entries/single/entry', |
| 875 | [ |
| 876 | 'utm' => $this->get_entries_utm(), |
| 877 | ], |
| 878 | true |
| 879 | ); |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * Increase entries count once a form is submitted. |
| 884 | * |
| 885 | * @since 1.5.9 |
| 886 | * @since 1.8.2 Added Payment ID. |
| 887 | * |
| 888 | * @param array $fields Set of form fields. |
| 889 | * @param array $entry Entry contents. |
| 890 | * @param array $form_data Form data. |
| 891 | * @param int $entry_id Entry ID. |
| 892 | * @param int $payment_id Payment ID for the payment form. |
| 893 | * |
| 894 | * @noinspection PhpMissingParamTypeInspection |
| 895 | * @noinspection PhpUnusedParameterInspection |
| 896 | */ |
| 897 | public function update_entry_count( $fields, $entry, $form_data, $entry_id, $payment_id ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed |
| 898 | |
| 899 | if ( ! empty( $form_data['spam_reason'] ) ) { |
| 900 | return; |
| 901 | } |
| 902 | |
| 903 | global $wpdb; |
| 904 | |
| 905 | /** |
| 906 | * Filters whether to allow counting entries for Lite users. |
| 907 | * |
| 908 | * @since 1.5.9 |
| 909 | * |
| 910 | * @param bool $allow_entries_count True to allow, false to disallow. Default: true. |
| 911 | */ |
| 912 | if ( ! apply_filters( 'wpforms_dash_widget_allow_entries_count_lite', true ) ) { // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName |
| 913 | return; |
| 914 | } |
| 915 | |
| 916 | $form_id = absint( $form_data['id'] ); |
| 917 | |
| 918 | if ( empty( $form_id ) ) { |
| 919 | return; |
| 920 | } |
| 921 | |
| 922 | if ( wpforms_is_form_template( $form_id ) ) { |
| 923 | return; |
| 924 | } |
| 925 | |
| 926 | if ( add_post_meta( $form_id, 'wpforms_entries_count', 1, true ) ) { |
| 927 | return; |
| 928 | } |
| 929 | |
| 930 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 931 | $wpdb->query( |
| 932 | $wpdb->prepare( |
| 933 | "UPDATE $wpdb->postmeta |
| 934 | SET meta_value = meta_value + 1 |
| 935 | WHERE post_id = %d AND meta_key = 'wpforms_entries_count'", |
| 936 | $form_id |
| 937 | ) |
| 938 | ); |
| 939 | } |
| 940 | |
| 941 | /** |
| 942 | * Submit entry to the Lite Connect API. |
| 943 | * |
| 944 | * @since 1.7.4 |
| 945 | * @since 1.8.2 Added Payment ID. |
| 946 | * |
| 947 | * @param array $fields Set of form fields. |
| 948 | * @param array $entry Entry contents. |
| 949 | * @param array $form_data Form data. |
| 950 | * @param int $entry_id Entry ID. |
| 951 | * @param int $payment_id Payment ID for the payment form. |
| 952 | * |
| 953 | * @noinspection PhpMissingParamTypeInspection |
| 954 | * @noinspection PhpUnusedParameterInspection |
| 955 | */ |
| 956 | public function entry_submit( $fields, $entry, $form_data, $entry_id, $payment_id ) { |
| 957 | |
| 958 | $submission = wpforms()->obj( 'submission' ); |
| 959 | |
| 960 | $submission->register( $fields, $entry, $form_data['id'], $form_data ); |
| 961 | |
| 962 | // Prepare the entry args. |
| 963 | $entry_args = $submission->prepare_entry_data(); |
| 964 | |
| 965 | if ( $payment_id ) { |
| 966 | $entry_args['type'] = 'payment'; |
| 967 | $entry_args['payment_id'] = $payment_id; |
| 968 | } |
| 969 | |
| 970 | if ( ! empty( $form_data['spam_reason'] ) ) { |
| 971 | $entry_args['status'] = 'spam'; |
| 972 | } |
| 973 | |
| 974 | // Submit entry args and form data to the Lite Connect API. |
| 975 | if ( |
| 976 | ! empty( $entry_args ) && |
| 977 | LiteConnect::is_allowed() && |
| 978 | LiteConnect::is_enabled() |
| 979 | ) { |
| 980 | ( new LiteConnectIntegration() )->submit( $entry_args, $form_data ); |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | /** |
| 985 | * Add Lite-specific templates to the list of searchable template paths. |
| 986 | * |
| 987 | * @since 1.6.6 |
| 988 | * |
| 989 | * @param array $paths Paths to templates. |
| 990 | * |
| 991 | * @return array |
| 992 | */ |
| 993 | public function add_templates( $paths ) { |
| 994 | |
| 995 | $paths = (array) $paths; |
| 996 | |
| 997 | $paths[102] = trailingslashit( __DIR__ . '/templates' ); |
| 998 | |
| 999 | return $paths; |
| 1000 | } |
| 1001 | |
| 1002 | /** |
| 1003 | * Render Upgrade to Pro admin bar menu item. |
| 1004 | * |
| 1005 | * @since 1.7.4 |
| 1006 | * |
| 1007 | * @param WP_Admin_Bar $wp_admin_bar WordPress Admin Bar object. |
| 1008 | */ |
| 1009 | public function upgrade_to_pro_menu( WP_Admin_Bar $wp_admin_bar ) { |
| 1010 | |
| 1011 | $current_screen = is_admin() ? get_current_screen() : null; |
| 1012 | $upgrade_utm_content = $current_screen === null ? 'Upgrade to Pro' : 'Upgrade to Pro - ' . $current_screen->base; |
| 1013 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 1014 | $upgrade_utm_content = empty( $_GET['view'] ) ? $upgrade_utm_content : $upgrade_utm_content . ': ' . sanitize_key( $_GET['view'] ); |
| 1015 | |
| 1016 | $wp_admin_bar->add_menu( |
| 1017 | [ |
| 1018 | 'parent' => 'wpforms-menu', |
| 1019 | 'id' => 'wpforms-upgrade', |
| 1020 | 'title' => esc_html__( 'Upgrade to Pro', 'wpforms-lite' ), |
| 1021 | 'href' => esc_url( $this->admin_upgrade_link( 'admin-bar', $upgrade_utm_content ) ), |
| 1022 | 'meta' => [ |
| 1023 | 'target' => '_blank', |
| 1024 | 'rel' => 'noopener noreferrer', |
| 1025 | ], |
| 1026 | ] |
| 1027 | ); |
| 1028 | } |
| 1029 | |
| 1030 | /** |
| 1031 | * Upgrade link used within the various admin pages. |
| 1032 | * |
| 1033 | * TODO: This is a duplicate of the function in the WPForms class. We should refactor this to use the same function. |
| 1034 | * |
| 1035 | * @since 1.8.5.1 |
| 1036 | * |
| 1037 | * @param string $medium URL parameter: utm_medium. |
| 1038 | * @param string $content URL parameter: utm_content. |
| 1039 | * |
| 1040 | * @return string |
| 1041 | */ |
| 1042 | private function admin_upgrade_link( string $medium = 'link', string $content = '' ): string { |
| 1043 | |
| 1044 | $url = 'https://wpforms.com/lite-upgrade/'; |
| 1045 | |
| 1046 | if ( wpforms()->is_pro() ) { |
| 1047 | $license_key = wpforms_get_license_key(); |
| 1048 | $url = add_query_arg( |
| 1049 | 'license_key', |
| 1050 | sanitize_text_field( $license_key ), |
| 1051 | 'https://wpforms.com/pricing/' |
| 1052 | ); |
| 1053 | } |
| 1054 | |
| 1055 | $upgrade = wpforms_utm_link( $url, apply_filters( 'wpforms_upgrade_link_medium', $medium ), $content ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName, WPForms.Comments.PHPDocHooks.RequiredHookDocumentation |
| 1056 | |
| 1057 | /** |
| 1058 | * Modify upgrade link. |
| 1059 | * |
| 1060 | * @since 1.5.1 |
| 1061 | * |
| 1062 | * @param string $upgrade Upgrade links. |
| 1063 | */ |
| 1064 | return apply_filters( 'wpforms_upgrade_link', $upgrade ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName |
| 1065 | } |
| 1066 | |
| 1067 | /** |
| 1068 | * Handle plugin installation upon activation. |
| 1069 | * |
| 1070 | * @since 1.7.4 |
| 1071 | */ |
| 1072 | public function install() { |
| 1073 | |
| 1074 | // Restart the import flags for Lite Connect if needed. |
| 1075 | if ( class_exists( LiteConnectIntegration::class ) ) { |
| 1076 | LiteConnectIntegration::maybe_restart_import_flag(); |
| 1077 | } |
| 1078 | |
| 1079 | // Wipe templates content cache. |
| 1080 | if ( class_exists( TemplatesCache::class ) ) { |
| 1081 | ( new TemplatesCache() )->wipe_content_cache(); |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | /** |
| 1086 | * Retrieve UTM parameters for Entries pages. |
| 1087 | * |
| 1088 | * @since 1.8.9 |
| 1089 | * |
| 1090 | * @return array |
| 1091 | */ |
| 1092 | private function get_entries_utm(): array { |
| 1093 | |
| 1094 | return [ |
| 1095 | 'entries_list_button' => 'https://wpforms.com/lite-upgrade/?utm_campaign=liteplugin&utm_source=WordPress&utm_medium=entries&utm_content=Upgrade%20Now%20-%20Entries%20list', |
| 1096 | 'entries_list_link' => 'https://wpforms.com/lite-upgrade/?utm_campaign=liteplugin&utm_source=WordPress&utm_medium=entries&utm_content=Upgrade%20to%20Pro%20-%20Entries%20list', |
| 1097 | 'entry_single_button' => 'https://wpforms.com/lite-upgrade/?utm_campaign=liteplugin&utm_source=WordPress&utm_medium=entries&utm_content=Upgrade%20to%20Pro%20-%20Single%20Entry', |
| 1098 | 'entry_single_link' => 'https://wpforms.com/lite-upgrade/?utm_campaign=liteplugin&utm_source=WordPress&utm_medium=entries&utm_content=Upgrade%20to%20Pro%20-%20Single%20Entry', |
| 1099 | ]; |
| 1100 | } |
| 1101 | |
| 1102 | /** |
| 1103 | * Retrieve dummy data for the Entries List page. |
| 1104 | * |
| 1105 | * @since 1.8.9 |
| 1106 | * |
| 1107 | * return array |
| 1108 | */ |
| 1109 | private function get_entries_list_data(): array { |
| 1110 | |
| 1111 | return [ |
| 1112 | [ |
| 1113 | 'name' => 'Michael Johnson', |
| 1114 | 'read' => true, |
| 1115 | ], |
| 1116 | [ |
| 1117 | 'name' => 'David Thompson', |
| 1118 | 'read' => true, |
| 1119 | ], |
| 1120 | [ |
| 1121 | 'name' => 'Sarah Parker', |
| 1122 | 'read' => true, |
| 1123 | ], |
| 1124 | [ |
| 1125 | 'name' => 'Brian Anderson', |
| 1126 | 'read' => true, |
| 1127 | 'star' => true, |
| 1128 | ], |
| 1129 | [ |
| 1130 | 'name' => 'Emily Davis', |
| 1131 | 'read' => true, |
| 1132 | 'star' => true, |
| 1133 | ], |
| 1134 | [ |
| 1135 | 'name' => 'Laura White', |
| 1136 | 'read' => true, |
| 1137 | ], |
| 1138 | [ |
| 1139 | 'name' => 'Kevin Wilson', |
| 1140 | 'read' => true, |
| 1141 | ], |
| 1142 | [ |
| 1143 | 'name' => 'Megan Clark', |
| 1144 | 'read' => true, |
| 1145 | ], |
| 1146 | [ |
| 1147 | 'name' => 'Nicole Allen', |
| 1148 | 'read' => true, |
| 1149 | 'star' => true, |
| 1150 | ], |
| 1151 | [ |
| 1152 | 'name' => 'Jason Miller', |
| 1153 | ], |
| 1154 | [ |
| 1155 | 'name' => 'Rachel Moore', |
| 1156 | ], |
| 1157 | [ |
| 1158 | 'name' => 'Chris Taylor', |
| 1159 | 'star' => true, |
| 1160 | ], |
| 1161 | ]; |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | new WPForms_Lite(); |
| 1166 |