Completed
Push — master ( a8ef06...de0a9e )
by
unknown
02:00 queued 10s
created

welcome::lasso_preflight_check()   B

Complexity

Conditions 10
Paths 64

Size

Total Lines 60

Duplication

Lines 10
Ratio 16.67 %

Importance

Changes 0
Metric Value
cc 10
nc 64
nop 0
dl 10
loc 60
rs 7.006
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
/**
3
 * Creates a welcome screen with pre-flight check sequence
4
 *
5
 * @since 0.8.2
6
 */
7
namespace lasso_admin\menus;
8
9
class welcome {
10
11
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
12
13
		add_action( 'admin_init',   array( $this, 'redirect' ) );
14
		add_action( 'admin_menu',   array( $this, 'lasso_welcome' ) );
15
		add_action( 'network_admin_menu',   array( $this, 'lasso_welcome' ) );  // CHANGED Added hook.
16
17
		add_action( 'tgmpa_register',  array( $this,'required_plugins' ));
18
19
	}
20
21
	function redirect() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
22
23
		// Bail if no activation redirect
24
		if ( !get_transient( '_lasso_welcome_redirect' ) ) {
25
			return;
26
		}
27
28
		// Delete the redirect transient
29
		delete_transient( '_lasso_welcome_redirect' );
30
31
		// Bail if activating from network, or bulk
32
		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
33
			return;
34
		}
35
36
		wp_safe_redirect( esc_url_raw( add_query_arg( array( 'page' => 'lasso-editor' ), admin_url( 'admin.php' ) ) ) );
37
38
	}
39
40
	/**
41
	 * Add dashboard pages for welcome and welcome back
42
	 *
43
	 * @since 0.8
44
	 */
45
	function lasso_welcome() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
46
47
		// CHANGED Removed condition.
48
		add_menu_page( __( 'Editus', 'lasso' ), __( 'Editus', 'lasso' ), 'manage_options', 'lasso-editor', '', LASSO_URL.'/admin/assets/img/menu-icon.png' );
49
		add_submenu_page( 'lasso-editor', __( 'Welcome', 'lasso' ), __( 'Status', 'lasso' ), 'manage_options', 'lasso-editor', array( $this, 'welcome' ) );
50
51
	}
52
53
	/**
54
	 * Callback for the intial welcome screen for new users
55
	 *
56
	 * @since 0.8.2
57
	 */
58
	function welcome() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
59
60
		?>
61
		  <div class="wrap lasso--welcome">
62
63
		  		<?php self::header();?>
64
65
		  		<ul class="lasso--welcome__steps">
66
67
		  		<?php // CHANGED Added the is_network_admin condition. ?>
68
			  		<?php if ( is_network_admin() ) : ?>
69
70
			  			<li>
71
			  				<p><?php _e( 'We will check the current theme on every site in your network and give you a quick status feedback here. You can see the status by visiting the Editus menu on each site.', 'lasso' );?></p>
72
			  			</li>
73
74
			  		<?php else :
75
76
					$checks = self::lasso_preflight_check();
77
78
					if ( $checks && !defined( 'LASSO_AGENCY_MODE' ) ):
79
80
						foreach ( (array) $checks as $key => $check ) {
81
82
							echo $check;
83
						}
84
85
						else:
86
87
							// pre-flight is go for flight
88
						?>
89
						<li class="success">
90
							<h3><?php _e( 'You\'re Ready to Rock!', 'lasso' );?></h3>
91
							<?php if ( lasso_get_supported_theme_class() ) { ?>
92
							<p><?php _e( 'Your theme is automatically supported. No additional setup is needed.', 'lasso' );?></p>
93
							<?php } ?>
94
			  				<p><?php _e( 'Editus will place a small menu on the bottom of your site. While on a single post or page, click the "pen" icon to go into edit mode. Press escape to get out of edit mode.', 'lasso' );?></p>
95
			  			</li>
96
			  			<?php
97
			  			endif;
98
					endif; ?>
99
100
			  	</ul>
101
		  	</div>
102
	 	<?php
103
	}
104
105
	/**
106
	 * Universal header draw on both welcome and activation screens
107
	 *
108
	 * @since 0.8.2
109
	 */
110
	function header() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
111
112
?>
113
114
	  		<div class="lasso--welcome__top">
115
116
	  			<img style="width:125px;" src="<?php echo LASSO_URL.'/admin/assets/img/logo.png';?>">
