@@ -18,83 +18,83 @@ 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 | $this->load_components( 'locking' ); |
| 44 | 44 | |
| 45 | - $this->load_components( 'render' ); |
|
| 45 | + $this->load_components( 'render' ); |
|
| 46 | 46 | |
| 47 | - // If GF User Registration Add-on exists |
|
| 48 | - $this->load_components( 'user-registration' ); |
|
| 47 | + // If GF User Registration Add-on exists |
|
| 48 | + $this->load_components( 'user-registration' ); |
|
| 49 | 49 | |
| 50 | - $this->add_hooks(); |
|
| 50 | + $this->add_hooks(); |
|
| 51 | 51 | |
| 52 | 52 | // Process hooks for addons that may or may not be present |
| 53 | 53 | $this->addon_specific_hooks(); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
| 57 | - static function getInstance() { |
|
| 57 | + static function getInstance() { |
|
| 58 | 58 | |
| 59 | - if( empty( self::$instance ) ) { |
|
| 60 | - self::$instance = new GravityView_Edit_Entry; |
|
| 61 | - } |
|
| 59 | + if( empty( self::$instance ) ) { |
|
| 60 | + self::$instance = new GravityView_Edit_Entry; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return self::$instance; |
|
| 64 | - } |
|
| 63 | + return self::$instance; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - private function load_components( $component ) { |
|
| 67 | + private function load_components( $component ) { |
|
| 68 | 68 | |
| 69 | - $dir = trailingslashit( self::$file ); |
|
| 69 | + $dir = trailingslashit( self::$file ); |
|
| 70 | 70 | |
| 71 | - $filename = $dir . 'class-edit-entry-' . $component . '.php'; |
|
| 72 | - $classname = 'GravityView_Edit_Entry_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $component ) ) ); |
|
| 71 | + $filename = $dir . 'class-edit-entry-' . $component . '.php'; |
|
| 72 | + $classname = 'GravityView_Edit_Entry_' . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $component ) ) ); |
|
| 73 | 73 | |
| 74 | - // Loads component and pass extension's instance so that component can |
|
| 75 | - // talk each other. |
|
| 76 | - require_once $filename; |
|
| 77 | - $this->instances[ $component ] = new $classname( $this ); |
|
| 78 | - $this->instances[ $component ]->load(); |
|
| 74 | + // Loads component and pass extension's instance so that component can |
|
| 75 | + // talk each other. |
|
| 76 | + require_once $filename; |
|
| 77 | + $this->instances[ $component ] = new $classname( $this ); |
|
| 78 | + $this->instances[ $component ]->load(); |
|
| 79 | 79 | |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - private function add_hooks() { |
|
| 82 | + private function add_hooks() { |
|
| 83 | 83 | |
| 84 | - // Add front-end access to Gravity Forms delete file action |
|
| 85 | - add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 84 | + // Add front-end access to Gravity Forms delete file action |
|
| 85 | + add_action( 'wp_ajax_nopriv_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 86 | 86 | |
| 87 | - // Make sure this hook is run for non-admins |
|
| 88 | - add_action( 'wp_ajax_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 87 | + // Make sure this hook is run for non-admins |
|
| 88 | + add_action( 'wp_ajax_rg_delete_file', array( 'GFForms', 'delete_file') ); |
|
| 89 | 89 | |
| 90 | - add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 ); |
|
| 90 | + add_filter( 'gravityview_blacklist_field_types', array( $this, 'modify_field_blacklist' ), 10, 2 ); |
|
| 91 | 91 | |
| 92 | - // add template path to check for field |
|
| 93 | - add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
|
| 92 | + // add template path to check for field |
|
| 93 | + add_filter( 'gravityview_template_paths', array( $this, 'add_template_path' ) ); |
|
| 94 | 94 | |
| 95 | 95 | add_filter( 'gravityview/field/is_visible', array( $this, 'maybe_not_visible' ), 10, 3 ); |
| 96 | 96 | |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * Trigger hooks that are normally run in the admin for Addons, but need to be triggered manually because we're not in the admin |
@@ -149,74 +149,74 @@ discard block |
||
| 149 | 149 | return false; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Include this extension templates path |
|
| 154 | - * @param array $file_paths List of template paths ordered |
|
| 155 | - */ |
|
| 156 | - public function add_template_path( $file_paths ) { |
|
| 157 | - |
|
| 158 | - // Index 100 is the default GravityView template path. |
|
| 159 | - $file_paths[ 110 ] = self::$file; |
|
| 160 | - |
|
| 161 | - return $file_paths; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * |
|
| 166 | - * Return a well formatted nonce key according to GravityView Edit Entry protocol |
|
| 167 | - * |
|
| 168 | - * @param $view_id int GravityView view id |
|
| 169 | - * @param $form_id int Gravity Forms form id |
|
| 170 | - * @param $entry_id int Gravity Forms entry id |
|
| 171 | - * @return string |
|
| 172 | - */ |
|
| 173 | - public static function get_nonce_key( $view_id, $form_id, $entry_id ) { |
|
| 174 | - return sprintf( 'edit_%d_%d_%d', $view_id, $form_id, $entry_id ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * The edit entry link creates a secure link with a nonce |
|
| 180 | - * |
|
| 181 | - * It also mimics the URL structure Gravity Forms expects to have so that |
|
| 182 | - * it formats the display of the edit form like it does in the backend, like |
|
| 183 | - * "You can edit this post from the post page" fields, for example. |
|
| 184 | - * |
|
| 185 | - * @param $entry array Gravity Forms entry object |
|
| 186 | - * @param $view_id int GravityView view id |
|
| 187 | - * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2} |
|
| 188 | - * @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/ } |
|
| 189 | - * @return string |
|
| 190 | - */ |
|
| 191 | - public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { |
|
| 192 | - |
|
| 193 | - $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id'] ); |
|
| 194 | - |
|
| 195 | - $base = gv_entry_link( $entry, $post_id ? : $view_id ); |
|
| 196 | - |
|
| 197 | - $url = add_query_arg( array( |
|
| 198 | - 'edit' => wp_create_nonce( $nonce_key ) |
|
| 199 | - ), $base ); |
|
| 200 | - |
|
| 201 | - if( $post_id ) { |
|
| 202 | - $url = add_query_arg( array( 'gvid' => $view_id ), $url ); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Allow passing params to dynamically populate entry with values |
|
| 207 | - * @since 1.9.2 |
|
| 208 | - */ |
|
| 209 | - if( !empty( $field_values ) ) { |
|
| 210 | - |
|
| 211 | - if( is_array( $field_values ) ) { |
|
| 212 | - // If already an array, no parse_str() needed |
|
| 213 | - $params = $field_values; |
|
| 214 | - } else { |
|
| 215 | - parse_str( $field_values, $params ); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $url = add_query_arg( $params, $url ); |
|
| 219 | - } |
|
| 152 | + /** |
|
| 153 | + * Include this extension templates path |
|
| 154 | + * @param array $file_paths List of template paths ordered |
|
| 155 | + */ |
|
| 156 | + public function add_template_path( $file_paths ) { |
|
| 157 | + |
|
| 158 | + // Index 100 is the default GravityView template path. |
|
| 159 | + $file_paths[ 110 ] = self::$file; |
|
| 160 | + |
|
| 161 | + return $file_paths; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * |
|
| 166 | + * Return a well formatted nonce key according to GravityView Edit Entry protocol |
|
| 167 | + * |
|
| 168 | + * @param $view_id int GravityView view id |
|
| 169 | + * @param $form_id int Gravity Forms form id |
|
| 170 | + * @param $entry_id int Gravity Forms entry id |
|
| 171 | + * @return string |
|
| 172 | + */ |
|
| 173 | + public static function get_nonce_key( $view_id, $form_id, $entry_id ) { |
|
| 174 | + return sprintf( 'edit_%d_%d_%d', $view_id, $form_id, $entry_id ); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * The edit entry link creates a secure link with a nonce |
|
| 180 | + * |
|
| 181 | + * It also mimics the URL structure Gravity Forms expects to have so that |
|
| 182 | + * it formats the display of the edit form like it does in the backend, like |
|
| 183 | + * "You can edit this post from the post page" fields, for example. |
|
| 184 | + * |
|
| 185 | + * @param $entry array Gravity Forms entry object |
|
| 186 | + * @param $view_id int GravityView view id |
|
| 187 | + * @param $post_id int GravityView Post ID where View may be embedded {@since 1.9.2} |
|
| 188 | + * @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/ } |
|
| 189 | + * @return string |
|
| 190 | + */ |
|
| 191 | + public static function get_edit_link( $entry, $view_id, $post_id = null, $field_values = '' ) { |
|
| 192 | + |
|
| 193 | + $nonce_key = self::get_nonce_key( $view_id, $entry['form_id'], $entry['id'] ); |
|
| 194 | + |
|
| 195 | + $base = gv_entry_link( $entry, $post_id ? : $view_id ); |
|
| 196 | + |
|
| 197 | + $url = add_query_arg( array( |
|
| 198 | + 'edit' => wp_create_nonce( $nonce_key ) |
|
| 199 | + ), $base ); |
|
| 200 | + |
|
| 201 | + if( $post_id ) { |
|
| 202 | + $url = add_query_arg( array( 'gvid' => $view_id ), $url ); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Allow passing params to dynamically populate entry with values |
|
| 207 | + * @since 1.9.2 |
|
| 208 | + */ |
|
| 209 | + if( !empty( $field_values ) ) { |
|
| 210 | + |
|
| 211 | + if( is_array( $field_values ) ) { |
|
| 212 | + // If already an array, no parse_str() needed |
|
| 213 | + $params = $field_values; |
|
| 214 | + } else { |
|
| 215 | + parse_str( $field_values, $params ); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $url = add_query_arg( $params, $url ); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | 221 | /** |
| 222 | 222 | * @filter `gravityview/edit/link` Filter the edit URL link. |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @param \GV\View $view The View. |
| 226 | 226 | */ |
| 227 | 227 | return apply_filters( 'gravityview/edit/link', $url, $entry, \GV\View::by_id( $view_id ) ); |
| 228 | - } |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | 230 | /** |
| 231 | 231 | * Edit mode doesn't allow certain field types. |
@@ -280,19 +280,19 @@ discard block |
||
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * checks if user has permissions to edit a specific entry |
|
| 285 | - * |
|
| 286 | - * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! |
|
| 287 | - * |
|
| 288 | - * @param array $entry Gravity Forms entry array |
|
| 289 | - * @param \GV\View|int $view ID of the view you want to check visibility against {@since 1.9.2}. Required since 2.0 |
|
| 290 | - * @return bool |
|
| 291 | - */ |
|
| 292 | - public static function check_user_cap_edit_entry( $entry, $view = 0 ) { |
|
| 283 | + /** |
|
| 284 | + * checks if user has permissions to edit a specific entry |
|
| 285 | + * |
|
| 286 | + * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_entry for maximum security!! |
|
| 287 | + * |
|
| 288 | + * @param array $entry Gravity Forms entry array |
|
| 289 | + * @param \GV\View|int $view ID of the view you want to check visibility against {@since 1.9.2}. Required since 2.0 |
|
| 290 | + * @return bool |
|
| 291 | + */ |
|
| 292 | + public static function check_user_cap_edit_entry( $entry, $view = 0 ) { |
|
| 293 | 293 | |
| 294 | - // No permission by default |
|
| 295 | - $user_can_edit = false; |
|
| 294 | + // No permission by default |
|
| 295 | + $user_can_edit = false; |
|
| 296 | 296 | |
| 297 | 297 | // get user_edit setting |
| 298 | 298 | if ( empty( $view ) ) { |
@@ -310,60 +310,60 @@ discard block |
||
| 310 | 310 | $user_edit = GVCommon::get_template_setting( $view_id, 'user_edit' ); |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - // If they can edit any entries (as defined in Gravity Forms) |
|
| 314 | - // Or if they can edit other people's entries |
|
| 315 | - // Then we're good. |
|
| 316 | - if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { |
|
| 313 | + // If they can edit any entries (as defined in Gravity Forms) |
|
| 314 | + // Or if they can edit other people's entries |
|
| 315 | + // Then we're good. |
|
| 316 | + if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ), $entry['id'] ) ) { |
|
| 317 | 317 | |
| 318 | - gravityview()->log->debug( 'User has ability to edit all entries.' ); |
|
| 318 | + gravityview()->log->debug( 'User has ability to edit all entries.' ); |
|
| 319 | 319 | |
| 320 | - $user_can_edit = true; |
|
| 320 | + $user_can_edit = true; |
|
| 321 | 321 | |
| 322 | - } else if( !isset( $entry['created_by'] ) ) { |
|
| 322 | + } else if( !isset( $entry['created_by'] ) ) { |
|
| 323 | 323 | |
| 324 | - gravityview()->log->error( 'Entry `created_by` doesn\'t exist.'); |
|
| 324 | + gravityview()->log->error( 'Entry `created_by` doesn\'t exist.'); |
|
| 325 | 325 | |
| 326 | - $user_can_edit = false; |
|
| 326 | + $user_can_edit = false; |
|
| 327 | 327 | |
| 328 | - } else { |
|
| 328 | + } else { |
|
| 329 | 329 | |
| 330 | - $current_user = wp_get_current_user(); |
|
| 330 | + $current_user = wp_get_current_user(); |
|
| 331 | 331 | |
| 332 | - // User edit is disabled |
|
| 333 | - if( empty( $user_edit ) ) { |
|
| 332 | + // User edit is disabled |
|
| 333 | + if( empty( $user_edit ) ) { |
|
| 334 | 334 | |
| 335 | - gravityview()->log->debug( 'User Edit is disabled. Returning false.' ); |
|
| 335 | + gravityview()->log->debug( 'User Edit is disabled. Returning false.' ); |
|
| 336 | 336 | |
| 337 | - $user_can_edit = false; |
|
| 338 | - } |
|
| 337 | + $user_can_edit = false; |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. |
|
| 341 | - else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
| 340 | + // User edit is enabled and the logged-in user is the same as the user who created the entry. We're good. |
|
| 341 | + else if( is_user_logged_in() && intval( $current_user->ID ) === intval( $entry['created_by'] ) ) { |
|
| 342 | 342 | |
| 343 | - gravityview()->log->debug( 'User {user_id} created the entry.', array( 'user_id', $current_user->ID ) ); |
|
| 343 | + gravityview()->log->debug( 'User {user_id} created the entry.', array( 'user_id', $current_user->ID ) ); |
|
| 344 | 344 | |
| 345 | - $user_can_edit = true; |
|
| 345 | + $user_can_edit = true; |
|
| 346 | 346 | |
| 347 | - } else if( ! is_user_logged_in() ) { |
|
| 347 | + } else if( ! is_user_logged_in() ) { |
|
| 348 | 348 | |
| 349 | - gravityview()->log->debug( 'No user defined; edit entry requires logged in user' ); |
|
| 349 | + gravityview()->log->debug( 'No user defined; edit entry requires logged in user' ); |
|
| 350 | 350 | |
| 351 | - $user_can_edit = false; // Here just for clarity |
|
| 352 | - } |
|
| 351 | + $user_can_edit = false; // Here just for clarity |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | - } |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - /** |
|
| 357 | - * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. |
|
| 358 | - * @since 1.15 Added `$entry` and `$view_id` parameters |
|
| 359 | - * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false) |
|
| 360 | - * @param[in] array $entry Gravity Forms entry array {@since 1.15} |
|
| 361 | - * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15} |
|
| 362 | - */ |
|
| 363 | - $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id ); |
|
| 356 | + /** |
|
| 357 | + * @filter `gravityview/edit_entry/user_can_edit_entry` Modify whether user can edit an entry. |
|
| 358 | + * @since 1.15 Added `$entry` and `$view_id` parameters |
|
| 359 | + * @param[in,out] boolean $user_can_edit Can the current user edit the current entry? (Default: false) |
|
| 360 | + * @param[in] array $entry Gravity Forms entry array {@since 1.15} |
|
| 361 | + * @param[in] int $view_id ID of the view you want to check visibility against {@since 1.15} |
|
| 362 | + */ |
|
| 363 | + $user_can_edit = apply_filters( 'gravityview/edit_entry/user_can_edit_entry', $user_can_edit, $entry, $view_id ); |
|
| 364 | 364 | |
| 365 | - return (bool) $user_can_edit; |
|
| 366 | - } |
|
| 365 | + return (bool) $user_can_edit; |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | 368 | |
| 369 | 369 | |
@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function add_downloads_data_filters() { |
| 68 | 68 | |
| 69 | - $downloads_data = get_site_transient( self::DOWNLOADS_DATA_TRANSIENT ); |
|
| 69 | + $downloads_data = get_site_transient( self::DOWNLOADS_DATA_TRANSIENT ); |
|
| 70 | 70 | |
| 71 | - if ( ! $downloads_data && ! isset( $_GET['cache'] ) ) { |
|
| 71 | + if ( ! $downloads_data && ! isset( $_GET['cache'] ) ) { |
|
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function add_admin_menu() { |
| 99 | 99 | |
| 100 | - $menu_text = _x( 'Extensions', 'Extensions are WordPress plugins that add functionality to GravityView and Gravity Forms', 'gravityview' ); |
|
| 100 | + $menu_text = _x( 'Extensions', 'Extensions are WordPress plugins that add functionality to GravityView and Gravity Forms', 'gravityview' ); |
|
| 101 | 101 | |
| 102 | 102 | $menu_text = sprintf( '<span title="%s" style="margin: 0">%s</span>', esc_attr__( 'Plugins that extend GravityView and Gravity Forms functionality.', 'gravityview' ), $menu_text ); |
| 103 | 103 | |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | - * When on the Installer page, show a different notice than on the Settings page |
|
| 116 | - * |
|
| 115 | + * When on the Installer page, show a different notice than on the Settings page |
|
| 116 | + * |
|
| 117 | 117 | * @param array $notice |
| 118 | 118 | * |
| 119 | 119 | * @return string License notice |
@@ -121,10 +121,10 @@ discard block |
||
| 121 | 121 | public function maybe_modify_license_notice( $notice = '' ) { |
| 122 | 122 | |
| 123 | 123 | if ( ! gravityview()->request->is_admin( '', 'downloads' ) ) { |
| 124 | - return $notice; |
|
| 125 | - } |
|
| 124 | + return $notice; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - return esc_html__( 'Your license %s. Do you want access to these plugins? %sActivate your license%s or %sget a license here%s.', 'gravityview' ); |
|
| 127 | + return esc_html__( 'Your license %s. Do you want access to these plugins? %sActivate your license%s or %sget a license here%s.', 'gravityview' ); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -162,43 +162,43 @@ discard block |
||
| 162 | 162 | * Get downloads data from transient or from API; save transient after getting data from API |
| 163 | 163 | * |
| 164 | 164 | * @return WP_Error|array If error, returns WP_Error. If not valid JSON, empty array. Otherwise, this structure: { |
| 165 | - * @type array $info { |
|
| 166 | - * @type string $id int 17 |
|
| 167 | - * @type string $slug Extension slug |
|
| 168 | - * @type string $title Extension title |
|
| 169 | - * @type string $create_date in '2018-07-19 20:03:10' format |
|
| 170 | - * @type string $modified_date |
|
| 171 | - * @type string $status |
|
| 172 | - * @type string $link URL to public plugin page |
|
| 173 | - * @type string $content |
|
| 174 | - * @type string $excerpt |
|
| 175 | - * @type string $thumbnail URL to thumbnail |
|
| 176 | - * @type array $category Taxonomy details for the plugin's category { |
|
| 177 | - * @type int $term_id => int 30 |
|
| 178 | - * @type string $name => string 'Plugins' (length=7) |
|
| 179 | - * @type string $slug => string 'plugins' (length=7) |
|
| 180 | - * @type int $term_group => int 0 |
|
| 181 | - * @type int $term_taxonomy_id => int 30 |
|
| 182 | - * @type string $taxonomy => string 'download_category' (length=17) |
|
| 183 | - * @type string $description => string '' (length=0) |
|
| 184 | - * @type int $parent => int 0 |
|
| 185 | - * @type int $count => int 4 |
|
| 186 | - * @type string $filter => string 'raw' (length=3) |
|
| 187 | - * } |
|
| 188 | - * @type array $tags {see $category above} |
|
| 189 | - * @type string $textdomain string 'gravityview' (length=11) |
|
| 190 | - * } |
|
| 191 | - * @type array $pricing array of `price_name_slugs` => '00.00' values, if price options exist |
|
| 192 | - * @type array $licensing { |
|
| 193 | - * @type bool $enabled Is licensing enabled for the extension |
|
| 194 | - * @type string $version Version number |
|
| 195 | - * @type string $exp_unit Expiration unit ('years') |
|
| 196 | - * @type string $exp_length Expiration length ('1') |
|
| 197 | - * } |
|
| 198 | - * @type array $files Array of files. Empty if user has no access to the file. { |
|
| 199 | - * @type string $file string URL of the file download |
|
| 200 | - * } |
|
| 201 | - * } |
|
| 165 | + * @type array $info { |
|
| 166 | + * @type string $id int 17 |
|
| 167 | + * @type string $slug Extension slug |
|
| 168 | + * @type string $title Extension title |
|
| 169 | + * @type string $create_date in '2018-07-19 20:03:10' format |
|
| 170 | + * @type string $modified_date |
|
| 171 | + * @type string $status |
|
| 172 | + * @type string $link URL to public plugin page |
|
| 173 | + * @type string $content |
|
| 174 | + * @type string $excerpt |
|
| 175 | + * @type string $thumbnail URL to thumbnail |
|
| 176 | + * @type array $category Taxonomy details for the plugin's category { |
|
| 177 | + * @type int $term_id => int 30 |
|
| 178 | + * @type string $name => string 'Plugins' (length=7) |
|
| 179 | + * @type string $slug => string 'plugins' (length=7) |
|
| 180 | + * @type int $term_group => int 0 |
|
| 181 | + * @type int $term_taxonomy_id => int 30 |
|
| 182 | + * @type string $taxonomy => string 'download_category' (length=17) |
|
| 183 | + * @type string $description => string '' (length=0) |
|
| 184 | + * @type int $parent => int 0 |
|
| 185 | + * @type int $count => int 4 |
|
| 186 | + * @type string $filter => string 'raw' (length=3) |
|
| 187 | + * } |
|
| 188 | + * @type array $tags {see $category above} |
|
| 189 | + * @type string $textdomain string 'gravityview' (length=11) |
|
| 190 | + * } |
|
| 191 | + * @type array $pricing array of `price_name_slugs` => '00.00' values, if price options exist |
|
| 192 | + * @type array $licensing { |
|
| 193 | + * @type bool $enabled Is licensing enabled for the extension |
|
| 194 | + * @type string $version Version number |
|
| 195 | + * @type string $exp_unit Expiration unit ('years') |
|
| 196 | + * @type string $exp_length Expiration length ('1') |
|
| 197 | + * } |
|
| 198 | + * @type array $files Array of files. Empty if user has no access to the file. { |
|
| 199 | + * @type string $file string URL of the file download |
|
| 200 | + * } |
|
| 201 | + * } |
|
| 202 | 202 | */ |
| 203 | 203 | public function get_downloads_data() { |
| 204 | 204 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | ) ); |
| 231 | 231 | |
| 232 | 232 | if ( is_wp_error( $response ) ) { |
| 233 | - gravityview()->log->error( "Extension data response is an error", array( 'data' => $response ) ); |
|
| 233 | + gravityview()->log->error( "Extension data response is an error", array( 'data' => $response ) ); |
|
| 234 | 234 | return $response; |
| 235 | 235 | } |
| 236 | 236 | |
@@ -283,10 +283,10 @@ discard block |
||
| 283 | 283 | <div class="gv-admin-installer-notice notice inline error"> |
| 284 | 284 | <h3><?php esc_html_e( 'Extensions and plugins data cannot be loaded at the moment. Please try again later.', 'gravityview' ); ?></h3> |
| 285 | 285 | <?php |
| 286 | - if ( is_wp_error( $downloads_data ) ) { |
|
| 287 | - echo wpautop( '<pre>' . esc_html( $downloads_data->get_error_message() ) . '</pre>' ); |
|
| 288 | - } |
|
| 289 | - ?> |
|
| 286 | + if ( is_wp_error( $downloads_data ) ) { |
|
| 287 | + echo wpautop( '<pre>' . esc_html( $downloads_data->get_error_message() ) . '</pre>' ); |
|
| 288 | + } |
|
| 289 | + ?> |
|
| 290 | 290 | </div> |
| 291 | 291 | </div> |
| 292 | 292 | <?php |
@@ -342,9 +342,9 @@ discard block |
||
| 342 | 342 | protected function render_download( $download, $wp_plugins ) { |
| 343 | 343 | |
| 344 | 344 | |
| 345 | - $details = $this->get_download_display_details( $download, $wp_plugins ); |
|
| 345 | + $details = $this->get_download_display_details( $download, $wp_plugins ); |
|
| 346 | 346 | |
| 347 | - $download_info = $details['download_info']; |
|
| 347 | + $download_info = $details['download_info']; |
|
| 348 | 348 | |
| 349 | 349 | ?> |
| 350 | 350 | <div class="item <?php echo esc_attr( $details['item_class'] ); ?>"> |
@@ -366,43 +366,43 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | <div class="addon-excerpt"><?php |
| 368 | 368 | |
| 369 | - $excerpt = \GV\Utils::get( $download_info, 'installer_excerpt', $download_info['excerpt'] ); |
|
| 369 | + $excerpt = \GV\Utils::get( $download_info, 'installer_excerpt', $download_info['excerpt'] ); |
|
| 370 | 370 | |
| 371 | - // Allow some pure HTML tags, but remove everything else from the excerpt. |
|
| 372 | - $tags = array( '<strong>', '</strong>', '<em>', '</em>', '<code>', '</code>' ); |
|
| 373 | - $replacements = array( '[b]', '[/b]', '[i]', '[/i]', '[code]', '[/code]' ); |
|
| 371 | + // Allow some pure HTML tags, but remove everything else from the excerpt. |
|
| 372 | + $tags = array( '<strong>', '</strong>', '<em>', '</em>', '<code>', '</code>' ); |
|
| 373 | + $replacements = array( '[b]', '[/b]', '[i]', '[/i]', '[code]', '[/code]' ); |
|
| 374 | 374 | |
| 375 | - $excerpt = str_replace( $tags, $replacements, $excerpt ); |
|
| 376 | - $excerpt = esc_html( strip_tags( $excerpt ) ); |
|
| 375 | + $excerpt = str_replace( $tags, $replacements, $excerpt ); |
|
| 376 | + $excerpt = esc_html( strip_tags( $excerpt ) ); |
|
| 377 | 377 | $excerpt = str_replace( $replacements, $tags, $excerpt ); |
| 378 | 378 | |
| 379 | 379 | echo wpautop( $excerpt ); |
| 380 | - ?></div> |
|
| 380 | + ?></div> |
|
| 381 | 381 | </div> |
| 382 | 382 | </div> |
| 383 | 383 | <?php |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
| 387 | - * Generates details array for the download to keep the render_download() method a bit tidier |
|
| 388 | - * |
|
| 387 | + * Generates details array for the download to keep the render_download() method a bit tidier |
|
| 388 | + * |
|
| 389 | 389 | * @param array $download Single download, as returned by {@see get_downloads_data} |
| 390 | 390 | * @param array $wp_plugins All active plugins, as returned by {@see get_plugins()} |
| 391 | 391 | * |
| 392 | 392 | * @return array { |
| 393 | - * @type array $download_info |
|
| 394 | - * @type string $plugin_path |
|
| 395 | - * @type string $status License status returned by Easy Digital Downloads ("active", "inactive", "expired", "revoked", etc) |
|
| 396 | - * @type string $status_label |
|
| 397 | - * @type string $button_title Title attribute to show when hovering over the download's button |
|
| 398 | - * @type string $button_class CSS class to use for the button |
|
| 399 | - * @type string $button_label Text to use for the download's anchor link |
|
| 400 | - * @type string $href URL for the download's button |
|
| 401 | - * @type bool $spinner Whether to show the spinner icon |
|
| 402 | - * @type string $item_class CSS class for the download container |
|
| 403 | - * @type string $required_license The name of the required license for the download ("All Access" or "Core + Extensions") |
|
| 404 | - * @type bool $is_active Is the current GravityView license (as entered in Settings) active? |
|
| 405 | - * } |
|
| 393 | + * @type array $download_info |
|
| 394 | + * @type string $plugin_path |
|
| 395 | + * @type string $status License status returned by Easy Digital Downloads ("active", "inactive", "expired", "revoked", etc) |
|
| 396 | + * @type string $status_label |
|
| 397 | + * @type string $button_title Title attribute to show when hovering over the download's button |
|
| 398 | + * @type string $button_class CSS class to use for the button |
|
| 399 | + * @type string $button_label Text to use for the download's anchor link |
|
| 400 | + * @type string $href URL for the download's button |
|
| 401 | + * @type bool $spinner Whether to show the spinner icon |
|
| 402 | + * @type string $item_class CSS class for the download container |
|
| 403 | + * @type string $required_license The name of the required license for the download ("All Access" or "Core + Extensions") |
|
| 404 | + * @type bool $is_active Is the current GravityView license (as entered in Settings) active? |
|
| 405 | + * } |
|
| 406 | 406 | */ |
| 407 | 407 | private function get_download_display_details( $download, $wp_plugins ) { |
| 408 | 408 | |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | 'slug' => '', |
| 414 | 414 | 'excerpt' => '', |
| 415 | 415 | 'link' => '', |
| 416 | - 'coming_soon' => false, |
|
| 416 | + 'coming_soon' => false, |
|
| 417 | 417 | 'installer_title' => null, // May not be defined |
| 418 | 418 | 'installer_excerpt' => null, // May not be defined |
| 419 | 419 | ) ); |
@@ -456,14 +456,14 @@ discard block |
||
| 456 | 456 | $href = 'https://gravityview.co/pricing/?utm_source=admin-installer&utm_medium=admin&utm_campaign=Admin%20Notice&utm_content=' . $required_license; |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | - elseif ( ! empty( $download_info['coming_soon'] ) ) { |
|
| 460 | - $spinner = false; |
|
| 461 | - $status = 'notinstalled'; |
|
| 462 | - $status_label = __( 'Coming Soon', 'gravityview' ); |
|
| 463 | - $button_label = __( 'Learn More', 'gravityview' ); |
|
| 464 | - $button_class = 'button-primary button-large'; |
|
| 465 | - $href = \GV\Utils::get( $download_info, 'link', 'https://gravityview.co/extensions/' ); |
|
| 466 | - } |
|
| 459 | + elseif ( ! empty( $download_info['coming_soon'] ) ) { |
|
| 460 | + $spinner = false; |
|
| 461 | + $status = 'notinstalled'; |
|
| 462 | + $status_label = __( 'Coming Soon', 'gravityview' ); |
|
| 463 | + $button_label = __( 'Learn More', 'gravityview' ); |
|
| 464 | + $button_class = 'button-primary button-large'; |
|
| 465 | + $href = \GV\Utils::get( $download_info, 'link', 'https://gravityview.co/extensions/' ); |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | 468 | // Access but the plugin is not installed |
| 469 | 469 | elseif ( ! $wp_plugin ) { |
@@ -503,18 +503,18 @@ discard block |
||
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | return compact( 'download_info','plugin_path', 'status', 'status_label', 'button_title', 'button_class', 'button_label', 'href', 'spinner', 'item_class', 'required_license', 'is_active' ); |
| 506 | - } |
|
| 506 | + } |
|
| 507 | 507 | |
| 508 | 508 | /** |
| 509 | - * Returns the base price for an extension |
|
| 510 | - * |
|
| 509 | + * Returns the base price for an extension |
|
| 510 | + * |
|
| 511 | 511 | * @param array $download |
| 512 | 512 | * |
| 513 | 513 | * @return float Base price for an extension. If not for sale separately, returns 0 |
| 514 | 514 | */ |
| 515 | 515 | private function get_download_base_price( $download ) { |
| 516 | 516 | |
| 517 | - $base_price = \GV\Utils::get( $download, 'pricing/amount', 0 ); |
|
| 517 | + $base_price = \GV\Utils::get( $download, 'pricing/amount', 0 ); |
|
| 518 | 518 | $base_price = \GFCommon::to_number( $base_price ); |
| 519 | 519 | |
| 520 | 520 | unset( $download['pricing']['amount'] ); |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | return floatval( $base_price ); |
| 528 | - } |
|
| 528 | + } |
|
| 529 | 529 | |
| 530 | 530 | /** |
| 531 | 531 | * Handle AJAX request to activate extension |
@@ -543,8 +543,8 @@ discard block |
||
| 543 | 543 | |
| 544 | 544 | if ( is_wp_error( $result ) || ! is_plugin_active( $data['path'] ) ) { |
| 545 | 545 | wp_send_json_error( array( |
| 546 | - 'error' => sprintf( __( 'Plugin activation failed: %s', 'gravityview' ), $result->get_error_message() ) |
|
| 547 | - ) ); |
|
| 546 | + 'error' => sprintf( __( 'Plugin activation failed: %s', 'gravityview' ), $result->get_error_message() ) |
|
| 547 | + ) ); |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | wp_send_json_success(); |
@@ -565,10 +565,10 @@ discard block |
||
| 565 | 565 | deactivate_plugins( $data['path'] ); |
| 566 | 566 | |
| 567 | 567 | if( is_plugin_active( $data['path'] ) ) { |
| 568 | - wp_send_json_error( array( |
|
| 569 | - 'error' => sprintf( __( 'Plugin deactivation failed.', 'gravityview' ) ) |
|
| 570 | - ) ); |
|
| 571 | - } |
|
| 568 | + wp_send_json_error( array( |
|
| 569 | + 'error' => sprintf( __( 'Plugin deactivation failed.', 'gravityview' ) ) |
|
| 570 | + ) ); |
|
| 571 | + } |
|
| 572 | 572 | |
| 573 | 573 | wp_send_json_success(); |
| 574 | 574 | } |
@@ -39,13 +39,13 @@ |
||
| 39 | 39 | 'tooltip' => __( 'Enter the number of words to be shown. If specified it truncates the text. Leave it blank if you want to show the full text.', 'gravityview' ), |
| 40 | 40 | ); |
| 41 | 41 | |
| 42 | - $field_options['make_clickable'] = array( |
|
| 43 | - 'type' => 'checkbox', |
|
| 44 | - 'merge_tags' => false, |
|
| 45 | - 'value' => 0, |
|
| 46 | - 'label' => __( 'Convert text URLs to HTML links', 'gravityview' ), |
|
| 47 | - 'tooltip' => __( 'Converts URI, www, FTP, and email addresses in HTML links', 'gravityview' ), |
|
| 48 | - ); |
|
| 42 | + $field_options['make_clickable'] = array( |
|
| 43 | + 'type' => 'checkbox', |
|
| 44 | + 'merge_tags' => false, |
|
| 45 | + 'value' => 0, |
|
| 46 | + 'label' => __( 'Convert text URLs to HTML links', 'gravityview' ), |
|
| 47 | + 'tooltip' => __( 'Converts URI, www, FTP, and email addresses in HTML links', 'gravityview' ), |
|
| 48 | + ); |
|
| 49 | 49 | |
| 50 | 50 | $field_options['allow_html'] = array( |
| 51 | 51 | 'type' => 'checkbox', |