Completed
Push — add/double-encode-message ( 8b6530...2d4e84 )
by
unknown
14:26 queued 05:57
created

Publicize_Util::crop_html()   D

Complexity

Conditions 17
Paths 96

Size

Total Lines 91
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 57
nc 96
nop 3
dl 0
loc 91
rs 4.8361
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: Publicize makes it easy to share your site’s posts on several social media networks automatically when you publish a new post.
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, jetpack publicize, twitter, tumblr, linkedin, social, tweet, connections, sharing, social media, automated, automated sharing, auto publish, auto tweet and like, auto tweet, facebook auto post, facebook posting
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
52
	function jetpack_configuration_load() {
53
		wp_safe_redirect( menu_page_url( 'sharing', false ) );
54
		exit;
55
	}
56
}
57
58
global $publicize_ui;
59
new Jetpack_Publicize;
60
61
if( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) && ! function_exists( 'publicize_init' ) ) {
62
/**
63
 * Helper for grabbing a Publicize object from the "front-end" (non-admin) of
64
 * a site. Normally Publicize is only loaded in wp-admin, so there's a little
65
 * set up that you might need to do if you want to use it on the front end.
66
 * Just call this function and it returns a Publicize object.
67
 *
68
 * @return Publicize Object
69
 */
70
function publicize_init() {
71
	global $publicize;
72
73
	if ( ! class_exists( 'Publicize' ) ) {
74
		require_once dirname( __FILE__ ) . '/publicize/publicize.php';
75
	}
76
77
	return $publicize;
78
}
79
80
}
81