117
	    		<h1><?php _e( 'Welcome to Editus', 'lasso' );?></h1>
118
	    		<p><?php _e( 'Version', 'lasso' );echo '<span> '.LASSO_VERSION.'</span>';?></p>
119
120
	    		<?php if ( !defined( 'LASSO_AGENCY_MODE' ) ): ?>
121
122
			    	<ul class="lasso--welcome__social">
123
			    		<li><a href="https://edituswp.com/help" target="_blank"><i class="dashicons dashicons-sos"></i> <?php _e( 'Help', 'lasso' );?></a></li>
124
			    		<li><a href="http://twitter.com/aesopinteractiv" target="_blank"><i class="dashicons dashicons-twitter"></i> <?php _e( 'Twitter', 'lasso' );?></a></li>
125
			    		<li><a href="http://facebook.com/aesopinteractive" target="_blank"><i class="dashicons dashicons-facebook"></i> <?php _e( 'Facebook', 'lasso' );?></a></li>
126
			    	</ul>
127
128
			    <?php endif; ?>
129
130
		    </div>
131
132
	 	<?php
133
	}
134
135
	/**
136
	 * Run a series of checks to inform the user about incompatibilities, missing option fields, missing license keys for updates and suggested addons
137
	 *
138
	 * @since 0.8.6
139
	 */
140
	function lasso_preflight_check() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
141
142
		$notices 		= array();
143
144
		$article_object = lasso_editor_get_option( 'article_class', 'lasso_editor' );
145
146
		$theme_name  	= wp_get_theme()->get('Name');
0 ignored issues
show
Unused Code introduced by
$theme_name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
147
		$theme_class  	= lasso_get_supported_theme_class();
148
149
		$license   		= get_option( 'lasso_license_key' );
150
		$status   		= get_option( 'lasso_license_status' );
151
		
152
153
		// if the required CSS class has not been saved
154
		if ( empty( $article_object ) && false == $theme_class ) {
155
156
			// we dont automatically support this theme so show them otherwise
157
			$notices[] = sprintf('<li class="error">
158
							<h3>'.__( 'Article CSS Class Needed!', 'lasso' ).'</h3>
159
							<p>'.__( 'Before using Editus,', 'lasso' ).' <a href="%s">'.__( 'enter and save', 'lasso' ).'</a> '.__( 'the CSS class of the container that holds your post and page content. You can <a href="https://dl.dropboxusercontent.com/u/5594632/lasso-media/doc-movies/using-inspector-lasso.gif" target="_blank">use a tool like inspector</a> in Chrome or Firefox to find this CSS class, or ', 'lasso' ).' <a href="mailto:[email protected]">'.__( 'email us.', 'lasso' ).'</a> '.__( 'with a link to a public URL with the theme and we\'ll find it for you.', 'lasso' ).'</p>
160
							</li>', admin_url( 'admin.php?page=lasso-editor-settings' ) );
161
		}
162
163
		// WP REST API not active
164
		if ( !function_exists( 'json_get_url_prefix' ) &&  !function_exists( 'rest_url' )) {
165
			$notices[] = '<li class="info"><h3>WP REST API not Activated!</h3>
166
							<p>'.__( 'Just a heads up that the WP REST API isn\'t activated. This is required to list the posts and pages on the front-end.', 'lasso' ).'</p>
167
							</li>';
168
		}
169
170
		// aesop story engine isnt active
