PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 2.0.13
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v2.0.13
5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 5.5.43 All 159 releases
wp-data-access / WPDataAccess / Utilities / WPDA_Example.php

WPDA_Example.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 2.0.13, at WPDataAccess/Utilities/WPDA_Example.php

70 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Suppress "error - 0 - No summary was found for this file" on phpdoc generation
4 *
5 * @package WPDataAccess\Utilities
6 */
7
8 namespace WPDataAccess\Utilities {
9
10 /**
11 * Class WPDA_Example
12 *
13 * Show downloadable example code.
14 *
15 * @package WPDataAccess\Utilities
16 * @author Peter Schulz
17 * @since 1.0.0
18 */
19 class WPDA_Example {
20
21 /**
22 * Send example file
23 *
24 * @since 1.0.0
25 */
26 public function get_example() {
27
28 if ( isset( $_REQUEST['filename'] ) ) {
29 $filename = sanitize_text_field( wp_unslash( $_REQUEST['filename'] ) ); // input var okay.
30 if ( 'wpda-test' === $filename ) {
31 $this->send_file( $filename );
32 } else {
33 wp_die( esc_html__( 'ERROR: Wrong arguments', 'wp-data-access' ) );
34 }
35 } else {
36 wp_die( esc_html__( 'ERROR: Wrong arguments', 'wp-data-access' ) );
37 }
38
39 }
40
41 /**
42 * Send content of example file
43 *
44 * @since 1.0.0
45 *
46 * @param string $example_name Name of example file without file extention.
47 */
48 protected function send_file( $example_name ) {
49
50 $example_file_name = plugin_dir_path( dirname( __FILE__ ) ) . '../tutorials/' . $example_name . '.php.txt';
51 $example_file_handle = fopen( $example_file_name, 'r' );
52 if ( $example_file_handle ) {
53 // Read file content and close handle.
54 $example_file_content = fread( $example_file_handle, filesize( $example_file_name ) );
55 fclose( $example_file_handle );
56
57 // Send file content.
58 header( 'Content-type: text/plain; charset=utf-8' );
59 header( "Content-Disposition: attachment; filename=$example_name.php.txt" );
60 header( 'Pragma: no-cache' );
61 header( 'Expires: 0' );
62 echo $example_file_content;
63 }
64
65 }
66
67 }
68
69 }
70