PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.7
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.7
1.8.13.1 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 All 212 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.7, at includes/licensing/class-charitable-plugin-updater.php

186 lines 5.7 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 if ( isset( $version_info->download_link ) !== false ) {
115 $name = esc_html( $version_info->name );
116 } else if ( isset( $version_info->slug ) !== false ) {
117 $name = esc_html( $version_info->slug );
118 } else {
119 $name = 'Charitable';
120 }
121 printf(
122 __( '<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' ),
123 $name,
124 esc_url( $changelog_link ),
125 esc_html( $version_info->new_version ),
126 esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
127 );
128 break;
129 }
130 } else {
131 if ( isset( $version_info->download_link ) !== false ) {
132 $name = esc_html( $version_info->name );
133 } else if ( isset( $version_info->slug ) !== false ) {
134 $name = esc_html( $version_info->slug );
135 } else {
136 $name = 'Charitable';
137 }
138 printf(
139 __( '<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' ),
140 $name,
141 esc_url( $changelog_link ),
142 esc_html( $version_info->new_version ),
143 esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
144 );
145 }
146
147 do_action( "in_plugin_update_message-{$file}", $plugin, $version_info );
148
149 echo '</div></td></tr>';
150 }
151 }
152
153 /**
154 * Display the changelog.
155 *
156 * @since 1.0.0
157 *
158 * @return void
159 */
160 public function show_changelog() {
161 if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
162 return;
163 }
164
165 if ( empty( $_REQUEST['plugin'] ) ) {
166 return;
167 }
168
169 if ( empty( $_REQUEST['slug'] ) ) {
170 return;
171 }
172
173 if ( ! current_user_can( 'update_plugins' ) ) {
174 wp_die( __( 'You do not have permission to install plugin updates', 'charitable' ), __( 'Error', 'charitable' ), array( 'response' => 403 ) );
175 }
176
177 $version_info = Charitable_Licenses::get_instance()->get_version_info( $_REQUEST['plugin'] );
178
179 if ( $version_info && isset( $version_info->sections['changelog'] ) ) {
180 echo '<div style="padding:10px;">' . $version_info->sections['changelog'] . '</div>';
181 }
182
183 exit;
184 }
185 }
186