@@ -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( 'RGForms', 'delete_file') ); |
|
| 83 | + // Add front-end access to Gravity Forms delete file action |
|
| 84 | + add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'RGForms', 'delete_file') ); |
|
| 85 | 85 | |
| 86 | - // Make sure this hook is run for non-admins |
|
| 87 | - add_action( 'wp_ajax_rg_delete_file', array( 'RGForms', 'delete_file') ); |
|
| 86 | + // Make sure this hook is run for non-admins |
|
| 87 | + add_action( 'wp_ajax_rg_delete_file', array( 'RGForms', '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,75 +105,75 @@ 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 | - 'page' => 'gf_entries', // Needed for GFForms::get_page() |
|
| 155 | - 'view' => 'entry', // Needed for GFForms::get_page() |
|
| 156 | - 'edit' => wp_create_nonce( $nonce_key ) |
|
| 157 | - ), $base ); |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Allow passing params to dynamically populate entry with values |
|
| 161 | - * @since 1.9.2 |
|
| 162 | - */ |
|
| 163 | - if( !empty( $field_values ) ) { |
|
| 164 | - |
|
| 165 | - if( is_array( $field_values ) ) { |
|
| 166 | - // If already an array, no parse_str() needed |
|
| 167 | - $params = $field_values; |
|
| 168 | - } else { |
|
| 169 | - parse_str( $field_values, $params ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - $url = add_query_arg( $params, $url ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return $url; |
|
| 176 | - } |
|
| 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 | + 'page' => 'gf_entries', // Needed for GFForms::get_page() |
|
| 155 | + 'view' => 'entry', // Needed for GFForms::get_page() |
|
| 156 | + 'edit' => wp_create_nonce( $nonce_key ) |
|
| 157 | + ), $base ); |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Allow passing params to dynamically populate entry with values |
|
| 161 | + * @since 1.9.2 |
|
| 162 | + */ |
|
| 163 | + if( !empty( $field_values ) ) { |
|
| 164 | + |
|
| 165 | + if( is_array( $field_values ) ) { |
|
| 166 | + // If already an array, no parse_str() needed |
|
| 167 | + $params = $field_values; |
|
| 168 | + } else { |
|
| 169 | + parse_str( $field_values, $params ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + $url = add_query_arg( $params, $url ); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return $url; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -209,81 +209,81 @@ discard block |
||
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * checks if user has permissions to edit a specific entry |
|
| 214 | - * |
|
| 215 | - * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! |
|
| 216 | - * |
|
| 217 | - * @param array $entry Gravity Forms entry array |
|
| 218 | - * @param int $view_id ID of the view you want to check visibility against {@since 1.9.2} |
|
| 219 | - * @return bool |
|
| 220 | - */ |
|
| 221 | - public static function check_user_cap_edit_entry( $entry, $view_id = 0 ) { |
|
| 212 | + /** |
|
| 213 | + * checks if user has permissions to edit a specific entry |
|
| 214 | + * |
|
| 215 | + * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! |
|
| 216 | + * |
|
| 217 | + * @param array $entry Gravity Forms entry array |
|
| 218 | + * @param int $view_id ID of the view you want to check visibility against {@since 1.9.2} |
|
| 219 | + * @return bool |
|
| 220 | + */ |
|
| 221 | + public static function check_user_cap_edit_entry( $entry, $view_id = 0 ) { |
|
| 222 | 222 | |
| 223 | - // No permission by default |
|
| 224 | - $user_can_edit = false; |
|
| 223 | + // No permission by default |
|
| 224 | + $user_can_edit = false; |
|
| 225 | 225 | |
| 226 | - // If they can edit any entries (as defined in Gravity Forms) |
|
| 227 | - // Or if they can edit other people's entries |
|
| 228 | - // Then we're good. |
|
| 229 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { |
|
| 226 | + // If they can edit any entries (as defined in Gravity Forms) |
|
| 227 | + // Or if they can edit other people's entries |
|
| 228 | + // Then we're good. |
|
| 229 | + if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { |
|
| 230 | 230 | |
| 231 | - do_action('gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.'); |
|
| 231 | + do_action('gravityview_log_debug', __METHOD__ . ' - User has ability to edit all entries.'); |
|
| 232 | 232 | |
| 233 | - $user_can_edit = true; |
|
| 233 | + $user_can_edit = true; |
|
| 234 | 234 | |
| 235 | - } else if( !isset( $entry['created_by'] ) ) { |
|
| 235 | + } else if( !isset( $entry['created_by'] ) ) { |
|
| 236 | 236 | |
| 237 | - do_action('gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.'); |
|
| 237 | + do_action('gravityview_log_error', 'GravityView_Edit_Entry[check_user_cap_edit_entry] Entry `created_by` doesn\'t exist.'); |
|
| 238 | 238 | |
| 239 | - $user_can_edit = false; |
|
| 239 | + $user_can_edit = false; |
|
| 240 | 240 | |
| 241 | - } else { |
|
| 241 | + } else { |
|
| 242 | 242 | |
| 243 | - // get user_edit setting |
|
| 244 | - if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) { |
|
| 245 | - // if View ID not specified or is the current view |
|
| 246 | - $user_edit = GravityView_View::getInstance()->getAtts('user_edit'); |
|
| 247 | - } else { |
|
| 248 | - // in case is specified and not the current view |
|
| 249 | - $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' ); |
|
| 250 | - } |
|
| 243 | + // get user_edit setting |
|
| 244 | + if( empty( $view_id ) || $view_id == GravityView_View::getInstance()->getViewId() ) { |
|
| 245 | + // if View ID not specified or is the current view |
|
| 246 | + $user_edit = GravityView_View::getInstance()->getAtts('user_edit'); |
|
| 247 | + } else { |
|
| 248 | + // in case is specified and not the current view |
|
| 249 | + $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' ); |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - $current_user = wp_get_current_user(); |
|
| 252 | + $current_user = wp_get_current_user(); |
|
| 253 | 253 | |
| 254 | - // User edit is disabled |
|
| 255 | - if( empty( $user_edit ) ) { |
|
| 254 | + // User edit is disabled |
|
| 255 | + if( empty( $user_edit ) ) { |
|
| 256 | 256 | |
| 257 | - do_action('gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' ); |
|
| 257 | + do_action('gravityview_log_debug', 'GravityView_Edit_Entry[check_user_cap_edit_entry] User Edit is disabled. Returning false.' ); |
|
| 258 | 258 | |
| 259 | - $user_can_edit = false; |
|
| 260 | - } |
|
| 259 | + $user_can_edit = false; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. |
|
| 263 | - else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
| 262 | + // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. |
|
| 263 | + else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
| 264 | 264 | |
| 265 | - do_action('gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) ); |
|
| 265 | + do_action('gravityview_log_debug', sprintf( 'GravityView_Edit_Entry[check_user_cap_edit_entry] User %s created the entry.', $current_user->ID ) ); |
|
| 266 | 266 | |
| 267 | - $user_can_edit = true; |
|
| 267 | + $user_can_edit = true; |
|
| 268 | 268 | |
| 269 | - } else if( ! is_user_logged_in() ) { |
|
| 269 | + } else if( ! is_user_logged_in() ) { |
|
| 270 | 270 | |
| 271 | - do_action( 'gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user' ); |
|
| 272 | - } |
|
| 271 | + do_action( 'gravityview_log_debug', __METHOD__ . ' No user defined; edit entry requires logged in user' ); |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - } |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - /** |
|
| 277 | - * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. |
|
| 278 | - * @since 1.15 Added `$entry` and `$view_id` parameters |
|
| 279 | - * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false) |
|
| 280 | - * @param[in] array $entry Gravity Forms entry array {@since 1.15} |
|
| 281 | - * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15} |
|
| 282 | - */ |
|
| 283 | - $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id ); |
|
| 276 | + /** |
|
| 277 | + * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. |
|
| 278 | + * @since 1.15 Added `$entry` and `$view_id` parameters |
|
| 279 | + * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false) |
|
| 280 | + * @param[in] array $entry Gravity Forms entry array {@since 1.15} |
|
| 281 | + * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15} |
|
| 282 | + */ |
|
| 283 | + $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id ); |
|
| 284 | 284 | |
| 285 | - return (bool)$user_can_edit; |
|
| 286 | - } |
|
| 285 | + return (bool)$user_can_edit; |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | 288 | |
| 289 | 289 | |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | self::getInstance()->set_entry( $entry ); |
| 230 | 230 | |
| 231 | - $base = GravityView_API::directory_link( $post_id, true ); |
|
| 231 | + $base = GravityView_API::directory_link( $post_id, true ); |
|
| 232 | 232 | |
| 233 | 233 | if( empty( $base ) ) { |
| 234 | 234 | do_action( 'gravityview_log_error', __METHOD__ . ' - Post ID does not exist: '.$post_id ); |
@@ -238,13 +238,13 @@ discard block |
||
| 238 | 238 | // Use the slug instead of the ID for consistent security |
| 239 | 239 | $entry_slug = GravityView_API::get_entry_slug( $entry['id'], $entry ); |
| 240 | 240 | |
| 241 | - $view_id = empty( $view_id ) ? gravityview_get_view_id() : $view_id; |
|
| 241 | + $view_id = empty( $view_id ) ? gravityview_get_view_id() : $view_id; |
|
| 242 | 242 | |
| 243 | 243 | $actionurl = add_query_arg( array( |
| 244 | 244 | 'action' => 'delete', |
| 245 | 245 | 'entry_id' => $entry_slug, |
| 246 | 246 | 'gvid' => $view_id, |
| 247 | - 'view_id' => $view_id, |
|
| 247 | + 'view_id' => $view_id, |
|
| 248 | 248 | ), $base ); |
| 249 | 249 | |
| 250 | 250 | $url = wp_nonce_url( $actionurl, 'delete_'.$entry_slug, 'delete' ); |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | * @action `gravityview/delete-entry/deleted` Triggered when an entry is deleted |
| 416 | 416 | * @since 1.16.4 |
| 417 | 417 | * @param int $entry_id ID of the Gravity Forms entry |
| 418 | - */ |
|
| 418 | + */ |
|
| 419 | 419 | do_action( 'gravityview/delete-entry/deleted', $entry_id ); |
| 420 | 420 | } |
| 421 | 421 | |
@@ -255,7 +255,6 @@ |
||
| 255 | 255 | * Get the default date format for a field based on the field ID and the time format setting |
| 256 | 256 | * |
| 257 | 257 | * @since 1.14 |
| 258 | - |
|
| 259 | 258 | * @param string $time_format The time format ("12" or "24"). Default: "12" {@since 1.14} |
| 260 | 259 | * @param int $field_id The ID of the field. Used to figure out full time/hours/minutes/am/pm {@since 1.14} |
| 261 | 260 | * |
@@ -40,11 +40,11 @@ |
||
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $field_options['link_phone'] = array( |
| 43 | - 'type' => 'checkbox', |
|
| 44 | - 'label' => __( 'Make Phone Number Clickable', 'gravityview' ), |
|
| 45 | - 'desc' => __( 'Allow dialing a number by clicking it?', 'gravityview'), |
|
| 46 | - 'value' => true, |
|
| 47 | - ); |
|
| 43 | + 'type' => 'checkbox', |
|
| 44 | + 'label' => __( 'Make Phone Number Clickable', 'gravityview' ), |
|
| 45 | + 'desc' => __( 'Allow dialing a number by clicking it?', 'gravityview'), |
|
| 46 | + 'value' => true, |
|
| 47 | + ); |
|
| 48 | 48 | |
| 49 | 49 | return $field_options; |
| 50 | 50 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $gv_modifiers = array( |
| 54 | 54 | 'maxwords:(\d+)' => 'modifier_maxwords', /** @see modifier_maxwords */ |
| 55 | 55 | 'wpautop' => 'modifier_wpautop', /** @see modifier_wpautop */ |
| 56 | - 'timestamp' => 'modifier_timestamp', /** @see modifier_timestamp */ |
|
| 56 | + 'timestamp' => 'modifier_timestamp', /** @see modifier_timestamp */ |
|
| 57 | 57 | ); |
| 58 | 58 | |
| 59 | 59 | $return = $value; |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | $atts = array( |
| 255 | 255 | 'format' => self::get_format_from_modifiers( $exploded, false ), |
| 256 | - 'human' => in_array( 'human', $exploded ), // {date_created:human} |
|
| 256 | + 'human' => in_array( 'human', $exploded ), // {date_created:human} |
|
| 257 | 257 | 'diff' => in_array( 'diff', $exploded ), // {date_created:diff} |
| 258 | 258 | 'raw' => in_array( 'raw', $exploded ), // {date_created:raw} |
| 259 | 259 | 'timestamp' => in_array( 'timestamp', $exploded ), // {date_created:timestamp} |
@@ -7,133 +7,133 @@ |
||
| 7 | 7 | |
| 8 | 8 | class GravityView_GFFormsModel extends GFFormsModel { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * Given information provided in an entry, get array of media IDs |
|
| 12 | - * |
|
| 13 | - * This is necessary because GF doesn't expect to need to update post images, only to create them. |
|
| 14 | - * |
|
| 15 | - * @see GFFormsModel::create_post() |
|
| 16 | - * |
|
| 17 | - * @since 1.17 |
|
| 18 | - * |
|
| 19 | - * @param array $form Gravity Forms form array |
|
| 20 | - * @param array $entry Gravity Forms entry array |
|
| 21 | - * |
|
| 22 | - * @return array Array of "Field ID" => "Media IDs" |
|
| 23 | - */ |
|
| 24 | - public static function get_post_field_images( $form, $entry ) { |
|
| 25 | - |
|
| 26 | - $post_data = self::get_post_fields( $form, $entry ); |
|
| 27 | - |
|
| 28 | - $media = get_attached_media( 'image', $entry['post_id'] ); |
|
| 29 | - |
|
| 30 | - $post_images = array(); |
|
| 31 | - |
|
| 32 | - foreach ( $media as $media_item ) { |
|
| 33 | - foreach( (array) $post_data['images'] as $post_data_item ) { |
|
| 34 | - if( |
|
| 35 | - rgar( $post_data_item, 'title' ) === $media_item->post_title && |
|
| 36 | - rgar( $post_data_item, 'description' ) === $media_item->post_content && |
|
| 37 | - rgar( $post_data_item, 'caption' ) === $media_item->post_excerpt |
|
| 38 | - ) { |
|
| 39 | - $post_images["{$post_data_item['field_id']}"] = $media_item->ID; |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - return $post_images; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Alias of GFFormsModel::get_post_fields(); just making it public |
|
| 49 | - * |
|
| 50 | - * @see GFFormsModel::get_post_fields() |
|
| 51 | - * |
|
| 52 | - * @since 1.17 |
|
| 53 | - * |
|
| 54 | - * @param array $form Gravity Forms form array |
|
| 55 | - * @param array $entry Gravity Forms entry array |
|
| 56 | - * |
|
| 57 | - * @return array |
|
| 58 | - */ |
|
| 59 | - public static function get_post_fields( $form, $entry ) { |
|
| 60 | - |
|
| 61 | - $reflection = new ReflectionMethod( 'GFFormsModel', 'get_post_fields' ); |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * If the method changes to public, use Gravity Forms' method |
|
| 65 | - * @todo: If/when the method is public, remove the unneeded copied code. |
|
| 66 | - */ |
|
| 67 | - if( $reflection->isPublic() ) { |
|
| 68 | - return parent::get_post_fields( $form, $entry ); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // It was private; let's make it public |
|
| 72 | - $reflection->setAccessible( true ); |
|
| 73 | - |
|
| 74 | - return $reflection->invoke( new GFFormsModel, $form, $entry ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Copied function from Gravity Forms plugin \GFFormsModel::copy_post_image since the method is private. |
|
| 79 | - * |
|
| 80 | - * @since 1.16.2 |
|
| 81 | - * |
|
| 82 | - * @param string $url URL of the post image to update |
|
| 83 | - * @param int $post_id ID of the post image to update |
|
| 84 | - * @return array|bool Array with `file`, `url` and `type` keys. False: failed to copy file to final directory path. |
|
| 85 | - */ |
|
| 86 | - public static function copy_post_image( $url, $post_id ) { |
|
| 87 | - |
|
| 88 | - $reflection = new ReflectionMethod( 'GFFormsModel', 'copy_post_image' ); |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * If the method changes to public, use Gravity Forms' method |
|
| 92 | - * @todo: If/when the method is public, remove the unneeded copied code. |
|
| 93 | - */ |
|
| 94 | - if( $reflection->isPublic() ) { |
|
| 95 | - return parent::copy_post_image( $url, $post_id ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // It was private; let's make it public |
|
| 99 | - $reflection->setAccessible( true ); |
|
| 100 | - |
|
| 101 | - return $reflection->invoke( new GFFormsModel, $url, $post_id ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Copied function from Gravity Forms plugin \GFFormsModel::media_handle_upload since the method is private. |
|
| 106 | - * |
|
| 107 | - * Note: The method became public in GF 1.9.17.7 |
|
| 108 | - * |
|
| 109 | - * @see GFFormsModel::media_handle_upload |
|
| 110 | - * @see GravityView_Edit_Entry_Render::maybe_update_post_fields |
|
| 111 | - * |
|
| 112 | - * @uses copy_post_image |
|
| 113 | - * @uses wp_insert_attachment |
|
| 114 | - * @uses wp_update_attachment_metadata |
|
| 115 | - * |
|
| 116 | - * @param string $url URL of the post image to update |
|
| 117 | - * @param int $post_id ID of the post image to update |
|
| 118 | - * @param array $post_data Array of data for the eventual attachment post type that is created using {@see wp_insert_attachment}. Supports `post_mime_type`, `guid`, `post_parent`, `post_title`, `post_content` keys. |
|
| 119 | - * @return bool|int ID of attachment Post created. Returns false if file not created by copy_post_image |
|
| 120 | - */ |
|
| 121 | - public static function media_handle_upload( $url, $post_id, $post_data = array() ) { |
|
| 122 | - |
|
| 123 | - $reflection = new ReflectionMethod( 'GFFormsModel', 'media_handle_upload' ); |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * If the method changes to public, use Gravity Forms' method |
|
| 127 | - * @todo: If/when the method is public, remove the unneeded copied code. |
|
| 128 | - */ |
|
| 129 | - if( $reflection->isPublic() ) { |
|
| 130 | - return parent::media_handle_upload( $url, $post_id, $post_data ); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // It was private; let's make it public |
|
| 134 | - $reflection->setAccessible( true ); |
|
| 135 | - |
|
| 136 | - return $reflection->invoke( new GFFormsModel, $url, $post_id, $post_data ); |
|
| 137 | - } |
|
| 10 | + /** |
|
| 11 | + * Given information provided in an entry, get array of media IDs |
|
| 12 | + * |
|
| 13 | + * This is necessary because GF doesn't expect to need to update post images, only to create them. |
|
| 14 | + * |
|
| 15 | + * @see GFFormsModel::create_post() |
|
| 16 | + * |
|
| 17 | + * @since 1.17 |
|
| 18 | + * |
|
| 19 | + * @param array $form Gravity Forms form array |
|
| 20 | + * @param array $entry Gravity Forms entry array |
|
| 21 | + * |
|
| 22 | + * @return array Array of "Field ID" => "Media IDs" |
|
| 23 | + */ |
|
| 24 | + public static function get_post_field_images( $form, $entry ) { |
|
| 25 | + |
|
| 26 | + $post_data = self::get_post_fields( $form, $entry ); |
|
| 27 | + |
|
| 28 | + $media = get_attached_media( 'image', $entry['post_id'] ); |
|
| 29 | + |
|
| 30 | + $post_images = array(); |
|
| 31 | + |
|
| 32 | + foreach ( $media as $media_item ) { |
|
| 33 | + foreach( (array) $post_data['images'] as $post_data_item ) { |
|
| 34 | + if( |
|
| 35 | + rgar( $post_data_item, 'title' ) === $media_item->post_title && |
|
| 36 | + rgar( $post_data_item, 'description' ) === $media_item->post_content && |
|
| 37 | + rgar( $post_data_item, 'caption' ) === $media_item->post_excerpt |
|
| 38 | + ) { |
|
| 39 | + $post_images["{$post_data_item['field_id']}"] = $media_item->ID; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + return $post_images; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Alias of GFFormsModel::get_post_fields(); just making it public |
|
| 49 | + * |
|
| 50 | + * @see GFFormsModel::get_post_fields() |
|
| 51 | + * |
|
| 52 | + * @since 1.17 |
|
| 53 | + * |
|
| 54 | + * @param array $form Gravity Forms form array |
|
| 55 | + * @param array $entry Gravity Forms entry array |
|
| 56 | + * |
|
| 57 | + * @return array |
|
| 58 | + */ |
|
| 59 | + public static function get_post_fields( $form, $entry ) { |
|
| 60 | + |
|
| 61 | + $reflection = new ReflectionMethod( 'GFFormsModel', 'get_post_fields' ); |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * If the method changes to public, use Gravity Forms' method |
|
| 65 | + * @todo: If/when the method is public, remove the unneeded copied code. |
|
| 66 | + */ |
|
| 67 | + if( $reflection->isPublic() ) { |
|
| 68 | + return parent::get_post_fields( $form, $entry ); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // It was private; let's make it public |
|
| 72 | + $reflection->setAccessible( true ); |
|
| 73 | + |
|
| 74 | + return $reflection->invoke( new GFFormsModel, $form, $entry ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Copied function from Gravity Forms plugin \GFFormsModel::copy_post_image since the method is private. |
|
| 79 | + * |
|
| 80 | + * @since 1.16.2 |
|
| 81 | + * |
|
| 82 | + * @param string $url URL of the post image to update |
|
| 83 | + * @param int $post_id ID of the post image to update |
|
| 84 | + * @return array|bool Array with `file`, `url` and `type` keys. False: failed to copy file to final directory path. |
|
| 85 | + */ |
|
| 86 | + public static function copy_post_image( $url, $post_id ) { |
|
| 87 | + |
|
| 88 | + $reflection = new ReflectionMethod( 'GFFormsModel', 'copy_post_image' ); |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * If the method changes to public, use Gravity Forms' method |
|
| 92 | + * @todo: If/when the method is public, remove the unneeded copied code. |
|
| 93 | + */ |
|
| 94 | + if( $reflection->isPublic() ) { |
|
| 95 | + return parent::copy_post_image( $url, $post_id ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // It was private; let's make it public |
|
| 99 | + $reflection->setAccessible( true ); |
|
| 100 | + |
|
| 101 | + return $reflection->invoke( new GFFormsModel, $url, $post_id ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Copied function from Gravity Forms plugin \GFFormsModel::media_handle_upload since the method is private. |
|
| 106 | + * |
|
| 107 | + * Note: The method became public in GF 1.9.17.7 |
|
| 108 | + * |
|
| 109 | + * @see GFFormsModel::media_handle_upload |
|
| 110 | + * @see GravityView_Edit_Entry_Render::maybe_update_post_fields |
|
| 111 | + * |
|
| 112 | + * @uses copy_post_image |
|
| 113 | + * @uses wp_insert_attachment |
|
| 114 | + * @uses wp_update_attachment_metadata |
|
| 115 | + * |
|
| 116 | + * @param string $url URL of the post image to update |
|
| 117 | + * @param int $post_id ID of the post image to update |
|
| 118 | + * @param array $post_data Array of data for the eventual attachment post type that is created using {@see wp_insert_attachment}. Supports `post_mime_type`, `guid`, `post_parent`, `post_title`, `post_content` keys. |
|
| 119 | + * @return bool|int ID of attachment Post created. Returns false if file not created by copy_post_image |
|
| 120 | + */ |
|
| 121 | + public static function media_handle_upload( $url, $post_id, $post_data = array() ) { |
|
| 122 | + |
|
| 123 | + $reflection = new ReflectionMethod( 'GFFormsModel', 'media_handle_upload' ); |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * If the method changes to public, use Gravity Forms' method |
|
| 127 | + * @todo: If/when the method is public, remove the unneeded copied code. |
|
| 128 | + */ |
|
| 129 | + if( $reflection->isPublic() ) { |
|
| 130 | + return parent::media_handle_upload( $url, $post_id, $post_data ); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // It was private; let's make it public |
|
| 134 | + $reflection->setAccessible( true ); |
|
| 135 | + |
|
| 136 | + return $reflection->invoke( new GFFormsModel, $url, $post_id, $post_data ); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | 139 | } |
| 140 | 140 | \ No newline at end of file |
@@ -146,20 +146,20 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | if( !empty( $field['custom_class'] ) ) { |
| 148 | 148 | |
| 149 | - $custom_class = $field['custom_class']; |
|
| 149 | + $custom_class = $field['custom_class']; |
|
| 150 | 150 | |
| 151 | - if( !empty( $entry ) ) { |
|
| 151 | + if( !empty( $entry ) ) { |
|
| 152 | 152 | |
| 153 | - // We want the merge tag to be formatted as a class. The merge tag may be |
|
| 154 | - // replaced by a multiple-word value that should be output as a single class. |
|
| 155 | - // "Office Manager" will be formatted as `.OfficeManager`, not `.Office` and `.Manager` |
|
| 156 | - add_filter('gform_merge_tag_filter', 'sanitize_html_class'); |
|
| 153 | + // We want the merge tag to be formatted as a class. The merge tag may be |
|
| 154 | + // replaced by a multiple-word value that should be output as a single class. |
|
| 155 | + // "Office Manager" will be formatted as `.OfficeManager`, not `.Office` and `.Manager` |
|
| 156 | + add_filter('gform_merge_tag_filter', 'sanitize_html_class'); |
|
| 157 | 157 | |
| 158 | - $custom_class = self::replace_variables( $custom_class, $form, $entry); |
|
| 158 | + $custom_class = self::replace_variables( $custom_class, $form, $entry); |
|
| 159 | 159 | |
| 160 | - // And then we want life to return to normal |
|
| 161 | - remove_filter('gform_merge_tag_filter', 'sanitize_html_class'); |
|
| 162 | - } |
|
| 160 | + // And then we want life to return to normal |
|
| 161 | + remove_filter('gform_merge_tag_filter', 'sanitize_html_class'); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | 164 | // And now we want the spaces to be handled nicely. |
| 165 | 165 | $classes[] = gravityview_sanitize_html_class( $custom_class ); |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | 'format' => $format, |
| 278 | 278 | 'entry' => $entry, |
| 279 | 279 | 'field_type' => $field_type, /** {@since 1.6} */ |
| 280 | - 'field_path' => $field_path, /** {@since 1.16} */ |
|
| 280 | + 'field_path' => $field_path, /** {@since 1.16} */ |
|
| 281 | 281 | )); |
| 282 | 282 | |
| 283 | 283 | if( ! empty( $field_path ) ) { |
@@ -594,32 +594,32 @@ discard block |
||
| 594 | 594 | return sanitize_title( $slug ); |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | - /** |
|
| 598 | - * If using the entry custom slug feature, make sure the new entries have the custom slug created and saved as meta |
|
| 599 | - * |
|
| 600 | - * Triggered by add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 ); |
|
| 601 | - * |
|
| 602 | - * @param $entry array Gravity Forms entry object |
|
| 603 | - * @param $form array Gravity Forms form object |
|
| 604 | - */ |
|
| 605 | - public static function entry_create_custom_slug( $entry, $form ) { |
|
| 606 | - /** |
|
| 607 | - * @filter `gravityview_custom_entry_slug` On entry creation, check if we are using the custom entry slug feature and update the meta |
|
| 608 | - * @param boolean $custom Should we process the custom entry slug? |
|
| 609 | - */ |
|
| 610 | - $custom = apply_filters( 'gravityview_custom_entry_slug', false ); |
|
| 611 | - if( $custom ) { |
|
| 612 | - // create the gravityview_unique_id and save it |
|
| 597 | + /** |
|
| 598 | + * If using the entry custom slug feature, make sure the new entries have the custom slug created and saved as meta |
|
| 599 | + * |
|
| 600 | + * Triggered by add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 ); |
|
| 601 | + * |
|
| 602 | + * @param $entry array Gravity Forms entry object |
|
| 603 | + * @param $form array Gravity Forms form object |
|
| 604 | + */ |
|
| 605 | + public static function entry_create_custom_slug( $entry, $form ) { |
|
| 606 | + /** |
|
| 607 | + * @filter `gravityview_custom_entry_slug` On entry creation, check if we are using the custom entry slug feature and update the meta |
|
| 608 | + * @param boolean $custom Should we process the custom entry slug? |
|
| 609 | + */ |
|
| 610 | + $custom = apply_filters( 'gravityview_custom_entry_slug', false ); |
|
| 611 | + if( $custom ) { |
|
| 612 | + // create the gravityview_unique_id and save it |
|
| 613 | 613 | |
| 614 | - // Get the entry hash |
|
| 615 | - $hash = self::get_custom_entry_slug( $entry['id'], $entry ); |
|
| 614 | + // Get the entry hash |
|
| 615 | + $hash = self::get_custom_entry_slug( $entry['id'], $entry ); |
|
| 616 | 616 | |
| 617 | - do_action( 'gravityview_log_debug', __METHOD__ . ' - Setting hash for entry "'.$entry['id'].'": ' . $hash ); |
|
| 617 | + do_action( 'gravityview_log_debug', __METHOD__ . ' - Setting hash for entry "'.$entry['id'].'": ' . $hash ); |
|
| 618 | 618 | |
| 619 | - gform_update_meta( $entry['id'], 'gravityview_unique_id', $hash, rgar( $entry, 'form_id' ) ); |
|
| 619 | + gform_update_meta( $entry['id'], 'gravityview_unique_id', $hash, rgar( $entry, 'form_id' ) ); |
|
| 620 | 620 | |
| 621 | - } |
|
| 622 | - } |
|
| 621 | + } |
|
| 622 | + } |
|
| 623 | 623 | |
| 624 | 624 | |
| 625 | 625 | |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | |
| 896 | 896 | // If there was an error, continue to the next term. |
| 897 | 897 | if ( is_wp_error( $term_link ) ) { |
| 898 | - continue; |
|
| 898 | + continue; |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | $output[] = gravityview_get_link( $term_link, esc_html( $term->name ) ); |
@@ -5,220 +5,220 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class GravityView_Change_Entry_Creator { |
| 7 | 7 | |
| 8 | - function __construct() { |
|
| 9 | - |
|
| 10 | - /** |
|
| 11 | - * @since 1.5.1 |
|
| 12 | - */ |
|
| 13 | - add_action('gform_user_registered', array( $this, 'assign_new_user_to_lead'), 10, 4 ); |
|
| 14 | - |
|
| 15 | - // ONLY ADMIN FROM HERE ON. |
|
| 16 | - if( !is_admin() ) { return; } |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * @filter `gravityview_disable_change_entry_creator` Disable the Change Entry Creator functionality |
|
| 20 | - * @since 1.7.4 |
|
| 21 | - * @param boolean $disable Disable the Change Entry Creator functionality. Default: false. |
|
| 22 | - */ |
|
| 23 | - if( apply_filters('gravityview_disable_change_entry_creator', false ) ) { |
|
| 24 | - return; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Use `init` to fix bbPress warning |
|
| 29 | - * @see https://bbpress.trac.wordpress.org/ticket/2309 |
|
| 30 | - */ |
|
| 31 | - add_action('init', array( $this, 'load'), 100 ); |
|
| 32 | - |
|
| 33 | - add_action('plugins_loaded', array( $this, 'prevent_conflicts') ); |
|
| 8 | + function __construct() { |
|
| 9 | + |
|
| 10 | + /** |
|
| 11 | + * @since 1.5.1 |
|
| 12 | + */ |
|
| 13 | + add_action('gform_user_registered', array( $this, 'assign_new_user_to_lead'), 10, 4 ); |
|
| 14 | + |
|
| 15 | + // ONLY ADMIN FROM HERE ON. |
|
| 16 | + if( !is_admin() ) { return; } |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * @filter `gravityview_disable_change_entry_creator` Disable the Change Entry Creator functionality |
|
| 20 | + * @since 1.7.4 |
|
| 21 | + * @param boolean $disable Disable the Change Entry Creator functionality. Default: false. |
|
| 22 | + */ |
|
| 23 | + if( apply_filters('gravityview_disable_change_entry_creator', false ) ) { |
|
| 24 | + return; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Use `init` to fix bbPress warning |
|
| 29 | + * @see https://bbpress.trac.wordpress.org/ticket/2309 |
|
| 30 | + */ |
|
| 31 | + add_action('init', array( $this, 'load'), 100 ); |
|
| 32 | + |
|
| 33 | + add_action('plugins_loaded', array( $this, 'prevent_conflicts') ); |
|
| 34 | 34 | |
| 35 | - } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * When an user is created using the User Registration add-on, assign the entry to them |
|
| 39 | - * |
|
| 40 | - * @since 1.5.1 |
|
| 41 | - * @uses RGFormsModel::update_lead_property() Modify the entry `created_by` field |
|
| 42 | - * @param int $user_id WordPress User ID |
|
| 43 | - * @param array $config User registration feed configuration |
|
| 44 | - * @param array $entry GF Entry array |
|
| 45 | - * @param string $password User password |
|
| 46 | - * @return void |
|
| 47 | - */ |
|
| 48 | - function assign_new_user_to_lead( $user_id, $config, $entry = array(), $password = '' ) { |
|
| 37 | + /** |
|
| 38 | + * When an user is created using the User Registration add-on, assign the entry to them |
|
| 39 | + * |
|
| 40 | + * @since 1.5.1 |
|
| 41 | + * @uses RGFormsModel::update_lead_property() Modify the entry `created_by` field |
|
| 42 | + * @param int $user_id WordPress User ID |
|
| 43 | + * @param array $config User registration feed configuration |
|
| 44 | + * @param array $entry GF Entry array |
|
| 45 | + * @param string $password User password |
|
| 46 | + * @return void |
|
| 47 | + */ |
|
| 48 | + function assign_new_user_to_lead( $user_id, $config, $entry = array(), $password = '' ) { |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Disable assigning the new user to the entry by returning false. |
|
| 52 | - * @param int $user_id WordPress User ID |
|
| 53 | - * @param array $config User registration feed configuration |
|
| 54 | - * @param array $entry GF Entry array |
|
| 55 | - */ |
|
| 56 | - $assign_to_lead = apply_filters( 'gravityview_assign_new_user_to_entry', true, $user_id, $config, $entry ); |
|
| 57 | - |
|
| 58 | - // If filter returns false, do not process |
|
| 59 | - if( empty( $assign_to_lead ) ) { |
|
| 60 | - return; |
|
| 61 | - } |
|
| 50 | + /** |
|
| 51 | + * Disable assigning the new user to the entry by returning false. |
|
| 52 | + * @param int $user_id WordPress User ID |
|
| 53 | + * @param array $config User registration feed configuration |
|
| 54 | + * @param array $entry GF Entry array |
|
| 55 | + */ |
|
| 56 | + $assign_to_lead = apply_filters( 'gravityview_assign_new_user_to_entry', true, $user_id, $config, $entry ); |
|
| 57 | + |
|
| 58 | + // If filter returns false, do not process |
|
| 59 | + if( empty( $assign_to_lead ) ) { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - // Update the entry. The `false` prevents checking Akismet; `true` disables the user updated hook from firing |
|
| 64 | - $result = RGFormsModel::update_lead_property( $entry['id'], 'created_by', $user_id, false, true ); |
|
| 63 | + // Update the entry. The `false` prevents checking Akismet; `true` disables the user updated hook from firing |
|
| 64 | + $result = RGFormsModel::update_lead_property( $entry['id'], 'created_by', $user_id, false, true ); |
|
| 65 | 65 | |
| 66 | - if( empty( $result ) ) { |
|
| 67 | - $status = __('Error', 'gravityview'); |
|
| 68 | - } else { |
|
| 69 | - $status = __('Success', 'gravityview'); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $note = sprintf( _x('%s: Assigned User ID #%d as the entry creator.', 'First parameter: Success or error of the action. Second: User ID number', 'gravityview'), $status, $user_id ); |
|
| 66 | + if( empty( $result ) ) { |
|
| 67 | + $status = __('Error', 'gravityview'); |
|
| 68 | + } else { |
|
| 69 | + $status = __('Success', 'gravityview'); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $note = sprintf( _x('%s: Assigned User ID #%d as the entry creator.', 'First parameter: Success or error of the action. Second: User ID number', 'gravityview'), $status, $user_id ); |
|
| 73 | 73 | |
| 74 | - do_action( 'gravityview_log_debug', 'GravityView_Change_Entry_Creator[assign_new_user_to_lead] - '.$note ); |
|
| 74 | + do_action( 'gravityview_log_debug', 'GravityView_Change_Entry_Creator[assign_new_user_to_lead] - '.$note ); |
|
| 75 | 75 | |
| 76 | - GravityView_Entry_Notes::add_note( $entry['id'], -1, 'GravityView', $note, 'gravityview' ); |
|
| 76 | + GravityView_Entry_Notes::add_note( $entry['id'], -1, 'GravityView', $note, 'gravityview' ); |
|
| 77 | 77 | |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Disable previous functionality; use this one as the canonical. |
|
| 82 | - * @return void |
|
| 83 | - */ |
|
| 84 | - function prevent_conflicts() { |
|
| 80 | + /** |
|
| 81 | + * Disable previous functionality; use this one as the canonical. |
|
| 82 | + * @return void |
|
| 83 | + */ |
|
| 84 | + function prevent_conflicts() { |
|
| 85 | 85 | |
| 86 | - // Plugin that was provided here: |
|
| 87 | - // @link https://gravityview.co/support/documentation/201991205/ |
|
| 88 | - remove_action("gform_entry_info", 'gravityview_change_entry_creator_form', 10 ); |
|
| 89 | - remove_action("gform_after_update_entry", 'gravityview_update_entry_creator', 10 ); |
|
| 86 | + // Plugin that was provided here: |
|
| 87 | + // @link https://gravityview.co/support/documentation/201991205/ |
|
| 88 | + remove_action("gform_entry_info", 'gravityview_change_entry_creator_form', 10 ); |
|
| 89 | + remove_action("gform_after_update_entry", 'gravityview_update_entry_creator', 10 ); |
|
| 90 | 90 | |
| 91 | - // Disable for Gravity Forms Add-ons 3.6.2 and lower |
|
| 92 | - if( class_exists( 'KWS_GF_Change_Lead_Creator' ) ) { |
|
| 91 | + // Disable for Gravity Forms Add-ons 3.6.2 and lower |
|
| 92 | + if( class_exists( 'KWS_GF_Change_Lead_Creator' ) ) { |
|
| 93 | 93 | |
| 94 | - $Old_Lead_Creator = new KWS_GF_Change_Lead_Creator; |
|
| 94 | + $Old_Lead_Creator = new KWS_GF_Change_Lead_Creator; |
|
| 95 | 95 | |
| 96 | - // Now, no validation is required in the methods; let's hook in. |
|
| 97 | - remove_action('admin_init', array( $Old_Lead_Creator, 'set_screen_mode' ) ); |
|
| 96 | + // Now, no validation is required in the methods; let's hook in. |
|
| 97 | + remove_action('admin_init', array( $Old_Lead_Creator, 'set_screen_mode' ) ); |
|
| 98 | 98 | |
| 99 | - remove_action("gform_entry_info", array( $Old_Lead_Creator, 'add_select' ), 10 ); |
|
| 99 | + remove_action("gform_entry_info", array( $Old_Lead_Creator, 'add_select' ), 10 ); |
|
| 100 | 100 | |
| 101 | - remove_action("gform_after_update_entry", array( $Old_Lead_Creator, 'update_entry_creator' ), 10 ); |
|
| 102 | - } |
|
| 101 | + remove_action("gform_after_update_entry", array( $Old_Lead_Creator, 'update_entry_creator' ), 10 ); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * @since 3.6.3 |
|
| 108 | - * @return void |
|
| 109 | - */ |
|
| 110 | - function load() { |
|
| 106 | + /** |
|
| 107 | + * @since 3.6.3 |
|
| 108 | + * @return void |
|
| 109 | + */ |
|
| 110 | + function load() { |
|
| 111 | 111 | |
| 112 | - // Does GF exist? |
|
| 113 | - if( !class_exists('GFCommon') ) { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 112 | + // Does GF exist? |
|
| 113 | + if( !class_exists('GFCommon') ) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - // Can the user edit entries? |
|
| 118 | - if( ! GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_entries' ) ) ) { |
|
| 119 | - return; |
|
| 120 | - } |
|
| 117 | + // Can the user edit entries? |
|
| 118 | + if( ! GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_entries' ) ) ) { |
|
| 119 | + return; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - // If screen mode isn't set, then we're in the wrong place. |
|
| 123 | - if( empty( $_REQUEST['screen_mode'] ) ) { |
|
| 124 | - return; |
|
| 125 | - } |
|
| 122 | + // If screen mode isn't set, then we're in the wrong place. |
|
| 123 | + if( empty( $_REQUEST['screen_mode'] ) ) { |
|
| 124 | + return; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - // Now, no validation is required in the methods; let's hook in. |
|
| 128 | - add_action('admin_init', array( &$this, 'set_screen_mode' ) ); |
|
| 127 | + // Now, no validation is required in the methods; let's hook in. |
|
| 128 | + add_action('admin_init', array( &$this, 'set_screen_mode' ) ); |
|
| 129 | 129 | |
| 130 | - add_action("gform_entry_info", array( &$this, 'add_select' ), 10, 2); |
|
| 130 | + add_action("gform_entry_info", array( &$this, 'add_select' ), 10, 2); |
|
| 131 | 131 | |
| 132 | - add_action("gform_after_update_entry", array( &$this, 'update_entry_creator' ), 10, 2); |
|
| 132 | + add_action("gform_after_update_entry", array( &$this, 'update_entry_creator' ), 10, 2); |
|
| 133 | 133 | |
| 134 | - } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Allows for edit links to work with a link instead of a form (GET instead of POST) |
|
| 138 | - * @return void |
|
| 139 | - */ |
|
| 140 | - function set_screen_mode() { |
|
| 136 | + /** |
|
| 137 | + * Allows for edit links to work with a link instead of a form (GET instead of POST) |
|
| 138 | + * @return void |
|
| 139 | + */ |
|
| 140 | + function set_screen_mode() { |
|
| 141 | 141 | |
| 142 | - // If $_GET['screen_mode'] is set to edit, set $_POST value |
|
| 143 | - if( rgget('screen_mode') === 'edit' ) { |
|
| 144 | - $_POST["screen_mode"] = 'edit'; |
|
| 145 | - } |
|
| 142 | + // If $_GET['screen_mode'] is set to edit, set $_POST value |
|
| 143 | + if( rgget('screen_mode') === 'edit' ) { |
|
| 144 | + $_POST["screen_mode"] = 'edit'; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * When the entry creator is changed, add a note to the entry |
|
| 151 | - * @param array $form GF entry array |
|
| 152 | - * @param int $entry_id Entry ID |
|
| 153 | - * @return void |
|
| 154 | - */ |
|
| 155 | - function update_entry_creator($form, $entry_id) { |
|
| 156 | - global $current_user; |
|
| 149 | + /** |
|
| 150 | + * When the entry creator is changed, add a note to the entry |
|
| 151 | + * @param array $form GF entry array |
|
| 152 | + * @param int $entry_id Entry ID |
|
| 153 | + * @return void |
|
| 154 | + */ |
|
| 155 | + function update_entry_creator($form, $entry_id) { |
|
| 156 | + global $current_user; |
|
| 157 | 157 | |
| 158 | - // Update the entry |
|
| 159 | - $created_by = absint( rgpost('created_by') ); |
|
| 158 | + // Update the entry |
|
| 159 | + $created_by = absint( rgpost('created_by') ); |
|
| 160 | 160 | |
| 161 | - RGFormsModel::update_lead_property( $entry_id, 'created_by', $created_by ); |
|
| 161 | + RGFormsModel::update_lead_property( $entry_id, 'created_by', $created_by ); |
|
| 162 | 162 | |
| 163 | - // If the creator has changed, let's add a note about who it used to be. |
|
| 164 | - $originally_created_by = rgpost('originally_created_by'); |
|
| 163 | + // If the creator has changed, let's add a note about who it used to be. |
|
| 164 | + $originally_created_by = rgpost('originally_created_by'); |
|
| 165 | 165 | |
| 166 | - // If there's no owner and there didn't used to be, keep going |
|
| 167 | - if( empty( $originally_created_by ) && empty( $created_by ) ) { |
|
| 168 | - return; |
|
| 169 | - } |
|
| 166 | + // If there's no owner and there didn't used to be, keep going |
|
| 167 | + if( empty( $originally_created_by ) && empty( $created_by ) ) { |
|
| 168 | + return; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - // If the values have changed |
|
| 172 | - if( absint( $originally_created_by ) !== absint( $created_by ) ) { |
|
| 171 | + // If the values have changed |
|
| 172 | + if( absint( $originally_created_by ) !== absint( $created_by ) ) { |
|
| 173 | 173 | |
| 174 | - $user_data = get_userdata($current_user->ID); |
|
| 174 | + $user_data = get_userdata($current_user->ID); |
|
| 175 | 175 | |
| 176 | - $user_format = _x('%s (ID #%d)', 'The name and the ID of users who initiated changes to entry ownership', 'gravityview'); |
|
| 176 | + $user_format = _x('%s (ID #%d)', 'The name and the ID of users who initiated changes to entry ownership', 'gravityview'); |
|
| 177 | 177 | |
| 178 | - $original_name = $created_by_name = esc_attr_x( 'No User', 'To show that the entry was unassigned from an actual user to no user.', 'gravityview'); |
|
| 178 | + $original_name = $created_by_name = esc_attr_x( 'No User', 'To show that the entry was unassigned from an actual user to no user.', 'gravityview'); |
|
| 179 | 179 | |
| 180 | - if( !empty( $originally_created_by ) ) { |
|
| 181 | - $originally_created_by_user_data = get_userdata($originally_created_by); |
|
| 182 | - $original_name = sprintf( $user_format, $originally_created_by_user_data->display_name, $originally_created_by_user_data->ID ); |
|
| 183 | - } |
|
| 180 | + if( !empty( $originally_created_by ) ) { |
|
| 181 | + $originally_created_by_user_data = get_userdata($originally_created_by); |
|
| 182 | + $original_name = sprintf( $user_format, $originally_created_by_user_data->display_name, $originally_created_by_user_data->ID ); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - if( !empty( $created_by ) ) { |
|
| 186 | - $created_by_user_data = get_userdata($created_by); |
|
| 187 | - $created_by_name = sprintf( $user_format, $created_by_user_data->display_name, $created_by_user_data->ID ); |
|
| 188 | - } |
|
| 185 | + if( !empty( $created_by ) ) { |
|
| 186 | + $created_by_user_data = get_userdata($created_by); |
|
| 187 | + $created_by_name = sprintf( $user_format, $created_by_user_data->display_name, $created_by_user_data->ID ); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __('Changed entry creator from %s to %s', 'gravityview'), $original_name, $created_by_name ), 'note' ); |
|
| 191 | - } |
|
| 190 | + GravityView_Entry_Notes::add_note( $entry_id, $current_user->ID, $user_data->display_name, sprintf( __('Changed entry creator from %s to %s', 'gravityview'), $original_name, $created_by_name ), 'note' ); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Output the select to change the entry creator |
|
| 197 | - * @param int $form_id GF Form ID |
|
| 198 | - * @param array $entry GF entry array |
|
| 199 | - * @return void |
|
| 200 | - */ |
|
| 201 | - function add_select($form_id, $entry ) { |
|
| 195 | + /** |
|
| 196 | + * Output the select to change the entry creator |
|
| 197 | + * @param int $form_id GF Form ID |
|
| 198 | + * @param array $entry GF entry array |
|
| 199 | + * @return void |
|
| 200 | + */ |
|
| 201 | + function add_select($form_id, $entry ) { |
|
| 202 | 202 | |
| 203 | - if( rgpost('screen_mode') !== 'edit' ) { |
|
| 204 | - return; |
|
| 205 | - } |
|
| 203 | + if( rgpost('screen_mode') !== 'edit' ) { |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - $users = GVCommon::get_users( 'change_entry_creator' ); |
|
| 207 | + $users = GVCommon::get_users( 'change_entry_creator' ); |
|
| 208 | 208 | |
| 209 | - $output = '<label for="change_created_by">'; |
|
| 210 | - $output .= esc_html__('Change Entry Creator:', 'gravityview'); |
|
| 211 | - $output .= '</label> |
|
| 209 | + $output = '<label for="change_created_by">'; |
|
| 210 | + $output .= esc_html__('Change Entry Creator:', 'gravityview'); |
|
| 211 | + $output .= '</label> |
|
| 212 | 212 | <select name="created_by" id="change_created_by" class="widefat">'; |
| 213 | - $output .= '<option value=""> — '.esc_attr_x( 'No User', 'No user assigned to the entry', 'gravityview').' — </option>'; |
|
| 214 | - foreach($users as $user) { |
|
| 215 | - $output .= '<option value="'. $user->ID .'"'. selected( $entry['created_by'], $user->ID, false ).'>'.esc_attr( $user->display_name.' ('.$user->user_nicename.')' ).'</option>'; |
|
| 216 | - } |
|
| 217 | - $output .= '</select>'; |
|
| 218 | - $output .= '<input name="originally_created_by" value="'.esc_attr( $entry['created_by'] ).'" type="hidden" />'; |
|
| 219 | - echo $output; |
|
| 220 | - |
|
| 221 | - } |
|
| 213 | + $output .= '<option value=""> — '.esc_attr_x( 'No User', 'No user assigned to the entry', 'gravityview').' — </option>'; |
|
| 214 | + foreach($users as $user) { |
|
| 215 | + $output .= '<option value="'. $user->ID .'"'. selected( $entry['created_by'], $user->ID, false ).'>'.esc_attr( $user->display_name.' ('.$user->user_nicename.')' ).'</option>'; |
|
| 216 | + } |
|
| 217 | + $output .= '</select>'; |
|
| 218 | + $output .= '<input name="originally_created_by" value="'.esc_attr( $entry['created_by'] ).'" type="hidden" />'; |
|
| 219 | + echo $output; |
|
| 220 | + |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | 223 | } |
| 224 | 224 | |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * If the user doesn't have the `gravityview_support_port` capability, returns false; then |
| 223 | 223 | * If global setting is "hide", returns false; then |
| 224 | - * If user preference is not set, return global setting; then |
|
| 225 | - * If user preference is set, return that setting. |
|
| 224 | + * If user preference is not set, return global setting; then |
|
| 225 | + * If user preference is set, return that setting. |
|
| 226 | 226 | * |
| 227 | 227 | * @since 1.15 |
| 228 | - * @since 1.17.5 Changed behavior to respect global setting |
|
| 228 | + * @since 1.17.5 Changed behavior to respect global setting |
|
| 229 | 229 | * |
| 230 | 230 | * @param int $user Optional. ID of the user to check, defaults to 0 for current user. |
| 231 | 231 | * |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | $global_setting = GravityView_Settings::getSetting( 'support_port' ); |
| 241 | 241 | |
| 242 | 242 | if ( empty( $global_setting ) ) { |
| 243 | - return false; |
|
| 243 | + return false; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | // Get the per-user Support Port setting |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | * Modifies the output of profile.php to add GravityView Support preference |
| 277 | 277 | * |
| 278 | 278 | * @since 1.15 |
| 279 | - * @since 1.17.5 Only show if global setting is active |
|
| 279 | + * @since 1.17.5 Only show if global setting is active |
|
| 280 | 280 | * |
| 281 | 281 | * @param WP_User $user Current user info |
| 282 | 282 | * |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | $global_setting = GravityView_Settings::getSetting( 'support_port' ); |
| 288 | 288 | |
| 289 | 289 | if ( empty( $global_setting ) ) { |
| 290 | - return; |
|
| 290 | + return; |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |