PluginProbe
Insert Pages / trunk
Insert Pages vtrunk
3.11.5 trunk 1.4 2.4 2.5 2.6 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 3.0 3.0.1 3.0.2 3.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 All 79 releases
insert-pages / options.php

options.php in Insert Pages trunk, at options.php

277 lines 13.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Render the Insert Pages Settings page.
4 *
5 * @package insert-pages
6 */
7
8 /**
9 * Add 'Insert Pages' to the Settings menu.
10 *
11 * @return void
12 */
13 function wpip_add_admin_menu() {
14 add_options_page( 'Insert Pages', 'Insert Pages', 'manage_options', 'insert_pages', 'wpip_options_page' );
15 }
16 add_action( 'admin_menu', 'wpip_add_admin_menu' );
17
18 /**
19 * Register settings fields.
20 *
21 * @return void
22 */
23 function wpip_settings_init() {
24 register_setting( 'wpipSettings', 'wpip_settings' );
25 add_settings_section(
26 'wpip_section',
27 __( 'Insert Pages', 'insert-pages' ),
28 'wpip_settings_section_callback',
29 'wpipSettings'
30 );
31 add_settings_field(
32 'wpip_format',
33 __( 'Shortcode format', 'insert-pages' ),
34 'wpip_format_render',
35 'wpipSettings',
36 'wpip_section'
37 );
38 add_settings_field(
39 'wpip_wrapper',
40 __( 'Wrapper for inserts', 'insert-pages' ),
41 'wpip_wrapper_render',
42 'wpipSettings',
43 'wpip_section'
44 );
45 add_settings_field(
46 'wpip_insert_method',
47 __( 'Insert method', 'insert-pages' ),
48 'wpip_insert_method_render',
49 'wpipSettings',
50 'wpip_section'
51 );
52 add_settings_field(
53 'wpip_tinymce_filter',
54 __( 'TinyMCE filter', 'insert-pages' ),
55 'wpip_tinymce_filter_render',
56 'wpipSettings',
57 'wpip_section'
58 );
59 add_settings_field(
60 'wpip_gutenberg_block',
61 __( 'Gutenberg block', 'insert-pages' ),
62 'wpip_gutenberg_block_render',
63 'wpipSettings',
64 'wpip_section'
65 );
66 add_settings_field(
67 'wpip_classic_editor_hide_others_posts',
68 __( 'TinyMCE capabilities', 'insert-pages' ),
69 'wpip_classic_editor_hide_others_posts_render',
70 'wpipSettings',
71 'wpip_section'
72 );
73 add_settings_field(
74 'wpip_public_post_statuses',
75 __( 'Allow anyone to see inserted pages with these statuses', 'insert-pages' ),
76 'wpip_public_post_statuses_render',
77 'wpipSettings',
78 'wpip_section'
79 );
80 }
81 add_action( 'admin_init', 'wpip_settings_init' );
82
83 /**
84 * Set meaningful defaults for settings.
85 *
86 * @return array Insert Pages settings.
87 */
88 function wpip_set_defaults() {
89 $options = get_option( 'wpip_settings' );
90 if ( false === $options ) {
91 $options = array();
92 }
93
94 if ( ! array_key_exists( 'wpip_format', $options ) ) {
95 $options['wpip_format'] = 'slug';
96 }
97
98 if ( ! array_key_exists( 'wpip_wrapper', $options ) ) {
99 $options['wpip_wrapper'] = 'block';
100 }
101
102 if ( ! array_key_exists( 'wpip_insert_method', $options ) ) {
103 $options['wpip_insert_method'] = 'normal';
104 }
105
106 if ( ! array_key_exists( 'wpip_tinymce_filter', $options ) ) {
107 $options['wpip_tinymce_filter'] = 'normal';
108 }
109
110 if ( ! array_key_exists( 'wpip_gutenberg_block', $options ) ) {
111 $options['wpip_gutenberg_block'] = 'enabled';
112 }
113
114 if ( empty( $options['wpip_classic_editor_hide_others_posts'] ) ) {
115 $options['wpip_classic_editor_hide_others_posts'] = 'disabled';
116 }
117
118 if ( empty( $options['wpip_public_post_statuses'] ) || ! is_array( $options['wpip_public_post_statuses'] ) ) {
119 $options['wpip_public_post_statuses'] = array();
120 }
121
122 update_option( 'wpip_settings', $options );
123
124 return $options;
125 }
126 register_activation_hook( __FILE__, 'wpip_set_defaults' );
127
128 /**
129 * Print heading for Insert Pages settings page.
130 *
131 * @return void
132 */
133 function wpip_settings_section_callback() {
134 esc_html_e( 'You may override some default settings here.', 'insert-pages' );
135 }
136
137 /**
138 * Print Insert Pages settings page.
139 *
140 * @return void
141 */
142 function wpip_options_page() {
143 ?>
144 <form action='options.php' method='post'>
145 <?php
146 settings_fields( 'wpipSettings' );
147 do_settings_sections( 'wpipSettings' );
148 submit_button();
149 ?>
150 </form>
151 <?php
152 }
153
154 /**
155 * Print 'Format' setting.
156 *
157 * @return void
158 */
159 function wpip_format_render() {
160 $options = get_option( 'wpip_settings' );
161 if ( false === $options || ! is_array( $options ) || ! array_key_exists( 'wpip_format', $options ) ) {
162 $options = wpip_set_defaults();
163 }
164 ?>
165 <input type='radio' name='wpip_settings[wpip_format]' <?php checked( $options['wpip_format'], 'slug' ); ?> id="wpip_format_slug" value='slug'><label for="wpip_format_slug">Use page slugs (more readable). Example: <code>[insert&nbsp;page='hello&#8209;world&#8209;post'&nbsp;display='all']</code></label><br />
166 <input type='radio' name='wpip_settings[wpip_format]' <?php checked( $options['wpip_format'], 'post_id' ); ?> id="wpip_format_id" value='post_id'><label for="wpip_format_id">Use page IDs (more compatible). Example: <code>[insert&nbsp;page='1'&nbsp;display='all']</code></label><br />
167 <small><em>If your site reuses page slugs (for example, WPML sites often use the same page slug for each translation of the page in a different language), you should use page IDs.</em></small>
168 <?php
169 }
170
171 /**
172 * Print 'Wrapper' setting.
173 *
174 * @return void
175 */
176 function wpip_wrapper_render() {
177 $options = get_option( 'wpip_settings' );
178 if ( false === $options || ! is_array( $options ) || ! array_key_exists( 'wpip_wrapper', $options ) ) {
179 $options = wpip_set_defaults();
180 }
181 ?>
182 <input type='radio' name='wpip_settings[wpip_wrapper]' <?php checked( $options['wpip_wrapper'], 'block' ); ?> id="wpip_wrapper_block" value='block'><label for="wpip_wrapper_block">Use block wrapper (div). Example: <code>&lt;div data-post-id="1" class="insert-page">...&lt;/div></code></label><br />
183 <input type='radio' name='wpip_settings[wpip_wrapper]' <?php checked( $options['wpip_wrapper'], 'inline' ); ?> id="wpip_wrapper_inline" value='inline'><label for="wpip_wrapper_inline">Use inline wrapper (span). Example: <code>&lt;span data-post-id="1" class="insert-page">...&lt;/span></code></label><br />
184 <small><em>If you want to embed pages inline (for example, you can insert a link to a page in the flow of a normal paragraph), you should use inline tags. Note that the HTML spec does not allow block level elements within inline elements, so the inline wrapper has limited use.</em></small>
185 <?php
186 }
187
188 /**
189 * Print 'Insert Method' setting.
190 *
191 * @return void
192 */
193 function wpip_insert_method_render() {
194 $options = get_option( 'wpip_settings' );
195 if ( false === $options || ! is_array( $options ) || ! array_key_exists( 'wpip_insert_method', $options ) ) {
196 $options = wpip_set_defaults();
197 }
198 ?>
199 <input type='radio' name='wpip_settings[wpip_insert_method]' <?php checked( $options['wpip_insert_method'], 'legacy' ); ?> id="wpip_insert_method_legacy" value='legacy'><label for="wpip_insert_method_legacy">Use legacy method (compatible with <a href="https://wordpress.org/plugins/beaver-builder-lite-version/" target="_blank">Beaver Builder</a> and <a href="https://wordpress.org/plugins/siteorigin-panels/" target="_blank">Page Builder by SiteOrigin</a>, but less efficient). </label><br />
200 <input type='radio' name='wpip_settings[wpip_insert_method]' <?php checked( $options['wpip_insert_method'], 'normal' ); ?> id="wpip_insert_method_normal" value='normal'><label for="wpip_insert_method_normal">Use normal method (more compatible with other plugins, and more efficient). Compatible with Gutenberg.</label><br />
201 <small><em>The legacy method uses <a href="https://codex.wordpress.org/Function_Reference/query_posts" target="_blank">query_posts()</a>, which the Codex cautions against using. However, to recreate the exact state that many page builder plugins are expecting, the Main Loop has to be replaced with the inserted page while it is being rendered. The normal method, on the other hand, just uses <a href="https://developer.wordpress.org/reference/functions/get_post/" target="_blank">get_post()</a>.</em></small>
202 <?php
203 }
204
205 /**
206 * Print 'TinyMCE Filter' setting.
207 *
208 * @return void
209 */
210 function wpip_tinymce_filter_render() {
211 $options = get_option( 'wpip_settings' );
212 if ( false === $options || ! is_array( $options ) || ! array_key_exists( 'wpip_tinymce_filter', $options ) ) {
213 $options = wpip_set_defaults();
214 }
215 ?>
216 <input type='radio' name='wpip_settings[wpip_tinymce_filter]' <?php checked( $options['wpip_tinymce_filter'], 'normal' ); ?> id="wpip_tinymce_filter_normal" value='normal'><label for="wpip_tinymce_filter_normal">Use normal method (compatible with Divi theme and most situations). </label><br />
217 <input type='radio' name='wpip_settings[wpip_tinymce_filter]' <?php checked( $options['wpip_tinymce_filter'], 'compatibility' ); ?> id="wpip_tinymce_filter_compatibility" value='compatibility'><label for="wpip_tinymce_filter_compatibility">Use compatibility method (works with <a href="https://wordpress.org/plugins/siteorigin-panels/" target="_blank">Page Builder by SiteOrigin</a>).</label><br />
218 <small><em>The normal method adds the TinyMCE plugin filters in the <a href="https://developer.wordpress.org/reference/hooks/admin_head/" target="_blank">admin_head</a> hook. For users using SiteOrigin PageBuilder with the so-widgets-bundle enabled and using Contact Form, Editor, Google Maps, Hero Image, or Testimonials widgets, a bug in that plugin prevents other plugins from registering TinyMCE plugins. Use compatibility mode here to use a workaround.</em></small>
219 <?php
220 }
221
222 /**
223 * Print 'Gutenberg block' setting.
224 *
225 * @return void
226 */
227 function wpip_gutenberg_block_render() {
228 $options = get_option( 'wpip_settings' );
229 if ( false === $options || ! is_array( $options ) || ! array_key_exists( 'wpip_gutenberg_block', $options ) ) {
230 $options = wpip_set_defaults();
231 }
232 ?>
233 <input type='radio' name='wpip_settings[wpip_gutenberg_block]' <?php checked( $options['wpip_gutenberg_block'], 'enabled' ); ?> id="wpip_gutenberg_block_enabled" value='enabled'><label for="wpip_gutenberg_block_enabled">Enable Insert Pages Gutenberg block.</label><br />
234 <input type='radio' name='wpip_settings[wpip_gutenberg_block]' <?php checked( $options['wpip_gutenberg_block'], 'disabled' ); ?> id="wpip_gutenberg_block_disabled" value='disabled'><label for="wpip_gutenberg_block_disabled">Disable Insert Pages Gutenberg block.</label>
235 <?php
236 }
237
238 /**
239 * Print 'TinyMCE capabilities' setting.
240 *
241 * @return void
242 */
243 function wpip_classic_editor_hide_others_posts_render() {
244 $options = get_option( 'wpip_settings' );
245 if ( false === $options || ! is_array( $options ) || empty( $options['wpip_classic_editor_hide_others_posts'] ) ) {
246 $options = wpip_set_defaults();
247 }
248 ?>
249 <input type='radio' name='wpip_settings[wpip_classic_editor_hide_others_posts]' <?php checked( $options['wpip_classic_editor_hide_others_posts'], 'enabled' ); ?> id="wpip_classic_editor_hide_others_posts_enabled" value='enabled'><label for="wpip_classic_editor_hide_others_posts_enabled">Authors and Contributors only see their own content to insert.</label><br />
250 <input type='radio' name='wpip_settings[wpip_classic_editor_hide_others_posts]' <?php checked( $options['wpip_classic_editor_hide_others_posts'], 'disabled' ); ?> id="wpip_classic_editor_hide_others_posts_disabled" value='disabled'><label for="wpip_classic_editor_hide_others_posts_disabled">Authors and Contributors see all published content to insert.</label><br />
251 <small><em>Note: this option only restricts Contributors and Authors (i.e., the roles without the <code>edit_others_posts</code> capability) from seeing other's content in the TinyMCE Insert Page popup; they can still insert any published content if they know the page slug.</em></small>
252 <?php
253 }
254
255 /**
256 * Print 'Insertable post statuses' setting.
257 *
258 * @return void
259 */
260 function wpip_public_post_statuses_render() {
261 $options = get_option( 'wpip_settings' );
262 if ( false === $options || ! is_array( $options ) || empty( $options['wpip_public_post_statuses'] ) || ! is_array( $options['wpip_public_post_statuses'] ) ) {
263 $options = wpip_set_defaults();
264 }
265 ?>
266 <input type='checkbox' disabled checked id="wpip_public_post_statuses_publish" value='publish'><label for="wpip_public_post_statuses_publish">Published</label><br />
267
268 <input type='checkbox' name='wpip_settings[wpip_public_post_statuses][]' <?php checked( in_array( 'private', $options['wpip_public_post_statuses'], true ) ); ?> id="wpip_public_post_statuses_private" value='private'><label for="wpip_public_post_statuses_private">Private, authored by anyone (normally only visible to site admins and editors)</label><br />
269 <input type='checkbox' name='wpip_settings[wpip_public_post_statuses][]' <?php checked( in_array( 'private_self', $options['wpip_public_post_statuses'], true ) ); ?> id="wpip_public_post_statuses_private_self" value='private_self'><label for="wpip_public_post_statuses_private_self">Private, only where inserted page and parent page have the same author (normally only visible to site admins and editors)</label><br />
270 <input type='checkbox' name='wpip_settings[wpip_public_post_statuses][]' <?php checked( in_array( 'draft', $options['wpip_public_post_statuses'], true ) ); ?> id="wpip_public_post_statuses_draft" value='draft'><label for="wpip_public_post_statuses_draft">Draft (not ready to publish)</label><br />
271 <input type='checkbox' name='wpip_settings[wpip_public_post_statuses][]' <?php checked( in_array( 'pending', $options['wpip_public_post_statuses'], true ) ); ?> id="wpip_public_post_statuses_pending" value='pending'><label for="wpip_public_post_statuses_pending">Pending (waiting for review before publishing)</label><br />
272 <input type='checkbox' name='wpip_settings[wpip_public_post_statuses][]' <?php checked( in_array( 'future', $options['wpip_public_post_statuses'], true ) ); ?> id="wpip_public_post_statuses_future" value='future'><label for="wpip_public_post_statuses_future">Scheduled (scheduled to be published on a future date)</label><br />
273 <input type='checkbox' name='wpip_settings[wpip_public_post_statuses][]' <?php checked( in_array( 'has_password', $options['wpip_public_post_statuses'], true ) ); ?> id="wpip_public_post_statuses_has_password" value='has_password'><label for="wpip_public_post_statuses_has_password">Password-protected (normally only visible to those who know the password)</label><br />
274 <small><em>Note: there are security considerations when making these statuses publicly viewable, such as unintentional information disclosure when inserting private pages. If enabling them, please review accordingly.</em></small>
275 <?php
276 }
277