| 1 |
<?php |
| 2 |
function flying_scripts_format_list($list) { |
| 3 |
$list = trim($list); |
| 4 |
$list = $list ? array_map('trim', explode("\n", str_replace("\r", "", $list))) : []; |
| 5 |
return $list; |
| 6 |
} |
| 7 |
|
| 8 |
function flying_scripts_view_settings() { |
| 9 |
|
| 10 |
if (isset($_POST['submit'])) { |
| 11 |
update_option('flying_scripts_timeout', sanitize_text_field($_POST['flying_scripts_timeout'])); |
| 12 |
update_option('flying_scripts_include_list', flying_scripts_format_list($_POST['flying_scripts_include_list'])); |
| 13 |
} |
| 14 |
|
| 15 |
$timeout = get_option('flying_scripts_timeout'); |
| 16 |
$include_list = get_option('flying_scripts_include_list'); |
| 17 |
|
| 18 |
?> |
| 19 |
<form method="POST"> |
| 20 |
<?php wp_nonce_field('flying-scripts', 'flying-scripts-settings-form'); ?> |
| 21 |
<table class="form-table" role="presentation"> |
| 22 |
<tbody> |
| 23 |
<tr> |
| 24 |
<th scope="row"><label>Include Keywords</label></th> |
| 25 |
<td> |
| 26 |
<textarea name="flying_scripts_include_list" rows="4" cols="50"><?php echo implode(' ', $include_list); ?></textarea> |
| 27 |
<p class="description">Keywords that identify scripts that should load on user interaction. One keyword per line.</p> |
| 28 |
</td> |
| 29 |
</tr> |
| 30 |
<tr> |
| 31 |
<th scope="row"><label>Timeout</label></th> |
| 32 |
<td> |
| 33 |
<select name="flying_scripts_timeout" value="<?php echo $timeout; ?>"> |
| 34 |
<option value="1" <?php if ($timeout == 1) {echo 'selected';} ?>>1s</option> |
| 35 |
<option value="2" <?php if ($timeout == 2) {echo 'selected';} ?>>2s</option> |
| 36 |
<option value="3" <?php if ($timeout == 3) {echo 'selected';} ?>>3s</option> |
| 37 |
<option value="4" <?php if ($timeout == 4) {echo 'selected';} ?>>4s</option> |
| 38 |
<option value="5" <?php if ($timeout == 5) {echo 'selected';} ?>>5s</option> |
| 39 |
<option value="6" <?php if ($timeout == 6) {echo 'selected';} ?>>6s</option> |
| 40 |
<option value="7" <?php if ($timeout == 7) {echo 'selected';} ?>>7s</option> |
| 41 |
<option value="8" <?php if ($timeout == 8) {echo 'selected';} ?>>8s</option> |
| 42 |
<option value="9" <?php if ($timeout == 9) {echo 'selected';} ?>>9s</option> |
| 43 |
<option value="10" <?php if ($timeout == 10) {echo 'selected';} ?>>10s</option> |
| 44 |
</select> |
| 45 |
<p class="description">Load scripts after a timeout when there is no user interaction</p> |
| 46 |
<td> |
| 47 |
</tr> |
| 48 |
</tbody> |
| 49 |
</table> |
| 50 |
<p class="submit"> |
| 51 |
<input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes"> |
| 52 |
</p> |
| 53 |
</form> |
| 54 |
<?php |
| 55 |
} |
| 56 |
|