Completed
Push — master ( 45f118...bcc91e )
by Devin
17:37 queued 14:12
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
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
}