css
11 months ago
font
11 months ago
images
11 months ago
js
11 months ago
admin.php
11 months ago
edit.php
11 months ago
form.php
11 months ago
insert.php
11 months ago
manage.php
11 months ago
settings.php
11 months ago
tools.php
11 months ago
admin.php
302 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 | if( !current_user_can( 'edit_shortcoders' ) ){ |
| 186 | wp_die(); |
| 187 | } |
| 188 | |
| 189 | $g = self::clean_get(); |
| 190 | $do = $g[ 'do' ]; |
| 191 | |
| 192 | if( $do == 'close_changelog' ){ |
| 193 | update_option( 'shortcoder_last_changelog', SC_VERSION ); |
| 194 | echo 'done'; |
| 195 | } |
| 196 | |
| 197 | wp_die(); |
| 198 | |
| 199 | } |
| 200 | |
| 201 | public static function changelog(){ |
| 202 | |
| 203 | if( !self::is_sc_admin_page() ){ |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | $last_changelog = get_option( 'shortcoder_last_changelog' ); |
| 208 | |
| 209 | if( $last_changelog && version_compare( $last_changelog, SC_VERSION, '>=' ) ){ |
| 210 | return false; |
| 211 | } |
| 212 | |
| 213 | $response = wp_remote_get( 'https://raw.githubusercontent.com/vaakash/vaakash.github.io/master/misc/shortcoder/changelogs/' . SC_VERSION . '.html' ); |
| 214 | $changelog = false; |
| 215 | |
| 216 | if( !is_wp_error( $response ) && $response[ 'response' ][ 'code' ] == 200 ){ |
| 217 | $changelog = wp_remote_retrieve_body( $response ); |
| 218 | } |
| 219 | |
| 220 | if( !$changelog ){ |
| 221 | update_option( 'shortcoder_last_changelog', SC_VERSION ); |
| 222 | return false; |
| 223 | } |
| 224 | |
| 225 | echo '<div class="sc_changelog"><main> |
| 226 | <article>' . wp_kses_post( $changelog ) . '</article> |
| 227 | <footer><button href="#" class="button button-primary dismiss_btn">' . esc_html__( 'Continue using Shortcoder', 'shortcoder' ) . '</a></footer> |
| 228 | </main></div>'; |
| 229 | |
| 230 | } |
| 231 | |
| 232 | public static function import_export(){ |
| 233 | |
| 234 | if( !self::is_sc_admin_page() ){ |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | $screen = get_current_screen(); |
| 239 | if( $screen->base != 'edit' ){ |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | echo '<div id="ie_content" class="hidden"><div> |
| 244 | <div id="contextual-help-back"></div> |
| 245 | <div id="contextual-help-columns"> |
| 246 | <div class="contextual-help-tabs"> |
| 247 | <ul> |
| 248 | <li class="active"><a href="#export-tab" aria-controls="export-tab">' . esc_html__( 'Export', 'shortcoder' ) . '</a></li> |
| 249 | <li><a href="#import-tab" aria-controls="import-tab">' . esc_html__( 'Import', 'shortcoder' ) . '</a></li> |
| 250 | <li><a href="#import-others-tab" aria-controls="import-others-tab">' . esc_html__( 'Import from other sources', 'shortcoder' ) . '</a></li> |
| 251 | </ul> |
| 252 | </div> |
| 253 | <div class="contextual-help-sidebar"><p><a href="https://www.aakashweb.com/docs/shortcoder/" target="_blank">' . esc_html__( 'Documentation', 'shortcoder' ) . '</a></p></div> |
| 254 | <div class="contextual-help-tabs-wrap"> |
| 255 | <div id="export-tab" class="help-tab-content active"> |
| 256 | <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> |
| 257 | <a href="' . esc_url( admin_url( 'export.php' ) ) . '" class="button button-primary">' . esc_html__( 'Go to export page', 'shortcoder' ) . '</a> |
| 258 | </div> |
| 259 | <div id="import-tab" class="help-tab-content"> |
| 260 | <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> |
| 261 | <a href="' . esc_url( admin_url( 'import.php' ) ) . '" class="button button-primary">' . esc_html__( 'Go to import page', 'shortcoder' ) . '</a> |
| 262 | </div> |
| 263 | <div id="import-others-tab" class="help-tab-content"> |
| 264 | <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> |
| 265 | <a href="https://www.aakashweb.com/docs/shortcoder/import-export/" target="_blank" class="button button-primary">' . esc_html__( 'Open documentation', 'shortcoder' ) . '</a> |
| 266 | </div> |
| 267 | </div> |
| 268 | </div> |
| 269 | </div></div>'; |
| 270 | |
| 271 | } |
| 272 | |
| 273 | public static function action_links( $links ){ |
| 274 | array_unshift( $links, '<a href="'. esc_url( admin_url( 'edit.php?post_type=shortcoder') ) .'">' . esc_html__( 'View shortcodes', 'shortcoder' ) . '</a>' ); |
| 275 | 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>' ); |
| 276 | return $links; |
| 277 | } |
| 278 | |
| 279 | public static function upgrade_menu(){ |
| 280 | 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 ); |
| 281 | } |
| 282 | |
| 283 | public static function clean_get(){ |
| 284 | |
| 285 | foreach( $_GET as $k => $v ){ |
| 286 | $_GET[$k] = sanitize_text_field( $v ); |
| 287 | } |
| 288 | |
| 289 | return $_GET; |
| 290 | } |
| 291 | |
| 292 | public static function clean_post(){ |
| 293 | |
| 294 | return stripslashes_deep( $_POST ); |
| 295 | |
| 296 | } |
| 297 | |
| 298 | } |
| 299 | |
| 300 | SC_Admin::init(); |
| 301 | |
| 302 | ?> |