PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.1
Shortcoder — Create Shortcodes for Anything v5.1
trunk 3.0 3.0.1 3.1 3.2 3.3 3.4 3.4.1 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.3 4.4 4.5 4.6 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.1 5.2 5.2.1 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.4 5.5 5.6 5.7 5.8 6.0 6.1 6.2 6.3 6.3.1 6.3.2 6.4 6.5 6.5.1 6.5.2 6.5.3
shortcoder / admin / admin.php
shortcoder / admin Last commit date
css 6 years ago font 6 years ago images 6 years ago js 6 years ago admin.php 6 years ago edit.php 6 years ago form.php 6 years ago insert.php 6 years ago manage.php 6 years ago tools.php 6 years ago
admin.php
259 lines
1 <?php
2
3 if( ! defined( 'ABSPATH' ) ) exit;
4
5 class SC_Admin{
6
7 public static function init(){
8
9 add_action( 'init', array( __class__, 'register_post_type' ), 0 );
10
11 add_action( 'init', array( __class__, 'register_taxonomy' ), 0 );
12
13 add_action( 'admin_enqueue_scripts', array( __class__, 'enqueue_scripts' ) );
14
15 add_action( 'admin_footer', array( __class__, 'changelog' ) );
16
17 add_action( 'admin_footer', array( __class__, 'import_export' ) );
18
19 add_action( 'wp_ajax_sc_admin_ajax', array( __class__, 'admin_ajax' ) );
20
21 }
22
23 public static function register_post_type(){
24
25 $labels = array(
26 'name' => _x( 'Shortcoder', 'Post Type General Name', 'sc' ),
27 'singular_name' => _x( 'Shortcode', 'Post Type Singular Name', 'sc' ),
28 'menu_name' => __( 'Shortcoder', 'sc' ),
29 'name_admin_bar' => __( 'Shortcode', 'sc' ),
30 'archives' => __( 'Shortcode Archives', 'sc' ),
31 'attributes' => __( 'Shortcode Attributes', 'sc' ),
32 'parent_item_colon' => __( 'Parent Shortcode:', 'sc' ),
33 'all_items' => __( 'All Shortcodes', 'sc' ),
34 'add_new_item' => __( 'Create shortcode', 'sc' ),
35 'add_new' => __( 'Create shortcode', 'sc' ),
36 'new_item' => __( 'New Shortcode', 'sc' ),
37 'edit_item' => __( 'Edit Shortcode', 'sc' ),
38 'update_item' => __( 'Update Shortcode', 'sc' ),
39 'view_item' => __( 'View Shortcode', 'sc' ),
40 'view_items' => __( 'View Shortcodes', 'sc' ),
41 'search_items' => __( 'Search Shortcode', 'sc' ),
42 'not_found' => __( 'Not found', 'sc' ),
43 'not_found_in_trash' => __( 'Not found in Trash', 'sc' ),
44 'featured_image' => __( 'Featured Image', 'sc' ),
45 'set_featured_image' => __( 'Set featured image', 'sc' ),
46 'remove_featured_image' => __( 'Remove featured image', 'sc' ),
47 'use_featured_image' => __( 'Use as featured image', 'sc' ),
48 'insert_into_item' => __( 'Insert into shortcode', 'sc' ),
49 'uploaded_to_this_item' => __( 'Uploaded to this shortcode', 'sc' ),
50 'items_list' => __( 'Shortcodes list', 'sc' ),
51 'items_list_navigation' => __( 'Shortcodes list navigation', 'sc' ),
52 'filter_items_list' => __( 'Filter shortcodes list', 'sc' ),
53 );
54
55 $args = array(
56 'label' => __( 'Shortcode', 'sc' ),
57 'labels' => $labels,
58 'supports' => false,
59 'taxonomies' => array( 'sc_tag' ),
60 'hierarchical' => false,
61 'public' => false,
62 'show_ui' => true,
63 'show_in_menu' => true,
64 'menu_position' => 25,
65 'menu_icon' => '',
66 'show_in_admin_bar' => true,
67 'show_in_nav_menus' => true,
68 'can_export' => true,
69 'has_archive' => false,
70 'exclude_from_search' => true,
71 'publicly_queryable' => false,
72 'show_in_rest' => false,
73 'map_meta_cap' => true,
74 'capability_type' => 'shortcoder',
75 );
76
77 register_post_type( SC_POST_TYPE, $args );
78
79 }
80
81 public static function register_taxonomy(){
82
83 $labels = array(
84 'name' => _x( 'Tags', 'Taxonomy General Name', 'sc' ),
85 'singular_name' => _x( 'Tag', 'Taxonomy Singular Name', 'sc' ),
86 'menu_name' => __( 'Tags', 'sc' ),
87 'all_items' => __( 'All Tags', 'sc' ),
88 'parent_item' => __( 'Parent Tag', 'sc' ),
89 'parent_item_colon' => __( 'Parent Tag:', 'sc' ),
90 'new_item_name' => __( 'New Tag Name', 'sc' ),
91 'add_new_item' => __( 'Add New Tag', 'sc' ),
92 'edit_item' => __( 'Edit Tag', 'sc' ),
93 'update_item' => __( 'Update Tag', 'sc' ),
94 'view_item' => __( 'View Tag', 'sc' ),
95 'separate_items_with_commas' => __( 'Separate tags with commas', 'sc' ),
96 'add_or_remove_items' => __( 'Add or remove tags', 'sc' ),
97 'choose_from_most_used' => __( 'Choose from the most used', 'sc' ),
98 'popular_items' => __( 'Popular Tags', 'sc' ),
99 'search_items' => __( 'Search Tags', 'sc' ),
100 'not_found' => __( 'Not Found', 'sc' ),
101 'no_terms' => __( 'No tags', 'sc' ),
102 'items_list' => __( 'Tags list', 'sc' ),
103 'items_list_navigation' => __( 'Tags list navigation', 'sc' ),
104 );
105 $args = array(
106 'labels' => $labels,
107 'hierarchical' => false,
108 'public' => false,
109 'show_ui' => true,
110 'show_admin_column' => true,
111 'show_in_nav_menus' => false,
112 'show_tagcloud' => false,
113 'show_in_rest' => false,
114 );
115
116 register_taxonomy( 'sc_tag', array( SC_POST_TYPE ), $args );
117
118 }
119
120 public static function is_sc_admin_page(){
121
122 $screen = get_current_screen();
123
124 if( $screen && $screen->post_type == SC_POST_TYPE ){
125 return true;
126 }else{
127 return false;
128 }
129
130 }
131
132 public static function inline_js_variables(){
133
134 return array(
135 'sc_version' => SC_VERSION,
136 'ajax_url' => get_admin_url() . 'admin-ajax.php',
137 'screen' => get_current_screen(),
138 'text_editor_switch_notice' => __( 'Switching editor will refresh the page. Please save your changes before refreshing. Do you want to refresh the page now ?', 'sc' )
139 );
140
141 }
142
143 public static function enqueue_scripts( $hook ){
144
145 wp_enqueue_style( 'sc-icon-css', SC_ADMIN_URL . 'css/menu-icon.css', array(), SC_VERSION );
146
147 if( !self::is_sc_admin_page() ){
148 return false;
149 }
150
151 wp_enqueue_style( 'sc-admin-css', SC_ADMIN_URL . 'css/style.css', array(), SC_VERSION );
152
153 wp_enqueue_script( 'jquery' );
154 wp_enqueue_script( 'sc-admin-js', SC_ADMIN_URL . 'js/script.js', array( 'jquery' ), SC_VERSION );
155
156 wp_localize_script( 'sc-admin-js', 'SC_VARS', self::inline_js_variables() );
157
158 }
159
160 public static function admin_ajax(){
161
162 $g = self::clean_get();
163 $do = $g[ 'do' ];
164
165 if( $do == 'close_changelog' ){
166 update_option( 'shortcoder_last_changelog', SC_VERSION );
167 echo 'done';
168 }
169
170 die( 0 );
171
172 }
173
174 public static function changelog(){
175
176 if( !self::is_sc_admin_page() ){
177 return false;
178 }
179
180 $last_changelog = get_option( 'shortcoder_last_changelog' );
181
182 if( $last_changelog && version_compare( $last_changelog, SC_VERSION, '>=' ) ){
183 return false;
184 }
185
186 $response = wp_remote_get( 'https://raw.githubusercontent.com/vaakash/vaakash.github.io/master/misc/shortcoder/changelogs/' . SC_VERSION . '.html' );
187 $changelog = false;
188
189 if( !is_wp_error( $response ) && $response[ 'response' ][ 'code' ] == 200 ){
190 $changelog = wp_remote_retrieve_body( $response );
191 }
192
193 if( !$changelog ){
194 update_option( 'shortcoder_last_changelog', SC_VERSION );
195 return false;
196 }
197
198 echo '<div class="sc_changelog"><main>
199 <article>' . $changelog . '</article>
200 <footer><button href="#" class="button button-primary dismiss_btn">' . __( 'Continue using Shortcoder', 'sc' ) . '</a></footer>
201 </main></div>';
202
203 }
204
205 public static function import_export(){
206
207 if( !self::is_sc_admin_page() ){
208 return false;
209 }
210
211 $screen = get_current_screen();
212 if( $screen->base != 'edit' ){
213 return false;
214 }
215
216 echo '<div id="ie_content" class="hidden"><div>
217 <div id="contextual-help-back"></div>
218 <div id="contextual-help-columns">
219 <div class="contextual-help-tabs">
220 <ul>
221 <li class="active"><a href="#export-tab" aria-controls="export-tab">Export</a></li>
222 <li><a href="#import-tab" aria-controls="import-tab">Import</a></li>
223 <li><a href="#import-others-tab" aria-controls="import-others-tab">Import from other sources</a></li>
224 </ul>
225 </div>
226 <div class="contextual-help-sidebar"><p><a href="https://www.aakashweb.com/docs/shortcoder-doc/" target="_blank">Documentation</a></p></div>
227 <div class="contextual-help-tabs-wrap">
228 <div id="export-tab" class="help-tab-content active">
229 <h3>' . __( 'Export', 'sc' ) . '</h3><p>' . __( 'WordPress has a native exporter tool which can be used to export shortcoder data. Navigate to <code>Tools -> Export</code> and select "Shortcoder" as the content to export.', 'sc' ) . '</p>
230 <a href="' . admin_url( 'export.php' ) . '" class="button button-primary">' . __( 'Go to export page', 'sc' ) . '</a>
231 </div>
232 <div id="import-tab" class="help-tab-content">
233 <h3>' . __( 'Import', 'sc' ) . '</h3><p>' . __( 'The XML file downloaded through the native export process can be imported via WordPress\'s own import tool. Navigate to <code>Tools -> Import</code>, install the importer plugin if not installed and run the importer under WordPress section.', 'sc' ) . '</p>
234 <a href="' . admin_url( 'import.php' ) . '" class="button button-primary">' . __( 'Go to import page', 'sc' ) . '</a>
235 </div>
236 <div id="import-others-tab" class="help-tab-content">
237 <h3>' . __( 'Import from other sources', 'sc' ) . '</h3><p>' . __( 'To import from other sources like CSV, excel please read the below linked documentation.', 'sc' ) . '</p>
238 <a href="https://www.aakashweb.com/docs/shortcoder-doc/import-export/" target="_blank" class="button button-primary">' . __( 'Open documentation', 'sc' ) . '</a>
239 </div>
240 </div>
241 </div>
242 </div></div>';
243
244 }
245
246 public static function clean_get(){
247
248 foreach( $_GET as $k => $v ){
249 $_GET[$k] = sanitize_text_field( $v );
250 }
251
252 return $_GET;
253 }
254
255 }
256
257 SC_Admin::init();
258
259 ?>