Completed
Push — add/crowdsignal-shortcode ( 65c42e...1b4a63 )
by Kuba
14:46 queued 06:22
created

Jetpack_Settings_Page::page_render()   D

Complexity

Conditions 13
Paths 256

Size

Total Lines 122

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
nc 256
nop 0
dl 0
loc 122
rs 4.0666
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
include_once( 'class.jetpack-admin-page.php' );
3
include_once( JETPACK__PLUGIN_DIR . 'class.jetpack-modules-list-table.php' );
4
5
// Builds the settings page and its menu
6
class Jetpack_Settings_Page extends Jetpack_Admin_Page {
7
8
	// Show the settings page only when Jetpack is connected or in dev mode
9
	protected $dont_show_if_not_active = true;
10
11
	function add_page_actions( $hook ) {}
12
13
	// Adds the Settings sub menu
14
	function get_page_hook() {
15
		return add_submenu_page(
16
			null,
17
			__( 'Jetpack Settings', 'jetpack' ),
18
			__( 'Settings', 'jetpack' ),
19
			'jetpack_manage_modules',
20
			'jetpack_modules',
21
			array( $this, 'render' )
22
		);
23
	}
24
25
	// Renders the module list table where you can use bulk action or row
26
	// actions to activate/deactivate and configure modules
27
	function page_render() {
28
		$list_table = new Jetpack_Modules_List_Table;
29
30
		// We have static.html so let's continue trying to fetch the others
31
		$noscript_notice = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static-noscript-notice.html' );
32
		$version_notice = $rest_api_notice = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static-version-notice.html' );
33
		$ie_notice = @file_get_contents( JETPACK__PLUGIN_DIR . '_inc/build/static-ie-notice.html' );
34
35
		$noscript_notice = str_replace(
36
			'#HEADER_TEXT#',
37
			esc_html__( 'You have JavaScript disabled', 'jetpack' ),
38
			$noscript_notice
39
		);
40
		$noscript_notice = str_replace(
41
			'#TEXT#',
42
			esc_html__( "Turn on JavaScript to unlock Jetpack's full potential!", 'jetpack' ),
43
			$noscript_notice
44
		);
45
46
		$version_notice = str_replace(
47
			'#HEADER_TEXT#',
48
			esc_html__( 'You are using an outdated version of WordPress', 'jetpack' ),
49
			$version_notice
50
		);
51
		$version_notice = str_replace(
52
			'#TEXT#',
53
			esc_html__( "Update WordPress to unlock Jetpack's full potential!", 'jetpack' ),
54
			$version_notice
55
		);
56
57
		$rest_api_notice = str_replace(
58
			'#HEADER_TEXT#',
59
			esc_html( __( 'WordPress REST API is disabled', 'jetpack' ) ),
60
			$rest_api_notice
61
		);
62
		$rest_api_notice = str_replace(
63
			'#TEXT#',
64
			esc_html( __( "Enable WordPress REST API to unlock Jetpack's full potential!", 'jetpack' ) ),
65
			$rest_api_notice
66
		);
67
68
		$ie_notice = str_replace(
69
			'#HEADER_TEXT#',
70
			esc_html__( 'You are using an unsupported browser version.', 'jetpack' ),
71
			$ie_notice
72
		);
73
		$ie_notice = str_replace(
74
			'#TEXT#',
75
			esc_html__( "Update your browser to unlock Jetpack's full potential!", 'jetpack' ),
76
			$ie_notice
77
		);
78
79
		if ( $this->is_wp_version_too_old() ) {
80
			echo $version_notice;
81
		}
82
		if ( ! $this->is_rest_api_enabled() ) {
83
			echo $rest_api_notice;
84
		}
85
		echo $noscript_notice;
86
		echo $ie_notice;
87
		?>
88
89
		<div class="page-content configure">
90
			<div class="frame top hide-if-no-js">
91
				<div class="wrap">
92
					<div class="manage-left">
93
						<table class="table table-bordered fixed-top">
94
							<thead>
95
								<tr>
96
									<th class="check-column"><input type="checkbox" class="checkall"></th>
97
									<th colspan="2">
98
										<?php $list_table->unprotected_display_tablenav( 'top' ); ?>
99
										<span class="filter-search">
100
											<button type="button" class="button">Filter</button>
101
										</span>
102
									</th>
103
								</tr>
104
							</thead>
105
						</table>
106
					</div>
107
				</div><!-- /.wrap -->
108
			</div><!-- /.frame -->
109
			<div class="frame bottom">
110
				<div class="wrap">
111
					<div class="manage-right" style="display: none;">
112
						<div class="bumper">
113
							<form class="navbar-form" role="search">
114
								<input type="hidden" name="page" value="jetpack_modules" />
115
								<?php $list_table->search_box( __( 'Search', 'jetpack' ), 'srch-term' ); ?>
116
								<p><?php esc_html_e( 'View:', 'jetpack' ); ?></p>
117
								<div class="button-group filter-active">
118
									<button type="button" class="button <?php if ( empty( $_GET['activated'] ) ) echo 'active'; ?>"><?php esc_html_e( 'All', 'jetpack' ); ?></button>
119
									<button type="button" class="button <?php if ( ! empty( $_GET['activated'] ) && 'true' == $_GET['activated'] ) echo 'active'; ?>" data-filter-by="activated" data-filter-value="true"><?php esc_html_e( 'Active', 'jetpack' ); ?></button>
120
									<button type="button" class="button <?php if ( ! empty( $_GET['activated'] ) && 'false' == $_GET['activated'] ) echo 'active'; ?>" data-filter-by="activated" data-filter-value="false"><?php esc_html_e( 'Inactive', 'jetpack' ); ?></button>
121
								</div>
122
								<p><?php esc_html_e( 'Sort by:', 'jetpack' ); ?></p>
123
								<div class="button-group sort">
124
									<button type="button" class="button <?php if ( empty( $_GET['sort_by'] ) ) echo 'active'; ?>" data-sort-by="name"><?php esc_html_e( 'Alphabetical', 'jetpack' ); ?></button>
125
									<button type="button" class="button <?php if ( ! empty( $_GET['sort_by'] ) && 'introduced' == $_GET['sort_by'] ) echo 'active'; ?>" data-sort-by="introduced" data-sort-order="reverse"><?php esc_html_e( 'Newest', 'jetpack' ); ?></button>
126
									<button type="button" class="button <?php if ( ! empty( $_GET['sort_by'] ) && 'sort' == $_GET['sort_by'] ) echo 'active'; ?>" data-sort-by="sort"><?php esc_html_e( 'Popular', 'jetpack' ); ?></button>
127
								</div>
128
								<p><?php esc_html_e( 'Show:', 'jetpack' ); ?></p>
129
								<?php $list_table->views(); ?>
130
							</form>
131
						</div>
132
					</div>
133
					<div class="manage-left" style="width: 100%;">
134
						<form class="jetpack-modules-list-table-form" onsubmit="return false;">
135
						<table class="<?php echo implode( ' ', $list_table->get_table_classes() ); ?>">
136
							<tbody id="the-list">
137
								<?php $list_table->display_rows_or_placeholder(); ?>
138
							</tbody>
139
						</table>
140
						</form>
141
					</div>
142
				</div><!-- /.wrap -->
143
			</div><!-- /.frame -->
144
		</div><!-- /.content -->
145
		<?php
146
147
		JetpackTracking::record_user_event( 'wpa_page_view', array( 'path' => 'old_settings' ) );
148
	}
149
150
	/**
151
	 * Load styles for static page.
152
	 *
153
	 * @since 4.3.0
154
	 */
155
	function additional_styles() {
156
		Jetpack_Admin_Page::load_wrapper_styles();
157
	}
158
159
	// Javascript logic specific to the list table
160
	function page_admin_scripts() {
161
		wp_enqueue_script(
162
			'jetpack-admin-js',
163
			Jetpack::get_file_url_for_environment( '_inc/build/jetpack-admin.min.js', '_inc/jetpack-admin.js' ),
164
			array( 'jquery' ),
165
			JETPACK__VERSION
166
		);
167
	}
168
}
169