PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.0.1
Shortcoder — Create Shortcodes for Anything v5.0.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
216 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( 'wp_ajax_sc_admin_ajax', array( __class__, 'admin_ajax' ) );
18
19 }
20
21 public static function register_post_type(){
22
23 $labels = array(
24 'name' => _x( 'Shortcoder', 'Post Type General Name', 'sc' ),
25 'singular_name' => _x( 'Shortcode', 'Post Type Singular Name', 'sc' ),
26 'menu_name' => __( 'Shortcoder', 'sc' ),
27 'name_admin_bar' => __( 'Shortcode', 'sc' ),
28 'archives' => __( 'Shortcode Archives', 'sc' ),
29 'attributes' => __( 'Shortcode Attributes', 'sc' ),
30 'parent_item_colon' => __( 'Parent Shortcode:', 'sc' ),
31 'all_items' => __( 'All Shortcodes', 'sc' ),
32 'add_new_item' => __( 'Create shortcode', 'sc' ),
33 'add_new' => __( 'Create shortcode', 'sc' ),
34 'new_item' => __( 'New Shortcode', 'sc' ),
35 'edit_item' => __( 'Edit Shortcode', 'sc' ),
36 'update_item' => __( 'Update Shortcode', 'sc' ),
37 'view_item' => __( 'View Shortcode', 'sc' ),
38 'view_items' => __( 'View Shortcodes', 'sc' ),
39 'search_items' => __( 'Search Shortcode', 'sc' ),
40 'not_found' => __( 'Not found', 'sc' ),
41 'not_found_in_trash' => __( 'Not found in Trash', 'sc' ),
42 'featured_image' => __( 'Featured Image', 'sc' ),
43 'set_featured_image' => __( 'Set featured image', 'sc' ),
44 'remove_featured_image' => __( 'Remove featured image', 'sc' ),
45 'use_featured_image' => __( 'Use as featured image', 'sc' ),
46 'insert_into_item' => __( 'Insert into shortcode', 'sc' ),
47 'uploaded_to_this_item' => __( 'Uploaded to this shortcode', 'sc' ),
48 'items_list' => __( 'Shortcodes list', 'sc' ),
49 'items_list_navigation' => __( 'Shortcodes list navigation', 'sc' ),
50 'filter_items_list' => __( 'Filter shortcodes list', 'sc' ),
51 );
52
53 $args = array(
54 'label' => __( 'Shortcode', 'sc' ),
55 'labels' => $labels,
56 'supports' => false,
57 'taxonomies' => array( 'sc_tag' ),
58 'hierarchical' => false,
59 'public' => false,
60 'show_ui' => true,
61 'show_in_menu' => true,
62 'menu_position' => 25,
63 'menu_icon' => '',
64 'show_in_admin_bar' => true,
65 'show_in_nav_menus' => true,
66 'can_export' => true,
67 'has_archive' => false,
68 'exclude_from_search' => true,
69 'publicly_queryable' => false,
70 'show_in_rest' => false,
71 'map_meta_cap' => true,
72 'capability_type' => 'shortcoder',
73 );
74
75 register_post_type( SC_POST_TYPE, $args );
76
77 }
78
79 public static function register_taxonomy(){
80
81 $labels = array(
82 'name' => _x( 'Tags', 'Taxonomy General Name', 'sc' ),
83 'singular_name' => _x( 'Tag', 'Taxonomy Singular Name', 'sc' ),
84 'menu_name' => __( 'Tags', 'sc' ),
85 'all_items' => __( 'All Tags', 'sc' ),
86 'parent_item' => __( 'Parent Tag', 'sc' ),
87 'parent_item_colon' => __( 'Parent Tag:', 'sc' ),
88 'new_item_name' => __( 'New Tag Name', 'sc' ),
89 'add_new_item' => __( 'Add New Tag', 'sc' ),
90 'edit_item' => __( 'Edit Tag', 'sc' ),
91 'update_item' => __( 'Update Tag', 'sc' ),
92 'view_item' => __( 'View Tag', 'sc' ),
93 'separate_items_with_commas' => __( 'Separate tags with commas', 'sc' ),
94 'add_or_remove_items' => __( 'Add or remove tags', 'sc' ),
95 'choose_from_most_used' => __( 'Choose from the most used', 'sc' ),
96 'popular_items' => __( 'Popular Tags', 'sc' ),
97 'search_items' => __( 'Search Tags', 'sc' ),
98 'not_found' => __( 'Not Found', 'sc' ),
99 'no_terms' => __( 'No tags', 'sc' ),
100 'items_list' => __( 'Tags list', 'sc' ),
101 'items_list_navigation' => __( 'Tags list navigation', 'sc' ),
102 );
103 $args = array(
104 'labels' => $labels,
105 'hierarchical' => false,
106 'public' => false,
107 'show_ui' => true,
108 'show_admin_column' => true,
109 'show_in_nav_menus' => false,
110 'show_tagcloud' => false,
111 'show_in_rest' => false,
112 );
113
114 register_taxonomy( 'sc_tag', array( SC_POST_TYPE ), $args );
115
116 }
117
118 public static function is_sc_admin_page(){
119
120 $screen = get_current_screen();
121
122 if( $screen && $screen->post_type == SC_POST_TYPE ){
123 return true;
124 }else{
125 return false;
126 }
127
128 }
129
130 public static function inline_js_variables(){
131
132 return array(
133 'sc_version' => SC_VERSION,
134 'ajax_url' => get_admin_url() . 'admin-ajax.php',
135 'screen' => get_current_screen(),
136 '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' )
137 );
138
139 }
140
141 public static function enqueue_scripts( $hook ){
142
143 wp_enqueue_style( 'sc-icon-css', SC_ADMIN_URL . 'css/menu-icon.css', array(), SC_VERSION );
144
145 if( !self::is_sc_admin_page() ){
146 return false;
147 }
148
149 wp_enqueue_style( 'sc-admin-css', SC_ADMIN_URL . 'css/style.css', array(), SC_VERSION );
150
151 wp_enqueue_script( 'jquery' );
152 wp_enqueue_script( 'sc-admin-js', SC_ADMIN_URL . 'js/script.js', array( 'jquery' ), SC_VERSION );
153
154 wp_localize_script( 'sc-admin-js', 'SC_VARS', self::inline_js_variables() );
155
156 }
157
158 public static function admin_ajax(){
159
160 $g = self::clean_get();
161 $do = $g[ 'do' ];
162
163 if( $do == 'close_changelog' ){
164 update_option( 'shortcoder_last_changelog', SC_VERSION );
165 echo 'done';
166 }
167
168 die( 0 );
169
170 }
171
172 public static function changelog(){
173
174 if( !self::is_sc_admin_page() ){
175 return false;
176 }
177
178 $last_changelog = get_option( 'shortcoder_last_changelog' );
179
180 if( $last_changelog && version_compare( $last_changelog, SC_VERSION, '>=' ) ){
181 return false;
182 }
183
184 $response = wp_remote_get( 'https://vaakash.github.io/misc/shortcoder/changelogs/' . SC_VERSION . '.html' );
185 $changelog = false;
186
187 if( !is_wp_error( $response ) && $response[ 'response' ][ 'code' ] == 200 ){
188 $changelog = wp_remote_retrieve_body( $response );
189 }
190
191 if( !$changelog ){
192 update_option( 'shortcoder_last_changelog', SC_VERSION );
193 return false;
194 }
195
196 echo '<div class="sc_changelog"><main>
197 <article>' . $changelog . '</article>
198 <footer><button href="#" class="button button-primary dismiss_btn">' . __( 'Continue using Shortcoder', 'sc' ) . '</a></footer>
199 </main></div>';
200
201 }
202
203 public static function clean_get(){
204
205 foreach( $_GET as $k => $v ){
206 $_GET[$k] = sanitize_text_field( $v );
207 }
208
209 return $_GET;
210 }
211
212 }
213
214 SC_Admin::init();
215
216 ?>