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

162 lines 4.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 switch ( $version_info->download_link ) {
106 case 'missing_license':
107 case 'expired_license':
108 case 'missing_requirements':
109 echo htmlspecialchars_decode( $version_info->package_download_restriction );
110 break;
111
112 default:
113 printf(
114 __( '<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' ),
115 esc_html( $version_info->name ),
116 esc_url( $changelog_link ),
117 esc_html( $version_info->new_version ),
118 esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) )
119 );
120 break;
121 }
122
123 do_action( "in_plugin_update_message-{$file}", $plugin, $version_info );
124
125 echo '</div></td></tr>';
126 }
127 }
128
129 /**
130 * Display the changelog.
131 *
132 * @since 1.0.0
133 *
134 * @return void
135 */
136 public function show_changelog() {
137 if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
138 return;
139 }
140
141 if ( empty( $_REQUEST['plugin'] ) ) {
142 return;
143 }
144
145 if ( empty( $_REQUEST['slug'] ) ) {
146 return;
147 }
148
149 if ( ! current_user_can( 'update_plugins' ) ) {
150 wp_die( __( 'You do not have permission to install plugin updates', 'charitable' ), __( 'Error', 'charitable' ), array( 'response' => 403 ) );
151 }
152
153 $version_info = Charitable_Licenses::get_instance()->get_version_info( $_REQUEST['plugin'] );
154
155 if ( $version_info && isset( $version_info->sections['changelog'] ) ) {
156 echo '<div style="padding:10px;">' . $version_info->sections['changelog'] . '</div>';
157 }
158
159 exit;
160 }
161 }
162