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