notification-success-message.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * Class for our success message notification type.
  4. *
  5. * @package Ninja Forms
  6. * @subpackage Classes/Notifications
  7. * @copyright Copyright (c) 2014, WPNINJAS
  8. * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9. * @since 2.8
  10. */
  11. class NF_Notification_Success_Message extends NF_Notification_Base_Type
  12. {
  13. /**
  14. * Get things rolling
  15. */
  16. function __construct() {
  17. $this->name = __( 'Success Message', 'ninja-forms' );
  18. }
  19. /**
  20. * Output our edit screen
  21. *
  22. * @access public
  23. * @since 2.8
  24. * @return void
  25. */
  26. public function edit_screen( $id = '' ) {
  27. $settings = array(
  28. 'textarea_name' => 'settings[success_msg]',
  29. );
  30. $loc_opts = apply_filters( 'nf_success_message_locations',
  31. array(
  32. array( 'action' => 'ninja_forms_display_before_fields', 'name' => __( 'Before Form', 'ninja-forms' ) ),
  33. array( 'action' => 'ninja_forms_display_after_fields', 'name' => __( 'After Form', 'ninja-forms' ) ),
  34. )
  35. );
  36. ?>
  37. <!-- <tr>
  38. <th scope="row"><label for="success_message_loc"><?php _e( 'Location', 'ninja-forms' ); ?></label></th>
  39. <td>
  40. <select name="settings[success_message_loc]">
  41. <?php
  42. foreach ( $loc_opts as $opt ) {
  43. ?>
  44. <option value="<?php echo $opt['action'];?>" <?php selected( nf_get_object_meta_value( $id, 'success_message_loc' ), $opt['action'] ); ?>><?php echo $opt['name'];?></option>
  45. <?php
  46. }
  47. ?>
  48. </select>
  49. </td>
  50. </tr> -->
  51. <tr>
  52. <th scope="row"><label for="success_msg"><?php _e( 'Message', 'ninja-forms' ); ?></label></th>
  53. <td>
  54. <?php wp_editor( nf_get_object_meta_value( $id, 'success_msg' ), 'success_msg', $settings ); ?>
  55. </td>
  56. </tr>
  57. <?php
  58. }
  59. /**
  60. * Process our Success Message notification
  61. *
  62. * @access public
  63. * @since 2.8
  64. * @return void
  65. */
  66. public function process( $id ) {
  67. global $ninja_forms_processing;
  68. // We need to get our name setting so that we can use it to create a unique success message ID.
  69. $name = Ninja_Forms()->notification( $id )->get_setting( 'name' );
  70. // If our name is empty, we need to generate a random string.
  71. if ( empty ( $name ) ) {
  72. $name = ninja_forms_random_string( 4 );
  73. }
  74. $success_msg = apply_filters( 'nf_success_msg', Ninja_Forms()->notification( $id )->get_setting( 'success_msg' ), $id );
  75. $success_msg = do_shortcode( wpautop( $success_msg ) );
  76. $success_msg = nf_parse_fields_shortcode( $success_msg );
  77. $ninja_forms_processing->add_success_msg( 'success_msg-' . $name, $success_msg );
  78. }
  79. }
  80. return new NF_Notification_Success_Message();