Completed
Push — issues/611 ( f0b8b3...915615 )
by Ravinder
19:46
created

add-ons.php ➔ give_add_ons_get_feed()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 14
nc 4
nop 0
dl 0
loc 24
rs 6.7272
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 25 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Admin Add-ons
4
 *
5
 * @package     Give
6
 * @subpackage  Admin/Add-ons
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Add-ons Page
19
 *
20
 * Renders the add-ons page content.
21
 *
22
 * @since 1.0
23
 * @return void
24
 */
25
function give_add_ons_page() {
26
	ob_start(); ?>
27
	<div class="wrap" id="give-add-ons">
28
		<h1><?php echo get_admin_page_title(); ?>
29
			&nbsp;&mdash;&nbsp;<a href="https://givewp.com/addons/" class="button-primary give-view-addons-all" target="_blank"><?php esc_html_e( 'View All Add-ons', 'give' ); ?>
30
				<span class="dashicons dashicons-external"></span></a>
31
		</h1>
32
33
		<p><?php esc_html_e( 'The following Add-ons extend the functionality of Give.', 'give' ); ?></p>
34
		<?php echo give_add_ons_get_feed(); ?>
35
	</div>
36
	<?php
37
	echo ob_get_clean();
38
}
39
40
/**
41
 * Add-ons Get Feed
42
 *
43
 * Gets the add-ons page feed.
44
 *
45
 * @since 1.0
46
 * @return string $cache
47
 */
48
function give_add_ons_get_feed() {
49
50
	$addons_debug = false; //set to true to debug
51
	$cache        = Give_Cache::get( 'give_add_ons_feed', true );
52
53
	if ( $cache === false || $addons_debug === true && WP_DEBUG === true ) {
54
		$feed = wp_remote_get( 'https://givewp.com/downloads/feed/', array( 'sslverify' => false ) );
55
56
		if ( ! is_wp_error( $feed ) ) {
57
			if ( isset( $feed['body'] ) && strlen( $feed['body'] ) > 0 ) {
58
				$cache = wp_remote_retrieve_body( $feed );
59
				Give_Cache::set( 'give_add_ons_feed', $cache, HOUR_IN_SECONDS, true );
60
			}
61
		} else {
62
			$cache = sprintf(
63
				'<div class="error"><p>%s</p></div>',
64
				esc_html__( 'There was an error retrieving the Give Add-ons list from the server. Please try again later.', 'give' )
65
			);
66
		}
67
	}
68
69
	return $cache;
70
71
}