PluginProbe
Snippet Shortcodes / 5.0a
Snippet Shortcodes v5.0a
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 / pages / page.edit.php

page.edit.php in Snippet Shortcodes 5.0a, at includes/pages/page.edit.php

198 lines 11.0 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 function sh_cd_pages_your_shortcodes_edit( $action = 'add', $save_result = NULL ) {
6
7 if ( false === in_array( $action, [ 'add', 'edit', 'save' ] ) ) {
8 return;
9 }
10
11 sh_cd_permission_check();
12
13 // Saving / Inserting a shortcode?
14 if ( false === $save_result ) {
15 sh_cd_message_display( __( 'There was an error saving your shortcode!' , SH_CD_SLUG ), ! $save_result );
16 }
17 global $wpdb;
18
19 // Load
20 $shortcode = ( false === empty( $_GET['id'] ) ) ?
21 sh_cd_db_shortcodes_by_id( (int) $_GET['id'] ) :
22 sh_cd_get_values_from_post( [ 'id', 'slug', 'previous_slug', 'data', 'disabled', 'multisite', 'editor' ] );
23
24 $shortcode['data'] = stripslashes( $shortcode['data'] );
25
26 $current_editor = ( false === empty( $_GET[ 'editor' ] ) ) ? $_GET[ 'editor' ] : $shortcode[ 'editor' ];
27
28 if ( true === empty( $current_editor ) ) {
29 $current_editor = sh_cd_default_editor_get();
30 }
31 ?>
32 <form method="post" action="<?php echo sh_cd_link_your_shortcodes() . '&action=save'; ?>" class="sh-cd-form">
33
34 <div class="wrap">
35 <div id="icon-options-general" class="icon32"></div>
36 <div id="poststuff">
37 <div id="post-body" class="metabox-holder columns-3">
38 <div id="post-body-content">
39 <div class="meta-box-sortables ui-sortable">
40 <?php if ( false === sh_cd_is_premium() ) : ?>
41 <p>
42 <i class="fa-regular fa-star"></i>
43 <a href="<?php echo sh_cd_license_upgrade_link(); ?>">
44 <?php echo __( 'Multi site support and editing slugs are only available for Premium users. Upgrade now.', SH_CD_SLUG ); ?>
45 </a>
46 </p>
47 <?php endif; ?>
48 <div class="postbox sh-cd-postbox-edit-slug">
49 <h3 class="postbox-header">
50 <span>
51 <?php echo __( 'Slug', SH_CD_SLUG ); ?>
52 </span>
53 </h3>
54 <div style="padding: 0px 15px 0px 15px">
55 <?php
56
57 if ( true === $save_result ) :
58
59 printf('<p>%1$s.<a href="%2$s">%3$s</a>.</p>',
60 __( 'Your shortcode has been saved successfully', SH_CD_SLUG ),
61 sh_cd_link_your_shortcodes(),
62 __( 'Return to all shortcodes', SH_CD_SLUG )
63 );
64
65 else:
66
67 ?>
68
69 <input type="hidden" id="id" name="id" value="<?php echo esc_attr( $shortcode['id'] ); ?>" />
70 <?php wp_nonce_field( 'save-shortcode' ); ?>
71
72 <div class="sh-cd-row">
73 <input type="text" required class="regular-text sh-cd-slug-validation" size="100" id="slug" name="slug"
74 placeholder="Enter a name for your shortcode" title="Only letters, numbers, dashes and underscores are allowed."
75 value="<?php echo esc_attr( $shortcode['slug'] )?>" <?php if ( false === sh_cd_is_premium() && 'edit' === $action ) { echo 'disabled="disabled"'; } ?> />
76
77 <?php $previous_slug = ( false === empty( $shortcode['previous_slug'] ) ) ? $shortcode['previous_slug'] : $shortcode['slug']; ?>
78 <input type="hidden" id="previous_slug" name="previous_slug" value="<?php echo esc_attr( $previous_slug )?>" />
79
80 <p class="sh-cd-shortcode-slug">
81 <?php
82 $default_slug = ( 'add' === $action ) ? 'enter-a-name-for-your-shortcode' : $previous_slug;
83 ?>
84 <?php echo __( 'Shortcode:', SH_CD_SLUG ); ?><span id="sh-cd-test-shortcode-slug">[<?php echo SH_CD_SHORTCODE; ?> slug="<span id="sh-cd-shortcode-slug-preview"><?php echo esc_html( $default_slug ); ?></span>"]</span>
85 <i class="far fa-copy sh-cd-copy-trigger <?php if ( 'add' === $action ): ?>sh-cd-hide<?php endif; ?>" data-clipboard-text="[<?php echo SH_CD_SHORTCODE; ?> slug=&quot;<?php echo esc_html( $default_slug ); ?>&quot;]"></i>
86 </p>
87 </div>
88 </div>
89 </div>
90 <div class="postbox sh-cd-postbox-edit-content">
91 <h3 class="postbox-header">
92 <span>
93 <?php echo __( 'Content', SH_CD_SLUG ); ?>
94 </span>
95 <?php sh_cd_editor_change_button( $current_editor ); ?>
96 </h3>
97 <div class="sh-cd-postbox-content">
98 <?php
99 if ( 'code' !== $current_editor ) {
100 wp_editor( $shortcode['data'], 'data', [ 'textarea_name' => 'data' ] );
101 } else {
102 printf( ' <textarea id="sh-cd-code-editor" name="data">%s</textarea>
103 <script>
104 jQuery( document ).ready(function ($) {
105 wp.codeEditor.initialize($("#sh-cd-code-editor"), cm_settings);
106 });
107 </script>', $shortcode['data'] );
108 }
109
110 $premium_icon = sh_cd_display_premium_star();
111
112 ?>
113 <input type="hidden" id="editor" name="editor" value="<?php echo esc_attr( $current_editor ); ?>" />
114 <table class="sh-cd-shortcode-options" width="100%">
115 <tr>
116 <th width="100">
117 <?php echo __( 'Disable?', SH_CD_SLUG ); ?>
118 <?php echo sh_cd_display_info_tooltip( 'If disabled, no content will appear at the location of the shortcode in the public facing site.'); ?>
119 <?php echo $premium_icon; ?>
120 </th>
121 <td width="*">
122 <select id="disabled" name="disabled" <?php if ( false === sh_cd_is_premium() ) { echo 'disabled="disabled"'; } ?>>
123 <option value="0" <?php selected( $shortcode['disabled'], 0 ); ?>><?php echo __( 'No', SH_CD_SLUG ); ?></option>
124 <option value="1" <?php selected( $shortcode['disabled'], 1 ); ?>><?php echo __( 'Yes', SH_CD_SLUG ); ?></option>
125 </select>
126 </td>
127 </tr>
128 <tr>
129 <th><?php echo __( 'Global?', SH_CD_SLUG ); ?>
130 <?php echo sh_cd_display_info_tooltip( "Enable this to make the shortcode available across all sites in your multisite network. Note: Global shortcodes override local ones with the same slug, and conflicts may arise if slugs aren't unique. Updates may take up to 30 seconds to apply."); ?>
131 <?php echo $premium_icon; ?>
132 </th>
133 <td>
134 <select id="multisite" name="multisite" <?php if ( false === sh_cd_is_premium() ) { echo 'disabled="disabled"'; } ?>>
135 <option value="0" <?php selected( $shortcode['multisite'], 0 ); ?>><?php echo __( 'No', SH_CD_SLUG ); ?></option>
136 <option value="1" <?php selected( $shortcode['multisite'], 1 ); ?>><?php echo __( 'Yes', SH_CD_SLUG ); ?></option>
137 </select>
138 </td>
139 </tr>
140 </table>
141 <div class="sh-cd-button-row sh-cd-border-top">
142 <a class="comment-submit button" href="<?php echo sh_cd_link_your_shortcodes(); ?>"><?php echo __( 'Cancel', SH_CD_SLUG ); ?></a>
143 <input name="submit_button" type="submit" value="Save Shortcode" class="comment-submit button button-primary sh-cd-button">
144 </div>
145
146 <?php endif; ?>
147 </div>
148 </div>
149 </div>
150 </div>
151 </div>
152
153 </div>
154 </div>
155 </form>
156 <?php
157 }
158
159 /**
160 * Button for toggling editor
161 *
162 * @return void
163 */
164 function sh_cd_editor_change_button( $current_editor = null ) {
165
166 if ( true === empty( $current_editor ) ) {
167 $current_editor = sh_cd_default_editor_get();
168 }
169
170 $editor = ( 'tinymce' === $current_editor ) ? 'code' : 'tinymce';
171 $text = ( 'tinymce' === $current_editor ) ? __( 'Change to HTML Editor', SH_CD_SLUG ) : __( 'Change to WordPress Editor', SH_CD_SLUG );
172 $icon = ( 'tinymce' === $current_editor ) ? 'fa-solid fa-code' : 'fa-brands fa-wordpress';
173
174 $url = add_query_arg( [ 'editor' => $editor ], sh_cd_get_current_url() );
175
176 echo sprintf( '<a type="button" class="button sh-cd-button sh-cd-button-editor-select sh-cd-button-%2$s" href="%1$s" data-new-editor="%2$s"><i class="%3$s"></i> %4$s</a>',
177 esc_url( $url ),
178 $editor,
179 esc_html( $icon ),
180 esc_html( $text ));
181 }
182
183 /**
184 * If using code editor, load the code editor
185 */
186 add_action( 'admin_enqueue_scripts', function() {
187
188 if ( false === sh_cd_is_snippet_shortcodes_admin_page() ) {
189 return;
190 }
191
192 // Types found here: https://docs.classicpress.net/reference/functions/wp_enqueue_code_editor/
193 $cm_settings['codeEditor'] = wp_enqueue_code_editor( [ 'type' => 'text/html' ] );
194 wp_localize_script( 'jquery', 'cm_settings', $cm_settings) ;
195
196 wp_enqueue_script( 'wp-theme-plugin-editor' );
197 wp_enqueue_style( 'wp-codemirror' );
198 });