Completed
Push — fix/mod_rewrite-not-found ( b32513 )
by
unknown
23:27 queued 15:09
created

jetpack.php ➔ jetpack_index_permalinks_rest_api_url()   B

Complexity

Conditions 6
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 8
nc 2
nop 1
dl 0
loc 11
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Plugin Name: Jetpack by WordPress.com
5
 * Plugin URI: http://jetpack.com
6
 * Description: Bring the power of the WordPress.com cloud to your self-hosted WordPress. Jetpack enables you to connect your blog to a WordPress.com account to use the powerful features normally only available to WordPress.com users.
7
 * Author: Automattic
8
 * Version: 4.4-beta4
9
 * Author URI: http://jetpack.com
10
 * License: GPL2+
11
 * Text Domain: jetpack
12
 * Domain Path: /languages/
13
 */
14
15
define( 'JETPACK__MINIMUM_WP_VERSION', '4.5' );
16
17
define( 'JETPACK__VERSION',            '4.4-beta4' );
18
define( 'JETPACK_MASTER_USER',         true );
19
define( 'JETPACK__API_VERSION',        1 );
20
define( 'JETPACK__PLUGIN_DIR',         plugin_dir_path( __FILE__ ) );
21
define( 'JETPACK__PLUGIN_FILE',        __FILE__ );
22
23
defined( 'JETPACK_CLIENT__AUTH_LOCATION' )   or define( 'JETPACK_CLIENT__AUTH_LOCATION', 'header' );
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
24
defined( 'JETPACK_CLIENT__HTTPS' )           or define( 'JETPACK_CLIENT__HTTPS', 'AUTO' );
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
25
defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) or define( 'JETPACK__GLOTPRESS_LOCALES_PATH', JETPACK__PLUGIN_DIR . 'locales.php' );
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
26
defined( 'JETPACK__API_BASE' )               or define( 'JETPACK__API_BASE', 'https://jetpack.wordpress.com/jetpack.' );
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
27
defined( 'JETPACK_PROTECT__API_HOST' )       or define( 'JETPACK_PROTECT__API_HOST', 'https://api.bruteprotect.com/' );
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
28
defined( 'JETPACK__WPCOM_JSON_API_HOST' )    or define( 'JETPACK__WPCOM_JSON_API_HOST', 'public-api.wordpress.com' );
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
29
30
add_filter( 'rest_url_prefix', 'jetpack_index_permalinks_rest_api_url', 999 );
31
/**
32
 * Fix the REST API URL for sites using index permalinks
33
 *
34
 * @todo   Remove when 4.7 is minimum version
0 ignored issues
show
Coding Style introduced by
Comment refers to a TODO task

This check looks TODO comments that have been left in the code.

``TODO``s show that something is left unfinished and should be attended to.

Loading history...
35
 * @see    https://core.trac.wordpress.org/ticket/38182
36
 * @see    https://github.com/Automattic/jetpack/issues/5216
37
 * @author kraftbj
38
 *
39
 * @param string $prefix REST API endpoint URL base prefix.
40
 *
41
 * @return string
42
 */
43
function jetpack_index_permalinks_rest_api_url( $prefix ){
44
	global $wp_rewrite, $wp_version;
45
	if ( version_compare( $wp_version, '4.7-alpha-38790', '<' )
46
		&& isset( $wp_rewrite ) && $wp_rewrite instanceof WP_Rewrite
0 ignored issues
show
Bug introduced by
The class WP_Rewrite does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
47
		&& method_exists( $wp_rewrite, 'using_index_permalinks' )
48
		&& $wp_rewrite->using_index_permalinks() ) {
49
		$prefix = $wp_rewrite->index . '/' . $prefix;
50
	}
51
52
	return $prefix;
53
}
54
55
/**
56
 * Returns the location of Jetpack's lib directory. This filter is applied
57
 * in require_lib().
58
 *
59
 * @since 4.0.2
60
 *
61
 * @return string Location of Jetpack library directory.
62
 *
63
 * @filter require_lib_dir
64
 */
65
function jetpack_require_lib_dir() {
66
	return JETPACK__PLUGIN_DIR . '_inc/lib';
67
}
68
add_filter( 'jetpack_require_lib_dir', 'jetpack_require_lib_dir' );
69
70
// @todo: Abstract out the admin functions, and only include them if is_admin()
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
71
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack.php'               );
72
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-network.php'       );
73
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-client.php'        );
74
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-data.php'          );
75
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-client-server.php' );
76
require_once( JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-actions.php' );
77
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-options.php'       );
78
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-user-agent.php'    );
79
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-post-images.php'   );
80
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-error.php'         );
81
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-heartbeat.php'     );
82
require_once( JETPACK__PLUGIN_DIR . 'class.photon.php'                );
83
require_once( JETPACK__PLUGIN_DIR . 'functions.photon.php'            );
84
require_once( JETPACK__PLUGIN_DIR . 'functions.global.php'            );
85
require_once( JETPACK__PLUGIN_DIR . 'functions.compat.php'            );
86
require_once( JETPACK__PLUGIN_DIR . 'functions.gallery.php'           );
87
require_once( JETPACK__PLUGIN_DIR . 'require-lib.php'                 );
88
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-autoupdate.php'    );
89
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-tracks.php'        );
90
require_once( JETPACK__PLUGIN_DIR . 'class.frame-nonce-preview.php'   );
91
require_once( JETPACK__PLUGIN_DIR . 'modules/module-headings.php');
92
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-constants.php');
93
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-idc.php'  );
94
require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-connection-banner.php'  );
95
96
if ( is_admin() ) {
97
	require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-admin.php'     );
98
	require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-jitm.php'      );
99
	require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-debugger.php'  );
100
}
101
102
// Play nice with http://wp-cli.org/
103
if ( defined( 'WP_CLI' ) && WP_CLI ) {
104
	require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-cli.php'       );
105
}
106
107
require_once( JETPACK__PLUGIN_DIR . '_inc/lib/class.core-rest-api-endpoints.php' );
108
109
register_activation_hook( __FILE__, array( 'Jetpack', 'plugin_activation' ) );
110
register_deactivation_hook( __FILE__, array( 'Jetpack', 'plugin_deactivation' ) );
111
add_action( 'updating_jetpack_version', array( 'Jetpack', 'do_version_bump' ), 10, 2 );
112
add_action( 'init', array( 'Jetpack', 'init' ) );
113
add_action( 'plugins_loaded', array( 'Jetpack', 'plugin_textdomain' ), 99 );
114
add_action( 'plugins_loaded', array( 'Jetpack', 'load_modules' ), 100 );
115
add_filter( 'jetpack_static_url', array( 'Jetpack', 'staticize_subdomain' ) );
116
add_filter( 'is_jetpack_site', '__return_true' );
117
118
/**
119
 * Add an easy way to photon-ize a URL that is safe to call even if Jetpack isn't active.
120
 *
121
 * See: http://jetpack.com/2013/07/11/photon-and-themes/
122
 */
123
if ( Jetpack::is_module_active( 'photon' ) ) {
124
	add_filter( 'jetpack_photon_url', 'jetpack_photon_url', 10, 3 );
125
}
126
127
require_once( JETPACK__PLUGIN_DIR . '3rd-party/3rd-party.php' );
128
129
Jetpack::init();
130