PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.2
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.2
1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 All 211 releases
charitable / includes / licensing / class-charitable-plugin-updater.php

class-charitable-plugin-updater.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.2, at includes/licensing/class-charitable-plugin-updater.php

174 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // uncomment this line for testing
4 //set_site_transient( 'update_plugins', null );
5
6 /**
7 * Allows plugins to use their own update API.
8 *
9 * This is part of the EDD Software Licensing suite. Just renamed here for Charitable.
10 *
11 * @author Pippin Williamson
12 * @version 1.6
13 */
14 class Charitable_Plugin_Updater {
15 private $api_url = '';
16 private $api_data = array();
17 private $name = '';
18 private $slug = '';
19 private $version = '';
20
21 /**
22 * Class constructor.
23 *
24 * @uses plugin_basename()
25 * @uses hook()
26 *
27 * @param string $_api_url The URL pointing to the custom API endpoint.
28 * @param string $_plugin_file Path to the plugin file.
29 * @param array $_api_data Optional data to send with API calls.
30 */
31 public function __construct( $_api_url, $_plugin_file, $_api_data = array() ) {
32 $this->api_url = trailingslashit( $_api_url );
33 $this->api_data = $_api_data;
34 $this->name = plugin_basename( $_plugin_file );
35 $this->slug = basename( $_plugin_file, '.php' );
36 $this->version = $_api_data['version'];
37
38 // Set up hooks.
39 $this->init();
40 }
41
42 /**
43 * Set up WordPress filters to hook into WP's update process.
44 *
45 * @since 1.0.0
46 *
47 * @return void
48 */
49 public function init() {
50 add_action( 'load-plugins.php', array( $this, 'setup_update_notification' ), 30 );
51 add_action( 'admin_init', array( $this, 'show_changelog' ) );
52 }
53
54 /**
55 * This disables the default update row shown for Charitable extensions,
56 * and sets up our own callback to show the update notification.
57 *
58 * @since 1.4.20
59 *
60 * @return void
61 */
62 public function setup_update_notification() {
63 remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 );
64 add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
65 }
66
67 /**
68 * Show update nofication row.
69 *
70 * This is a drop-in replacement for wp_plugin_update_row(),
71 * which is the function that will normally show the update row
72 * for a plugin. Replaced here to show our changelog and also
73 * prompt to the user to renew/set their license if it has
74 * expired or hasn't been added yet.
75 *
76 * @since 1.0.0
77 *
78 * @param string $file
79 * @param array $plugin
80 */
81 public function show_update_notification( $file, $plugin ) {
82 if ( ! current_user_can( 'update_plugins' ) ) {
83 return;
84 }
85
86 if ( $this->name != $file ) {
87 return;
88 }
89
90 $version_info = Charitable_Licenses::get_instance()->get_version_info( $this->name );
91
92 if ( ! $version_info ) {
93 return;
94 }
95
96 if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
97
98 // Build a plugin list row, with update notification.
99 echo '<tr class="plugin-update-tr" id="' . $this->slug . '-update" data-slug="' . $this->slug . '" data-plugin="' . $this->slug . '/' . $file . '">';
100 echo '<td colspan="3" class="plugin-update colspanchange">';
101 echo '<div class="update-message notice inline notice-warning notice-alt">';
102
103 $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' );
104
105 if ( isset( $version_info->download_link ) ) {
106 switch ( $version_info->download_link ) {
107 case 'missing_license':
108 case 'expired_license':
109 case 'missing_requirements':
110 echo htmlspecialchars_decode( $version_info->package_download_restriction );
111 break;
112
113 default:
114 $name = isset( ( $version_info->name ) ) ? esc_html( $version_info->name ) : esc_html( $version_info->slug );
115 printf(
116 __( '<p>There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.</p>', 'charitable' ),
117 $name,
118 esc_url( $changelog_link ),
119 esc_html( $version_info->new_version ),
120 esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
121 );
122 break;
123 }
124 } else {
125 $name = isset( ( $version_info->name ) ) ? esc_html( $version_info->name ) : esc_html( $version_info->slug );
126 printf(
127 __( '<p>There is a new version of %1$s available. <a target="_blank" class="thickbox" href="%2$s">View version %3$s details</a> or <a href="%4$s">update now</a>.</p>', 'charitable' ),
128 $name,
129 esc_url( $changelog_link ),
130 esc_html( $version_info->new_version ),
131 esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
132 );
133 }
134
135 do_action( "in_plugin_update_message-{$file}", $plugin, $version_info );
136
137 echo '</div></td></tr>';
138 }
139 }
140
141 /**
142 * Display the changelog.
143 *
144 * @since 1.0.0
145 *
146 * @return void
147 */
148 public function show_changelog() {
149 if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
150 return;
151 }
152
153 if ( empty( $_REQUEST['plugin'] ) ) {
154 return;
155 }
156
157 if ( empty( $_REQUEST['slug'] ) ) {
158 return;
159 }
160
161 if ( ! current_user_can( 'update_plugins' ) ) {
162 wp_die( __( 'You do not have permission to install plugin updates', 'charitable' ), __( 'Error', 'charitable' ), array( 'response' => 403 ) );
163 }
164
165 $version_info = Charitable_Licenses::get_instance()->get_version_info( $_REQUEST['plugin'] );
166
167 if ( $version_info && isset( $version_info->sections['changelog'] ) ) {
168 echo '<div style="padding:10px;">' . $version_info->sections['changelog'] . '</div>';
169 }
170
171 exit;
172 }
173 }
174