43 var
$icon =
'dashicons-admin-comments';
47 self::$path = plugin_dir_path( __FILE__ );
48 self::$file = __FILE__;
50 $this->doing_ajax = defined(
'DOING_AJAX' ) && DOING_AJAX;
54 parent::__construct();
66 add_shortcode(
'gv_note_add', array(
'GravityView_Field_Notes',
'get_add_note_part' ) );
68 add_action(
'wp', array( $this,
'maybe_delete_notes'), 1000 );
69 add_action(
'wp_ajax_nopriv_gv_delete_notes', array( $this,
'maybe_delete_notes') );
70 add_action(
'wp_ajax_gv_delete_notes', array( $this,
'maybe_delete_notes') );
72 add_action(
'wp', array( $this,
'maybe_add_note'), 1000 );
73 add_action(
'wp_ajax_nopriv_gv_note_add', array( $this,
'maybe_add_note') );
74 add_action(
'wp_ajax_gv_note_add', array( $this,
'maybe_add_note') );
77 add_filter(
'gravityview_template_paths', array( $this,
'add_template_path' ) );
78 add_filter(
'gravityview/template/fields_template_paths', array( $this,
'add_template_path' ) );
80 add_action(
'wp_enqueue_scripts', array( $this,
'register_scripts') );
81 add_action(
'gravityview/field/notes/scripts', array( $this,
'enqueue_scripts' ) );
83 add_filter(
'gravityview_entry_default_fields', array( $this,
'add_entry_default_field' ), 10, 3 );
102 if( in_array( $zone, array(
'directory',
'single' ) ) ) {
103 $entry_default_fields[
'notes'] = array(
104 'label' => __(
'Entry Notes',
'gk-gravityview' ),
106 'desc' => __(
'Display, add, and delete notes for an entry.',
'gk-gravityview' ),
107 'icon' =>
'dashicons-admin-comments',
111 return $entry_default_fields;
137 if( ! wp_script_is(
'gravityview-notes',
'enqueued' ) ) {
138 wp_enqueue_style(
'gravityview-notes' );
139 wp_enqueue_script(
'gravityview-notes' );
142 if( ! wp_script_is(
'gravityview-notes',
'done' ) ) {
146 wp_localize_script(
'gravityview-notes',
'GVNotes', array(
147 'ajaxurl' => admin_url(
'admin-ajax.php' ),
149 'processing' =>
$strings[
'processing'],
150 'delete_confirm' =>
$strings[
'delete-confirm'],
151 'note_added' =>
$strings[
'added-note'],
152 'error_invalid' =>
$strings[
'error-invalid'],
153 'error_empty_note' =>
$strings[
'error-empty-note'],
169 if ( ! isset( $_POST[
'action'] ) ||
'gv_note_add' !== $_POST[
'action'] ) {
174 gravityview()->log->error(
"The user isn't allowed to add entry notes." );
179 $post = wp_unslash( $_POST );
181 if ( $this->doing_ajax ) {
182 parse_str(
$post[
'data'], $data );
213 if( empty( $data[
'entry-slug'] ) ) {
215 $error = self::strings(
'error-invalid');
216 gravityview()->log->error(
'The note is missing an Entry ID.' );
220 $valid = wp_verify_nonce( $data[
'gv_note_add'],
'gv_note_add_' . $data[
'entry-slug'] );
225 $error = self::strings(
'error-cap-add' );
226 gravityview()->log->error(
'Adding a note failed: the user does not have the "gravityview_add_entry_notes" capability.' );
227 } elseif ( $valid ) {
234 if ( is_wp_error( $added ) ) {
236 $error = $added->get_error_message();
247 $success = self::display_note( $note, ! empty( $data[
'show-delete'] ) );
248 gravityview()->log->debug(
'The note was successfully created', array(
'data' => compact(
'note',
'data' ) ) );
250 $error = self::strings(
'error-add-note');
251 gravityview()->log->error(
'The note was not successfully created', array(
'data' => compact(
'note',
'data' ) ) );
255 $error = self::strings(
'error-invalid');
256 gravityview()->log->error(
'Nonce validation failed; the note was not created' );
261 if( $this->doing_ajax ) {
263 wp_send_json_success( array(
'html' => $success ) );
265 $error = $error ? $error : self::strings(
'error-invalid' );
266 wp_send_json_error( array(
'error' => esc_html( $error ) ) );
288 if ( isset( $_POST[
'action'] ) &&
'gv_delete_notes' === $_POST[
'action'] ) {
290 $post = wp_unslash( $_POST );
291 if ( $this->doing_ajax ) {
292 parse_str(
$post[
'data'], $data );
297 $required_args = array(
298 'gv_delete_notes' =>
'',
302 $data = wp_parse_args( $data, $required_args );
323 $valid = wp_verify_nonce( $data[
'gv_delete_notes'],
'gv_delete_notes_' . $data[
'entry-slug'] );
327 if ( $valid && $has_cap ) {
332 if( $this->doing_ajax ) {
335 wp_send_json_success();
338 $error_message = self::strings(
'error-invalid' );
340 $error_message = self::strings(
'error-permission-delete' );
343 wp_send_json_error( array(
'error' => $error_message ) );
359 $file_paths[ 172 ] = self::$path;
360 $file_paths[ 173 ] = self::$path .
'partials/';
367 unset( $field_options[
'show_as_link'] );
369 $notes_options = array(
371 'type' =>
'checkboxes',
372 'label' => __(
'Note Settings',
'gk-gravityview'),
373 'desc' => sprintf( _x(
'Only users with specific capabilities will be able to view, add and delete notes. %sRead more%s.',
'%s is opening and closing HTML link',
'gk-gravityview' ),
'<a href="https://docs.gravityview.co/article/311-gravityview-capabilities">',
'</a>' ),
376 'label' => __(
'Display notes?',
'gk-gravityview' ),
378 'view_loggedout' => array(
379 'label' => __(
'Display notes to users who are not logged-in?',
'gk-gravityview' ),
380 'requires' =>
'view',
383 'label' => __(
'Enable adding notes?',
'gk-gravityview' ),
386 'label' => __(
'Allow emailing notes?',
'gk-gravityview' ),
390 'label' => __(
'Allow deleting notes?',
'gk-gravityview' ),
393 'value' => array(
'view' => 1,
'add' => 1,
'email' => 1 ),
397 return $notes_options + $field_options;
414 'add-note' => __(
'Add Note',
'gk-gravityview' ),
415 'added-note' => __(
'Note added.',
'gk-gravityview' ),
416 'content-label' => __(
'Note Content',
'gk-gravityview' ),
417 'delete' => __(
'Delete',
'gk-gravityview' ),
418 'delete-confirm' => __(
'Are you sure you want to delete the selected notes?',
'gk-gravityview' ),
419 'caption' => __(
'Notes for this entry',
'gk-gravityview' ),
420 'toggle-notes' => __(
'Toggle all notes',
'gk-gravityview' ),
421 'no-notes' => __(
'There are no notes.',
'gk-gravityview' ),
422 'processing' => __(
'Processing…',
'gk-gravityview' ),
423 'other-email' => __(
'Other email address',
'gk-gravityview' ),
424 'email-label' => __(
'Email address',
'gk-gravityview' ),
425 'email-placeholder' => _x(
'[email protected]',
'Example email address used as a placeholder',
'gk-gravityview'),
426 'subject-label' => __(
'Subject',
'gk-gravityview' ),
427 'subject' => __(
'Email subject',
'gk-gravityview' ),
428 'default-email-subject' => __(
'New entry note',
'gk-gravityview' ),
429 'email-footer' => __(
'This note was sent from {url}',
'gk-gravityview' ),
430 'also-email' => __(
'Also email this note to',
'gk-gravityview' ),
431 'error-add-note' => __(
'There was an error adding the note.',
'gk-gravityview' ),
432 'error-invalid' => __(
'The request was invalid. Refresh the page and try again.',
'gk-gravityview' ),
433 'error-empty-note' => _x(
'Note cannot be blank.',
'Message to display when submitting a note without content.',
'gk-gravityview' ),
434 'error-cap-delete' => __(
'You don\'t have the ability to delete notes.',
'gk-gravityview' ),
435 'error-cap-add' => __(
'You don\'t have the ability to add notes.',
'gk-gravityview' ),
467 if( ! is_object( $note ) ) {
471 $note_content = array(
472 'avatar' => get_avatar( $note->user_id, 48 ),
473 'user_name' => $note->user_name,
474 'user_email' => $note->user_email,
475 'added_on' => esc_html__(
'added on {date_created_formatted}',
'gk-gravityview' ),
476 'value' => wpautop( esc_html( $note->value ) ),
477 'date_created' => $note->date_created,
478 'date_created_formatted' => GFCommon::format_date( $note->date_created,
false ),
479 'user_id' => intval( $note->user_id ),
480 'note_type' => $note->note_type,
481 'note_id' => intval( $note->id ),
493 $note_content = apply_filters(
'gravityview/field/notes/content', $note_content, $note,
$show_delete, $context );
497 if ( $context instanceof \
GV\Template_Context ) {
500 $context->template->get_template_part(
'note',
'detail',
true );
501 $note_detail_html = ob_get_clean();
504 $context->template->get_template_part(
'note', $note_row_template,
true );
505 $note_row = ob_get_clean();
510 $note_detail_html = ob_get_clean();
514 $note_row = ob_get_clean();
517 foreach ( $note_content as $tag =>
$value ) {
518 $note_detail_html = str_replace(
'{' . $tag .
'}',
$value, $note_detail_html );
521 $replacements = array(
522 '{note_id}' => $note_content[
'note_id'],
523 '{row_class}' =>
'gv-note',
524 '{note_detail}' => $note_detail_html
530 foreach ( $replacements as $tag => $replacement ) {
550 global $current_user, $wpdb;
552 $user_data = get_userdata( $current_user->ID );
554 $note_content = trim( $data[
'gv-note-content'] );
556 if( empty( $note_content ) ) {
557 return new WP_Error(
'gv-add-note-empty', __(
'The note is empty.',
'gk-gravityview' ) );
578 $atts = shortcode_atts( array(
'entry' => null ), $atts );
581 gravityview()->log->error(
'User does not have permission to add entry notes ("gravityview_add_entry_notes").' );
585 if ( $context instanceof \
GV\Template_Context ) {
588 $context->template->get_template_part(
'note',
'add-note',
true );
589 $add_note_html = ob_get_clean();
592 $gv_entry = $context->entry;
598 $add_note_html = ob_get_clean();
602 if ( $atts[
'entry'] ) {
603 $entry = GFAPI::get_entry( $atts[
'entry'] );
617 $nonce_field = wp_nonce_field(
'gv_note_add_' .
$entry_slug,
'gv_note_add',
false,
false );
622 $email_fields = self::get_note_email_fields(
$entry_slug );
625 $add_note_html = str_replace(
'{entry_slug}',
$entry_slug, $add_note_html );
626 $add_note_html = str_replace(
'{nonce_field}', $nonce_field, $add_note_html );
628 $add_note_html = str_replace(
'{email_fields}', $email_fields, $add_note_html );
629 $add_note_html = str_replace(
'{url}', esc_url_raw( add_query_arg( array() ) ), $add_note_html );
631 return $add_note_html;
650 $note_emails = array();
652 foreach ( $email_fields as $email_field ) {
653 if ( ! empty( $entry[
"{$email_field->id}"] ) && is_email( $entry[
"{$email_field->id}"] ) ) {
654 $note_emails[] = $entry[
"{$email_field->id}"];
664 $note_emails = apply_filters(
'gravityview/field/notes/emails', $note_emails, $entry );
666 return (array) $note_emails;
683 gravityview()->log->error(
'User does not have permission to email entry notes ("gravityview_email_entry_notes").' );
689 $note_emails = self::get_note_emails_array();
698 $include_custom = apply_filters(
'gravityview/field/notes/custom-email',
true );
702 if ( ! empty( $note_emails ) || $include_custom ) { ?>
703 <div
class=
"gv-note-email-container">
704 <label
for=
"gv-note-email-to-<?php echo $entry_slug_esc; ?>" class=
"screen-reader-text"><?php echo
$strings[
'also-email']; ?></label>
705 <select
class=
"gv-note-email-to" name=
"gv-note-to" id=
"gv-note-email-to-<?php echo $entry_slug_esc; ?>">
706 <option value=
""><?php echo $strings[
'also-email']; ?></option>
707 <?php
foreach ( $note_emails as $email ) {
709 <option value=
"<?php echo esc_attr( $email ); ?>"><?php echo esc_html( $email ); ?></option>
711 if( $include_custom ) { ?>
712 <option value=
"custom"><?php echo self::strings(
'other-email'); ?></option>
715 <fieldset
class=
"gv-note-to-container">
716 <?php
if( $include_custom ) { ?>
717 <div
class=
'gv-note-to-custom-container'>
718 <label
for=
"gv-note-email-to-custom-<?php echo $entry_slug_esc; ?>"><?php echo $strings[
'email-label']; ?></label>
719 <input type=
"text" name=
"gv-note-to-custom" placeholder=
"<?php echo $strings['email-placeholder']; ?>" id=
"gv-note-to-custom-<?php echo $entry_slug_esc; ?>" value=
"" />
722 <div
class=
'gv-note-subject-container'>
723 <label
for=
"gv-note-subject-<?php echo $entry_slug_esc; ?>"><?php echo $strings[
'subject-label']; ?></label>
724 <input type=
"text" name=
"gv-note-subject" placeholder=
"<?php echo $strings['subject']; ?>" id=
"gv-note-subject-<?php echo $entry_slug_esc; ?>" value=
"" />
731 return ob_get_clean();
748 gravityview()->log->debug(
'User doesn\'t have "gravityview_email_entry_notes" cap, or $note is empty', array(
'data' => $note ) );
752 gravityview()->log->debug(
'$data', array(
'data' => $data ) );
755 if ( ! empty( $data[
'gv-note-to'] ) ) {
757 $default_data = array(
759 'gv-note-to-custom' =>
'',
760 'gv-note-subject' =>
'',
761 'gv-note-content' =>
'',
765 $current_user = wp_get_current_user();
766 $email_data = wp_parse_args( $data, $default_data );
768 $from = $current_user->user_email;
769 $to = $email_data[
'gv-note-to'];
775 $include_custom = apply_filters(
'gravityview/field/notes/custom-email',
true );
777 if(
'custom' === $to && $include_custom ) {
778 $to = $email_data[
'gv-note-to-custom'];
779 gravityview()->log->debug(
'Sending note to a custom email address: {to}', array(
'to' => $to ) );
782 if ( ! GFCommon::is_valid_email_list( $to ) ) {
783 gravityview()->log->error(
'$to not a valid email or email list (CSV of emails): {to}', array(
'to' => print_r( $to,
true ),
'data' => $email_data ) );
789 $subject = trim( $email_data[
'gv-note-subject'] );
792 $subject = empty( $subject ) ? self::strings(
'default-email-subject' ) : $subject;
793 $message = $email_data[
'gv-note-content'];
794 $email_footer = self::strings(
'email-footer' );
795 $from_name = $current_user->display_name;
796 $message_format =
'html';
804 $email_content = apply_filters(
'gravityview/field/notes/email_content', compact(
'from',
'to',
'bcc',
'reply_to',
'subject',
'message',
'from_name',
'message_format',
'entry',
'email_footer' ) );
806 extract( $email_content );
808 $is_html = (
'html' === $message_format );
811 $message .= $this->
get_email_footer( $email_footer, $is_html, $email_data );
818 $wpautop_email = apply_filters(
'gravityview/field/notes/wpautop_email',
true );
820 if ( $is_html && $wpautop_email ) {
821 $message = wpautop( $message );
824 GVCommon::send_email( $from, $to, $bcc, $reply_to, $subject, $message, $from_name, $message_format,
'',
$entry,
false );
826 $form = isset(
$entry[
'form_id'] ) ? GFAPI::get_form(
$entry[
'form_id'] ) : array();
831 do_action(
'gform_post_send_entry_note', __METHOD__, $to, $from, $subject, $message,
$form,
$entry );
848 private function get_email_footer( $email_footer =
'', $is_html =
true, $email_data = array() ) {
852 if( ! empty( $email_footer ) ) {
857 $content = $is_html ?
"<a href='{$url}'>{$url}</a>" :
$url;
859 $email_footer = str_replace(
'{url}',
$content, $email_footer );
861 $output .=
"\n\n$email_footer";
Modify field settings by extending this class.
const GV_PLUGIN_VERSION(! GravityKit\GravityView\Foundation\meets_min_php_version_requirement(__FILE__, '7.2.0'))
Constants.
static delete_notes( $note_ids=array())
Delete an array of notes Alias for GFFormsModel::delete_notes()
static getInstance( $passed_post=NULL)
$gravityview_view
array $entry array $form array $field_settings
if(! function_exists( 'gravityview_sanitize_html_class')) gravityview_strip_whitespace( $string)
Replace multiple newlines, tabs, and spaces with a single space.
static get_note_email_fields( $entry_slug='')
Generate a HTML dropdown of email values based on email fields from the current form.
get_email_footer( $email_footer='', $is_html=true, $email_data=array())
Get the footer for Entry Note emails.
maybe_send_entry_notes( $note=false, $entry=array(), $data=array())
If note has an email to send, and the user has the right caps, send it.
enqueue_scripts()
Enqueue, localize field scripts and styles.
field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id)
gravityview_get_entry( $entry_slug, $force_allow_ids=false, $check_entry_display=true, $view=null)
Return a single entry object.
process_delete_notes( $data)
static from_entry( $entry)
Construct a instance from a Gravity Forms entry array.
maybe_delete_notes()
Possibly delete notes, if request is proper.
gravityview_css_url( $css_file='', $dir_path='')
Functions that don't require GravityView or Gravity Forms API access but are used in the plugin to ex...
if(gravityview() ->plugin->is_GF_25()) $form
add_hooks()
Add AJAX hooks, [gv_note_add] shortcode, and template loading paths.
if(empty( $field_settings['content'])) $content
register_scripts()
Register scripts and styles used by the Notes field.
new GravityView_Field_Notes
gv_map_deep( $value, $callback)
Maps a function to all non-iterable elements of an array or an object.
static send_email( $from, $to, $bcc, $reply_to, $subject, $message, $from_name='', $message_format='html', $attachments='', $entry=false, $notification=false)
Send email using GFCommon::send_email()
static display_note( $note, $show_delete=false, $context=null)
Generate HTML output for a single note.
maybe_add_note()
Verify permissions, check if $_POST is set and as expected.
add_template_path( $file_paths)
Include this extension templates path.
static strings( $key='')
Get strings used by the Entry Notes field.
static get_note( $note_id)
Get a single note by note ID.
if(empty( $created_by)) $form_id
add_entry_default_field( $entry_default_fields, $form, $zone)
Add Entry Notes to the Add Field picker in Edit View.
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
static add_note( $lead_id, $user_id, $user_name, $note='', $note_type='gravityview')
Alias for GFFormsModel::add_note() with default note_type of 'gravityview'.
gravityview()
The main GravityView wrapper function.
static get_add_note_part( $atts, $context=null)
Get the Add Note form HTML.
static get_note_emails_array()
Get array of emails addresses from the stored entry.
add_note( $entry, $data)
Add a note.
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed