Changeset 2349030
- Timestamp:
- 07/30/2020 11:14:30 AM (6 years ago)
- Location:
- add-entries-functionality-to-wpforms
- Files:
-
- 14 edited
- 1 copied
-
tags/1.1.0 (copied) (copied from add-entries-functionality-to-wpforms/trunk)
-
tags/1.1.0/add-wpform-entries.php (modified) (4 diffs)
-
tags/1.1.0/includes/admin/entry/entries-db.php (modified) (1 diff)
-
tags/1.1.0/includes/admin/entry/entries-page.php (modified) (6 diffs)
-
tags/1.1.0/includes/admin/entry/entries-table.php (modified) (4 diffs)
-
tags/1.1.0/includes/class-db.php (modified) (2 diffs)
-
tags/1.1.0/includes/functions.php (modified) (1 diff)
-
tags/1.1.0/readme.txt (modified) (2 diffs)
-
trunk/add-wpform-entries.php (modified) (4 diffs)
-
trunk/includes/admin/entry/entries-db.php (modified) (1 diff)
-
trunk/includes/admin/entry/entries-page.php (modified) (6 diffs)
-
trunk/includes/admin/entry/entries-table.php (modified) (4 diffs)
-
trunk/includes/class-db.php (modified) (2 diffs)
-
trunk/includes/functions.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
add-entries-functionality-to-wpforms/tags/1.1.0/add-wpform-entries.php
r2345376 r2349030 7 7 Author URI:http://aaivatech.com/ 8 8 COntributors: 9 Version: 1. 0.09 Version: 1.1.0 10 10 @copyright Copyright (c) 2020, Ankur Khurana 11 11 @license http://opensource.org/licenses/gpl-2.0.php GNU Public License … … 21 21 * @var string 22 22 */ 23 public $ank_wpforms_entry_version = '1. 0.0';23 public $ank_wpforms_entry_version = '1.1.0'; 24 24 25 25 /** … … 115 115 include_once ANK_WPFORM_ENTRY_BASE_DIR . '/includes/admin/entry/entries-db.php'; 116 116 include_once ANK_WPFORM_ENTRY_BASE_DIR . '/includes/admin/entry/entries-page.php'; 117 include_once ANK_WPFORM_ENTRY_BASE_DIR . '/includes/exporter/export-csv.php'; 117 118 } 118 119 … … 270 271 //main call starts from here 271 272 ank_wpforms_entry(); 273 274 /* 275 * Displays update information for a plugin. 276 */ 277 function ank_wpforms_entry_update_message( $data, $response ) 278 { 279 var_dump("test"); 280 if(isset( $data['upgrade_notice'])) 281 { 282 printf( 283 '<div class="update-message ">%s</div>', 284 wpautop ($data['upgrade_notice']) 285 ); 286 } 287 } 288 add_action( 'in_plugin_update_message-add-wpform-entries/add-wpform-entries.php', 'ank_wpforms_entry_update_message', 10, 2 ); -
add-entries-functionality-to-wpforms/tags/1.1.0/includes/admin/entry/entries-db.php
r2345376 r2349030 236 236 * 237 237 */ 238 public function get_entries( $form_id, $page , $per_page) {238 public function get_entries( $form_id, $page = '', $per_page = '' ) { 239 239 240 240 $temp_entry = array(); 241 241 242 $entries = parent::get_all_records( $form_id, $page, $per_page );242 $entries = parent::get_all_records( $form_id, $page, $per_page ); 243 243 244 244 foreach ( $entries as $entry ) { -
add-entries-functionality-to-wpforms/tags/1.1.0/includes/admin/entry/entries-page.php
r2345376 r2349030 17 17 const SLUG = 'ank-wpforms-entries'; 18 18 19 const EXPORT_BUTTON = 'Export Entries'; 20 19 21 /** 20 22 * Primary class constructor. … … 26 28 // Maybe load entries page. 27 29 add_action( 'admin_init', array( $this, 'init' ) ); 30 31 // Maybe load entries page. 32 add_action( 'admin_init', array( $this, 'catch_export_request' ) ); 28 33 29 34 // Setup screen options. Needs to be here as admin_init hook it too late. … … 63 68 64 69 /** 70 * Determine if the request has come exporting entries. 71 * 72 * @since 1.1.0 73 */ 74 public function catch_export_request() { 75 // Check what page we are on. 76 $page = isset( $_GET['page'] ) ? \sanitize_key( \wp_unslash( $_GET['page'] ) ) : ''; 77 78 // Export only if we are on right page and export is requested. 79 if ( self::SLUG === $page && $_GET['export'] === self::EXPORT_BUTTON ) { 80 $user_can_export = ank_wpforms_entries_user_permission(); 81 82 if ( $user_can_export ) { 83 //core processing on CSV export happens here 84 $export = new Ank_WPForms_Export(); 85 $export->process_export(); 86 } else { 87 if ( is_admin() ) { 88 //Admin notice to mention about permissions required for exporting 89 add_action( 'admin_notices', array( $this, 'export_lack_of_permission_admin_notice' ) ); 90 } else { 91 wp_redirect( wp_login_url() ); 92 } 93 } 94 95 } else { 96 return; 97 } 98 99 } 100 101 /** 102 * Admin notice to show if the user does not have access to export 103 * 104 * @since 1.1.0 105 */ 106 public function export_lack_of_permission_admin_notice() { 107 echo '<div class="notice notice-error"><p>' . __( 'By default, admin are given access to export WPForm entries. ', 'ank-wpforms-entry' ) . '</p></div>'; 108 } 109 110 111 /** 65 112 * Add per-page screen option to the Forms table. 66 113 * … … 77 124 'per_page', 78 125 array( 79 'label' => esc_html__( 'Number of entries per page:', 'ank-wpforms-entry' ),126 'label' => esc_html__( 'Number of entries per page:', 'ank-wpforms-entry' ), 80 127 'option' => 'ank_entries_per_page', 81 128 'default' => apply_filters( 'ank_entries_per_page', 20 ), … … 123 170 <div id="wpforms-overview" class="wrap wpforms-admin-wrap"> 124 171 125 <?php126 $entries_table = new Ank_WPForms_Entries_Table();127 ?>172 <?php 173 $entries_table = new Ank_WPForms_Entries_Table(); 174 ?> 128 175 <h1 class="page-title"> 129 <?php esc_html_e( 'Contact form entries' , 'ank-wpforms-entry' ); ?>130 <?php131 if($entries_table->default_form_title ){132 esc_html_e( " for " . $entries_table->default_form_title);176 <?php esc_html_e( 'Contact form entries', 'ank-wpforms-entry' ); ?> 177 <?php 178 if ( $entries_table->default_form_title ) { 179 esc_html_e( " for " . $entries_table->default_form_title ); 133 180 } 134 181 ?> … … 137 184 <?php 138 185 //prepare entries only if the fields/columns for selected form are defined 139 //no items message is displayed if no fields are present for the form186 //no items message is displayed if no fields are present for the form 140 187 if ( $entries_table->fields ) { 141 188 $entries_table->prepare_items(); -
add-entries-functionality-to-wpforms/tags/1.1.0/includes/admin/entry/entries-table.php
r2345376 r2349030 81 81 */ 82 82 public function get_columns() { 83 ; 83 84 84 $columns = array(); 85 85 … … 232 232 echo $output; 233 233 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); 234 submit_button( __( Ank_WPForms_Entries::EXPORT_BUTTON ), 'primary', 'export', false, array( 'id' => 'export-request-submit' ) ); 234 235 } 235 236 } … … 257 258 */ 258 259 protected function get_form_fields() { 259 //TODO: Add option to restrict columns to certain form fields only260 //TODO: Add option to restrict columns to certain form fields only 260 261 $fields = wpforms_get_form_fields( $this->default_form_id ); 261 262 $this->fields = $fields; … … 399 400 do_action( 'ank_wpforms_entries_admin_overview_after_rows', $this ); 400 401 } 402 401 403 } 402 404 -
add-entries-functionality-to-wpforms/tags/1.1.0/includes/class-db.php
r2345376 r2349030 98 98 * 99 99 */ 100 public function get_all_records( $form_id, $page, $per_page ) { 101 102 global $wpdb; 103 104 $pgstrt = absint( ( $page - 1 ) * $per_page ) . ', '; 105 $limits = ' LIMIT ' . $pgstrt . $per_page; 100 public function get_all_records( $form_id, $page='', $per_page='' ) { 101 102 global $wpdb; 103 $limits = ""; 104 105 //If the page is coming as blank then do not set limit 106 if ( ! empty( $page ) ) { 107 $pgstrt = absint( ( $page - 1 ) * $per_page ) . ', '; 108 $limits = ' LIMIT ' . $pgstrt . $per_page; 109 } 106 110 107 111 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching … … 123 127 * 124 128 */ 125 public function get_count_all_records ( $form_id ) {129 public function get_count_all_records( $form_id ) { 126 130 127 131 global $wpdb; -
add-entries-functionality-to-wpforms/tags/1.1.0/includes/functions.php
r2345376 r2349030 54 54 $data = ''; 55 55 } else { 56 $data = json_decode( $decoded, true );56 $data = json_decode( $decoded, true ); 57 57 } 58 58 59 59 return $data; 60 60 } 61 62 /** 63 * Validate user for permissions 64 * 65 * 66 * @since 1.1.0 67 * 68 */ 69 function ank_wpforms_entries_user_permission() { 70 71 // Check if user has rights to export 72 $current_user = wp_get_current_user(); 73 $current_user->roles = apply_filters( 'ank_wpforms_entries_add_user_roles', $current_user->roles ); 74 $current_user->roles = array_unique( $current_user->roles ); 75 76 $user_can_export = false; 77 $roles_with_export_permission = apply_filters( 'ank_wpforms_entries_user_export_permission_roles', array( 'administrator' ) ); 78 79 if ( $current_user instanceof WP_User ) { 80 $can_users = array_intersect( $roles_with_export_permission, $current_user->roles ); 81 if ( ! empty( $can_users ) || is_super_admin( $current_user->ID ) ) { 82 $user_can_export = true; 83 } 84 } 85 86 return $user_can_export; 87 } -
add-entries-functionality-to-wpforms/tags/1.1.0/readme.txt
r2345396 r2349030 1 1 === Add entries functionality to WPForms === 2 2 Contributors: ankgne 3 Tags: entries, wprforms, entry, wpform 3 Tags: entries, wprforms, entry, wpform, export entries, export WPForm entries in CSV, CSV, export 4 4 Requires at least: 1.0.0 5 5 Tested up to: 5.4.2 6 6 Requires PHP: 7.0.33 7 Stable tag: 1.1.0 7 8 License: GNU General Public License v2.0 or later 8 9 … … 39 40 2. Entries are also accessible form WPForms overview page 40 41 42 43 == Upgrade Notice == 44 45 = 1.1.0 = 46 * Added functionality of exporting entries of selected WPForm in CSV format 47 -
add-entries-functionality-to-wpforms/trunk/add-wpform-entries.php
r2345376 r2349030 7 7 Author URI:http://aaivatech.com/ 8 8 COntributors: 9 Version: 1. 0.09 Version: 1.1.0 10 10 @copyright Copyright (c) 2020, Ankur Khurana 11 11 @license http://opensource.org/licenses/gpl-2.0.php GNU Public License … … 21 21 * @var string 22 22 */ 23 public $ank_wpforms_entry_version = '1. 0.0';23 public $ank_wpforms_entry_version = '1.1.0'; 24 24 25 25 /** … … 115 115 include_once ANK_WPFORM_ENTRY_BASE_DIR . '/includes/admin/entry/entries-db.php'; 116 116 include_once ANK_WPFORM_ENTRY_BASE_DIR . '/includes/admin/entry/entries-page.php'; 117 include_once ANK_WPFORM_ENTRY_BASE_DIR . '/includes/exporter/export-csv.php'; 117 118 } 118 119 … … 270 271 //main call starts from here 271 272 ank_wpforms_entry(); 273 274 /* 275 * Displays update information for a plugin. 276 */ 277 function ank_wpforms_entry_update_message( $data, $response ) 278 { 279 var_dump("test"); 280 if(isset( $data['upgrade_notice'])) 281 { 282 printf( 283 '<div class="update-message ">%s</div>', 284 wpautop ($data['upgrade_notice']) 285 ); 286 } 287 } 288 add_action( 'in_plugin_update_message-add-wpform-entries/add-wpform-entries.php', 'ank_wpforms_entry_update_message', 10, 2 ); -
add-entries-functionality-to-wpforms/trunk/includes/admin/entry/entries-db.php
r2345376 r2349030 236 236 * 237 237 */ 238 public function get_entries( $form_id, $page , $per_page) {238 public function get_entries( $form_id, $page = '', $per_page = '' ) { 239 239 240 240 $temp_entry = array(); 241 241 242 $entries = parent::get_all_records( $form_id, $page, $per_page );242 $entries = parent::get_all_records( $form_id, $page, $per_page ); 243 243 244 244 foreach ( $entries as $entry ) { -
add-entries-functionality-to-wpforms/trunk/includes/admin/entry/entries-page.php
r2345376 r2349030 17 17 const SLUG = 'ank-wpforms-entries'; 18 18 19 const EXPORT_BUTTON = 'Export Entries'; 20 19 21 /** 20 22 * Primary class constructor. … … 26 28 // Maybe load entries page. 27 29 add_action( 'admin_init', array( $this, 'init' ) ); 30 31 // Maybe load entries page. 32 add_action( 'admin_init', array( $this, 'catch_export_request' ) ); 28 33 29 34 // Setup screen options. Needs to be here as admin_init hook it too late. … … 63 68 64 69 /** 70 * Determine if the request has come exporting entries. 71 * 72 * @since 1.1.0 73 */ 74 public function catch_export_request() { 75 // Check what page we are on. 76 $page = isset( $_GET['page'] ) ? \sanitize_key( \wp_unslash( $_GET['page'] ) ) : ''; 77 78 // Export only if we are on right page and export is requested. 79 if ( self::SLUG === $page && $_GET['export'] === self::EXPORT_BUTTON ) { 80 $user_can_export = ank_wpforms_entries_user_permission(); 81 82 if ( $user_can_export ) { 83 //core processing on CSV export happens here 84 $export = new Ank_WPForms_Export(); 85 $export->process_export(); 86 } else { 87 if ( is_admin() ) { 88 //Admin notice to mention about permissions required for exporting 89 add_action( 'admin_notices', array( $this, 'export_lack_of_permission_admin_notice' ) ); 90 } else { 91 wp_redirect( wp_login_url() ); 92 } 93 } 94 95 } else { 96 return; 97 } 98 99 } 100 101 /** 102 * Admin notice to show if the user does not have access to export 103 * 104 * @since 1.1.0 105 */ 106 public function export_lack_of_permission_admin_notice() { 107 echo '<div class="notice notice-error"><p>' . __( 'By default, admin are given access to export WPForm entries. ', 'ank-wpforms-entry' ) . '</p></div>'; 108 } 109 110 111 /** 65 112 * Add per-page screen option to the Forms table. 66 113 * … … 77 124 'per_page', 78 125 array( 79 'label' => esc_html__( 'Number of entries per page:', 'ank-wpforms-entry' ),126 'label' => esc_html__( 'Number of entries per page:', 'ank-wpforms-entry' ), 80 127 'option' => 'ank_entries_per_page', 81 128 'default' => apply_filters( 'ank_entries_per_page', 20 ), … … 123 170 <div id="wpforms-overview" class="wrap wpforms-admin-wrap"> 124 171 125 <?php126 $entries_table = new Ank_WPForms_Entries_Table();127 ?>172 <?php 173 $entries_table = new Ank_WPForms_Entries_Table(); 174 ?> 128 175 <h1 class="page-title"> 129 <?php esc_html_e( 'Contact form entries' , 'ank-wpforms-entry' ); ?>130 <?php131 if($entries_table->default_form_title ){132 esc_html_e( " for " . $entries_table->default_form_title);176 <?php esc_html_e( 'Contact form entries', 'ank-wpforms-entry' ); ?> 177 <?php 178 if ( $entries_table->default_form_title ) { 179 esc_html_e( " for " . $entries_table->default_form_title ); 133 180 } 134 181 ?> … … 137 184 <?php 138 185 //prepare entries only if the fields/columns for selected form are defined 139 //no items message is displayed if no fields are present for the form186 //no items message is displayed if no fields are present for the form 140 187 if ( $entries_table->fields ) { 141 188 $entries_table->prepare_items(); -
add-entries-functionality-to-wpforms/trunk/includes/admin/entry/entries-table.php
r2345376 r2349030 81 81 */ 82 82 public function get_columns() { 83 ; 83 84 84 $columns = array(); 85 85 … … 232 232 echo $output; 233 233 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); 234 submit_button( __( Ank_WPForms_Entries::EXPORT_BUTTON ), 'primary', 'export', false, array( 'id' => 'export-request-submit' ) ); 234 235 } 235 236 } … … 257 258 */ 258 259 protected function get_form_fields() { 259 //TODO: Add option to restrict columns to certain form fields only260 //TODO: Add option to restrict columns to certain form fields only 260 261 $fields = wpforms_get_form_fields( $this->default_form_id ); 261 262 $this->fields = $fields; … … 399 400 do_action( 'ank_wpforms_entries_admin_overview_after_rows', $this ); 400 401 } 402 401 403 } 402 404 -
add-entries-functionality-to-wpforms/trunk/includes/class-db.php
r2345376 r2349030 98 98 * 99 99 */ 100 public function get_all_records( $form_id, $page, $per_page ) { 101 102 global $wpdb; 103 104 $pgstrt = absint( ( $page - 1 ) * $per_page ) . ', '; 105 $limits = ' LIMIT ' . $pgstrt . $per_page; 100 public function get_all_records( $form_id, $page='', $per_page='' ) { 101 102 global $wpdb; 103 $limits = ""; 104 105 //If the page is coming as blank then do not set limit 106 if ( ! empty( $page ) ) { 107 $pgstrt = absint( ( $page - 1 ) * $per_page ) . ', '; 108 $limits = ' LIMIT ' . $pgstrt . $per_page; 109 } 106 110 107 111 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching … … 123 127 * 124 128 */ 125 public function get_count_all_records ( $form_id ) {129 public function get_count_all_records( $form_id ) { 126 130 127 131 global $wpdb; -
add-entries-functionality-to-wpforms/trunk/includes/functions.php
r2345376 r2349030 54 54 $data = ''; 55 55 } else { 56 $data = json_decode( $decoded, true );56 $data = json_decode( $decoded, true ); 57 57 } 58 58 59 59 return $data; 60 60 } 61 62 /** 63 * Validate user for permissions 64 * 65 * 66 * @since 1.1.0 67 * 68 */ 69 function ank_wpforms_entries_user_permission() { 70 71 // Check if user has rights to export 72 $current_user = wp_get_current_user(); 73 $current_user->roles = apply_filters( 'ank_wpforms_entries_add_user_roles', $current_user->roles ); 74 $current_user->roles = array_unique( $current_user->roles ); 75 76 $user_can_export = false; 77 $roles_with_export_permission = apply_filters( 'ank_wpforms_entries_user_export_permission_roles', array( 'administrator' ) ); 78 79 if ( $current_user instanceof WP_User ) { 80 $can_users = array_intersect( $roles_with_export_permission, $current_user->roles ); 81 if ( ! empty( $can_users ) || is_super_admin( $current_user->ID ) ) { 82 $user_can_export = true; 83 } 84 } 85 86 return $user_can_export; 87 } -
add-entries-functionality-to-wpforms/trunk/readme.txt
r2345396 r2349030 1 1 === Add entries functionality to WPForms === 2 2 Contributors: ankgne 3 Tags: entries, wprforms, entry, wpform 3 Tags: entries, wprforms, entry, wpform, export entries, export WPForm entries in CSV, CSV, export 4 4 Requires at least: 1.0.0 5 5 Tested up to: 5.4.2 6 6 Requires PHP: 7.0.33 7 Stable tag: 1.1.0 7 8 License: GNU General Public License v2.0 or later 8 9 … … 39 40 2. Entries are also accessible form WPForms overview page 40 41 42 43 == Upgrade Notice == 44 45 = 1.1.0 = 46 * Added functionality of exporting entries of selected WPForm in CSV format 47
Note: See TracChangeset
for help on using the changeset viewer.