Completed
Push — plugin-submission ( 832c1a...6a66a3 )
by LA
01:50
created

options-page.php ➔ imgix_options_page()   B

Complexity

Conditions 8
Paths 1

Size

Total Lines 53
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 18
nc 1
nop 0
dl 0
loc 53
rs 7.1199
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 *
4
 * Renders options page
5
 *
6
 * @package imgix
7
 */
8
function imgix_options_page() {
9
10
	global $imgix_options;
11
12
?>
13
	<div class="wrap">
14
15
                <h1><img src="<?php echo IMGIX_PLUGIN_URL; ?>assets/images/imgix-logo.png" alt="imgix Logo"></h1>
16
                <h1><img src="<?php echo IMGIX_PLUGIN_URL; ?>assets/images/imgix-logo.png" alt="imgix Logo"></h1>
17
18
                <p><strong>Need help getting started?</strong> It's easy! Check out our <a href="https://github.com/imgix-wordpress/imgix-wordpress#getting-started" target="_blank">instructions.</a></p>
19
20
		<form method="post" action="options.php">
21
			<?php settings_fields( 'imgix_settings_group' ); ?>
22
23
			<table class="form-table">
24
25
				<tbody>
26
27
					<tr>
28
						<th><label class="description" for="imgix_settings[cdn_link]"><?php esc_html_e( 'imgix Source', 'imgix_domain' ); ?></th>
29
						<td><input id="imgix_settings[cdn_link]" type="url" name="imgix_settings[cdn_link]" placeholder="https://yourcompany.imgix.net" value="<?php echo isset( $imgix_options['cdn_link'] ) ? esc_url( $imgix_options['cdn_link'] ) : ''; ?>" class="regular-text code" /></td>
30
					</tr>
31
32
					<tr>
33
                                                <th><label class="description" for="imgix_settings[auto_format]"><?php esc_html_e( 'Auto Format Images', 'auto_format' ); ?></label></th>
34
						<td><input id="imgix_settings[auto_format]" type="checkbox" name="imgix_settings[auto_format]" value="1" <?php echo isset( $imgix_options['auto_format'] ) && '1' === $imgix_options['auto_format'] ? 'checked="checked"' : ''; ?> /></td>
35
					</tr>
36
37
					<tr>
38
                                                <th><label class="description" for="imgix_settings[auto_enhance]"><?php esc_html_e( 'Auto Enhance Images', 'auto_enhance' ); ?></label></th>
39
						<td><input id="imgix_settings[auto_enhance]" type="checkbox" name="imgix_settings[auto_enhance]" value="1" <?php echo isset( $imgix_options['auto_enhance'] ) && '1' === $imgix_options['auto_enhance'] ? 'checked="checked"' : ''; ?> /></td>
40
					</tr>
41
42
					<tr>
43
						<th><label class="description" for="imgix_settings[add_dpi2_srcset]"><?php esc_html_e( 'Automatically add retina images using srcset', 'add_dpi2_srcset' ); ?></label></th>
44
						<td><input id="imgix_settings[add_dpi2_srcset]" type="checkbox" name="imgix_settings[add_dpi2_srcset]" value="1" <?php echo isset( $imgix_options['add_dpi2_srcset'] ) && '1' === $imgix_options['add_dpi2_srcset'] ? 'checked="checked"' : ''; ?> /></td>
45
					</tr>
46
47
				</tbody>
48
			</table>
49
50
			<p class="submit">
51
				<input type="submit" class="button-primary" value="<?php esc_html_e( 'Save Options', 'imgix_domain' ); ?>" />
52
			</p>
53
		</form>
54
55
		<p class="description">
56
			This plugin is powered by <a href="http://www.imgix.com" target="_blank">imgix</a>. You can find and contribute to the code on <a href="https://github.com/imgix-wordpress/imgix-wordpress" target="_blank">GitHub</a>.
57
		</p>
58
	</div>
59
<?php
60
}
61
62
/**
63
 *  Adds link to options page in Admin > Settings menu.
64
 */
65
function imgix_add_options_link() {
66
	add_options_page( 'imgix', 'imgix', 'manage_options', 'imgix-options', 'imgix_options_page' );
67
}
68
add_action( 'admin_menu', 'imgix_add_options_link' );
69
70
/**
71
 *  Creates our settings in the options table.
72
 */
73
function imgix_register_settings() {
74
	register_setting( 'imgix_settings_group', 'imgix_settings' );
75
}
76
77
add_action( 'admin_init', 'imgix_register_settings' );
78