PluginProbe
Snippet Shortcodes / 3.5.1
Snippet Shortcodes v3.5.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
shortcode-variables / includes / hooks.php

hooks.php in Snippet Shortcodes 3.5.1, at includes/hooks.php

145 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') or die('Jog on!');
4
5 /**
6 * Build admin menu
7 */
8 function sh_cd_build_admin_menu() {
9
10 $allowed_viewer = sh_cd_permission_role();
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-editor-kitchensink' );
13
14 // Hide duplicated sub menu (wee hack!)
15 add_submenu_page( 'sh-cd-shortcode-variables-main-menu', '', '', 'manage_options', 'sh-cd-shortcode-variables-main-menu', 'sh_cd_pages_your_shortcodes');
16
17 // 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');
20
21 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' );
22
23 $menu_text = ( true === sh_cd_license_is_premium() ) ? __( 'Your License', SH_CD_SLUG ) : __( 'Upgrade to Premium', SH_CD_SLUG );
24
25 add_submenu_page( 'sh-cd-shortcode-variables-main-menu', $menu_text, $menu_text, 'manage_options', 'sh-cd-shortcode-variables-license', 'sh_cd_advertise_pro');
26 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' );
27 }
28 add_action( 'admin_menu', 'sh_cd_build_admin_menu' );
29
30 /**
31 * Enqueue relevant CSS / JS
32 */
33 function sh_cd_enqueue_scripts() {
34 wp_enqueue_style( 'sh-cd', plugins_url( '../assets/css/sh-cd.css', __FILE__ ), [], SH_CD_PLUGIN_VERSION ) ;
35 wp_enqueue_style('fontawesome', 'https://use.fontawesome.com/releases/v5.7.2/css/all.css', [], SH_CD_PLUGIN_VERSION);
36 wp_enqueue_script( 'sh-cd', plugins_url( '../assets/js/sh-cd.js', __FILE__ ), [ 'jquery' ], SH_CD_PLUGIN_VERSION);
37
38 wp_localize_script( 'sh-cd', 'sh_cd', [ 'security' => wp_create_nonce( 'sh-cd-security' ), 'premium' => sh_cd_license_is_premium() ] );
39
40 }
41 add_action( 'admin_enqueue_scripts', 'sh_cd_enqueue_scripts' );
42
43 /**
44 * Run installer on each version number change or install
45 */
46 function sh_cd_upgrade() {
47
48 if ( true === update_option( 'sh-cd-version-number-2021', SH_CD_PLUGIN_VERSION ) ) {
49
50 sh_cd_create_database_table();
51
52 sh_cd_create_database_table_multisite();
53
54 sh_cd_cron_licence_check();
55
56 do_action( 'sh-cd-upgrade' );
57 }
58 }
59 add_action('admin_init', 'sh_cd_upgrade');
60
61
62 /**
63 Ajax handler for toggling disable status of a shortcode
64 **/
65 function sh_cd_ajax_toggle_status() {
66
67 if ( false === sh_cd_license_is_premium() ) {
68 wp_send_json( 'not-premium' );
69 }
70
71 check_ajax_referer( 'sh-cd-security', 'security' );
72
73 $id = ( false === empty( $_POST['id'] ) ) ? (int) $_POST['id'] : NULL;
74
75 if ( false === empty( $id ) ) {
76
77 $new_status = sh_cd_toggle_status( $id );
78
79 wp_send_json( [ 'id' => $id, 'status' => $new_status, 'ok' => 1 ] );
80 }
81
82 wp_send_json( 'shortcode-not-found' );
83 }
84 add_action( 'wp_ajax_toggle_status', 'sh_cd_ajax_toggle_status' );
85
86 /**
87 Ajax handler for toggling disable status of a shortcode
88 **/
89 function sh_cd_ajax_toggle_multisite() {
90
91 if ( false === sh_cd_license_is_premium() ) {
92 wp_send_json( 'not-premium' );
93 }
94
95 check_ajax_referer( 'sh-cd-security', 'security' );
96
97 $id = ( false === empty( $_POST['id'] ) ) ? (int) $_POST['id'] : NULL;
98
99 if ( false === empty( $id ) ) {
100
101 $new_multisite = sh_cd_toggle_multisite( $id );
102
103 wp_send_json( [ 'id' => $id, 'multisite' => $new_multisite, 'ok' => 1 ] );
104 }
105
106 wp_send_json( 'shortcode-not-found' );
107 }
108 add_action( 'wp_ajax_toggle_multisite', 'sh_cd_ajax_toggle_multisite' );
109
110 /**
111 Ajax handler for saving shortcode inline
112 **/
113 function sh_cd_ajax_update_shortcode() {
114
115 if ( false === sh_cd_license_is_premium() ) {
116 wp_send_json( 'not-premium' );
117 }
118
119 check_ajax_referer( 'sh-cd-security', 'security' );
120
121 $id = ( false === empty( $_POST['id'] ) ) ? (int) $_POST['id'] : NULL;
122 $content = ( false === empty( $_POST['content'] ) ) ? $_POST['content'] : '';
123
124 if ( false === empty( $id ) ) {
125
126 $result = sh_cd_db_shortcodes_update_content( $id, $content );
127
128 wp_send_json( [ 'id' => $id, 'ok' => ( true === $result ) ? 1 : 0 ] );
129 }
130
131 wp_send_json( 'shortcode-not-found' );
132 }
133 add_action( 'wp_ajax_update_shortcode', 'sh_cd_ajax_update_shortcode' );
134
135 /**
136 * Replace shortcodes within menu titles.
137 *
138 * @param $title
139 * @return mixed
140 */
141 function sh_cd_menu_replace_shortcodes( $title ) {
142 return do_shortcode( $title );
143 }
144 add_filter('nav_menu_item_title', 'sh_cd_menu_replace_shortcodes', 10, 1);
145