PluginProbe
Snippet Shortcodes / 5.1.1
Snippet Shortcodes v5.1.1
5.2.1 5.2 5.1.8 5.1.6 5.1.7 5.1.5 trunk 1.0 1.1 1.2 1.3 1.3.1 1.4 1.5 1.5.1 1.6 1.6.1 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 2.0 2.0.1 All 74 releases
shortcode-variables / includes / pages / page.import.php

page.import.php in Snippet Shortcodes 5.1.1, at includes/pages/page.import.php

130 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') or die('Naw ya dinnie!');
4
5 function sh_cd_admin_page_import() {
6
7 sh_cd_permission_check();
8
9 wp_enqueue_media();
10
11 $importing = false;
12 $output = '';
13
14 if ( true === sh_cd_is_premium() &&
15 false === empty( $_POST[ 'attachment-id' ] ) ){
16
17 $importing = true;
18 $dry_run = ( false === empty( $_POST[ 'dry-run' ] ) );
19 $output = sh_cd_import_csv( $_POST[ 'attachment-id' ], $dry_run );
20 }
21
22 ?>
23 <div class="wrap sh-cd-csv-import ws-ls-admin-page">
24 <div id="poststuff">
25 <div id="post-body" class="metabox-holder">
26 <div id="post-body-content">
27 <div class="meta-box-sortables ui-sortable">
28 <?php
29 if ( false === sh_cd_is_premium() ) {
30 sh_cd_display_pro_upgrade_notice();
31 }
32 ?>
33 <div class="postbox">
34 <h3 class="postbox-header">
35 <span>
36 <?php echo __( 'Import CSV', SH_CD_SLUG ); ?>
37 </span>
38 </h3>
39 <div class="inside">
40 <?php if ( false === $importing ): ?>
41 <div class="sh-cd-form-row">
42 <p>
43 <?php echo __( 'Please select a CSV file to import one or more shortcodes into your collection.', SH_CD_SLUG ); ?>
44 <a href="https://snippet-shortcodes.yeken.uk/csv-import.html" rel="noopener noreferrer" target="_blank"><?php echo __( 'Read more about CSV imports and the required format', SH_CD_SLUG ); ?>.</a>
45 </p>
46 <input id="select_csv" type="button" class="button sh-cd-button" value="<?php echo __( 'Select CSV file', SH_CD_SLUG ); ?>" />
47 <br />
48 </div>
49 <div class="sh-cd-hide sh-cd-import-selected" id="selected-form" >
50 <form action="<?php echo admin_url( 'admin.php?page=sh-cd-import&mode=import'); ?>" method="post">
51 <div class="sh-cd-form-row">
52 <label for="attachment-path"><?php echo __( 'Selected file:', SH_CD_SLUG ); ?></label>
53 <input type='text' name='attachment-path' id='attachment-path' value='' class="widefat" disabled="disabled" />
54 <input type='hidden' name='attachment-id' id='attachment-id' value='' />
55 </div>
56 <div class="sh-cd-form-row">
57 <input type='checkbox' name='dry-run' id='dry-run' value='yes' />
58 <label for="dry-run"><?php echo __( 'Dry run mode. This will do basic tests on the file without performing an import.', SH_CD_SLUG ); ?></label>
59 </div>
60 <div class="sh-cd-form-row">
61 <input type="submit" class="button button-primary sh-cd-button" value="<?php echo __( 'Import CSV', SH_CD_SLUG ); ?>" <?php if ( false === sh_cd_is_premium() ) { echo 'disabled="disabled"'; } ?> />
62 </div>
63 </form>
64 </div>
65 <?php else: ?>
66 <p><strong><?php echo __( 'Output:', SH_CD_SLUG ); ?></strong></p>
67 <textarea class="widefat" rows="20" cols="100"><?php echo esc_html( $output ); ?></textarea>
68 <?php endif; ?>
69 </div>
70 </div>
71 </div>
72 </div>
73 </div>
74 <br class="clear">
75 </div>
76 <script>
77 jQuery( document ).ready(function ($) {
78
79 // CSV import for
80 let file_frame;
81
82 $( '#select_csv').on('click', function( event ){
83
84 event.preventDefault();
85
86 <?php if ( false === sh_cd_is_premium() ) : ?>
87 alert( '<?php echo __( "Please upgrade to bulk import shortcodes via CSV.", SH_CD_SLUG ); ?>' );
88 return;
89 <?php else: ?>
90
91 // If the media frame already exists, reopen it.
92 if ( file_frame ) {
93
94 // Open frame
95 file_frame.open();
96 return;
97 }
98
99 // Create the media frame.
100 file_frame = wp.media.frames.file_frame = wp.media({
101 title: '<?php echo __( "Select a CSV", SH_CD_SLUG ); ?>',
102 button: {
103 text: '<?php echo __( "Use this file", SH_CD_SLUG ); ?>',
104 },
105 library : {
106 type : ['application/csv', 'text/csv'],
107 },
108 multiple: false
109 });
110
111 // When an image is selected, run a callback.
112 file_frame.on( 'select', function() {
113
114 attachment = file_frame.state().get('selection').first().toJSON();
115
116 $( '#attachment-id' ).val( attachment.id );
117 $( '#attachment-path' ).val( attachment.url );
118 $( '#selected-form' ).removeClass( 'sh-cd-hide' );
119
120 });
121
122 file_frame.open();
123
124 <?php endif; ?>
125 });
126 });
127 </script>
128 <?php
129 }
130