PluginProbe
Insert Pages / 3.8
Insert Pages v3.8
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 3.8, at options.php

243 lines 10.5 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 }
74 add_action( 'admin_init', 'wpip_settings_init' );
75
76 /**
77 * Set meaningful defaults for settings.
78 *
79 * @return array Insert Pages settings.
80 */
81 function wpip_set_defaults() {
82 $options = get_option( 'wpip_settings' );
83 if ( false === $options ) {
84 $options = array();
85 }
86
87 if ( ! array_key_exists( 'wpip_format', $options ) ) {
88 $options['wpip_format'] = 'slug';
89 }
90
91 if ( ! array_key_exists( 'wpip_wrapper', $options ) ) {
92 $options['wpip_wrapper'] = 'block';
93 }
94
95 if ( ! array_key_exists( 'wpip_insert_method', $options ) ) {
96 $options['wpip_insert_method'] = 'normal';
97 }
98
99 if ( ! array_key_exists( 'wpip_tinymce_filter', $options ) ) {
100 $options['wpip_tinymce_filter'] = 'normal';
101 }
102
103 if ( ! array_key_exists( 'wpip_gutenberg_block', $options ) ) {
104 $options['wpip_gutenberg_block'] = 'enabled';
105 }
106
107 if ( empty( $options['wpip_classic_editor_hide_others_posts'] ) ) {
108 $options['wpip_classic_editor_hide_others_posts'] = 'disabled';
109 }
110
111 update_option( 'wpip_settings', $options );
112
113 return $options;
114 }
115 register_activation_hook( __FILE__, 'wpip_set_defaults' );
116
117 /**
118 * Print heading for Insert Pages settings page.
119 *
120 * @return void
121 */
122 function wpip_settings_section_callback() {
123 esc_html_e( 'You may override some default settings here.', 'insert-pages' );
124 }
125
126 /**
127 * Print Insert Pages settings page.
128 *
129 * @return void
130 */
131 function wpip_options_page() {
132 ?>
133 <form action='options.php' method='post'>
134 <?php
135 settings_fields( 'wpipSettings' );
136 do_settings_sections( 'wpipSettings' );
137 submit_button();
138 ?>
139 </form>
140 <?php
141 }
142
143 /**
144 * Print 'Format' setting.
145 *
146 * @return void
147 */
148 function wpip_format_render() {
149 $options = get_option( 'wpip_settings' );
150 if ( false === $options || ! is_array( $options ) || ! array_key_exists( 'wpip_format', $options ) ) {
151 $options = wpip_set_defaults();
152 }
153 ?>
154 <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 />
155 <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 />
156 <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>
157 <?php
158 }
159
160 /**
161 * Print 'Wrapper' setting.
162 *
163 * @return void
164 */
165 function wpip_wrapper_render() {
166 $options = get_option( 'wpip_settings' );
167 if ( false === $options || ! is_array( $options ) || ! array_key_exists( 'wpip_wrapper', $options ) ) {
168 $options = wpip_set_defaults();
169 }
170 ?>
171 <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 />
172 <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 />
173 <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>
174 <?php
175 }
176
177 /**
178 * Print 'Insert Method' setting.
179 *
180 * @return void
181 */
182 function wpip_insert_method_render() {
183 $options = get_option( 'wpip_settings' );
184 if ( false === $options || ! is_array( $options ) || ! array_key_exists( 'wpip_insert_method', $options ) ) {
185 $options = wpip_set_defaults();
186 }
187 ?>
188 <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 />
189 <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 />
190 <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>
191 <?php
192 }
193
194 /**
195 * Print 'TinyMCE Filter' setting.
196 *
197 * @return void
198 */
199 function wpip_tinymce_filter_render() {
200 $options = get_option( 'wpip_settings' );
201 if ( false === $options || ! is_array( $options ) || ! array_key_exists( 'wpip_tinymce_filter', $options ) ) {
202 $options = wpip_set_defaults();
203 }
204 ?>
205 <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 />
206 <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 />
207 <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>
208 <?php
209 }
210
211 /**
212 * Print 'Gutenberg block' setting.
213 *
214 * @return void
215 */
216 function wpip_gutenberg_block_render() {
217 $options = get_option( 'wpip_settings' );
218 if ( false === $options || ! is_array( $options ) || ! array_key_exists( 'wpip_gutenberg_block', $options ) ) {
219 $options = wpip_set_defaults();
220 }
221 ?>
222 <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 />
223 <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>
224 <?php
225 }
226
227 /**
228 * Print 'TinyMCE capabilities' setting.
229 *
230 * @return void
231 */
232 function wpip_classic_editor_hide_others_posts_render() {
233 $options = get_option( 'wpip_settings' );
234 if ( false === $options || ! is_array( $options ) || empty( $options['wpip_classic_editor_hide_others_posts'] ) ) {
235 $options = wpip_set_defaults();
236 }
237 ?>
238 <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 />
239 <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 />
240 <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>
241 <?php
242 }
243