gravityview /
GravityView
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 2 | |||
| 3 | /** |
||
| 4 | * Actions to be performed on the Gravity Forms Entries list screen |
||
| 5 | */ |
||
| 6 | class GravityView_GF_Entries_List { |
||
| 7 | |||
| 8 | function __construct() { |
||
| 9 | |||
| 10 | // Add Edit link to the entry actions |
||
| 11 | add_action( 'gform_entries_first_column_actions', array( $this, 'add_edit_link' ), 10, 5 ); |
||
| 12 | |||
| 13 | // Add script to enable edit link |
||
| 14 | add_action( 'admin_head-forms_page_gf_entries', array( $this, 'add_edit_script') ); |
||
| 15 | |||
| 16 | } |
||
| 17 | |||
| 18 | /** |
||
| 19 | * When clicking the edit link, convert the Entries form to go to the edit screen. |
||
| 20 | * |
||
| 21 | * Gravity Forms requires $_POST['screen_mode'] to be set to get to the "Edit" mode. This enables direct access to the edit mode. |
||
| 22 | * |
||
| 23 | * @hack |
||
| 24 | * @return void |
||
| 25 | */ |
||
| 26 | public function add_edit_script() { |
||
| 27 | |||
| 28 | // We're on a single entry page, or at least not the Entries page. |
||
| 29 | if( !empty( $_GET['view'] ) && $_GET['view'] !== 'entries' ) { return; } |
||
| 30 | ?> |
||
| 31 | <script> |
||
| 32 | jQuery( document ).ready( function( $ ) { |
||
| 33 | $('.edit_entry a').click(function(e) { |
||
| 34 | e.preventDefault(); |
||
| 35 | $( e.target ).parents('form') |
||
| 36 | .prepend('<input name="screen_mode" type="hidden" value="edit" />') |
||
| 37 | .attr('action', $(e.target).attr('href') ) |
||
| 38 | .submit(); |
||
| 39 | }); |
||
| 40 | }); |
||
| 41 | </script> |
||
| 42 | <?php |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Add an Edit link to the GF Entry actions row |
||
| 47 | * @param int $form_id ID of the current form |
||
| 48 | * @param int $field_id The ID of the field in the first column, where the row actions are shown |
||
| 49 | * @param string $value The value of the `$field_id` field |
||
| 50 | * @param array $lead The current entry data |
||
| 51 | * @param string $query_string URL query string for a link to the current entry. Missing the `?page=` part, which is strange. Example: `gf_entries&view=entry&id=35&lid=5212&filter=&paged=1` |
||
| 52 | */ |
||
| 53 | function add_edit_link( $form_id = NULL, $field_id = NULL, $value = NULL, $lead = array(), $query_string = NULL ) { |
||
| 54 | |||
| 55 | $params = array( |
||
| 56 | 'page' => 'gf_entries', |
||
| 57 | 'view' => 'entry', |
||
| 58 | 'id' => (int)$form_id, |
||
| 59 | 'lid' => (int)$lead["id"], |
||
| 60 | 'screen_mode' => 'edit', |
||
| 61 | ); |
||
| 62 | ?> |
||
| 63 | |||
| 64 | <span class="edit edit_entry"> |
||
| 65 | | |
||
| 66 | <a title="<?php esc_attr_e( 'Edit this entry', 'gravityview'); ?>" href="<?php echo esc_url( add_query_arg( $params, admin_url( 'admin.php?page='.$query_string ) ) ); ?>"><?php esc_html_e( 'Edit', 'gravityview' ); ?></a> |
||
| 67 | </span> |
||
| 68 | <?php |
||
| 69 | } |
||
| 70 | |||
| 71 | } |
||
| 72 | |||
| 73 | new GravityView_GF_Entries_List; |
||
| 74 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.