Completed
Push — try/gutenberg-separate-jetpack... ( e8dd3e...f0efb9 )
by Bernhard
39:26 queued 23:22
created

Publicize_Util::crop_html()   D

Complexity

Conditions 17
Paths 96

Size

Total Lines 96

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
nc 96
nop 3
dl 0
loc 96
rs 4.2606
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
 * Module Name: Publicize
4
 * Module Description: Automated social marketing.
5
 * Sort Order: 10
6
 * Recommendation Order: 7
7
 * First Introduced: 2.0
8
 * Requires Connection: Yes
9
 * Auto Activate: Yes
10
 * Module Tags: Social, Recommended
11
 * Feature: Engagement
12
 * Additional Search Queries: facebook, twitter, google+, googleplus, google, path, tumblr, linkedin, social, tweet, connections, sharing
13
 */
14
15
class Jetpack_Publicize {
16
17
	public $in_jetpack = true;
18
19
	function __construct() {
20
		global $publicize_ui;
21
22
		$this->in_jetpack = ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'enable_module_configurable' ) ) ? true : false;
23
24
		if ( $this->in_jetpack && method_exists( 'Jetpack', 'module_configuration_load' ) ) {
25
			Jetpack::enable_module_configurable( __FILE__ );
26
			Jetpack::module_configuration_load( __FILE__, array( $this, 'jetpack_configuration_load' ) );
27
		}
28
29
		require_once dirname( __FILE__ ) . '/publicize/publicize.php';
30
31
		if ( $this->in_jetpack )
32
			require_once dirname( __FILE__ ) . '/publicize/publicize-jetpack.php';
33
		else {
34
			require_once dirname( dirname( __FILE__ ) ) . '/mu-plugins/keyring/keyring.php';
35
			require_once dirname( __FILE__ ) . '/publicize/publicize-wpcom.php';
36
		}
37
38
		require_once dirname( __FILE__ ) . '/publicize/ui.php';
39
		$publicize_ui = new Publicize_UI();
40
		$publicize_ui->in_jetpack = $this->in_jetpack;
0 ignored issues
show
Bug introduced by
The property in_jetpack does not seem to exist in Publicize_UI.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
41
42
		// Jetpack specific checks / hooks
43
		if ( $this->in_jetpack) {
44
			// if sharedaddy isn't active, the sharing menu hasn't been added yet
45
			$active = Jetpack::get_active_modules();
46 View Code Duplication
			if ( in_array( 'publicize', $active ) && !in_array( 'sharedaddy', $active ) )
47
				add_action( 'admin_menu', array( &$publicize_ui, 'sharing_menu' ) );
48
		}
49
	}
50
51
	function jetpack_configuration_load() {
52
		wp_safe_redirect( menu_page_url( 'sharing', false ) );
53
		exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method jetpack_configuration_load() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
54
	}
55
}
56
57
global $publicize_ui;
58
new Jetpack_Publicize;
59
60
if( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) && ! function_exists( 'publicize_init' ) ) {
61
/**
62
 * Helper for grabbing a Publicize object from the "front-end" (non-admin) of
63
 * a site. Normally Publicize is only loaded in wp-admin, so there's a little
64
 * set up that you might need to do if you want to use it on the front end.
65
 * Just call this function and it returns a Publicize object.
66
 *
67
 * @return Publicize Object
68
 */
69
function publicize_init() {
70
	global $publicize;
71
72
	if ( ! class_exists( 'Publicize' ) ) {
73
		require_once dirname( __FILE__ ) . '/publicize/publicize.php';
74
	}
75
76
	return $publicize;
77
}
78
79
}
80