Completed
Push — renovate/babel-eslint-10.x ( cb89d5...6fd2a7 )
by
unknown
25:23 queued 18:32
created

Jetpack_Settings_Page::page_render()   C

Complexity

Conditions 12
Paths 128

Size

Total Lines 108

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
nc 128
nop 0
dl 0
loc 108
rs 5.3865
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
		$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
		$rest_api_notice = str_replace(
47
			'#HEADER_TEXT#',
48
			esc_html( __( 'WordPress REST API is disabled', 'jetpack' ) ),
49
			$rest_api_notice
50
		);
51
		$rest_api_notice = str_replace(
52
			'#TEXT#',
53
			esc_html( __( "Enable WordPress REST API to unlock Jetpack's full potential!", 'jetpack' ) ),
54
			$rest_api_notice
55
		);
56
57
		$ie_notice = str_replace(
58
			'#HEADER_TEXT#',
59
			esc_html__( 'You are using an unsupported browser version.', 'jetpack' ),
60
			$ie_notice
61
		);
62
		$ie_notice = str_replace(
63
			'#TEXT#',
64
			esc_html__( "Update your browser to unlock Jetpack's full potential!", 'jetpack' ),
65
			$ie_notice
66
		);
67
68
		if ( ! $this->is_rest_api_enabled() ) {
69
			echo $rest_api_notice;
70
		}
71
		echo $noscript_notice;
72
		echo $ie_notice;
73
		?>
74
75
		<div class="page-content configure">
76
			<div class="frame top hide-if-no-js">
77
				<div class="wrap">
78
					<div class="manage-left">
79
						<table class="table table-bordered fixed-top">
80
							<thead>
81
								<tr>
82
									<th class="check-column"><input type="checkbox" class="checkall"></th>
83
									<th colspan="2">
84
										<?php $list_table->unprotected_display_tablenav( 'top' ); ?>
85
										<span class="filter-search">
86
											<button type="button" class="button">Filter</button>
87
										</span>
88
									</th>
89
								</tr>
90
							</thead>
91
						</table>
92
					</div>
93
				</div><!-- /.wrap -->
94
			</div><!-- /.frame -->
95
			<div class="frame bottom">
96
				<div class="wrap">
97
					<div class="manage-right" style="display: none;">
98
						<div class="bumper">
99
							<form class="navbar-form" role="search">
100
								<input type="hidden" name="page" value="jetpack_modules" />
101
								<?php $list_table->search_box( __( 'Search', 'jetpack' ), 'srch-term' ); ?>
102
								<p><?php esc_html_e( 'View:', 'jetpack' ); ?></p>
103
								<div class="button-group filter-active">
104
									<button type="button" class="button <?php if ( empty( $_GET['activated'] ) ) echo 'active'; ?>"><?php esc_html_e( 'All', 'jetpack' ); ?></button>
105
									<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>
106
									<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>
107
								</div>
108
								<p><?php esc_html_e( 'Sort by:', 'jetpack' ); ?></p>
109
								<div class="button-group sort">
110
									<button type="button" class="button <?php if ( empty( $_GET['sort_by'] ) ) echo 'active'; ?>" data-sort-by="name"><?php esc_html_e( 'Alphabetical', 'jetpack' ); ?></button>
111
									<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>
112
									<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>
113
								</div>
114
								<p><?php esc_html_e( 'Show:', 'jetpack' ); ?></p>
115
								<?php $list_table->views(); ?>
116
							</form>
117
						</div>
118
					</div>
119
					<div class="manage-left" style="width: 100%;">
120
						<form class="jetpack-modules-list-table-form" onsubmit="return false;">
121
						<table class="<?php echo implode( ' ', $list_table->get_table_classes() ); ?>">
122
							<tbody id="the-list">
123
								<?php $list_table->display_rows_or_placeholder(); ?>
124
							</tbody>
125
						</table>
126
						</form>
127
					</div>
128
				</div><!-- /.wrap -->
129
			</div><!-- /.frame -->
130
		</div><!-- /.content -->
131
		<?php
132
133
		JetpackTracking::record_user_event( 'wpa_page_view', array( 'path' => 'old_settings' ) );
134
	}
135
136
	/**
137
	 * Load styles for static page.
138
	 *
139
	 * @since 4.3.0
140
	 */
141
	function additional_styles() {
142
		Jetpack_Admin_Page::load_wrapper_styles();
143
	}
144
145
	// Javascript logic specific to the list table
146
	function page_admin_scripts() {
147
		wp_enqueue_script(
148
			'jetpack-admin-js',
149
			Jetpack::get_file_url_for_environment( '_inc/build/jetpack-admin.min.js', '_inc/jetpack-admin.js' ),
150
			array( 'jquery' ),
151
			JETPACK__VERSION
152
		);
153
	}
154
}
155