171
		if ( !class_exists( 'Aesop_Core' ) ) {
172
			$notices[] = sprintf( '<li class="info"><h3>Aesop Story Engine not Activated!</h3>
173
							<p>'.__( 'Just a heads up that ', 'lasso' ).'<a href="%s" target="_blank
174
							">'.__( 'Aesop Story Engine', 'lasso' ).'</a> '.__( 'isn\'t activated. It\'s not required to use Editus, but you won\'t get the cool drag and drop components without it activated. It\'s free!', 'lasso' ).'</p>
175
							</li>', admin_url('plugin-install.php?tab=search&s=aesop+story+engine') );
176
		}
177
178
		// we dont really get along with wp side comments because of the section ids that get applied dynamically. since we save our html, it'll get saved along with the post as HTML
179 View Code Duplication
		if ( class_exists( 'WP_Side_Comments' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
180
			$notices[] = '<li class="error"><h3>'.__( 'WP Side Comments Compatibility Warning!', 'lasso' ).'</h3>
181
							<p>'.__( 'Since Editus saves the HTML of a post, this may cause undesired issues. We\'re working to resolve incompatibilities faster than a jack rabbit in a hot greasy griddle in the middle of August.', 'lasso' ).'</p>
182
							</li>';
183
		}
184
185
		// if the license key isnt activated
186 View Code Duplication
		if ( empty( $license ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
187
			$notices[] = '<li class="info"><h3>'.__( 'License Key Not Activated', 'lasso' ).'</h3>
188
							<p>'.__( 'Just a heads up, your license key isn\'t activated. Enter your license key into the License tab on the left in order to receive plugin update notifications.', 'lasso' ).'</p>
189
							</li>';
190
		}
191
		if ( !empty( $license ) && 'invalid' == $status ) {
192
			$notices[] = '<li class="error"><h3>'.__( 'License Key Invalid', 'lasso' ).'</h3>
193
							<p>'.__( 'The license key that you entered is ', 'lasso' ).'<strong>'.__( 'invalid', 'lasso' ).'</strong>'.__( '. It may have been entered incorreclty, or may have expired.', 'lasso' ).'</p>
194
							</li>';
195
		}
196
197
		return apply_filters( 'lasso_preflight_notices', $notices );
198
199
	}
200
201
	/**
202
	 * Register the required plugins for this theme.
203
	 *
204
	 *	@since 0.9.3
205
	 */
206
	function required_plugins() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
207
208
	    $plugins = array(
209
210
	        array(
211
	            'name'      => __('Aesop Story Engine','lasso'),
212
	            'slug'      => 'aesop-story-engine',
213
	            'required'  => false,
214
	        ),
215
216
	    );
217
218
	    $config = array(
219
	        'default_path' => '',                      // Default absolute path to pre-packaged plugins.
220
	        'menu'         => 'lasso-install-plugins', // Menu slug.
221
	        'has_notices'  => true,                    // Show admin notices or not.
222
	        'dismissable'  => true,                    // If false, a user cannot dismiss the nag message.
223
	        'dismiss_msg'  => '',                      // If 'dismissable' is false, this message will be output at top of nag.
224
	        'is_automatic' => false,                   // Automatically activate plugins after installation or not.
225
	        'message'      => '',                      // Message to output right before the plugins table.
226
	        'strings'      => array(
227
	            'page_title'                      => __( 'Install Required Plugins', 'lasso' ),
228
	            'menu_title'                      => __( 'Install Plugins', 'lasso' ),
229
	            'installing'                      => __( 'Installing Plugin: %s', 'lasso' ), // %s = plugin name.
230
	            'oops'                            => __( 'Something went wrong with the plugin API.', 'lasso' ),
231
	            'notice_can_install_required'     => _n_noop( 'This plugin requires the following plugin: %1$s.', 'This plugin requires the following plugins: %1$s.' ), // %1$s = plugin name(s).
232
	            'notice_can_install_recommended'  => _n_noop( 'This plugin recommends the following plugin: %1$s.', 'This plugin recommends the following plugins: %1$s.' ), // %1$s = plugin name(s).
233
	            'notice_cannot_install'           => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.' ), // %1$s = plugin name(s).
234
	            'notice_can_activate_required'    => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.' ), // %1$s = plugin name(s).
235
	            'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.' ), // %1$s = plugin name(s).
236
	            'notice_cannot_activate'          => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.' ), // %1$s = plugin name(s).
237
	            'notice_ask_to_update'            => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this plugin: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this plugin: %1$s.' ), // %1$s = plugin name(s).
238
	            'notice_cannot_update'            => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.' ), // %1$s = plugin name(s).
239
	            'install_link'                    => _n_noop( 'Begin installing plugin', 'Begin installing plugins' ),
240
	            'activate_link'                   => _n_noop( 'Begin activating plugin', 'Begin activating plugins' ),
241
	            'return'                          => __( 'Return to Required Plugins Installer', 'lasso' ),
242
	            'plugin_activated'                => __( 'Plugin activated successfully.', 'lasso' ),
243
	            'complete'                        => __( 'All plugins installed and activated successfully. %s', 'lasso' ), // %s = dashboard link.
244
	            'nag_type'                        => 'updated' // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'.
245
	        )
246
	    );
247
		
248
		$plugins = apply_filters( 'lasso_required_plugins', $plugins );
249
250
	    tgmpa( $plugins, $config );
251
252
	}
253
}
254
255