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