PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.3
Shortcoder — Create Shortcodes for Anything v5.3
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
266 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 inline_js_variables(){
135
136 return array(
137 'sc_version' => SC_VERSION,
138 'ajax_url' => get_admin_url() . 'admin-ajax.php',
139 'screen' => get_current_screen(),
140 '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' )
141 );
142
143 }
144
145 public static function enqueue_scripts( $hook ){
146
147 wp_enqueue_style( 'sc-icon-css', SC_ADMIN_URL . 'css/menu-icon.css', array(), SC_VERSION );
148
149 if( !self::is_sc_admin_page() ){
150 return false;
151 }
152
153 wp_enqueue_style( 'sc-admin-css', SC_ADMIN_URL . 'css/style.css', array(), SC_VERSION );
154
155 wp_enqueue_script( 'jquery' );
156 wp_enqueue_script( 'sc-admin-js', SC_ADMIN_URL . 'js/script.js', array( 'jquery' ), SC_VERSION );
157
158 wp_localize_script( 'sc-admin-js', 'SC_VARS', self::inline_js_variables() );
159
160 }
161
162 public static function admin_ajax(){
163
164 $g = self::clean_get();
165 $do = $g[ 'do' ];
166
167 if( $do == 'close_changelog' ){
168 update_option( 'shortcoder_last_changelog', SC_VERSION );
169 echo 'done';
170 }
171
172 die( 0 );
173
174 }
175
176 public static function changelog(){
177
178 if( !self::is_sc_admin_page() ){
179 return false;
180 }
181
182 $last_changelog = get_option( 'shortcoder_last_changelog' );
183
184 if( $last_changelog && version_compare( $last_changelog, SC_VERSION, '>=' ) ){
185 return false;
186 }
187
188 $response = wp_remote_get( 'https://raw.githubusercontent.com/vaakash/vaakash.github.io/master/misc/shortcoder/changelogs/' . SC_VERSION . '.html' );
189 $changelog = false;
190
191 if( !is_wp_error( $response ) && $response[ 'response' ][ 'code' ] == 200 ){
192 $changelog = wp_remote_retrieve_body( $response );
193 }
194
195 if( !$changelog ){
196 update_option( 'shortcoder_last_changelog', SC_VERSION );
197 return false;
198 }
199
200 echo '<div class="sc_changelog"><main>
201 <article>' . $changelog . '</article>
202 <footer><button href="#" class="button button-primary dismiss_btn">' . __( 'Continue using Shortcoder', 'shortcoder' ) . '</a></footer>
203 </main></div>';
204
205 }
206
207 public static function import_export(){
208
209 if( !self::is_sc_admin_page() ){
210 return false;
211 }
212
213 $screen = get_current_screen();
214 if( $screen->base != 'edit' ){
215 return false;
216 }
217
218 echo '<div id="ie_content" class="hidden"><div>
219 <div id="contextual-help-back"></div>
220 <div id="contextual-help-columns">
221 <div class="contextual-help-tabs">
222 <ul>
223 <li class="active"><a href="#export-tab" aria-controls="export-tab">' . __( 'Export', 'shortcoder' ) . '</a></li>
224 <li><a href="#import-tab" aria-controls="import-tab">' . __( 'Import', 'shortcoder' ) . '</a></li>
225 <li><a href="#import-others-tab" aria-controls="import-others-tab">' . __( 'Import from other sources', 'shortcoder' ) . '</a></li>
226 </ul>
227 </div>
228 <div class="contextual-help-sidebar"><p><a href="https://www.aakashweb.com/docs/shortcoder-doc/" target="_blank">' . __( 'Documentation', 'shortcoder' ) . '</a></p></div>
229 <div class="contextual-help-tabs-wrap">
230 <div id="export-tab" class="help-tab-content active">
231 <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>
232 <a href="' . admin_url( 'export.php' ) . '" class="button button-primary">' . __( 'Go to export page', 'shortcoder' ) . '</a>
233 </div>
234 <div id="import-tab" class="help-tab-content">
235 <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>
236 <a href="' . admin_url( 'import.php' ) . '" class="button button-primary">' . __( 'Go to import page', 'shortcoder' ) . '</a>
237 </div>
238 <div id="import-others-tab" class="help-tab-content">
239 <h3>' . __( 'Import from other sources', 'shortcoder' ) . '</h3><p>' . __( 'To import from other sources like CSV, excel please read the below linked documentation.', 'shortcoder' ) . '</p>
240 <a href="https://www.aakashweb.com/docs/shortcoder-doc/import-export/" target="_blank" class="button button-primary">' . __( 'Open documentation', 'shortcoder' ) . '</a>
241 </div>
242 </div>
243 </div>
244 </div></div>';
245
246 }
247
248 public static function action_links( $links ){
249 array_unshift( $links, '<a href="'. esc_url( admin_url( 'edit.php?post_type=shortcoder') ) .'">' . __( 'Manage shortcodes', 'shortcoder' ) . '</a>' );
250 return $links;
251 }
252
253 public static function clean_get(){
254
255 foreach( $_GET as $k => $v ){
256 $_GET[$k] = sanitize_text_field( $v );
257 }
258
259 return $_GET;
260 }
261
262 }
263
264 SC_Admin::init();
265
266 ?>