@@ -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` |
@@ -10,175 +10,175 @@ |
||
| 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() { |
|
| 26 | - |
|
| 27 | - if( !is_admin() ) { |
|
| 28 | - return; |
|
| 29 | - } |
|
| 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 ); |
|
| 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 ); |
|
| 25 | + function load() { |
|
| 26 | + |
|
| 27 | + if( !is_admin() ) { |
|
| 28 | + return; |
|
| 29 | + } |
|
| 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 ); |
|
| 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 ); |
|
| 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_tooltips', array( $this, 'tooltips') ); |
|
| 42 | - |
|
| 43 | - // custom fields' options for zone EDIT |
|
| 44 | - add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 5 ); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Add Edit Link as a default field, outside those set in the Gravity Form form |
|
| 49 | - * @param array $entry_default_fields Existing fields |
|
| 50 | - * @param string|array $form form_ID or form object |
|
| 51 | - * @param string $zone Either 'single', 'directory', 'header', 'footer' |
|
| 52 | - */ |
|
| 53 | - function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
| 54 | - |
|
| 55 | - if( $zone !== 'edit' ) { |
|
| 56 | - |
|
| 57 | - $entry_default_fields['edit_link'] = array( |
|
| 58 | - 'label' => __('Edit Entry', 'gravityview'), |
|
| 59 | - 'type' => 'edit_link', |
|
| 60 | - 'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
| 61 | - ); |
|
| 62 | - |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return $entry_default_fields; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Change wording for the Edit context to read Entry Creator |
|
| 70 | - * |
|
| 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 | - * @param string $template_id Table slug |
|
| 74 | - * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
|
| 75 | - * @param string $context What context are we in? Example: `single` or `directory` |
|
| 76 | - * @param string $input_type (textarea, list, select, etc.) |
|
| 77 | - * @return array Array of field options with `label`, `value`, `type`, `default` keys |
|
| 78 | - */ |
|
| 79 | - function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
| 80 | - |
|
| 81 | - $caps = $visibility_caps; |
|
| 82 | - |
|
| 83 | - // If we're configuring fields in the edit context, we want a limited selection |
|
| 84 | - if( $context === 'edit' ) { |
|
| 85 | - |
|
| 86 | - // Remove other built-in caps. |
|
| 87 | - unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
| 88 | - |
|
| 89 | - $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - return $caps; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Add "Edit Link Text" setting to the edit_link field settings |
|
| 97 | - * @param [type] $field_options [description] |
|
| 98 | - * @param [type] $template_id [description] |
|
| 99 | - * @param [type] $field_id [description] |
|
| 100 | - * @param [type] $context [description] |
|
| 101 | - * @param [type] $input_type [description] |
|
| 102 | - * @return [type] [description] |
|
| 103 | - */ |
|
| 104 | - function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 105 | - |
|
| 106 | - // Always a link, never a filter |
|
| 107 | - unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
| 108 | - |
|
| 109 | - // Edit Entry link should only appear to visitors capable of editing entries |
|
| 110 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 111 | - |
|
| 112 | - $add_option['edit_link'] = array( |
|
| 113 | - 'type' => 'text', |
|
| 114 | - 'label' => __( 'Edit Link Text', 'gravityview' ), |
|
| 115 | - 'desc' => NULL, |
|
| 116 | - 'value' => __('Edit Entry', 'gravityview'), |
|
| 117 | - 'merge_tags' => true, |
|
| 118 | - ); |
|
| 119 | - |
|
| 120 | - return array_merge( $add_option, $field_options ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Add tooltips |
|
| 125 | - * @param array $tooltips Existing tooltips |
|
| 126 | - * @return array Modified tooltips |
|
| 127 | - */ |
|
| 128 | - function tooltips( $tooltips ) { |
|
| 129 | - |
|
| 130 | - $return = $tooltips; |
|
| 131 | - |
|
| 132 | - $return['allow_edit_cap'] = array( |
|
| 133 | - 'title' => __('Limiting Edit Access', 'gravityview'), |
|
| 134 | - 'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
| 135 | - ); |
|
| 136 | - |
|
| 137 | - return $return; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Manipulate the fields' options for the EDIT ENTRY screen |
|
| 142 | - * @param [type] $field_options [description] |
|
| 143 | - * @param [type] $template_id [description] |
|
| 144 | - * @param [type] $field_id [description] |
|
| 145 | - * @param [type] $context [description] |
|
| 146 | - * @param [type] $input_type [description] |
|
| 147 | - * @return [type] [description] |
|
| 148 | - */ |
|
| 149 | - function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 150 | - |
|
| 151 | - // We only want to modify the settings for the edit context |
|
| 152 | - if( 'edit' !== $context ) { |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @since 1.8.4 |
|
| 156 | - */ |
|
| 157 | - $field_options['new_window'] = array( |
|
| 158 | - 'type' => 'checkbox', |
|
| 159 | - 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
| 160 | - 'value' => false, |
|
| 161 | - ); |
|
| 162 | - |
|
| 163 | - return $field_options; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // Entry field is only for logged in users |
|
| 167 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 168 | - |
|
| 169 | - $add_options = array( |
|
| 170 | - 'allow_edit_cap' => array( |
|
| 171 | - 'type' => 'select', |
|
| 172 | - 'label' => __( 'Make field editable to:', 'gravityview' ), |
|
| 173 | - 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
| 174 | - 'tooltip' => 'allow_edit_cap', |
|
| 175 | - 'class' => 'widefat', |
|
| 176 | - 'value' => 'read', // Default: entry creator |
|
| 177 | - ), |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - return array_merge( $field_options, $add_options ); |
|
| 181 | - } |
|
| 40 | + // add tooltips |
|
| 41 | + add_filter( 'gravityview_tooltips', array( $this, 'tooltips') ); |
|
| 42 | + |
|
| 43 | + // custom fields' options for zone EDIT |
|
| 44 | + add_filter( 'gravityview_template_field_options', array( $this, 'field_options' ), 10, 5 ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Add Edit Link as a default field, outside those set in the Gravity Form form |
|
| 49 | + * @param array $entry_default_fields Existing fields |
|
| 50 | + * @param string|array $form form_ID or form object |
|
| 51 | + * @param string $zone Either 'single', 'directory', 'header', 'footer' |
|
| 52 | + */ |
|
| 53 | + function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
|
| 54 | + |
|
| 55 | + if( $zone !== 'edit' ) { |
|
| 56 | + |
|
| 57 | + $entry_default_fields['edit_link'] = array( |
|
| 58 | + 'label' => __('Edit Entry', 'gravityview'), |
|
| 59 | + 'type' => 'edit_link', |
|
| 60 | + 'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
| 61 | + ); |
|
| 62 | + |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return $entry_default_fields; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Change wording for the Edit context to read Entry Creator |
|
| 70 | + * |
|
| 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 | + * @param string $template_id Table slug |
|
| 74 | + * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by` |
|
| 75 | + * @param string $context What context are we in? Example: `single` or `directory` |
|
| 76 | + * @param string $input_type (textarea, list, select, etc.) |
|
| 77 | + * @return array Array of field options with `label`, `value`, `type`, `default` keys |
|
| 78 | + */ |
|
| 79 | + function modify_visibility_caps( $visibility_caps = array(), $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
|
| 80 | + |
|
| 81 | + $caps = $visibility_caps; |
|
| 82 | + |
|
| 83 | + // If we're configuring fields in the edit context, we want a limited selection |
|
| 84 | + if( $context === 'edit' ) { |
|
| 85 | + |
|
| 86 | + // Remove other built-in caps. |
|
| 87 | + unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
| 88 | + |
|
| 89 | + $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + return $caps; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Add "Edit Link Text" setting to the edit_link field settings |
|
| 97 | + * @param [type] $field_options [description] |
|
| 98 | + * @param [type] $template_id [description] |
|
| 99 | + * @param [type] $field_id [description] |
|
| 100 | + * @param [type] $context [description] |
|
| 101 | + * @param [type] $input_type [description] |
|
| 102 | + * @return [type] [description] |
|
| 103 | + */ |
|
| 104 | + function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 105 | + |
|
| 106 | + // Always a link, never a filter |
|
| 107 | + unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
| 108 | + |
|
| 109 | + // Edit Entry link should only appear to visitors capable of editing entries |
|
| 110 | + unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 111 | + |
|
| 112 | + $add_option['edit_link'] = array( |
|
| 113 | + 'type' => 'text', |
|
| 114 | + 'label' => __( 'Edit Link Text', 'gravityview' ), |
|
| 115 | + 'desc' => NULL, |
|
| 116 | + 'value' => __('Edit Entry', 'gravityview'), |
|
| 117 | + 'merge_tags' => true, |
|
| 118 | + ); |
|
| 119 | + |
|
| 120 | + return array_merge( $add_option, $field_options ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Add tooltips |
|
| 125 | + * @param array $tooltips Existing tooltips |
|
| 126 | + * @return array Modified tooltips |
|
| 127 | + */ |
|
| 128 | + function tooltips( $tooltips ) { |
|
| 129 | + |
|
| 130 | + $return = $tooltips; |
|
| 131 | + |
|
| 132 | + $return['allow_edit_cap'] = array( |
|
| 133 | + 'title' => __('Limiting Edit Access', 'gravityview'), |
|
| 134 | + 'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
| 135 | + ); |
|
| 136 | + |
|
| 137 | + return $return; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Manipulate the fields' options for the EDIT ENTRY screen |
|
| 142 | + * @param [type] $field_options [description] |
|
| 143 | + * @param [type] $template_id [description] |
|
| 144 | + * @param [type] $field_id [description] |
|
| 145 | + * @param [type] $context [description] |
|
| 146 | + * @param [type] $input_type [description] |
|
| 147 | + * @return [type] [description] |
|
| 148 | + */ |
|
| 149 | + function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
| 150 | + |
|
| 151 | + // We only want to modify the settings for the edit context |
|
| 152 | + if( 'edit' !== $context ) { |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @since 1.8.4 |
|
| 156 | + */ |
|
| 157 | + $field_options['new_window'] = array( |
|
| 158 | + 'type' => 'checkbox', |
|
| 159 | + 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
|
| 160 | + 'value' => false, |
|
| 161 | + ); |
|
| 162 | + |
|
| 163 | + return $field_options; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // Entry field is only for logged in users |
|
| 167 | + unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 168 | + |
|
| 169 | + $add_options = array( |
|
| 170 | + 'allow_edit_cap' => array( |
|
| 171 | + 'type' => 'select', |
|
| 172 | + 'label' => __( 'Make field editable to:', 'gravityview' ), |
|
| 173 | + 'choices' => GravityView_Render_Settings::get_cap_choices( $template_id, $field_id, $context, $input_type ), |
|
| 174 | + 'tooltip' => 'allow_edit_cap', |
|
| 175 | + 'class' => 'widefat', |
|
| 176 | + 'value' => 'read', // Default: entry creator |
|
| 177 | + ), |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + return array_merge( $field_options, $add_options ); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | 183 | |
| 184 | 184 | } // end class |
| 185 | 185 | \ No newline at end of file |
@@ -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_tooltips', array( $this, 'tooltips') ); |
|
| 41 | + add_filter( 'gravityview_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, 5 ); |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | function add_default_field( $entry_default_fields, $form = array(), $zone = '' ) { |
| 54 | 54 | |
| 55 | - if( $zone !== 'edit' ) { |
|
| 55 | + if ( $zone !== 'edit' ) { |
|
| 56 | 56 | |
| 57 | - $entry_default_fields['edit_link'] = array( |
|
| 58 | - 'label' => __('Edit Entry', 'gravityview'), |
|
| 57 | + $entry_default_fields[ 'edit_link' ] = array( |
|
| 58 | + 'label' => __( 'Edit Entry', 'gravityview' ), |
|
| 59 | 59 | 'type' => 'edit_link', |
| 60 | - 'desc' => __('A link to edit the entry. Visible based on View settings.', 'gravityview'), |
|
| 60 | + 'desc' => __( 'A link to edit the entry. Visible based on View settings.', 'gravityview' ), |
|
| 61 | 61 | ); |
| 62 | 62 | |
| 63 | 63 | } |
@@ -81,12 +81,12 @@ discard block |
||
| 81 | 81 | $caps = $visibility_caps; |
| 82 | 82 | |
| 83 | 83 | // If we're configuring fields in the edit context, we want a limited selection |
| 84 | - if( $context === 'edit' ) { |
|
| 84 | + if ( $context === 'edit' ) { |
|
| 85 | 85 | |
| 86 | 86 | // Remove other built-in caps. |
| 87 | - unset( $caps['publish_posts'], $caps['gravityforms_view_entries'], $caps['delete_others_posts'] ); |
|
| 87 | + unset( $caps[ 'publish_posts' ], $caps[ 'gravityforms_view_entries' ], $caps[ 'delete_others_posts' ] ); |
|
| 88 | 88 | |
| 89 | - $caps['read'] = _x('Entry Creator','User capability', 'gravityview'); |
|
| 89 | + $caps[ 'read' ] = _x( 'Entry Creator', 'User capability', 'gravityview' ); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | return $caps; |
@@ -104,16 +104,16 @@ discard block |
||
| 104 | 104 | function edit_link_field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
| 105 | 105 | |
| 106 | 106 | // Always a link, never a filter |
| 107 | - unset( $field_options['show_as_link'], $field_options['search_filter'] ); |
|
| 107 | + unset( $field_options[ 'show_as_link' ], $field_options[ 'search_filter' ] ); |
|
| 108 | 108 | |
| 109 | 109 | // Edit Entry link should only appear to visitors capable of editing entries |
| 110 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 110 | + unset( $field_options[ 'only_loggedin' ], $field_options[ 'only_loggedin_cap' ] ); |
|
| 111 | 111 | |
| 112 | - $add_option['edit_link'] = array( |
|
| 112 | + $add_option[ 'edit_link' ] = array( |
|
| 113 | 113 | 'type' => 'text', |
| 114 | 114 | 'label' => __( 'Edit Link Text', 'gravityview' ), |
| 115 | 115 | 'desc' => NULL, |
| 116 | - 'value' => __('Edit Entry', 'gravityview'), |
|
| 116 | + 'value' => __( 'Edit Entry', 'gravityview' ), |
|
| 117 | 117 | 'merge_tags' => true, |
| 118 | 118 | ); |
| 119 | 119 | |
@@ -129,9 +129,9 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | $return = $tooltips; |
| 131 | 131 | |
| 132 | - $return['allow_edit_cap'] = array( |
|
| 133 | - 'title' => __('Limiting Edit Access', 'gravityview'), |
|
| 134 | - 'value' => __('Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview'), |
|
| 132 | + $return[ 'allow_edit_cap' ] = array( |
|
| 133 | + 'title' => __( 'Limiting Edit Access', 'gravityview' ), |
|
| 134 | + 'value' => __( 'Change this setting if you don\'t want the user who created the entry to be able to edit this field.', 'gravityview' ), |
|
| 135 | 135 | ); |
| 136 | 136 | |
| 137 | 137 | return $return; |
@@ -149,12 +149,12 @@ discard block |
||
| 149 | 149 | function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
| 150 | 150 | |
| 151 | 151 | // We only want to modify the settings for the edit context |
| 152 | - if( 'edit' !== $context ) { |
|
| 152 | + if ( 'edit' !== $context ) { |
|
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | 155 | * @since 1.8.4 |
| 156 | 156 | */ |
| 157 | - $field_options['new_window'] = array( |
|
| 157 | + $field_options[ 'new_window' ] = array( |
|
| 158 | 158 | 'type' => 'checkbox', |
| 159 | 159 | 'label' => __( 'Open link in a new tab or window?', 'gravityview' ), |
| 160 | 160 | 'value' => false, |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // Entry field is only for logged in users |
| 167 | - unset( $field_options['only_loggedin'], $field_options['only_loggedin_cap'] ); |
|
| 167 | + unset( $field_options[ 'only_loggedin' ], $field_options[ 'only_loggedin_cap' ] ); |
|
| 168 | 168 | |
| 169 | 169 | $add_options = array( |
| 170 | 170 | 'allow_edit_cap' => array( |
@@ -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 ) { |
@@ -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,102 +22,102 @@ discard block |
||
| 22 | 22 | /** |
| 23 | 23 | * @var GravityView_Edit_Entry |
| 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 | - do_action( 'gravityview_log_error', __METHOD__ . ': GFAPI or User Registration class not found; not updating the user' ); |
|
| 77 | - return; |
|
| 78 | - } elseif( empty( $entry_id ) ) { |
|
| 79 | - do_action( 'gravityview_log_error', __METHOD__ . ': Entry ID is empty; not updating the user', $entry_id ); |
|
| 80 | - return; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** @var GF_User_Registration $gf_user_registration */ |
|
| 84 | - $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 85 | - |
|
| 86 | - $entry = GFAPI::get_entry( $entry_id ); |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
| 90 | - * @since 1.11 |
|
| 91 | - * @param array $entry Gravity Forms entry |
|
| 92 | - * @param array $form Gravity Forms form |
|
| 93 | - */ |
|
| 94 | - $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
| 95 | - |
|
| 96 | - $config = $this->get_feed_configuration( $entry, $form ); |
|
| 97 | - |
|
| 98 | - // Make sure the feed is active |
|
| 99 | - if ( ! rgar( $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 | + do_action( 'gravityview_log_error', __METHOD__ . ': GFAPI or User Registration class not found; not updating the user' ); |
|
| 100 | 77 | return; |
| 101 | - } |
|
| 78 | + } elseif( empty( $entry_id ) ) { |
|
| 79 | + do_action( 'gravityview_log_error', __METHOD__ . ': Entry ID is empty; not updating the user', $entry_id ); |
|
| 80 | + return; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** @var GF_User_Registration $gf_user_registration */ |
|
| 84 | + $gf_user_registration = GF_User_Registration::get_instance(); |
|
| 85 | + |
|
| 86 | + $entry = GFAPI::get_entry( $entry_id ); |
|
| 102 | 87 | |
| 103 | - // If an Update feed, make sure the conditions are met. |
|
| 104 | - if( rgars( $config, 'meta/feedType' ) === 'update' ) { |
|
| 105 | - if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 106 | - return; |
|
| 107 | - } |
|
| 108 | - } |
|
| 88 | + /** |
|
| 89 | + * @filter `gravityview/edit_entry/user_registration/entry` Modify entry details before updating the user via User Registration add-on |
|
| 90 | + * @since 1.11 |
|
| 91 | + * @param array $entry Gravity Forms entry |
|
| 92 | + * @param array $form Gravity Forms form |
|
| 93 | + */ |
|
| 94 | + $entry = apply_filters( 'gravityview/edit_entry/user_registration/entry', $entry, $form ); |
|
| 95 | + |
|
| 96 | + $config = $this->get_feed_configuration( $entry, $form ); |
|
| 97 | + |
|
| 98 | + // Make sure the feed is active |
|
| 99 | + if ( ! rgar( $config, 'is_active', false ) ) { |
|
| 100 | + return; |
|
| 101 | + } |
|
| 109 | 102 | |
| 110 | - // The priority is set to 3 so that default priority (10) will still override it |
|
| 111 | - add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 112 | - add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 103 | + // If an Update feed, make sure the conditions are met. |
|
| 104 | + if( rgars( $config, 'meta/feedType' ) === 'update' ) { |
|
| 105 | + if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 108 | + } |
|
| 113 | 109 | |
| 114 | - // Trigger the User Registration update user method |
|
| 115 | - $gf_user_registration->update_user( $entry, $form, $config ); |
|
| 110 | + // The priority is set to 3 so that default priority (10) will still override it |
|
| 111 | + add_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 112 | + add_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 116 | 113 | |
| 117 | - remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 118 | - remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 114 | + // Trigger the User Registration update user method |
|
| 115 | + $gf_user_registration->update_user( $entry, $form, $config ); |
|
| 119 | 116 | |
| 120 | - } |
|
| 117 | + remove_filter( 'send_password_change_email', '__return_false', 3 ); |
|
| 118 | + remove_filter( 'send_email_change_email', '__return_false', 3 ); |
|
| 119 | + |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | 123 | * Get the User Registration feed configuration for the entry & form |
@@ -132,185 +132,185 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @return array |
| 134 | 134 | */ |
| 135 | - public function get_feed_configuration( $entry, $form ) { |
|
| 136 | - |
|
| 137 | - /** @var GF_User_Registration $gf_user_registration */ |
|
| 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 && rgars( $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 | - do_action('gravityview_log_error', __METHOD__ . sprintf( ' - User not found at $user_id #%d', $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 | - do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
| 305 | - } else { |
|
| 306 | - do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $this->_user_before_update = null; |
|
| 310 | - |
|
| 311 | - unset( $restored_user, $user_after_update ); |
|
| 312 | - |
|
| 313 | - return $updated; |
|
| 314 | - } |
|
| 135 | + public function get_feed_configuration( $entry, $form ) { |
|
| 136 | + |
|
| 137 | + /** @var GF_User_Registration $gf_user_registration */ |
|
| 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 && rgars( $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 | + do_action('gravityview_log_error', __METHOD__ . sprintf( ' - User not found at $user_id #%d', $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 | + do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
| 305 | + } else { |
|
| 306 | + do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $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 |
@@ -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 | do_action( 'gravityview_log_error', __METHOD__ . ': 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 | do_action( 'gravityview_log_error', __METHOD__ . ': Entry ID is empty; not updating the user', $entry_id ); |
| 80 | 80 | return; |
| 81 | 81 | } |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | // If an Update feed, make sure the conditions are met. |
| 104 | - if( rgars( $config, 'meta/feedType' ) === 'update' ) { |
|
| 105 | - if( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 104 | + if ( rgars( $config, 'meta/feedType' ) === 'update' ) { |
|
| 105 | + if ( ! $gf_user_registration->is_feed_condition_met( $config, $form, $entry ) ) { |
|
| 106 | 106 | return; |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -149,17 +149,17 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | $preserve_role = apply_filters( 'gravityview/edit_entry/user_registration/preserve_role', true, $config, $form, $entry ); |
| 151 | 151 | |
| 152 | - if( $preserve_role ) { |
|
| 153 | - $config['meta']['role'] = 'gfur_preserve_role'; |
|
| 152 | + if ( $preserve_role ) { |
|
| 153 | + $config[ 'meta' ][ 'role' ] = 'gfur_preserve_role'; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - $displayname = $this->match_current_display_name( $entry['created_by'] ); |
|
| 156 | + $displayname = $this->match_current_display_name( $entry[ 'created_by' ] ); |
|
| 157 | 157 | |
| 158 | 158 | /** |
| 159 | 159 | * Make sure the current display name is not changed with the update user method. |
| 160 | 160 | * @since 1.15 |
| 161 | 161 | */ |
| 162 | - $config['meta']['displayname'] = $displayname ? $displayname : $config['meta']['displayname']; |
|
| 162 | + $config[ 'meta' ][ 'displayname' ] = $displayname ? $displayname : $config[ 'meta' ][ 'displayname' ]; |
|
| 163 | 163 | |
| 164 | 164 | /** |
| 165 | 165 | * @filter `gravityview/edit_entry/user_registration/config` Modify the User Registration Addon feed configuration |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | $user = get_userdata( $user_id ); |
| 188 | 188 | |
| 189 | - if( ! $user ) { |
|
| 189 | + if ( ! $user ) { |
|
| 190 | 190 | return false; |
| 191 | 191 | } |
| 192 | 192 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * In case we can't find the current display name format, trigger last resort method at the 'gform_user_updated' hook |
| 199 | 199 | * @see restore_display_name |
| 200 | 200 | */ |
| 201 | - if( false === $format ) { |
|
| 201 | + if ( false === $format ) { |
|
| 202 | 202 | $this->_user_before_update = $user; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -216,20 +216,20 @@ discard block |
||
| 216 | 216 | public function generate_display_names( $profileuser ) { |
| 217 | 217 | |
| 218 | 218 | $public_display = array(); |
| 219 | - $public_display['nickname'] = $profileuser->nickname; |
|
| 220 | - $public_display['username'] = $profileuser->user_login; |
|
| 219 | + $public_display[ 'nickname' ] = $profileuser->nickname; |
|
| 220 | + $public_display[ 'username' ] = $profileuser->user_login; |
|
| 221 | 221 | |
| 222 | - if ( !empty($profileuser->first_name) ) { |
|
| 223 | - $public_display['firstname'] = $profileuser->first_name; |
|
| 222 | + if ( ! empty( $profileuser->first_name ) ) { |
|
| 223 | + $public_display[ 'firstname' ] = $profileuser->first_name; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - if ( !empty($profileuser->last_name) ) { |
|
| 227 | - $public_display['lastname'] = $profileuser->last_name; |
|
| 226 | + if ( ! empty( $profileuser->last_name ) ) { |
|
| 227 | + $public_display[ 'lastname' ] = $profileuser->last_name; |
|
| 228 | 228 | } |
| 229 | 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; |
|
| 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 | 233 | } |
| 234 | 234 | |
| 235 | 235 | $public_display = array_map( 'trim', $public_display ); |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | $restore_display_name = apply_filters( 'gravityview/edit_entry/restore_display_name', true ); |
| 261 | 261 | |
| 262 | - $is_update_feed = ( $config && rgars( $config, 'meta/feed_type') === 'update' ); |
|
| 262 | + $is_update_feed = ( $config && rgars( $config, 'meta/feed_type' ) === 'update' ); |
|
| 263 | 263 | |
| 264 | 264 | /** |
| 265 | 265 | * Don't restore display name: |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * - or we don't need as we found the correct format before updating user. |
| 269 | 269 | * @since 1.14.4 |
| 270 | 270 | */ |
| 271 | - if( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 271 | + if ( ! $restore_display_name || $is_update_feed || is_null( $this->_user_before_update ) ) { |
|
| 272 | 272 | return null; |
| 273 | 273 | } |
| 274 | 274 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | // User not found |
| 278 | 278 | if ( ! $user_after_update ) { |
| 279 | - do_action('gravityview_log_error', __METHOD__ . sprintf( ' - User not found at $user_id #%d', $user_id ) ); |
|
| 279 | + do_action( 'gravityview_log_error', __METHOD__ . sprintf( ' - User not found at $user_id #%d', $user_id ) ); |
|
| 280 | 280 | return false; |
| 281 | 281 | } |
| 282 | 282 | |
@@ -300,10 +300,10 @@ discard block |
||
| 300 | 300 | |
| 301 | 301 | $updated = wp_update_user( $restored_user ); |
| 302 | 302 | |
| 303 | - if( is_wp_error( $updated ) ) { |
|
| 304 | - do_action('gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
| 303 | + if ( is_wp_error( $updated ) ) { |
|
| 304 | + do_action( 'gravityview_log_error', __METHOD__ . sprintf( ' - There was an error updating user #%d details', $user_id ), $updated ); |
|
| 305 | 305 | } else { |
| 306 | - do_action('gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); |
|
| 306 | + do_action( 'gravityview_log_debug', __METHOD__ . sprintf( ' - User #%d details restored', $user_id ) ); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | $this->_user_before_update = null; |
@@ -65,6 +65,9 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | |
| 68 | + /** |
|
| 69 | + * @param string $component |
|
| 70 | + */ |
|
| 68 | 71 | private function load_components( $component ) { |
| 69 | 72 | |
| 70 | 73 | $dir = trailingslashit( self::$file ); |
@@ -141,7 +144,7 @@ discard block |
||
| 141 | 144 | * "You can edit this post from the post page" fields, for example. |
| 142 | 145 | * |
| 143 | 146 | * @param $entry array Gravity Forms entry object |
| 144 | - * @param $view_id int GravityView view id |
|
| 147 | + * @param integer $view_id int GravityView view id |
|
| 145 | 148 | * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2} |
| 146 | 149 | * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } |
| 147 | 150 | * @return string |
@@ -18,80 +18,80 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | class GravityView_Edit_Entry { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | 24 | static $file; |
| 25 | 25 | |
| 26 | 26 | static $instance; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Component instances. |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - public $instances = array(); |
|
| 28 | + /** |
|
| 29 | + * Component instances. |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + public $instances = array(); |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | function __construct() { |
| 36 | 36 | |
| 37 | - self::$file = plugin_dir_path( __FILE__ ); |
|
| 37 | + self::$file = plugin_dir_path( __FILE__ ); |
|
| 38 | 38 | |
| 39 | - if( is_admin() ) { |
|
| 40 | - $this->load_components( 'admin' ); |
|
| 41 | - } |
|
| 39 | + if( is_admin() ) { |
|
| 40 | + $this->load_components( 'admin' ); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - $this->load_components( 'render' ); |
|
| 44 | + $this->load_components( 'render' ); |
|
| 45 | 45 | |
| 46 | - // If GF User Registration Add-on exists |
|
| 47 | - $this->load_components( 'user-registration' ); |
|
| 46 | + // If GF User Registration Add-on exists |
|
| 47 | + $this->load_components( 'user-registration' ); |
|
| 48 | 48 | |
| 49 | - $this->add_hooks(); |
|
| 49 | + $this->add_hooks(); |
|
| 50 | 50 | |
| 51 | 51 | // Process hooks for addons that may or may not be present |
| 52 | 52 | $this->addon_specific_hooks(); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | |
| 56 | - static function getInstance() { |
|
| 56 | + static function getInstance() { |
|
| 57 | 57 | |
| 58 | - if( empty( self::$instance ) ) { |
|
| 59 | - self::$instance = new GravityView_Edit_Entry; |
|
| 60 | - } |
|
| 58 | + if( empty( self::$instance ) ) { |
|
| 59 | + self::$instance = new GravityView_Edit_Entry; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return self::$instance; |
|
| 63 | - } |
|
| 62 | + return self::$instance; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - private function load_components( $component ) { |
|
| 66 | + private function load_components( $component ) { |
|
| 67 | 67 | |
| 68 | - $dir = trailingslashit( self::$file ); |
|
| 68 | + $dir = trailingslashit( self::$file ); |
|
| 69 | 69 | |
| 70 | - $filename = $dir . 'class-edit-entry-' . $component . '.php'; |
|
| 71 | - $classname = 'GravityView_Edit_Entry_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $component ) ) ); |
|
| 70 | + $filename = $dir . 'class-edit-entry-' . $component . '.php'; |
|
| 71 | + $classname = 'GravityView_Edit_Entry_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $component ) ) ); |
|
| 72 | 72 | |
| 73 | - // Loads component and pass extension's instance so that component can |
|
| 74 | - // talk each other. |
|
| 75 | - require_once $filename; |
|
| 76 | - $this->instances[ $component ] = new $classname( $this ); |
|
| 77 | - $this->instances[ $component ]->load(); |
|
| 73 | + // Loads component and pass extension's instance so that component can |
|
| 74 | + // talk each other. |
|
| 75 | + require_once $filename; |
|
| 76 | + $this->instances[ $component ] = new $classname( $this ); |
|
| 77 | + $this->instances[ $component ]->load(); |
|
| 78 | 78 | |
| 79 | - } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - private function add_hooks() { |
|
| 81 | + private function add_hooks() { |
|
| 82 | 82 | |
| 83 | - // Add front-end access to Gravity Forms delete file action |
|
| 84 | - add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 83 | + // Add front-end access to Gravity Forms delete file action |
|
| 84 | + add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 85 | 85 | |
| 86 | - // Make sure this hook is run for non-admins |
|
| 87 | - add_action( 'wp_ajax_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 86 | + // Make sure this hook is run for non-admins |
|
| 87 | + add_action( 'wp_ajax_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 88 | 88 | |
| 89 | - add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 ); |
|
| 89 | + add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 ); |
|
| 90 | 90 | |
| 91 | - // add template path to check for field |
|
| 92 | - add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
|
| 91 | + // add template path to check for field |
|
| 92 | + add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
|
| 93 | 93 | |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | 97 | * Trigger hooks that are normally run in the admin for Addons, but need to be triggered manually because we're not in the admin |
@@ -105,73 +105,73 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Include this extension templates path |
|
| 110 | - * @param array $file_paths List of template paths ordered |
|
| 111 | - */ |
|
| 112 | - public function add_template_path( $file_paths ) { |
|
| 113 | - |
|
| 114 | - // Index 100 is the default GravityView template path. |
|
| 115 | - $file_paths[ 110 ] = self::$file; |
|
| 116 | - |
|
| 117 | - return $file_paths; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * |
|
| 122 | - * Return a well formatted nonce key according to GravityView Edit Entry protocol |
|
| 123 | - * |
|
| 124 | - * @param $view_id int GravityView view id |
|
| 125 | - * @param $form_id int Gravity Forms form id |
|
| 126 | - * @param $entry_id int Gravity Forms entry id |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - public static function get_nonce_key( $view_id, $form_id, $entry_id ) { |
|
| 130 | - return sprintf( 'edit_%d_%d_%d', $view_id, $form_id, $entry_id ); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * The edit entry link creates a secure link with a nonce |
|
| 136 | - * |
|
| 137 | - * It also mimics the URL structure Gravity Forms expects to have so that |
|
| 138 | - * it formats the display of the edit form like it does in the backend, like |
|
| 139 | - * "You can edit this post from the post page" fields, for example. |
|
| 140 | - * |
|
| 141 | - * @param $entry array Gravity Forms entry object |
|
| 142 | - * @param $view_id int GravityView view id |
|
| 143 | - * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2} |
|
| 144 | - * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } |
|
| 145 | - * @return string |
|
| 146 | - */ |
|
| 147 | - public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { |
|
| 148 | - |
|
| 149 | - $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id'] ); |
|
| 150 | - |
|
| 151 | - $base = gv_entry_link( $entry, $post_id ); |
|
| 152 | - |
|
| 153 | - $url = add_query_arg( array( |
|
| 154 | - 'edit' => wp_create_nonce( $nonce_key ) |
|
| 155 | - ), $base ); |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Allow passing params to dynamically populate entry with values |
|
| 159 | - * @since 1.9.2 |
|
| 160 | - */ |
|
| 161 | - if( !empty( $field_values ) ) { |
|
| 162 | - |
|
| 163 | - if( is_array( $field_values ) ) { |
|
| 164 | - // If already an array, no parse_str() needed |
|
| 165 | - $params = $field_values; |
|
| 166 | - } else { |
|
| 167 | - parse_str( $field_values, $params ); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $url = add_query_arg( $params, $url ); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return $url; |
|
| 174 | - } |
|
| 108 | + /** |
|
| 109 | + * Include this extension templates path |
|
| 110 | + * @param array $file_paths List of template paths ordered |
|
| 111 | + */ |
|
| 112 | + public function add_template_path( $file_paths ) { |
|
| 113 | + |
|
| 114 | + // Index 100 is the default GravityView template path. |
|
| 115 | + $file_paths[ 110 ] = self::$file; |
|
| 116 | + |
|
| 117 | + return $file_paths; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * |
|
| 122 | + * Return a well formatted nonce key according to GravityView Edit Entry protocol |
|
| 123 | + * |
|
| 124 | + * @param $view_id int GravityView view id |
|
| 125 | + * @param $form_id int Gravity Forms form id |
|
| 126 | + * @param $entry_id int Gravity Forms entry id |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + public static function get_nonce_key( $view_id, $form_id, $entry_id ) { |
|
| 130 | + return sprintf( 'edit_%d_%d_%d', $view_id, $form_id, $entry_id ); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * The edit entry link creates a secure link with a nonce |
|
| 136 | + * |
|
| 137 | + * It also mimics the URL structure Gravity Forms expects to have so that |
|
| 138 | + * it formats the display of the edit form like it does in the backend, like |
|
| 139 | + * "You can edit this post from the post page" fields, for example. |
|
| 140 | + * |
|
| 141 | + * @param $entry array Gravity Forms entry object |
|
| 142 | + * @param $view_id int GravityView view id |
|
| 143 | + * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2} |
|
| 144 | + * @param string|array $field_values Parameters to pass in to the Edit Entry form to prefill data. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@since 1.9.2} {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } |
|
| 145 | + * @return string |
|
| 146 | + */ |
|
| 147 | + public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { |
|
| 148 | + |
|
| 149 | + $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id'] ); |
|
| 150 | + |
|
| 151 | + $base = gv_entry_link( $entry, $post_id ); |
|
| 152 | + |
|
| 153 | + $url = add_query_arg( array( |
|
| 154 | + 'edit' => wp_create_nonce( $nonce_key ) |
|
| 155 | + ), $base ); |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Allow passing params to dynamically populate entry with values |
|
| 159 | + * @since 1.9.2 |
|
| 160 | + */ |
|
| 161 | + if( !empty( $field_values ) ) { |
|
| 162 | + |
|
| 163 | + if( is_array( $field_values ) ) { |
|
| 164 | + // If already an array, no parse_str() needed |
|
| 165 | + $params = $field_values; |
|
| 166 | + } else { |
|
| 167 | + parse_str( $field_values, $params ); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $url = add_query_arg( $params, $url ); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return $url; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | /** |
| 177 | 177 | * Edit mode doesn't allow certain field types. |
@@ -225,81 +225,81 @@ discard block |
||
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * checks if user has permissions to edit a specific entry |
|
| 230 | - * |
|
| 231 | - * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! |
|
| 232 | - * |
|
| 233 | - * @param array $entry Gravity Forms entry array |
|
| 234 | - * @param int $view_id ID of the view you want to check visibility against {@since 1.9.2} |
|
| 235 | - * @return bool |
|
| 236 | - */ |
|
| 237 | - public static function check_user_cap_edit_entry( $entry, $view_id = 0 ) { |
|
| 228 | + /** |
|
| 229 | + * checks if user has permissions to edit a specific entry |
|
| 230 | + * |
|
| 231 | + * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! |
|
| 232 | + * |
|
| 233 | + * @param array $entry Gravity Forms entry array |
|
| 234 | + * @param int $view_id ID of the view you want to check visibility against {@since 1.9.2} |
|
| 235 | + * @return bool |
|
| 236 | + */ |
|
| 237 | + public static function check_user_cap_edit_entry( $entry, $view_id = 0 ) { |
|
| 238 | 238 | |
| 239 | - // No permission by default |
|
| 240 | - $user_can_edit = false; |
|
| 239 | + // No permission by default |
|
| 240 | + $user_can_edit = false; |
|
| 241 | 241 | |
| 242 | - // If they can edit any entries (as defined in Gravity Forms) |
|
| 243 | - // Or if they can edit other people's entries |
|
| 244 | - // Then we're good. |
|
| 245 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { |
|
| 242 | + // If they can edit any entries (as defined in Gravity Forms) |
|
| 243 | + // Or if they can edit other people's entries |
|
| 244 | + // Then we're good. |
|
| 245 | + if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { |
|
| 246 | 246 | |
| 247 | - do_action('gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.'); |
|
| 247 | + do_action('gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.'); |
|
| 248 | 248 | |
| 249 | - $user_can_edit = true; |
|
| 249 | + $user_can_edit = true; |
|
| 250 | 250 | |
| 251 | - } else if( !isset( $entry['created_by'] ) ) { |
|
| 251 | + } else if( !isset( $entry['created_by'] ) ) { |
|
| 252 | 252 | |
| 253 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.'); |
|
| 253 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.'); |
|
| 254 | 254 | |
| 255 | - $user_can_edit = false; |
|
| 255 | + $user_can_edit = false; |
|
| 256 | 256 | |
| 257 | - } else { |
|
| 257 | + } else { |
|
| 258 | 258 | |
| 259 | - // get user_edit setting |
|
| 260 | - if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) { |
|
| 261 | - // if View ID not specified or is the current view |
|
| 262 | - $user_edit = GravityView_View::getInstance()->getAtts('user_edit'); |
|
| 263 | - } else { |
|
| 264 | - // in case is specified and not the current view |
|
| 265 | - $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' ); |
|
| 266 | - } |
|
| 259 | + // get user_edit setting |
|
| 260 | + if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) { |
|
| 261 | + // if View ID not specified or is the current view |
|
| 262 | + $user_edit = GravityView_View::getInstance()->getAtts('user_edit'); |
|
| 263 | + } else { |
|
| 264 | + // in case is specified and not the current view |
|
| 265 | + $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' ); |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - $current_user = wp_get_current_user(); |
|
| 268 | + $current_user = wp_get_current_user(); |
|
| 269 | 269 | |
| 270 | - // User edit is disabled |
|
| 271 | - if( empty( $user_edit ) ) { |
|
| 270 | + // User edit is disabled |
|
| 271 | + if( empty( $user_edit ) ) { |
|
| 272 | 272 | |
| 273 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' ); |
|
| 273 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' ); |
|
| 274 | 274 | |
| 275 | - $user_can_edit = false; |
|
| 276 | - } |
|
| 275 | + $user_can_edit = false; |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. |
|
| 279 | - else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
| 278 | + // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. |
|
| 279 | + else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
| 280 | 280 | |
| 281 | - do_action('gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) ); |
|
| 281 | + do_action('gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) ); |
|
| 282 | 282 | |
| 283 | - $user_can_edit = true; |
|
| 283 | + $user_can_edit = true; |
|
| 284 | 284 | |
| 285 | - } else if( ! is_user_logged_in() ) { |
|
| 285 | + } else if( ! is_user_logged_in() ) { |
|
| 286 | 286 | |
| 287 | - do_action( 'gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user' ); |
|
| 288 | - } |
|
| 287 | + do_action( 'gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user' ); |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - } |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - /** |
|
| 293 | - * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. |
|
| 294 | - * @since 1.15 Added `$entry` and `$view_id` parameters |
|
| 295 | - * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false) |
|
| 296 | - * @param[in] array $entry Gravity Forms entry array {@since 1.15} |
|
| 297 | - * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15} |
|
| 298 | - */ |
|
| 299 | - $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id ); |
|
| 292 | + /** |
|
| 293 | + * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. |
|
| 294 | + * @since 1.15 Added `$entry` and `$view_id` parameters |
|
| 295 | + * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false) |
|
| 296 | + * @param[in] array $entry Gravity Forms entry array {@since 1.15} |
|
| 297 | + * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15} |
|
| 298 | + */ |
|
| 299 | + $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id ); |
|
| 300 | 300 | |
| 301 | - return (bool)$user_can_edit; |
|
| 302 | - } |
|
| 301 | + return (bool)$user_can_edit; |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | 304 | |
| 305 | 305 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | self::$file = plugin_dir_path( __FILE__ ); |
| 38 | 38 | |
| 39 | - if( is_admin() ) { |
|
| 39 | + if ( is_admin() ) { |
|
| 40 | 40 | $this->load_components( 'admin' ); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | static function getInstance() { |
| 57 | 57 | |
| 58 | - if( empty( self::$instance ) ) { |
|
| 58 | + if ( empty( self::$instance ) ) { |
|
| 59 | 59 | self::$instance = new GravityView_Edit_Entry; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | private function add_hooks() { |
| 82 | 82 | |
| 83 | 83 | // Add front-end access to Gravity Forms delete file action |
| 84 | - add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 84 | + add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'GFForms', 'delete_file' ) ); |
|
| 85 | 85 | |
| 86 | 86 | // Make sure this hook is run for non-admins |
| 87 | - add_action( 'wp_ajax_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 87 | + add_action( 'wp_ajax_rg_delete_file', array( 'GFForms', 'delete_file' ) ); |
|
| 88 | 88 | |
| 89 | 89 | add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 ); |
| 90 | 90 | |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | private function addon_specific_hooks() { |
| 101 | 101 | |
| 102 | - if( class_exists( 'GFSignature' ) && is_callable( array( 'GFSignature', 'get_instance' ) ) ) { |
|
| 103 | - add_filter('gform_admin_pre_render', array( GFSignature::get_instance(), 'edit_lead_script')); |
|
| 102 | + if ( class_exists( 'GFSignature' ) && is_callable( array( 'GFSignature', 'get_instance' ) ) ) { |
|
| 103 | + add_filter( 'gform_admin_pre_render', array( GFSignature::get_instance(), 'edit_lead_script' ) ); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { |
| 148 | 148 | |
| 149 | - $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id'] ); |
|
| 149 | + $nonce_key = self::get_nonce_key( $view_id, $entry[ 'form_id' ], $entry[ 'id' ] ); |
|
| 150 | 150 | |
| 151 | 151 | $base = gv_entry_link( $entry, $post_id ); |
| 152 | 152 | |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | * Allow passing params to dynamically populate entry with values |
| 159 | 159 | * @since 1.9.2 |
| 160 | 160 | */ |
| 161 | - if( !empty( $field_values ) ) { |
|
| 161 | + if ( ! empty( $field_values ) ) { |
|
| 162 | 162 | |
| 163 | - if( is_array( $field_values ) ) { |
|
| 163 | + if ( is_array( $field_values ) ) { |
|
| 164 | 164 | // If already an array, no parse_str() needed |
| 165 | 165 | $params = $field_values; |
| 166 | 166 | } else { |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | public function modify_field_blacklist( $fields = array(), $context = NULL ) { |
| 183 | 183 | |
| 184 | - if( empty( $context ) || $context !== 'edit' ) { |
|
| 184 | + if ( empty( $context ) || $context !== 'edit' ) { |
|
| 185 | 185 | return $fields; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -242,24 +242,24 @@ discard block |
||
| 242 | 242 | // If they can edit any entries (as defined in Gravity Forms) |
| 243 | 243 | // Or if they can edit other people's entries |
| 244 | 244 | // Then we're good. |
| 245 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { |
|
| 245 | + if ( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry[ 'id' ] ) ) { |
|
| 246 | 246 | |
| 247 | - do_action('gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.'); |
|
| 247 | + do_action( 'gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.' ); |
|
| 248 | 248 | |
| 249 | 249 | $user_can_edit = true; |
| 250 | 250 | |
| 251 | - } else if( !isset( $entry['created_by'] ) ) { |
|
| 251 | + } else if ( ! isset( $entry[ 'created_by' ] ) ) { |
|
| 252 | 252 | |
| 253 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.'); |
|
| 253 | + do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.' ); |
|
| 254 | 254 | |
| 255 | 255 | $user_can_edit = false; |
| 256 | 256 | |
| 257 | 257 | } else { |
| 258 | 258 | |
| 259 | 259 | // get user_edit setting |
| 260 | - if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) { |
|
| 260 | + if ( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) { |
|
| 261 | 261 | // if View ID not specified or is the current view |
| 262 | - $user_edit = GravityView_View::getInstance()->getAtts('user_edit'); |
|
| 262 | + $user_edit = GravityView_View::getInstance()->getAtts( 'user_edit' ); |
|
| 263 | 263 | } else { |
| 264 | 264 | // in case is specified and not the current view |
| 265 | 265 | $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' ); |
@@ -268,21 +268,21 @@ discard block |
||
| 268 | 268 | $current_user = wp_get_current_user(); |
| 269 | 269 | |
| 270 | 270 | // User edit is disabled |
| 271 | - if( empty( $user_edit ) ) { |
|
| 271 | + if ( empty( $user_edit ) ) { |
|
| 272 | 272 | |
| 273 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' ); |
|
| 273 | + do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' ); |
|
| 274 | 274 | |
| 275 | 275 | $user_can_edit = false; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. |
| 279 | - else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
| 279 | + else if ( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry[ 'created_by' ] ) ) { |
|
| 280 | 280 | |
| 281 | - do_action('gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) ); |
|
| 281 | + do_action( 'gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) ); |
|
| 282 | 282 | |
| 283 | 283 | $user_can_edit = true; |
| 284 | 284 | |
| 285 | - } else if( ! is_user_logged_in() ) { |
|
| 285 | + } else if ( ! is_user_logged_in() ) { |
|
| 286 | 286 | |
| 287 | 287 | do_action( 'gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user' ); |
| 288 | 288 | } |
@@ -169,7 +169,6 @@ |
||
| 169 | 169 | * |
| 170 | 170 | * @since 1.15.2 |
| 171 | 171 | * |
| 172 | - * @param array $handles Array of meta keys to check for existence of shortcodes |
|
| 173 | 172 | * @param int $post_id The ID being checked by GravityView |
| 174 | 173 | * |
| 175 | 174 | * @return array Meta key array, merged with existing meta keys |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | private function maybe_add_hooks() { |
| 92 | 92 | $class_exists = $this->class_name && class_exists( $this->class_name ); |
| 93 | 93 | $function_exists = $this->function_name && function_exists( $this->function_name ); |
| 94 | - $constant_defined = $this->constant_name && defined("{$this->constant_name}"); |
|
| 94 | + $constant_defined = $this->constant_name && defined( "{$this->constant_name}" ); |
|
| 95 | 95 | |
| 96 | - if( $class_exists || $function_exists || $constant_defined ) { |
|
| 96 | + if ( $class_exists || $function_exists || $constant_defined ) { |
|
| 97 | 97 | $this->add_hooks(); |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -104,19 +104,19 @@ discard block |
||
| 104 | 104 | * @return void |
| 105 | 105 | */ |
| 106 | 106 | protected function add_hooks() { |
| 107 | - if( $this->content_meta_keys ) { |
|
| 107 | + if ( $this->content_meta_keys ) { |
|
| 108 | 108 | add_filter( 'gravityview/data/parse/meta_keys', array( $this, 'merge_content_meta_keys' ), 10, 2 ); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if( $this->script_handles ) { |
|
| 111 | + if ( $this->script_handles ) { |
|
| 112 | 112 | add_filter( 'gravityview_noconflict_scripts', array( $this, 'merge_noconflict_scripts' ) ); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if( $this->style_handles ) { |
|
| 115 | + if ( $this->style_handles ) { |
|
| 116 | 116 | add_filter( 'gravityview_noconflict_styles', array( $this, 'merge_noconflict_styles' ) ); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if( $this->post_type_support ) { |
|
| 119 | + if ( $this->post_type_support ) { |
|
| 120 | 120 | add_filter( 'gravityview_post_type_support', array( $this, 'merge_post_type_support' ), 10, 2 ); |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -51,6 +51,9 @@ |
||
| 51 | 51 | // hold widget View options |
| 52 | 52 | private $widget_options; |
| 53 | 53 | |
| 54 | + /** |
|
| 55 | + * @param string $widget_id |
|
| 56 | + */ |
|
| 54 | 57 | function __construct( $widget_label , $widget_id , $defaults = array(), $settings = array() ) { |
| 55 | 58 | |
| 56 | 59 | |
@@ -116,12 +116,12 @@ |
||
| 116 | 116 | return $settings; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 122 | - public function get_widget_id() { |
|
| 123 | - return $this->widget_id; |
|
| 124 | - } |
|
| 119 | + /** |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | + public function get_widget_id() { |
|
| 123 | + return $this->widget_id; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | 127 | * Get the widget settings |
@@ -51,14 +51,14 @@ discard block |
||
| 51 | 51 | // hold widget View options |
| 52 | 52 | private $widget_options; |
| 53 | 53 | |
| 54 | - function __construct( $widget_label , $widget_id , $defaults = array(), $settings = array() ) { |
|
| 54 | + function __construct( $widget_label, $widget_id, $defaults = array(), $settings = array() ) { |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * The shortcode name is set to the lowercase name of the widget class, unless overridden by the class specifying a different value for $shortcode_name |
| 59 | 59 | * @var string |
| 60 | 60 | */ |
| 61 | - $this->shortcode_name = !isset( $this->shortcode_name ) ? strtolower( get_class($this) ) : $this->shortcode_name; |
|
| 61 | + $this->shortcode_name = ! isset( $this->shortcode_name ) ? strtolower( get_class( $this ) ) : $this->shortcode_name; |
|
| 62 | 62 | |
| 63 | 63 | $this->widget_label = $widget_label; |
| 64 | 64 | $this->widget_id = $widget_id; |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $this->settings = wp_parse_args( $settings, $this->settings ); |
| 70 | 70 | |
| 71 | 71 | // register widgets to be listed in the View Configuration |
| 72 | - add_filter( 'gravityview_register_directory_widgets', array( $this, 'register_widget') ); |
|
| 72 | + add_filter( 'gravityview_register_directory_widgets', array( $this, 'register_widget' ) ); |
|
| 73 | 73 | |
| 74 | 74 | // widget options |
| 75 | 75 | add_filter( 'gravityview_template_widget_options', array( $this, 'assign_widget_options' ), 10, 3 ); |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | add_action( "gravityview_render_widget_{$widget_id}", array( $this, 'render_frontend' ), 10, 1 ); |
| 79 | 79 | |
| 80 | 80 | // register shortcodes |
| 81 | - add_action( 'wp', array( $this, 'add_shortcode') ); |
|
| 81 | + add_action( 'wp', array( $this, 'add_shortcode' ) ); |
|
| 82 | 82 | |
| 83 | 83 | // Use shortcodes in text widgets. |
| 84 | - add_filter('widget_text', array( $this, 'maybe_do_shortcode' ) ); |
|
| 84 | + add_filter( 'widget_text', array( $this, 'maybe_do_shortcode' ) ); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | |
@@ -99,14 +99,14 @@ discard block |
||
| 99 | 99 | * @param boolean $enable_custom_class False by default. Return true if you want to enable. |
| 100 | 100 | * @param GravityView_Widget $this Current instance of GravityView_Widget |
| 101 | 101 | */ |
| 102 | - $enable_custom_class = apply_filters('gravityview/widget/enable_custom_class', false, $this ); |
|
| 102 | + $enable_custom_class = apply_filters( 'gravityview/widget/enable_custom_class', false, $this ); |
|
| 103 | 103 | |
| 104 | - if( $enable_custom_class ) { |
|
| 104 | + if ( $enable_custom_class ) { |
|
| 105 | 105 | |
| 106 | - $settings['custom_class'] = array( |
|
| 106 | + $settings[ 'custom_class' ] = array( |
|
| 107 | 107 | 'type' => 'text', |
| 108 | 108 | 'label' => __( 'Custom CSS Class:', 'gravityview' ), |
| 109 | - 'desc' => __( 'This class will be added to the widget container', 'gravityview'), |
|
| 109 | + 'desc' => __( 'This class will be added to the widget container', 'gravityview' ), |
|
| 110 | 110 | 'value' => '', |
| 111 | 111 | 'merge_tags' => true, |
| 112 | 112 | ); |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @return array|null Settings array; NULL if not set |
| 129 | 129 | */ |
| 130 | 130 | public function get_settings() { |
| 131 | - return !empty( $this->settings ) ? $this->settings : NULL; |
|
| 131 | + return ! empty( $this->settings ) ? $this->settings : NULL; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | public function get_setting( $key ) { |
| 140 | 140 | $setting = NULL; |
| 141 | 141 | |
| 142 | - if( isset( $this->settings ) && is_array( $this->settings ) ) { |
|
| 142 | + if ( isset( $this->settings ) && is_array( $this->settings ) ) { |
|
| 143 | 143 | $setting = isset( $this->settings[ $key ] ) ? $this->settings[ $key ] : NULL; |
| 144 | 144 | } |
| 145 | 145 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | function maybe_do_shortcode( $text, $widget = NULL ) { |
| 156 | 156 | |
| 157 | - if( !empty( $this->shortcode_name ) && has_shortcode( $text, $this->shortcode_name ) ) { |
|
| 157 | + if ( ! empty( $this->shortcode_name ) && has_shortcode( $text, $this->shortcode_name ) ) { |
|
| 158 | 158 | return do_shortcode( $text ); |
| 159 | 159 | } |
| 160 | 160 | |
@@ -183,26 +183,26 @@ discard block |
||
| 183 | 183 | return; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - if( empty( $this->shortcode_name ) ) { return; } |
|
| 186 | + if ( empty( $this->shortcode_name ) ) { return; } |
|
| 187 | 187 | |
| 188 | 188 | // If the widget shouldn't output on single entries, don't show it |
| 189 | - if( empty( $this->show_on_single ) && class_exists('GravityView_frontend') && GravityView_frontend::is_single_entry() ) { |
|
| 190 | - do_action('gravityview_log_debug', sprintf( '%s[add_shortcode]: Skipping; set to not run on single entry.', get_class($this)) ); |
|
| 189 | + if ( empty( $this->show_on_single ) && class_exists( 'GravityView_frontend' ) && GravityView_frontend::is_single_entry() ) { |
|
| 190 | + do_action( 'gravityview_log_debug', sprintf( '%s[add_shortcode]: Skipping; set to not run on single entry.', get_class( $this ) ) ); |
|
| 191 | 191 | |
| 192 | 192 | add_shortcode( $this->shortcode_name, '__return_null' ); |
| 193 | 193 | return; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | |
| 197 | - if( !has_gravityview_shortcode( $post ) ) { |
|
| 197 | + if ( ! has_gravityview_shortcode( $post ) ) { |
|
| 198 | 198 | |
| 199 | - do_action('gravityview_log_debug', sprintf( '%s[add_shortcode]: No shortcode present; not adding render_frontend shortcode.', get_class($this)) ); |
|
| 199 | + do_action( 'gravityview_log_debug', sprintf( '%s[add_shortcode]: No shortcode present; not adding render_frontend shortcode.', get_class( $this ) ) ); |
|
| 200 | 200 | |
| 201 | 201 | add_shortcode( $this->shortcode_name, '__return_null' ); |
| 202 | 202 | return; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - add_shortcode( $this->shortcode_name, array( $this, 'render_shortcode') ); |
|
| 205 | + add_shortcode( $this->shortcode_name, array( $this, 'render_shortcode' ) ); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | function register_widget( $widgets ) { |
| 214 | 214 | $widgets[ $this->widget_id ] = array( |
| 215 | - 'label' => $this->widget_label , |
|
| 215 | + 'label' => $this->widget_label, |
|
| 216 | 216 | 'description' => $this->widget_description, |
| 217 | 217 | 'subtitle' => $this->widget_subtitle, |
| 218 | 218 | ); |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | public function assign_widget_options( $options = array(), $template = '', $widget = '' ) { |
| 231 | 231 | |
| 232 | - if( $this->widget_id === $widget ) { |
|
| 232 | + if ( $this->widget_id === $widget ) { |
|
| 233 | 233 | $options = array_merge( $options, $this->settings ); |
| 234 | 234 | } |
| 235 | 235 | |
@@ -242,9 +242,9 @@ discard block |
||
| 242 | 242 | * |
| 243 | 243 | * @return void |
| 244 | 244 | */ |
| 245 | - public function render_frontend( $widget_args, $content = '', $context = '') { |
|
| 245 | + public function render_frontend( $widget_args, $content = '', $context = '' ) { |
|
| 246 | 246 | // to be defined by child class |
| 247 | - if( !$this->pre_render_frontend() ) { |
|
| 247 | + if ( ! $this->pre_render_frontend() ) { |
|
| 248 | 248 | return; |
| 249 | 249 | } |
| 250 | 250 | } |
@@ -256,8 +256,8 @@ discard block |
||
| 256 | 256 | public function pre_render_frontend() { |
| 257 | 257 | $gravityview_view = GravityView_View::getInstance(); |
| 258 | 258 | |
| 259 | - if( empty( $gravityview_view ) ) { |
|
| 260 | - do_action('gravityview_log_debug', sprintf( '%s[render_frontend]: $gravityview_view not instantiated yet.', get_class($this)) ); |
|
| 259 | + if ( empty( $gravityview_view ) ) { |
|
| 260 | + do_action( 'gravityview_log_debug', sprintf( '%s[render_frontend]: $gravityview_view not instantiated yet.', get_class( $this ) ) ); |
|
| 261 | 261 | return false; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -268,8 +268,8 @@ discard block |
||
| 268 | 268 | */ |
| 269 | 269 | $hide_until_search = apply_filters( 'gravityview/widget/hide_until_searched', $gravityview_view->hide_until_searched, $this ); |
| 270 | 270 | |
| 271 | - if( $hide_until_search ) { |
|
| 272 | - do_action('gravityview_log_debug', sprintf( '%s[render_frontend]: Hide View data until search is performed', get_class($this)) ); |
|
| 271 | + if ( $hide_until_search ) { |
|
| 272 | + do_action( 'gravityview_log_debug', sprintf( '%s[render_frontend]: Hide View data until search is performed', get_class( $this ) ) ); |
|
| 273 | 273 | return false; |
| 274 | 274 | } |
| 275 | 275 | |
@@ -312,11 +312,11 @@ discard block |
||
| 312 | 312 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' ); |
| 313 | 313 | |
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * When an entry is created, check if we need to update the custom slug meta |
|
| 317 | - * todo: move this to its own class.. |
|
| 318 | - */ |
|
| 319 | - add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 ); |
|
| 315 | + /** |
|
| 316 | + * When an entry is created, check if we need to update the custom slug meta |
|
| 317 | + * todo: move this to its own class.. |
|
| 318 | + */ |
|
| 319 | + add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 ); |
|
| 320 | 320 | |
| 321 | 321 | /** |
| 322 | 322 | * @action `gravityview_include_frontend_actions` Triggered after all GravityView frontend files are loaded |
@@ -347,34 +347,34 @@ discard block |
||
| 347 | 347 | |
| 348 | 348 | /** DEBUG */ |
| 349 | 349 | |
| 350 | - /** |
|
| 351 | - * Logs messages using Gravity Forms logging add-on |
|
| 352 | - * @param string $message log message |
|
| 353 | - * @param mixed $data Additional data to display |
|
| 354 | - * @return void |
|
| 355 | - */ |
|
| 356 | - public static function log_debug( $message, $data = null ){ |
|
| 357 | - /** |
|
| 358 | - * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output |
|
| 359 | - * @param string $message Message to display |
|
| 360 | - * @param mixed $data Supporting data to print alongside it |
|
| 361 | - */ |
|
| 362 | - do_action( 'gravityview_log_debug', $message, $data ); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Logs messages using Gravity Forms logging add-on |
|
| 367 | - * @param string $message log message |
|
| 368 | - * @return void |
|
| 369 | - */ |
|
| 370 | - public static function log_error( $message, $data = null ){ |
|
| 371 | - /** |
|
| 372 | - * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output |
|
| 373 | - * @param string $message Error message to display |
|
| 374 | - * @param mixed $data Supporting data to print alongside it |
|
| 375 | - */ |
|
| 376 | - do_action( 'gravityview_log_error', $message, $data ); |
|
| 377 | - } |
|
| 350 | + /** |
|
| 351 | + * Logs messages using Gravity Forms logging add-on |
|
| 352 | + * @param string $message log message |
|
| 353 | + * @param mixed $data Additional data to display |
|
| 354 | + * @return void |
|
| 355 | + */ |
|
| 356 | + public static function log_debug( $message, $data = null ){ |
|
| 357 | + /** |
|
| 358 | + * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output |
|
| 359 | + * @param string $message Message to display |
|
| 360 | + * @param mixed $data Supporting data to print alongside it |
|
| 361 | + */ |
|
| 362 | + do_action( 'gravityview_log_debug', $message, $data ); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Logs messages using Gravity Forms logging add-on |
|
| 367 | + * @param string $message log message |
|
| 368 | + * @return void |
|
| 369 | + */ |
|
| 370 | + public static function log_error( $message, $data = null ){ |
|
| 371 | + /** |
|
| 372 | + * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output |
|
| 373 | + * @param string $message Error message to display |
|
| 374 | + * @param mixed $data Supporting data to print alongside it |
|
| 375 | + */ |
|
| 376 | + do_action( 'gravityview_log_error', $message, $data ); |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | 379 | } // end class GravityView_Plugin |
| 380 | 380 | |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | * @param mixed $data Additional data to display |
| 352 | 352 | * @return void |
| 353 | 353 | */ |
| 354 | - public static function log_debug( $message, $data = null ){ |
|
| 354 | + public static function log_debug( $message, $data = null ) { |
|
| 355 | 355 | /** |
| 356 | 356 | * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output |
| 357 | 357 | * @param string $message Message to display |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | * @param string $message log message |
| 366 | 366 | * @return void |
| 367 | 367 | */ |
| 368 | - public static function log_error( $message, $data = null ){ |
|
| 368 | + public static function log_error( $message, $data = null ) { |
|
| 369 | 369 | /** |
| 370 | 370 | * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output |
| 371 | 371 | * @param string $message Error message to display |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public static function getInstance() { |
| 74 | 74 | |
| 75 | - if( empty( self::$instance ) ) { |
|
| 75 | + if ( empty( self::$instance ) ) { |
|
| 76 | 76 | self::$instance = new self; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | self::require_files(); |
| 85 | 85 | |
| 86 | - if( ! GravityView_Compatibility::is_valid() ) { |
|
| 86 | + if ( ! GravityView_Compatibility::is_valid() ) { |
|
| 87 | 87 | return; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | private static function require_files() { |
| 100 | 100 | require_once( GRAVITYVIEW_DIR . 'includes/helper-functions.php' ); |
| 101 | - require_once( GRAVITYVIEW_DIR . 'includes/class-common.php'); |
|
| 102 | - require_once( GRAVITYVIEW_DIR . 'includes/connector-functions.php'); |
|
| 101 | + require_once( GRAVITYVIEW_DIR . 'includes/class-common.php' ); |
|
| 102 | + require_once( GRAVITYVIEW_DIR . 'includes/connector-functions.php' ); |
|
| 103 | 103 | require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-compatibility.php' ); |
| 104 | 104 | require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-roles-capabilities.php' ); |
| 105 | 105 | require_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-notices.php' ); |
| 106 | - require_once( GRAVITYVIEW_DIR .'includes/class-admin.php' ); |
|
| 107 | - require_once( GRAVITYVIEW_DIR . 'includes/class-post-types.php'); |
|
| 108 | - require_once( GRAVITYVIEW_DIR . 'includes/class-cache.php'); |
|
| 106 | + require_once( GRAVITYVIEW_DIR . 'includes/class-admin.php' ); |
|
| 107 | + require_once( GRAVITYVIEW_DIR . 'includes/class-post-types.php' ); |
|
| 108 | + require_once( GRAVITYVIEW_DIR . 'includes/class-cache.php' ); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -138,22 +138,22 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-approval-status.php' ); |
| 141 | - include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-entry-approval.php' ); |
|
| 141 | + include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-approval.php' ); |
|
| 142 | 142 | |
| 143 | - include_once( GRAVITYVIEW_DIR .'includes/class-gravityview-entry-notes.php' ); |
|
| 144 | - include_once( GRAVITYVIEW_DIR .'includes/load-plugin-and-theme-hooks.php' ); |
|
| 143 | + include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-notes.php' ); |
|
| 144 | + include_once( GRAVITYVIEW_DIR . 'includes/load-plugin-and-theme-hooks.php' ); |
|
| 145 | 145 | |
| 146 | 146 | // Load Extensions |
| 147 | 147 | // @todo: Convert to a scan of the directory or a method where this all lives |
| 148 | - include_once( GRAVITYVIEW_DIR .'includes/extensions/edit-entry/class-edit-entry.php' ); |
|
| 149 | - include_once( GRAVITYVIEW_DIR .'includes/extensions/delete-entry/class-delete-entry.php' ); |
|
| 150 | - include_once( GRAVITYVIEW_DIR .'includes/extensions/entry-notes/class-gravityview-field-notes.php' ); |
|
| 148 | + include_once( GRAVITYVIEW_DIR . 'includes/extensions/edit-entry/class-edit-entry.php' ); |
|
| 149 | + include_once( GRAVITYVIEW_DIR . 'includes/extensions/delete-entry/class-delete-entry.php' ); |
|
| 150 | + include_once( GRAVITYVIEW_DIR . 'includes/extensions/entry-notes/class-gravityview-field-notes.php' ); |
|
| 151 | 151 | |
| 152 | 152 | // Load WordPress Widgets |
| 153 | - include_once( GRAVITYVIEW_DIR .'includes/wordpress-widgets/register-wordpress-widgets.php' ); |
|
| 153 | + include_once( GRAVITYVIEW_DIR . 'includes/wordpress-widgets/register-wordpress-widgets.php' ); |
|
| 154 | 154 | |
| 155 | 155 | // Load GravityView Widgets |
| 156 | - include_once( GRAVITYVIEW_DIR .'includes/widgets/register-gravityview-widgets.php' ); |
|
| 156 | + include_once( GRAVITYVIEW_DIR . 'includes/widgets/register-gravityview-widgets.php' ); |
|
| 157 | 157 | |
| 158 | 158 | // Add oEmbed |
| 159 | 159 | include_once( GRAVITYVIEW_DIR . 'includes/class-oembed.php' ); |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | include_once( GRAVITYVIEW_DIR . 'includes/class-frontend-views.php' ); |
| 167 | 167 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-admin-bar.php' ); |
| 168 | 168 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-list.php' ); |
| 169 | - include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-merge-tags.php'); /** @since 1.8.4 */ |
|
| 169 | + include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-merge-tags.php' ); /** @since 1.8.4 */ |
|
| 170 | 170 | include_once( GRAVITYVIEW_DIR . 'includes/class-data.php' ); |
| 171 | 171 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-shortcode.php' ); |
| 172 | 172 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-entry-link-shortcode.php' ); |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @return bool |
| 182 | 182 | */ |
| 183 | 183 | public static function is_network_activated() { |
| 184 | - return is_multisite() && ( function_exists('is_plugin_active_for_network') && is_plugin_active_for_network( 'gravityview/gravityview.php' ) ); |
|
| 184 | + return is_multisite() && ( function_exists( 'is_plugin_active_for_network' ) && is_plugin_active_for_network( 'gravityview/gravityview.php' ) ); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * @since 1.7.5.1 |
| 247 | 247 | */ |
| 248 | 248 | public static function include_widget_class() { |
| 249 | - include_once( GRAVITYVIEW_DIR .'includes/widgets/class-gravityview-widget.php' ); |
|
| 249 | + include_once( GRAVITYVIEW_DIR . 'includes/widgets/class-gravityview-widget.php' ); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | } |
| 269 | 269 | if ( ! $loaded ) { |
| 270 | 270 | $locale = apply_filters( 'plugin_locale', get_locale(), 'gravityview' ); |
| 271 | - $mofile = dirname( __FILE__ ) . '/languages/gravityview-'. $locale .'.mo'; |
|
| 271 | + $mofile = dirname( __FILE__ ) . '/languages/gravityview-' . $locale . '.mo'; |
|
| 272 | 272 | load_textdomain( 'gravityview', $mofile ); |
| 273 | 273 | } |
| 274 | 274 | |
@@ -299,12 +299,12 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | public function frontend_actions( $force = false ) { |
| 301 | 301 | |
| 302 | - if( self::is_admin() && ! $force ) { return; } |
|
| 302 | + if ( self::is_admin() && ! $force ) { return; } |
|
| 303 | 303 | |
| 304 | 304 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-image.php' ); |
| 305 | - include_once( GRAVITYVIEW_DIR .'includes/class-template.php' ); |
|
| 306 | - include_once( GRAVITYVIEW_DIR .'includes/class-api.php' ); |
|
| 307 | - include_once( GRAVITYVIEW_DIR .'includes/class-frontend-views.php' ); |
|
| 305 | + include_once( GRAVITYVIEW_DIR . 'includes/class-template.php' ); |
|
| 306 | + include_once( GRAVITYVIEW_DIR . 'includes/class-api.php' ); |
|
| 307 | + include_once( GRAVITYVIEW_DIR . 'includes/class-frontend-views.php' ); |
|
| 308 | 308 | include_once( GRAVITYVIEW_DIR . 'includes/class-gravityview-change-entry-creator.php' ); |
| 309 | 309 | |
| 310 | 310 | |
@@ -329,8 +329,8 @@ discard block |
||
| 329 | 329 | */ |
| 330 | 330 | public static function get_default_widget_areas() { |
| 331 | 331 | $default_areas = array( |
| 332 | - array( '1-1' => array( array( 'areaid' => 'top', 'title' => __('Top', 'gravityview' ) , 'subtitle' => '' ) ) ), |
|
| 333 | - array( '1-2' => array( array( 'areaid' => 'left', 'title' => __('Left', 'gravityview') , 'subtitle' => '' ) ), '2-2' => array( array( 'areaid' => 'right', 'title' => __('Right', 'gravityview') , 'subtitle' => '' ) ) ), |
|
| 332 | + array( '1-1' => array( array( 'areaid' => 'top', 'title' => __( 'Top', 'gravityview' ), 'subtitle' => '' ) ) ), |
|
| 333 | + array( '1-2' => array( array( 'areaid' => 'left', 'title' => __( 'Left', 'gravityview' ), 'subtitle' => '' ) ), '2-2' => array( array( 'areaid' => 'right', 'title' => __( 'Right', 'gravityview' ), 'subtitle' => '' ) ) ), |
|
| 334 | 334 | ); |
| 335 | 335 | |
| 336 | 336 | /** |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | * @param mixed $data Additional data to display |
| 349 | 349 | * @return void |
| 350 | 350 | */ |
| 351 | - public static function log_debug( $message, $data = null ){ |
|
| 351 | + public static function log_debug( $message, $data = null ) { |
|
| 352 | 352 | /** |
| 353 | 353 | * @action `gravityview_log_debug` Log a debug message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output |
| 354 | 354 | * @param string $message Message to display |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * @param string $message log message |
| 363 | 363 | * @return void |
| 364 | 364 | */ |
| 365 | - public static function log_error( $message, $data = null ){ |
|
| 365 | + public static function log_error( $message, $data = null ) { |
|
| 366 | 366 | /** |
| 367 | 367 | * @action `gravityview_log_error` Log an error message that shows up in the Gravity Forms Logging Addon and also the Debug Bar plugin output |
| 368 | 368 | * @param string $message Error message to display |
@@ -373,4 +373,4 @@ discard block |
||
| 373 | 373 | |
| 374 | 374 | } // end class GravityView_Plugin |
| 375 | 375 | |
| 376 | -add_action('plugins_loaded', array('GravityView_Plugin', 'getInstance'), 1); |
|
| 376 | +add_action( 'plugins_loaded', array( 'GravityView_Plugin', 'getInstance' ), 1 ); |
|
@@ -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 ); ?>" /> |
@@ -18,10 +18,10 @@ |
||
| 18 | 18 | |
| 19 | 19 | $show_mt = $this->show_merge_tags(); |
| 20 | 20 | |
| 21 | - if( $show_mt && $this->field['merge_tags'] !== false || $this->field['merge_tags'] === 'force' ) { |
|
| 22 | - $class = 'merge-tag-support mt-position-right mt-hide_all_fields '; |
|
| 23 | - } |
|
| 24 | - $class .= !empty( $this->field['class'] ) ? $this->field['class'] : 'widefat'; |
|
| 21 | + if( $show_mt && $this->field['merge_tags'] !== false || $this->field['merge_tags'] === 'force' ) { |
|
| 22 | + $class = 'merge-tag-support mt-position-right mt-hide_all_fields '; |
|
| 23 | + } |
|
| 24 | + $class .= !empty( $this->field['class'] ) ? $this->field['class'] : 'widefat'; |
|
| 25 | 25 | |
| 26 | 26 | ?> |
| 27 | 27 | <input name="<?php echo esc_attr( $this->name ); ?>" id="<?php echo $this->get_field_id(); ?>" type="number" value="<?php echo esc_attr( $this->value ); ?>" class="<?php echo esc_attr( $class ); ?>"> |
@@ -3,13 +3,13 @@ discard block |
||
| 3 | 3 | * number input type |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -if( !class_exists('GravityView_FieldType_text') ) { |
|
| 6 | +if ( ! class_exists( 'GravityView_FieldType_text' ) ) { |
|
| 7 | 7 | include_once( GRAVITYVIEW_DIR . 'includes/admin/field-types/type_text.php' ); |
| 8 | 8 | } |
| 9 | 9 | class GravityView_FieldType_number extends GravityView_FieldType_text { |
| 10 | 10 | |
| 11 | 11 | function render_input( $override_input = null ) { |
| 12 | - if( isset( $override_input ) ) { |
|
| 12 | + if ( isset( $override_input ) ) { |
|
| 13 | 13 | echo $override_input; |
| 14 | 14 | return; |
| 15 | 15 | } |
@@ -18,10 +18,10 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | $show_mt = $this->show_merge_tags(); |
| 20 | 20 | |
| 21 | - if( $show_mt && $this->field['merge_tags'] !== false || $this->field['merge_tags'] === 'force' ) { |
|
| 21 | + if ( $show_mt && $this->field[ 'merge_tags' ] !== false || $this->field[ 'merge_tags' ] === 'force' ) { |
|
| 22 | 22 | $class = 'merge-tag-support mt-position-right mt-hide_all_fields '; |
| 23 | 23 | } |
| 24 | - $class .= !empty( $this->field['class'] ) ? $this->field['class'] : 'widefat'; |
|
| 24 | + $class .= ! empty( $this->field[ 'class' ] ) ? $this->field[ 'class' ] : 'widefat'; |
|
| 25 | 25 | |
| 26 | 26 | ?> |
| 27 | 27 | <input name="<?php echo esc_attr( $this->name ); ?>" id="<?php echo $this->get_field_id(); ?>" type="number" value="<?php echo esc_attr( $this->value ); ?>" class="<?php echo esc_attr( $class ); ?>"> |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | if( !GravityView_Compatibility::is_valid() ) { return; } |
| 16 | 16 | |
| 17 | - self::$metaboxes_dir = GRAVITYVIEW_DIR . 'includes/admin/metaboxes/'; |
|
| 17 | + self::$metaboxes_dir = GRAVITYVIEW_DIR . 'includes/admin/metaboxes/'; |
|
| 18 | 18 | |
| 19 | 19 | include_once self::$metaboxes_dir . 'class-gravityview-metabox-tab.php'; |
| 20 | 20 | |
@@ -228,13 +228,13 @@ discard block |
||
| 228 | 228 | $get_id_backup = isset($_GET['id']) ? $_GET['id'] : NULL; |
| 229 | 229 | |
| 230 | 230 | if( isset( $form['id'] ) ) { |
| 231 | - $form_script = 'var form = ' . GFCommon::json_encode($form) . ';'; |
|
| 231 | + $form_script = 'var form = ' . GFCommon::json_encode($form) . ';'; |
|
| 232 | 232 | |
| 233 | - // The `gf_vars()` method needs a $_GET[id] variable set with the form ID. |
|
| 234 | - $_GET['id'] = $form['id']; |
|
| 233 | + // The `gf_vars()` method needs a $_GET[id] variable set with the form ID. |
|
| 234 | + $_GET['id'] = $form['id']; |
|
| 235 | 235 | |
| 236 | 236 | } else { |
| 237 | - $form_script = 'var form = new Form();'; |
|
| 237 | + $form_script = 'var form = new Form();'; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | $output = '<script type="text/javascript" data-gv-merge-tags="1">' . $form_script . "\n" . GFCommon::gf_vars(false) . '</script>'; |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | function __construct() { |
| 19 | 19 | |
| 20 | - if( !GravityView_Compatibility::is_valid() ) { return; } |
|
| 20 | + if ( ! GravityView_Compatibility::is_valid() ) { return; } |
|
| 21 | 21 | |
| 22 | 22 | self::$metaboxes_dir = GRAVITYVIEW_DIR . 'includes/admin/metaboxes/'; |
| 23 | 23 | |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function initialize() { |
| 37 | 37 | |
| 38 | - add_action( 'add_meta_boxes', array( $this, 'register_metaboxes' )); |
|
| 38 | + add_action( 'add_meta_boxes', array( $this, 'register_metaboxes' ) ); |
|
| 39 | 39 | |
| 40 | - add_action( 'add_meta_boxes_gravityview' , array( $this, 'update_priority' ) ); |
|
| 40 | + add_action( 'add_meta_boxes_gravityview', array( $this, 'update_priority' ) ); |
|
| 41 | 41 | |
| 42 | 42 | // information box |
| 43 | 43 | add_action( 'post_submitbox_misc_actions', array( $this, 'render_shortcode_hint' ) ); |
@@ -51,13 +51,13 @@ discard block |
||
| 51 | 51 | function update_priority() { |
| 52 | 52 | global $wp_meta_boxes; |
| 53 | 53 | |
| 54 | - if( ! empty( $wp_meta_boxes['gravityview'] ) ) { |
|
| 55 | - foreach( array( 'high', 'core', 'low' ) as $position ) { |
|
| 56 | - if( isset( $wp_meta_boxes['gravityview']['normal'][ $position ] ) ) { |
|
| 57 | - foreach( $wp_meta_boxes['gravityview']['normal'][ $position ] as $key => $meta_box ) { |
|
| 58 | - if( ! preg_match( '/^gravityview_/ism', $key ) ) { |
|
| 59 | - $wp_meta_boxes['gravityview']['advanced'][ $position ][ $key ] = $meta_box; |
|
| 60 | - unset( $wp_meta_boxes['gravityview']['normal'][ $position ][ $key ] ); |
|
| 54 | + if ( ! empty( $wp_meta_boxes[ 'gravityview' ] ) ) { |
|
| 55 | + foreach ( array( 'high', 'core', 'low' ) as $position ) { |
|
| 56 | + if ( isset( $wp_meta_boxes[ 'gravityview' ][ 'normal' ][ $position ] ) ) { |
|
| 57 | + foreach ( $wp_meta_boxes[ 'gravityview' ][ 'normal' ][ $position ] as $key => $meta_box ) { |
|
| 58 | + if ( ! preg_match( '/^gravityview_/ism', $key ) ) { |
|
| 59 | + $wp_meta_boxes[ 'gravityview' ][ 'advanced' ][ $position ][ $key ] = $meta_box; |
|
| 60 | + unset( $wp_meta_boxes[ 'gravityview' ][ 'normal' ][ $position ][ $key ] ); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | global $post; |
| 70 | 70 | |
| 71 | 71 | // On Comment Edit, for example, $post isn't set. |
| 72 | - if( empty( $post ) || !is_object( $post ) || !isset( $post->ID ) ) { |
|
| 72 | + if ( empty( $post ) || ! is_object( $post ) || ! isset( $post->ID ) ) { |
|
| 73 | 73 | return; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -152,9 +152,9 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | $metaboxes = apply_filters( 'gravityview/metaboxes/default', $metaboxes ); |
| 154 | 154 | |
| 155 | - foreach( $metaboxes as $m ) { |
|
| 155 | + foreach ( $metaboxes as $m ) { |
|
| 156 | 156 | |
| 157 | - $tab = new GravityView_Metabox_Tab( $m['id'], $m['title'], $m['file'], $m['icon-class'], $m['callback'], $m['callback_args'] ); |
|
| 157 | + $tab = new GravityView_Metabox_Tab( $m[ 'id' ], $m[ 'title' ], $m[ 'file' ], $m[ 'icon-class' ], $m[ 'callback' ], $m[ 'callback_args' ] ); |
|
| 158 | 158 | |
| 159 | 159 | GravityView_Metabox_Tabs::add( $tab ); |
| 160 | 160 | |
@@ -180,8 +180,8 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | $links = GravityView_Admin_Views::get_connected_form_links( $current_form, false ); |
| 182 | 182 | |
| 183 | - if( !empty( $links ) ) { |
|
| 184 | - $links = '<span class="alignright gv-form-links">'. $links .'</span>'; |
|
| 183 | + if ( ! empty( $links ) ) { |
|
| 184 | + $links = '<span class="alignright gv-form-links">' . $links . '</span>'; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | return __( 'Data Source', 'gravityview' ) . $links; |
@@ -220,28 +220,28 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | public static function render_merge_tags_scripts( $curr_form ) { |
| 222 | 222 | |
| 223 | - if( empty( $curr_form )) { |
|
| 223 | + if ( empty( $curr_form ) ) { |
|
| 224 | 224 | return NULL; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | $form = gravityview_get_form( $curr_form ); |
| 228 | 228 | |
| 229 | - $get_id_backup = isset($_GET['id']) ? $_GET['id'] : NULL; |
|
| 229 | + $get_id_backup = isset( $_GET[ 'id' ] ) ? $_GET[ 'id' ] : NULL; |
|
| 230 | 230 | |
| 231 | - if( isset( $form['id'] ) ) { |
|
| 232 | - $form_script = 'var form = ' . GFCommon::json_encode($form) . ';'; |
|
| 231 | + if ( isset( $form[ 'id' ] ) ) { |
|
| 232 | + $form_script = 'var form = ' . GFCommon::json_encode( $form ) . ';'; |
|
| 233 | 233 | |
| 234 | 234 | // The `gf_vars()` method needs a $_GET[id] variable set with the form ID. |
| 235 | - $_GET['id'] = $form['id']; |
|
| 235 | + $_GET[ 'id' ] = $form[ 'id' ]; |
|
| 236 | 236 | |
| 237 | 237 | } else { |
| 238 | 238 | $form_script = 'var form = new Form();'; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - $output = '<script type="text/javascript" data-gv-merge-tags="1">' . $form_script . "\n" . GFCommon::gf_vars(false) . '</script>'; |
|
| 241 | + $output = '<script type="text/javascript" data-gv-merge-tags="1">' . $form_script . "\n" . GFCommon::gf_vars( false ) . '</script>'; |
|
| 242 | 242 | |
| 243 | 243 | // Restore previous $_GET setting |
| 244 | - $_GET['id'] = $get_id_backup; |
|
| 244 | + $_GET[ 'id' ] = $get_id_backup; |
|
| 245 | 245 | |
| 246 | 246 | return $output; |
| 247 | 247 | } |
@@ -297,10 +297,10 @@ discard block |
||
| 297 | 297 | global $post; |
| 298 | 298 | |
| 299 | 299 | // Only show this on GravityView post types. |
| 300 | - if( false === gravityview_is_admin_page() ) { return; } |
|
| 300 | + if ( false === gravityview_is_admin_page() ) { return; } |
|
| 301 | 301 | |
| 302 | 302 | // If the View hasn't been configured yet, don't show embed shortcode |
| 303 | - if( !gravityview_get_directory_fields( $post->ID ) ) { return; } |
|
| 303 | + if ( ! gravityview_get_directory_fields( $post->ID ) ) { return; } |
|
| 304 | 304 | |
| 305 | 305 | include self::$metaboxes_dir . 'views/shortcode-hint.php'; |
| 306 | 306 | } |