PluginProbe
iframe / trunk
iframe vtrunk
trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7 1.8 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 4.0 4.1 4.2 4.3 All 35 releases
iframe / iframe-settings.php

iframe-settings.php in iframe trunk, at iframe-settings.php

151 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * iframe Plugin Settings Page
4 *
5 * Handles all admin settings functionality for the iframe plugin
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Avoid direct calls to this file
10 }
11
12 /**
13 * Get plugin settings with defaults
14 *
15 * @return array All plugin settings with default values
16 */
17 function iframe_plugin_get_settings() {
18 $defaults = array(
19 'loading' => 'none' // Default to none (no loading attribute)
20 );
21
22 $options = get_option('iframe_plugin_options', array());
23
24 // Merge with defaults to ensure all keys exist
25 return wp_parse_args($options, $defaults);
26 }
27
28 // Register settings
29 function iframe_plugin_register_settings() {
30 register_setting('iframe_plugin_settings', 'iframe_plugin_options', array(
31 'type' => 'array',
32 'default' => array(
33 'loading' => 'none'
34 ),
35 'sanitize_callback' => 'iframe_plugin_sanitize_options'
36 ));
37 }
38 add_action('admin_init', 'iframe_plugin_register_settings');
39
40 // Sanitize all plugin options
41 function iframe_plugin_sanitize_options($input) {
42 $sanitized = array();
43
44 // Sanitize loading attribute
45 if (isset($input['loading'])) {
46 $allowed_loading = array('none', 'lazy', 'eager');
47 $sanitized['loading'] = in_array($input['loading'], $allowed_loading, true) ? $input['loading'] : 'none';
48 }
49
50 // Add sanitization for future options here
51
52 return $sanitized;
53 }
54
55 // Add settings page to admin menu
56 function iframe_plugin_add_settings_page() {
57 add_options_page(
58 'iframe Settings', // Page title
59 'iframe', // Menu title
60 'manage_options', // Capability
61 'iframe-settings', // Menu slug
62 'iframe_plugin_settings_page' // Callback function
63 );
64 }
65 add_action('admin_menu', 'iframe_plugin_add_settings_page');
66
67 // Render settings page
68 function iframe_plugin_settings_page() {
69 if (!current_user_can('manage_options')) {
70 return;
71 }
72
73 // Get current settings
74 $options = iframe_plugin_get_settings();
75 ?>
76 <div class="wrap">
77 <h1><?php echo esc_html(get_admin_page_title()); ?></h1>
78
79 <div style="display: flex; gap: 20px;">
80 <div style="flex: 1;">
81 <form action="options.php" method="post">
82 <?php
83 settings_fields('iframe_plugin_settings');
84 ?>
85 <table class="form-table" role="presentation">
86 <tr>
87 <th scope="row">
88 <label for="iframe_loading"><?php _e('Default Loading Behavior', 'iframe'); ?></label>
89 </th>
90 <td>
91 <select name="iframe_plugin_options[loading]" id="iframe_loading">
92 <option value="none" <?php selected($options['loading'], 'none'); ?>>
93 <?php _e('None (Browser Default - No loading attribute)', 'iframe'); ?>
94 </option>
95 <option value="lazy" <?php selected($options['loading'], 'lazy'); ?>>
96 <?php _e('Lazy (Recommended - Improves Performance)', 'iframe'); ?>
97 </option>
98 <option value="eager" <?php selected($options['loading'], 'eager'); ?>>
99 <?php _e('Eager (Load Immediately)', 'iframe'); ?>
100 </option>
101 </select>
102 <p class="description">
103 <?php _e('Choose when iframes should load. "Lazy" defers loading until the iframe is near the viewport, improving page performance. You can override this setting on individual shortcodes using the loading parameter.', 'iframe'); ?>
104 </p>
105 <p class="description">
106 <strong><?php _e('Example override:', 'iframe'); ?></strong>
107 <code>[iframe src="..." loading="eager"]</code>
108 </p>
109 </td>
110 </tr>
111 </table>
112 <?php submit_button(__('Save Settings', 'iframe')); ?>
113 </form>
114 </div>
115
116 <!-- Sidebar Promotion -->
117 <div style="width: 300px;">
118 <div style="background: #fff; border: 1px solid #ccd0d4; border-radius: 4px; padding: 20px; box-shadow: 0 1px 1px rgba(0,0,0,.04);">
119 <h2 style="margin-top: 0; font-size: 18px; border-bottom: 1px solid #eee; padding-bottom: 10px;">
120 <?php _e('Need More Features?', 'iframe'); ?>
121 </h2>
122
123 <div style="margin: 15px 0;">
124 <h3 style="font-size: 16px; margin: 0 0 15px 0; color: #333;">
125 <?php _e('You may try Advanced iFrame with more features', 'iframe'); ?>
126 </h3>
127 <ul style="list-style-type: disc; list-style-position: outside; margin: 0 0 15px 0; padding-left: 20px;">
128 <li><?php _e('Auto-resize to content height/width', 'iframe'); ?></li>
129 <li><?php _e('Show only specific iframe areas', 'iframe'); ?></li>
130 <li><?php _e('Modify CSS/JS in parent and iframe', 'iframe'); ?></li>
131 <li><?php _e('Forward parameters & URL mapping', 'iframe'); ?></li>
132 <li><?php _e('Hide elements & custom styling', 'iframe'); ?></li>
133 <li><?php _e('Cross-domain support with workaround', 'iframe'); ?></li>
134 <li><?php _e('Widget support & much more', 'iframe'); ?></li>
135 </ul>
136 <p style="margin: 0 0 15px 0;">
137 <a href="https://r.freemius.com/13759/8047958/" target="_blank" class="button button-primary" style="width: 100%; text-align: center; box-sizing: border-box;">
138 <?php _e('Try Advanced iFrame', 'iframe'); ?>
139 </a>
140 </p>
141 <p style="margin: 0 0 15px 0; color: #666; font-size: 12px; font-style: italic;">
142 <?php _e('✓ 30-day trial available', 'iframe'); ?>
143 </p>
144 </div>
145 </div>
146 </div>
147 </div>
148 </div>
149 <?php
150 }
151