@@ -220,6 +220,9 @@ |
||
220 | 220 | |
221 | 221 | } |
222 | 222 | |
223 | + /** |
|
224 | + * @param string $key |
|
225 | + */ |
|
223 | 226 | public function getCurrentFieldSetting( $key ) { |
224 | 227 | $settings = $this->getCurrentField('field_settings'); |
225 | 228 |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | // Make sure the keys are all set |
68 | 68 | $note = wp_parse_args( $note, $default_note ); |
69 | 69 | |
70 | - GFFormsModel::add_note( intval( $note['lead_id'] ), intval( $note['user_id'] ), esc_attr( $note['user_name'] ), $note['note'], esc_attr( $note['note_type'] ) ); |
|
70 | + GFFormsModel::add_note( intval( $note[ 'lead_id' ] ), intval( $note[ 'user_id' ] ), esc_attr( $note[ 'user_name' ] ), $note[ 'note' ], esc_attr( $note[ 'note_type' ] ) ); |
|
71 | 71 | |
72 | 72 | // If last_error is empty string, there was no error. |
73 | - if( empty( $wpdb->last_error ) ) { |
|
73 | + if ( empty( $wpdb->last_error ) ) { |
|
74 | 74 | $return = $wpdb->insert_id; |
75 | 75 | } else { |
76 | 76 | $return = new WP_Error( 'gravityview-add-note', $wpdb->last_error ); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public static function delete_notes( $note_ids = array() ) { |
98 | 98 | |
99 | - if( !is_array( $note_ids ) ) { |
|
99 | + if ( ! is_array( $note_ids ) ) { |
|
100 | 100 | |
101 | 101 | do_action( 'gravityview_log_error', __METHOD__ . ' - Note IDs not an array. Not processing delete request.', $note_ids ); |
102 | 102 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | ) |
152 | 152 | ); |
153 | 153 | |
154 | - return $results ? $results[0] : false; |
|
154 | + return $results ? $results[ 0 ] : false; |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public static function filter_avatar( $avatar = '', $note ) { |
166 | 166 | |
167 | - if( 'gravityview' === $note->note_type && -1 === (int)$note->user_id ) { |
|
168 | - $avatar = sprintf( '<img src="%s" width="48" height="48" alt="GravityView" class="avatar avatar-48 gravityview-avatar" />', esc_url_raw( plugins_url( 'assets/images/floaty-avatar.png', GRAVITYVIEW_FILE ) ) ); |
|
167 | + if ( 'gravityview' === $note->note_type && -1 === (int)$note->user_id ) { |
|
168 | + $avatar = sprintf( '<img src="%s" width="48" height="48" alt="GravityView" class="avatar avatar-48 gravityview-avatar" />', esc_url_raw( plugins_url( 'assets/images/floaty-avatar.png', GRAVITYVIEW_FILE ) ) ); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | return $avatar; |
@@ -21,10 +21,10 @@ |
||
21 | 21 | {email_fields} |
22 | 22 | |
23 | 23 | <div class="gv-note-content-container"> |
24 | - <label for="gv-note-content-{entry_slug}" class="screen-reader-text"><?php echo GravityView_Field_Notes::strings('content-label'); ?></label> |
|
24 | + <label for="gv-note-content-{entry_slug}" class="screen-reader-text"><?php echo GravityView_Field_Notes::strings( 'content-label' ); ?></label> |
|
25 | 25 | <textarea name="gv-note-content" id="gv-note-content-{entry_slug}"></textarea> |
26 | 26 | </div> |
27 | 27 | |
28 | - <button type="submit" class="button gv-add-note-submit"><?php echo GravityView_Field_Notes::strings('add-note'); ?></button> |
|
28 | + <button type="submit" class="button gv-add-note-submit"><?php echo GravityView_Field_Notes::strings( 'add-note' ); ?></button> |
|
29 | 29 | </div> |
30 | 30 | </form> |
31 | 31 | \ No newline at end of file |
@@ -21,7 +21,7 @@ |
||
21 | 21 | * @return string |
22 | 22 | */ |
23 | 23 | function get_field_desc() { |
24 | - return !empty( $this->field['desc'] ) ? $this->field['desc'] : ''; |
|
24 | + return ! empty( $this->field[ 'desc' ] ) ? $this->field[ 'desc' ] : ''; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | } |
23 | 23 | |
24 | 24 | function render_input( $override_input = null ) { |
25 | - if( isset( $override_input ) ) { |
|
25 | + if ( isset( $override_input ) ) { |
|
26 | 26 | echo $override_input; |
27 | 27 | return; |
28 | 28 | } |
@@ -30,18 +30,18 @@ discard block |
||
30 | 30 | ?> |
31 | 31 | <ul class="gv-setting-list"> |
32 | 32 | <?php |
33 | - foreach( $this->field['options'] as $value => $label ) { ?> |
|
34 | - <li <?php if( isset( $label['requires'] ) ) { printf( 'class="gv-sub-setting" data-requires="%s"', $label['requires'] ); } ?>> |
|
33 | + foreach ( $this->field[ 'options' ] as $value => $label ) { ?> |
|
34 | + <li <?php if ( isset( $label[ 'requires' ] ) ) { printf( 'class="gv-sub-setting" data-requires="%s"', $label[ 'requires' ] ); } ?>> |
|
35 | 35 | <label> |
36 | 36 | <input name="<?php printf( '%s[%s]', esc_attr( $this->name ), esc_attr( $value ) ); ?>" type="hidden" |
37 | 37 | value="0"/> |
38 | 38 | <input name="<?php printf( '%s[%s]', esc_attr( $this->name ), esc_attr( $value ) ); ?>" |
39 | 39 | id="<?php echo $this->get_field_id(); ?>" type="checkbox" |
40 | 40 | value="1" <?php checked( ! empty( $this->value[ $value ] ) ); ?> /> |
41 | - <?php echo esc_html( $label['label'] ); ?> |
|
41 | + <?php echo esc_html( $label[ 'label' ] ); ?> |
|
42 | 42 | </label> |
43 | - <?php if( ! empty( $label['desc'] ) ) { |
|
44 | - printf( '<span class="howto">%s</span>', $label['desc'] ); |
|
43 | + <?php if ( ! empty( $label[ 'desc' ] ) ) { |
|
44 | + printf( '<span class="howto">%s</span>', $label[ 'desc' ] ); |
|
45 | 45 | } |
46 | 46 | ?> |
47 | 47 | </li> |
@@ -9,9 +9,9 @@ discard block |
||
9 | 9 | $gravityview_view = GravityView_View::getInstance(); |
10 | 10 | |
11 | 11 | $visibility_settings = $gravityview_view->getCurrentFieldSetting( 'notes' ); |
12 | -$show_notes_logged_out = ( ! empty( $visibility_settings['view'] ) && ! empty( $visibility_settings['view_loggedout'] ) ); |
|
12 | +$show_notes_logged_out = ( ! empty( $visibility_settings[ 'view' ] ) && ! empty( $visibility_settings[ 'view_loggedout' ] ) ); |
|
13 | 13 | |
14 | -if( ! GVCommon::has_cap( array( 'gravityview_view_entry_notes', 'gravityview_add_entry_notes', 'gravityview_delete_entry_notes' ) ) && ! $show_notes_logged_out ) { |
|
14 | +if ( ! GVCommon::has_cap( array( 'gravityview_view_entry_notes', 'gravityview_add_entry_notes', 'gravityview_delete_entry_notes' ) ) && ! $show_notes_logged_out ) { |
|
15 | 15 | return; |
16 | 16 | } |
17 | 17 | |
@@ -25,20 +25,20 @@ discard block |
||
25 | 25 | do_action( 'gravityview/field/notes/scripts' ); |
26 | 26 | |
27 | 27 | $entry = $gravityview_view->getCurrentEntry(); |
28 | -$notes = GravityView_Entry_Notes::get_notes( $entry['id'] ); |
|
28 | +$notes = GravityView_Entry_Notes::get_notes( $entry[ 'id' ] ); |
|
29 | 29 | $strings = GravityView_Field_Notes::strings(); |
30 | -$entry_slug = GravityView_API::get_entry_slug( $entry['id'], $entry ); |
|
30 | +$entry_slug = GravityView_API::get_entry_slug( $entry[ 'id' ], $entry ); |
|
31 | 31 | |
32 | -$show_add = ! empty( $visibility_settings['add'] ); |
|
33 | -$show_delete = ( ! empty( $visibility_settings['delete'] ) && GVCommon::has_cap( 'gravityview_delete_entry_notes' ) ); |
|
34 | -$show_notes = $show_notes_logged_out || ( ! empty( $visibility_settings['view'] ) && GVCommon::has_cap( 'gravityview_view_entry_notes' ) ); |
|
32 | +$show_add = ! empty( $visibility_settings[ 'add' ] ); |
|
33 | +$show_delete = ( ! empty( $visibility_settings[ 'delete' ] ) && GVCommon::has_cap( 'gravityview_delete_entry_notes' ) ); |
|
34 | +$show_notes = $show_notes_logged_out || ( ! empty( $visibility_settings[ 'view' ] ) && GVCommon::has_cap( 'gravityview_view_entry_notes' ) ); |
|
35 | 35 | |
36 | 36 | $container_class = ( sizeof( $notes ) > 0 ? 'gv-has-notes' : 'gv-no-notes' ); |
37 | 37 | $container_class .= $show_notes ? ' gv-show-notes' : ' gv-hide-notes'; |
38 | 38 | ?> |
39 | 39 | <div class="gv-notes <?php echo $container_class; ?>"> |
40 | 40 | <?php |
41 | - if( $show_notes ) { |
|
41 | + if ( $show_notes ) { |
|
42 | 42 | ?> |
43 | 43 | <form method="post" class="gv-notes-list"> |
44 | 44 | <?php if ( $show_delete ) { wp_nonce_field( 'gv_delete_notes_' . $entry_slug, 'gv_delete_notes' ); } ?> |
@@ -46,21 +46,21 @@ discard block |
||
46 | 46 | <input type="hidden" name="action" value="gv_delete_notes" /> |
47 | 47 | <input type="hidden" name="entry-slug" value="<?php echo esc_attr( $entry_slug ); ?>" /> |
48 | 48 | <table> |
49 | - <caption><?php echo $strings['caption']; ?></caption> |
|
49 | + <caption><?php echo $strings[ 'caption' ]; ?></caption> |
|
50 | 50 | <?php |
51 | 51 | if ( $show_delete ) { |
52 | 52 | ?> |
53 | 53 | <thead> |
54 | 54 | <tr> |
55 | 55 | <th colspan="2"> |
56 | - <label><input type="checkbox" value="" class="gv-notes-toggle" title="<?php echo $strings['toggle-notes']; ?>"><span class="screen-reader-text"><?php echo $strings['toggle-notes']; ?></span></label> |
|
57 | - <button type="submit" class="button button-small gv-notes-delete"><?php echo $strings['delete']; ?></button> |
|
56 | + <label><input type="checkbox" value="" class="gv-notes-toggle" title="<?php echo $strings[ 'toggle-notes' ]; ?>"><span class="screen-reader-text"><?php echo $strings[ 'toggle-notes' ]; ?></span></label> |
|
57 | + <button type="submit" class="button button-small gv-notes-delete"><?php echo $strings[ 'delete' ]; ?></button> |
|
58 | 58 | </th> |
59 | 59 | </tr> |
60 | 60 | </thead> |
61 | 61 | <?php } ?> |
62 | 62 | <tbody> |
63 | - <tr class="gv-notes-no-notes"><td colspan="2"><?php echo $strings['no-notes']; ?></td></tr> |
|
63 | + <tr class="gv-notes-no-notes"><td colspan="2"><?php echo $strings[ 'no-notes' ]; ?></td></tr> |
|
64 | 64 | <?php |
65 | 65 | foreach ( $notes as $note ) { |
66 | 66 | echo GravityView_Field_Notes::display_note( $note, $show_delete ); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | <?php |
74 | 74 | } // End if can view notes |
75 | 75 | |
76 | - if( $show_add ) { |
|
76 | + if ( $show_add ) { |
|
77 | 77 | echo do_shortcode( '[gv_note_add]' ); |
78 | 78 | } |
79 | 79 | ?> |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public static function get_instance() { |
87 | 87 | |
88 | - if( empty( self::$instance ) ) { |
|
88 | + if ( empty( self::$instance ) ) { |
|
89 | 89 | self::$instance = new self; |
90 | 90 | } |
91 | 91 | |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | |
119 | 119 | $operators = array_merge( self::$SUPPORTED_ARRAY_OPERATORS, self::$SUPPORTED_NUMERIC_OPERATORS, self::$SUPPORTED_SCALAR_OPERATORS, self::$SUPPORTED_CUSTOM_OPERATORS ); |
120 | 120 | |
121 | - if( $with_values ) { |
|
121 | + if ( $with_values ) { |
|
122 | 122 | $operators_with_values = array(); |
123 | - foreach( $operators as $key ) { |
|
123 | + foreach ( $operators as $key ) { |
|
124 | 124 | $operators_with_values[ $key ] = ''; |
125 | 125 | } |
126 | 126 | return $operators_with_values; |
@@ -137,14 +137,14 @@ discard block |
||
137 | 137 | */ |
138 | 138 | function set_operation( $operation = '' ) { |
139 | 139 | |
140 | - if( empty( $operation ) ) { |
|
140 | + if ( empty( $operation ) ) { |
|
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | |
144 | 144 | $operators = $this->get_operators( false ); |
145 | 145 | |
146 | - if( !in_array( $operation, $operators ) ) { |
|
147 | - do_action( 'gravityview_log_debug', __METHOD__ .' Attempted to add invalid operation type.', $operation ); |
|
146 | + if ( ! in_array( $operation, $operators ) ) { |
|
147 | + do_action( 'gravityview_log_debug', __METHOD__ . ' Attempted to add invalid operation type.', $operation ); |
|
148 | 148 | return false; |
149 | 149 | } |
150 | 150 | |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | */ |
165 | 165 | private function setup_operation_and_comparison() { |
166 | 166 | |
167 | - foreach( $this->atts as $key => $value ) { |
|
167 | + foreach ( $this->atts as $key => $value ) { |
|
168 | 168 | |
169 | 169 | $valid = $this->set_operation( $key ); |
170 | 170 | |
171 | - if( $valid ) { |
|
171 | + if ( $valid ) { |
|
172 | 172 | $this->comparison = $value; |
173 | 173 | return true; |
174 | 174 | } |
@@ -191,8 +191,8 @@ discard block |
||
191 | 191 | return null; |
192 | 192 | } |
193 | 193 | |
194 | - if( empty( $atts ) ) { |
|
195 | - do_action( 'gravityview_log_error', __METHOD__.' $atts are empty.', $atts ); |
|
194 | + if ( empty( $atts ) ) { |
|
195 | + do_action( 'gravityview_log_error', __METHOD__ . ' $atts are empty.', $atts ); |
|
196 | 196 | return null; |
197 | 197 | } |
198 | 198 | |
@@ -203,16 +203,16 @@ discard block |
||
203 | 203 | $this->parse_atts(); |
204 | 204 | |
205 | 205 | // We need an "if" |
206 | - if( false === $this->if ) { |
|
207 | - do_action( 'gravityview_log_error', __METHOD__.' $atts->if is empty.', $this->passed_atts ); |
|
206 | + if ( false === $this->if ) { |
|
207 | + do_action( 'gravityview_log_error', __METHOD__ . ' $atts->if is empty.', $this->passed_atts ); |
|
208 | 208 | return null; |
209 | 209 | } |
210 | 210 | |
211 | 211 | $setup = $this->setup_operation_and_comparison(); |
212 | 212 | |
213 | 213 | // We need an operation and comparison value |
214 | - if( ! $setup ) { |
|
215 | - do_action( 'gravityview_log_error', __METHOD__.' No valid operators were passed.', $this->atts ); |
|
214 | + if ( ! $setup ) { |
|
215 | + do_action( 'gravityview_log_error', __METHOD__ . ' No valid operators were passed.', $this->atts ); |
|
216 | 216 | return null; |
217 | 217 | } |
218 | 218 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | private function get_output() { |
247 | 247 | |
248 | - if( $this->is_match ) { |
|
248 | + if ( $this->is_match ) { |
|
249 | 249 | $output = $this->content; |
250 | 250 | } else { |
251 | 251 | $output = $this->else_content; |
@@ -259,9 +259,9 @@ discard block |
||
259 | 259 | * @param string $output HTML/text output |
260 | 260 | * @param GVLogic_Shortcode $this This class |
261 | 261 | */ |
262 | - $output = apply_filters('gravityview/gvlogic/output', $output, $this ); |
|
262 | + $output = apply_filters( 'gravityview/gvlogic/output', $output, $this ); |
|
263 | 263 | |
264 | - do_action( 'gravityview_log_debug', __METHOD__ .' Output: ', $output ); |
|
264 | + do_action( 'gravityview_log_debug', __METHOD__ . ' Output: ', $output ); |
|
265 | 265 | |
266 | 266 | return $output; |
267 | 267 | } |
@@ -277,11 +277,11 @@ discard block |
||
277 | 277 | |
278 | 278 | $content = explode( '[else]', $this->passed_content ); |
279 | 279 | |
280 | - $this->content = $content[0]; |
|
280 | + $this->content = $content[ 0 ]; |
|
281 | 281 | |
282 | - $else_attr = isset( $this->atts['else'] ) ? $this->atts['else'] : NULL; |
|
282 | + $else_attr = isset( $this->atts[ 'else' ] ) ? $this->atts[ 'else' ] : NULL; |
|
283 | 283 | |
284 | - $this->else_content = isset( $content[1] ) ? $content[1] : $else_attr; |
|
284 | + $this->else_content = isset( $content[ 1 ] ) ? $content[ 1 ] : $else_attr; |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -304,10 +304,10 @@ discard block |
||
304 | 304 | $this->atts = function_exists( 'array_intersect_key' ) ? array_intersect_key( $this->passed_atts, $this->atts ) : $this->atts; |
305 | 305 | |
306 | 306 | // Strip whitespace if it's not default false |
307 | - $this->if = is_string( $this->atts['if'] ) ? trim( $this->atts['if'] ) : false; |
|
307 | + $this->if = is_string( $this->atts[ 'if' ] ) ? trim( $this->atts[ 'if' ] ) : false; |
|
308 | 308 | |
309 | 309 | // Make sure the "if" isn't processed in self::setup_operation_and_comparison() |
310 | - unset( $this->atts['if'] ); |
|
310 | + unset( $this->atts[ 'if' ] ); |
|
311 | 311 | } |
312 | 312 | } |
313 | 313 |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | |
43 | 43 | add_action( 'wp', array( $this, 'process_delete' ), 10000 ); |
44 | 44 | |
45 | - add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field'), 10, 3 ); |
|
45 | + add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 ); |
|
46 | 46 | |
47 | 47 | add_action( 'gravityview_before', array( $this, 'display_message' ) ); |
48 | 48 | |
49 | 49 | // For the Delete Entry Link, you don't want visible to all users. |
50 | - add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps'), 10, 5 ); |
|
50 | + add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 ); |
|
51 | 51 | |
52 | 52 | // Modify the field options based on the name of the field type |
53 | 53 | add_filter( 'gravityview_template_delete_link_options', array( $this, 'delete_link_field_options' ), 10, 5 ); |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | // add template path to check for field |
56 | 56 | add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
57 | 57 | |
58 | - add_action( 'gravityview/edit-entry/publishing-action/after', array( $this, 'add_delete_button'), 10, 3 ); |
|
58 | + add_action( 'gravityview/edit-entry/publishing-action/after', array( $this, 'add_delete_button' ), 10, 3 ); |
|
59 | 59 | |
60 | - add_action ( 'gravityview/delete-entry/deleted', array( $this, 'process_connected_posts' ), 10, 2 ); |
|
61 | - add_action ( 'gravityview/delete-entry/trashed', array( $this, 'process_connected_posts' ), 10, 2 ); |
|
60 | + add_action( 'gravityview/delete-entry/deleted', array( $this, 'process_connected_posts' ), 10, 2 ); |
|
61 | + add_action( 'gravityview/delete-entry/trashed', array( $this, 'process_connected_posts' ), 10, 2 ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | static function getInstance() { |
71 | 71 | |
72 | - if( empty( self::$instance ) ) { |
|
72 | + if ( empty( self::$instance ) ) { |
|
73 | 73 | self::$instance = new self; |
74 | 74 | } |
75 | 75 | |
@@ -105,20 +105,20 @@ discard block |
||
105 | 105 | function delete_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
106 | 106 | |
107 | 107 | // Always a link, never a filter |
108 | - unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
108 | + unset( $field_options[ 'show_as_link' ], $field_options[ 'search_filter' ] ); |
|
109 | 109 | |
110 | 110 | // Delete Entry link should only appear to visitors capable of editing entries |
111 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
111 | + unset( $field_options[ 'only_loggedin' ], $field_options[ 'only_loggedin_cap' ] ); |
|
112 | 112 | |
113 | - $add_option['delete_link'] = array( |
|
113 | + $add_option[ 'delete_link' ] = array( |
|
114 | 114 | 'type' => 'text', |
115 | 115 | 'label' => __( 'Delete Link Text', 'gravityview' ), |
116 | 116 | 'desc' => NULL, |
117 | - 'value' => __('Delete Entry', 'gravityview'), |
|
117 | + 'value' => __( 'Delete Entry', 'gravityview' ), |
|
118 | 118 | 'merge_tags' => true, |
119 | 119 | ); |
120 | 120 | |
121 | - $field_options['allow_edit_cap'] = array( |
|
121 | + $field_options[ 'allow_edit_cap' ] = array( |
|
122 | 122 | 'type' => 'select', |
123 | 123 | 'label' => __( 'Allow the following users to delete the entry:', 'gravityview' ), |
124 | 124 | 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | */ |
143 | 143 | function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
144 | 144 | |
145 | - $entry_default_fields['delete_link'] = array( |
|
146 | - 'label' => __('Delete Entry', 'gravityview'), |
|
145 | + $entry_default_fields[ 'delete_link' ] = array( |
|
146 | + 'label' => __( 'Delete Entry', 'gravityview' ), |
|
147 | 147 | 'type' => 'delete_link', |
148 | - 'desc' => __('A link to delete the entry. Respects the Delete Entry permissions.', 'gravityview'), |
|
148 | + 'desc' => __( 'A link to delete the entry. Respects the Delete Entry permissions.', 'gravityview' ), |
|
149 | 149 | ); |
150 | 150 | |
151 | 151 | return $entry_default_fields; |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | function add_available_field( $available_fields = array() ) { |
160 | 160 | |
161 | - $available_fields['delete_link'] = array( |
|
161 | + $available_fields[ 'delete_link' ] = array( |
|
162 | 162 | 'label_text' => __( 'Delete Entry', 'gravityview' ), |
163 | 163 | 'field_id' => 'delete_link', |
164 | 164 | 'label_type' => 'field', |
@@ -186,12 +186,12 @@ discard block |
||
186 | 186 | $caps = $visibility_caps; |
187 | 187 | |
188 | 188 | // If we're configuring fields in the edit context, we want a limited selection |
189 | - if( $field_id === 'delete_link' ) { |
|
189 | + if ( $field_id === 'delete_link' ) { |
|
190 | 190 | |
191 | 191 | // Remove other built-in caps. |
192 | - unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
192 | + unset( $caps[ 'publish_posts' ], $caps[ 'gravityforms_view_entries' ], $caps[ 'delete_others_posts' ] ); |
|
193 | 193 | |
194 | - $caps['read'] = _x('Entry Creator', 'User capability', 'gravityview'); |
|
194 | + $caps[ 'read' ] = _x( 'Entry Creator', 'User capability', 'gravityview' ); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | return $caps; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @param [type] $entry [description] |
205 | 205 | */ |
206 | 206 | function set_entry( $entry = null ) { |
207 | - $this->entry = empty( $entry ) ? GravityView_View::getInstance()->entries[0] : $entry; |
|
207 | + $this->entry = empty( $entry ) ? GravityView_View::getInstance()->entries[ 0 ] : $entry; |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -234,13 +234,13 @@ discard block |
||
234 | 234 | |
235 | 235 | $base = GravityView_API::directory_link( $post_id, true ); |
236 | 236 | |
237 | - if( empty( $base ) ) { |
|
238 | - do_action( 'gravityview_log_error', __METHOD__ . ' - Post ID does not exist: '.$post_id ); |
|
237 | + if ( empty( $base ) ) { |
|
238 | + do_action( 'gravityview_log_error', __METHOD__ . ' - Post ID does not exist: ' . $post_id ); |
|
239 | 239 | return NULL; |
240 | 240 | } |
241 | 241 | |
242 | 242 | // Use the slug instead of the ID for consistent security |
243 | - $entry_slug = GravityView_API::get_entry_slug( $entry['id'], $entry ); |
|
243 | + $entry_slug = GravityView_API::get_entry_slug( $entry[ 'id' ], $entry ); |
|
244 | 244 | |
245 | 245 | $view_id = empty( $view_id ) ? gravityview_get_view_id() : $view_id; |
246 | 246 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | 'view_id' => $view_id, |
252 | 252 | ), $base ); |
253 | 253 | |
254 | - $url = wp_nonce_url( $actionurl, 'delete_'.$entry_slug, 'delete' ); |
|
254 | + $url = wp_nonce_url( $actionurl, 'delete_' . $entry_slug, 'delete' ); |
|
255 | 255 | |
256 | 256 | return $url; |
257 | 257 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | function add_delete_button( $form = array(), $entry = array(), $view_id = NULL ) { |
269 | 269 | |
270 | 270 | // Only show the link to those who are allowed to see it. |
271 | - if( !self::check_user_cap_delete_entry( $entry ) ) { |
|
271 | + if ( ! self::check_user_cap_delete_entry( $entry ) ) { |
|
272 | 272 | return; |
273 | 273 | } |
274 | 274 | |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | $show_delete_button = apply_filters( 'gravityview/delete-entry/show-delete-button', true ); |
280 | 280 | |
281 | 281 | // If the button is hidden by the filter, don't show. |
282 | - if( !$show_delete_button ) { |
|
282 | + if ( ! $show_delete_button ) { |
|
283 | 283 | return; |
284 | 284 | } |
285 | 285 | |
@@ -309,27 +309,27 @@ discard block |
||
309 | 309 | function process_delete() { |
310 | 310 | |
311 | 311 | // If the form is submitted |
312 | - if( isset( $_GET['action'] ) && 'delete' === $_GET['action'] && isset( $_GET['entry_id'] ) ) { |
|
312 | + if ( isset( $_GET[ 'action' ] ) && 'delete' === $_GET[ 'action' ] && isset( $_GET[ 'entry_id' ] ) ) { |
|
313 | 313 | |
314 | 314 | // Make sure it's a GravityView request |
315 | - $valid_nonce_key = wp_verify_nonce( $_GET['delete'], self::get_nonce_key( $_GET['entry_id'] ) ); |
|
315 | + $valid_nonce_key = wp_verify_nonce( $_GET[ 'delete' ], self::get_nonce_key( $_GET[ 'entry_id' ] ) ); |
|
316 | 316 | |
317 | - if( ! $valid_nonce_key ) { |
|
318 | - do_action('gravityview_log_debug', __METHOD__ . ' Delete entry not processed: nonce validation failed.' ); |
|
317 | + if ( ! $valid_nonce_key ) { |
|
318 | + do_action( 'gravityview_log_debug', __METHOD__ . ' Delete entry not processed: nonce validation failed.' ); |
|
319 | 319 | return; |
320 | 320 | } |
321 | 321 | |
322 | 322 | // Get the entry slug |
323 | - $entry_slug = esc_attr( $_GET['entry_id'] ); |
|
323 | + $entry_slug = esc_attr( $_GET[ 'entry_id' ] ); |
|
324 | 324 | |
325 | 325 | // See if there's an entry there |
326 | 326 | $entry = gravityview_get_entry( $entry_slug ); |
327 | 327 | |
328 | - if( $entry ) { |
|
328 | + if ( $entry ) { |
|
329 | 329 | |
330 | 330 | $has_permission = $this->user_can_delete_entry( $entry ); |
331 | 331 | |
332 | - if( is_wp_error( $has_permission ) ) { |
|
332 | + if ( is_wp_error( $has_permission ) ) { |
|
333 | 333 | |
334 | 334 | $messages = array( |
335 | 335 | 'message' => urlencode( $has_permission->get_error_message() ), |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | // Delete the entry |
342 | 342 | $delete_response = $this->delete_or_trash_entry( $entry ); |
343 | 343 | |
344 | - if( is_wp_error( $delete_response ) ) { |
|
344 | + if ( is_wp_error( $delete_response ) ) { |
|
345 | 345 | |
346 | 346 | $messages = array( |
347 | 347 | 'message' => urlencode( $delete_response->get_error_message() ), |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | |
361 | 361 | } else { |
362 | 362 | |
363 | - do_action('gravityview_log_debug', __METHOD__ . ' Delete entry failed: there was no entry with the entry slug '. $entry_slug ); |
|
363 | + do_action( 'gravityview_log_debug', __METHOD__ . ' Delete entry failed: there was no entry with the entry slug ' . $entry_slug ); |
|
364 | 364 | |
365 | 365 | $messages = array( |
366 | - 'message' => urlencode( __('The entry does not exist.', 'gravityview') ), |
|
366 | + 'message' => urlencode( __( 'The entry does not exist.', 'gravityview' ) ), |
|
367 | 367 | 'status' => 'error', |
368 | 368 | ); |
369 | 369 | } |
@@ -403,18 +403,18 @@ discard block |
||
403 | 403 | */ |
404 | 404 | private function delete_or_trash_entry( $entry ) { |
405 | 405 | |
406 | - $entry_id = $entry['id']; |
|
406 | + $entry_id = $entry[ 'id' ]; |
|
407 | 407 | |
408 | 408 | $mode = $this->get_delete_mode(); |
409 | 409 | |
410 | - if( 'delete' === $mode ) { |
|
410 | + if ( 'delete' === $mode ) { |
|
411 | 411 | |
412 | 412 | do_action( 'gravityview_log_debug', __METHOD__ . ' Starting delete entry: ', $entry_id ); |
413 | 413 | |
414 | 414 | // Delete the entry |
415 | 415 | $delete_response = GFAPI::delete_entry( $entry_id ); |
416 | 416 | |
417 | - if( ! is_wp_error( $delete_response ) ) { |
|
417 | + if ( ! is_wp_error( $delete_response ) ) { |
|
418 | 418 | $delete_response = 'deleted'; |
419 | 419 | |
420 | 420 | /** |
@@ -435,8 +435,8 @@ discard block |
||
435 | 435 | $trashed = GFAPI::update_entry_property( $entry_id, 'status', 'trash' ); |
436 | 436 | new GravityView_Cache; |
437 | 437 | |
438 | - if( ! $trashed ) { |
|
439 | - $delete_response = new WP_Error( 'trash_entry_failed', __('Moving the entry to the trash failed.', 'gravityview' ) ); |
|
438 | + if ( ! $trashed ) { |
|
439 | + $delete_response = new WP_Error( 'trash_entry_failed', __( 'Moving the entry to the trash failed.', 'gravityview' ) ); |
|
440 | 440 | } else { |
441 | 441 | |
442 | 442 | /** |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | public function process_connected_posts( $entry_id = 0, $entry = array() ) { |
468 | 468 | |
469 | 469 | // The entry had no connected post |
470 | - if( empty( $entry['post_id'] ) ) { |
|
470 | + if ( empty( $entry[ 'post_id' ] ) ) { |
|
471 | 471 | return; |
472 | 472 | } |
473 | 473 | |
@@ -478,22 +478,22 @@ discard block |
||
478 | 478 | */ |
479 | 479 | $delete_post = apply_filters( 'gravityview/delete-entry/delete-connected-post', true ); |
480 | 480 | |
481 | - if( false === $delete_post ) { |
|
481 | + if ( false === $delete_post ) { |
|
482 | 482 | return; |
483 | 483 | } |
484 | 484 | |
485 | 485 | $action = current_action(); |
486 | 486 | |
487 | - if( 'gravityview/delete-entry/deleted' === $action ) { |
|
488 | - $result = wp_delete_post( $entry['post_id'], true ); |
|
487 | + if ( 'gravityview/delete-entry/deleted' === $action ) { |
|
488 | + $result = wp_delete_post( $entry[ 'post_id' ], true ); |
|
489 | 489 | } else { |
490 | - $result = wp_trash_post( $entry['post_id'] ); |
|
490 | + $result = wp_trash_post( $entry[ 'post_id' ] ); |
|
491 | 491 | } |
492 | 492 | |
493 | - if( false === $result ) { |
|
494 | - do_action( 'gravityview_log_error', __METHOD__ . ' (called by '.$action.'): Error processing the Post connected to the entry.', $entry ); |
|
493 | + if ( false === $result ) { |
|
494 | + do_action( 'gravityview_log_error', __METHOD__ . ' (called by ' . $action . '): Error processing the Post connected to the entry.', $entry ); |
|
495 | 495 | } else { |
496 | - do_action( 'gravityview_log_debug', __METHOD__ . ' (called by '.$action.'): Successfully processed Post connected to the entry.', $entry ); |
|
496 | + do_action( 'gravityview_log_debug', __METHOD__ . ' (called by ' . $action . '): Successfully processed Post connected to the entry.', $entry ); |
|
497 | 497 | } |
498 | 498 | } |
499 | 499 | |
@@ -506,13 +506,13 @@ discard block |
||
506 | 506 | public function verify_nonce() { |
507 | 507 | |
508 | 508 | // No delete entry request was made |
509 | - if( empty( $_GET['entry_id'] ) || empty( $_GET['delete'] ) ) { |
|
509 | + if ( empty( $_GET[ 'entry_id' ] ) || empty( $_GET[ 'delete' ] ) ) { |
|
510 | 510 | return false; |
511 | 511 | } |
512 | 512 | |
513 | - $nonce_key = self::get_nonce_key( $_GET['entry_id'] ); |
|
513 | + $nonce_key = self::get_nonce_key( $_GET[ 'entry_id' ] ); |
|
514 | 514 | |
515 | - $valid = wp_verify_nonce( $_GET['delete'], $nonce_key ); |
|
515 | + $valid = wp_verify_nonce( $_GET[ 'delete' ], $nonce_key ); |
|
516 | 516 | |
517 | 517 | /** |
518 | 518 | * @filter `gravityview/delete-entry/verify_nonce` Override Delete Entry nonce validation. Return true to declare nonce valid. |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | */ |
535 | 535 | public static function get_confirm_dialog() { |
536 | 536 | |
537 | - $confirm = __('Are you sure you want to delete this entry? This cannot be undone.', 'gravityview'); |
|
537 | + $confirm = __( 'Are you sure you want to delete this entry? This cannot be undone.', 'gravityview' ); |
|
538 | 538 | |
539 | 539 | /** |
540 | 540 | * @filter `gravityview/delete-entry/confirm-text` Modify the Delete Entry Javascript confirmation text |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | */ |
543 | 543 | $confirm = apply_filters( 'gravityview/delete-entry/confirm-text', $confirm ); |
544 | 544 | |
545 | - return 'return window.confirm(\''. esc_js( $confirm ) .'\');'; |
|
545 | + return 'return window.confirm(\'' . esc_js( $confirm ) . '\');'; |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -560,16 +560,16 @@ discard block |
||
560 | 560 | |
561 | 561 | $error = NULL; |
562 | 562 | |
563 | - if( ! $this->verify_nonce() ) { |
|
564 | - $error = __( 'The link to delete this entry is not valid; it may have expired.', 'gravityview'); |
|
563 | + if ( ! $this->verify_nonce() ) { |
|
564 | + $error = __( 'The link to delete this entry is not valid; it may have expired.', 'gravityview' ); |
|
565 | 565 | } |
566 | 566 | |
567 | - if( ! self::check_user_cap_delete_entry( $entry ) ) { |
|
568 | - $error = __( 'You do not have permission to delete this entry.', 'gravityview'); |
|
567 | + if ( ! self::check_user_cap_delete_entry( $entry ) ) { |
|
568 | + $error = __( 'You do not have permission to delete this entry.', 'gravityview' ); |
|
569 | 569 | } |
570 | 570 | |
571 | - if( $entry['status'] === 'trash' ) { |
|
572 | - if( 'trash' === $this->get_delete_mode() ) { |
|
571 | + if ( $entry[ 'status' ] === 'trash' ) { |
|
572 | + if ( 'trash' === $this->get_delete_mode() ) { |
|
573 | 573 | $error = __( 'The entry is already in the trash.', 'gravityview' ); |
574 | 574 | } else { |
575 | 575 | $error = __( 'You cannot delete the entry; it is already in the trash.', 'gravityview' ); |
@@ -577,11 +577,11 @@ discard block |
||
577 | 577 | } |
578 | 578 | |
579 | 579 | // No errors; everything's fine here! |
580 | - if( empty( $error ) ) { |
|
580 | + if ( empty( $error ) ) { |
|
581 | 581 | return true; |
582 | 582 | } |
583 | 583 | |
584 | - do_action('gravityview_log_error', 'GravityView_Delete_Entry[user_can_delete_entry]' . $error ); |
|
584 | + do_action( 'gravityview_log_error', 'GravityView_Delete_Entry[user_can_delete_entry]' . $error ); |
|
585 | 585 | |
586 | 586 | return new WP_Error( 'gravityview-delete-entry-permissions', $error ); |
587 | 587 | } |
@@ -603,32 +603,32 @@ discard block |
||
603 | 603 | |
604 | 604 | $current_user = wp_get_current_user(); |
605 | 605 | |
606 | - $entry_id = isset( $entry['id'] ) ? $entry['id'] : NULL; |
|
606 | + $entry_id = isset( $entry[ 'id' ] ) ? $entry[ 'id' ] : NULL; |
|
607 | 607 | |
608 | 608 | // Or if they can delete any entries (as defined in Gravity Forms), we're good. |
609 | - if( GVCommon::has_cap( array( 'gravityforms_delete_entries', 'gravityview_delete_others_entries' ), $entry_id ) ) { |
|
609 | + if ( GVCommon::has_cap( array( 'gravityforms_delete_entries', 'gravityview_delete_others_entries' ), $entry_id ) ) { |
|
610 | 610 | |
611 | - do_action('gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Current user has `gravityforms_delete_entries` or `gravityview_delete_others_entries` capability.' ); |
|
611 | + do_action( 'gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Current user has `gravityforms_delete_entries` or `gravityview_delete_others_entries` capability.' ); |
|
612 | 612 | |
613 | 613 | return true; |
614 | 614 | } |
615 | 615 | |
616 | 616 | |
617 | 617 | // If field options are passed, check if current user can view the link |
618 | - if( !empty( $field ) ) { |
|
618 | + if ( ! empty( $field ) ) { |
|
619 | 619 | |
620 | 620 | // If capability is not defined, something is not right! |
621 | - if( empty( $field['allow_edit_cap'] ) ) { |
|
621 | + if ( empty( $field[ 'allow_edit_cap' ] ) ) { |
|
622 | 622 | |
623 | 623 | do_action( 'gravityview_log_error', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Cannot read delete entry field caps', $field ); |
624 | 624 | |
625 | 625 | return false; |
626 | 626 | } |
627 | 627 | |
628 | - if( GVCommon::has_cap( $field['allow_edit_cap'] ) ) { |
|
628 | + if ( GVCommon::has_cap( $field[ 'allow_edit_cap' ] ) ) { |
|
629 | 629 | |
630 | 630 | // Do not return true if cap is read, as we need to check if the current user created the entry |
631 | - if( $field['allow_edit_cap'] !== 'read' ) { |
|
631 | + if ( $field[ 'allow_edit_cap' ] !== 'read' ) { |
|
632 | 632 | return true; |
633 | 633 | } |
634 | 634 | |
@@ -641,9 +641,9 @@ discard block |
||
641 | 641 | |
642 | 642 | } |
643 | 643 | |
644 | - if( !isset( $entry['created_by'] ) ) { |
|
644 | + if ( ! isset( $entry[ 'created_by' ] ) ) { |
|
645 | 645 | |
646 | - do_action('gravityview_log_error', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Entry `created_by` doesn\'t exist.'); |
|
646 | + do_action( 'gravityview_log_error', 'GravityView_Delete_Entry[check_user_cap_delete_entry] Entry `created_by` doesn\'t exist.' ); |
|
647 | 647 | |
648 | 648 | return false; |
649 | 649 | } |
@@ -651,24 +651,24 @@ discard block |
||
651 | 651 | $view_id = empty( $view_id ) ? $gravityview_view->getViewId() : $view_id; |
652 | 652 | |
653 | 653 | // Only checks user_delete view option if view is already set |
654 | - if( $view_id ) { |
|
654 | + if ( $view_id ) { |
|
655 | 655 | |
656 | 656 | $current_view = gravityview_get_current_view_data( $view_id ); |
657 | 657 | |
658 | - $user_delete = isset( $current_view['atts']['user_delete'] ) ? $current_view['atts']['user_delete'] : false; |
|
658 | + $user_delete = isset( $current_view[ 'atts' ][ 'user_delete' ] ) ? $current_view[ 'atts' ][ 'user_delete' ] : false; |
|
659 | 659 | |
660 | - if( empty( $user_delete ) ) { |
|
660 | + if ( empty( $user_delete ) ) { |
|
661 | 661 | |
662 | - do_action('gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] User Delete is disabled. Returning false.' ); |
|
662 | + do_action( 'gravityview_log_debug', 'GravityView_Delete_Entry[check_user_cap_delete_entry] User Delete is disabled. Returning false.' ); |
|
663 | 663 | |
664 | 664 | return false; |
665 | 665 | } |
666 | 666 | } |
667 | 667 | |
668 | 668 | // If the logged-in user is the same as the user who created the entry, we're good. |
669 | - if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
669 | + if ( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry[ 'created_by' ] ) ) { |
|
670 | 670 | |
671 | - do_action('gravityview_log_debug', sprintf( 'GravityView_Delete_Entry[check_user_cap_delete_entry] User %s created the entry.', $current_user->ID ) ); |
|
671 | + do_action( 'gravityview_log_debug', sprintf( 'GravityView_Delete_Entry[check_user_cap_delete_entry] User %s created the entry.', $current_user->ID ) ); |
|
672 | 672 | |
673 | 673 | return true; |
674 | 674 | } |
@@ -691,31 +691,31 @@ discard block |
||
691 | 691 | */ |
692 | 692 | public function display_message( $current_view_id = 0 ) { |
693 | 693 | |
694 | - if( empty( $_GET['status'] ) || ! self::verify_nonce() ) { |
|
694 | + if ( empty( $_GET[ 'status' ] ) || ! self::verify_nonce() ) { |
|
695 | 695 | return; |
696 | 696 | } |
697 | 697 | |
698 | 698 | // Entry wasn't deleted from current View |
699 | - if( intval( $_GET['gvid'] ) !== intval( $current_view_id ) ) { |
|
699 | + if ( intval( $_GET[ 'gvid' ] ) !== intval( $current_view_id ) ) { |
|
700 | 700 | return; |
701 | 701 | } |
702 | 702 | |
703 | - $status = esc_attr( $_GET['status'] ); |
|
704 | - $message_from_url = rgget('message'); |
|
703 | + $status = esc_attr( $_GET[ 'status' ] ); |
|
704 | + $message_from_url = rgget( 'message' ); |
|
705 | 705 | $message_from_url = urldecode( stripslashes_deep( $message_from_url ) ); |
706 | 706 | $class = ''; |
707 | 707 | |
708 | 708 | switch ( $status ) { |
709 | 709 | case 'error': |
710 | 710 | $class = ' gv-error error'; |
711 | - $error_message = __('There was an error deleting the entry: %s', 'gravityview'); |
|
711 | + $error_message = __( 'There was an error deleting the entry: %s', 'gravityview' ); |
|
712 | 712 | $message = sprintf( $error_message, $message_from_url ); |
713 | 713 | break; |
714 | 714 | case 'trashed': |
715 | - $message = __('The entry was successfully moved to the trash.', 'gravityview'); |
|
715 | + $message = __( 'The entry was successfully moved to the trash.', 'gravityview' ); |
|
716 | 716 | break; |
717 | 717 | default: |
718 | - $message = __('The entry was successfully deleted.', 'gravityview'); |
|
718 | + $message = __( 'The entry was successfully deleted.', 'gravityview' ); |
|
719 | 719 | break; |
720 | 720 | } |
721 | 721 | |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | $message = apply_filters( 'gravityview/delete-entry/message', esc_attr( $message ), $status, $message_from_url ); |
730 | 730 | |
731 | 731 | // DISPLAY ERROR/SUCCESS MESSAGE |
732 | - echo '<div class="gv-notice' . esc_attr( $class ) .'">'. $message .'</div>'; |
|
732 | + echo '<div class="gv-notice' . esc_attr( $class ) . '">' . $message . '</div>'; |
|
733 | 733 | } |
734 | 734 | |
735 | 735 |
@@ -7,183 +7,183 @@ |
||
7 | 7 | |
8 | 8 | class GravityView_GFFormsModel extends GFFormsModel { |
9 | 9 | |
10 | - /** |
|
11 | - * Copied function from Gravity Forms plugin \GFFormsModel::copy_post_image since the method is private. |
|
12 | - * |
|
13 | - * @since 1.16.2 |
|
14 | - * |
|
15 | - * @param string $url URL of the post image to update |
|
16 | - * @param int $post_id ID of the post image to update |
|
17 | - * @return array|bool Array with `file`, `url` and `type` keys. False: failed to copy file to final directory path. |
|
18 | - */ |
|
19 | - public static function copy_post_image( $url, $post_id ) { |
|
20 | - |
|
21 | - $reflection = new ReflectionMethod( 'GFFormsModel', 'copy_post_image' ); |
|
22 | - |
|
23 | - /** |
|
24 | - * If the method changes to public, use Gravity Forms' method |
|
25 | - * @todo: If/when the method is public, remove the unneeded copied code. |
|
26 | - */ |
|
27 | - if( $reflection->isPublic() ) { |
|
28 | - return parent::copy_post_image( $url, $post_id ); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Original Gravity Forms code below: |
|
33 | - * ================================== |
|
34 | - */ |
|
35 | - |
|
36 | - $time = current_time( 'mysql' ); |
|
37 | - |
|
38 | - if ( $post = get_post( $post_id ) ) { |
|
39 | - if ( substr( $post->post_date, 0, 4 ) > 0 ) { |
|
40 | - $time = $post->post_date; |
|
41 | - } |
|
42 | - } |
|
43 | - |
|
44 | - //making sure there is a valid upload folder |
|
45 | - if ( ! ( ( $upload_dir = wp_upload_dir( $time ) ) && false === $upload_dir['error'] ) ) { |
|
46 | - return false; |
|
47 | - } |
|
48 | - |
|
49 | - $form_id = get_post_meta( $post_id, '_gform-form-id', true ); |
|
50 | - |
|
51 | - /** |
|
52 | - * Filter the media upload location. |
|
53 | - * |
|
54 | - * @param array $upload_dir The current upload directory’s path and url. |
|
55 | - * @param int $form_id The ID of the form currently being processed. |
|
56 | - * @param int $post_id The ID of the post created from the entry currently being processed. |
|
57 | - */ |
|
58 | - $upload_dir = gf_apply_filters( 'gform_media_upload_path', $form_id, $upload_dir, $form_id, $post_id ); |
|
59 | - |
|
60 | - if ( ! file_exists( $upload_dir['path'] ) ) { |
|
61 | - if ( ! wp_mkdir_p( $upload_dir['path'] ) ) { |
|
62 | - return false; |
|
63 | - } |
|
64 | - } |
|
65 | - |
|
66 | - $name = basename( $url ); |
|
67 | - $filename = wp_unique_filename( $upload_dir['path'], $name ); |
|
68 | - |
|
69 | - // the destination path |
|
70 | - $new_file = $upload_dir['path'] . "/$filename"; |
|
71 | - |
|
72 | - // the source path |
|
73 | - $y = substr( $time, 0, 4 ); |
|
74 | - $m = substr( $time, 5, 2 ); |
|
75 | - $target_root = RGFormsModel::get_upload_path( $form_id ) . "/$y/$m/"; |
|
76 | - $target_root_url = RGFormsModel::get_upload_url( $form_id ) . "/$y/$m/"; |
|
77 | - $upload_root_info = array( 'path' => $target_root, 'url' => $target_root_url ); |
|
78 | - $upload_root_info = gf_apply_filters( 'gform_upload_path', $form_id, $upload_root_info, $form_id ); |
|
79 | - $path = str_replace( $upload_root_info['url'], $upload_root_info['path'], $url ); |
|
80 | - |
|
81 | - // copy the file to the destination path |
|
82 | - if ( ! copy( $path, $new_file ) ) { |
|
83 | - return false; |
|
84 | - } |
|
85 | - |
|
86 | - // Set correct file permissions |
|
87 | - $stat = stat( dirname( $new_file ) ); |
|
88 | - $perms = $stat['mode'] & 0000666; |
|
89 | - @ chmod( $new_file, $perms ); |
|
90 | - |
|
91 | - // Compute the URL |
|
92 | - $url = $upload_dir['url'] . "/$filename"; |
|
93 | - |
|
94 | - if ( is_multisite() ) { |
|
95 | - delete_transient( 'dirsize_cache' ); |
|
96 | - } |
|
97 | - |
|
98 | - $type = wp_check_filetype( $new_file ); |
|
99 | - |
|
100 | - return array( 'file' => $new_file, 'url' => $url, 'type' => $type['type'] ); |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Copied function from Gravity Forms plugin \GFFormsModel::media_handle_upload since the method is private. |
|
106 | - * |
|
107 | - * Note: The method became public in GF 1.9.17.7 |
|
108 | - * |
|
109 | - * @see GFFormsModel::media_handle_upload |
|
110 | - * @see GravityView_Edit_Entry_Render::maybe_update_post_fields |
|
111 | - * |
|
112 | - * @uses copy_post_image |
|
113 | - * @uses wp_insert_attachment |
|
114 | - * @uses wp_update_attachment_metadata |
|
115 | - * |
|
116 | - * @param string $url URL of the post image to update |
|
117 | - * @param int $post_id ID of the post image to update |
|
118 | - * @param array $post_data Array of data for the eventual attachment post type that is created using {@see wp_insert_attachment}. Supports `post_mime_type`, `guid`, `post_parent`, `post_title`, `post_content` keys. |
|
119 | - * @return bool|int ID of attachment Post created. Returns false if file not created by copy_post_image |
|
120 | - */ |
|
121 | - public static function media_handle_upload( $url, $post_id, $post_data = array() ) { |
|
122 | - |
|
123 | - $reflection = new ReflectionMethod( 'GFFormsModel', 'media_handle_upload' ); |
|
124 | - |
|
125 | - /** |
|
126 | - * If the method changes to public, use Gravity Forms' method |
|
127 | - * @todo: If/when the method is public, remove the unneeded copied code. |
|
128 | - */ |
|
129 | - if( $reflection->isPublic() ) { |
|
130 | - return parent::media_handle_upload( $url, $post_id, $post_data ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Original Gravity Forms code below: |
|
135 | - * ================================== |
|
136 | - */ |
|
137 | - |
|
138 | - //WordPress Administration API required for the media_handle_upload() function |
|
139 | - require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
|
140 | - |
|
141 | - $name = basename( $url ); |
|
142 | - |
|
143 | - $file = self::copy_post_image( $url, $post_id ); |
|
144 | - |
|
145 | - if ( ! $file ) { |
|
146 | - return false; |
|
147 | - } |
|
148 | - |
|
149 | - $name_parts = pathinfo( $name ); |
|
150 | - $name = trim( substr( $name, 0, - ( 1 + strlen( $name_parts['extension'] ) ) ) ); |
|
151 | - |
|
152 | - $url = $file['url']; |
|
153 | - $type = $file['type']; |
|
154 | - $file = $file['file']; |
|
155 | - $title = $name; |
|
156 | - $content = ''; |
|
157 | - |
|
158 | - // use image exif/iptc data for title and caption defaults if possible |
|
159 | - if ( $image_meta = @wp_read_image_metadata( $file ) ) { |
|
160 | - if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { |
|
161 | - $title = $image_meta['title']; |
|
162 | - } |
|
163 | - if ( trim( $image_meta['caption'] ) ) { |
|
164 | - $content = $image_meta['caption']; |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - // Construct the attachment array |
|
169 | - $attachment = array_merge( |
|
170 | - array( |
|
171 | - 'post_mime_type' => $type, |
|
172 | - 'guid' => $url, |
|
173 | - 'post_parent' => $post_id, |
|
174 | - 'post_title' => $title, |
|
175 | - 'post_content' => $content, |
|
176 | - ), $post_data |
|
177 | - ); |
|
178 | - |
|
179 | - // Save the data |
|
180 | - $id = wp_insert_attachment( $attachment, $file, $post_id ); |
|
181 | - if ( ! is_wp_error( $id ) ) { |
|
182 | - wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
|
183 | - } |
|
184 | - |
|
185 | - return $id; |
|
186 | - } |
|
10 | + /** |
|
11 | + * Copied function from Gravity Forms plugin \GFFormsModel::copy_post_image since the method is private. |
|
12 | + * |
|
13 | + * @since 1.16.2 |
|
14 | + * |
|
15 | + * @param string $url URL of the post image to update |
|
16 | + * @param int $post_id ID of the post image to update |
|
17 | + * @return array|bool Array with `file`, `url` and `type` keys. False: failed to copy file to final directory path. |
|
18 | + */ |
|
19 | + public static function copy_post_image( $url, $post_id ) { |
|
20 | + |
|
21 | + $reflection = new ReflectionMethod( 'GFFormsModel', 'copy_post_image' ); |
|
22 | + |
|
23 | + /** |
|
24 | + * If the method changes to public, use Gravity Forms' method |
|
25 | + * @todo: If/when the method is public, remove the unneeded copied code. |
|
26 | + */ |
|
27 | + if( $reflection->isPublic() ) { |
|
28 | + return parent::copy_post_image( $url, $post_id ); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Original Gravity Forms code below: |
|
33 | + * ================================== |
|
34 | + */ |
|
35 | + |
|
36 | + $time = current_time( 'mysql' ); |
|
37 | + |
|
38 | + if ( $post = get_post( $post_id ) ) { |
|
39 | + if ( substr( $post->post_date, 0, 4 ) > 0 ) { |
|
40 | + $time = $post->post_date; |
|
41 | + } |
|
42 | + } |
|
43 | + |
|
44 | + //making sure there is a valid upload folder |
|
45 | + if ( ! ( ( $upload_dir = wp_upload_dir( $time ) ) && false === $upload_dir['error'] ) ) { |
|
46 | + return false; |
|
47 | + } |
|
48 | + |
|
49 | + $form_id = get_post_meta( $post_id, '_gform-form-id', true ); |
|
50 | + |
|
51 | + /** |
|
52 | + * Filter the media upload location. |
|
53 | + * |
|
54 | + * @param array $upload_dir The current upload directory’s path and url. |
|
55 | + * @param int $form_id The ID of the form currently being processed. |
|
56 | + * @param int $post_id The ID of the post created from the entry currently being processed. |
|
57 | + */ |
|
58 | + $upload_dir = gf_apply_filters( 'gform_media_upload_path', $form_id, $upload_dir, $form_id, $post_id ); |
|
59 | + |
|
60 | + if ( ! file_exists( $upload_dir['path'] ) ) { |
|
61 | + if ( ! wp_mkdir_p( $upload_dir['path'] ) ) { |
|
62 | + return false; |
|
63 | + } |
|
64 | + } |
|
65 | + |
|
66 | + $name = basename( $url ); |
|
67 | + $filename = wp_unique_filename( $upload_dir['path'], $name ); |
|
68 | + |
|
69 | + // the destination path |
|
70 | + $new_file = $upload_dir['path'] . "/$filename"; |
|
71 | + |
|
72 | + // the source path |
|
73 | + $y = substr( $time, 0, 4 ); |
|
74 | + $m = substr( $time, 5, 2 ); |
|
75 | + $target_root = RGFormsModel::get_upload_path( $form_id ) . "/$y/$m/"; |
|
76 | + $target_root_url = RGFormsModel::get_upload_url( $form_id ) . "/$y/$m/"; |
|
77 | + $upload_root_info = array( 'path' => $target_root, 'url' => $target_root_url ); |
|
78 | + $upload_root_info = gf_apply_filters( 'gform_upload_path', $form_id, $upload_root_info, $form_id ); |
|
79 | + $path = str_replace( $upload_root_info['url'], $upload_root_info['path'], $url ); |
|
80 | + |
|
81 | + // copy the file to the destination path |
|
82 | + if ( ! copy( $path, $new_file ) ) { |
|
83 | + return false; |
|
84 | + } |
|
85 | + |
|
86 | + // Set correct file permissions |
|
87 | + $stat = stat( dirname( $new_file ) ); |
|
88 | + $perms = $stat['mode'] & 0000666; |
|
89 | + @ chmod( $new_file, $perms ); |
|
90 | + |
|
91 | + // Compute the URL |
|
92 | + $url = $upload_dir['url'] . "/$filename"; |
|
93 | + |
|
94 | + if ( is_multisite() ) { |
|
95 | + delete_transient( 'dirsize_cache' ); |
|
96 | + } |
|
97 | + |
|
98 | + $type = wp_check_filetype( $new_file ); |
|
99 | + |
|
100 | + return array( 'file' => $new_file, 'url' => $url, 'type' => $type['type'] ); |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Copied function from Gravity Forms plugin \GFFormsModel::media_handle_upload since the method is private. |
|
106 | + * |
|
107 | + * Note: The method became public in GF 1.9.17.7 |
|
108 | + * |
|
109 | + * @see GFFormsModel::media_handle_upload |
|
110 | + * @see GravityView_Edit_Entry_Render::maybe_update_post_fields |
|
111 | + * |
|
112 | + * @uses copy_post_image |
|
113 | + * @uses wp_insert_attachment |
|
114 | + * @uses wp_update_attachment_metadata |
|
115 | + * |
|
116 | + * @param string $url URL of the post image to update |
|
117 | + * @param int $post_id ID of the post image to update |
|
118 | + * @param array $post_data Array of data for the eventual attachment post type that is created using {@see wp_insert_attachment}. Supports `post_mime_type`, `guid`, `post_parent`, `post_title`, `post_content` keys. |
|
119 | + * @return bool|int ID of attachment Post created. Returns false if file not created by copy_post_image |
|
120 | + */ |
|
121 | + public static function media_handle_upload( $url, $post_id, $post_data = array() ) { |
|
122 | + |
|
123 | + $reflection = new ReflectionMethod( 'GFFormsModel', 'media_handle_upload' ); |
|
124 | + |
|
125 | + /** |
|
126 | + * If the method changes to public, use Gravity Forms' method |
|
127 | + * @todo: If/when the method is public, remove the unneeded copied code. |
|
128 | + */ |
|
129 | + if( $reflection->isPublic() ) { |
|
130 | + return parent::media_handle_upload( $url, $post_id, $post_data ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Original Gravity Forms code below: |
|
135 | + * ================================== |
|
136 | + */ |
|
137 | + |
|
138 | + //WordPress Administration API required for the media_handle_upload() function |
|
139 | + require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
|
140 | + |
|
141 | + $name = basename( $url ); |
|
142 | + |
|
143 | + $file = self::copy_post_image( $url, $post_id ); |
|
144 | + |
|
145 | + if ( ! $file ) { |
|
146 | + return false; |
|
147 | + } |
|
148 | + |
|
149 | + $name_parts = pathinfo( $name ); |
|
150 | + $name = trim( substr( $name, 0, - ( 1 + strlen( $name_parts['extension'] ) ) ) ); |
|
151 | + |
|
152 | + $url = $file['url']; |
|
153 | + $type = $file['type']; |
|
154 | + $file = $file['file']; |
|
155 | + $title = $name; |
|
156 | + $content = ''; |
|
157 | + |
|
158 | + // use image exif/iptc data for title and caption defaults if possible |
|
159 | + if ( $image_meta = @wp_read_image_metadata( $file ) ) { |
|
160 | + if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) { |
|
161 | + $title = $image_meta['title']; |
|
162 | + } |
|
163 | + if ( trim( $image_meta['caption'] ) ) { |
|
164 | + $content = $image_meta['caption']; |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + // Construct the attachment array |
|
169 | + $attachment = array_merge( |
|
170 | + array( |
|
171 | + 'post_mime_type' => $type, |
|
172 | + 'guid' => $url, |
|
173 | + 'post_parent' => $post_id, |
|
174 | + 'post_title' => $title, |
|
175 | + 'post_content' => $content, |
|
176 | + ), $post_data |
|
177 | + ); |
|
178 | + |
|
179 | + // Save the data |
|
180 | + $id = wp_insert_attachment( $attachment, $file, $post_id ); |
|
181 | + if ( ! is_wp_error( $id ) ) { |
|
182 | + wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
|
183 | + } |
|
184 | + |
|
185 | + return $id; |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | 189 | } |
190 | 190 | \ No newline at end of file |