PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.6
Shortcoder — Create Shortcodes for Anything v5.6
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 4 years ago font 4 years ago images 4 years ago js 4 years ago admin.php 4 years ago edit.php 4 years ago form.php 4 years ago insert.php 4 years ago manage.php 4 years ago settings.php 4 years ago tools.php 4 years ago
admin.php
288 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 add_filter( 'plugin_action_links_' . SC_BASE_NAME, array( __CLASS__, 'action_links' ) );
22
23 }
24
25 public static function register_post_type(){
26
27 $labels = array(
28 'name' => _x( 'Shortcoder', 'Post Type General Name', 'shortcoder' ),
29 'singular_name' => _x( 'Shortcode', 'Post Type Singular Name', 'shortcoder' ),
30 'menu_name' => __( 'Shortcoder', 'shortcoder' ),
31 'name_admin_bar' => __( 'Shortcode', 'shortcoder' ),
32 'archives' => __( 'Shortcode Archives', 'shortcoder' ),
33 'attributes' => __( 'Shortcode Attributes', 'shortcoder' ),
34 'parent_item_colon' => __( 'Parent Shortcode:', 'shortcoder' ),
35 'all_items' => __( 'All Shortcodes', 'shortcoder' ),
36 'add_new_item' => __( 'Create shortcode', 'shortcoder' ),
37 'add_new' => __( 'Create shortcode', 'shortcoder' ),
38 'new_item' => __( 'New Shortcode', 'shortcoder' ),
39 'edit_item' => __( 'Edit Shortcode', 'shortcoder' ),
40 'update_item' => __( 'Update Shortcode', 'shortcoder' ),
41 'view_item' => __( 'View Shortcode', 'shortcoder' ),
42 'view_items' => __( 'View Shortcodes', 'shortcoder' ),
43 'search_items' => __( 'Search Shortcode', 'shortcoder' ),
44 'not_found' => __( 'Not found', 'shortcoder' ),
45 'not_found_in_trash' => __( 'Not found in Trash', 'shortcoder' ),
46 'featured_image' => __( 'Featured Image', 'shortcoder' ),
47 'set_featured_image' => __( 'Set featured image', 'shortcoder' ),
48 'remove_featured_image' => __( 'Remove featured image', 'shortcoder' ),
49 'use_featured_image' => __( 'Use as featured image', 'shortcoder' ),
50 'insert_into_item' => __( 'Insert into shortcode', 'shortcoder' ),
51 'uploaded_to_this_item' => __( 'Uploaded to this shortcode', 'shortcoder' ),
52 'items_list' => __( 'Shortcodes list', 'shortcoder' ),
53 'items_list_navigation' => __( 'Shortcodes list navigation', 'shortcoder' ),
54 'filter_items_list' => __( 'Filter shortcodes list', 'shortcoder' ),
55 );
56
57 $args = array(
58 'label' => __( 'Shortcode', 'shortcoder' ),
59 'labels' => $labels,
60 'supports' => false,
61 'taxonomies' => array( 'sc_tag' ),
62 'hierarchical' => false,
63 'public' => false,
64 'show_ui' => true,
65 'show_in_menu' => true,
66 'menu_position' => 25,
67 'menu_icon' => '',
68 'show_in_admin_bar' => true,
69 'show_in_nav_menus' => true,
70 'can_export' => true,
71 'has_archive' => false,
72 'exclude_from_search' => true,
73 'publicly_queryable' => false,
74 'show_in_rest' => false,
75 'map_meta_cap' => true,
76 'capability_type' => 'shortcoder',
77 );
78
79 register_post_type( SC_POST_TYPE, $args );
80
81 }
82
83 public static function register_taxonomy(){
84
85 $labels = array(
86 'name' => _x( 'Tags', 'Taxonomy General Name', 'shortcoder' ),
87 'singular_name' => _x( 'Tag', 'Taxonomy Singular Name', 'shortcoder' ),
88 'menu_name' => __( 'Tags', 'shortcoder' ),
89 'all_items' => __( 'All Tags', 'shortcoder' ),
90 'parent_item' => __( 'Parent Tag', 'shortcoder' ),
91 'parent_item_colon' => __( 'Parent Tag:', 'shortcoder' ),
92 'new_item_name' => __( 'New Tag Name', 'shortcoder' ),
93 'add_new_item' => __( 'Add New Tag', 'shortcoder' ),
94 'edit_item' => __( 'Edit Tag', 'shortcoder' ),
95 'update_item' => __( 'Update Tag', 'shortcoder' ),
96 'view_item' => __( 'View Tag', 'shortcoder' ),
97 'separate_items_with_commas' => __( 'Separate tags with commas', 'shortcoder' ),
98 'add_or_remove_items' => __( 'Add or remove tags', 'shortcoder' ),
99 'choose_from_most_used' => __( 'Choose from the most used', 'shortcoder' ),
100 'popular_items' => __( 'Popular Tags', 'shortcoder' ),
101 'search_items' => __( 'Search Tags', 'shortcoder' ),
102 'not_found' => __( 'Not Found', 'shortcoder' ),
103 'no_terms' => __( 'No tags', 'shortcoder' ),
104 'items_list' => __( 'Tags list', 'shortcoder' ),
105 'items_list_navigation' => __( 'Tags list navigation', 'shortcoder' ),
106 );
107 $args = array(
108 'labels' => $labels,
109 'hierarchical' => false,
110 'public' => false,
111 'show_ui' => true,
112 'show_admin_column' => true,
113 'show_in_nav_menus' => false,
114 'show_tagcloud' => false,
115 'show_in_rest' => false,
116 );
117
118 register_taxonomy( 'sc_tag', array( SC_POST_TYPE ), $args );
119
120 }
121
122 public static function is_sc_admin_page(){
123
124 $screen = get_current_screen();
125
126 if( $screen && $screen->post_type == SC_POST_TYPE ){
127 return true;
128 }else{
129 return false;
130 }
131
132 }
133
134 public static function is_edit_page( $new_edit = null ){
135
136 global $pagenow;
137
138 if (!is_admin()) return false;
139
140 if( $new_edit == 'edit' ){
141 return in_array( $pagenow, array( 'post.php' ) );
142 }elseif( $new_edit == 'new' ){
143 return in_array( $pagenow, array( 'post-new.php' ) );
144 }else{
145 return in_array( $pagenow, array( 'post.php', 'post-new.php' ) );
146 }
147
148 }
149
150 public static function inline_js_variables(){
151
152 return array(
153 'sc_version' => SC_VERSION,
154 'ajax_url' => get_admin_url() . 'admin-ajax.php',
155 'screen' => get_current_screen(),
156 'text_editor_switch_notice' => __( 'Switching editor will refresh the page. Please save your changes before refreshing. Do you want to refresh the page now ?', 'shortcoder' )
157 );
158
159 }
160
161 public static function enqueue_scripts( $hook ){
162
163 wp_enqueue_style( 'sc-icon-css', SC_ADMIN_URL . 'css/menu-icon.css', array(), SC_VERSION );
164
165 if( !self::is_sc_admin_page() || $hook == 'shortcoder_page_settings' ){
166 return false;
167 }
168
169 wp_enqueue_style( 'sc-admin-css', SC_ADMIN_URL . 'css/style.css', array(), SC_VERSION );
170
171 wp_enqueue_script( 'jquery' );
172 wp_enqueue_script( 'sc-admin-js', SC_ADMIN_URL . 'js/script.js', array( 'jquery' ), SC_VERSION );
173
174 wp_localize_script( 'sc-admin-js', 'SC_VARS', self::inline_js_variables() );
175
176 }
177
178 public static function admin_ajax(){
179
180 $g = self::clean_get();
181 $do = $g[ 'do' ];
182
183 if( $do == 'close_changelog' ){
184 update_option( 'shortcoder_last_changelog', SC_VERSION );
185 echo 'done';
186 }
187
188 die( 0 );
189
190 }
191
192 public static function changelog(){
193
194 if( !self::is_sc_admin_page() ){
195 return false;
196 }
197
198 $last_changelog = get_option( 'shortcoder_last_changelog' );
199
200 if( $last_changelog && version_compare( $last_changelog, SC_VERSION, '>=' ) ){
201 return false;
202 }
203
204 $response = wp_remote_get( 'https://raw.githubusercontent.com/vaakash/vaakash.github.io/master/misc/shortcoder/changelogs/' . SC_VERSION . '.html' );
205 $changelog = false;
206
207 if( !is_wp_error( $response ) && $response[ 'response' ][ 'code' ] == 200 ){
208 $changelog = wp_remote_retrieve_body( $response );
209 }
210
211 if( !$changelog ){
212 update_option( 'shortcoder_last_changelog', SC_VERSION );
213 return false;
214 }
215
216 echo '<div class="sc_changelog"><main>
217 <article>' . $changelog . '</article>
218 <footer><button href="#" class="button button-primary dismiss_btn">' . __( 'Continue using Shortcoder', 'shortcoder' ) . '</a></footer>
219 </main></div>';
220
221 }
222
223 public static function import_export(){
224
225 if( !self::is_sc_admin_page() ){
226 return false;
227 }
228
229 $screen = get_current_screen();
230 if( $screen->base != 'edit' ){
231 return false;
232 }
233
234 echo '<div id="ie_content" class="hidden"><div>
235 <div id="contextual-help-back"></div>
236 <div id="contextual-help-columns">
237 <div class="contextual-help-tabs">
238 <ul>
239 <li class="active"><a href="#export-tab" aria-controls="export-tab">' . __( 'Export', 'shortcoder' ) . '</a></li>
240 <li><a href="#import-tab" aria-controls="import-tab">' . __( 'Import', 'shortcoder' ) . '</a></li>
241 <li><a href="#import-others-tab" aria-controls="import-others-tab">' . __( 'Import from other sources', 'shortcoder' ) . '</a></li>
242 </ul>
243 </div>
244 <div class="contextual-help-sidebar"><p><a href="https://www.aakashweb.com/docs/shortcoder/" target="_blank">' . __( 'Documentation', 'shortcoder' ) . '</a></p></div>
245 <div class="contextual-help-tabs-wrap">
246 <div id="export-tab" class="help-tab-content active">
247 <h3>' . __( 'Export', 'shortcoder' ) . '</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.', 'shortcoder' ) . '</p>
248 <a href="' . admin_url( 'export.php' ) . '" class="button button-primary">' . __( 'Go to export page', 'shortcoder' ) . '</a>
249 </div>
250 <div id="import-tab" class="help-tab-content">
251 <h3>' . __( 'Import', 'shortcoder' ) . '</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.', 'shortcoder' ) . '</p>
252 <a href="' . admin_url( 'import.php' ) . '" class="button button-primary">' . __( 'Go to import page', 'shortcoder' ) . '</a>
253 </div>
254 <div id="import-others-tab" class="help-tab-content">
255 <h3>' . __( 'Import from other sources', 'shortcoder' ) . '</h3><p>' . __( 'To import from other sources like CSV, excel please read the below linked documentation.', 'shortcoder' ) . '</p>
256 <a href="https://www.aakashweb.com/docs/shortcoder/import-export/" target="_blank" class="button button-primary">' . __( 'Open documentation', 'shortcoder' ) . '</a>
257 </div>
258 </div>
259 </div>
260 </div></div>';
261
262 }
263
264 public static function action_links( $links ){
265 array_unshift( $links, '<a href="'. esc_url( admin_url( 'edit.php?post_type=shortcoder') ) .'">' . __( 'Manage shortcodes', 'shortcoder' ) . '</a>' );
266 return $links;
267 }
268
269 public static function clean_get(){
270
271 foreach( $_GET as $k => $v ){
272 $_GET[$k] = sanitize_text_field( $v );
273 }
274
275 return $_GET;
276 }
277
278 public static function clean_post(){
279
280 return stripslashes_deep( $_POST );
281
282 }
283
284 }
285
286 SC_Admin::init();
287
288 ?>