PluginProbe
Code Embed / 2.6
Code Embed v2.6
2.6.4 2.6.3 2.6.2 2.6.1 trunk 1.0 1.1 1.2 1.3 1.4.1 1.5.1 1.6.1 2.0.2 2.1.2 2.2.2 2.3.9 2.4 2.5.1 2.5.2 2.6
simple-embed-code / includes / options-screen.php

options-screen.php in Code Embed 2.6, at includes/options-screen.php

135 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Code Embed Options
4 *
5 * Allow the user to change the default options.
6 *
7 * @package simple-embed-code
8 */
9
10 // Exit if accessed directly.
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15 ?>
16 <div class="wrap">
17 <h1><?php echo esc_html__( 'Code Embed Options', 'simple-embed-code' ); ?></h1>
18 <?php
19
20 // If options have been updated on screen, update the database.
21
22 if ( ( ! empty( $_POST ) ) && ( check_admin_referer( 'code-embed-profile', 'code_embed_profile_nonce' ) ) ) {
23
24 // Make sure the user has the correct permissions. This is a belt-and-braces check as this is already done by core at page access time.
25
26 if ( ! current_user_can( 'manage_options' ) ) {
27 wp_die( esc_html__( 'Insufficient permissions.', 'simple-embed-code' ) );
28 }
29
30 // Get the options. If they don't exist, create a new array.
31
32 $options = get_option( 'artiss_code_embed' );
33 if ( ! is_array( $options ) ) {
34 $options = array();
35 }
36
37 // Update the options array from the form fields. Strip invalid tags.
38
39 if ( ! empty( $_POST['code_embed_opening'] ) ) {
40 $options['opening_ident'] = strtoupper( trim( sanitize_text_field( wp_unslash( $_POST['code_embed_opening'] ) ) ) );
41 } else {
42 $options['opening_ident'] = '{{';
43 }
44
45 if ( ! empty( $_POST['code_embed_keyword'] ) ) {
46 $options['keyword_ident'] = strtoupper( trim( sanitize_text_field( wp_unslash( $_POST['code_embed_keyword'] ) ) ) );
47 } else {
48 $options['keyword_ident'] = 'CODE';
49 }
50
51 if ( ! empty( $_POST['code_embed_closing'] ) ) {
52 $options['closing_ident'] = strtoupper( trim( sanitize_text_field( wp_unslash( $_POST['code_embed_closing'] ) ) ) );
53 } else {
54 $options['closing_ident'] = '}}';
55 }
56
57 if ( isset( $_POST['code_embed_excerpt'] ) ) {
58 $options['excerpt'] = sanitize_text_field( wp_unslash( $_POST['code_embed_excerpt'] ) );
59 } else {
60 $options['excerpt'] = '';
61 }
62
63 update_option( 'artiss_code_embed', $options );
64
65 echo '<div class="updated fade" role="status"><p><strong>' . esc_html__( 'Settings saved.', 'simple-embed-code' ) . "</strong></p></div>\n";
66 }
67
68 // Fetch options into an array.
69
70 $options = get_option( 'artiss_code_embed' );
71 ?>
72
73 <form method="post" action="<?php echo esc_url( admin_url( 'options-general.php?page=ce-options' ) ); ?>">
74
75 <table class="form-table">
76
77 <tr>
78 <th scope="row"><label for="code_embed_excerpt"><?php echo esc_html__( 'Allow in excerpts', 'simple-embed-code' ); ?></label></th>
79 <td><input type="checkbox" id="code_embed_excerpt" name="code_embed_excerpt" value="1"
80 <?php checked( '1', $options['excerpt'] ); ?>
81 /><label for="code_embed_excerpt"><?php esc_html_e( 'Allow embedded code to be shown in excerpts', 'simple-embed-code' ); ?></label></td>
82 </tr>
83
84 </table>
85
86 <?php echo '<h2>' . esc_html__( 'Identifier Format', 'simple-embed-code' ) . '</h2><p>' . esc_html__( 'Specify the format that will be used to define the way the code is embedded in your post. The formats are case insensitive and characters &lt; &gt [ ] are invalid.', 'simple-embed-code' ) . '</p>'; ?>
87
88 <table class="form-table">
89
90 <tr>
91 <th scope="row"><label for="code_embed_keyword"><?php echo esc_html__( 'Keyword', 'simple-embed-code' ); ?></label></th>
92 <td><input type="text" size="12" maxlength="12" id="code_embed_keyword" name="code_embed_keyword" value="<?php echo esc_attr( $options['keyword_ident'] ); ?>"/><p class="description"><?php esc_html_e( 'The keyword that is used to name the custom field and then place in your post where the code should be embedded. A suffix of any type can then be placed on the end.', 'simple-embed-code' ); ?></p></td>
93 </tr>
94
95 <tr>
96 <th scope="row"><label for="code_embed_opening"><?php echo esc_html__( 'Opening Identifier', 'simple-embed-code' ); ?></label></th>
97 <td><input type="text" size="4" maxlength="4" id="code_embed_opening" name="code_embed_opening" value="<?php echo esc_attr( $options['opening_ident'] ); ?>"/><p class="description"><?php esc_html_e( 'The character(s) that must be placed in the post before the keyword to uniquely identify it.', 'simple-embed-code' ); ?></p></td>
98 </tr>
99
100 <tr>
101 <th scope="row"><label for="code_embed_closing"><?php echo esc_html__( 'Closing Identifier', 'simple-embed-code' ); ?></label></th>
102 <td><input type="text" size="4" maxlength="4" id="code_embed_closing" name="code_embed_closing" value="<?php echo esc_attr( $options['closing_ident'] ); ?>"/><p class="description"><?php esc_html_e( 'The character(s) that must be placed in the post after the keyword to uniquely identify it.', 'simple-embed-code' ); ?></p></td>
103 </tr>
104
105 </table>
106
107 <?php wp_nonce_field( 'code-embed-profile', 'code_embed_profile_nonce', true, true ); ?>
108
109 <p><input type="submit" name="Submit" class="button-primary" value="<?php echo esc_attr__( 'Save changes', 'simple-embed-code' ); ?>"/></p>
110
111 </form>
112
113 <?php
114
115 // How to embed.
116
117 echo '<h2>' . esc_html__( 'How To Embed', 'simple-embed-code' ) . "</h2>\n";
118
119 /* translators: %1$s: example of custom field key value to use based on current settings, %2$s: details of key used in example */
120 echo '<p>' . sprintf( esc_html__( 'Based upon your current settings to embed some code simply add a custom field named %1$s, where %2$s is any suffix you wish. The code to embed is then added as the field value.', 'simple-embed-code' ), esc_html( $options['keyword_ident'] ) . 'x', 'x' ) . "\n";
121
122 /* translators: %1$s: example of how to embed code in a post based on current settings, %2$s: details of key used in example */
123 echo ' ' . sprintf( esc_html__( 'Then, to add the code into your post simply add %1$s where you wish it to appear. %2$s is the suffix you used for the custom field name.', 'simple-embed-code' ), esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ) . 'x' . esc_html( $options['closing_ident'] ), 'x' ) . "</p>\n";
124
125 /* translators: %1$s: another example of adding a custom field, %2$s: another example of adding embed to a post */
126
127 /* translators: %1$s: example embedding for responsive layout , %2$s: details of key used in example */
128 echo '<p>' . sprintf( esc_html__( 'To embed the same code but to make it responsive you would use %1$s. To set a maximum width you would use %2$s, where %3$s is the maximum width in pixels.', 'simple-embed-code' ), esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ) . 'x_RES' . esc_html( $options['closing_ident'] ), esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ) . 'x_RES_y' . esc_html( $options['closing_ident'] ), 'y' ) . "</p>\n";
129
130 /* translators: %1$s: example of embedding a file, %2$s: details of key used in example */
131 echo '<p>' . sprintf( esc_html__( 'To embed an external URL you would type %1$s, where %2$s is the URL.', 'simple-embed-code' ), esc_html( $options['opening_ident'] ) . 'url' . esc_html( $options['closing_ident'] ), 'url' ) . "</p>\n";
132 ?>
133
134 </div>
135