PluginProbe
Snippet Shortcodes / 2.2.1
Snippet Shortcodes v2.2.1
5.2.1 5.2 5.1.8 5.1.6 5.1.7 5.1.5 trunk 1.0 1.1 1.2 1.3 1.3.1 1.4 1.5 1.5.1 1.6 1.6.1 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 2.0 2.0.1 All 74 releases
← All changes | includes/hooks.php +88 -8 1.42.2.1 View file →
@@ -1,17 +1,97 @@
1 1 <?php
2 2
3 3 defined('ABSPATH') or die('Jog on!');
4 4
5 -function sh_cd_build_admin_menu()
6 -{
7 - add_menu_page( SH_CD_PLUGIN_NAME, SH_CD_PLUGIN_NAME, 'manage_options', 'sh-cd-shortcode-variables-main-menu', 'sh_cd_user_defined_page', 'dashicons-editor-kitchensink' );
8 -
5 +/**
6 + * Build admin menu
7 + */
8 +function sh_cd_build_admin_menu() {
9 +
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 +
9 12 // Hide duplicated sub menu (wee hack!)
10 - add_submenu_page( 'sh-cd-shortcode-variables-main-menu', '', '', 'manage_options', 'sh-cd-shortcode-variables-main-menu', 'sh_cd_user_defined_page');
11 -
13 + add_submenu_page( 'sh-cd-shortcode-variables-main-menu', '', '', 'manage_options', 'sh-cd-shortcode-variables-main-menu', 'sh_cd_pages_your_shortcodes');
14 +
12 15 // Add sub menus
13 - add_submenu_page( 'sh-cd-shortcode-variables-main-menu', __('Your Shotcodes'), __('Your shortcodes'), 'manage_options', 'sh-cd-shortcode-variables-user-defined', 'sh_cd_user_defined_page');
14 - add_submenu_page( 'sh-cd-shortcode-variables-main-menu', __('Premade Shortcodes'), __('Premade shortcodes'), 'manage_options', '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'), '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'), 'manage_options', 'sh-cd-shortcode-variables-sub-premade', 'sh_cd_premade_shortcodes_page');
18 +
19 + $menu_text = ( true === sh_cd_license_is_premium() ) ? __('Your License', SH_CD_SLUG ) : __('Upgrade to Premium', SH_CD_SLUG );
20 +
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');
15 22 }
16 23 add_action( 'admin_menu', 'sh_cd_build_admin_menu' );
17 24
25 +/**
26 + * Enqueue relevant CSS / JS
27 + */
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);
32 +
33 + wp_localize_script( 'sh-cd', 'sh_cd', [ 'security' => wp_create_nonce( 'sh-cd-security' ), 'premium' => sh_cd_license_is_premium() ] );
34 +
35 +}
36 +add_action( 'admin_enqueue_scripts', 'sh_cd_enqueue_scripts' );
37 +
38 +/**
39 + * Run installer on each version number change or install
40 + */
41 +function sh_cd_upgrade() {
42 +
43 + if ( true === update_option( 'sh-cd-version-number', SH_CD_PLUGIN_VERSION ) ) {
44 + sh_cd_create_database_table();
45 + }
46 +}
47 +add_action('admin_init', 'sh_cd_upgrade');
48 +
49 +
50 +/**
51 + Ajax handler for toggling disable status of a shortcode
52 + **/
53 +function sh_cd_ajax_toggle_status() {
54 +
55 + if ( false === sh_cd_license_is_premium() ) {
56 + wp_send_json( 'not-premium' );
57 + }
58 +
59 + check_ajax_referer( 'sh-cd-security', 'security' );
60 +
61 + $id = ( false === empty( $_POST['id'] ) ) ? (int) $_POST['id'] : NULL;
62 +
63 + if ( false === empty( $id ) ) {
64 +
65 + $new_status = sh_cd_toggle_status( $id );
66 +
67 + wp_send_json( [ 'id' => $id, 'status' => $new_status, 'ok' => 1 ] );
68 + }
69 +
70 + wp_send_json( 'shortcode-not-found' );
71 +}
72 +add_action( 'wp_ajax_toggle_status', 'sh_cd_ajax_toggle_status' );
73 +
74 +/**
75 +Ajax handler for saving shortcode inline
76 + **/
77 +function sh_cd_ajax_update_shortcode() {
78 +
79 + if ( false === sh_cd_license_is_premium() ) {
80 + wp_send_json( 'not-premium' );
81 + }
82 +
83 + check_ajax_referer( 'sh-cd-security', 'security' );
84 +
85 + $id = ( false === empty( $_POST['id'] ) ) ? (int) $_POST['id'] : NULL;
86 + $content = ( false === empty( $_POST['content'] ) ) ? $_POST['content'] : '';
87 +
88 + if ( false === empty( $id ) ) {
89 +
90 + $result = sh_cd_db_shortcodes_update_content( $id, $content );
91 +
92 + wp_send_json( [ 'id' => $id, 'ok' => ( true === $result ) ? 1 : 0 ] );
93 + }
94 +
95 + wp_send_json( 'shortcode-not-found' );
96 +}
97 +add_action( 'wp_ajax_update_shortcode', 'sh_cd_ajax_update_shortcode' );