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

182 lines 5.8 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 switch ( $version_info->download_link ) {
106 case 'missing_license' :
107 printf(
108 __( '<p>There is a new version of %1$s available but you have not activated your license. <a target="_top" href="%2$s">Activate your license</a> or <a target="_blank" class="thickbox" href="%3$s">view version %4$s details</a>.</p>', 'charitable' ),
109 esc_html( $version_info->name ),
110 admin_url( 'admin.php?page=charitable-settings&tab=licenses' ),
111 esc_url( $changelog_link ),
112 esc_html( $version_info->new_version )
113 );
114 break;
115
116 case 'expired_license' :
117 $base_renewal_url = isset( $version_info->renewal_link ) ? $version_info->renewal_link : 'https://www.wpcharitable.com/account';
118
119 printf(
120 __( '<p>There is a new version of %1$s available but your license has expired. <a target="_blank" href="%2$s">Renew your license</a> or <a target="_blank" class="thickbox" href="%3$s">view version %4$s details</a>.</p>', 'charitable' ),
121 esc_html( $version_info->name ),
122 esc_url( add_query_arg( array(
123 'utm_source' => 'plugin-upgrades',
124 'utm_medium' => 'wordpress-dashboard',
125 'utm_campaign' => 'expired-license',
126 ), $base_renewal_url ) ),
127 esc_url( $changelog_link ),
128 esc_html( $version_info->new_version )
129 );
130 break;
131
132 default :
133 printf(
134 __( '<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' ),
135 esc_html( $version_info->name ),
136 esc_url( $changelog_link ),
137 esc_html( $version_info->new_version ),
138 esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
139 );
140 break;
141 }
142
143 do_action( "in_plugin_update_message-{$file}", $plugin, $version_info );
144
145 echo '</div></td></tr>';
146 }
147 }
148
149 /**
150 * Display the changelog.
151 *
152 * @since 1.0.0
153 *
154 * @return void
155 */
156 public function show_changelog() {
157 if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
158 return;
159 }
160
161 if ( empty( $_REQUEST['plugin'] ) ) {
162 return;
163 }
164
165 if ( empty( $_REQUEST['slug'] ) ) {
166 return;
167 }
168
169 if ( ! current_user_can( 'update_plugins' ) ) {
170 wp_die( __( 'You do not have permission to install plugin updates', 'charitable' ), __( 'Error', 'charitable' ), array( 'response' => 403 ) );
171 }
172
173 $version_info = Charitable_Licenses::get_instance()->get_version_info( $_REQUEST['plugin'] );
174
175 if ( $version_info && isset( $version_info->sections['changelog'] ) ) {
176 echo '<div style="padding:10px;">' . $version_info->sections['changelog'] . '</div>';
177 }
178
179 exit;
180 }
181 }
182