@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @since 1.15 |
| 29 | 29 | * @param bool|false $mixed |
| 30 | 30 | * |
| 31 | - * @return bool |
|
| 31 | + * @return boolean|null |
|
| 32 | 32 | */ |
| 33 | 33 | private function _exit( $mixed = NULL ) { |
| 34 | 34 | |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * Import Gravity Form XML or JSON |
| 201 | 201 | * |
| 202 | 202 | * @param string $xml_or_json_path Path to form XML or JSON file |
| 203 | - * @return int|bool Imported form ID or false |
|
| 203 | + * @return false|string Imported form ID or false |
|
| 204 | 204 | */ |
| 205 | 205 | function import_form( $xml_or_json_path = '' ) { |
| 206 | 206 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | // template areas |
| 140 | 140 | $template_areas_directory = apply_filters( 'gravityview_template_active_areas', array(), $template_id, 'directory' ); |
| 141 | - $template_areas_single = apply_filters( 'gravityview_template_active_areas', array(), $template_id, 'single' ); |
|
| 141 | + $template_areas_single = apply_filters( 'gravityview_template_active_areas', array(), $template_id, 'single' ); |
|
| 142 | 142 | |
| 143 | 143 | // widget areas |
| 144 | 144 | $default_widget_areas = \GV\Widget::get_default_widget_areas(); |
@@ -331,40 +331,40 @@ discard block |
||
| 331 | 331 | // load file |
| 332 | 332 | $xmlstr = file_get_contents( $form_file ); |
| 333 | 333 | |
| 334 | - $options = array( |
|
| 335 | - "page" => array("unserialize_as_array" => true), |
|
| 336 | - "form"=> array("unserialize_as_array" => true), |
|
| 337 | - "field"=> array("unserialize_as_array" => true), |
|
| 338 | - "rule"=> array("unserialize_as_array" => true), |
|
| 339 | - "choice"=> array("unserialize_as_array" => true), |
|
| 340 | - "input"=> array("unserialize_as_array" => true), |
|
| 341 | - "routing_item"=> array("unserialize_as_array" => true), |
|
| 342 | - "creditCard"=> array("unserialize_as_array" => true), |
|
| 343 | - "routin"=> array("unserialize_as_array" => true), |
|
| 344 | - "confirmation" => array("unserialize_as_array" => true), |
|
| 345 | - "notification" => array("unserialize_as_array" => true) |
|
| 346 | - ); |
|
| 334 | + $options = array( |
|
| 335 | + "page" => array("unserialize_as_array" => true), |
|
| 336 | + "form"=> array("unserialize_as_array" => true), |
|
| 337 | + "field"=> array("unserialize_as_array" => true), |
|
| 338 | + "rule"=> array("unserialize_as_array" => true), |
|
| 339 | + "choice"=> array("unserialize_as_array" => true), |
|
| 340 | + "input"=> array("unserialize_as_array" => true), |
|
| 341 | + "routing_item"=> array("unserialize_as_array" => true), |
|
| 342 | + "creditCard"=> array("unserialize_as_array" => true), |
|
| 343 | + "routin"=> array("unserialize_as_array" => true), |
|
| 344 | + "confirmation" => array("unserialize_as_array" => true), |
|
| 345 | + "notification" => array("unserialize_as_array" => true) |
|
| 346 | + ); |
|
| 347 | 347 | |
| 348 | 348 | $xml = new RGXML($options); |
| 349 | - $forms = $xml->unserialize($xmlstr); |
|
| 349 | + $forms = $xml->unserialize($xmlstr); |
|
| 350 | 350 | |
| 351 | - if( !$forms ) { |
|
| 352 | - gravityview()->log->error( 'Importing Form Fields for preset [{template_id}]. Error importing file. (File) {path}', array( 'template_id' => $template_id, 'path' => $form_file ) ); |
|
| 353 | - return false; |
|
| 354 | - } |
|
| 351 | + if( !$forms ) { |
|
| 352 | + gravityview()->log->error( 'Importing Form Fields for preset [{template_id}]. Error importing file. (File) {path}', array( 'template_id' => $template_id, 'path' => $form_file ) ); |
|
| 353 | + return false; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - if( !empty( $forms[0] ) && is_array( $forms[0] ) ) { |
|
| 357 | - $form = $forms[0]; |
|
| 358 | - } |
|
| 356 | + if( !empty( $forms[0] ) && is_array( $forms[0] ) ) { |
|
| 357 | + $form = $forms[0]; |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - if( empty( $form ) ) { |
|
| 361 | - gravityview()->log->error( '$form not set.', array( 'data' => $forms ) ); |
|
| 362 | - return false; |
|
| 363 | - } |
|
| 360 | + if( empty( $form ) ) { |
|
| 361 | + gravityview()->log->error( '$form not set.', array( 'data' => $forms ) ); |
|
| 362 | + return false; |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | - gravityview()->log->debug( '[pre_get_available_fields] Importing Form Fields for preset [{template_id}]. (Form)', array( 'template_id' => $template_id, 'data' => $form ) ); |
|
| 365 | + gravityview()->log->debug( '[pre_get_available_fields] Importing Form Fields for preset [{template_id}]. (Form)', array( 'template_id' => $template_id, 'data' => $form ) ); |
|
| 366 | 366 | |
| 367 | - return $form; |
|
| 367 | + return $form; |
|
| 368 | 368 | |
| 369 | 369 | } |
| 370 | 370 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * Don't exit if we're running test suite. |
| 37 | 37 | * @since 1.15 |
| 38 | 38 | */ |
| 39 | - if( defined( 'DOING_GRAVITYVIEW_TESTS' ) && DOING_GRAVITYVIEW_TESTS ) { |
|
| 39 | + if ( defined( 'DOING_GRAVITYVIEW_TESTS' ) && DOING_GRAVITYVIEW_TESTS ) { |
|
| 40 | 40 | return $mixed; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @return void |
| 51 | 51 | */ |
| 52 | 52 | function check_ajax_nonce() { |
| 53 | - if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'gravityview_ajaxviews' ) ) { |
|
| 53 | + if ( ! isset( $_POST[ 'nonce' ] ) || ! wp_verify_nonce( $_POST[ 'nonce' ], 'gravityview_ajaxviews' ) ) { |
|
| 54 | 54 | $this->_exit( false ); |
| 55 | 55 | } |
| 56 | 56 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $context = rgpost( 'context' ); |
| 70 | 70 | |
| 71 | 71 | // Return markup for a single or multiple contexts |
| 72 | - if( $context ) { |
|
| 72 | + if ( $context ) { |
|
| 73 | 73 | $data = array( |
| 74 | 74 | esc_attr( $context ) => '' |
| 75 | 75 | ); |
@@ -113,17 +113,17 @@ discard block |
||
| 113 | 113 | function get_active_areas() { |
| 114 | 114 | $this->check_ajax_nonce(); |
| 115 | 115 | |
| 116 | - if( empty( $_POST['template_id'] ) ) { |
|
| 116 | + if ( empty( $_POST[ 'template_id' ] ) ) { |
|
| 117 | 117 | $this->_exit( false ); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | ob_start(); |
| 121 | - do_action( 'gravityview_render_directory_active_areas', $_POST['template_id'], 'directory', '', true ); |
|
| 122 | - $response['directory'] = ob_get_clean(); |
|
| 121 | + do_action( 'gravityview_render_directory_active_areas', $_POST[ 'template_id' ], 'directory', '', true ); |
|
| 122 | + $response[ 'directory' ] = ob_get_clean(); |
|
| 123 | 123 | |
| 124 | 124 | ob_start(); |
| 125 | - do_action( 'gravityview_render_directory_active_areas', $_POST['template_id'], 'single', '', true ); |
|
| 126 | - $response['single'] = ob_get_clean(); |
|
| 125 | + do_action( 'gravityview_render_directory_active_areas', $_POST[ 'template_id' ], 'single', '', true ); |
|
| 126 | + $response[ 'single' ] = ob_get_clean(); |
|
| 127 | 127 | |
| 128 | 128 | $response = array_map( 'gravityview_strip_whitespace', $response ); |
| 129 | 129 | |
@@ -138,20 +138,20 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | $this->check_ajax_nonce(); |
| 140 | 140 | |
| 141 | - if( empty( $_POST['template_id'] ) ) { |
|
| 141 | + if ( empty( $_POST[ 'template_id' ] ) ) { |
|
| 142 | 142 | $this->_exit( false ); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // get the fields xml config file for this specific preset |
| 146 | - $preset_fields_path = apply_filters( 'gravityview_template_fieldsxml', array(), $_POST['template_id'] ); |
|
| 146 | + $preset_fields_path = apply_filters( 'gravityview_template_fieldsxml', array(), $_POST[ 'template_id' ] ); |
|
| 147 | 147 | // import fields |
| 148 | - if( !empty( $preset_fields_path ) ) { |
|
| 148 | + if ( ! empty( $preset_fields_path ) ) { |
|
| 149 | 149 | $presets = $this->import_fields( $preset_fields_path ); |
| 150 | 150 | } else { |
| 151 | 151 | $presets = array( 'widgets' => array(), 'fields' => array() ); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - $template_id = esc_attr( $_POST['template_id'] ); |
|
| 154 | + $template_id = esc_attr( $_POST[ 'template_id' ] ); |
|
| 155 | 155 | |
| 156 | 156 | // template areas |
| 157 | 157 | $template_areas_directory = apply_filters( 'gravityview_template_active_areas', array(), $template_id, 'directory' ); |
@@ -161,20 +161,20 @@ discard block |
||
| 161 | 161 | $default_widget_areas = \GV\Widget::get_default_widget_areas(); |
| 162 | 162 | |
| 163 | 163 | ob_start(); |
| 164 | - do_action('gravityview_render_active_areas', $template_id, 'widget', 'header', $default_widget_areas, $presets['widgets'] ); |
|
| 165 | - $response['header'] = ob_get_clean(); |
|
| 164 | + do_action( 'gravityview_render_active_areas', $template_id, 'widget', 'header', $default_widget_areas, $presets[ 'widgets' ] ); |
|
| 165 | + $response[ 'header' ] = ob_get_clean(); |
|
| 166 | 166 | |
| 167 | 167 | ob_start(); |
| 168 | - do_action('gravityview_render_active_areas', $template_id, 'widget', 'footer', $default_widget_areas, $presets['widgets'] ); |
|
| 169 | - $response['footer'] = ob_get_clean(); |
|
| 168 | + do_action( 'gravityview_render_active_areas', $template_id, 'widget', 'footer', $default_widget_areas, $presets[ 'widgets' ] ); |
|
| 169 | + $response[ 'footer' ] = ob_get_clean(); |
|
| 170 | 170 | |
| 171 | 171 | ob_start(); |
| 172 | - do_action('gravityview_render_active_areas', $template_id, 'field', 'directory', $template_areas_directory, $presets['fields'] ); |
|
| 173 | - $response['directory'] = ob_get_clean(); |
|
| 172 | + do_action( 'gravityview_render_active_areas', $template_id, 'field', 'directory', $template_areas_directory, $presets[ 'fields' ] ); |
|
| 173 | + $response[ 'directory' ] = ob_get_clean(); |
|
| 174 | 174 | |
| 175 | 175 | ob_start(); |
| 176 | - do_action('gravityview_render_active_areas', $template_id, 'field', 'single', $template_areas_single, $presets['fields'] ); |
|
| 177 | - $response['single'] = ob_get_clean(); |
|
| 176 | + do_action( 'gravityview_render_active_areas', $template_id, 'field', 'single', $template_areas_single, $presets[ 'fields' ] ); |
|
| 177 | + $response[ 'single' ] = ob_get_clean(); |
|
| 178 | 178 | |
| 179 | 179 | $response = array_map( 'gravityview_strip_whitespace', $response ); |
| 180 | 180 | |
@@ -192,26 +192,26 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | $this->check_ajax_nonce(); |
| 194 | 194 | |
| 195 | - if( empty( $_POST['template_id'] ) ) { |
|
| 195 | + if ( empty( $_POST[ 'template_id' ] ) ) { |
|
| 196 | 196 | gravityview()->log->error( 'Cannot create preset form; the template_id is empty.' ); |
| 197 | 197 | $this->_exit( false ); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // get the xml for this specific template_id |
| 201 | - $preset_form_xml_path = apply_filters( 'gravityview_template_formxml', '', $_POST['template_id'] ); |
|
| 201 | + $preset_form_xml_path = apply_filters( 'gravityview_template_formxml', '', $_POST[ 'template_id' ] ); |
|
| 202 | 202 | |
| 203 | 203 | // import form |
| 204 | 204 | $form = $this->import_form( $preset_form_xml_path ); |
| 205 | 205 | |
| 206 | 206 | // get the form ID |
| 207 | - if( false === $form ) { |
|
| 207 | + if ( false === $form ) { |
|
| 208 | 208 | // send error to user |
| 209 | - gravityview()->log->error( 'Error importing form for template id: {template_id}', array( 'template_id' => (int) $_POST['template_id'] ) ); |
|
| 209 | + gravityview()->log->error( 'Error importing form for template id: {template_id}', array( 'template_id' => (int)$_POST[ 'template_id' ] ) ); |
|
| 210 | 210 | |
| 211 | 211 | $this->_exit( false ); |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - $this->_exit( '<option value="'.esc_attr( $form['id'] ).'" selected="selected">'.esc_html( $form['title'] ).'</option>' ); |
|
| 214 | + $this->_exit( '<option value="' . esc_attr( $form[ 'id' ] ) . '" selected="selected">' . esc_html( $form[ 'title' ] ) . '</option>' ); |
|
| 215 | 215 | |
| 216 | 216 | } |
| 217 | 217 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | |
| 226 | 226 | gravityview()->log->debug( '[import_form] Import Preset Form. (File) {path}', array( 'path' => $xml_or_json_path ) ); |
| 227 | 227 | |
| 228 | - if( empty( $xml_or_json_path ) || !class_exists('GFExport') || !file_exists( $xml_or_json_path ) ) { |
|
| 228 | + if ( empty( $xml_or_json_path ) || ! class_exists( 'GFExport' ) || ! file_exists( $xml_or_json_path ) ) { |
|
| 229 | 229 | gravityview()->log->error( 'Class GFExport or file not found. file: {path}', array( 'path' => $xml_or_json_path ) ); |
| 230 | 230 | return false; |
| 231 | 231 | } |
@@ -237,13 +237,13 @@ discard block |
||
| 237 | 237 | gravityview()->log->debug( '[import_form] Importing form (Result) {count}', array( 'count' => $count ) ); |
| 238 | 238 | gravityview()->log->debug( '[import_form] Importing form (Form) ', array( 'data' => $forms ) ); |
| 239 | 239 | |
| 240 | - if( $count != 1 || empty( $forms[0]['id'] ) ) { |
|
| 240 | + if ( $count != 1 || empty( $forms[ 0 ][ 'id' ] ) ) { |
|
| 241 | 241 | gravityview()->log->error( 'Form Import Failed!' ); |
| 242 | 242 | return false; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // import success - return form id |
| 246 | - return $forms[0]; |
|
| 246 | + return $forms[ 0 ]; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | function get_field_options() { |
| 258 | 258 | $this->check_ajax_nonce(); |
| 259 | 259 | |
| 260 | - if( empty( $_POST['template'] ) || empty( $_POST['area'] ) || empty( $_POST['field_id'] ) || empty( $_POST['field_type'] ) ) { |
|
| 260 | + if ( empty( $_POST[ 'template' ] ) || empty( $_POST[ 'area' ] ) || empty( $_POST[ 'field_id' ] ) || empty( $_POST[ 'field_type' ] ) ) { |
|
| 261 | 261 | gravityview()->log->error( 'Required fields were not set in the $_POST request. ' ); |
| 262 | 262 | $this->_exit( false ); |
| 263 | 263 | } |
@@ -269,11 +269,11 @@ discard block |
||
| 269 | 269 | $_post = array_map( 'esc_attr', $_post ); |
| 270 | 270 | |
| 271 | 271 | // The GF type of field: `product`, `name`, `creditcard`, `id`, `text` |
| 272 | - $input_type = isset($_post['input_type']) ? esc_attr( $_post['input_type'] ) : NULL; |
|
| 273 | - $context = isset($_post['context']) ? esc_attr( $_post['context'] ) : NULL; |
|
| 272 | + $input_type = isset( $_post[ 'input_type' ] ) ? esc_attr( $_post[ 'input_type' ] ) : NULL; |
|
| 273 | + $context = isset( $_post[ 'context' ] ) ? esc_attr( $_post[ 'context' ] ) : NULL; |
|
| 274 | 274 | |
| 275 | - $form_id = empty( $_post['form_id'] ) ? null : $_post['form_id']; |
|
| 276 | - $response = GravityView_Render_Settings::render_field_options( $form_id, $_post['field_type'], $_post['template'], $_post['field_id'], $_post['field_label'], $_post['area'], $input_type, '', '', $context ); |
|
| 275 | + $form_id = empty( $_post[ 'form_id' ] ) ? null : $_post[ 'form_id' ]; |
|
| 276 | + $response = GravityView_Render_Settings::render_field_options( $form_id, $_post[ 'field_type' ], $_post[ 'template' ], $_post[ 'field_id' ], $_post[ 'field_label' ], $_post[ 'area' ], $input_type, '', '', $context ); |
|
| 277 | 277 | |
| 278 | 278 | $response = gravityview_strip_whitespace( $response ); |
| 279 | 279 | |
@@ -294,15 +294,15 @@ discard block |
||
| 294 | 294 | $form = ''; |
| 295 | 295 | |
| 296 | 296 | // if form id is set, use it, else, get form from preset |
| 297 | - if( !empty( $_POST['form_id'] ) ) { |
|
| 297 | + if ( ! empty( $_POST[ 'form_id' ] ) ) { |
|
| 298 | 298 | |
| 299 | - $form = (int) $_POST['form_id']; |
|
| 299 | + $form = (int)$_POST[ 'form_id' ]; |
|
| 300 | 300 | |
| 301 | 301 | } |
| 302 | 302 | // get form from preset |
| 303 | - elseif( !empty( $_POST['template_id'] ) ) { |
|
| 303 | + elseif ( ! empty( $_POST[ 'template_id' ] ) ) { |
|
| 304 | 304 | |
| 305 | - $form = GravityView_Ajax::pre_get_form_fields( $_POST['template_id'] ); |
|
| 305 | + $form = GravityView_Ajax::pre_get_form_fields( $_POST[ 'template_id' ] ); |
|
| 306 | 306 | |
| 307 | 307 | } |
| 308 | 308 | |
@@ -318,27 +318,27 @@ discard block |
||
| 318 | 318 | * @param string $template_id Preset template |
| 319 | 319 | * |
| 320 | 320 | */ |
| 321 | - static function pre_get_form_fields( $template_id = '') { |
|
| 321 | + static function pre_get_form_fields( $template_id = '' ) { |
|
| 322 | 322 | |
| 323 | - if( empty( $template_id ) ) { |
|
| 323 | + if ( empty( $template_id ) ) { |
|
| 324 | 324 | gravityview()->log->error( 'Template ID not set.' ); |
| 325 | 325 | return false; |
| 326 | 326 | } else { |
| 327 | 327 | $form_file = apply_filters( 'gravityview_template_formxml', '', $template_id ); |
| 328 | - if( !file_exists( $form_file ) ) { |
|
| 328 | + if ( ! file_exists( $form_file ) ) { |
|
| 329 | 329 | gravityview()->log->error( 'Importing Form Fields for preset [{template_id}]. File not found. file: {path}', array( 'template_id' => $template_id, 'path' => $form_file ) ); |
| 330 | 330 | return false; |
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | // Load xml parser (from GravityForms) |
| 335 | - if( class_exists( 'GFCommon' ) ) { |
|
| 335 | + if ( class_exists( 'GFCommon' ) ) { |
|
| 336 | 336 | $xml_parser = GFCommon::get_base_path() . '/xml.php'; |
| 337 | 337 | } else { |
| 338 | 338 | $xml_parser = trailingslashit( WP_PLUGIN_DIR ) . 'gravityforms/xml.php'; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - if( file_exists( $xml_parser ) ) { |
|
| 341 | + if ( file_exists( $xml_parser ) ) { |
|
| 342 | 342 | require_once( $xml_parser ); |
| 343 | 343 | } else { |
| 344 | 344 | gravityview()->log->debug( ' - Gravity Forms XML Parser not found {path}.', array( 'path' => $xml_parser ) ); |
@@ -349,32 +349,32 @@ discard block |
||
| 349 | 349 | $xmlstr = file_get_contents( $form_file ); |
| 350 | 350 | |
| 351 | 351 | $options = array( |
| 352 | - "page" => array("unserialize_as_array" => true), |
|
| 353 | - "form"=> array("unserialize_as_array" => true), |
|
| 354 | - "field"=> array("unserialize_as_array" => true), |
|
| 355 | - "rule"=> array("unserialize_as_array" => true), |
|
| 356 | - "choice"=> array("unserialize_as_array" => true), |
|
| 357 | - "input"=> array("unserialize_as_array" => true), |
|
| 358 | - "routing_item"=> array("unserialize_as_array" => true), |
|
| 359 | - "creditCard"=> array("unserialize_as_array" => true), |
|
| 360 | - "routin"=> array("unserialize_as_array" => true), |
|
| 361 | - "confirmation" => array("unserialize_as_array" => true), |
|
| 362 | - "notification" => array("unserialize_as_array" => true) |
|
| 352 | + "page" => array( "unserialize_as_array" => true ), |
|
| 353 | + "form"=> array( "unserialize_as_array" => true ), |
|
| 354 | + "field"=> array( "unserialize_as_array" => true ), |
|
| 355 | + "rule"=> array( "unserialize_as_array" => true ), |
|
| 356 | + "choice"=> array( "unserialize_as_array" => true ), |
|
| 357 | + "input"=> array( "unserialize_as_array" => true ), |
|
| 358 | + "routing_item"=> array( "unserialize_as_array" => true ), |
|
| 359 | + "creditCard"=> array( "unserialize_as_array" => true ), |
|
| 360 | + "routin"=> array( "unserialize_as_array" => true ), |
|
| 361 | + "confirmation" => array( "unserialize_as_array" => true ), |
|
| 362 | + "notification" => array( "unserialize_as_array" => true ) |
|
| 363 | 363 | ); |
| 364 | 364 | |
| 365 | - $xml = new RGXML($options); |
|
| 366 | - $forms = $xml->unserialize($xmlstr); |
|
| 365 | + $xml = new RGXML( $options ); |
|
| 366 | + $forms = $xml->unserialize( $xmlstr ); |
|
| 367 | 367 | |
| 368 | - if( !$forms ) { |
|
| 368 | + if ( ! $forms ) { |
|
| 369 | 369 | gravityview()->log->error( 'Importing Form Fields for preset [{template_id}]. Error importing file. (File) {path}', array( 'template_id' => $template_id, 'path' => $form_file ) ); |
| 370 | 370 | return false; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - if( !empty( $forms[0] ) && is_array( $forms[0] ) ) { |
|
| 374 | - $form = $forms[0]; |
|
| 373 | + if ( ! empty( $forms[ 0 ] ) && is_array( $forms[ 0 ] ) ) { |
|
| 374 | + $form = $forms[ 0 ]; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - if( empty( $form ) ) { |
|
| 377 | + if ( empty( $form ) ) { |
|
| 378 | 378 | gravityview()->log->error( '$form not set.', array( 'data' => $forms ) ); |
| 379 | 379 | return false; |
| 380 | 380 | } |
@@ -393,38 +393,38 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | function import_fields( $file ) { |
| 395 | 395 | |
| 396 | - if( empty( $file ) || !file_exists( $file ) ) { |
|
| 396 | + if ( empty( $file ) || ! file_exists( $file ) ) { |
|
| 397 | 397 | gravityview()->log->error( 'Importing Preset Fields. File not found. (File) {path}', array( 'path' => $file ) ); |
| 398 | 398 | return false; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - if( !class_exists('WXR_Parser') ) { |
|
| 401 | + if ( ! class_exists( 'WXR_Parser' ) ) { |
|
| 402 | 402 | include_once GRAVITYVIEW_DIR . 'includes/lib/xml-parsers/parsers.php'; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | $parser = new WXR_Parser(); |
| 406 | 406 | $presets = $parser->parse( $file ); |
| 407 | 407 | |
| 408 | - if(is_wp_error( $presets )) { |
|
| 408 | + if ( is_wp_error( $presets ) ) { |
|
| 409 | 409 | gravityview()->log->error( 'Importing Preset Fields failed. Threw WP_Error.', array( 'data' => $presets ) ); |
| 410 | 410 | return false; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | - if( empty( $presets['posts'][0]['postmeta'] ) && !is_array( $presets['posts'][0]['postmeta'] ) ) { |
|
| 413 | + if ( empty( $presets[ 'posts' ][ 0 ][ 'postmeta' ] ) && ! is_array( $presets[ 'posts' ][ 0 ][ 'postmeta' ] ) ) { |
|
| 414 | 414 | gravityview()->log->error( 'Importing Preset Fields failed. Meta not found in file. {path}', array( 'path' => $file ) ); |
| 415 | 415 | return false; |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - gravityview()->log->debug( '[import_fields] postmeta', array( 'data' => $presets['posts'][0]['postmeta'] ) ); |
|
| 418 | + gravityview()->log->debug( '[import_fields] postmeta', array( 'data' => $presets[ 'posts' ][ 0 ][ 'postmeta' ] ) ); |
|
| 419 | 419 | |
| 420 | 420 | $fields = $widgets = array(); |
| 421 | - foreach( $presets['posts'][0]['postmeta'] as $meta ) { |
|
| 422 | - switch ($meta['key']) { |
|
| 421 | + foreach ( $presets[ 'posts' ][ 0 ][ 'postmeta' ] as $meta ) { |
|
| 422 | + switch ( $meta[ 'key' ] ) { |
|
| 423 | 423 | case '_gravityview_directory_fields': |
| 424 | - $fields = maybe_unserialize( $meta['value'] ); |
|
| 424 | + $fields = maybe_unserialize( $meta[ 'value' ] ); |
|
| 425 | 425 | break; |
| 426 | 426 | case '_gravityview_directory_widgets': |
| 427 | - $widgets = maybe_unserialize( $meta['value'] ); |
|
| 427 | + $widgets = maybe_unserialize( $meta[ 'value' ] ); |
|
| 428 | 428 | break; |
| 429 | 429 | } |
| 430 | 430 | } |
@@ -195,7 +195,7 @@ |
||
| 195 | 195 | * |
| 196 | 196 | * @since 1.6 |
| 197 | 197 | * |
| 198 | - * @param int $new_view_id The ID of the newly created View |
|
| 198 | + * @param int $new_id The ID of the newly created View |
|
| 199 | 199 | * @param WP_Post $post The View that was just cloned |
| 200 | 200 | * |
| 201 | 201 | * @return void |
@@ -15,12 +15,12 @@ discard block |
||
| 15 | 15 | function __construct() { |
| 16 | 16 | |
| 17 | 17 | // Only run on Admin |
| 18 | - if ( !is_admin() ) { |
|
| 18 | + if ( ! is_admin() ) { |
|
| 19 | 19 | return; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | // If the Duplicate Post plugin is active, don't run. |
| 23 | - if( defined('DUPLICATE_POST_CURRENT_VERSION') ) { |
|
| 23 | + if ( defined( 'DUPLICATE_POST_CURRENT_VERSION' ) ) { |
|
| 24 | 24 | return; |
| 25 | 25 | } |
| 26 | 26 | |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | global $post; |
| 61 | 61 | |
| 62 | 62 | // We only want to add Clone links to the Edit View metabox |
| 63 | - if( !$this->is_all_views_page() ) { |
|
| 63 | + if ( ! $this->is_all_views_page() ) { |
|
| 64 | 64 | |
| 65 | - if( $duplicate_links = $this->make_duplicate_link_row( array(), $post ) ) { |
|
| 66 | - $links[] = '<span>' . $duplicate_links['edit_as_new_draft'] . '</span>'; |
|
| 65 | + if ( $duplicate_links = $this->make_duplicate_link_row( array(), $post ) ) { |
|
| 66 | + $links[ ] = '<span>' . $duplicate_links[ 'edit_as_new_draft' ] . '</span>'; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @param string|null If string, the status to set for the new View. If empty, use existing View status. |
| 124 | 124 | * @param WP_Post $post View being cloned |
| 125 | 125 | */ |
| 126 | - $new_view_status = apply_filters('gravityview/duplicate-view/status', $status, $post ); |
|
| 126 | + $new_view_status = apply_filters( 'gravityview/duplicate-view/status', $status, $post ); |
|
| 127 | 127 | |
| 128 | 128 | $new_view = array( |
| 129 | 129 | 'menu_order' => $post->menu_order, |
@@ -146,11 +146,11 @@ discard block |
||
| 146 | 146 | * @param boolean $copy_date Whether the copy the date from the existing View. Default: `false` |
| 147 | 147 | * @param WP_Post $post View being cloned |
| 148 | 148 | */ |
| 149 | - $copy_date = apply_filters('gravityview/duplicate-view/copy-date', false, $post ); |
|
| 149 | + $copy_date = apply_filters( 'gravityview/duplicate-view/copy-date', false, $post ); |
|
| 150 | 150 | |
| 151 | 151 | if ( $copy_date ) { |
| 152 | - $new_view['post_date'] = $new_post_date = $post->post_date; |
|
| 153 | - $new_view['post_date_gmt'] = get_gmt_from_date( $new_post_date ); |
|
| 152 | + $new_view[ 'post_date' ] = $new_post_date = $post->post_date; |
|
| 153 | + $new_view[ 'post_date_gmt' ] = get_gmt_from_date( $new_post_date ); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @param array $new_view Array of settings to be passed to wp_insert_post() |
| 160 | 160 | * @param WP_Post $post View being cloned |
| 161 | 161 | */ |
| 162 | - $new_view = apply_filters('gravityview/duplicate-view/new-view', $new_view, $post ); |
|
| 162 | + $new_view = apply_filters( 'gravityview/duplicate-view/new-view', $new_view, $post ); |
|
| 163 | 163 | |
| 164 | 164 | // Magic happens here. |
| 165 | 165 | $new_view_id = wp_insert_post( $new_view ); |
@@ -241,13 +241,13 @@ discard block |
||
| 241 | 241 | $clone_text = __( 'Clone', 'gravityview' ); |
| 242 | 242 | $clone_title = __( 'Clone this View', 'gravityview' ); |
| 243 | 243 | |
| 244 | - $actions['clone'] = gravityview_get_link( $clone_link, $clone_text, 'title='.$clone_title ); |
|
| 244 | + $actions[ 'clone' ] = gravityview_get_link( $clone_link, $clone_text, 'title=' . $clone_title ); |
|
| 245 | 245 | |
| 246 | 246 | $clone_draft_link = $this->get_clone_view_link( $post->ID ); |
| 247 | 247 | $clone_draft_text = $this->is_all_views_page() ? __( 'New Draft', 'gravityview' ) : __( 'Clone View', 'gravityview' ); |
| 248 | 248 | $clone_draft_title = __( 'Copy as a new draft View', 'gravityview' ); |
| 249 | 249 | |
| 250 | - $actions['edit_as_new_draft'] = gravityview_get_link( $clone_draft_link, esc_html( $clone_draft_text ), 'title='.$clone_draft_title ); |
|
| 250 | + $actions[ 'edit_as_new_draft' ] = gravityview_get_link( $clone_draft_link, esc_html( $clone_draft_text ), 'title=' . $clone_draft_title ); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | return $actions; |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // Verify the View exists |
| 274 | - if ( !$view = get_post( $id ) ) { |
|
| 274 | + if ( ! $view = get_post( $id ) ) { |
|
| 275 | 275 | return ''; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | $post_type_object = get_post_type_object( $view->post_type ); |
| 287 | 287 | |
| 288 | 288 | /** If there's no gravityview post type for some reason, abort! */ |
| 289 | - if ( !$post_type_object ) { |
|
| 289 | + if ( ! $post_type_object ) { |
|
| 290 | 290 | gravityview()->log->error( 'No gravityview post type exists when trying to clone the View.', array( 'data' => $view ) ); |
| 291 | 291 | return ''; |
| 292 | 292 | } |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | * @param int $view_id View ID |
| 299 | 299 | * @param string $context How to display the link. If "display", the URL is run through esc_html(). Default: `display` |
| 300 | 300 | */ |
| 301 | - $clone_view_link = apply_filters( 'gravityview/duplicate-view/get_clone_view_link', admin_url( "admin.php". $action ), $view->ID, $context ); |
|
| 301 | + $clone_view_link = apply_filters( 'gravityview/duplicate-view/get_clone_view_link', admin_url( "admin.php" . $action ), $view->ID, $context ); |
|
| 302 | 302 | |
| 303 | 303 | return $clone_view_link; |
| 304 | 304 | } |
@@ -325,14 +325,14 @@ discard block |
||
| 325 | 325 | */ |
| 326 | 326 | public function save_as_new_view( $status = '' ) { |
| 327 | 327 | |
| 328 | - if ( ! ( isset( $_GET['post'] ) || isset( $_POST['post'] ) ) ) { |
|
| 328 | + if ( ! ( isset( $_GET[ 'post' ] ) || isset( $_POST[ 'post' ] ) ) ) { |
|
| 329 | 329 | wp_die( __( 'No post to duplicate has been supplied!', 'gravityview' ) ); |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | // Get the original post |
| 333 | - $id = ( isset( $_GET['post'] ) ? $_GET['post'] : $_POST['post'] ); |
|
| 333 | + $id = ( isset( $_GET[ 'post' ] ) ? $_GET[ 'post' ] : $_POST[ 'post' ] ); |
|
| 334 | 334 | |
| 335 | - if( ! $this->current_user_can_copy( $id ) ) { |
|
| 335 | + if ( ! $this->current_user_can_copy( $id ) ) { |
|
| 336 | 336 | wp_die( __( 'You don\'t have permission to copy this View.', 'gravityview' ) ); |
| 337 | 337 | } |
| 338 | 338 | |
@@ -116,7 +116,7 @@ |
||
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * @since 1.12 |
| 119 | - * @return bool |
|
| 119 | + * @return boolean|null |
|
| 120 | 120 | */ |
| 121 | 121 | private function add_fallback_shortcode() { |
| 122 | 122 | |
@@ -240,7 +240,7 @@ |
||
| 240 | 240 | self::$notices['wp_version'] = array( |
| 241 | 241 | 'class' => 'error', |
| 242 | 242 | 'message' => sprintf( __( "%sGravityView requires WordPress %s or newer.%s \n\nYou're using Version %s. Please upgrade your WordPress installation.", 'gravityview' ), '<h3>', GV_MIN_WP_VERSION, "</h3>\n\n", '<span style="font-family: Consolas, Courier, monospace;">' . $wp_version . '</span>' ), |
| 243 | - 'cap' => 'update_core', |
|
| 243 | + 'cap' => 'update_core', |
|
| 244 | 244 | 'dismiss' => 'wp_version', |
| 245 | 245 | ); |
| 246 | 246 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @return GravityView_Compatibility |
| 77 | 77 | */ |
| 78 | 78 | public static function getInstance() { |
| 79 | - if( self::$instance ) { |
|
| 79 | + if ( self::$instance ) { |
|
| 80 | 80 | return self::$instance; |
| 81 | 81 | } |
| 82 | 82 | return new self; |
@@ -138,10 +138,10 @@ discard block |
||
| 138 | 138 | // If Gravity Forms doesn't exist or is outdated, load the admin view class to |
| 139 | 139 | // show the notice, but not load any post types or process shortcodes. |
| 140 | 140 | // Without Gravity Forms, there is no GravityView. Beautiful, really. |
| 141 | - if( ! self::is_valid() ) { |
|
| 141 | + if ( ! self::is_valid() ) { |
|
| 142 | 142 | |
| 143 | 143 | // If the plugin's not loaded, might as well hide the shortcode for people. |
| 144 | - add_shortcode( 'gravityview', array( $this, '_shortcode_gf_notice') ); |
|
| 144 | + add_shortcode( 'gravityview', array( $this, '_shortcode_gf_notice' ) ); |
|
| 145 | 145 | |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -167,15 +167,15 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | public function _shortcode_gf_notice( $atts = array(), $content = null, $shortcode = 'gravityview' ) { |
| 169 | 169 | |
| 170 | - if( ! GVCommon::has_cap( 'activate_plugins' ) ) { |
|
| 170 | + if ( ! GVCommon::has_cap( 'activate_plugins' ) ) { |
|
| 171 | 171 | return null; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | $notices = self::get_notices(); |
| 175 | 175 | |
| 176 | - $message = '<div style="border:1px solid red; padding: 15px;"><p style="text-align:center;"><em>' . esc_html__( 'You are seeing this notice because you are an administrator. Other users of the site will see nothing.', 'gravityview') . '</em></p>'; |
|
| 177 | - foreach( (array)$notices as $notice ) { |
|
| 178 | - $message .= wpautop( $notice['message'] ); |
|
| 176 | + $message = '<div style="border:1px solid red; padding: 15px;"><p style="text-align:center;"><em>' . esc_html__( 'You are seeing this notice because you are an administrator. Other users of the site will see nothing.', 'gravityview' ) . '</em></p>'; |
|
| 177 | + foreach ( (array)$notices as $notice ) { |
|
| 178 | + $message .= wpautop( $notice[ 'message' ] ); |
|
| 179 | 179 | } |
| 180 | 180 | $message .= '</div>'; |
| 181 | 181 | |
@@ -195,9 +195,9 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | if ( ! gravityview()->plugin->is_compatible_php() ) { |
| 197 | 197 | |
| 198 | - self::$notices['php_version'] = array( |
|
| 198 | + self::$notices[ 'php_version' ] = array( |
|
| 199 | 199 | 'class' => 'error', |
| 200 | - 'message' => sprintf( __( "%sGravityView requires PHP Version %s or newer.%s \n\nYou're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview' ), '<h3>', GV_MIN_PHP_VERSION, "</h3>\n\n", '<span style="font-family: Consolas, Courier, monospace;">'.phpversion().'</span>' ), |
|
| 200 | + 'message' => sprintf( __( "%sGravityView requires PHP Version %s or newer.%s \n\nYou're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview' ), '<h3>', GV_MIN_PHP_VERSION, "</h3>\n\n", '<span style="font-family: Consolas, Courier, monospace;">' . phpversion() . '</span>' ), |
|
| 201 | 201 | 'cap' => 'manage_options', |
| 202 | 202 | 'dismiss' => 'php_version', |
| 203 | 203 | ); |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | if ( ! gravityview()->plugin->is_compatible_future_php() ) { |
| 209 | 209 | |
| 210 | 210 | // Show the notice on every update. Yes, annoying, but not as annoying as a plugin breaking. |
| 211 | - $key = sprintf('php_%s_%s', GV_FUTURE_MIN_PHP_VERSION, GravityView_Plugin::version ); |
|
| 211 | + $key = sprintf( 'php_%s_%s', GV_FUTURE_MIN_PHP_VERSION, GravityView_Plugin::version ); |
|
| 212 | 212 | |
| 213 | 213 | self::$notices[ $key ] = array( |
| 214 | 214 | 'class' => 'error', |
| 215 | - 'message' => sprintf( __( "%sGravityView will soon require PHP Version %s.%s \n\nYou're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview' ), '<h3>', GV_FUTURE_MIN_PHP_VERSION, "</h3>\n\n", '<span style="font-family: Consolas, Courier, monospace;">'.phpversion().'</span>' ), |
|
| 215 | + 'message' => sprintf( __( "%sGravityView will soon require PHP Version %s.%s \n\nYou're using Version %s. Please ask your host to upgrade your server's PHP.", 'gravityview' ), '<h3>', GV_FUTURE_MIN_PHP_VERSION, "</h3>\n\n", '<span style="font-family: Consolas, Courier, monospace;">' . phpversion() . '</span>' ), |
|
| 216 | 216 | 'cap' => 'manage_options', |
| 217 | 217 | 'dismiss' => $key, |
| 218 | 218 | ); |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | if ( ! gravityview()->plugin->is_compatible_wordpress() ) { |
| 239 | 239 | |
| 240 | - self::$notices['wp_version'] = array( |
|
| 240 | + self::$notices[ 'wp_version' ] = array( |
|
| 241 | 241 | 'class' => 'error', |
| 242 | 242 | 'message' => sprintf( __( "%sGravityView requires WordPress %s or newer.%s \n\nYou're using Version %s. Please upgrade your WordPress installation.", 'gravityview' ), '<h3>', GV_MIN_WP_VERSION, "</h3>\n\n", '<span style="font-family: Consolas, Courier, monospace;">' . $wp_version . '</span>' ), |
| 243 | 243 | 'cap' => 'update_core', |
@@ -271,17 +271,17 @@ discard block |
||
| 271 | 271 | public static function check_gravityforms() { |
| 272 | 272 | |
| 273 | 273 | // Bypass other checks: if the class exists |
| 274 | - if( class_exists( 'GFCommon' ) ) { |
|
| 274 | + if ( class_exists( 'GFCommon' ) ) { |
|
| 275 | 275 | |
| 276 | 276 | // Does the version meet future requirements? |
| 277 | - if( true === gravityview()->plugin->is_compatible_future_gravityforms() ) { |
|
| 277 | + if ( true === gravityview()->plugin->is_compatible_future_gravityforms() ) { |
|
| 278 | 278 | return true; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // Does it meet minimum requirements? |
| 282 | 282 | $meets_minimum = gravityview()->plugin->is_compatible_gravityforms(); |
| 283 | 283 | |
| 284 | - if( $meets_minimum ) { |
|
| 284 | + if ( $meets_minimum ) { |
|
| 285 | 285 | /* translators: first placeholder is the future required version of Gravity Forms. The second placeholder is the current version of Gravity Forms. */ |
| 286 | 286 | $title = __( 'In the future, GravityView will require Gravity Forms Version %s or newer.', 'gravityview' ); |
| 287 | 287 | $version = GV_FUTURE_MIN_GF_VERSION; |
@@ -296,14 +296,14 @@ discard block |
||
| 296 | 296 | $message = '<h3>' . esc_html( sprintf( $title, $version ) ) . '</h3>'; |
| 297 | 297 | |
| 298 | 298 | /* translators: the placeholder is the current version of Gravity Forms. */ |
| 299 | - $message .= '<p>' . sprintf( esc_html__( "You're using Version %s. Please update your Gravity Forms or purchase a license.", 'gravityview' ), '<span style="font-family: Consolas, Courier, monospace;">'.GFCommon::$version.'</span>' ) . '</p>'; |
|
| 299 | + $message .= '<p>' . sprintf( esc_html__( "You're using Version %s. Please update your Gravity Forms or purchase a license.", 'gravityview' ), '<span style="font-family: Consolas, Courier, monospace;">' . GFCommon::$version . '</span>' ) . '</p>'; |
|
| 300 | 300 | |
| 301 | 301 | /* translators: In this context, "get" means purchase */ |
| 302 | 302 | $message .= '<p><a href="https://gravityview.co/gravityforms/" class="button button-secondary button-large button-hero">' . esc_html__( 'Get the Latest Gravity Forms', 'gravityview' ) . '</a></p>'; |
| 303 | 303 | |
| 304 | 304 | |
| 305 | 305 | // Show the notice even if the future version requirements aren't met |
| 306 | - self::$notices['gf_version'] = array( |
|
| 306 | + self::$notices[ 'gf_version' ] = array( |
|
| 307 | 307 | 'class' => $class, |
| 308 | 308 | 'message' => $message, |
| 309 | 309 | 'cap' => 'update_plugins', |
@@ -321,42 +321,42 @@ discard block |
||
| 321 | 321 | * OR |
| 322 | 322 | * It's the Network Admin and we just don't know whether the sites have GF activated themselves. |
| 323 | 323 | */ |
| 324 | - if( true === $gf_status || is_network_admin() ) { |
|
| 324 | + if ( true === $gf_status || is_network_admin() ) { |
|
| 325 | 325 | return true; |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | // If GFCommon doesn't exist, assume GF not active |
| 329 | 329 | $return = false; |
| 330 | 330 | |
| 331 | - switch( $gf_status ) { |
|
| 331 | + switch ( $gf_status ) { |
|
| 332 | 332 | case 'inactive': |
| 333 | 333 | |
| 334 | 334 | // Required for multisite |
| 335 | - if( ! function_exists('wp_create_nonce') ) { |
|
| 335 | + if ( ! function_exists( 'wp_create_nonce' ) ) { |
|
| 336 | 336 | require_once ABSPATH . WPINC . '/pluggable.php'; |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | // Otherwise, throws an error on activation & deactivation "Use of undefined constant LOGGED_IN_COOKIE" |
| 340 | - if( is_multisite() ) { |
|
| 340 | + if ( is_multisite() ) { |
|
| 341 | 341 | wp_cookie_constants(); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | $return = false; |
| 345 | 345 | |
| 346 | - $button = function_exists('is_network_admin') && is_network_admin() ? '<strong><a href="#gravity-forms">' : '<strong><a href="'. wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=gravityforms/gravityforms.php' ), 'activate-plugin_gravityforms/gravityforms.php') . '" class="button button-large">'; |
|
| 346 | + $button = function_exists( 'is_network_admin' ) && is_network_admin() ? '<strong><a href="#gravity-forms">' : '<strong><a href="' . wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=gravityforms/gravityforms.php' ), 'activate-plugin_gravityforms/gravityforms.php' ) . '" class="button button-large">'; |
|
| 347 | 347 | |
| 348 | - self::$notices['gf_inactive'] = array( |
|
| 348 | + self::$notices[ 'gf_inactive' ] = array( |
|
| 349 | 349 | 'class' => 'error', |
| 350 | - 'message' => sprintf( __( '%sGravityView requires Gravity Forms to be active. %sActivate Gravity Forms%s to use the GravityView plugin.', 'gravityview' ), '<h3>', "</h3>\n\n". $button, '</a></strong>' ), |
|
| 350 | + 'message' => sprintf( __( '%sGravityView requires Gravity Forms to be active. %sActivate Gravity Forms%s to use the GravityView plugin.', 'gravityview' ), '<h3>', "</h3>\n\n" . $button, '</a></strong>' ), |
|
| 351 | 351 | 'cap' => 'activate_plugins', |
| 352 | 352 | 'dismiss' => 'gf_inactive', |
| 353 | 353 | ); |
| 354 | 354 | |
| 355 | 355 | break; |
| 356 | 356 | default: |
| 357 | - self::$notices['gf_installed'] = array( |
|
| 357 | + self::$notices[ 'gf_installed' ] = array( |
|
| 358 | 358 | 'class' => 'error', |
| 359 | - 'message' => sprintf( __( '%sGravityView requires Gravity Forms to be installed in order to run properly. %sGet Gravity Forms%s - starting at $59%s%s', 'gravityview' ), '<h3>', "</h3>\n\n".'<a href="https://gravityview.co/gravityforms/" class="button button-secondary button-large button-hero">' , '<em>', '</em>', '</a>'), |
|
| 359 | + 'message' => sprintf( __( '%sGravityView requires Gravity Forms to be installed in order to run properly. %sGet Gravity Forms%s - starting at $59%s%s', 'gravityview' ), '<h3>', "</h3>\n\n" . '<a href="https://gravityview.co/gravityforms/" class="button button-secondary button-large button-hero">', '<em>', '</em>', '</a>' ), |
|
| 360 | 360 | 'cap' => 'install_plugins', |
| 361 | 361 | 'dismiss' => 'gf_installed', |
| 362 | 362 | ); |
@@ -373,10 +373,10 @@ discard block |
||
| 373 | 373 | */ |
| 374 | 374 | private static function check_gf_directory() { |
| 375 | 375 | |
| 376 | - if( class_exists( 'GFDirectory' ) ) { |
|
| 377 | - self::$notices['gf_directory'] = array( |
|
| 376 | + if ( class_exists( 'GFDirectory' ) ) { |
|
| 377 | + self::$notices[ 'gf_directory' ] = array( |
|
| 378 | 378 | 'class' => 'error is-dismissible', |
| 379 | - 'title' => __('Potential Conflict', 'gravityview' ), |
|
| 379 | + 'title' => __( 'Potential Conflict', 'gravityview' ), |
|
| 380 | 380 | 'message' => __( 'GravityView and Gravity Forms Directory are both active. This may cause problems. If you experience issues, disable the Gravity Forms Directory plugin.', 'gravityview' ), |
| 381 | 381 | 'dismiss' => 'gf_directory', |
| 382 | 382 | 'cap' => 'activate_plugins', |
@@ -394,21 +394,21 @@ discard block |
||
| 394 | 394 | */ |
| 395 | 395 | public static function get_plugin_status( $location = '' ) { |
| 396 | 396 | |
| 397 | - if( ! function_exists('is_plugin_active') ) { |
|
| 397 | + if ( ! function_exists( 'is_plugin_active' ) ) { |
|
| 398 | 398 | include_once( ABSPATH . '/wp-admin/includes/plugin.php' ); |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - if( is_network_admin() && is_plugin_active_for_network( $location ) ) { |
|
| 401 | + if ( is_network_admin() && is_plugin_active_for_network( $location ) ) { |
|
| 402 | 402 | return true; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - if( ! is_network_admin() && is_plugin_active( $location ) ) { |
|
| 405 | + if ( ! is_network_admin() && is_plugin_active( $location ) ) { |
|
| 406 | 406 | return true; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - if( |
|
| 410 | - !file_exists( trailingslashit( WP_PLUGIN_DIR ) . $location ) && |
|
| 411 | - !file_exists( trailingslashit( WPMU_PLUGIN_DIR ) . $location ) |
|
| 409 | + if ( |
|
| 410 | + ! file_exists( trailingslashit( WP_PLUGIN_DIR ) . $location ) && |
|
| 411 | + ! file_exists( trailingslashit( WPMU_PLUGIN_DIR ) . $location ) |
|
| 412 | 412 | ) { |
| 413 | 413 | return false; |
| 414 | 414 | } |
@@ -221,7 +221,6 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @since 1.15 |
| 223 | 223 | * |
| 224 | - * @param string|null $content Content inside shortcode, if defined |
|
| 225 | 224 | * |
| 226 | 225 | * @return string|boolean If URL is fetched, the URL to the entry link. If not found, returns false. |
| 227 | 226 | */ |
@@ -316,7 +315,7 @@ discard block |
||
| 316 | 315 | * |
| 317 | 316 | * @since 1.15 |
| 318 | 317 | * |
| 319 | - * @param string $href URL |
|
| 318 | + * @param string|null $url |
|
| 320 | 319 | */ |
| 321 | 320 | private function maybe_add_field_values_query_args( $url ) { |
| 322 | 321 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | $atts = shortcode_atts( self::$defaults, $atts ); |
| 77 | 77 | |
| 78 | - $atts['action'] = 'edit'; |
|
| 78 | + $atts[ 'action' ] = 'edit'; |
|
| 79 | 79 | |
| 80 | 80 | return $this->shortcode( $atts, $content, $context ); |
| 81 | 81 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | $atts = shortcode_atts( self::$defaults, $atts ); |
| 93 | 93 | |
| 94 | - $atts['action'] = 'delete'; |
|
| 94 | + $atts[ 'action' ] = 'delete'; |
|
| 95 | 95 | |
| 96 | 96 | return $this->shortcode( $atts, $content, $context ); |
| 97 | 97 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | $this->settings = shortcode_atts( self::$defaults, $atts, $context ); |
| 133 | 133 | |
| 134 | - $this->view_id = empty( $this->settings['view_id'] ) ? GravityView_View::getInstance()->getViewId() : absint( $this->settings['view_id'] ); |
|
| 134 | + $this->view_id = empty( $this->settings[ 'view_id' ] ) ? GravityView_View::getInstance()->getViewId() : absint( $this->settings[ 'view_id' ] ); |
|
| 135 | 135 | |
| 136 | 136 | if ( empty( $this->view_id ) ) { |
| 137 | 137 | gravityview()->log->error( 'A View ID was not defined and we are not inside a View' ); |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | return null; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - $this->entry = $this->get_entry( $this->settings['entry_id'] ); |
|
| 142 | + $this->entry = $this->get_entry( $this->settings[ 'entry_id' ] ); |
|
| 143 | 143 | |
| 144 | 144 | if ( empty( $this->entry ) ) { |
| 145 | - gravityview()->log->error( 'An Entry ID was not defined or found. Entry ID: {entry_id}', array( 'entry_id' => $this->settings['entry_id'] ) ); |
|
| 145 | + gravityview()->log->error( 'An Entry ID was not defined or found. Entry ID: {entry_id}', array( 'entry_id' => $this->settings[ 'entry_id' ] ) ); |
|
| 146 | 146 | |
| 147 | 147 | return null; |
| 148 | 148 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | gravityview()->log->debug( '{context} atts:', array( 'context' => $context, 'data' => $atts ) ); |
| 151 | 151 | |
| 152 | 152 | if ( ! $this->has_cap() ) { |
| 153 | - gravityview()->log->error( 'User does not have the capability to {action} this entry: {entry_id}', array( 'action' => esc_attr( $this->settings['action'] ), 'entry_id' => $this->entry['id'] ) ); |
|
| 153 | + gravityview()->log->error( 'User does not have the capability to {action} this entry: {entry_id}', array( 'action' => esc_attr( $this->settings[ 'action' ] ), 'entry_id' => $this->entry[ 'id' ] ) ); |
|
| 154 | 154 | |
| 155 | 155 | return null; |
| 156 | 156 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // Get just the URL, not the tag |
| 167 | - if ( 'url' === $this->settings['return'] ) { |
|
| 167 | + if ( 'url' === $this->settings[ 'return' ] ) { |
|
| 168 | 168 | return $url; |
| 169 | 169 | } |
| 170 | 170 | |
@@ -185,13 +185,13 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | private function get_link_atts() { |
| 187 | 187 | |
| 188 | - wp_parse_str( $this->settings['link_atts'], $link_atts ); |
|
| 188 | + wp_parse_str( $this->settings[ 'link_atts' ], $link_atts ); |
|
| 189 | 189 | |
| 190 | - if ( 'delete' === $this->settings['action'] ) { |
|
| 191 | - $link_atts['onclick'] = isset( $link_atts['onclick'] ) ? $link_atts['onclick'] : GravityView_Delete_Entry::get_confirm_dialog(); |
|
| 190 | + if ( 'delete' === $this->settings[ 'action' ] ) { |
|
| 191 | + $link_atts[ 'onclick' ] = isset( $link_atts[ 'onclick' ] ) ? $link_atts[ 'onclick' ] : GravityView_Delete_Entry::get_confirm_dialog(); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - return (array) $link_atts; |
|
| 194 | + return (array)$link_atts; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | return do_shortcode( $content ); |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - switch ( $this->settings['action'] ) { |
|
| 214 | + switch ( $this->settings[ 'action' ] ) { |
|
| 215 | 215 | case 'edit': |
| 216 | 216 | $anchor_text = __( 'Edit Entry', 'gravityview' ); |
| 217 | 217 | break; |
@@ -239,9 +239,9 @@ discard block |
||
| 239 | 239 | private function get_url() { |
| 240 | 240 | |
| 241 | 241 | // if post_id is not defined, default to view_id |
| 242 | - $post_id = empty( $this->settings['post_id'] ) ? $this->view_id : $this->settings['post_id']; |
|
| 242 | + $post_id = empty( $this->settings[ 'post_id' ] ) ? $this->view_id : $this->settings[ 'post_id' ]; |
|
| 243 | 243 | |
| 244 | - switch ( $this->settings['action'] ) { |
|
| 244 | + switch ( $this->settings[ 'action' ] ) { |
|
| 245 | 245 | case 'edit': |
| 246 | 246 | $url = GravityView_Edit_Entry::get_edit_link( $this->entry, $this->view_id, $post_id ); |
| 247 | 247 | break; |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | */ |
| 267 | 267 | private function has_cap() { |
| 268 | 268 | |
| 269 | - switch ( $this->settings['action'] ) { |
|
| 269 | + switch ( $this->settings[ 'action' ] ) { |
|
| 270 | 270 | case 'edit': |
| 271 | 271 | $has_cap = GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry, $this->view_id ); |
| 272 | 272 | break; |
@@ -331,9 +331,9 @@ discard block |
||
| 331 | 331 | */ |
| 332 | 332 | private function maybe_add_field_values_query_args( $url ) { |
| 333 | 333 | |
| 334 | - if ( $url && ! empty( $this->settings['field_values'] ) ) { |
|
| 334 | + if ( $url && ! empty( $this->settings[ 'field_values' ] ) ) { |
|
| 335 | 335 | |
| 336 | - wp_parse_str( $this->settings['field_values'], $field_values ); |
|
| 336 | + wp_parse_str( $this->settings[ 'field_values' ], $field_values ); |
|
| 337 | 337 | |
| 338 | 338 | $url = add_query_arg( $field_values, $url ); |
| 339 | 339 | } |
@@ -67,7 +67,6 @@ |
||
| 67 | 67 | * |
| 68 | 68 | * @since 1.15 |
| 69 | 69 | * |
| 70 | - * @param array $allcaps An array of all the user's capabilities. |
|
| 71 | 70 | * @param array $caps Actual capabilities for meta capability. |
| 72 | 71 | * @param array $args Optional parameters passed to has_cap(), typically object ID. |
| 73 | 72 | * @param WP_User|null $user The user object, in WordPress 3.7.0 or higher |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | add_filter( 'members_get_capabilities', array( 'GravityView_Roles_Capabilities', 'merge_with_all_caps' ) ); |
| 57 | 57 | add_action( 'members_register_cap_groups', array( $this, 'members_register_cap_group' ), 20 ); |
| 58 | 58 | add_filter( 'user_has_cap', array( $this, 'filter_user_has_cap' ), 10, 4 ); |
| 59 | - add_action( 'admin_init', array( $this, 'add_caps') ); |
|
| 59 | + add_action( 'admin_init', array( $this, 'add_caps') ); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | |
@@ -360,7 +360,6 @@ discard block |
||
| 360 | 360 | * Add Gravity Forms and GravityView's "full access" caps when any other caps are checked against. |
| 361 | 361 | * |
| 362 | 362 | * @since 1.15 |
| 363 | - |
|
| 364 | 363 | * @param array $caps_to_check |
| 365 | 364 | * |
| 366 | 365 | * @return array |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public static function get_instance() { |
| 35 | 35 | |
| 36 | - if( ! self::$instance ) { |
|
| 36 | + if ( ! self::$instance ) { |
|
| 37 | 37 | self::$instance = new self; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | add_filter( 'members_get_capabilities', array( 'GravityView_Roles_Capabilities', 'merge_with_all_caps' ) ); |
| 57 | 57 | add_action( 'members_register_cap_groups', array( $this, 'members_register_cap_group' ), 20 ); |
| 58 | 58 | add_filter( 'user_has_cap', array( $this, 'filter_user_has_cap' ), 10, 4 ); |
| 59 | - add_action( 'admin_init', array( $this, 'add_caps') ); |
|
| 59 | + add_action( 'admin_init', array( $this, 'add_caps' ) ); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | |
@@ -77,18 +77,18 @@ discard block |
||
| 77 | 77 | public function filter_user_has_cap( $usercaps = array(), $caps = array(), $args = array(), $user = NULL ) { |
| 78 | 78 | |
| 79 | 79 | // Empty caps_to_check array |
| 80 | - if( ! $usercaps || ! $caps ) { |
|
| 80 | + if ( ! $usercaps || ! $caps ) { |
|
| 81 | 81 | return $usercaps; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | 85 | * Enable all GravityView caps_to_check if `gravityview_full_access` is enabled |
| 86 | 86 | */ |
| 87 | - if( ! empty( $usercaps['gravityview_full_access'] ) ) { |
|
| 87 | + if ( ! empty( $usercaps[ 'gravityview_full_access' ] ) ) { |
|
| 88 | 88 | |
| 89 | 89 | $all_gravityview_caps = self::all_caps(); |
| 90 | 90 | |
| 91 | - foreach( $all_gravityview_caps as $gv_cap ) { |
|
| 91 | + foreach ( $all_gravityview_caps as $gv_cap ) { |
|
| 92 | 92 | $usercaps[ $gv_cap ] = true; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | $all = $administrator; |
| 307 | 307 | |
| 308 | 308 | // If role is set, return caps_to_check for just that role. |
| 309 | - if( $single_role ) { |
|
| 309 | + if ( $single_role ) { |
|
| 310 | 310 | $caps = isset( ${$single_role} ) ? ${$single_role} : false; |
| 311 | 311 | return $flat_array ? $caps : array( $single_role => $caps ); |
| 312 | 312 | } |
@@ -355,9 +355,9 @@ discard block |
||
| 355 | 355 | |
| 356 | 356 | if ( true === $allow_logged_out ) { |
| 357 | 357 | |
| 358 | - $all_caps = self::all_caps('editor'); |
|
| 358 | + $all_caps = self::all_caps( 'editor' ); |
|
| 359 | 359 | |
| 360 | - if( array_intersect( $all_caps, (array) $caps_to_check ) ) { |
|
| 360 | + if ( array_intersect( $all_caps, (array)$caps_to_check ) ) { |
|
| 361 | 361 | return true; |
| 362 | 362 | } |
| 363 | 363 | } |
@@ -378,13 +378,13 @@ discard block |
||
| 378 | 378 | $caps_to_check = self::maybe_add_full_access_caps( $caps_to_check ); |
| 379 | 379 | |
| 380 | 380 | foreach ( $caps_to_check as $cap ) { |
| 381 | - if( ! is_null( $object_id ) ) { |
|
| 381 | + if ( ! is_null( $object_id ) ) { |
|
| 382 | 382 | $has_cap = $user_id ? user_can( $user_id, $cap, $object_id ) : current_user_can( $cap, $object_id ); |
| 383 | 383 | } else { |
| 384 | 384 | $has_cap = $user_id ? user_can( $user_id, $cap ) : current_user_can( $cap ); |
| 385 | 385 | } |
| 386 | 386 | // At the first successful response, stop checking |
| 387 | - if( $has_cap ) { |
|
| 387 | + if ( $has_cap ) { |
|
| 388 | 388 | break; |
| 389 | 389 | } |
| 390 | 390 | } |
@@ -408,15 +408,15 @@ discard block |
||
| 408 | 408 | $all_gravityview_caps = self::all_caps(); |
| 409 | 409 | |
| 410 | 410 | // Are there any $caps_to_check that are from GravityView? |
| 411 | - if( $has_gravityview_caps = array_intersect( $caps_to_check, $all_gravityview_caps ) ) { |
|
| 412 | - $caps_to_check[] = 'gravityview_full_access'; |
|
| 411 | + if ( $has_gravityview_caps = array_intersect( $caps_to_check, $all_gravityview_caps ) ) { |
|
| 412 | + $caps_to_check[ ] = 'gravityview_full_access'; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | $all_gravity_forms_caps = class_exists( 'GFCommon' ) ? GFCommon::all_caps() : array(); |
| 416 | 416 | |
| 417 | 417 | // Are there any $caps_to_check that are from Gravity Forms? |
| 418 | - if( $all_gravity_forms_caps = array_intersect( $caps_to_check, $all_gravity_forms_caps ) ) { |
|
| 419 | - $caps_to_check[] = 'gform_full_access'; |
|
| 418 | + if ( $all_gravity_forms_caps = array_intersect( $caps_to_check, $all_gravity_forms_caps ) ) { |
|
| 419 | + $caps_to_check[ ] = 'gform_full_access'; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | return array_unique( $caps_to_check ); |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | $capabilities = self::all_caps(); |
| 439 | 439 | |
| 440 | 440 | // Loop through each role and remove GV caps_to_check |
| 441 | - foreach( $wp_roles->get_names() as $role_slug => $role_name ) { |
|
| 441 | + foreach ( $wp_roles->get_names() as $role_slug => $role_name ) { |
|
| 442 | 442 | foreach ( $capabilities as $cap ) { |
| 443 | 443 | $wp_roles->remove_cap( $role_slug, $cap ); |
| 444 | 444 | } |
@@ -37,6 +37,9 @@ discard block |
||
| 37 | 37 | public $active_areas; |
| 38 | 38 | |
| 39 | 39 | |
| 40 | + /** |
|
| 41 | + * @param string $id |
|
| 42 | + */ |
|
| 40 | 43 | function __construct( $id, $settings = array(), $field_options = array(), $areas = array() ) { |
| 41 | 44 | |
| 42 | 45 | if ( empty( $id ) ) { |
@@ -144,6 +147,9 @@ discard block |
||
| 144 | 147 | return $areas; |
| 145 | 148 | } |
| 146 | 149 | |
| 150 | + /** |
|
| 151 | + * @param string $context |
|
| 152 | + */ |
|
| 147 | 153 | public function get_active_areas( $context ) { |
| 148 | 154 | if ( isset( $this->active_areas[ $context ] ) ) { |
| 149 | 155 | return $this->active_areas[ $context ]; |
@@ -156,8 +162,8 @@ discard block |
||
| 156 | 162 | /** |
| 157 | 163 | * Assign template specific field options |
| 158 | 164 | * |
| 159 | - * @param array $options (default: array()) |
|
| 160 | - * @param string $template (default: '') |
|
| 165 | + * @param array $field_options (default: array()) |
|
| 166 | + * @param string $template_id (default: '') |
|
| 161 | 167 | * @param string $field_id key for the field |
| 162 | 168 | * @param string|array $context Context for the field; `directory` or `single` for example. |
| 163 | 169 | * |
@@ -193,8 +193,8 @@ discard block |
||
| 193 | 193 | * @return string Path to XML file |
| 194 | 194 | */ |
| 195 | 195 | public function assign_form_xml( $xml = '', $template = '' ) { |
| 196 | - if ( $this->settings['type'] === 'preset' && ! empty( $this->settings['preset_form'] ) && $this->template_id === $template ) { |
|
| 197 | - return $this->settings['preset_form']; |
|
| 196 | + if ( $this->settings[ 'type' ] === 'preset' && ! empty( $this->settings[ 'preset_form' ] ) && $this->template_id === $template ) { |
|
| 197 | + return $this->settings[ 'preset_form' ]; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | return $xml; |
@@ -207,8 +207,8 @@ discard block |
||
| 207 | 207 | * @return string Path to XML file |
| 208 | 208 | */ |
| 209 | 209 | public function assign_fields_xml( $xml = '', $template = '' ) { |
| 210 | - if ( $this->settings['type'] === 'preset' && ! empty( $this->settings['preset_fields'] ) && $this->template_id === $template ) { |
|
| 211 | - return $this->settings['preset_fields']; |
|
| 210 | + if ( $this->settings[ 'type' ] === 'preset' && ! empty( $this->settings[ 'preset_fields' ] ) && $this->template_id === $template ) { |
|
| 211 | + return $this->settings[ 'preset_fields' ]; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | return $xml; |
@@ -226,8 +226,8 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | public function assign_view_slug( $default, $context ) { |
| 228 | 228 | |
| 229 | - if ( ! empty( $this->settings['slug'] ) ) { |
|
| 230 | - return $this->settings['slug']; |
|
| 229 | + if ( ! empty( $this->settings[ 'slug' ] ) ) { |
|
| 230 | + return $this->settings[ 'slug' ]; |
|
| 231 | 231 | } |
| 232 | 232 | if ( ! empty( $default ) ) { |
| 233 | 233 | return $default; |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | * @return void |
| 245 | 245 | */ |
| 246 | 246 | public function register_styles() { |
| 247 | - if ( ! empty( $this->settings['css_source'] ) ) { |
|
| 248 | - wp_register_style( 'gravityview_style_' . $this->template_id, $this->settings['css_source'], array(), GravityView_Plugin::version, 'all' ); |
|
| 247 | + if ( ! empty( $this->settings[ 'css_source' ] ) ) { |
|
| 248 | + wp_register_style( 'gravityview_style_' . $this->template_id, $this->settings[ 'css_source' ], array(), GravityView_Plugin::version, 'all' ); |
|
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | |
@@ -69,7 +69,6 @@ |
||
| 69 | 69 | * Change wording for the Edit context to read Entry Creator |
| 70 | 70 | * |
| 71 | 71 | * @param array $visibility_caps Array of capabilities to display in field dropdown. |
| 72 | - * @param string $field_type Type of field options to render (`field` or `widget`) |
|
| 73 | 72 | * @param string $template_id Table slug |
| 74 | 73 | * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
| 75 | 74 | * @param string $context What context are we in? Example: `single` or `directory` |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | function load() { |
| 26 | 26 | |
| 27 | - if( !is_admin() ) { |
|
| 27 | + if ( ! is_admin() ) { |
|
| 28 | 28 | return; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | add_filter( 'gravityview_template_edit_link_options', array( $this, 'edit_link_field_options' ), 10, 5 ); |
| 39 | 39 | |
| 40 | 40 | // add tooltips |
| 41 | - add_filter( 'gravityview/metaboxes/tooltips', array( $this, 'tooltips') ); |
|
| 41 | + add_filter( 'gravityview/metaboxes/tooltips', array( $this, 'tooltips' ) ); |
|
| 42 | 42 | |
| 43 | 43 | // custom fields' options for zone EDIT |
| 44 | 44 | add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 6 ); |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
| 79 | 79 | |
| 80 | - if( $zone !== 'edit' ) { |
|
| 80 | + if ( $zone !== 'edit' ) { |
|
| 81 | 81 | |
| 82 | - $entry_default_fields['edit_link'] = array( |
|
| 83 | - 'label' => __('Edit Entry', 'gravityview'), |
|
| 82 | + $entry_default_fields[ 'edit_link' ] = array( |
|
| 83 | + 'label' => __( 'Edit Entry', 'gravityview' ), |
|
| 84 | 84 | 'type' => 'edit_link', |
| 85 | - 'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
| 85 | + 'desc' => __( 'A link to edit the entry. Visible based on View settings.', 'gravityview' ), |
|
| 86 | 86 | 'icon' => 'dashicons-welcome-write-blog', |
| 87 | 87 | ); |
| 88 | 88 | |
@@ -107,12 +107,12 @@ discard block |
||
| 107 | 107 | $caps = $visibility_caps; |
| 108 | 108 | |
| 109 | 109 | // If we're configuring fields in the edit context, we want a limited selection |
| 110 | - if( $context === 'edit' ) { |
|
| 110 | + if ( $context === 'edit' ) { |
|
| 111 | 111 | |
| 112 | 112 | // Remove other built-in caps. |
| 113 | - unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
| 113 | + unset( $caps[ 'publish_posts' ], $caps[ 'gravityforms_view_entries' ], $caps[ 'delete_others_posts' ] ); |
|
| 114 | 114 | |
| 115 | - $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
| 115 | + $caps[ 'read' ] = _x( 'Entry Creator', 'User capability', 'gravityview' ); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | return $caps; |
@@ -130,16 +130,16 @@ discard block |
||
| 130 | 130 | function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
| 131 | 131 | |
| 132 | 132 | // Always a link, never a filter |
| 133 | - unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
| 133 | + unset( $field_options[ 'show_as_link' ], $field_options[ 'search_filter' ] ); |
|
| 134 | 134 | |
| 135 | 135 | // Edit Entry link should only appear to visitors capable of editing entries |
| 136 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 136 | + unset( $field_options[ 'only_loggedin' ], $field_options[ 'only_loggedin_cap' ] ); |
|
| 137 | 137 | |
| 138 | - $add_option['edit_link'] = array( |
|
| 138 | + $add_option[ 'edit_link' ] = array( |
|
| 139 | 139 | 'type' => 'text', |
| 140 | 140 | 'label' => __( 'Edit Link Text', 'gravityview' ), |
| 141 | 141 | 'desc' => NULL, |
| 142 | - 'value' => __('Edit Entry', 'gravityview'), |
|
| 142 | + 'value' => __( 'Edit Entry', 'gravityview' ), |
|
| 143 | 143 | 'merge_tags' => true, |
| 144 | 144 | ); |
| 145 | 145 | |
@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | $return = $tooltips; |
| 157 | 157 | |
| 158 | - $return['allow_edit_cap'] = array( |
|
| 159 | - 'title' => __('Limiting Edit Access', 'gravityview'), |
|
| 160 | - 'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
| 158 | + $return[ 'allow_edit_cap' ] = array( |
|
| 159 | + 'title' => __( 'Limiting Edit Access', 'gravityview' ), |
|
| 160 | + 'value' => __( 'Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview' ), |
|
| 161 | 161 | ); |
| 162 | 162 | |
| 163 | 163 | return $return; |
@@ -175,12 +175,12 @@ discard block |
||
| 175 | 175 | public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) { |
| 176 | 176 | |
| 177 | 177 | // We only want to modify the settings for the edit context |
| 178 | - if( 'edit' !== $context ) { |
|
| 178 | + if ( 'edit' !== $context ) { |
|
| 179 | 179 | |
| 180 | 180 | /** |
| 181 | 181 | * @since 1.8.4 |
| 182 | 182 | */ |
| 183 | - $field_options['new_window'] = array( |
|
| 183 | + $field_options[ 'new_window' ] = array( |
|
| 184 | 184 | 'type' => 'checkbox', |
| 185 | 185 | 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
| 186 | 186 | 'value' => false, |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | // Entry field is only for logged in users |
| 193 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 193 | + unset( $field_options[ 'only_loggedin' ], $field_options[ 'only_loggedin_cap' ] ); |
|
| 194 | 194 | |
| 195 | 195 | $add_options = array( |
| 196 | 196 | 'allow_edit_cap' => array( |
@@ -10,42 +10,42 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | if ( ! defined( 'WPINC' ) ) { |
| 13 | - die; |
|
| 13 | + die; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | class GravityView_Edit_Entry_Admin { |
| 18 | 18 | |
| 19 | - protected $loader; |
|
| 19 | + protected $loader; |
|
| 20 | 20 | |
| 21 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
| 22 | - $this->loader = $loader; |
|
| 23 | - } |
|
| 21 | + function __construct( GravityView_Edit_Entry $loader ) { |
|
| 22 | + $this->loader = $loader; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - function load() { |
|
| 25 | + function load() { |
|
| 26 | 26 | |
| 27 | - if( !is_admin() ) { |
|
| 28 | - return; |
|
| 29 | - } |
|
| 27 | + if( !is_admin() ) { |
|
| 28 | + return; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - // Add Edit Link as a default field, outside those set in the Gravity Form form |
|
| 32 | - add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 ); |
|
| 31 | + // Add Edit Link as a default field, outside those set in the Gravity Form form |
|
| 32 | + add_filter( 'gravityview_entry_default_fields', array( $this, 'add_default_field' ), 10, 3 ); |
|
| 33 | 33 | |
| 34 | - // For the Edit Entry Link, you don't want visible to all users. |
|
| 35 | - add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 ); |
|
| 34 | + // For the Edit Entry Link, you don't want visible to all users. |
|
| 35 | + add_filter( 'gravityview_field_visibility_caps', array( $this, 'modify_visibility_caps' ), 10, 5 ); |
|
| 36 | 36 | |
| 37 | - // Modify the field options based on the name of the field type |
|
| 38 | - add_filter( 'gravityview_template_edit_link_options', array( $this, 'edit_link_field_options' ), 10, 5 ); |
|
| 37 | + // Modify the field options based on the name of the field type |
|
| 38 | + add_filter( 'gravityview_template_edit_link_options', array( $this, 'edit_link_field_options' ), 10, 5 ); |
|
| 39 | 39 | |
| 40 | - // add tooltips |
|
| 41 | - add_filter( 'gravityview/metaboxes/tooltips', array( $this, 'tooltips') ); |
|
| 40 | + // add tooltips |
|
| 41 | + add_filter( 'gravityview/metaboxes/tooltips', array( $this, 'tooltips') ); |
|
| 42 | 42 | |
| 43 | - // custom fields' options for zone EDIT |
|
| 44 | - add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 6 ); |
|
| 43 | + // custom fields' options for zone EDIT |
|
| 44 | + add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 6 ); |
|
| 45 | 45 | |
| 46 | - // Add Edit Entry settings to View Settings |
|
| 47 | - add_action( 'gravityview/metaboxes/edit_entry', array( $this, 'view_settings_metabox' ) ); |
|
| 48 | - } |
|
| 46 | + // Add Edit Entry settings to View Settings |
|
| 47 | + add_action( 'gravityview/metaboxes/edit_entry', array( $this, 'view_settings_metabox' ) ); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Render Edit Entry View metabox settings |
@@ -69,101 +69,101 @@ discard block |
||
| 69 | 69 | GravityView_Render_Settings::render_setting_row( 'edit_redirect_url', $current_settings ); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Add Edit Link as a default field, outside those set in the Gravity Form form |
|
| 74 | - * @param array $entry_default_fields Existing fields |
|
| 75 | - * @param string|array $form form_ID or form object |
|
| 76 | - * @param string $zone Either 'single', 'directory', 'header', 'footer' |
|
| 77 | - */ |
|
| 78 | - function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
| 79 | - |
|
| 80 | - if( $zone !== 'edit' ) { |
|
| 81 | - |
|
| 82 | - $entry_default_fields['edit_link'] = array( |
|
| 83 | - 'label' => __('Edit Entry', 'gravityview'), |
|
| 84 | - 'type' => 'edit_link', |
|
| 85 | - 'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
| 86 | - 'icon' => 'dashicons-welcome-write-blog', |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return $entry_default_fields; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Change wording for the Edit context to read Entry Creator |
|
| 96 | - * |
|
| 97 | - * @param array $visibility_caps Array of capabilities to display in field dropdown. |
|
| 98 | - * @param string $field_type Type of field options to render (`field` or `widget`) |
|
| 99 | - * @param string $template_id Table slug |
|
| 100 | - * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
|
| 101 | - * @param string $context What context are we in? Example: `single` or `directory` |
|
| 102 | - * @param string $input_type (textarea, list, select, etc.) |
|
| 103 | - * @return array Array of field options with `label`, `value`, `type`, `default` keys |
|
| 104 | - */ |
|
| 105 | - function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
| 106 | - |
|
| 107 | - $caps = $visibility_caps; |
|
| 108 | - |
|
| 109 | - // If we're configuring fields in the edit context, we want a limited selection |
|
| 110 | - if( $context === 'edit' ) { |
|
| 111 | - |
|
| 112 | - // Remove other built-in caps. |
|
| 113 | - unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
| 114 | - |
|
| 115 | - $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return $caps; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Add "Edit Link Text" setting to the edit_link field settings |
|
| 123 | - * |
|
| 124 | - * @param array $field_options |
|
| 125 | - * @param string $template_id |
|
| 126 | - * @param string $field_id |
|
| 127 | - * @param string $context |
|
| 128 | - * @param string $input_type |
|
| 129 | - * |
|
| 130 | - * @return array $field_options, with "Edit Link Text" field option |
|
| 131 | - */ |
|
| 132 | - function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 133 | - |
|
| 134 | - // Always a link, never a filter |
|
| 135 | - unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
| 136 | - |
|
| 137 | - // Edit Entry link should only appear to visitors capable of editing entries |
|
| 138 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 139 | - |
|
| 140 | - $add_option['edit_link'] = array( |
|
| 141 | - 'type' => 'text', |
|
| 142 | - 'label' => __( 'Edit Link Text', 'gravityview' ), |
|
| 143 | - 'desc' => NULL, |
|
| 144 | - 'value' => __('Edit Entry', 'gravityview'), |
|
| 145 | - 'merge_tags' => true, |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - return array_merge( $add_option, $field_options ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Add tooltips |
|
| 153 | - * @param array $tooltips Existing tooltips |
|
| 154 | - * @return array Modified tooltips |
|
| 155 | - */ |
|
| 156 | - function tooltips( $tooltips ) { |
|
| 157 | - |
|
| 158 | - $return = $tooltips; |
|
| 159 | - |
|
| 160 | - $return['allow_edit_cap'] = array( |
|
| 161 | - 'title' => __('Limiting Edit Access', 'gravityview'), |
|
| 162 | - 'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
| 163 | - ); |
|
| 164 | - |
|
| 165 | - return $return; |
|
| 166 | - } |
|
| 72 | + /** |
|
| 73 | + * Add Edit Link as a default field, outside those set in the Gravity Form form |
|
| 74 | + * @param array $entry_default_fields Existing fields |
|
| 75 | + * @param string|array $form form_ID or form object |
|
| 76 | + * @param string $zone Either 'single', 'directory', 'header', 'footer' |
|
| 77 | + */ |
|
| 78 | + function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
| 79 | + |
|
| 80 | + if( $zone !== 'edit' ) { |
|
| 81 | + |
|
| 82 | + $entry_default_fields['edit_link'] = array( |
|
| 83 | + 'label' => __('Edit Entry', 'gravityview'), |
|
| 84 | + 'type' => 'edit_link', |
|
| 85 | + 'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
| 86 | + 'icon' => 'dashicons-welcome-write-blog', |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return $entry_default_fields; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Change wording for the Edit context to read Entry Creator |
|
| 96 | + * |
|
| 97 | + * @param array $visibility_caps Array of capabilities to display in field dropdown. |
|
| 98 | + * @param string $field_type Type of field options to render (`field` or `widget`) |
|
| 99 | + * @param string $template_id Table slug |
|
| 100 | + * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
|
| 101 | + * @param string $context What context are we in? Example: `single` or `directory` |
|
| 102 | + * @param string $input_type (textarea, list, select, etc.) |
|
| 103 | + * @return array Array of field options with `label`, `value`, `type`, `default` keys |
|
| 104 | + */ |
|
| 105 | + function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
| 106 | + |
|
| 107 | + $caps = $visibility_caps; |
|
| 108 | + |
|
| 109 | + // If we're configuring fields in the edit context, we want a limited selection |
|
| 110 | + if( $context === 'edit' ) { |
|
| 111 | + |
|
| 112 | + // Remove other built-in caps. |
|
| 113 | + unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
| 114 | + |
|
| 115 | + $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return $caps; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Add "Edit Link Text" setting to the edit_link field settings |
|
| 123 | + * |
|
| 124 | + * @param array $field_options |
|
| 125 | + * @param string $template_id |
|
| 126 | + * @param string $field_id |
|
| 127 | + * @param string $context |
|
| 128 | + * @param string $input_type |
|
| 129 | + * |
|
| 130 | + * @return array $field_options, with "Edit Link Text" field option |
|
| 131 | + */ |
|
| 132 | + function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 133 | + |
|
| 134 | + // Always a link, never a filter |
|
| 135 | + unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
| 136 | + |
|
| 137 | + // Edit Entry link should only appear to visitors capable of editing entries |
|
| 138 | + unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 139 | + |
|
| 140 | + $add_option['edit_link'] = array( |
|
| 141 | + 'type' => 'text', |
|
| 142 | + 'label' => __( 'Edit Link Text', 'gravityview' ), |
|
| 143 | + 'desc' => NULL, |
|
| 144 | + 'value' => __('Edit Entry', 'gravityview'), |
|
| 145 | + 'merge_tags' => true, |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + return array_merge( $add_option, $field_options ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Add tooltips |
|
| 153 | + * @param array $tooltips Existing tooltips |
|
| 154 | + * @return array Modified tooltips |
|
| 155 | + */ |
|
| 156 | + function tooltips( $tooltips ) { |
|
| 157 | + |
|
| 158 | + $return = $tooltips; |
|
| 159 | + |
|
| 160 | + $return['allow_edit_cap'] = array( |
|
| 161 | + 'title' => __('Limiting Edit Access', 'gravityview'), |
|
| 162 | + 'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
| 163 | + ); |
|
| 164 | + |
|
| 165 | + return $return; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | 169 | * Add "Edit Link Text" setting to the edit_link field settings |
@@ -179,37 +179,37 @@ discard block |
||
| 179 | 179 | */ |
| 180 | 180 | public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) { |
| 181 | 181 | |
| 182 | - // We only want to modify the settings for the edit context |
|
| 183 | - if( 'edit' !== $context ) { |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @since 1.8.4 |
|
| 187 | - */ |
|
| 188 | - $field_options['new_window'] = array( |
|
| 189 | - 'type' => 'checkbox', |
|
| 190 | - 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
| 191 | - 'value' => false, |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - return $field_options; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // Entry field is only for logged in users |
|
| 198 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 199 | - |
|
| 200 | - $add_options = array( |
|
| 201 | - 'allow_edit_cap' => array( |
|
| 202 | - 'type' => 'select', |
|
| 203 | - 'label' => __( 'Make field editable to:', 'gravityview' ), |
|
| 204 | - 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
| 205 | - 'tooltip' => 'allow_edit_cap', |
|
| 206 | - 'class' => 'widefat', |
|
| 207 | - 'value' => 'read', // Default: entry creator |
|
| 208 | - ), |
|
| 209 | - ); |
|
| 210 | - |
|
| 211 | - return array_merge( $field_options, $add_options ); |
|
| 212 | - } |
|
| 182 | + // We only want to modify the settings for the edit context |
|
| 183 | + if( 'edit' !== $context ) { |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @since 1.8.4 |
|
| 187 | + */ |
|
| 188 | + $field_options['new_window'] = array( |
|
| 189 | + 'type' => 'checkbox', |
|
| 190 | + 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
| 191 | + 'value' => false, |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + return $field_options; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // Entry field is only for logged in users |
|
| 198 | + unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 199 | + |
|
| 200 | + $add_options = array( |
|
| 201 | + 'allow_edit_cap' => array( |
|
| 202 | + 'type' => 'select', |
|
| 203 | + 'label' => __( 'Make field editable to:', 'gravityview' ), |
|
| 204 | + 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
| 205 | + 'tooltip' => 'allow_edit_cap', |
|
| 206 | + 'class' => 'widefat', |
|
| 207 | + 'value' => 'read', // Default: entry creator |
|
| 208 | + ), |
|
| 209 | + ); |
|
| 210 | + |
|
| 211 | + return array_merge( $field_options, $add_options ); |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | 214 | |
| 215 | 215 | } // end class |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | * @since 1.11 |
| 58 | 58 | * |
| 59 | 59 | * @param array $form Gravity Forms form array |
| 60 | - * @param string $entry_id Gravity Forms entry ID |
|
| 60 | + * @param integer $entry_id Gravity Forms entry ID |
|
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | 63 | public function update_user( $form = array(), $entry_id = 0 ) { |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * @since 1.11 |
| 53 | 53 | * @param boolean $boolean Whether to trigger update on user registration (default: true) |
| 54 | 54 | */ |
| 55 | - if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
| 55 | + if ( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
| 56 | 56 | |
| 57 | - add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
| 57 | + add_action( 'gravityview/edit_entry/after_update', array( $this, 'update_user' ), 10, 2 ); |
|
| 58 | 58 | |
| 59 | 59 | // last resort in case the current user display name don't match any of the defaults |
| 60 | 60 | add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function update_user( $form = array(), $entry_id = 0 ) { |
| 74 | 74 | |
| 75 | - if( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) ) { |
|
| 75 | + if ( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) ) { |
|
| 76 | 76 | gravityview()->log->error( 'GFAPI or User Registration class not found; not updating the user' ); |
| 77 | 77 | return; |
| 78 | - } elseif( empty( $entry_id ) ) { |
|
| 78 | + } elseif ( empty( $entry_id ) ) { |
|
| 79 | 79 | gravityview()->log->error( 'Entry ID is empty [{entry_id}]; not updating the user', array( 'entry_id' => $entry_id ) ); |
| 80 | 80 | return; |
| 81 | 81 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | // If an Update feed, make sure the conditions are met. |
| 104 | 104 | if ( \GV\Utils::get( $config, 'meta/feedType' ) === 'update' ) { |
| 105 | - if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 105 | + if ( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 106 | 106 | return; |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | remove_filter( 'send_email_change_email', '__return_false', 3 ); |
| 119 | 119 | |
| 120 | 120 | // Prevent double-triggering by removing the hook |
| 121 | - remove_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10 ); |
|
| 121 | + remove_action( 'gravityview/edit_entry/after_update', array( $this, 'update_user' ), 10 ); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -151,17 +151,17 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
| 153 | 153 | |
| 154 | - if( $preserve_role ) { |
|
| 155 | - $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 154 | + if ( $preserve_role ) { |
|
| 155 | + $config[ 'meta' ][ 'role' ] = 'gfur_preserve_role'; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 158 | + $displayname = $this->match_current_display_name( $entry[ 'created_by' ] ); |
|
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | 161 | * Make sure the current display name is not changed with the update user method. |
| 162 | 162 | * @since 1.15 |
| 163 | 163 | */ |
| 164 | - $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 164 | + $config[ 'meta' ][ 'displayname' ] = $displayname ? $displayname : $config[ 'meta' ][ 'displayname' ]; |
|
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | 167 | * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | $user = get_userdata( $user_id ); |
| 190 | 190 | |
| 191 | - if( ! $user ) { |
|
| 191 | + if ( ! $user ) { |
|
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
| 201 | 201 | * @see restore_display_name |
| 202 | 202 | */ |
| 203 | - if( false === $format ) { |
|
| 203 | + if ( false === $format ) { |
|
| 204 | 204 | $this->_user_before_update = $user; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -218,20 +218,20 @@ discard block |
||
| 218 | 218 | public function generate_display_names( $profileuser ) { |
| 219 | 219 | |
| 220 | 220 | $public_display = array(); |
| 221 | - $public_display['nickname'] = $profileuser->nickname; |
|
| 222 | - $public_display['username'] = $profileuser->user_login; |
|
| 221 | + $public_display[ 'nickname' ] = $profileuser->nickname; |
|
| 222 | + $public_display[ 'username' ] = $profileuser->user_login; |
|
| 223 | 223 | |
| 224 | - if ( !empty($profileuser->first_name) ) { |
|
| 225 | - $public_display['firstname'] = $profileuser->first_name; |
|
| 224 | + if ( ! empty( $profileuser->first_name ) ) { |
|
| 225 | + $public_display[ 'firstname' ] = $profileuser->first_name; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - if ( !empty($profileuser->last_name) ) { |
|
| 229 | - $public_display['lastname'] = $profileuser->last_name; |
|
| 228 | + if ( ! empty( $profileuser->last_name ) ) { |
|
| 229 | + $public_display[ 'lastname' ] = $profileuser->last_name; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
| 233 | - $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
| 234 | - $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
| 232 | + if ( ! empty( $profileuser->first_name ) && ! empty( $profileuser->last_name ) ) { |
|
| 233 | + $public_display[ 'firstlast' ] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
| 234 | + $public_display[ 'lastfirst' ] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | $public_display = array_map( 'trim', $public_display ); |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * - or we don't need as we found the correct format before updating user. |
| 271 | 271 | * @since 1.14.4 |
| 272 | 272 | */ |
| 273 | - if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 273 | + if ( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 274 | 274 | return null; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | $updated = wp_update_user( $restored_user ); |
| 304 | 304 | |
| 305 | - if( is_wp_error( $updated ) ) { |
|
| 305 | + if ( is_wp_error( $updated ) ) { |
|
| 306 | 306 | gravityview()->log->error( 'There was an error updating user #{user_id} details', array( 'user_id' => $user_id, 'data' => $updated ) ); |
| 307 | 307 | } else { |
| 308 | 308 | gravityview()->log->debug( 'User #{user_id} details restored', array( 'user_id' => $user_id ) ); |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | if ( ! defined( 'WPINC' ) ) { |
| 14 | - die; |
|
| 14 | + die; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -22,103 +22,103 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * @var GravityView_Edit_Entry $loader |
| 24 | 24 | */ |
| 25 | - protected $loader; |
|
| 25 | + protected $loader; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var WP_User|null Temporary storage used by restore_user_details() |
|
| 29 | - */ |
|
| 30 | - private $_user_before_update = null; |
|
| 27 | + /** |
|
| 28 | + * @var WP_User|null Temporary storage used by restore_user_details() |
|
| 29 | + */ |
|
| 30 | + private $_user_before_update = null; |
|
| 31 | 31 | |
| 32 | - function __construct( GravityView_Edit_Entry $loader ) { |
|
| 33 | - $this->loader = $loader; |
|
| 34 | - } |
|
| 32 | + function __construct( GravityView_Edit_Entry $loader ) { |
|
| 33 | + $this->loader = $loader; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * @since 1.11 |
| 38 | 38 | */ |
| 39 | 39 | public function load() { |
| 40 | 40 | add_action( 'wp', array( $this, 'add_hooks' ), 10 ); |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Add hooks to trigger updating the user |
| 45 | 45 | * |
| 46 | 46 | * @since 1.18 |
| 47 | 47 | */ |
| 48 | - public function add_hooks() { |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated? |
|
| 52 | - * @since 1.11 |
|
| 53 | - * @param boolean $boolean Whether to trigger update on user registration (default: true) |
|
| 54 | - */ |
|
| 55 | - if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
| 56 | - |
|
| 57 | - add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
| 58 | - |
|
| 59 | - // last resort in case the current user display name don't match any of the defaults |
|
| 60 | - add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Update the WordPress user profile based on the GF User Registration create feed |
|
| 66 | - * |
|
| 67 | - * @since 1.11 |
|
| 68 | - * |
|
| 69 | - * @param array $form Gravity Forms form array |
|
| 70 | - * @param string $entry_id Gravity Forms entry ID |
|
| 71 | - * @return void |
|
| 72 | - */ |
|
| 73 | - public function update_user( $form = array(), $entry_id = 0 ) { |
|
| 74 | - |
|
| 75 | - if( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) ) { |
|
| 76 | - gravityview()->log->error( 'GFAPI or User Registration class not found; not updating the user' ); |
|
| 77 | - return; |
|
| 78 | - } elseif( empty( $entry_id ) ) { |
|
| 79 | - gravityview()->log->error( 'Entry ID is empty [{entry_id}]; not updating the user', array( 'entry_id' => $entry_id ) ); |
|
| 80 | - return; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 84 | - |
|
| 85 | - $entry = GFAPI::get_entry( $entry_id ); |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
| 89 | - * @since 1.11 |
|
| 90 | - * @param array $entry Gravity Forms entry |
|
| 91 | - * @param array $form Gravity Forms form |
|
| 92 | - */ |
|
| 93 | - $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
| 94 | - |
|
| 95 | - $config = $this->get_feed_configuration( $entry, $form ); |
|
| 96 | - |
|
| 97 | - // Make sure the feed is active |
|
| 98 | - if ( ! \GV\Utils::get( $config, 'is_active', false ) ) { |
|
| 48 | + public function add_hooks() { |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @filter `gravityview/edit_entry/user_registration/trigger_update` Choose whether to update user information via User Registration add-on when an entry is updated? |
|
| 52 | + * @since 1.11 |
|
| 53 | + * @param boolean $boolean Whether to trigger update on user registration (default: true) |
|
| 54 | + */ |
|
| 55 | + if( apply_filters( 'gravityview/edit_entry/user_registration/trigger_update', true ) ) { |
|
| 56 | + |
|
| 57 | + add_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10, 2 ); |
|
| 58 | + |
|
| 59 | + // last resort in case the current user display name don't match any of the defaults |
|
| 60 | + add_action( 'gform_user_updated', array( $this, 'restore_display_name' ), 10, 4 ); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Update the WordPress user profile based on the GF User Registration create feed |
|
| 66 | + * |
|
| 67 | + * @since 1.11 |
|
| 68 | + * |
|
| 69 | + * @param array $form Gravity Forms form array |
|
| 70 | + * @param string $entry_id Gravity Forms entry ID |
|
| 71 | + * @return void |
|
| 72 | + */ |
|
| 73 | + public function update_user( $form = array(), $entry_id = 0 ) { |
|
| 74 | + |
|
| 75 | + if( ! class_exists( 'GFAPI' ) || ! class_exists( 'GF_User_Registration' ) ) { |
|
| 76 | + gravityview()->log->error( 'GFAPI or User Registration class not found; not updating the user' ); |
|
| 99 | 77 | return; |
| 100 | - } |
|
| 78 | + } elseif( empty( $entry_id ) ) { |
|
| 79 | + gravityview()->log->error( 'Entry ID is empty [{entry_id}]; not updating the user', array( 'entry_id' => $entry_id ) ); |
|
| 80 | + return; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 84 | + |
|
| 85 | + $entry = GFAPI::get_entry( $entry_id ); |
|
| 101 | 86 | |
| 102 | - // If an Update feed, make sure the conditions are met. |
|
| 103 | - if ( \GV\Utils::get( $config, 'meta/feedType' ) === 'update' ) { |
|
| 104 | - if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 105 | - return; |
|
| 106 | - } |
|
| 107 | - } |
|
| 87 | + /** |
|
| 88 | + * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
| 89 | + * @since 1.11 |
|
| 90 | + * @param array $entry Gravity Forms entry |
|
| 91 | + * @param array $form Gravity Forms form |
|
| 92 | + */ |
|
| 93 | + $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
| 94 | + |
|
| 95 | + $config = $this->get_feed_configuration( $entry, $form ); |
|
| 96 | + |
|
| 97 | + // Make sure the feed is active |
|
| 98 | + if ( ! \GV\Utils::get( $config, 'is_active', false ) ) { |
|
| 99 | + return; |
|
| 100 | + } |
|
| 108 | 101 | |
| 109 | - // The priority is set to 3 so that default priority (10) will still override it |
|
| 110 | - add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 111 | - add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 102 | + // If an Update feed, make sure the conditions are met. |
|
| 103 | + if ( \GV\Utils::get( $config, 'meta/feedType' ) === 'update' ) { |
|
| 104 | + if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 105 | + return; |
|
| 106 | + } |
|
| 107 | + } |
|
| 112 | 108 | |
| 113 | - // Trigger the User Registration update user method |
|
| 114 | - $gf_user_registration->update_user( $entry, $form, $config ); |
|
| 109 | + // The priority is set to 3 so that default priority (10) will still override it |
|
| 110 | + add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 111 | + add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 115 | 112 | |
| 116 | - remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 117 | - remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 113 | + // Trigger the User Registration update user method |
|
| 114 | + $gf_user_registration->update_user( $entry, $form, $config ); |
|
| 118 | 115 | |
| 119 | - // Prevent double-triggering by removing the hook |
|
| 120 | - remove_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10 ); |
|
| 121 | - } |
|
| 116 | + remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 117 | + remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 118 | + |
|
| 119 | + // Prevent double-triggering by removing the hook |
|
| 120 | + remove_action( 'gravityview/edit_entry/after_update' , array( $this, 'update_user' ), 10 ); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | 124 | * Get the User Registration feed configuration for the entry & form |
@@ -133,184 +133,184 @@ discard block |
||
| 133 | 133 | * |
| 134 | 134 | * @return array |
| 135 | 135 | */ |
| 136 | - public function get_feed_configuration( $entry, $form ) { |
|
| 137 | - |
|
| 138 | - $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 139 | - |
|
| 140 | - $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
| 144 | - * @since 1.15 |
|
| 145 | - * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
| 146 | - * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
| 147 | - * @param[in] array $form Gravity Forms form array |
|
| 148 | - * @param[in] array $entry Gravity Forms entry being edited |
|
| 149 | - */ |
|
| 150 | - $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
| 151 | - |
|
| 152 | - if( $preserve_role ) { |
|
| 153 | - $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Make sure the current display name is not changed with the update user method. |
|
| 160 | - * @since 1.15 |
|
| 161 | - */ |
|
| 162 | - $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
| 166 | - * @since 1.14 |
|
| 167 | - * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
| 168 | - * @param[in] array $form Gravity Forms form array |
|
| 169 | - * @param[in] array $entry Gravity Forms entry being edited |
|
| 170 | - */ |
|
| 171 | - $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
| 172 | - |
|
| 173 | - return $config; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Calculate the user display name format |
|
| 178 | - * |
|
| 179 | - * @since 1.15 |
|
| 180 | - * @since 1.20 Returns false if user not found at $user_id |
|
| 181 | - * |
|
| 182 | - * @param int $user_id WP User ID |
|
| 183 | - * @return false|string Display name format as used inside Gravity Forms User Registration. Returns false if user not found. |
|
| 184 | - */ |
|
| 185 | - public function match_current_display_name( $user_id ) { |
|
| 186 | - |
|
| 187 | - $user = get_userdata( $user_id ); |
|
| 188 | - |
|
| 189 | - if( ! $user ) { |
|
| 190 | - return false; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - $names = $this->generate_display_names( $user ); |
|
| 194 | - |
|
| 195 | - $format = array_search( $user->display_name, $names, true ); |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
|
| 199 | - * @see restore_display_name |
|
| 200 | - */ |
|
| 201 | - if( false === $format ) { |
|
| 202 | - $this->_user_before_update = $user; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return $format; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Generate an array of all the user display names possibilities |
|
| 210 | - * |
|
| 211 | - * @since 1.15 |
|
| 212 | - * |
|
| 213 | - * @param object $profileuser WP_User object |
|
| 214 | - * @return array List all the possible display names for a certain User object |
|
| 215 | - */ |
|
| 216 | - public function generate_display_names( $profileuser ) { |
|
| 217 | - |
|
| 218 | - $public_display = array(); |
|
| 219 | - $public_display['nickname'] = $profileuser->nickname; |
|
| 220 | - $public_display['username'] = $profileuser->user_login; |
|
| 221 | - |
|
| 222 | - if ( !empty($profileuser->first_name) ) { |
|
| 223 | - $public_display['firstname'] = $profileuser->first_name; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - if ( !empty($profileuser->last_name) ) { |
|
| 227 | - $public_display['lastname'] = $profileuser->last_name; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
| 231 | - $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
| 232 | - $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $public_display = array_map( 'trim', $public_display ); |
|
| 236 | - $public_display = array_unique( $public_display ); |
|
| 237 | - |
|
| 238 | - return $public_display; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
| 244 | - * |
|
| 245 | - * @see GFUser::update_user() |
|
| 246 | - * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
| 247 | - * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
| 248 | - * @param array $entry The Gravity Forms entry that was just updated |
|
| 249 | - * @param string $password User password |
|
| 250 | - * @return int|false|WP_Error|null True: User updated; False: $user_id not a valid User ID; WP_Error: User update error; Null: Method didn't process |
|
| 251 | - */ |
|
| 252 | - public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
| 256 | - * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
| 257 | - * @since 1.14.4 |
|
| 258 | - * @param boolean $restore_display_name Restore Display Name? Default: true |
|
| 259 | - */ |
|
| 260 | - $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
| 261 | - |
|
| 262 | - $is_update_feed = ( $config && \GV\Utils::get( $config, 'meta/feed_type' ) === 'update' ); |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Don't restore display name: |
|
| 266 | - * - either disabled, |
|
| 267 | - * - or it is an Update feed (we only care about Create feed) |
|
| 268 | - * - or we don't need as we found the correct format before updating user. |
|
| 269 | - * @since 1.14.4 |
|
| 270 | - */ |
|
| 271 | - if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 272 | - return null; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - $user_after_update = get_userdata( $user_id ); |
|
| 276 | - |
|
| 277 | - // User not found |
|
| 278 | - if ( ! $user_after_update ) { |
|
| 279 | - gravityview()->log->error( 'User not found at $user_id #{user_id}', array( 'user_id' => $user_id ) ); |
|
| 280 | - return false; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - $restored_user = $user_after_update; |
|
| 284 | - |
|
| 285 | - // Restore previous display_name |
|
| 286 | - $restored_user->display_name = $this->_user_before_update->display_name; |
|
| 287 | - |
|
| 288 | - // Don't have WP update the password. |
|
| 289 | - unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
| 293 | - * @since 1.14 |
|
| 294 | - * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
| 295 | - * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
| 296 | - * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
| 297 | - * @param array $entry The Gravity Forms entry that was just updated |
|
| 298 | - */ |
|
| 299 | - $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
| 300 | - |
|
| 301 | - $updated = wp_update_user( $restored_user ); |
|
| 302 | - |
|
| 303 | - if( is_wp_error( $updated ) ) { |
|
| 304 | - gravityview()->log->error( 'There was an error updating user #{user_id} details', array( 'user_id' => $user_id, 'data' => $updated ) ); |
|
| 305 | - } else { |
|
| 306 | - gravityview()->log->debug( 'User #{user_id} details restored', array( 'user_id' => $user_id ) ); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $this->_user_before_update = null; |
|
| 310 | - |
|
| 311 | - unset( $restored_user, $user_after_update ); |
|
| 312 | - |
|
| 313 | - return $updated; |
|
| 314 | - } |
|
| 136 | + public function get_feed_configuration( $entry, $form ) { |
|
| 137 | + |
|
| 138 | + $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 139 | + |
|
| 140 | + $config = $gf_user_registration->get_single_submission_feed( $entry, $form ); |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @filter `gravityview/edit_entry/user_registration/preserve_role` Keep the current user role or override with the role defined in the Create feed |
|
| 144 | + * @since 1.15 |
|
| 145 | + * @param[in,out] boolean $preserve_role Preserve current user role Default: true |
|
| 146 | + * @param[in] array $config Gravity Forms User Registration feed configuration for the form |
|
| 147 | + * @param[in] array $form Gravity Forms form array |
|
| 148 | + * @param[in] array $entry Gravity Forms entry being edited |
|
| 149 | + */ |
|
| 150 | + $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
|
| 151 | + |
|
| 152 | + if( $preserve_role ) { |
|
| 153 | + $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Make sure the current display name is not changed with the update user method. |
|
| 160 | + * @since 1.15 |
|
| 161 | + */ |
|
| 162 | + $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
|
| 166 | + * @since 1.14 |
|
| 167 | + * @param[in,out] array $config Gravity Forms User Registration feed configuration for the form |
|
| 168 | + * @param[in] array $form Gravity Forms form array |
|
| 169 | + * @param[in] array $entry Gravity Forms entry being edited |
|
| 170 | + */ |
|
| 171 | + $config = apply_filters( 'gravityview/edit_entry/user_registration/config', $config, $form, $entry ); |
|
| 172 | + |
|
| 173 | + return $config; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Calculate the user display name format |
|
| 178 | + * |
|
| 179 | + * @since 1.15 |
|
| 180 | + * @since 1.20 Returns false if user not found at $user_id |
|
| 181 | + * |
|
| 182 | + * @param int $user_id WP User ID |
|
| 183 | + * @return false|string Display name format as used inside Gravity Forms User Registration. Returns false if user not found. |
|
| 184 | + */ |
|
| 185 | + public function match_current_display_name( $user_id ) { |
|
| 186 | + |
|
| 187 | + $user = get_userdata( $user_id ); |
|
| 188 | + |
|
| 189 | + if( ! $user ) { |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + $names = $this->generate_display_names( $user ); |
|
| 194 | + |
|
| 195 | + $format = array_search( $user->display_name, $names, true ); |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
|
| 199 | + * @see restore_display_name |
|
| 200 | + */ |
|
| 201 | + if( false === $format ) { |
|
| 202 | + $this->_user_before_update = $user; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return $format; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Generate an array of all the user display names possibilities |
|
| 210 | + * |
|
| 211 | + * @since 1.15 |
|
| 212 | + * |
|
| 213 | + * @param object $profileuser WP_User object |
|
| 214 | + * @return array List all the possible display names for a certain User object |
|
| 215 | + */ |
|
| 216 | + public function generate_display_names( $profileuser ) { |
|
| 217 | + |
|
| 218 | + $public_display = array(); |
|
| 219 | + $public_display['nickname'] = $profileuser->nickname; |
|
| 220 | + $public_display['username'] = $profileuser->user_login; |
|
| 221 | + |
|
| 222 | + if ( !empty($profileuser->first_name) ) { |
|
| 223 | + $public_display['firstname'] = $profileuser->first_name; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + if ( !empty($profileuser->last_name) ) { |
|
| 227 | + $public_display['lastname'] = $profileuser->last_name; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) { |
|
| 231 | + $public_display['firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name; |
|
| 232 | + $public_display['lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $public_display = array_map( 'trim', $public_display ); |
|
| 236 | + $public_display = array_unique( $public_display ); |
|
| 237 | + |
|
| 238 | + return $public_display; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Restore the Display Name and roles of a user after being updated by Gravity Forms User Registration Addon |
|
| 244 | + * |
|
| 245 | + * @see GFUser::update_user() |
|
| 246 | + * @param int $user_id WP User ID that was updated by Gravity Forms User Registration Addon |
|
| 247 | + * @param array $config Gravity Forms User Registration Addon form feed configuration |
|
| 248 | + * @param array $entry The Gravity Forms entry that was just updated |
|
| 249 | + * @param string $password User password |
|
| 250 | + * @return int|false|WP_Error|null True: User updated; False: $user_id not a valid User ID; WP_Error: User update error; Null: Method didn't process |
|
| 251 | + */ |
|
| 252 | + public function restore_display_name( $user_id = 0, $config = array(), $entry = array(), $password = '' ) { |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @filter `gravityview/edit_entry/restore_display_name` Whether display names should be restored to before updating an entry. |
|
| 256 | + * Otherwise, display names will be reset to the format specified in Gravity Forms User Registration "Update" feed |
|
| 257 | + * @since 1.14.4 |
|
| 258 | + * @param boolean $restore_display_name Restore Display Name? Default: true |
|
| 259 | + */ |
|
| 260 | + $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
|
| 261 | + |
|
| 262 | + $is_update_feed = ( $config && \GV\Utils::get( $config, 'meta/feed_type' ) === 'update' ); |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Don't restore display name: |
|
| 266 | + * - either disabled, |
|
| 267 | + * - or it is an Update feed (we only care about Create feed) |
|
| 268 | + * - or we don't need as we found the correct format before updating user. |
|
| 269 | + * @since 1.14.4 |
|
| 270 | + */ |
|
| 271 | + if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 272 | + return null; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + $user_after_update = get_userdata( $user_id ); |
|
| 276 | + |
|
| 277 | + // User not found |
|
| 278 | + if ( ! $user_after_update ) { |
|
| 279 | + gravityview()->log->error( 'User not found at $user_id #{user_id}', array( 'user_id' => $user_id ) ); |
|
| 280 | + return false; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + $restored_user = $user_after_update; |
|
| 284 | + |
|
| 285 | + // Restore previous display_name |
|
| 286 | + $restored_user->display_name = $this->_user_before_update->display_name; |
|
| 287 | + |
|
| 288 | + // Don't have WP update the password. |
|
| 289 | + unset( $restored_user->data->user_pass, $restored_user->user_pass ); |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Modify the user data after updated by Gravity Forms User Registration but before restored by GravityView |
|
| 293 | + * @since 1.14 |
|
| 294 | + * @param WP_User $restored_user The user with restored details about to be updated by wp_update_user() |
|
| 295 | + * @param WP_User $user_before_update The user before being updated by Gravity Forms User Registration |
|
| 296 | + * @param WP_User $user_after_update The user after being updated by Gravity Forms User Registration |
|
| 297 | + * @param array $entry The Gravity Forms entry that was just updated |
|
| 298 | + */ |
|
| 299 | + $restored_user = apply_filters( 'gravityview/edit_entry/user_registration/restored_user', $restored_user, $this->_user_before_update, $user_after_update, $entry ); |
|
| 300 | + |
|
| 301 | + $updated = wp_update_user( $restored_user ); |
|
| 302 | + |
|
| 303 | + if( is_wp_error( $updated ) ) { |
|
| 304 | + gravityview()->log->error( 'There was an error updating user #{user_id} details', array( 'user_id' => $user_id, 'data' => $updated ) ); |
|
| 305 | + } else { |
|
| 306 | + gravityview()->log->debug( 'User #{user_id} details restored', array( 'user_id' => $user_id ) ); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $this->_user_before_update = null; |
|
| 310 | + |
|
| 311 | + unset( $restored_user, $user_after_update ); |
|
| 312 | + |
|
| 313 | + return $updated; |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | 316 | } //end class |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | return; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - $class = !empty( $this->field['class'] ) ? $this->field['class'] : 'widefat'; |
|
| 18 | + $class = !empty( $this->field['class'] ) ? $this->field['class'] : 'widefat'; |
|
| 19 | 19 | |
| 20 | 20 | ?> |
| 21 | 21 | <input name="<?php echo esc_attr( $this->name ); ?>" id="<?php echo $this->get_field_id(); ?>" type="hidden" value="<?php echo esc_attr( $this->value ); ?>" class="<?php echo esc_attr( $class ); ?>" /> |
@@ -10,12 +10,12 @@ |
||
| 10 | 10 | |
| 11 | 11 | function render_input( $override_input = null ) { |
| 12 | 12 | |
| 13 | - if( isset( $override_input ) ) { |
|
| 13 | + if ( isset( $override_input ) ) { |
|
| 14 | 14 | echo $override_input; |
| 15 | 15 | return; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - $class = !empty( $this->field['class'] ) ? $this->field['class'] : 'widefat'; |
|
| 18 | + $class = ! empty( $this->field[ 'class' ] ) ? $this->field[ 'class' ] : 'widefat'; |
|
| 19 | 19 | |
| 20 | 20 | ?> |
| 21 | 21 | <input name="<?php echo esc_attr( $this->name ); ?>" id="<?php echo $this->get_field_id(); ?>" type="hidden" value="<?php echo esc_attr( $this->value ); ?>" class="<?php echo esc_attr( $class ); ?>" /> |