| @@ -6,29 +6,20 @@ | ||
| 6 | 6 | * Build admin menu |
| 7 | 7 | */ |
| 8 | 8 | function sh_cd_build_admin_menu() { |
| 9 | 9 | |
| 10 | - $allowed_viewer = sh_cd_permission_role(); | |
| 10 | + add_menu_page( SH_CD_PLUGIN_NAME, SH_CD_PLUGIN_NAME, 'manage_options', 'sh-cd-shortcode-variables-main-menu', 'sh_cd_pages_your_shortcodes', 'dashicons-editor-kitchensink' ); | |
| 11 | 11 | |
| 12 | - add_menu_page( SH_CD_PLUGIN_NAME, SH_CD_PLUGIN_NAME, 'manage_options', 'sh-cd-shortcode-variables-main-menu', 'sh_cd_pages_your_shortcodes', 'dashicons-snippet-shortcodes' ); | |
| 13 | - | |
| 14 | 12 | // Hide duplicated sub menu (wee hack!) |
| 15 | 13 | add_submenu_page( 'sh-cd-shortcode-variables-main-menu', '', '', 'manage_options', 'sh-cd-shortcode-variables-main-menu', 'sh_cd_pages_your_shortcodes'); |
| 16 | 14 | |
| 17 | 15 | // Add sub menus |
| 18 | - add_submenu_page( 'sh-cd-shortcode-variables-main-menu', __( 'Your Shortcodes', SH_CD_SLUG ), __( 'Your shortcodes', SH_CD_SLUG ), $allowed_viewer, 'sh-cd-shortcode-variables-your-shortcodes', 'sh_cd_pages_your_shortcodes'); | |
| 19 | - add_submenu_page( 'sh-cd-shortcode-variables-main-menu', __( 'Premade Shortcodes', SH_CD_SLUG ), __( 'Premade shortcodes', SH_CD_SLUG ), $allowed_viewer, 'sh-cd-shortcode-variables-sub-premade', 'sh_cd_premade_shortcodes_page'); | |
| 16 | + add_submenu_page( 'sh-cd-shortcode-variables-main-menu', __( 'Your Shortcodes', SH_CD_SLUG ), __( 'Your shortcodes', SH_CD_SLUG ), 'manage_options', 'sh-cd-shortcode-variables-your-shortcodes', 'sh_cd_pages_your_shortcodes'); | |
| 17 | + add_submenu_page( 'sh-cd-shortcode-variables-main-menu', __( 'Premade Shortcodes', SH_CD_SLUG ), __( 'Premade shortcodes', SH_CD_SLUG ), 'manage_options', 'sh-cd-shortcode-variables-sub-premade', 'sh_cd_premade_shortcodes_page'); | |
| 20 | 18 | |
| 21 | - add_submenu_page( 'sh-cd-shortcode-variables-main-menu', __( 'Import / Export', SH_CD_SLUG ), __( 'Import / Export', SH_CD_SLUG ), 'manage_options', 'sh-cd-import', 'sh_cd_admin_page_import' ); | |
| 19 | + $menu_text = ( true === sh_cd_license_is_premium() ) ? __( 'Your License', SH_CD_SLUG ) : __( 'Upgrade to Premium', SH_CD_SLUG ); | |
| 22 | 20 | |
| 23 | - if( false === sh_cd_is_premium_plugin_activated() ) { | |
| 24 | - add_submenu_page( 'sh-cd-shortcode-variables-main-menu', '<i class="fa-solid fa-star"></i> ' . __( 'Upgrade to Premium', SH_CD_SLUG ), '<i class="fa-solid fa-star"></i> ' . __( 'Get Premium', SH_CD_SLUG ), 'manage_options', 'sh-cd-shortcode-variables-upgrade', 'sh_cd_page_upgrade'); | |
| 25 | - } | |
| 26 | - | |
| 27 | - do_action( 'sh-cd-admin-menu-upgrade' ); | |
| 28 | - | |
| 29 | - add_submenu_page( 'sh-cd-shortcode-variables-main-menu', __( 'Settings', SH_CD_SLUG ), __( 'Settings', SH_CD_SLUG ), 'manage_options', 'sh-cd-settings', 'sh_cd_settings_page_generic' ); | |
| 30 | - add_submenu_page( 'sh-cd-shortcode-variables-main-menu', __( 'Help', SH_CD_SLUG ), __( 'Help', SH_CD_SLUG ), 'manage_options', 'sh-cd-help', 'sh_cd_help_page' ); | |
| 21 | + add_submenu_page( 'sh-cd-shortcode-variables-main-menu', $menu_text, $menu_text, 'manage_options', 'sh-cd-shortcode-variables-license', 'sh_cd_advertise_pro'); | |
| 31 | 22 | } |
| 32 | 23 | add_action( 'admin_menu', 'sh_cd_build_admin_menu' ); |
| 33 | 24 | |
| 34 | 25 | /** |
| @@ -34,98 +25,28 @@ | ||
| 34 | 25 | /** |
| 35 | 26 | * Enqueue relevant CSS / JS |
| 36 | 27 | */ |
| 37 | 28 | function sh_cd_enqueue_scripts() { |
| 29 | + wp_enqueue_style( 'sh-cd', plugins_url( '../assets/css/sh-cd.css', __FILE__ ), [], SH_CD_PLUGIN_VERSION ) ; | |
| 30 | + wp_enqueue_style('fontawesome', 'https://use.fontawesome.com/releases/v5.7.2/css/all.css', [], SH_CD_PLUGIN_VERSION); | |
| 31 | + wp_enqueue_script( 'sh-cd', plugins_url( '../assets/js/sh-cd.js', __FILE__ ), [ 'jquery' ], SH_CD_PLUGIN_VERSION); | |
| 38 | 32 | |
| 39 | - wp_enqueue_style( 'sh-cd-dashicon', plugins_url( '../assets/css/sh-cd-dashicon.css', __FILE__ ), [], SH_CD_PLUGIN_VERSION ); | |
| 33 | + wp_localize_script( 'sh-cd', 'sh_cd', [ 'security' => wp_create_nonce( 'sh-cd-security' ), 'premium' => sh_cd_license_is_premium() ] ); | |
| 40 | 34 | |
| 41 | - // Allow marketing.js on any page so admin's can dismiss admin notices anywhere | |
| 42 | - wp_enqueue_script( 'sh-cd-marketing', plugins_url( '../assets/js/marketing.js', __FILE__ ), [ 'jquery' ], SH_CD_PLUGIN_VERSION, true ); | |
| 43 | - | |
| 44 | - if ( ! sh_cd_is_snippet_shortcodes_admin_page() ) { | |
| 45 | - return; | |
| 46 | - } | |
| 47 | - | |
| 48 | - $main_js_dependencies = [ 'jquery', 'sh-cd-clipboard' ]; | |
| 49 | - | |
| 50 | - // Tooltips | |
| 51 | - if ( sh_cd_tooltips_is_enabled() ) { | |
| 52 | - wp_enqueue_script( 'sh-cd-tooltip', plugins_url( '../assets/zerbratooltips/zebra_tooltips.min.js', __FILE__ ), [ ], SH_CD_PLUGIN_VERSION ); | |
| 53 | - wp_enqueue_style( 'sh-cd-tooltip', plugins_url( '../assets/zerbratooltips/zebra_tooltips.min.css', __FILE__ ), [], SH_CD_PLUGIN_VERSION ) ; | |
| 54 | - | |
| 55 | - $main_js_dependencies[] = 'sh-cd-tooltip'; | |
| 56 | - } | |
| 57 | - | |
| 58 | - // CSS | |
| 59 | - wp_enqueue_style( 'sh-cd', plugins_url( '../assets/css/sh-cd.css', __FILE__ ), [ 'sh-cd-dashicon' ], SH_CD_PLUGIN_VERSION ); | |
| 60 | - wp_enqueue_style( 'sh-cd-fontawesome', plugins_url( '../assets/fontawesome/css/fontawesome.min.css', __FILE__ ), [], SH_CD_PLUGIN_VERSION ); | |
| 61 | - wp_enqueue_style( 'sh-cd-fontawesome-solid', plugins_url( '../assets/fontawesome/css/solid.min.css', __FILE__ ), [ 'sh-cd-fontawesome' ], SH_CD_PLUGIN_VERSION ); | |
| 62 | - wp_enqueue_style( 'sh-cd-fontawesome-regular', plugins_url( '../assets/fontawesome/css/regular.min.css', __FILE__ ), [ 'sh-cd-fontawesome' ], SH_CD_PLUGIN_VERSION ); | |
| 63 | - wp_enqueue_style( 'sh-cd-fontawesome-brands', plugins_url( '../assets/fontawesome/css/brands.min.css', __FILE__ ), [ 'sh-cd-fontawesome' ], SH_CD_PLUGIN_VERSION ); | |
| 64 | - | |
| 65 | - // JS | |
| 66 | - wp_enqueue_script( 'sh-cd-clipboard', plugins_url( '../assets/js/clipboard.min.js', __FILE__ ), [], SH_CD_PLUGIN_VERSION, true ); | |
| 67 | - wp_enqueue_script( 'sh-cd', plugins_url( '../assets/js/sh-cd.js', __FILE__ ), $main_js_dependencies, SH_CD_PLUGIN_VERSION, true ); | |
| 68 | - wp_localize_script( 'sh-cd', 'sh_cd', sh_cd_js_config() ); | |
| 69 | - | |
| 70 | 35 | } |
| 71 | 36 | add_action( 'admin_enqueue_scripts', 'sh_cd_enqueue_scripts' ); |
| 72 | 37 | |
| 73 | 38 | /** |
| 74 | - * Determine if we are on a Snippet Shortcodes admin page | |
| 75 | - * | |
| 76 | - * @return bool | |
| 77 | - */ | |
| 78 | -function sh_cd_is_snippet_shortcodes_admin_page() { | |
| 79 | - | |
| 80 | - if ( true === empty( $_GET['page' ] ) ) { | |
| 81 | - return false; | |
| 82 | - } | |
| 83 | - | |
| 84 | - $known_admin_pages = apply_filters( 'sh-cd-admin-pages', [ 'sh-cd-shortcode-variables-main-menu', | |
| 85 | - 'sh-cd-shortcode-variables-your-shortcodes', | |
| 86 | - 'sh-cd-shortcode-variables-sub-premade', | |
| 87 | - 'sh-cd-import', | |
| 88 | - 'sh-cd-shortcode-variables-upgrade', | |
| 89 | - 'sh-cd-settings', | |
| 90 | - 'sh-cd-help' ] ); | |
| 91 | - | |
| 92 | - return in_array( $_GET['page'], $known_admin_pages ); | |
| 93 | -} | |
| 94 | - | |
| 95 | -/** | |
| 96 | - * Config for JS | |
| 97 | - * @return array | |
| 98 | - */ | |
| 99 | -function sh_cd_js_config() { | |
| 100 | - return [ 'editor' => sh_cd_default_editor_get(), | |
| 101 | - 'page' => false === empty( $_GET['page'] ) ? $_GET['page'] : '', | |
| 102 | - 'action' => false === empty( $_GET['action'] ) ? $_GET['action'] : '', | |
| 103 | - 'security' => wp_create_nonce( 'sh-cd-security' ), | |
| 104 | - 'premium' => sh_cd_is_premium(), | |
| 105 | - 'text-delete-confirm' => __( 'Are you sure you wish to delete this shortcode?', SH_CD_SLUG ), | |
| 106 | - 'text-add' => __( 'Add', SH_CD_SLUG ), | |
| 107 | - 'text-save' => __( 'Save', SH_CD_SLUG ), | |
| 108 | - 'text-saved' => __( 'Saved!', SH_CD_SLUG ), | |
| 109 | - 'text-editor-change' => __( 'Changing the editor will cause any unsaved changes to be lost. Please ensure you have saved your shortcode before proceeding.', SH_CD_SLUG ), | |
| 110 | - 'text-error' => __( 'Unfortunately something went wrong!', SH_CD_SLUG ), | |
| 111 | - 'tooltips-enabled' => sh_cd_tooltips_is_enabled() ? 'yes' : 'no', | |
| 112 | - ]; | |
| 113 | -} | |
| 114 | - | |
| 115 | -/** | |
| 116 | 39 | * Run installer on each version number change or install |
| 117 | 40 | */ |
| 118 | 41 | function sh_cd_upgrade() { |
| 119 | 42 | |
| 120 | - if ( true === update_option( 'sh-cd-version-number-2021', SH_CD_PLUGIN_VERSION ) ) { | |
| 43 | + if ( true === update_option( 'sh-cd-version-number-2020', SH_CD_PLUGIN_VERSION ) ) { | |
| 121 | 44 | |
| 122 | 45 | sh_cd_create_database_table(); |
| 123 | 46 | |
| 124 | 47 | sh_cd_create_database_table_multisite(); |
| 125 | 48 | |
| 126 | - sh_cd_create_database_table_revisions(); | |
| 127 | - | |
| 128 | 49 | do_action( 'sh-cd-upgrade' ); |
| 129 | 50 | } |
| 130 | 51 | } |
| 131 | 52 | add_action('admin_init', 'sh_cd_upgrade'); |
| @@ -135,16 +56,14 @@ | ||
| 135 | 56 | Ajax handler for toggling disable status of a shortcode |
| 136 | 57 | **/ |
| 137 | 58 | function sh_cd_ajax_toggle_status() { |
| 138 | 59 | |
| 139 | - if ( false === sh_cd_is_premium() ) { | |
| 60 | + if ( false === sh_cd_license_is_premium() ) { | |
| 140 | 61 | wp_send_json( 'not-premium' ); |
| 141 | 62 | } |
| 142 | 63 | |
| 143 | 64 | check_ajax_referer( 'sh-cd-security', 'security' ); |
| 144 | 65 | |
| 145 | - sh_cd_permission_check(); | |
| 146 | - | |
| 147 | 66 | $id = ( false === empty( $_POST['id'] ) ) ? (int) $_POST['id'] : NULL; |
| 148 | 67 | |
| 149 | 68 | if ( false === empty( $id ) ) { |
| 150 | 69 | |
| @@ -157,42 +76,18 @@ | ||
| 157 | 76 | } |
| 158 | 77 | add_action( 'wp_ajax_toggle_status', 'sh_cd_ajax_toggle_status' ); |
| 159 | 78 | |
| 160 | 79 | /** |
| 161 | -Ajax handler for deleting a shortcode | |
| 162 | - **/ | |
| 163 | -function sh_cd_ajax_delete_shortcode() { | |
| 164 | - | |
| 165 | - check_ajax_referer( 'sh-cd-security', 'security' ); | |
| 166 | - | |
| 167 | - sh_cd_permission_check(); | |
| 168 | - | |
| 169 | - $id = ( false === empty( $_POST['id'] ) ) ? (int) $_POST['id'] : NULL; | |
| 170 | - | |
| 171 | - if ( false === empty( $id ) ) { | |
| 172 | - | |
| 173 | - $result = sh_cd_db_shortcodes_delete( $id ); | |
| 174 | - | |
| 175 | - wp_send_json( [ 'id' => $id, 'ok' => $result ] ); | |
| 176 | - } | |
| 177 | - | |
| 178 | - wp_send_json( 'shortcode-not-found' ); | |
| 179 | -} | |
| 180 | -add_action( 'wp_ajax_delete_shortcode', 'sh_cd_ajax_delete_shortcode' ); | |
| 181 | - | |
| 182 | -/** | |
| 183 | 80 | Ajax handler for toggling disable status of a shortcode |
| 184 | 81 | **/ |
| 185 | 82 | function sh_cd_ajax_toggle_multisite() { |
| 186 | 83 | |
| 187 | - if ( false === sh_cd_is_multisite_enabled() ) { | |
| 84 | + if ( false === sh_cd_license_is_premium() ) { | |
| 188 | 85 | wp_send_json( 'not-premium' ); |
| 189 | 86 | } |
| 190 | 87 | |
| 191 | 88 | check_ajax_referer( 'sh-cd-security', 'security' ); |
| 192 | 89 | |
| 193 | - sh_cd_permission_check(); | |
| 194 | - | |
| 195 | 90 | $id = ( false === empty( $_POST['id'] ) ) ? (int) $_POST['id'] : NULL; |
| 196 | 91 | |
| 197 | 92 | if ( false === empty( $id ) ) { |
| 198 | 93 | |
| @@ -209,16 +104,14 @@ | ||
| 209 | 104 | Ajax handler for saving shortcode inline |
| 210 | 105 | **/ |
| 211 | 106 | function sh_cd_ajax_update_shortcode() { |
| 212 | 107 | |
| 213 | - if ( false === sh_cd_is_premium() ) { | |
| 108 | + if ( false === sh_cd_license_is_premium() ) { | |
| 214 | 109 | wp_send_json( 'not-premium' ); |
| 215 | 110 | } |
| 216 | 111 | |
| 217 | 112 | check_ajax_referer( 'sh-cd-security', 'security' ); |
| 218 | 113 | |
| 219 | - sh_cd_permission_check(); | |
| 220 | - | |
| 221 | 114 | $id = ( false === empty( $_POST['id'] ) ) ? (int) $_POST['id'] : NULL; |
| 222 | 115 | $content = ( false === empty( $_POST['content'] ) ) ? $_POST['content'] : ''; |
| 223 | 116 | |
| 224 | 117 | if ( false === empty( $id ) ) { |
| @@ -230,43 +123,8 @@ | ||
| 230 | 123 | |
| 231 | 124 | wp_send_json( 'shortcode-not-found' ); |
| 232 | 125 | } |
| 233 | 126 | add_action( 'wp_ajax_update_shortcode', 'sh_cd_ajax_update_shortcode' ); |
| 234 | - | |
| 235 | -/** | |
| 236 | -Ajax handler for adding shortcode inline | |
| 237 | - **/ | |
| 238 | -function sh_cd_ajax_add_shortcode() { | |
| 239 | - | |
| 240 | - if ( false === sh_cd_is_premium() ) { | |
| 241 | - wp_send_json( 'not-premium' ); | |
| 242 | - } | |
| 243 | - | |
| 244 | - check_ajax_referer( 'sh-cd-security', 'security' ); | |
| 245 | - | |
| 246 | - sh_cd_permission_check(); | |
| 247 | - | |
| 248 | - if( true === empty( $_POST['slug'] ) ) { | |
| 249 | - wp_send_json( [ 'id' => 0, 'ok' => 0, 'error_message' => __( 'Error: Please specify a "Slug".', SH_CD_SLUG ) ] ); | |
| 250 | - } | |
| 251 | - | |
| 252 | - if( true === empty( $_POST['content'] ) ) { | |
| 253 | - wp_send_json( [ 'id' => 0, 'ok' => 0, 'error_message' => __( 'Error: Please add something for "Content".', SH_CD_SLUG ) ] ); | |
| 254 | - } | |
| 255 | - | |
| 256 | - $shortcode = [ 'slug' => $_POST['slug'], | |
| 257 | - 'previous_slug' => '', | |
| 258 | - 'data' => $_POST['content'], | |
| 259 | - 'disabled' => ! sh_cd_to_bool( $_POST[ 'enabled' ] ), | |
| 260 | - 'multisite' => sh_cd_to_bool( $_POST[ 'multisite' ] ) | |
| 261 | - ]; | |
| 262 | - | |
| 263 | - $result = sh_cd_db_shortcodes_save( $shortcode, true ); | |
| 264 | - | |
| 265 | - wp_send_json( [ 'shortcode' => $result, 'ok' => ( false !== $result ), 'error_message' => __( 'Error: There was an error when saving your shortcode.', SH_CD_SLUG ) ] ); | |
| 266 | - | |
| 267 | -} | |
| 268 | -add_action( 'wp_ajax_add_shortcode', 'sh_cd_ajax_add_shortcode' ); | |
| 269 | 127 | |
| 270 | 128 | /** |
| 271 | 129 | * Replace shortcodes within menu titles. |
| 272 | 130 | * |