Changeset 2412106
- Timestamp:
- 11/03/2020 11:19:42 PM (4 years ago)
- Location:
- buddyforms-members
- Files:
-
- 93 added
- 9 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
buddyforms-members/trunk/buddyforms-members.php
r2305563 r2412106 1 1 <?php 2 3 if ( ! defined( 'ABSPATH' ) ) { exit; } 4 2 5 3 6 class BuddyForms_Members { -
buddyforms-members/trunk/includes/admin-settings-tab.php
r2305563 r2412106 1 1 <?php 2 3 if ( ! defined( 'ABSPATH' ) ) { exit; } 4 2 5 3 6 add_filter( 'buddyforms_admin_tabs', 'buddyforms_buddypress_admin_tab', 1, 1 ); -
buddyforms-members/trunk/includes/form-elements.php
r2305563 r2412106 1 1 <?php 2 3 if ( ! defined( 'ABSPATH' ) ) { exit; } 4 2 5 function buddyforms_members_admin_settings_sidebar_metabox() { 3 6 add_meta_box( 'buddyforms_members', __( "BP Member Profiles", 'buddyforms-members' ), 'buddyforms_members_admin_settings_sidebar_metabox_html', 'buddyforms', 'normal', 'low' ); … … 37 40 if ( isset( $buddyform['bp_activity_stream'] ) ) { 38 41 $bp_activity_stream = $buddyform['bp_activity_stream']; 42 } 43 44 $bp_profile_member_message = false; 45 if ( isset( $buddyform['bp_profile_member_message'] ) ) { 46 $bp_profile_member_message = $buddyform['bp_profile_member_message']; 39 47 } 40 48 … … 48 56 'shortDesc' => __( 'Many Forms can have the same attached Page. All Forms with the same page with page as parent enabled will be listed as sub forms. This why you can group forms.', 'buddyforms-members' ) 49 57 ) ); 58 59 if ( isset( $buddyform['form_type'] ) && $buddyform['form_type'] === 'contact' ) { 60 $form_setup[] = new Element_Checkbox( "<br><b>" . __( 'Send Message to Member', 'buddyforms-members' ) . "</b>", "buddyforms_options[bp_profile_member_message]", array( "bp_profile_member_message" => "Integrate this form as a member contact form" ), array( 61 'value' => $bp_profile_member_message, 62 'shortDesc' => __( 'Visibility: This tab is only visible in other user profiles. You will not see it in your profile. It is visible to your profile visitors only. A new send to option is added to the notifications. Please make sure you have at least one notification send to the member.' ) 63 ) ); 64 } 65 50 66 $element = new Element_Checkbox( "<br><b>" . __( 'Activity Support', 'buddyforms-members' ) . "</b>", "buddyforms_options[bp_activity_stream]", array( "bp_activity_stream" => "Add Activity Support" ), array( 51 67 'value' => $bp_activity_stream, 52 68 'shortDesc' => __( 'Every time a new Post is created with this Form a BuddyPress Activity Item will be added to the Members Activity Stream', 'buddyforms-members' ) 53 69 ) ); 70 54 71 if ( buddyforms_members_fs()->is_not_paying() ) { 55 72 $element->setAttribute( 'disabled', 'disabled' ); 56 73 } 57 74 $form_setup[] = $element; 75 58 76 59 77 $form_setup[] = new Element_Select( "<br><b>" . __( 'Visibility', 'buddyforms-members' ) . "</b>", "buddyforms_options[profile_visibility]", array( … … 95 113 $elements_select_options['buddyforms']['fields']['xprofile_field'] = array( 96 114 'label' => __( 'xProfile Field', 'buddyforms-members' ), 115 'is_pro' => true, 97 116 ); 98 117 $elements_select_options['buddyforms']['fields']['xprofile_group'] = array( 99 118 'label' => __( 'xProfile Field Group', 'buddyforms-members' ), 119 'is_pro' => true, 100 120 ); 101 121 … … 131 151 132 152 $member_types = isset( $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['member_types'] ) ? $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['member_types'] : ''; 133 $element = new Element_Checkbox( ' Allow the User to select Member Types', "buddyforms_options[form_fields][" . $field_id . "][member_types]", $member_types_select, array( 'value' => $member_types ) );153 $element = new Element_Checkbox( '<b>Allow the User to select Member Types</b>', "buddyforms_options[form_fields][" . $field_id . "][member_types]", $member_types_select, array( 'value' => $member_types ) ); 134 154 if ( buddyforms_members_fs()->is_not_paying() ) { 135 155 $element->setAttribute( 'disabled', 'disabled' ); … … 137 157 $form_fields['general']['member_types'] = $element; 138 158 139 $member_type_hidden = isset( $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['member_type_hidden'] ) ? $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['member_type_hidden'] : ''; 140 $form_fields['general']['member_type_hidden'] = new Element_Checkbox( 'Hide this form element', "buddyforms_options[form_fields][" . $field_id . "][member_type_hidden]", array( 'hide' => 'Hidden' ), array( 'value' => $member_type_hidden, 141 'shortDesc' => 'Hide this form element to auto assign the default member type', 142 ) ); 159 $member_type_hidden = isset( $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['member_type_hidden'] ) ? $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['member_type_hidden'] : ''; 160 $member_type_hidden_prop = array( 'value' => buddyforms_members_fs()->is_not_paying() ? true : $member_type_hidden, 'shortDesc' => 'Hide this form element to auto assign the default member type'); 161 $element = new Element_Checkbox( '<b>Hide this form element</b>', "buddyforms_options[form_fields][" . $field_id . "][member_type_hidden]", array( 'hide' => 'Hidden' ), $member_type_hidden_prop ); 162 163 if ( buddyforms_members_fs()->is_not_paying() ) { 164 $element->setAttribute( 'disabled', 'disabled' ); 165 } 166 $form_fields['general']['member_type_hidden'] = $element; 143 167 144 168 $member_types = isset( $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['member_type_default'] ) ? $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['member_type_default'] : ''; 145 $form_fields['general']['hidden'] = new Element_Select( ' Default Member Type For this Form', "buddyforms_options[form_fields][" . $field_id . "][member_type_default]", $member_types_select, array( 'value' => $member_types,169 $form_fields['general']['hidden'] = new Element_Select( '<b>Default Member Type For this Form</b>', "buddyforms_options[form_fields][" . $field_id . "][member_type_default]", $member_types_select, array( 'value' => $member_types, 146 170 'shortDesc' => 'Only works in combination with the Hidden option', 147 171 ) ); … … 176 200 177 201 $xprofile_group = isset( $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['xprofile_group'] ) ? $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['xprofile_group'] : ''; 178 $element = new Element_Select( ' xProfile Group', "buddyforms_options[form_fields][" . $field_id . "][xprofile_group]", $groups_select, array( 'value' => $xprofile_group ) );202 $element = new Element_Select( '<b>xProfile Group</b>', "buddyforms_options[form_fields][" . $field_id . "][xprofile_group]", $groups_select, array( 'value' => $xprofile_group ) ); 179 203 if ( buddyforms_members_fs()->is_not_paying() ) { 180 204 $element->setAttribute( 'disabled', 'disabled' ); … … 213 237 214 238 $xprofile_group = isset( $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['xprofile_group'] ) ? $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['xprofile_group'] : ''; 215 $element = new Element_Select( ' xProfile Group', "buddyforms_options[form_fields][" . $field_id . "][xprofile_group]", $groups_select, array( 'value' => $xprofile_group ) );239 $element = new Element_Select( '<b>xProfile Group</b>', "buddyforms_options[form_fields][" . $field_id . "][xprofile_group]", $groups_select, array( 'value' => $xprofile_group ) ); 216 240 if ( buddyforms_members_fs()->is_not_paying() ) { 217 241 $element->setAttribute( 'disabled', 'disabled' ); … … 234 258 235 259 $xprofile_field = isset( $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['xprofile_field'] ) ? $buddyforms[ $form_slug ]['form_fields'][ $field_id ]['xprofile_field'] : ''; 236 $element = new Element_Select( ' xProfile Field', "buddyforms_options[form_fields][" . $field_id . "][xprofile_field]", $group_fields_select, array( 'value' => $xprofile_field ) );260 $element = new Element_Select( '<b>xProfile Field</b>', "buddyforms_options[form_fields][" . $field_id . "][xprofile_field]", $group_fields_select, array( 'value' => $xprofile_field ) ); 237 261 if ( buddyforms_members_fs()->is_not_paying() ) { 238 262 $element->setAttribute( 'disabled', 'disabled' ); -
buddyforms-members/trunk/includes/functions.php
r2305563 r2412106 1 1 <?php 2 3 if ( ! defined( 'ABSPATH' ) ) { exit; } 4 2 5 3 6 /** … … 173 176 return $button; 174 177 } 178 179 180 add_filter('buddyforms_mail_to_before_send_notification', 'buddyforms_send_notifiction_to_member', 10, 3 ); 181 function buddyforms_send_notifiction_to_member( $mail_to, $notification, $form_slug ) { 182 global $buddyforms; 183 184 if ( ! isset( $buddyforms[$form_slug] ) ) { 185 return $mail_to; 186 } 187 188 $form = $buddyforms[$form_slug]; 189 190 if ( $form['form_type'] !== 'contact' || ! isset( $form['bp_profile_member_message'] ) ) { 191 return $mail_to; 192 } 193 194 $member = get_userdata( bp_displayed_user_id() ); 195 196 if ( ! isset( $member->user_email ) ) { 197 return $mail_to; 198 } 199 200 if ( isset( $notification['mail_to'] ) && in_array( 'member', $notification['mail_to'] ) ) { 201 array_push( $mail_to, $member->user_email ); 202 } 203 204 return $mail_to; 205 } 206 207 add_filter('buddyforms_notifications_send_mail_to_options', 'buddyforms_notification_send_mail_to_member_option', 10, 3 ); 208 function buddyforms_notification_send_mail_to_member_option($mail_to_options, $trigger, $form_slug ) { 209 global $buddyforms; 210 211 if ( ! isset( $buddyforms[$form_slug] ) ) { 212 return $mail_to_options; 213 } 214 215 $form = $buddyforms[$form_slug]; 216 217 if ( $form['form_type'] !== 'contact' || ! isset( $form['bp_profile_member_message'] ) ) { 218 return $mail_to_options; 219 } 220 221 $mail_to_options['member'] = __( 'Member - send to displayed member', 'buddyforms' ); 222 223 return $mail_to_options; 224 } 225 226 add_action('post_submitbox_start', 'buddyforms_check_send_message_to_member_conditions'); 227 function buddyforms_check_send_message_to_member_conditions() { 228 global $buddyform; 229 230 $messages = array(); 231 232 if ( ! isset( $buddyform['form_type'] ) 233 || $buddyform['form_type'] !== 'contact' 234 || ! isset( $buddyform['bp_profile_member_message'] ) 235 ) { 236 return; 237 } 238 239 $mail_to = array(); 240 $bf_notice = new BfAdminNotices(); 241 $notifications = $buddyform['mail_submissions']; 242 243 foreach ($notifications as $notification) { 244 $mail_to = array_merge( $mail_to, $notification['mail_to'] ); 245 } 246 247 if ( ! in_array( 'member', $mail_to ) ) { 248 $messages[] = __( 'At least one Mail Notification must have selected Send mail to Member.', 'buddyforms' ); 249 } 250 251 if ( ! empty( $messages ) ) { 252 $bf_notice->show_form_notices($messages); 253 } 254 } -
buddyforms-members/trunk/includes/member-extension.php
r2305563 r2412106 1 1 <?php 2 3 if ( ! defined( 'ABSPATH' ) ) { exit; } 4 2 5 3 6 class BuddyForms_Members_Extention extends BP_Component { … … 70 73 if ( isset( $member_form['profiles_integration'] ) ) { 71 74 72 if ( $member_form['post_type'] == 'bf_submissions' && ! bp_is_my_profile() ) { 75 $is_member_message_enabled = isset( $member_form['bp_profile_member_message'] ); 76 77 if ( $member_form['form_type'] === 'contact' && $is_member_message_enabled && bp_is_my_profile() ) { 78 continue; 79 } 80 81 if ( $member_form['form_type'] === 'contact' && ! $is_member_message_enabled && ! bp_is_my_profile() ) { 73 82 continue; 74 83 } … … 140 149 } 141 150 142 $sub_nav[] = array( 143 'name' => sprintf( '%s <span>%d</span>', $name, $count ), 144 'slug' => $key . '-posts', 145 'parent_slug' => $parent_tab, 146 'parent_url' => trailingslashit( bp_displayed_user_domain() . $parent_tab ), 147 'item_css_id' => 'sub_nav_home', 148 'screen_function' => array( $this, 'buddyforms_screen_settings' ), 149 'user_has_access' => $profile_visibility, 150 'position' => $position, 151 ); 152 $buddyforms_member_tabs[ $parent_tab ][ $key . '-posts' ] = $key; 153 $position ++; 154 155 $sub_nav[] = array( 156 'name' => sprintf( __( ' Add %s', 'buddyforms-members' ), $member_form['singular_name'] ), 157 'slug' => $key . '-create', 158 'parent_slug' => $parent_tab, 159 'parent_url' => trailingslashit( bp_displayed_user_domain() . $parent_tab ), 160 'item_css_id' => 'add_sub_nav_' . $key, 161 'screen_function' => array( $this, 'load_members_post_create' ), 162 'user_has_access' => bp_is_my_profile(), 163 'position' => $position, 164 ); 165 $buddyforms_member_tabs[ $parent_tab ][ $key . '-create' ] = $key; 166 $position ++; 167 168 $sub_nav[] = array( 169 'name' => sprintf( __( ' Edit %s', 'buddyforms-members' ), $member_form['singular_name'] ), 170 'slug' => $key . '-edit', 171 'parent_slug' => $parent_tab, 172 'parent_url' => trailingslashit( bp_displayed_user_domain() . $parent_tab ), 173 'item_css_id' => 'sub_nav_edit', 174 'screen_function' => array( $this, 'buddyforms_screen_settings' ), 175 'user_has_access' => bp_is_my_profile(), 176 'position' => $position, 177 ); 178 $buddyforms_member_tabs[ $parent_tab ][ $key . '-edit' ] = $key; 179 $position ++; 180 181 $sub_nav[] = array( 182 'name' => sprintf( __( ' Revision %s', 'buddyforms-members' ), $member_form['singular_name'] ), 183 'slug' => $key . '-revision', 184 'parent_slug' => $parent_tab, 185 'parent_url' => trailingslashit( bp_loggedin_user_domain() . $parent_tab ), 186 'item_css_id' => 'sub_nav_revison', 187 'screen_function' => array( $this, 'buddyforms_screen_settings' ), 188 'user_has_access' => bp_is_my_profile(), 189 'position' => $position, 190 ); 191 $buddyforms_member_tabs[ $parent_tab ][ $key . '-revision' ] = $key; 192 $position ++; 193 194 $sub_nav[] = array( 195 'name' => sprintf( __( ' Page %s', 'buddyforms-members' ), $member_form['singular_name'] ), 196 'slug' => $key . '-page', 197 'parent_slug' => $parent_tab, 198 'parent_url' => trailingslashit( bp_loggedin_user_domain() . $parent_tab ), 199 'item_css_id' => 'sub_nav_page', 200 'screen_function' => array( $this, 'buddyforms_screen_settings' ), 201 'position' => $position, 202 ); 203 $buddyforms_member_tabs[ $parent_tab ][ $key . '-page' ] = $key; 204 $position ++; 151 if ( $member_form['form_type'] === 'contact' && $is_member_message_enabled && ! bp_is_my_profile() ) { 152 153 $main_nav['default_subnav_slug'] = $key . '-create'; 154 $sub_nav[] = array( 155 'name' => sprintf( __( ' Contact with %s', 'buddyforms-members' ), bp_get_displayed_user_fullname() ), 156 'slug' => $key . '-create', 157 'parent_slug' => $parent_tab, 158 'parent_url' => trailingslashit( bp_displayed_user_domain() . $parent_tab ), 159 'item_css_id' => 'add_sub_nav_' . $key, 160 'screen_function' => array( $this, 'buddyforms_screen_settings' ), 161 'user_has_access' => $profile_visibility, 162 'position' => $position, 163 ); 164 $buddyforms_member_tabs[ $parent_tab ][ $key . '-create' ] = $key; 165 $position ++; 166 167 } else { 168 $sub_nav[] = array( 169 'name' => sprintf( '%s <span>%d</span>', $name, $count ), 170 'slug' => $key . '-posts', 171 'parent_slug' => $parent_tab, 172 'parent_url' => trailingslashit( bp_displayed_user_domain() . $parent_tab ), 173 'item_css_id' => 'sub_nav_home', 174 'screen_function' => array( $this, 'buddyforms_screen_settings' ), 175 'user_has_access' => $profile_visibility, 176 'position' => $position, 177 ); 178 $buddyforms_member_tabs[ $parent_tab ][ $key . '-posts' ] = $key; 179 $position ++; 180 181 $sub_nav[] = array( 182 'name' => sprintf( __( ' Add %s', 'buddyforms-members' ), $member_form['singular_name'] ), 183 'slug' => $key . '-create', 184 'parent_slug' => $parent_tab, 185 'parent_url' => trailingslashit( bp_displayed_user_domain() . $parent_tab ), 186 'item_css_id' => 'add_sub_nav_' . $key, 187 'screen_function' => array( $this, 'load_members_post_create' ), 188 'user_has_access' => bp_is_my_profile(), 189 'position' => $position, 190 ); 191 $buddyforms_member_tabs[ $parent_tab ][ $key . '-create' ] = $key; 192 $position ++; 193 194 $sub_nav[] = array( 195 'name' => sprintf( __( ' Edit %s', 'buddyforms-members' ), $member_form['singular_name'] ), 196 'slug' => $key . '-edit', 197 'parent_slug' => $parent_tab, 198 'parent_url' => trailingslashit( bp_displayed_user_domain() . $parent_tab ), 199 'item_css_id' => 'sub_nav_edit', 200 'screen_function' => array( $this, 'buddyforms_screen_settings' ), 201 'user_has_access' => bp_is_my_profile(), 202 'position' => $position, 203 ); 204 $buddyforms_member_tabs[ $parent_tab ][ $key . '-edit' ] = $key; 205 $position ++; 206 207 $sub_nav[] = array( 208 'name' => sprintf( __( ' Revision %s', 'buddyforms-members' ), $member_form['singular_name'] ), 209 'slug' => $key . '-revision', 210 'parent_slug' => $parent_tab, 211 'parent_url' => trailingslashit( bp_loggedin_user_domain() . $parent_tab ), 212 'item_css_id' => 'sub_nav_revison', 213 'screen_function' => array( $this, 'buddyforms_screen_settings' ), 214 'user_has_access' => bp_is_my_profile(), 215 'position' => $position, 216 ); 217 $buddyforms_member_tabs[ $parent_tab ][ $key . '-revision' ] = $key; 218 $position ++; 219 220 $sub_nav[] = array( 221 'name' => sprintf( __( ' Page %s', 'buddyforms-members' ), $member_form['singular_name'] ), 222 'slug' => $key . '-page', 223 'parent_slug' => $parent_tab, 224 'parent_url' => trailingslashit( bp_loggedin_user_domain() . $parent_tab ), 225 'item_css_id' => 'sub_nav_page', 226 'screen_function' => array( $this, 'buddyforms_screen_settings' ), 227 'position' => $position, 228 ); 229 $buddyforms_member_tabs[ $parent_tab ][ $key . '-page' ] = $key; 230 $position ++; 231 } 205 232 } 206 207 208 233 209 234 $buddyforms_members_parent_setup_nav = apply_filters( 'buddyforms_members_parent_setup_nav', true, $key ); -
buddyforms-members/trunk/includes/redirect.php
r2305563 r2412106 1 1 <?php 2 3 if ( ! defined( 'ABSPATH' ) ) { exit; } 4 2 5 /** 3 6 * @package WordPress -
buddyforms-members/trunk/includes/resources/tgm/class-tgm-plugin-activation.php
r2305563 r2412106 1 1 <?php 2 /**3 * Plugin installation and activation for WordPress themes.4 *5 * Please note that this is a drop-in library for a theme or plugin.6 * The authors of this library (Thomas, Gary and Juliette) are NOT responsible7 * for the support of your plugin or theme. Please contact the plugin8 * or theme author for support.9 *10 * @package TGM-Plugin-Activation11 * @version 2.6.112 * @link http://tgmpluginactivation.com/13 * @author Thomas Griffin, Gary Jones, Juliette Reinders Folmer14 * @copyright Copyright (c) 2011, Thomas Griffin15 * @license GPL-2.0+16 */17 2 18 /* 19 Copyright 2011 Thomas Griffin (thomasgriffinmedia.com) 3 if ( ! defined( 'ABSPATH' ) ) { exit; } 20 4 21 This program is free software; you can redistribute it and/or modify 22 it under the terms of the GNU General Public License, version 2, as 23 published by the Free Software Foundation. 24 25 This program is distributed in the hope that it will be useful, 26 but WITHOUT ANY WARRANTY; without even the implied warranty of 27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 GNU General Public License for more details. 29 30 You should have received a copy of the GNU General Public License 31 along with this program; if not, write to the Free Software 32 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 33 */ 34 35 if ( ! class_exists( 'TGM_Plugin_Activation' ) ) { 36 37 /** 38 * Automatic plugin installation and activation library. 39 * 40 * Creates a way to automatically install and activate plugins from within themes. 41 * The plugins can be either bundled, downloaded from the WordPress 42 * Plugin Repository or downloaded from another external source. 43 * 44 * @since 1.0.0 45 * 46 * @package TGM-Plugin-Activation 47 * @author Thomas Griffin 48 * @author Gary Jones 49 */ 50 class TGM_Plugin_Activation { 51 /** 52 * TGMPA version number. 53 * 54 * @since 2.5.0 55 * 56 * @const string Version number. 57 */ 58 const TGMPA_VERSION = '2.6.1'; 59 60 /** 61 * Regular expression to test if a URL is a WP plugin repo URL. 62 * 63 * @const string Regex. 64 * 65 * @since 2.5.0 66 */ 67 const WP_REPO_REGEX = '|^http[s]?://wordpress\.org/(?:extend/)?plugins/|'; 68 69 /** 70 * Arbitrary regular expression to test if a string starts with a URL. 71 * 72 * @const string Regex. 73 * 74 * @since 2.5.0 75 */ 76 const IS_URL_REGEX = '|^http[s]?://|'; 77 78 /** 79 * Holds a copy of itself, so it can be referenced by the class name. 80 * 81 * @since 1.0.0 82 * 83 * @var TGM_Plugin_Activation 84 */ 85 public static $instance; 86 87 /** 88 * Holds arrays of plugin details. 89 * 90 * @since 1.0.0 91 * @since 2.5.0 the array has the plugin slug as an associative key. 92 * 93 * @var array 94 */ 95 public $plugins = array(); 96 97 /** 98 * Holds arrays of plugin names to use to sort the plugins array. 99 * 100 * @since 2.5.0 101 * 102 * @var array 103 */ 104 protected $sort_order = array(); 105 106 /** 107 * Whether any plugins have the 'force_activation' setting set to true. 108 * 109 * @since 2.5.0 110 * 111 * @var bool 112 */ 113 protected $has_forced_activation = false; 114 115 /** 116 * Whether any plugins have the 'force_deactivation' setting set to true. 117 * 118 * @since 2.5.0 119 * 120 * @var bool 121 */ 122 protected $has_forced_deactivation = false; 123 124 /** 125 * Name of the unique ID to hash notices. 126 * 127 * @since 2.4.0 128 * 129 * @var string 130 */ 131 public $id = 'buddyforms_members_tgmpa'; 132 133 /** 134 * Name of the query-string argument for the admin page. 135 * 136 * @since 1.0.0 137 * 138 * @var string 139 */ 140 protected $menu = 'buddyforms_members_tgmpa-install-plugins'; 141 142 /** 143 * Parent menu file slug. 144 * 145 * @since 2.5.0 146 * 147 * @var string 148 */ 149 public $parent_slug = 'themes.php'; 150 151 /** 152 * Capability needed to view the plugin installation menu item. 153 * 154 * @since 2.5.0 155 * 156 * @var string 157 */ 158 public $capability = 'edit_theme_options'; 159 160 /** 161 * Default absolute path to folder containing bundled plugin zip files. 162 * 163 * @since 2.0.0 164 * 165 * @var string Absolute path prefix to zip file location for bundled plugins. Default is empty string. 166 */ 167 public $default_path = ''; 168 169 /** 170 * Flag to show admin notices or not. 171 * 172 * @since 2.1.0 173 * 174 * @var boolean 175 */ 176 public $has_notices = true; 177 178 /** 179 * Flag to determine if the user can dismiss the notice nag. 180 * 181 * @since 2.4.0 182 * 183 * @var boolean 184 */ 185 public $dismissable = true; 186 187 /** 188 * Message to be output above nag notice if dismissable is false. 189 * 190 * @since 2.4.0 191 * 192 * @var string 193 */ 194 public $dismiss_msg = ''; 195 196 /** 197 * Flag to set automatic activation of plugins. Off by default. 198 * 199 * @since 2.2.0 200 * 201 * @var boolean 202 */ 203 public $is_automatic = false; 204 205 /** 206 * Optional message to display before the plugins table. 207 * 208 * @since 2.2.0 209 * 210 * @var string Message filtered by wp_kses_post(). Default is empty string. 211 */ 212 public $message = ''; 213 214 /** 215 * Holds configurable array of strings. 216 * 217 * Default values are added in the constructor. 218 * 219 * @since 2.0.0 220 * 221 * @var array 222 */ 223 public $strings = array(); 224 225 /** 226 * Holds the version of WordPress. 227 * 228 * @since 2.4.0 229 * 230 * @var int 231 */ 232 public $wp_version; 233 234 /** 235 * Holds the hook name for the admin page. 236 * 237 * @since 2.5.0 238 * 239 * @var string 240 */ 241 public $page_hook; 242 243 /** 244 * Adds a reference of this object to $instance, populates default strings, 245 * does the buddyforms_members_tgmpa_init action hook, and hooks in the interactions to init. 246 * 247 * {@internal This method should be `protected`, but as too many TGMPA implementations 248 * haven't upgraded beyond v2.3.6 yet, this gives backward compatibility issues. 249 * Reverted back to public for the time being.}} 250 * 251 * @since 1.0.0 252 * 253 * @see TGM_Plugin_Activation::init() 254 */ 255 public function __construct() { 256 // Set the current WordPress version. 257 $this->wp_version = $GLOBALS['wp_version']; 258 259 // Announce that the class is ready, and pass the object (for advanced use). 260 do_action_ref_array( 'buddyforms_members_tgmpa_init', array( $this ) ); 261 262 /* 263 * Load our text domain and allow for overloading the fall-back file. 264 * 265 * {@internal IMPORTANT! If this code changes, review the regex in the custom TGMPA 266 * generator on the website.}} 267 */ 268 add_action( 'init', array( $this, 'load_textdomain' ), 5 ); 269 add_filter( 'load_textdomain_mofile', array( $this, 'overload_textdomain_mofile' ), 10, 2 ); 270 271 // When the rest of WP has loaded, kick-start the rest of the class. 272 add_action( 'init', array( $this, 'init' ) ); 273 } 274 275 /** 276 * Magic method to (not) set protected properties from outside of this class. 277 * 278 * {@internal hackedihack... There is a serious bug in v2.3.2 - 2.3.6 where the `menu` property 279 * is being assigned rather than tested in a conditional, effectively rendering it useless. 280 * This 'hack' prevents this from happening.}} 281 * 282 * @see https://github.com/TGMPA/TGM-Plugin-Activation/blob/2.3.6/tgm-plugin-activation/class-tgm-plugin-activation.php#L1593 283 * 284 * @since 2.5.2 285 * 286 * @param string $name Name of an inaccessible property. 287 * @param mixed $value Value to assign to the property. 288 * 289 * @return void Silently fail to set the property when this is tried from outside of this class context. 290 * (Inside this class context, the __set() method if not used as there is direct access.) 291 */ 292 public function __set( $name, $value ) { 293 return; 294 } 295 296 /** 297 * Magic method to get the value of a protected property outside of this class context. 298 * 299 * @since 2.5.2 300 * 301 * @param string $name Name of an inaccessible property. 302 * 303 * @return mixed The property value. 304 */ 305 public function __get( $name ) { 306 return $this->{$name}; 307 } 308 309 /** 310 * Initialise the interactions between this class and WordPress. 311 * 312 * Hooks in three new methods for the class: admin_menu, notices and styles. 313 * 314 * @since 2.0.0 315 * 316 * @see TGM_Plugin_Activation::admin_menu() 317 * @see TGM_Plugin_Activation::notices() 318 * @see TGM_Plugin_Activation::styles() 319 */ 320 public function init() { 321 /** 322 * By default TGMPA only loads on the WP back-end and not in an Ajax call. Using this filter 323 * you can overrule that behaviour. 324 * 325 * @since 2.5.0 326 * 327 * @param bool $load Whether or not TGMPA should load. 328 * Defaults to the return of `is_admin() && ! defined( 'DOING_AJAX' )`. 329 */ 330 if ( true !== apply_filters( 'buddyforms_members_tgmpa_load', ( is_admin() && ! defined( 'DOING_AJAX' ) ) ) ) { 331 return; 332 } 333 334 // Load class strings. 335 $this->strings = array( 336 'page_title' => __( 'Install Required Plugins', 'buddyforms_members_tgmpa' ), 337 'menu_title' => __( 'Install Plugins', 'buddyforms_members_tgmpa' ), 338 /* translators: %s: plugin name. */ 339 'installing' => __( 'Installing Plugin: %s', 'buddyforms_members_tgmpa' ), 340 /* translators: %s: plugin name. */ 341 'updating' => __( 'Updating Plugin: %s', 'buddyforms_members_tgmpa' ), 342 'oops' => __( 'Something went wrong with the plugin API.', 'buddyforms_members_tgmpa' ), 343 'notice_can_install_required' => _n_noop( 344 /* translators: 1: plugin name(s). */ 345 'This theme requires the following plugin: %1$s.', 346 'This theme requires the following plugins: %1$s.', 347 'buddyforms_members_tgmpa' 348 ), 349 'notice_can_install_recommended' => _n_noop( 350 /* translators: 1: plugin name(s). */ 351 'This theme recommends the following plugin: %1$s.', 352 'This theme recommends the following plugins: %1$s.', 353 'buddyforms_members_tgmpa' 354 ), 355 'notice_ask_to_update' => _n_noop( 356 /* translators: 1: plugin name(s). */ 357 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 358 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 359 'buddyforms_members_tgmpa' 360 ), 361 'notice_ask_to_update_maybe' => _n_noop( 362 /* translators: 1: plugin name(s). */ 363 'There is an update available for: %1$s.', 364 'There are updates available for the following plugins: %1$s.', 365 'buddyforms_members_tgmpa' 366 ), 367 'notice_can_activate_required' => _n_noop( 368 /* translators: 1: plugin name(s). */ 369 'The following required plugin is currently inactive: %1$s.', 370 'The following required plugins are currently inactive: %1$s.', 371 'buddyforms_members_tgmpa' 372 ), 373 'notice_can_activate_recommended' => _n_noop( 374 /* translators: 1: plugin name(s). */ 375 'The following recommended plugin is currently inactive: %1$s.', 376 'The following recommended plugins are currently inactive: %1$s.', 377 'buddyforms_members_tgmpa' 378 ), 379 'install_link' => _n_noop( 380 'Begin installing plugin', 381 'Begin installing plugins', 382 'buddyforms_members_tgmpa' 383 ), 384 'update_link' => _n_noop( 385 'Begin updating plugin', 386 'Begin updating plugins', 387 'buddyforms_members_tgmpa' 388 ), 389 'activate_link' => _n_noop( 390 'Begin activating plugin', 391 'Begin activating plugins', 392 'buddyforms_members_tgmpa' 393 ), 394 'return' => __( 'Return to Required Plugins Installer', 'buddyforms_members_tgmpa' ), 395 'dashboard' => __( 'Return to the Dashboard', 'buddyforms_members_tgmpa' ), 396 'plugin_activated' => __( 'Plugin activated successfully.', 'buddyforms_members_tgmpa' ), 397 'activated_successfully' => __( 'The following plugin was activated successfully:', 'buddyforms_members_tgmpa' ), 398 /* translators: 1: plugin name. */ 399 'plugin_already_active' => __( 'No action taken. Plugin %1$s was already active.', 'buddyforms_members_tgmpa' ), 400 /* translators: 1: plugin name. */ 401 'plugin_needs_higher_version' => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'buddyforms_members_tgmpa' ), 402 /* translators: 1: dashboard link. */ 403 'complete' => __( 'All plugins installed and activated successfully. %1$s', 'buddyforms_members_tgmpa' ), 404 'dismiss' => __( 'Dismiss this notice', 'buddyforms_members_tgmpa' ), 405 'notice_cannot_install_activate' => __( 'There are one or more required or recommended plugins to install, update or activate.', 'buddyforms_members_tgmpa' ), 406 'contact_admin' => __( 'Please contact the administrator of this site for help.', 'buddyforms_members_tgmpa' ), 407 ); 408 409 do_action( 'buddyforms_members_tgmpa_register' ); 410 411 /* After this point, the plugins should be registered and the configuration set. */ 412 413 // Proceed only if we have plugins to handle. 414 if ( empty( $this->plugins ) || ! is_array( $this->plugins ) ) { 415 return; 416 } 417 418 // Set up the menu and notices if we still have outstanding actions. 419 if ( true !== $this->is_buddyforms_members_tgmpa_complete() ) { 420 // Sort the plugins. 421 array_multisort( $this->sort_order, SORT_ASC, $this->plugins ); 422 423 add_action( 'admin_menu', array( $this, 'admin_menu' ) ); 424 add_action( 'admin_head', array( $this, 'dismiss' ) ); 425 426 // Prevent the normal links from showing underneath a single install/update page. 427 add_filter( 'install_plugin_complete_actions', array( $this, 'actions' ) ); 428 add_filter( 'update_plugin_complete_actions', array( $this, 'actions' ) ); 429 430 if ( $this->has_notices ) { 431 add_action( 'admin_notices', array( $this, 'notices' ) ); 432 add_action( 'admin_init', array( $this, 'admin_init' ), 1 ); 433 add_action( 'admin_enqueue_scripts', array( $this, 'thickbox' ) ); 434 } 435 } 436 437 // If needed, filter plugin action links. 438 add_action( 'load-plugins.php', array( $this, 'add_plugin_action_link_filters' ), 1 ); 439 440 // Make sure things get reset on switch theme. 441 add_action( 'switch_theme', array( $this, 'flush_plugins_cache' ) ); 442 443 if ( $this->has_notices ) { 444 add_action( 'switch_theme', array( $this, 'update_dismiss' ) ); 445 } 446 447 // Setup the force activation hook. 448 if ( true === $this->has_forced_activation ) { 449 add_action( 'admin_init', array( $this, 'force_activation' ) ); 450 } 451 452 // Setup the force deactivation hook. 453 if ( true === $this->has_forced_deactivation ) { 454 add_action( 'switch_theme', array( $this, 'force_deactivation' ) ); 455 } 456 } 457 458 /** 459 * Load translations. 460 * 461 * @since 2.6.0 462 * 463 * (@internal Uses `load_theme_textdomain()` rather than `load_plugin_textdomain()` to 464 * get round the different ways of handling the path and deprecated notices being thrown 465 * and such. For plugins, the actual file name will be corrected by a filter.}} 466 * 467 * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA 468 * generator on the website.}} 469 */ 470 public function load_textdomain() { 471 if ( is_textdomain_loaded( 'buddyforms_members_tgmpa' ) ) { 472 return; 473 } 474 475 if ( false !== strpos( __FILE__, WP_PLUGIN_DIR ) || false !== strpos( __FILE__, WPMU_PLUGIN_DIR ) ) { 476 // Plugin, we'll need to adjust the file name. 477 add_action( 'load_textdomain_mofile', array( $this, 'correct_plugin_mofile' ), 10, 2 ); 478 load_theme_textdomain( 'buddyforms_members_tgmpa', dirname( __FILE__ ) . '/languages' ); 479 remove_action( 'load_textdomain_mofile', array( $this, 'correct_plugin_mofile' ), 10 ); 480 } else { 481 load_theme_textdomain( 'buddyforms_members_tgmpa', dirname( __FILE__ ) . '/languages' ); 482 } 483 } 484 485 /** 486 * Correct the .mo file name for (must-use) plugins. 487 * 488 * Themese use `/path/{locale}.mo` while plugins use `/path/{text-domain}-{locale}.mo`. 489 * 490 * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA 491 * generator on the website.}} 492 * 493 * @since 2.6.0 494 * 495 * @param string $mofile Full path to the target mofile. 496 * @param string $domain The domain for which a language file is being loaded. 497 * 498 * @return string $mofile 499 */ 500 public function correct_plugin_mofile( $mofile, $domain ) { 501 // Exit early if not our domain (just in case). 502 if ( 'buddyforms_members_tgmpa' !== $domain ) { 503 return $mofile; 504 } 505 506 return preg_replace( '`/([a-z]{2}_[A-Z]{2}.mo)$`', '/buddyforms_members_tgmpa-$1', $mofile ); 507 } 508 509 /** 510 * Potentially overload the fall-back translation file for the current language. 511 * 512 * WP, by default since WP 3.7, will load a local translation first and if none 513 * can be found, will try and find a translation in the /wp-content/languages/ directory. 514 * As this library is theme/plugin agnostic, translation files for TGMPA can exist both 515 * in the WP_LANG_DIR /plugins/ subdirectory as well as in the /themes/ subdirectory. 516 * 517 * This method makes sure both directories are checked. 518 * 519 * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA 520 * generator on the website.}} 521 * 522 * @since 2.6.0 523 * 524 * @param string $mofile Full path to the target mofile. 525 * @param string $domain The domain for which a language file is being loaded. 526 * 527 * @return string $mofile 528 */ 529 public function overload_textdomain_mofile( $mofile, $domain ) { 530 // Exit early if not our domain, not a WP_LANG_DIR load or if the file exists and is readable. 531 if ( 'buddyforms_members_tgmpa' !== $domain || false === strpos( $mofile, WP_LANG_DIR ) || @is_readable( $mofile ) ) { 532 return $mofile; 533 } 534 535 // Current fallback file is not valid, let's try the alternative option. 536 if ( false !== strpos( $mofile, '/themes/' ) ) { 537 return str_replace( '/themes/', '/plugins/', $mofile ); 538 } elseif ( false !== strpos( $mofile, '/plugins/' ) ) { 539 return str_replace( '/plugins/', '/themes/', $mofile ); 540 } else { 541 return $mofile; 542 } 543 } 544 545 /** 546 * Hook in plugin action link filters for the WP native plugins page. 547 * 548 * - Prevent activation of plugins which don't meet the minimum version requirements. 549 * - Prevent deactivation of force-activated plugins. 550 * - Add update notice if update available. 551 * 552 * @since 2.5.0 553 */ 554 public function add_plugin_action_link_filters() { 555 foreach ( $this->plugins as $slug => $plugin ) { 556 if ( false === $this->can_plugin_activate( $slug ) ) { 557 add_filter( 'plugin_action_links_' . $plugin['file_path'], array( 558 $this, 559 'filter_plugin_action_links_activate' 560 ), 20 ); 561 } 562 563 if ( true === $plugin['force_activation'] ) { 564 add_filter( 'plugin_action_links_' . $plugin['file_path'], array( 565 $this, 566 'filter_plugin_action_links_deactivate' 567 ), 20 ); 568 } 569 570 if ( false !== $this->does_plugin_require_update( $slug ) ) { 571 add_filter( 'plugin_action_links_' . $plugin['file_path'], array( 572 $this, 573 'filter_plugin_action_links_update' 574 ), 20 ); 575 } 576 } 577 } 578 579 /** 580 * Remove the 'Activate' link on the WP native plugins page if the plugin does not meet the 581 * minimum version requirements. 582 * 583 * @since 2.5.0 584 * 585 * @param array $actions Action links. 586 * 587 * @return array 588 */ 589 public function filter_plugin_action_links_activate( $actions ) { 590 unset( $actions['activate'] ); 591 592 return $actions; 593 } 594 595 /** 596 * Remove the 'Deactivate' link on the WP native plugins page if the plugin has been set to force activate. 597 * 598 * @since 2.5.0 599 * 600 * @param array $actions Action links. 601 * 602 * @return array 603 */ 604 public function filter_plugin_action_links_deactivate( $actions ) { 605 unset( $actions['deactivate'] ); 606 607 return $actions; 608 } 609 610 /** 611 * Add a 'Requires update' link on the WP native plugins page if the plugin does not meet the 612 * minimum version requirements. 613 * 614 * @since 2.5.0 615 * 616 * @param array $actions Action links. 617 * 618 * @return array 619 */ 620 public function filter_plugin_action_links_update( $actions ) { 621 $actions['update'] = sprintf( 622 '<a href="%1$s" title="%2$s" class="edit">%3$s</a>', 623 esc_url( $this->get_buddyforms_members_tgmpa_status_url( 'update' ) ), 624 esc_attr__( 'This plugin needs to be updated to be compatible with your theme.', 'buddyforms_members_tgmpa' ), 625 esc_html__( 'Update Required', 'buddyforms_members_tgmpa' ) 626 ); 627 628 return $actions; 629 } 630 631 /** 632 * Handles calls to show plugin information via links in the notices. 633 * 634 * We get the links in the admin notices to point to the TGMPA page, rather 635 * than the typical plugin-install.php file, so we can prepare everything 636 * beforehand. 637 * 638 * WP does not make it easy to show the plugin information in the thickbox - 639 * here we have to require a file that includes a function that does the 640 * main work of displaying it, enqueue some styles, set up some globals and 641 * finally call that function before exiting. 642 * 643 * Down right easy once you know how... 644 * 645 * Returns early if not the TGMPA page. 646 * 647 * @since 2.1.0 648 * 649 * @global string $tab Used as iframe div class names, helps with styling 650 * @global string $body_id Used as the iframe body ID, helps with styling 651 * 652 * @return null Returns early if not the TGMPA page. 653 */ 654 public function admin_init() { 655 if ( ! $this->is_buddyforms_members_tgmpa_page() ) { 656 return; 657 } 658 659 if ( isset( $_REQUEST['tab'] ) && 'plugin-information' === $_REQUEST['tab'] ) { 660 // Needed for install_plugin_information(). 661 require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; 662 663 wp_enqueue_style( 'plugin-install' ); 664 665 global $tab, $body_id; 666 $body_id = 'plugin-information'; 667 // @codingStandardsIgnoreStart 668 $tab = 'plugin-information'; 669 // @codingStandardsIgnoreEnd 670 671 install_plugin_information(); 672 673 exit; 674 } 675 } 676 677 /** 678 * Enqueue thickbox scripts/styles for plugin info. 679 * 680 * Thickbox is not automatically included on all admin pages, so we must 681 * manually enqueue it for those pages. 682 * 683 * Thickbox is only loaded if the user has not dismissed the admin 684 * notice or if there are any plugins left to install and activate. 685 * 686 * @since 2.1.0 687 */ 688 public function thickbox() { 689 if ( ! get_user_meta( get_current_user_id(), 'buddyforms_members_tgmpa_dismissed_notice_' . $this->id, true ) ) { 690 add_thickbox(); 691 } 692 } 693 694 /** 695 * Adds submenu page if there are plugin actions to take. 696 * 697 * This method adds the submenu page letting users know that a required 698 * plugin needs to be installed. 699 * 700 * This page disappears once the plugin has been installed and activated. 701 * 702 * @since 1.0.0 703 * 704 * @see TGM_Plugin_Activation::init() 705 * @see TGM_Plugin_Activation::install_plugins_page() 706 * 707 * @return null Return early if user lacks capability to install a plugin. 708 */ 709 public function admin_menu() { 710 // Make sure privileges are correct to see the page. 711 if ( ! current_user_can( 'install_plugins' ) ) { 712 return; 713 } 714 715 $args = apply_filters( 716 'buddyforms_members_tgmpa_admin_menu_args', 717 array( 718 'parent_slug' => $this->parent_slug, // Parent Menu slug. 719 'page_title' => $this->strings['page_title'], // Page title. 720 'menu_title' => $this->strings['menu_title'], // Menu title. 721 'capability' => $this->capability, // Capability. 722 'menu_slug' => $this->menu, // Menu slug. 723 'function' => array( $this, 'install_plugins_page' ), // Callback. 724 ) 725 ); 726 727 $this->add_admin_menu( $args ); 728 } 729 730 /** 731 * Add the menu item. 732 * 733 * {@internal IMPORTANT! If this function changes, review the regex in the custom TGMPA 734 * generator on the website.}} 735 * 736 * @since 2.5.0 737 * 738 * @param array $args Menu item configuration. 739 */ 740 protected function add_admin_menu( array $args ) { 741 if ( has_filter( 'buddyforms_members_tgmpa_admin_menu_use_add_theme_page' ) ) { 742 _deprecated_function( 'The "buddyforms_members_tgmpa_admin_menu_use_add_theme_page" filter', '2.5.0', esc_html__( 'Set the parent_slug config variable instead.', 'buddyforms_members_tgmpa' ) ); 743 } 744 745 if ( 'themes.php' === $this->parent_slug ) { 746 $this->page_hook = call_user_func( 'add_theme_page', $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'] ); 747 } else { 748 $this->page_hook = call_user_func( 'add_submenu_page', $args['parent_slug'], $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'] ); 749 } 750 } 751 752 /** 753 * Echoes plugin installation form. 754 * 755 * This method is the callback for the admin_menu method function. 756 * This displays the admin page and form area where the user can select to install and activate the plugin. 757 * Aborts early if we're processing a plugin installation action. 758 * 759 * @since 1.0.0 760 * 761 * @return null Aborts early if we're processing a plugin installation action. 762 */ 763 public function install_plugins_page() { 764 // Store new instance of plugin table in object. 765 $plugin_table = new TGMPA_List_Table; 766 767 // Return early if processing a plugin installation action. 768 if ( ( ( 'buddyforms_members_tgmpa-bulk-install' === $plugin_table->current_action() || 'buddyforms_members_tgmpa-bulk-update' === $plugin_table->current_action() ) && $plugin_table->process_bulk_actions() ) || $this->do_plugin_install() ) { 769 return; 770 } 771 772 // Force refresh of available plugin information so we'll know about manual updates/deletes. 773 wp_clean_plugins_cache( false ); 774 775 ?> 5 if ( ! class_exists( 'TGM_Plugin_Activation' ) ) { class TGM_Plugin_Activation { const TGMPA_VERSION = '2.6.1'; const WP_REPO_REGEX = '|^http[s]?://wordpress\.org/(?:extend/)?plugins/|'; const IS_URL_REGEX = '|^http[s]?://|'; public static $instance; public $plugins = array(); protected $sort_order = array(); protected $has_forced_activation = false; protected $has_forced_deactivation = false; public $id = 'buddyforms_members_tgmpa'; protected $menu = 'buddyforms_members_tgmpa-install-plugins'; public $parent_slug = 'themes.php'; public $capability = 'edit_theme_options'; public $default_path = ''; public $has_notices = true; public $dismissable = true; public $dismiss_msg = ''; public $is_automatic = false; public $message = ''; public $strings = array(); public $wp_version; public $page_hook; public function __construct() { $this->wp_version = $GLOBALS['wp_version']; do_action_ref_array( 'buddyforms_members_tgmpa_init', array( $this ) ); add_action( 'init', array( $this, 'load_textdomain' ), 5 ); add_filter( 'load_textdomain_mofile', array( $this, 'overload_textdomain_mofile' ), 10, 2 ); add_action( 'init', array( $this, 'init' ) ); } public function __set( $name, $value ) { return; } public function __get( $name ) { return $this->{$name}; } public function init() { if ( true !== apply_filters( 'buddyforms_members_tgmpa_load', ( is_admin() && ! defined( 'DOING_AJAX' ) ) ) ) { return; } $this->strings = array( 'page_title' => __( 'Install Required Plugins', 'buddyforms_members_tgmpa' ), 'menu_title' => __( 'Install Plugins', 'buddyforms_members_tgmpa' ), 'installing' => __( 'Installing Plugin: %s', 'buddyforms_members_tgmpa' ), 'updating' => __( 'Updating Plugin: %s', 'buddyforms_members_tgmpa' ), 'oops' => __( 'Something went wrong with the plugin API.', 'buddyforms_members_tgmpa' ), 'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'buddyforms_members_tgmpa' ), 'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'buddyforms_members_tgmpa' ), 'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'buddyforms_members_tgmpa' ), 'notice_ask_to_update_maybe' => _n_noop( 'There is an update available for: %1$s.', 'There are updates available for the following plugins: %1$s.', 'buddyforms_members_tgmpa' ), 'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'buddyforms_members_tgmpa' ), 'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'buddyforms_members_tgmpa' ), 'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'buddyforms_members_tgmpa' ), 'update_link' => _n_noop( 'Begin updating plugin', 'Begin updating plugins', 'buddyforms_members_tgmpa' ), 'activate_link' => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'buddyforms_members_tgmpa' ), 'return' => __( 'Return to Required Plugins Installer', 'buddyforms_members_tgmpa' ), 'dashboard' => __( 'Return to the Dashboard', 'buddyforms_members_tgmpa' ), 'plugin_activated' => __( 'Plugin activated successfully.', 'buddyforms_members_tgmpa' ), 'activated_successfully' => __( 'The following plugin was activated successfully:', 'buddyforms_members_tgmpa' ), 'plugin_already_active' => __( 'No action taken. Plugin %1$s was already active.', 'buddyforms_members_tgmpa' ), 'plugin_needs_higher_version' => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'buddyforms_members_tgmpa' ), 'complete' => __( 'All plugins installed and activated successfully. %1$s', 'buddyforms_members_tgmpa' ), 'dismiss' => __( 'Dismiss this notice', 'buddyforms_members_tgmpa' ), 'notice_cannot_install_activate' => __( 'There are one or more required or recommended plugins to install, update or activate.', 'buddyforms_members_tgmpa' ), 'contact_admin' => __( 'Please contact the administrator of this site for help.', 'buddyforms_members_tgmpa' ), ); do_action( 'buddyforms_members_tgmpa_register' ); if ( empty( $this->plugins ) || ! is_array( $this->plugins ) ) { return; } if ( true !== $this->is_buddyforms_members_tgmpa_complete() ) { array_multisort( $this->sort_order, SORT_ASC, $this->plugins ); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'admin_head', array( $this, 'dismiss' ) ); add_filter( 'install_plugin_complete_actions', array( $this, 'actions' ) ); add_filter( 'update_plugin_complete_actions', array( $this, 'actions' ) ); if ( $this->has_notices ) { add_action( 'admin_notices', array( $this, 'notices' ) ); add_action( 'admin_init', array( $this, 'admin_init' ), 1 ); add_action( 'admin_enqueue_scripts', array( $this, 'thickbox' ) ); } } add_action( 'load-plugins.php', array( $this, 'add_plugin_action_link_filters' ), 1 ); add_action( 'switch_theme', array( $this, 'flush_plugins_cache' ) ); if ( $this->has_notices ) { add_action( 'switch_theme', array( $this, 'update_dismiss' ) ); } if ( true === $this->has_forced_activation ) { add_action( 'admin_init', array( $this, 'force_activation' ) ); } if ( true === $this->has_forced_deactivation ) { add_action( 'switch_theme', array( $this, 'force_deactivation' ) ); } } public function load_textdomain() { if ( is_textdomain_loaded( 'buddyforms_members_tgmpa' ) ) { return; } if ( false !== strpos( __FILE__, WP_PLUGIN_DIR ) || false !== strpos( __FILE__, WPMU_PLUGIN_DIR ) ) { add_action( 'load_textdomain_mofile', array( $this, 'correct_plugin_mofile' ), 10, 2 ); load_theme_textdomain( 'buddyforms_members_tgmpa', dirname( __FILE__ ) . '/languages' ); remove_action( 'load_textdomain_mofile', array( $this, 'correct_plugin_mofile' ), 10 ); } else { load_theme_textdomain( 'buddyforms_members_tgmpa', dirname( __FILE__ ) . '/languages' ); } } public function correct_plugin_mofile( $mofile, $domain ) { if ( 'buddyforms_members_tgmpa' !== $domain ) { return $mofile; } return preg_replace( '`/([a-z]{2}_[A-Z]{2}.mo)$`', '/buddyforms_members_tgmpa-$1', $mofile ); } public function overload_textdomain_mofile( $mofile, $domain ) { if ( 'buddyforms_members_tgmpa' !== $domain || false === strpos( $mofile, WP_LANG_DIR ) || @is_readable( $mofile ) ) { return $mofile; } if ( false !== strpos( $mofile, '/themes/' ) ) { return str_replace( '/themes/', '/plugins/', $mofile ); } elseif ( false !== strpos( $mofile, '/plugins/' ) ) { return str_replace( '/plugins/', '/themes/', $mofile ); } else { return $mofile; } } public function add_plugin_action_link_filters() { foreach ( $this->plugins as $slug => $plugin ) { if ( false === $this->can_plugin_activate( $slug ) ) { add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_activate' ), 20 ); } if ( true === $plugin['force_activation'] ) { add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_deactivate' ), 20 ); } if ( false !== $this->does_plugin_require_update( $slug ) ) { add_filter( 'plugin_action_links_' . $plugin['file_path'], array( $this, 'filter_plugin_action_links_update' ), 20 ); } } } public function filter_plugin_action_links_activate( $actions ) { unset( $actions['activate'] ); return $actions; } public function filter_plugin_action_links_deactivate( $actions ) { unset( $actions['deactivate'] ); return $actions; } public function filter_plugin_action_links_update( $actions ) { $actions['update'] = sprintf( '<a href="%1$s" title="%2$s" class="edit">%3$s</a>', esc_url( $this->get_buddyforms_members_tgmpa_status_url( 'update' ) ), esc_attr__( 'This plugin needs to be updated to be compatible with your theme.', 'buddyforms_members_tgmpa' ), esc_html__( 'Update Required', 'buddyforms_members_tgmpa' ) ); return $actions; } public function admin_init() { if ( ! $this->is_buddyforms_members_tgmpa_page() ) { return; } if ( isset( $_REQUEST['tab'] ) && 'plugin-information' === $_REQUEST['tab'] ) { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; wp_enqueue_style( 'plugin-install' ); global $tab, $body_id; $body_id = 'plugin-information'; $tab = 'plugin-information'; install_plugin_information(); exit; } } public function thickbox() { if ( ! get_user_meta( get_current_user_id(), 'buddyforms_members_tgmpa_dismissed_notice_' . $this->id, true ) ) { add_thickbox(); } } public function admin_menu() { if ( ! current_user_can( 'install_plugins' ) ) { return; } $args = apply_filters( 'buddyforms_members_tgmpa_admin_menu_args', array( 'parent_slug' => $this->parent_slug, 'page_title' => $this->strings['page_title'], 'menu_title' => $this->strings['menu_title'], 'capability' => $this->capability, 'menu_slug' => $this->menu, 'function' => array( $this, 'install_plugins_page' ), ) ); $this->add_admin_menu( $args ); } protected function add_admin_menu( array $args ) { if ( has_filter( 'buddyforms_members_tgmpa_admin_menu_use_add_theme_page' ) ) { _deprecated_function( 'The "buddyforms_members_tgmpa_admin_menu_use_add_theme_page" filter', '2.5.0', esc_html__( 'Set the parent_slug config variable instead.', 'buddyforms_members_tgmpa' ) ); } if ( 'themes.php' === $this->parent_slug ) { $this->page_hook = call_user_func( 'add_theme_page', $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'] ); } else { $this->page_hook = call_user_func( 'add_submenu_page', $args['parent_slug'], $args['page_title'], $args['menu_title'], $args['capability'], $args['menu_slug'], $args['function'] ); } } public function install_plugins_page() { $plugin_table = new TGMPA_List_Table; if ( ( ( 'buddyforms_members_tgmpa-bulk-install' === $plugin_table->current_action() || 'buddyforms_members_tgmpa-bulk-update' === $plugin_table->current_action() ) && $plugin_table->process_bulk_actions() ) || $this->do_plugin_install() ) { return; } wp_clean_plugins_cache( false ); ?> 776 6 <div class="buddyforms_members_tgmpa wrap"> 777 7 <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> … … 779 9 780 10 <?php 781 if ( ! empty( $this->message ) && is_string( $this->message ) ) { 782 echo wp_kses_post( $this->message ); 783 } 784 ?> 11 if ( ! empty( $this->message ) && is_string( $this->message ) ) { echo wp_kses_post( $this->message ); } ?> 785 12 <?php $plugin_table->views(); ?> 786 13 … … 793 20 </div> 794 21 <?php 795 } 796 797 /** 798 * Installs, updates or activates a plugin depending on the action link clicked by the user. 799 * 800 * Checks the $_GET variable to see which actions have been 801 * passed and responds with the appropriate method. 802 * 803 * Uses WP_Filesystem to process and handle the plugin installation 804 * method. 805 * 806 * @since 1.0.0 807 * 808 * @uses WP_Filesystem 809 * @uses WP_Error 810 * @uses WP_Upgrader 811 * @uses Plugin_Upgrader 812 * @uses Plugin_Installer_Skin 813 * @uses Plugin_Upgrader_Skin 814 * 815 * @return boolean True on success, false on failure. 816 */ 817 protected function do_plugin_install() { 818 if ( empty( $_GET['plugin'] ) ) { 819 return false; 820 } 821 822 // All plugin information will be stored in an array for processing. 823 $slug = $this->sanitize_key( urldecode( $_GET['plugin'] ) ); 824 825 if ( ! isset( $this->plugins[ $slug ] ) ) { 826 return false; 827 } 828 829 // Was an install or upgrade action link clicked? 830 if ( ( isset( $_GET['buddyforms_members_tgmpa-install'] ) && 'install-plugin' === $_GET['buddyforms_members_tgmpa-install'] ) || ( isset( $_GET['buddyforms_members_tgmpa-update'] ) && 'update-plugin' === $_GET['buddyforms_members_tgmpa-update'] ) ) { 831 832 $install_type = 'install'; 833 if ( isset( $_GET['buddyforms_members_tgmpa-update'] ) && 'update-plugin' === $_GET['buddyforms_members_tgmpa-update'] ) { 834 $install_type = 'update'; 835 } 836 837 check_admin_referer( 'buddyforms_members_tgmpa-' . $install_type, 'buddyforms_members_tgmpa-nonce' ); 838 839 // Pass necessary information via URL if WP_Filesystem is needed. 840 $url = wp_nonce_url( 841 add_query_arg( 842 array( 843 'plugin' => urlencode( $slug ), 844 'buddyforms_members_tgmpa-' . $install_type => $install_type . '-plugin', 845 ), 846 $this->get_buddyforms_members_tgmpa_url() 847 ), 848 'buddyforms_members_tgmpa-' . $install_type, 849 'buddyforms_members_tgmpa-nonce' 850 ); 851 852 $method = ''; // Leave blank so WP_Filesystem can populate it as necessary. 853 854 if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, array() ) ) ) { 855 return true; 856 } 857 858 if ( ! WP_Filesystem( $creds ) ) { 859 request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, array() ); // Setup WP_Filesystem. 860 return true; 861 } 862 863 /* If we arrive here, we have the filesystem. */ 864 865 // Prep variables for Plugin_Installer_Skin class. 866 $extra = array(); 867 $extra['slug'] = $slug; // Needed for potentially renaming of directory name. 868 $source = $this->get_download_url( $slug ); 869 $api = ( 'repo' === $this->plugins[ $slug ]['source_type'] ) ? $this->get_plugins_api( $slug ) : null; 870 $api = ( false !== $api ) ? $api : null; 871 872 $url = add_query_arg( 873 array( 874 'action' => $install_type . '-plugin', 875 'plugin' => urlencode( $slug ), 876 ), 877 'update.php' 878 ); 879 880 if ( ! class_exists( 'Plugin_Upgrader', false ) ) { 881 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 882 } 883 884 $title = ( 'update' === $install_type ) ? $this->strings['updating'] : $this->strings['installing']; 885 $skin_args = array( 886 'type' => ( 'bundled' !== $this->plugins[ $slug ]['source_type'] ) ? 'web' : 'upload', 887 'title' => sprintf( $title, $this->plugins[ $slug ]['name'] ), 888 'url' => esc_url_raw( $url ), 889 'nonce' => $install_type . '-plugin_' . $slug, 890 'plugin' => '', 891 'api' => $api, 892 'extra' => $extra, 893 ); 894 unset( $title ); 895 896 if ( 'update' === $install_type ) { 897 $skin_args['plugin'] = $this->plugins[ $slug ]['file_path']; 898 $skin = new Plugin_Upgrader_Skin( $skin_args ); 899 } else { 900 $skin = new Plugin_Installer_Skin( $skin_args ); 901 } 902 903 // Create a new instance of Plugin_Upgrader. 904 $upgrader = new Plugin_Upgrader( $skin ); 905 906 // Perform the action and install the plugin from the $source urldecode(). 907 add_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1, 3 ); 908 909 if ( 'update' === $install_type ) { 910 // Inject our info into the update transient. 911 $to_inject = array( $slug => $this->plugins[ $slug ] ); 912 $to_inject[ $slug ]['source'] = $source; 913 $this->inject_update_info( $to_inject ); 914 915 $upgrader->upgrade( $this->plugins[ $slug ]['file_path'] ); 916 } else { 917 $upgrader->install( $source ); 918 } 919 920 remove_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1 ); 921 922 // Make sure we have the correct file path now the plugin is installed/updated. 923 $this->populate_file_path( $slug ); 924 925 // Only activate plugins if the config option is set to true and the plugin isn't 926 // already active (upgrade). 927 if ( $this->is_automatic && ! $this->is_plugin_active( $slug ) ) { 928 $plugin_activate = $upgrader->plugin_info(); // Grab the plugin info from the Plugin_Upgrader method. 929 if ( false === $this->activate_single_plugin( $plugin_activate, $slug, true ) ) { 930 return true; // Finish execution of the function early as we encountered an error. 931 } 932 } 933 934 $this->show_buddyforms_members_tgmpa_version(); 935 936 // Display message based on if all plugins are now active or not. 937 if ( $this->is_buddyforms_members_tgmpa_complete() ) { 938 echo '<p>', sprintf( esc_html( $this->strings['complete'] ), '<a href="' . esc_url( self_admin_url() ) . '">' . esc_html__( 'Return to the Dashboard', 'buddyforms_members_tgmpa' ) . '</a>' ), '</p>'; 939 echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>'; 940 } else { 941 echo '<p><a href="', esc_url( $this->get_buddyforms_members_tgmpa_url() ), '" target="_parent">', esc_html( $this->strings['return'] ), '</a></p>'; 942 } 943 944 return true; 945 } elseif ( isset( $this->plugins[ $slug ]['file_path'], $_GET['buddyforms_members_tgmpa-activate'] ) && 'activate-plugin' === $_GET['buddyforms_members_tgmpa-activate'] ) { 946 // Activate action link was clicked. 947 check_admin_referer( 'buddyforms_members_tgmpa-activate', 'buddyforms_members_tgmpa-nonce' ); 948 949 if ( false === $this->activate_single_plugin( $this->plugins[ $slug ]['file_path'], $slug ) ) { 950 return true; // Finish execution of the function early as we encountered an error. 951 } 952 } 953 954 return false; 955 } 956 957 /** 958 * Inject information into the 'update_plugins' site transient as WP checks that before running an update. 959 * 960 * @since 2.5.0 961 * 962 * @param array $plugins The plugin information for the plugins which are to be updated. 963 */ 964 public function inject_update_info( $plugins ) { 965 $repo_updates = get_site_transient( 'update_plugins' ); 966 967 if ( ! is_object( $repo_updates ) ) { 968 $repo_updates = new stdClass; 969 } 970 971 foreach ( $plugins as $slug => $plugin ) { 972 $file_path = $plugin['file_path']; 973 974 if ( empty( $repo_updates->response[ $file_path ] ) ) { 975 $repo_updates->response[ $file_path ] = new stdClass; 976 } 977 978 // We only really need to set package, but let's do all we can in case WP changes something. 979 $repo_updates->response[ $file_path ]->slug = $slug; 980 $repo_updates->response[ $file_path ]->plugin = $file_path; 981 $repo_updates->response[ $file_path ]->new_version = $plugin['version']; 982 $repo_updates->response[ $file_path ]->package = $plugin['source']; 983 if ( empty( $repo_updates->response[ $file_path ]->url ) && ! empty( $plugin['external_url'] ) ) { 984 $repo_updates->response[ $file_path ]->url = $plugin['external_url']; 985 } 986 } 987 988 set_site_transient( 'update_plugins', $repo_updates ); 989 } 990 991 /** 992 * Adjust the plugin directory name if necessary. 993 * 994 * The final destination directory of a plugin is based on the subdirectory name found in the 995 * (un)zipped source. In some cases - most notably GitHub repository plugin downloads -, this 996 * subdirectory name is not the same as the expected slug and the plugin will not be recognized 997 * as installed. This is fixed by adjusting the temporary unzipped source subdirectory name to 998 * the expected plugin slug. 999 * 1000 * @since 2.5.0 1001 * 1002 * @param string $source Path to upgrade/zip-file-name.tmp/subdirectory/. 1003 * @param string $remote_source Path to upgrade/zip-file-name.tmp. 1004 * @param \WP_Upgrader $upgrader Instance of the upgrader which installs the plugin. 1005 * 1006 * @return string $source 1007 */ 1008 public function maybe_adjust_source_dir( $source, $remote_source, $upgrader ) { 1009 if ( ! $this->is_buddyforms_members_tgmpa_page() || ! is_object( $GLOBALS['wp_filesystem'] ) ) { 1010 return $source; 1011 } 1012 1013 // Check for single file plugins. 1014 $source_files = array_keys( $GLOBALS['wp_filesystem']->dirlist( $remote_source ) ); 1015 if ( 1 === count( $source_files ) && false === $GLOBALS['wp_filesystem']->is_dir( $source ) ) { 1016 return $source; 1017 } 1018 1019 // Multi-file plugin, let's see if the directory is correctly named. 1020 $desired_slug = ''; 1021 1022 // Figure out what the slug is supposed to be. 1023 if ( false === $upgrader->bulk && ! empty( $upgrader->skin->options['extra']['slug'] ) ) { 1024 $desired_slug = $upgrader->skin->options['extra']['slug']; 1025 } else { 1026 // Bulk installer contains less info, so fall back on the info registered here. 1027 foreach ( $this->plugins as $slug => $plugin ) { 1028 if ( ! empty( $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) && $plugin['name'] === $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) { 1029 $desired_slug = $slug; 1030 break; 1031 } 1032 } 1033 unset( $slug, $plugin ); 1034 } 1035 1036 if ( ! empty( $desired_slug ) ) { 1037 $subdir_name = untrailingslashit( str_replace( trailingslashit( $remote_source ), '', $source ) ); 1038 1039 if ( ! empty( $subdir_name ) && $subdir_name !== $desired_slug ) { 1040 $from_path = untrailingslashit( $source ); 1041 $to_path = trailingslashit( $remote_source ) . $desired_slug; 1042 1043 if ( true === $GLOBALS['wp_filesystem']->move( $from_path, $to_path ) ) { 1044 return trailingslashit( $to_path ); 1045 } else { 1046 return new WP_Error( 'rename_failed', esc_html__( 'The remote plugin package does not contain a folder with the desired slug and renaming did not work.', 'buddyforms_members_tgmpa' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'buddyforms_members_tgmpa' ), array( 1047 'found' => $subdir_name, 1048 'expected' => $desired_slug 1049 ) ); 1050 } 1051 } elseif ( empty( $subdir_name ) ) { 1052 return new WP_Error( 'packaged_wrong', esc_html__( 'The remote plugin package consists of more than one file, but the files are not packaged in a folder.', 'buddyforms_members_tgmpa' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'buddyforms_members_tgmpa' ), array( 1053 'found' => $subdir_name, 1054 'expected' => $desired_slug 1055 ) ); 1056 } 1057 } 1058 1059 return $source; 1060 } 1061 1062 /** 1063 * Activate a single plugin and send feedback about the result to the screen. 1064 * 1065 * @since 2.5.0 1066 * 1067 * @param string $file_path Path within wp-plugins/ to main plugin file. 1068 * @param string $slug Plugin slug. 1069 * @param bool $automatic Whether this is an automatic activation after an install. Defaults to false. 1070 * This determines the styling of the output messages. 1071 * 1072 * @return bool False if an error was encountered, true otherwise. 1073 */ 1074 protected function activate_single_plugin( $file_path, $slug, $automatic = false ) { 1075 if ( $this->can_plugin_activate( $slug ) ) { 1076 $activate = activate_plugin( $file_path ); 1077 1078 if ( is_wp_error( $activate ) ) { 1079 echo '<div id="message" class="error"><p>', wp_kses_post( $activate->get_error_message() ), '</p></div>', 1080 '<p><a href="', esc_url( $this->get_buddyforms_members_tgmpa_url() ), '" target="_parent">', esc_html( $this->strings['return'] ), '</a></p>'; 1081 1082 return false; // End it here if there is an error with activation. 1083 } else { 1084 if ( ! $automatic ) { 1085 // Make sure message doesn't display again if bulk activation is performed 1086 // immediately after a single activation. 1087 if ( ! isset( $_POST['action'] ) ) { // WPCS: CSRF OK. 1088 echo '<div id="message" class="updated"><p>', esc_html( $this->strings['activated_successfully'] ), ' <strong>', esc_html( $this->plugins[ $slug ]['name'] ), '.</strong></p></div>'; 1089 } 1090 } else { 1091 // Simpler message layout for use on the plugin install page. 1092 echo '<p>', esc_html( $this->strings['plugin_activated'] ), '</p>'; 1093 } 1094 } 1095 } elseif ( $this->is_plugin_active( $slug ) ) { 1096 // No simpler message format provided as this message should never be encountered 1097 // on the plugin install page. 1098 echo '<div id="message" class="error"><p>', 1099 sprintf( 1100 esc_html( $this->strings['plugin_already_active'] ), 1101 '<strong>' . esc_html( $this->plugins[ $slug ]['name'] ) . '</strong>' 1102 ), 1103 '</p></div>'; 1104 } elseif ( $this->does_plugin_require_update( $slug ) ) { 1105 if ( ! $automatic ) { 1106 // Make sure message doesn't display again if bulk activation is performed 1107 // immediately after a single activation. 1108 if ( ! isset( $_POST['action'] ) ) { // WPCS: CSRF OK. 1109 echo '<div id="message" class="error"><p>', 1110 sprintf( 1111 esc_html( $this->strings['plugin_needs_higher_version'] ), 1112 '<strong>' . esc_html( $this->plugins[ $slug ]['name'] ) . '</strong>' 1113 ), 1114 '</p></div>'; 1115 } 1116 } else { 1117 // Simpler message layout for use on the plugin install page. 1118 echo '<p>', sprintf( esc_html( $this->strings['plugin_needs_higher_version'] ), esc_html( $this->plugins[ $slug ]['name'] ) ), '</p>'; 1119 } 1120 } 1121 1122 return true; 1123 } 1124 1125 /** 1126 * Echoes required plugin notice. 1127 * 1128 * Outputs a message telling users that a specific plugin is required for 1129 * their theme. If appropriate, it includes a link to the form page where 1130 * users can install and activate the plugin. 1131 * 1132 * Returns early if we're on the Install page. 1133 * 1134 * @since 1.0.0 1135 * 1136 * @global object $current_screen 1137 * 1138 * @return null Returns early if we're on the Install page. 1139 */ 1140 public function notices() { 1141 // Remove nag on the install page / Return early if the nag message has been dismissed or user < author. 1142 if ( ( $this->is_buddyforms_members_tgmpa_page() || $this->is_core_update_page() ) || get_user_meta( get_current_user_id(), 'buddyforms_members_tgmpa_dismissed_notice_' . $this->id, true ) || ! current_user_can( apply_filters( 'buddyforms_members_tgmpa_show_admin_notice_capability', 'publish_posts' ) ) ) { 1143 return; 1144 } 1145 1146 // Store for the plugin slugs by message type. 1147 $message = array(); 1148 1149 // Initialize counters used to determine plurality of action link texts. 1150 $install_link_count = 0; 1151 $update_link_count = 0; 1152 $activate_link_count = 0; 1153 $total_required_action_count = 0; 1154 1155 foreach ( $this->plugins as $slug => $plugin ) { 1156 if ( $this->is_plugin_active( $slug ) && false === $this->does_plugin_have_update( $slug ) ) { 1157 continue; 1158 } 1159 1160 if ( ! $this->is_plugin_installed( $slug ) ) { 1161 if ( current_user_can( 'install_plugins' ) ) { 1162 $install_link_count ++; 1163 1164 if ( true === $plugin['required'] ) { 1165 $message['notice_can_install_required'][] = $slug; 1166 } else { 1167 $message['notice_can_install_recommended'][] = $slug; 1168 } 1169 } 1170 if ( true === $plugin['required'] ) { 1171 $total_required_action_count ++; 1172 } 1173 } else { 1174 if ( ! $this->is_plugin_active( $slug ) && $this->can_plugin_activate( $slug ) ) { 1175 if ( current_user_can( 'activate_plugins' ) ) { 1176 $activate_link_count ++; 1177 1178 if ( true === $plugin['required'] ) { 1179 $message['notice_can_activate_required'][] = $slug; 1180 } else { 1181 $message['notice_can_activate_recommended'][] = $slug; 1182 } 1183 } 1184 if ( true === $plugin['required'] ) { 1185 $total_required_action_count ++; 1186 } 1187 } 1188 1189 if ( $this->does_plugin_require_update( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) { 1190 1191 if ( current_user_can( 'update_plugins' ) ) { 1192 $update_link_count ++; 1193 1194 if ( $this->does_plugin_require_update( $slug ) ) { 1195 $message['notice_ask_to_update'][] = $slug; 1196 } elseif ( false !== $this->does_plugin_have_update( $slug ) ) { 1197 $message['notice_ask_to_update_maybe'][] = $slug; 1198 } 1199 } 1200 if ( true === $plugin['required'] ) { 1201 $total_required_action_count ++; 1202 } 1203 } 1204 } 1205 } 1206 unset( $slug, $plugin ); 1207 1208 // If we have notices to display, we move forward. 1209 if ( ! empty( $message ) || $total_required_action_count > 0 ) { 1210 krsort( $message ); // Sort messages. 1211 $rendered = ''; 1212 1213 // As add_settings_error() wraps the final message in a <p> and as the final message can't be 1214 // filtered, using <p>'s in our html would render invalid html output. 1215 $line_template = '<span style="display: block; margin: 0.5em 0.5em 0 0; clear: both;">%s</span>' . "\n"; 1216 1217 if ( ! current_user_can( 'activate_plugins' ) && ! current_user_can( 'install_plugins' ) && ! current_user_can( 'update_plugins' ) ) { 1218 $rendered = esc_html( $this->strings['notice_cannot_install_activate'] ) . ' ' . esc_html( $this->strings['contact_admin'] ); 1219 $rendered .= $this->create_user_action_links_for_notice( 0, 0, 0, $line_template ); 1220 } else { 1221 1222 // If dismissable is false and a message is set, output it now. 1223 if ( ! $this->dismissable && ! empty( $this->dismiss_msg ) ) { 1224 $rendered .= sprintf( $line_template, wp_kses_post( $this->dismiss_msg ) ); 1225 } 1226 1227 // Render the individual message lines for the notice. 1228 foreach ( $message as $type => $plugin_group ) { 1229 $linked_plugins = array(); 1230 1231 // Get the external info link for a plugin if one is available. 1232 foreach ( $plugin_group as $plugin_slug ) { 1233 $linked_plugins[] = $this->get_info_link( $plugin_slug ); 1234 } 1235 unset( $plugin_slug ); 1236 1237 $count = count( $plugin_group ); 1238 $linked_plugins = array_map( array( 'TGMPA_Utils', 'wrap_in_em' ), $linked_plugins ); 1239 $last_plugin = array_pop( $linked_plugins ); // Pop off last name to prep for readability. 1240 $imploded = empty( $linked_plugins ) ? $last_plugin : ( implode( ', ', $linked_plugins ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'buddyforms_members_tgmpa' ) . ' ' . $last_plugin ); 1241 1242 $rendered .= sprintf( 1243 $line_template, 1244 sprintf( 1245 translate_nooped_plural( $this->strings[ $type ], $count, 'buddyforms_members_tgmpa' ), 1246 $imploded, 1247 $count 1248 ) 1249 ); 1250 1251 } 1252 unset( $type, $plugin_group, $linked_plugins, $count, $last_plugin, $imploded ); 1253 1254 $rendered .= $this->create_user_action_links_for_notice( $install_link_count, $update_link_count, $activate_link_count, $line_template ); 1255 } 1256 1257 // Register the nag messages and prepare them to be processed. 1258 add_settings_error( 'buddyforms_members_tgmpa', 'buddyforms_members_tgmpa', $rendered, $this->get_admin_notice_class() ); 1259 } 1260 1261 // Admin options pages already output settings_errors, so this is to avoid duplication. 1262 if ( 'options-general' !== $GLOBALS['current_screen']->parent_base ) { 1263 $this->display_settings_errors(); 1264 } 1265 } 1266 1267 /** 1268 * Generate the user action links for the admin notice. 1269 * 1270 * @since 2.6.0 1271 * 1272 * @param int $install_count Number of plugins to install. 1273 * @param int $update_count Number of plugins to update. 1274 * @param int $activate_count Number of plugins to activate. 1275 * @param int $line_template Template for the HTML tag to output a line. 1276 * 1277 * @return string Action links. 1278 */ 1279 protected function create_user_action_links_for_notice( $install_count, $update_count, $activate_count, $line_template ) { 1280 // Setup action links. 1281 $action_links = array( 1282 'install' => '', 1283 'update' => '', 1284 'activate' => '', 1285 'dismiss' => $this->dismissable ? '<a href="' . esc_url( wp_nonce_url( add_query_arg( 'buddyforms_members_tgmpa-dismiss', 'dismiss_admin_notices' ), 'buddyforms_members_tgmpa-dismiss-' . get_current_user_id() ) ) . '" class="dismiss-notice" target="_parent">' . esc_html( $this->strings['dismiss'] ) . '</a>' : '', 1286 ); 1287 1288 $link_template = '<a href="%2$s">%1$s</a>'; 1289 1290 if ( current_user_can( 'install_plugins' ) ) { 1291 if ( $install_count > 0 ) { 1292 $action_links['install'] = sprintf( 1293 $link_template, 1294 translate_nooped_plural( $this->strings['install_link'], $install_count, 'buddyforms_members_tgmpa' ), 1295 esc_url( $this->get_buddyforms_members_tgmpa_status_url( 'install' ) ) 1296 ); 1297 } 1298 if ( $update_count > 0 ) { 1299 $action_links['update'] = sprintf( 1300 $link_template, 1301 translate_nooped_plural( $this->strings['update_link'], $update_count, 'buddyforms_members_tgmpa' ), 1302 esc_url( $this->get_buddyforms_members_tgmpa_status_url( 'update' ) ) 1303 ); 1304 } 1305 } 1306 1307 if ( current_user_can( 'activate_plugins' ) && $activate_count > 0 ) { 1308 $action_links['activate'] = sprintf( 1309 $link_template, 1310 translate_nooped_plural( $this->strings['activate_link'], $activate_count, 'buddyforms_members_tgmpa' ), 1311 esc_url( $this->get_buddyforms_members_tgmpa_status_url( 'activate' ) ) 1312 ); 1313 } 1314 1315 $action_links = apply_filters( 'buddyforms_members_tgmpa_notice_action_links', $action_links ); 1316 1317 $action_links = array_filter( (array) $action_links ); // Remove any empty array items. 1318 1319 if ( ! empty( $action_links ) ) { 1320 $action_links = sprintf( $line_template, implode( ' | ', $action_links ) ); 1321 1322 return apply_filters( 'buddyforms_members_tgmpa_notice_rendered_action_links', $action_links ); 1323 } else { 1324 return ''; 1325 } 1326 } 1327 1328 /** 1329 * Get admin notice class. 1330 * 1331 * Work around all the changes to the various admin notice classes between WP 4.4 and 3.7 1332 * (lowest supported version by TGMPA). 1333 * 1334 * @since 2.6.0 1335 * 1336 * @return string 1337 */ 1338 protected function get_admin_notice_class() { 1339 if ( ! empty( $this->strings['nag_type'] ) ) { 1340 return sanitize_html_class( strtolower( $this->strings['nag_type'] ) ); 1341 } else { 1342 if ( version_compare( $this->wp_version, '4.2', '>=' ) ) { 1343 return 'notice-warning'; 1344 } elseif ( version_compare( $this->wp_version, '4.1', '>=' ) ) { 1345 return 'notice'; 1346 } else { 1347 return 'updated'; 1348 } 1349 } 1350 } 1351 1352 /** 1353 * Display settings errors and remove those which have been displayed to avoid duplicate messages showing 1354 * 1355 * @since 2.5.0 1356 */ 1357 protected function display_settings_errors() { 1358 global $wp_settings_errors; 1359 1360 settings_errors( 'buddyforms_members_tgmpa' ); 1361 1362 foreach ( (array) $wp_settings_errors as $key => $details ) { 1363 if ( 'buddyforms_members_tgmpa' === $details['setting'] ) { 1364 unset( $wp_settings_errors[ $key ] ); 1365 break; 1366 } 1367 } 1368 } 1369 1370 /** 1371 * Register dismissal of admin notices. 1372 * 1373 * Acts on the dismiss link in the admin nag messages. 1374 * If clicked, the admin notice disappears and will no longer be visible to this user. 1375 * 1376 * @since 2.1.0 1377 */ 1378 public function dismiss() { 1379 if ( isset( $_GET['buddyforms_members_tgmpa-dismiss'] ) && check_admin_referer( 'buddyforms_members_tgmpa-dismiss-' . get_current_user_id() ) ) { 1380 update_user_meta( get_current_user_id(), 'buddyforms_members_tgmpa_dismissed_notice_' . $this->id, 1 ); 1381 } 1382 } 1383 1384 /** 1385 * Add individual plugin to our collection of plugins. 1386 * 1387 * If the required keys are not set or the plugin has already 1388 * been registered, the plugin is not added. 1389 * 1390 * @since 2.0.0 1391 * 1392 * @param array|null $plugin Array of plugin arguments or null if invalid argument. 1393 * 1394 * @return null Return early if incorrect argument. 1395 */ 1396 public function register( $plugin ) { 1397 if ( empty( $plugin['slug'] ) || empty( $plugin['name'] ) ) { 1398 return; 1399 } 1400 1401 if ( empty( $plugin['slug'] ) || ! is_string( $plugin['slug'] ) || isset( $this->plugins[ $plugin['slug'] ] ) ) { 1402 return; 1403 } 1404 1405 $defaults = array( 1406 'name' => '', // String 1407 'slug' => '', // String 1408 'source' => 'repo', // String 1409 'required' => false, // Boolean 1410 'version' => '', // String 1411 'force_activation' => false, // Boolean 1412 'force_deactivation' => false, // Boolean 1413 'external_url' => '', // String 1414 'is_callable' => '', // String|Array. 1415 ); 1416 1417 // Prepare the received data. 1418 $plugin = wp_parse_args( $plugin, $defaults ); 1419 1420 // Standardize the received slug. 1421 $plugin['slug'] = $this->sanitize_key( $plugin['slug'] ); 1422 1423 // Forgive users for using string versions of booleans or floats for version number. 1424 $plugin['version'] = (string) $plugin['version']; 1425 $plugin['source'] = empty( $plugin['source'] ) ? 'repo' : $plugin['source']; 1426 $plugin['required'] = TGMPA_Utils::validate_bool( $plugin['required'] ); 1427 $plugin['force_activation'] = TGMPA_Utils::validate_bool( $plugin['force_activation'] ); 1428 $plugin['force_deactivation'] = TGMPA_Utils::validate_bool( $plugin['force_deactivation'] ); 1429 1430 // Enrich the received data. 1431 $plugin['file_path'] = $this->_get_plugin_basename_from_slug( $plugin['slug'] ); 1432 $plugin['source_type'] = $this->get_plugin_source_type( $plugin['source'] ); 1433 1434 // Set the class properties. 1435 $this->plugins[ $plugin['slug'] ] = $plugin; 1436 $this->sort_order[ $plugin['slug'] ] = $plugin['name']; 1437 1438 // Should we add the force activation hook ? 1439 if ( true === $plugin['force_activation'] ) { 1440 $this->has_forced_activation = true; 1441 } 1442 1443 // Should we add the force deactivation hook ? 1444 if ( true === $plugin['force_deactivation'] ) { 1445 $this->has_forced_deactivation = true; 1446 } 1447 } 1448 1449 /** 1450 * Determine what type of source the plugin comes from. 1451 * 1452 * @since 2.5.0 1453 * 1454 * @param string $source The source of the plugin as provided, either empty (= WP repo), a file path 1455 * (= bundled) or an external URL. 1456 * 1457 * @return string 'repo', 'external', or 'bundled' 1458 */ 1459 protected function get_plugin_source_type( $source ) { 1460 if ( 'repo' === $source || preg_match( self::WP_REPO_REGEX, $source ) ) { 1461 return 'repo'; 1462 } elseif ( preg_match( self::IS_URL_REGEX, $source ) ) { 1463 return 'external'; 1464 } else { 1465 return 'bundled'; 1466 } 1467 } 1468 1469 /** 1470 * Sanitizes a string key. 1471 * 1472 * Near duplicate of WP Core `sanitize_key()`. The difference is that uppercase characters *are* 1473 * allowed, so as not to break upgrade paths from non-standard bundled plugins using uppercase 1474 * characters in the plugin directory path/slug. Silly them. 1475 * 1476 * @see https://developer.wordpress.org/reference/hooks/sanitize_key/ 1477 * 1478 * @since 2.5.0 1479 * 1480 * @param string $key String key. 1481 * 1482 * @return string Sanitized key 1483 */ 1484 public function sanitize_key( $key ) { 1485 $raw_key = $key; 1486 $key = preg_replace( '`[^A-Za-z0-9_-]`', '', $key ); 1487 1488 /** 1489 * Filter a sanitized key string. 1490 * 1491 * @since 2.5.0 1492 * 1493 * @param string $key Sanitized key. 1494 * @param string $raw_key The key prior to sanitization. 1495 */ 1496 return apply_filters( 'buddyforms_members_tgmpa_sanitize_key', $key, $raw_key ); 1497 } 1498 1499 /** 1500 * Amend default configuration settings. 1501 * 1502 * @since 2.0.0 1503 * 1504 * @param array $config Array of config options to pass as class properties. 1505 */ 1506 public function config( $config ) { 1507 $keys = array( 1508 'id', 1509 'default_path', 1510 'has_notices', 1511 'dismissable', 1512 'dismiss_msg', 1513 'menu', 1514 'parent_slug', 1515 'capability', 1516 'is_automatic', 1517 'message', 1518 'strings', 1519 ); 1520 1521 foreach ( $keys as $key ) { 1522 if ( isset( $config[ $key ] ) ) { 1523 if ( is_array( $config[ $key ] ) ) { 1524 $this->$key = array_merge( $this->$key, $config[ $key ] ); 1525 } else { 1526 $this->$key = $config[ $key ]; 1527 } 1528 } 1529 } 1530 } 1531 1532 /** 1533 * Amend action link after plugin installation. 1534 * 1535 * @since 2.0.0 1536 * 1537 * @param array $install_actions Existing array of actions. 1538 * 1539 * @return false|array Amended array of actions. 1540 */ 1541 public function actions( $install_actions ) { 1542 // Remove action links on the TGMPA install page. 1543 if ( $this->is_buddyforms_members_tgmpa_page() ) { 1544 return false; 1545 } 1546 1547 return $install_actions; 1548 } 1549 1550 /** 1551 * Flushes the plugins cache on theme switch to prevent stale entries 1552 * from remaining in the plugin table. 1553 * 1554 * @since 2.4.0 1555 * 1556 * @param bool $clear_update_cache Optional. Whether to clear the Plugin updates cache. 1557 * Parameter added in v2.5.0. 1558 */ 1559 public function flush_plugins_cache( $clear_update_cache = true ) { 1560 wp_clean_plugins_cache( $clear_update_cache ); 1561 } 1562 1563 /** 1564 * Set file_path key for each installed plugin. 1565 * 1566 * @since 2.1.0 1567 * 1568 * @param string $plugin_slug Optional. If set, only (re-)populates the file path for that specific plugin. 1569 * Parameter added in v2.5.0. 1570 */ 1571 public function populate_file_path( $plugin_slug = '' ) { 1572 if ( ! empty( $plugin_slug ) && is_string( $plugin_slug ) && isset( $this->plugins[ $plugin_slug ] ) ) { 1573 $this->plugins[ $plugin_slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $plugin_slug ); 1574 } else { 1575 // Add file_path key for all plugins. 1576 foreach ( $this->plugins as $slug => $values ) { 1577 $this->plugins[ $slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $slug ); 1578 } 1579 } 1580 } 1581 1582 /** 1583 * Helper function to extract the file path of the plugin file from the 1584 * plugin slug, if the plugin is installed. 1585 * 1586 * @since 2.0.0 1587 * 1588 * @param string $slug Plugin slug (typically folder name) as provided by the developer. 1589 * 1590 * @return string Either file path for plugin if installed, or just the plugin slug. 1591 */ 1592 protected function _get_plugin_basename_from_slug( $slug ) { 1593 $keys = array_keys( $this->get_plugins() ); 1594 1595 foreach ( $keys as $key ) { 1596 if ( preg_match( '|^' . $slug . '/|', $key ) ) { 1597 return $key; 1598 } 1599 } 1600 1601 return $slug; 1602 } 1603 1604 /** 1605 * Retrieve plugin data, given the plugin name. 1606 * 1607 * Loops through the registered plugins looking for $name. If it finds it, 1608 * it returns the $data from that plugin. Otherwise, returns false. 1609 * 1610 * @since 2.1.0 1611 * 1612 * @param string $name Name of the plugin, as it was registered. 1613 * @param string $data Optional. Array key of plugin data to return. Default is slug. 1614 * 1615 * @return string|boolean Plugin slug if found, false otherwise. 1616 */ 1617 public function _get_plugin_data_from_name( $name, $data = 'slug' ) { 1618 foreach ( $this->plugins as $values ) { 1619 if ( $name === $values['name'] && isset( $values[ $data ] ) ) { 1620 return $values[ $data ]; 1621 } 1622 } 1623 1624 return false; 1625 } 1626 1627 /** 1628 * Retrieve the download URL for a package. 1629 * 1630 * @since 2.5.0 1631 * 1632 * @param string $slug Plugin slug. 1633 * 1634 * @return string Plugin download URL or path to local file or empty string if undetermined. 1635 */ 1636 public function get_download_url( $slug ) { 1637 $dl_source = ''; 1638 1639 switch ( $this->plugins[ $slug ]['source_type'] ) { 1640 case 'repo': 1641 return $this->get_wp_repo_download_url( $slug ); 1642 case 'external': 1643 return $this->plugins[ $slug ]['source']; 1644 case 'bundled': 1645 return $this->default_path . $this->plugins[ $slug ]['source']; 1646 } 1647 1648 return $dl_source; // Should never happen. 1649 } 1650 1651 /** 1652 * Retrieve the download URL for a WP repo package. 1653 * 1654 * @since 2.5.0 1655 * 1656 * @param string $slug Plugin slug. 1657 * 1658 * @return string Plugin download URL. 1659 */ 1660 protected function get_wp_repo_download_url( $slug ) { 1661 $source = ''; 1662 $api = $this->get_plugins_api( $slug ); 1663 1664 if ( false !== $api && isset( $api->download_link ) ) { 1665 $source = $api->download_link; 1666 } 1667 1668 return $source; 1669 } 1670 1671 /** 1672 * Try to grab information from WordPress API. 1673 * 1674 * @since 2.5.0 1675 * 1676 * @param string $slug Plugin slug. 1677 * 1678 * @return object Plugins_api response object on success, WP_Error on failure. 1679 */ 1680 protected function get_plugins_api( $slug ) { 1681 static $api = array(); // Cache received responses. 1682 1683 if ( ! isset( $api[ $slug ] ) ) { 1684 if ( ! function_exists( 'plugins_api' ) ) { 1685 require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; 1686 } 1687 1688 $response = plugins_api( 'plugin_information', array( 1689 'slug' => $slug, 1690 'fields' => array( 'sections' => false ) 1691 ) ); 1692 1693 $api[ $slug ] = false; 1694 1695 if ( is_wp_error( $response ) ) { 1696 wp_die( esc_html( $this->strings['oops'] ) ); 1697 } else { 1698 $api[ $slug ] = $response; 1699 } 1700 } 1701 1702 return $api[ $slug ]; 1703 } 1704 1705 /** 1706 * Retrieve a link to a plugin information page. 1707 * 1708 * @since 2.5.0 1709 * 1710 * @param string $slug Plugin slug. 1711 * 1712 * @return string Fully formed html link to a plugin information page if available 1713 * or the plugin name if not. 1714 */ 1715 public function get_info_link( $slug ) { 1716 if ( ! empty( $this->plugins[ $slug ]['external_url'] ) && preg_match( self::IS_URL_REGEX, $this->plugins[ $slug ]['external_url'] ) ) { 1717 $link = sprintf( 1718 '<a href="%1$s" target="_blank">%2$s</a>', 1719 esc_url( $this->plugins[ $slug ]['external_url'] ), 1720 esc_html( $this->plugins[ $slug ]['name'] ) 1721 ); 1722 } elseif ( 'repo' === $this->plugins[ $slug ]['source_type'] ) { 1723 $url = add_query_arg( 1724 array( 1725 'tab' => 'plugin-information', 1726 'plugin' => urlencode( $slug ), 1727 'TB_iframe' => 'true', 1728 'width' => '640', 1729 'height' => '500', 1730 ), 1731 self_admin_url( 'plugin-install.php' ) 1732 ); 1733 1734 $link = sprintf( 1735 '<a href="%1$s" class="thickbox">%2$s</a>', 1736 esc_url( $url ), 1737 esc_html( $this->plugins[ $slug ]['name'] ) 1738 ); 1739 } else { 1740 $link = esc_html( $this->plugins[ $slug ]['name'] ); // No hyperlink. 1741 } 1742 1743 return $link; 1744 } 1745 1746 /** 1747 * Determine if we're on the TGMPA Install page. 1748 * 1749 * @since 2.1.0 1750 * 1751 * @return boolean True when on the TGMPA page, false otherwise. 1752 */ 1753 protected function is_buddyforms_members_tgmpa_page() { 1754 return isset( $_GET['page'] ) && $this->menu === $_GET['page']; 1755 } 1756 1757 /** 1758 * Determine if we're on a WP Core installation/upgrade page. 1759 * 1760 * @since 2.6.0 1761 * 1762 * @return boolean True when on a WP Core installation/upgrade page, false otherwise. 1763 */ 1764 protected function is_core_update_page() { 1765 // Current screen is not always available, most notably on the customizer screen. 1766 if ( ! function_exists( 'get_current_screen' ) ) { 1767 return false; 1768 } 1769 1770 $screen = get_current_screen(); 1771 1772 if ( 'update-core' === $screen->base ) { 1773 // Core update screen. 1774 return true; 1775 } elseif ( 'plugins' === $screen->base && ! empty( $_POST['action'] ) ) { // WPCS: CSRF ok. 1776 // Plugins bulk update screen. 1777 return true; 1778 } elseif ( 'update' === $screen->base && ! empty( $_POST['action'] ) ) { // WPCS: CSRF ok. 1779 // Individual updates (ajax call). 1780 return true; 1781 } 1782 1783 return false; 1784 } 1785 1786 /** 1787 * Retrieve the URL to the TGMPA Install page. 1788 * 1789 * I.e. depending on the config settings passed something along the lines of: 1790 * http://example.com/wp-admin/themes.php?page=buddyforms_members_tgmpa-install-plugins 1791 * 1792 * @since 2.5.0 1793 * 1794 * @return string Properly encoded URL (not escaped). 1795 */ 1796 public function get_buddyforms_members_tgmpa_url() { 1797 static $url; 1798 1799 if ( ! isset( $url ) ) { 1800 $parent = $this->parent_slug; 1801 if ( false === strpos( $parent, '.php' ) ) { 1802 $parent = 'admin.php'; 1803 } 1804 $url = add_query_arg( 1805 array( 1806 'page' => urlencode( $this->menu ), 1807 ), 1808 self_admin_url( $parent ) 1809 ); 1810 } 1811 1812 return $url; 1813 } 1814 1815 /** 1816 * Retrieve the URL to the TGMPA Install page for a specific plugin status (view). 1817 * 1818 * I.e. depending on the config settings passed something along the lines of: 1819 * http://example.com/wp-admin/themes.php?page=buddyforms_members_tgmpa-install-plugins&plugin_status=install 1820 * 1821 * @since 2.5.0 1822 * 1823 * @param string $status Plugin status - either 'install', 'update' or 'activate'. 1824 * 1825 * @return string Properly encoded URL (not escaped). 1826 */ 1827 public function get_buddyforms_members_tgmpa_status_url( $status ) { 1828 return add_query_arg( 1829 array( 1830 'plugin_status' => urlencode( $status ), 1831 ), 1832 $this->get_buddyforms_members_tgmpa_url() 1833 ); 1834 } 1835 1836 /** 1837 * Determine whether there are open actions for plugins registered with TGMPA. 1838 * 1839 * @since 2.5.0 1840 * 1841 * @return bool True if complete, i.e. no outstanding actions. False otherwise. 1842 */ 1843 public function is_buddyforms_members_tgmpa_complete() { 1844 $complete = true; 1845 foreach ( $this->plugins as $slug => $plugin ) { 1846 if ( ! $this->is_plugin_active( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) { 1847 $complete = false; 1848 break; 1849 } 1850 } 1851 1852 return $complete; 1853 } 1854 1855 /** 1856 * Check if a plugin is installed. Does not take must-use plugins into account. 1857 * 1858 * @since 2.5.0 1859 * 1860 * @param string $slug Plugin slug. 1861 * 1862 * @return bool True if installed, false otherwise. 1863 */ 1864 public function is_plugin_installed( $slug ) { 1865 $installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached). 1866 1867 return ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ] ) ); 1868 } 1869 1870 /** 1871 * Check if a plugin is active. 1872 * 1873 * @since 2.5.0 1874 * 1875 * @param string $slug Plugin slug. 1876 * 1877 * @return bool True if active, false otherwise. 1878 */ 1879 public function is_plugin_active( $slug ) { 1880 return ( ( ! empty( $this->plugins[ $slug ]['is_callable'] ) && is_callable( $this->plugins[ $slug ]['is_callable'] ) ) || is_plugin_active( $this->plugins[ $slug ]['file_path'] ) ); 1881 } 1882 1883 /** 1884 * Check if a plugin can be updated, i.e. if we have information on the minimum WP version required 1885 * available, check whether the current install meets them. 1886 * 1887 * @since 2.5.0 1888 * 1889 * @param string $slug Plugin slug. 1890 * 1891 * @return bool True if OK to update, false otherwise. 1892 */ 1893 public function can_plugin_update( $slug ) { 1894 // We currently can't get reliable info on non-WP-repo plugins - issue #380. 1895 if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) { 1896 return true; 1897 } 1898 1899 $api = $this->get_plugins_api( $slug ); 1900 1901 if ( false !== $api && isset( $api->requires ) ) { 1902 return version_compare( $this->wp_version, $api->requires, '>=' ); 1903 } 1904 1905 // No usable info received from the plugins API, presume we can update. 1906 return true; 1907 } 1908 1909 /** 1910 * Check to see if the plugin is 'updatetable', i.e. installed, with an update available 1911 * and no WP version requirements blocking it. 1912 * 1913 * @since 2.6.0 1914 * 1915 * @param string $slug Plugin slug. 1916 * 1917 * @return bool True if OK to proceed with update, false otherwise. 1918 */ 1919 public function is_plugin_updatetable( $slug ) { 1920 if ( ! $this->is_plugin_installed( $slug ) ) { 1921 return false; 1922 } else { 1923 return ( false !== $this->does_plugin_have_update( $slug ) && $this->can_plugin_update( $slug ) ); 1924 } 1925 } 1926 1927 /** 1928 * Check if a plugin can be activated, i.e. is not currently active and meets the minimum 1929 * plugin version requirements set in TGMPA (if any). 1930 * 1931 * @since 2.5.0 1932 * 1933 * @param string $slug Plugin slug. 1934 * 1935 * @return bool True if OK to activate, false otherwise. 1936 */ 1937 public function can_plugin_activate( $slug ) { 1938 return ( ! $this->is_plugin_active( $slug ) && ! $this->does_plugin_require_update( $slug ) ); 1939 } 1940 1941 /** 1942 * Retrieve the version number of an installed plugin. 1943 * 1944 * @since 2.5.0 1945 * 1946 * @param string $slug Plugin slug. 1947 * 1948 * @return string Version number as string or an empty string if the plugin is not installed 1949 * or version unknown (plugins which don't comply with the plugin header standard). 1950 */ 1951 public function get_installed_version( $slug ) { 1952 $installed_plugins = $this->get_plugins(); // Retrieve a list of all installed plugins (WP cached). 1953 1954 if ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version'] ) ) { 1955 return $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version']; 1956 } 1957 1958 return ''; 1959 } 1960 1961 /** 1962 * Check whether a plugin complies with the minimum version requirements. 1963 * 1964 * @since 2.5.0 1965 * 1966 * @param string $slug Plugin slug. 1967 * 1968 * @return bool True when a plugin needs to be updated, otherwise false. 1969 */ 1970 public function does_plugin_require_update( $slug ) { 1971 $installed_version = $this->get_installed_version( $slug ); 1972 $minimum_version = $this->plugins[ $slug ]['version']; 1973 1974 return version_compare( $minimum_version, $installed_version, '>' ); 1975 } 1976 1977 /** 1978 * Check whether there is an update available for a plugin. 1979 * 1980 * @since 2.5.0 1981 * 1982 * @param string $slug Plugin slug. 1983 * 1984 * @return false|string Version number string of the available update or false if no update available. 1985 */ 1986 public function does_plugin_have_update( $slug ) { 1987 // Presume bundled and external plugins will point to a package which meets the minimum required version. 1988 if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) { 1989 if ( $this->does_plugin_require_update( $slug ) ) { 1990 return $this->plugins[ $slug ]['version']; 1991 } 1992 1993 return false; 1994 } 1995 1996 $repo_updates = get_site_transient( 'update_plugins' ); 1997 1998 if ( isset( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version ) ) { 1999 return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version; 2000 } 2001 2002 return false; 2003 } 2004 2005 /** 2006 * Retrieve potential upgrade notice for a plugin. 2007 * 2008 * @since 2.5.0 2009 * 2010 * @param string $slug Plugin slug. 2011 * 2012 * @return string The upgrade notice or an empty string if no message was available or provided. 2013 */ 2014 public function get_upgrade_notice( $slug ) { 2015 // We currently can't get reliable info on non-WP-repo plugins - issue #380. 2016 if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) { 2017 return ''; 2018 } 2019 2020 $repo_updates = get_site_transient( 'update_plugins' ); 2021 2022 if ( ! empty( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice ) ) { 2023 return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice; 2024 } 2025 2026 return ''; 2027 } 2028 2029 /** 2030 * Wrapper around the core WP get_plugins function, making sure it's actually available. 2031 * 2032 * @since 2.5.0 2033 * 2034 * @param string $plugin_folder Optional. Relative path to single plugin folder. 2035 * 2036 * @return array Array of installed plugins with plugin information. 2037 */ 2038 public function get_plugins( $plugin_folder = '' ) { 2039 if ( ! function_exists( 'get_plugins' ) ) { 2040 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 2041 } 2042 2043 return get_plugins( $plugin_folder ); 2044 } 2045 2046 /** 2047 * Delete dismissable nag option when theme is switched. 2048 * 2049 * This ensures that the user(s) is/are again reminded via nag of required 2050 * and/or recommended plugins if they re-activate the theme. 2051 * 2052 * @since 2.1.1 2053 */ 2054 public function update_dismiss() { 2055 delete_metadata( 'user', null, 'buddyforms_members_tgmpa_dismissed_notice_' . $this->id, null, true ); 2056 } 2057 2058 /** 2059 * Forces plugin activation if the parameter 'force_activation' is 2060 * set to true. 2061 * 2062 * This allows theme authors to specify certain plugins that must be 2063 * active at all times while using the current theme. 2064 * 2065 * Please take special care when using this parameter as it has the 2066 * potential to be harmful if not used correctly. Setting this parameter 2067 * to true will not allow the specified plugin to be deactivated unless 2068 * the user switches themes. 2069 * 2070 * @since 2.2.0 2071 */ 2072 public function force_activation() { 2073 foreach ( $this->plugins as $slug => $plugin ) { 2074 if ( true === $plugin['force_activation'] ) { 2075 if ( ! $this->is_plugin_installed( $slug ) ) { 2076 // Oops, plugin isn't there so iterate to next condition. 2077 continue; 2078 } elseif ( $this->can_plugin_activate( $slug ) ) { 2079 // There we go, activate the plugin. 2080 activate_plugin( $plugin['file_path'] ); 2081 } 2082 } 2083 } 2084 } 2085 2086 /** 2087 * Forces plugin deactivation if the parameter 'force_deactivation' 2088 * is set to true and adds the plugin to the 'recently active' plugins list. 2089 * 2090 * This allows theme authors to specify certain plugins that must be 2091 * deactivated upon switching from the current theme to another. 2092 * 2093 * Please take special care when using this parameter as it has the 2094 * potential to be harmful if not used correctly. 2095 * 2096 * @since 2.2.0 2097 */ 2098 public function force_deactivation() { 2099 $deactivated = array(); 2100 2101 foreach ( $this->plugins as $slug => $plugin ) { 2102 /* 2103 * Only proceed forward if the parameter is set to true and plugin is active 2104 * as a 'normal' (not must-use) plugin. 2105 */ 2106 if ( true === $plugin['force_deactivation'] && is_plugin_active( $plugin['file_path'] ) ) { 2107 deactivate_plugins( $plugin['file_path'] ); 2108 $deactivated[ $plugin['file_path'] ] = time(); 2109 } 2110 } 2111 2112 if ( ! empty( $deactivated ) ) { 2113 update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) ); 2114 } 2115 } 2116 2117 /** 2118 * Echo the current TGMPA version number to the page. 2119 * 2120 * @since 2.5.0 2121 */ 2122 public function show_buddyforms_members_tgmpa_version() { 2123 echo '<p style="float: right; padding: 0em 1.5em 0.5em 0;"><strong><small>', 2124 esc_html( 2125 sprintf( 2126 /* translators: %s: version number */ 2127 __( 'TGMPA v%s', 'buddyforms_members_tgmpa' ), 2128 self::TGMPA_VERSION 2129 ) 2130 ), 2131 '</small></strong></p>'; 2132 } 2133 2134 /** 2135 * Returns the singleton instance of the class. 2136 * 2137 * @since 2.4.0 2138 * 2139 * @return \TGM_Plugin_Activation The TGM_Plugin_Activation object. 2140 */ 2141 public static function get_instance() { 2142 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { 2143 self::$instance = new self(); 2144 } 2145 2146 return self::$instance; 2147 } 2148 } 2149 2150 if ( ! function_exists( 'load_tgm_plugin_activation' ) ) { 2151 /** 2152 * Ensure only one instance of the class is ever invoked. 2153 * 2154 * @since 2.5.0 2155 */ 2156 function load_tgm_plugin_activation() { 2157 $GLOBALS['buddyforms_members_tgmpa'] = TGM_Plugin_Activation::get_instance(); 2158 } 2159 } 2160 2161 if ( did_action( 'plugins_loaded' ) ) { 2162 load_tgm_plugin_activation(); 2163 } else { 2164 add_action( 'plugins_loaded', 'load_tgm_plugin_activation' ); 2165 } 2166 } 2167 2168 if ( ! function_exists( 'buddyforms_members_tgmpa' ) ) { 2169 /** 2170 * Helper function to register a collection of required plugins. 2171 * 2172 * @since 2.0.0 2173 * @api 2174 * 2175 * @param array $plugins An array of plugin arrays. 2176 * @param array $config Optional. An array of configuration values. 2177 */ 2178 function buddyforms_members_tgmpa( $plugins, $config = array() ) { 2179 $instance = call_user_func( array( get_class( $GLOBALS['buddyforms_members_tgmpa'] ), 'get_instance' ) ); 2180 2181 foreach ( $plugins as $plugin ) { 2182 call_user_func( array( $instance, 'register' ), $plugin ); 2183 } 2184 2185 if ( ! empty( $config ) && is_array( $config ) ) { 2186 // Send out notices for deprecated arguments passed. 2187 if ( isset( $config['notices'] ) ) { 2188 _deprecated_argument( __FUNCTION__, '2.2.0', 'The `notices` config parameter was renamed to `has_notices` in TGMPA 2.2.0. Please adjust your configuration.' ); 2189 if ( ! isset( $config['has_notices'] ) ) { 2190 $config['has_notices'] = $config['notices']; 2191 } 2192 } 2193 2194 if ( isset( $config['parent_menu_slug'] ) ) { 2195 _deprecated_argument( __FUNCTION__, '2.4.0', 'The `parent_menu_slug` config parameter was removed in TGMPA 2.4.0. In TGMPA 2.5.0 an alternative was (re-)introduced. Please adjust your configuration. For more information visit the website: http://tgmpluginactivation.com/configuration/#h-configuration-options.' ); 2196 } 2197 if ( isset( $config['parent_url_slug'] ) ) { 2198 _deprecated_argument( __FUNCTION__, '2.4.0', 'The `parent_url_slug` config parameter was removed in TGMPA 2.4.0. In TGMPA 2.5.0 an alternative was (re-)introduced. Please adjust your configuration. For more information visit the website: http://tgmpluginactivation.com/configuration/#h-configuration-options.' ); 2199 } 2200 2201 call_user_func( array( $instance, 'config' ), $config ); 2202 } 2203 } 2204 } 2205 2206 /** 2207 * WP_List_Table isn't always available. If it isn't available, 2208 * we load it here. 2209 * 2210 * @since 2.2.0 2211 */ 2212 if ( ! class_exists( 'WP_List_Table' ) ) { 2213 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; 2214 } 2215 2216 if ( ! class_exists( 'TGMPA_List_Table' ) ) { 2217 2218 /** 2219 * List table class for handling plugins. 2220 * 2221 * Extends the WP_List_Table class to provide a future-compatible 2222 * way of listing out all required/recommended plugins. 2223 * 2224 * Gives users an interface similar to the Plugin Administration 2225 * area with similar (albeit stripped down) capabilities. 2226 * 2227 * This class also allows for the bulk install of plugins. 2228 * 2229 * @since 2.2.0 2230 * 2231 * @package TGM-Plugin-Activation 2232 * @author Thomas Griffin 2233 * @author Gary Jones 2234 */ 2235 class TGMPA_List_Table extends WP_List_Table { 2236 /** 2237 * TGMPA instance. 2238 * 2239 * @since 2.5.0 2240 * 2241 * @var object 2242 */ 2243 protected $buddyforms_members_tgmpa; 2244 2245 /** 2246 * The currently chosen view. 2247 * 2248 * @since 2.5.0 2249 * 2250 * @var string One of: 'all', 'install', 'update', 'activate' 2251 */ 2252 public $view_context = 'all'; 2253 2254 /** 2255 * The plugin counts for the various views. 2256 * 2257 * @since 2.5.0 2258 * 2259 * @var array 2260 */ 2261 protected $view_totals = array( 2262 'all' => 0, 2263 'install' => 0, 2264 'update' => 0, 2265 'activate' => 0, 2266 ); 2267 2268 /** 2269 * References parent constructor and sets defaults for class. 2270 * 2271 * @since 2.2.0 2272 */ 2273 public function __construct() { 2274 $this->buddyforms_members_tgmpa = call_user_func( array( get_class( $GLOBALS['buddyforms_members_tgmpa'] ), 'get_instance' ) ); 2275 2276 parent::__construct( 2277 array( 2278 'singular' => 'plugin', 2279 'plural' => 'plugins', 2280 'ajax' => false, 2281 ) 2282 ); 2283 2284 if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 2285 'install', 2286 'update', 2287 'activate' 2288 ), true ) 2289 ) { 2290 $this->view_context = sanitize_key( $_REQUEST['plugin_status'] ); 2291 } 2292 2293 add_filter( 'buddyforms_members_tgmpa_table_data_items', array( $this, 'sort_table_items' ) ); 2294 } 2295 2296 /** 2297 * Get a list of CSS classes for the <table> tag. 2298 * 2299 * Overruled to prevent the 'plural' argument from being added. 2300 * 2301 * @since 2.5.0 2302 * 2303 * @return array CSS classnames. 2304 */ 2305 public function get_table_classes() { 2306 return array( 'widefat', 'fixed' ); 2307 } 2308 2309 /** 2310 * Gathers and renames all of our plugin information to be used by WP_List_Table to create our table. 2311 * 2312 * @since 2.2.0 2313 * 2314 * @return array $table_data Information for use in table. 2315 */ 2316 protected function _gather_plugin_data() { 2317 // Load thickbox for plugin links. 2318 $this->buddyforms_members_tgmpa->admin_init(); 2319 $this->buddyforms_members_tgmpa->thickbox(); 2320 2321 // Categorize the plugins which have open actions. 2322 $plugins = $this->categorize_plugins_to_views(); 2323 2324 // Set the counts for the view links. 2325 $this->set_view_totals( $plugins ); 2326 2327 // Prep variables for use and grab list of all installed plugins. 2328 $table_data = array(); 2329 $i = 0; 2330 2331 // Redirect to the 'all' view if no plugins were found for the selected view context. 2332 if ( empty( $plugins[ $this->view_context ] ) ) { 2333 $this->view_context = 'all'; 2334 } 2335 2336 foreach ( $plugins[ $this->view_context ] as $slug => $plugin ) { 2337 $table_data[ $i ]['sanitized_plugin'] = $plugin['name']; 2338 $table_data[ $i ]['slug'] = $slug; 2339 $table_data[ $i ]['plugin'] = '<strong>' . $this->buddyforms_members_tgmpa->get_info_link( $slug ) . '</strong>'; 2340 $table_data[ $i ]['source'] = $this->get_plugin_source_type_text( $plugin['source_type'] ); 2341 $table_data[ $i ]['type'] = $this->get_plugin_advise_type_text( $plugin['required'] ); 2342 $table_data[ $i ]['status'] = $this->get_plugin_status_text( $slug ); 2343 $table_data[ $i ]['installed_version'] = $this->buddyforms_members_tgmpa->get_installed_version( $slug ); 2344 $table_data[ $i ]['minimum_version'] = $plugin['version']; 2345 $table_data[ $i ]['available_version'] = $this->buddyforms_members_tgmpa->does_plugin_have_update( $slug ); 2346 2347 // Prep the upgrade notice info. 2348 $upgrade_notice = $this->buddyforms_members_tgmpa->get_upgrade_notice( $slug ); 2349 if ( ! empty( $upgrade_notice ) ) { 2350 $table_data[ $i ]['upgrade_notice'] = $upgrade_notice; 2351 2352 add_action( "buddyforms_members_tgmpa_after_plugin_row_{$slug}", array( $this, 'wp_plugin_update_row' ), 10, 2 ); 2353 } 2354 2355 $table_data[ $i ] = apply_filters( 'buddyforms_members_tgmpa_table_data_item', $table_data[ $i ], $plugin ); 2356 2357 $i ++; 2358 } 2359 2360 return $table_data; 2361 } 2362 2363 /** 2364 * Categorize the plugins which have open actions into views for the TGMPA page. 2365 * 2366 * @since 2.5.0 2367 */ 2368 protected function categorize_plugins_to_views() { 2369 $plugins = array( 2370 'all' => array(), // Meaning: all plugins which still have open actions. 2371 'install' => array(), 2372 'update' => array(), 2373 'activate' => array(), 2374 ); 2375 2376 foreach ( $this->buddyforms_members_tgmpa->plugins as $slug => $plugin ) { 2377 if ( $this->buddyforms_members_tgmpa->is_plugin_active( $slug ) && false === $this->buddyforms_members_tgmpa->does_plugin_have_update( $slug ) ) { 2378 // No need to display plugins if they are installed, up-to-date and active. 2379 continue; 2380 } else { 2381 $plugins['all'][ $slug ] = $plugin; 2382 2383 if ( ! $this->buddyforms_members_tgmpa->is_plugin_installed( $slug ) ) { 2384 $plugins['install'][ $slug ] = $plugin; 2385 } else { 2386 if ( false !== $this->buddyforms_members_tgmpa->does_plugin_have_update( $slug ) ) { 2387 $plugins['update'][ $slug ] = $plugin; 2388 } 2389 2390 if ( $this->buddyforms_members_tgmpa->can_plugin_activate( $slug ) ) { 2391 $plugins['activate'][ $slug ] = $plugin; 2392 } 2393 } 2394 } 2395 } 2396 2397 return $plugins; 2398 } 2399 2400 /** 2401 * Set the counts for the view links. 2402 * 2403 * @since 2.5.0 2404 * 2405 * @param array $plugins Plugins order by view. 2406 */ 2407 protected function set_view_totals( $plugins ) { 2408 foreach ( $plugins as $type => $list ) { 2409 $this->view_totals[ $type ] = count( $list ); 2410 } 2411 } 2412 2413 /** 2414 * Get the plugin required/recommended text string. 2415 * 2416 * @since 2.5.0 2417 * 2418 * @param string $required Plugin required setting. 2419 * 2420 * @return string 2421 */ 2422 protected function get_plugin_advise_type_text( $required ) { 2423 if ( true === $required ) { 2424 return __( 'Required', 'buddyforms_members_tgmpa' ); 2425 } 2426 2427 return __( 'Recommended', 'buddyforms_members_tgmpa' ); 2428 } 2429 2430 /** 2431 * Get the plugin source type text string. 2432 * 2433 * @since 2.5.0 2434 * 2435 * @param string $type Plugin type. 2436 * 2437 * @return string 2438 */ 2439 protected function get_plugin_source_type_text( $type ) { 2440 $string = ''; 2441 2442 switch ( $type ) { 2443 case 'repo': 2444 $string = __( 'WordPress Repository', 'buddyforms_members_tgmpa' ); 2445 break; 2446 case 'external': 2447 $string = __( 'External Source', 'buddyforms_members_tgmpa' ); 2448 break; 2449 case 'bundled': 2450 $string = __( 'Pre-Packaged', 'buddyforms_members_tgmpa' ); 2451 break; 2452 } 2453 2454 return $string; 2455 } 2456 2457 /** 2458 * Determine the plugin status message. 2459 * 2460 * @since 2.5.0 2461 * 2462 * @param string $slug Plugin slug. 2463 * 2464 * @return string 2465 */ 2466 protected function get_plugin_status_text( $slug ) { 2467 if ( ! $this->buddyforms_members_tgmpa->is_plugin_installed( $slug ) ) { 2468 return __( 'Not Installed', 'buddyforms_members_tgmpa' ); 2469 } 2470 2471 if ( ! $this->buddyforms_members_tgmpa->is_plugin_active( $slug ) ) { 2472 $install_status = __( 'Installed But Not Activated', 'buddyforms_members_tgmpa' ); 2473 } else { 2474 $install_status = __( 'Active', 'buddyforms_members_tgmpa' ); 2475 } 2476 2477 $update_status = ''; 2478 2479 if ( $this->buddyforms_members_tgmpa->does_plugin_require_update( $slug ) && false === $this->buddyforms_members_tgmpa->does_plugin_have_update( $slug ) ) { 2480 $update_status = __( 'Required Update not Available', 'buddyforms_members_tgmpa' ); 2481 2482 } elseif ( $this->buddyforms_members_tgmpa->does_plugin_require_update( $slug ) ) { 2483 $update_status = __( 'Requires Update', 'buddyforms_members_tgmpa' ); 2484 2485 } elseif ( false !== $this->buddyforms_members_tgmpa->does_plugin_have_update( $slug ) ) { 2486 $update_status = __( 'Update recommended', 'buddyforms_members_tgmpa' ); 2487 } 2488 2489 if ( '' === $update_status ) { 2490 return $install_status; 2491 } 2492 2493 return sprintf( 2494 /* translators: 1: install status, 2: update status */ 2495 _x( '%1$s, %2$s', 'Install/Update Status', 'buddyforms_members_tgmpa' ), 2496 $install_status, 2497 $update_status 2498 ); 2499 } 2500 2501 /** 2502 * Sort plugins by Required/Recommended type and by alphabetical plugin name within each type. 2503 * 2504 * @since 2.5.0 2505 * 2506 * @param array $items Prepared table items. 2507 * 2508 * @return array Sorted table items. 2509 */ 2510 public function sort_table_items( $items ) { 2511 $type = array(); 2512 $name = array(); 2513 2514 foreach ( $items as $i => $plugin ) { 2515 $type[ $i ] = $plugin['type']; // Required / recommended. 2516 $name[ $i ] = $plugin['sanitized_plugin']; 2517 } 2518 2519 array_multisort( $type, SORT_DESC, $name, SORT_ASC, $items ); 2520 2521 return $items; 2522 } 2523 2524 /** 2525 * Get an associative array ( id => link ) of the views available on this table. 2526 * 2527 * @since 2.5.0 2528 * 2529 * @return array 2530 */ 2531 public function get_views() { 2532 $status_links = array(); 2533 2534 foreach ( $this->view_totals as $type => $count ) { 2535 if ( $count < 1 ) { 2536 continue; 2537 } 2538 2539 switch ( $type ) { 2540 case 'all': 2541 /* translators: 1: number of plugins. */ 2542 $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins', 'buddyforms_members_tgmpa' ); 2543 break; 2544 case 'install': 2545 /* translators: 1: number of plugins. */ 2546 $text = _n( 'To Install <span class="count">(%s)</span>', 'To Install <span class="count">(%s)</span>', $count, 'buddyforms_members_tgmpa' ); 2547 break; 2548 case 'update': 2549 /* translators: 1: number of plugins. */ 2550 $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count, 'buddyforms_members_tgmpa' ); 2551 break; 2552 case 'activate': 2553 /* translators: 1: number of plugins. */ 2554 $text = _n( 'To Activate <span class="count">(%s)</span>', 'To Activate <span class="count">(%s)</span>', $count, 'buddyforms_members_tgmpa' ); 2555 break; 2556 default: 2557 $text = ''; 2558 break; 2559 } 2560 2561 if ( ! empty( $text ) ) { 2562 2563 $status_links[ $type ] = sprintf( 2564 '<a href="%s"%s>%s</a>', 2565 esc_url( $this->buddyforms_members_tgmpa->get_buddyforms_members_tgmpa_status_url( $type ) ), 2566 ( $type === $this->view_context ) ? ' class="current"' : '', 2567 sprintf( $text, number_format_i18n( $count ) ) 2568 ); 2569 } 2570 } 2571 2572 return $status_links; 2573 } 2574 2575 /** 2576 * Create default columns to display important plugin information 2577 * like type, action and status. 2578 * 2579 * @since 2.2.0 2580 * 2581 * @param array $item Array of item data. 2582 * @param string $column_name The name of the column. 2583 * 2584 * @return string 2585 */ 2586 public function column_default( $item, $column_name ) { 2587 return $item[ $column_name ]; 2588 } 2589 2590 /** 2591 * Required for bulk installing. 2592 * 2593 * Adds a checkbox for each plugin. 2594 * 2595 * @since 2.2.0 2596 * 2597 * @param array $item Array of item data. 2598 * 2599 * @return string The input checkbox with all necessary info. 2600 */ 2601 public function column_cb( $item ) { 2602 return sprintf( 2603 '<input type="checkbox" name="%1$s[]" value="%2$s" id="%3$s" />', 2604 esc_attr( $this->_args['singular'] ), 2605 esc_attr( $item['slug'] ), 2606 esc_attr( $item['sanitized_plugin'] ) 2607 ); 2608 } 2609 2610 /** 2611 * Create default title column along with the action links. 2612 * 2613 * @since 2.2.0 2614 * 2615 * @param array $item Array of item data. 2616 * 2617 * @return string The plugin name and action links. 2618 */ 2619 public function column_plugin( $item ) { 2620 return sprintf( 2621 '%1$s %2$s', 2622 $item['plugin'], 2623 $this->row_actions( $this->get_row_actions( $item ), true ) 2624 ); 2625 } 2626 2627 /** 2628 * Create version information column. 2629 * 2630 * @since 2.5.0 2631 * 2632 * @param array $item Array of item data. 2633 * 2634 * @return string HTML-formatted version information. 2635 */ 2636 public function column_version( $item ) { 2637 $output = array(); 2638 2639 if ( $this->buddyforms_members_tgmpa->is_plugin_installed( $item['slug'] ) ) { 2640 $installed = ! empty( $item['installed_version'] ) ? $item['installed_version'] : _x( 'unknown', 'as in: "version nr unknown"', 'buddyforms_members_tgmpa' ); 2641 2642 $color = ''; 2643 if ( ! empty( $item['minimum_version'] ) && $this->buddyforms_members_tgmpa->does_plugin_require_update( $item['slug'] ) ) { 2644 $color = ' color: #ff0000; font-weight: bold;'; 2645 } 2646 2647 $output[] = sprintf( 2648 '<p><span style="min-width: 32px; text-align: right; float: right;%1$s">%2$s</span>' . __( 'Installed version:', 'buddyforms_members_tgmpa' ) . '</p>', 2649 $color, 2650 $installed 2651 ); 2652 } 2653 2654 if ( ! empty( $item['minimum_version'] ) ) { 2655 $output[] = sprintf( 2656 '<p><span style="min-width: 32px; text-align: right; float: right;">%1$s</span>' . __( 'Minimum required version:', 'buddyforms_members_tgmpa' ) . '</p>', 2657 $item['minimum_version'] 2658 ); 2659 } 2660 2661 if ( ! empty( $item['available_version'] ) ) { 2662 $color = ''; 2663 if ( ! empty( $item['minimum_version'] ) && version_compare( $item['available_version'], $item['minimum_version'], '>=' ) ) { 2664 $color = ' color: #71C671; font-weight: bold;'; 2665 } 2666 2667 $output[] = sprintf( 2668 '<p><span style="min-width: 32px; text-align: right; float: right;%1$s">%2$s</span>' . __( 'Available version:', 'buddyforms_members_tgmpa' ) . '</p>', 2669 $color, 2670 $item['available_version'] 2671 ); 2672 } 2673 2674 if ( empty( $output ) ) { 2675 return ' '; // Let's not break the table layout. 2676 } else { 2677 return implode( "\n", $output ); 2678 } 2679 } 2680 2681 /** 2682 * Sets default message within the plugins table if no plugins 2683 * are left for interaction. 2684 * 2685 * Hides the menu item to prevent the user from clicking and 2686 * getting a permissions error. 2687 * 2688 * @since 2.2.0 2689 */ 2690 public function no_items() { 2691 echo esc_html__( 'No plugins to install, update or activate.', 'buddyforms_members_tgmpa' ) . ' <a href="' . esc_url( self_admin_url() ) . '"> ' . esc_html__( 'Return to the Dashboard', 'buddyforms_members_tgmpa' ) . '</a>'; 2692 echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>'; 2693 } 2694 2695 /** 2696 * Output all the column information within the table. 2697 * 2698 * @since 2.2.0 2699 * 2700 * @return array $columns The column names. 2701 */ 2702 public function get_columns() { 2703 $columns = array( 2704 'cb' => '<input type="checkbox" />', 2705 'plugin' => __( 'Plugin', 'buddyforms_members_tgmpa' ), 2706 'source' => __( 'Source', 'buddyforms_members_tgmpa' ), 2707 'type' => __( 'Type', 'buddyforms_members_tgmpa' ), 2708 ); 2709 2710 if ( 'all' === $this->view_context || 'update' === $this->view_context ) { 2711 $columns['version'] = __( 'Version', 'buddyforms_members_tgmpa' ); 2712 $columns['status'] = __( 'Status', 'buddyforms_members_tgmpa' ); 2713 } 2714 2715 return apply_filters( 'buddyforms_members_tgmpa_table_columns', $columns ); 2716 } 2717 2718 /** 2719 * Get name of default primary column 2720 * 2721 * @since 2.5.0 / WP 4.3+ compatibility 2722 * @access protected 2723 * 2724 * @return string 2725 */ 2726 protected function get_default_primary_column_name() { 2727 return 'plugin'; 2728 } 2729 2730 /** 2731 * Get the name of the primary column. 2732 * 2733 * @since 2.5.0 / WP 4.3+ compatibility 2734 * @access protected 2735 * 2736 * @return string The name of the primary column. 2737 */ 2738 protected function get_primary_column_name() { 2739 if ( method_exists( 'WP_List_Table', 'get_primary_column_name' ) ) { 2740 return parent::get_primary_column_name(); 2741 } else { 2742 return $this->get_default_primary_column_name(); 2743 } 2744 } 2745 2746 /** 2747 * Get the actions which are relevant for a specific plugin row. 2748 * 2749 * @since 2.5.0 2750 * 2751 * @param array $item Array of item data. 2752 * 2753 * @return array Array with relevant action links. 2754 */ 2755 protected function get_row_actions( $item ) { 2756 $actions = array(); 2757 $action_links = array(); 2758 2759 // Display the 'Install' action link if the plugin is not yet available. 2760 if ( ! $this->buddyforms_members_tgmpa->is_plugin_installed( $item['slug'] ) ) { 2761 /* translators: %2$s: plugin name in screen reader markup */ 2762 $actions['install'] = __( 'Install %2$s', 'buddyforms_members_tgmpa' ); 2763 } else { 2764 // Display the 'Update' action link if an update is available and WP complies with plugin minimum. 2765 if ( false !== $this->buddyforms_members_tgmpa->does_plugin_have_update( $item['slug'] ) && $this->buddyforms_members_tgmpa->can_plugin_update( $item['slug'] ) ) { 2766 /* translators: %2$s: plugin name in screen reader markup */ 2767 $actions['update'] = __( 'Update %2$s', 'buddyforms_members_tgmpa' ); 2768 } 2769 2770 // Display the 'Activate' action link, but only if the plugin meets the minimum version. 2771 if ( $this->buddyforms_members_tgmpa->can_plugin_activate( $item['slug'] ) ) { 2772 /* translators: %2$s: plugin name in screen reader markup */ 2773 $actions['activate'] = __( 'Activate %2$s', 'buddyforms_members_tgmpa' ); 2774 } 2775 } 2776 2777 // Create the actual links. 2778 foreach ( $actions as $action => $text ) { 2779 $nonce_url = wp_nonce_url( 2780 add_query_arg( 2781 array( 2782 'plugin' => urlencode( $item['slug'] ), 2783 'buddyforms_members_tgmpa-' . $action => $action . '-plugin', 2784 ), 2785 $this->buddyforms_members_tgmpa->get_buddyforms_members_tgmpa_url() 2786 ), 2787 'buddyforms_members_tgmpa-' . $action, 2788 'buddyforms_members_tgmpa-nonce' 2789 ); 2790 2791 $action_links[ $action ] = sprintf( 2792 '<a href="%1$s">' . esc_html( $text ) . '</a>', // $text contains the second placeholder. 2793 esc_url( $nonce_url ), 2794 '<span class="screen-reader-text">' . esc_html( $item['sanitized_plugin'] ) . '</span>' 2795 ); 2796 } 2797 2798 $prefix = ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) ? 'network_admin_' : ''; 2799 2800 return apply_filters( "buddyforms_members_tgmpa_{$prefix}plugin_action_links", array_filter( $action_links ), $item['slug'], $item, $this->view_context ); 2801 } 2802 2803 /** 2804 * Generates content for a single row of the table. 2805 * 2806 * @since 2.5.0 2807 * 2808 * @param object $item The current item. 2809 */ 2810 public function single_row( $item ) { 2811 parent::single_row( $item ); 2812 2813 /** 2814 * Fires after each specific row in the TGMPA Plugins list table. 2815 * 2816 * The dynamic portion of the hook name, `$item['slug']`, refers to the slug 2817 * for the plugin. 2818 * 2819 * @since 2.5.0 2820 */ 2821 do_action( "buddyforms_members_tgmpa_after_plugin_row_{$item['slug']}", $item['slug'], $item, $this->view_context ); 2822 } 2823 2824 /** 2825 * Show the upgrade notice below a plugin row if there is one. 2826 * 2827 * @since 2.5.0 2828 * 2829 * @see /wp-admin/includes/update.php 2830 * 2831 * @param string $slug Plugin slug. 2832 * @param array $item The information available in this table row. 2833 * 2834 * @return null Return early if upgrade notice is empty. 2835 */ 2836 public function wp_plugin_update_row( $slug, $item ) { 2837 if ( empty( $item['upgrade_notice'] ) ) { 2838 return; 2839 } 2840 2841 echo ' 22 } protected function do_plugin_install() { if ( empty( $_GET['plugin'] ) ) { return false; } $slug = $this->sanitize_key( urldecode( $_GET['plugin'] ) ); if ( ! isset( $this->plugins[ $slug ] ) ) { return false; } if ( ( isset( $_GET['buddyforms_members_tgmpa-install'] ) && 'install-plugin' === $_GET['buddyforms_members_tgmpa-install'] ) || ( isset( $_GET['buddyforms_members_tgmpa-update'] ) && 'update-plugin' === $_GET['buddyforms_members_tgmpa-update'] ) ) { $install_type = 'install'; if ( isset( $_GET['buddyforms_members_tgmpa-update'] ) && 'update-plugin' === $_GET['buddyforms_members_tgmpa-update'] ) { $install_type = 'update'; } check_admin_referer( 'buddyforms_members_tgmpa-' . $install_type, 'buddyforms_members_tgmpa-nonce' ); $url = wp_nonce_url( add_query_arg( array( 'plugin' => urlencode( $slug ), 'buddyforms_members_tgmpa-' . $install_type => $install_type . '-plugin', ), $this->get_buddyforms_members_tgmpa_url() ), 'buddyforms_members_tgmpa-' . $install_type, 'buddyforms_members_tgmpa-nonce' ); $method = ''; if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, array() ) ) ) { return true; } if ( ! WP_Filesystem( $creds ) ) { request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, array() ); return true; } $extra = array(); $extra['slug'] = $slug; $source = $this->get_download_url( $slug ); $api = ( 'repo' === $this->plugins[ $slug ]['source_type'] ) ? $this->get_plugins_api( $slug ) : null; $api = ( false !== $api ) ? $api : null; $url = add_query_arg( array( 'action' => $install_type . '-plugin', 'plugin' => urlencode( $slug ), ), 'update.php' ); if ( ! class_exists( 'Plugin_Upgrader', false ) ) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; } $title = ( 'update' === $install_type ) ? $this->strings['updating'] : $this->strings['installing']; $skin_args = array( 'type' => ( 'bundled' !== $this->plugins[ $slug ]['source_type'] ) ? 'web' : 'upload', 'title' => sprintf( $title, $this->plugins[ $slug ]['name'] ), 'url' => esc_url_raw( $url ), 'nonce' => $install_type . '-plugin_' . $slug, 'plugin' => '', 'api' => $api, 'extra' => $extra, ); unset( $title ); if ( 'update' === $install_type ) { $skin_args['plugin'] = $this->plugins[ $slug ]['file_path']; $skin = new Plugin_Upgrader_Skin( $skin_args ); } else { $skin = new Plugin_Installer_Skin( $skin_args ); } $upgrader = new Plugin_Upgrader( $skin ); add_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1, 3 ); if ( 'update' === $install_type ) { $to_inject = array( $slug => $this->plugins[ $slug ] ); $to_inject[ $slug ]['source'] = $source; $this->inject_update_info( $to_inject ); $upgrader->upgrade( $this->plugins[ $slug ]['file_path'] ); } else { $upgrader->install( $source ); } remove_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1 ); $this->populate_file_path( $slug ); if ( $this->is_automatic && ! $this->is_plugin_active( $slug ) ) { $plugin_activate = $upgrader->plugin_info(); if ( false === $this->activate_single_plugin( $plugin_activate, $slug, true ) ) { return true; } } $this->show_buddyforms_members_tgmpa_version(); if ( $this->is_buddyforms_members_tgmpa_complete() ) { echo '<p>', sprintf( esc_html( $this->strings['complete'] ), '<a href="' . esc_url( self_admin_url() ) . '">' . esc_html__( 'Return to the Dashboard', 'buddyforms_members_tgmpa' ) . '</a>' ), '</p>'; echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>'; } else { echo '<p><a href="', esc_url( $this->get_buddyforms_members_tgmpa_url() ), '" target="_parent">', esc_html( $this->strings['return'] ), '</a></p>'; } return true; } elseif ( isset( $this->plugins[ $slug ]['file_path'], $_GET['buddyforms_members_tgmpa-activate'] ) && 'activate-plugin' === $_GET['buddyforms_members_tgmpa-activate'] ) { check_admin_referer( 'buddyforms_members_tgmpa-activate', 'buddyforms_members_tgmpa-nonce' ); if ( false === $this->activate_single_plugin( $this->plugins[ $slug ]['file_path'], $slug ) ) { return true; } } return false; } public function inject_update_info( $plugins ) { $repo_updates = get_site_transient( 'update_plugins' ); if ( ! is_object( $repo_updates ) ) { $repo_updates = new stdClass; } foreach ( $plugins as $slug => $plugin ) { $file_path = $plugin['file_path']; if ( empty( $repo_updates->response[ $file_path ] ) ) { $repo_updates->response[ $file_path ] = new stdClass; } $repo_updates->response[ $file_path ]->slug = $slug; $repo_updates->response[ $file_path ]->plugin = $file_path; $repo_updates->response[ $file_path ]->new_version = $plugin['version']; $repo_updates->response[ $file_path ]->package = $plugin['source']; if ( empty( $repo_updates->response[ $file_path ]->url ) && ! empty( $plugin['external_url'] ) ) { $repo_updates->response[ $file_path ]->url = $plugin['external_url']; } } set_site_transient( 'update_plugins', $repo_updates ); } public function maybe_adjust_source_dir( $source, $remote_source, $upgrader ) { if ( ! $this->is_buddyforms_members_tgmpa_page() || ! is_object( $GLOBALS['wp_filesystem'] ) ) { return $source; } $source_files = array_keys( $GLOBALS['wp_filesystem']->dirlist( $remote_source ) ); if ( 1 === count( $source_files ) && false === $GLOBALS['wp_filesystem']->is_dir( $source ) ) { return $source; } $desired_slug = ''; if ( false === $upgrader->bulk && ! empty( $upgrader->skin->options['extra']['slug'] ) ) { $desired_slug = $upgrader->skin->options['extra']['slug']; } else { foreach ( $this->plugins as $slug => $plugin ) { if ( ! empty( $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) && $plugin['name'] === $upgrader->skin->plugin_names[ $upgrader->skin->i ] ) { $desired_slug = $slug; break; } } unset( $slug, $plugin ); } if ( ! empty( $desired_slug ) ) { $subdir_name = untrailingslashit( str_replace( trailingslashit( $remote_source ), '', $source ) ); if ( ! empty( $subdir_name ) && $subdir_name !== $desired_slug ) { $from_path = untrailingslashit( $source ); $to_path = trailingslashit( $remote_source ) . $desired_slug; if ( true === $GLOBALS['wp_filesystem']->move( $from_path, $to_path ) ) { return trailingslashit( $to_path ); } else { return new WP_Error( 'rename_failed', esc_html__( 'The remote plugin package does not contain a folder with the desired slug and renaming did not work.', 'buddyforms_members_tgmpa' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'buddyforms_members_tgmpa' ), array( 'found' => $subdir_name, 'expected' => $desired_slug ) ); } } elseif ( empty( $subdir_name ) ) { return new WP_Error( 'packaged_wrong', esc_html__( 'The remote plugin package consists of more than one file, but the files are not packaged in a folder.', 'buddyforms_members_tgmpa' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'buddyforms_members_tgmpa' ), array( 'found' => $subdir_name, 'expected' => $desired_slug ) ); } } return $source; } protected function activate_single_plugin( $file_path, $slug, $automatic = false ) { if ( $this->can_plugin_activate( $slug ) ) { $activate = activate_plugin( $file_path ); if ( is_wp_error( $activate ) ) { echo '<div id="message" class="error"><p>', wp_kses_post( $activate->get_error_message() ), '</p></div>', '<p><a href="', esc_url( $this->get_buddyforms_members_tgmpa_url() ), '" target="_parent">', esc_html( $this->strings['return'] ), '</a></p>'; return false; } else { if ( ! $automatic ) { if ( ! isset( $_POST['action'] ) ) { echo '<div id="message" class="updated"><p>', esc_html( $this->strings['activated_successfully'] ), ' <strong>', esc_html( $this->plugins[ $slug ]['name'] ), '.</strong></p></div>'; } } else { echo '<p>', esc_html( $this->strings['plugin_activated'] ), '</p>'; } } } elseif ( $this->is_plugin_active( $slug ) ) { echo '<div id="message" class="error"><p>', sprintf( esc_html( $this->strings['plugin_already_active'] ), '<strong>' . esc_html( $this->plugins[ $slug ]['name'] ) . '</strong>' ), '</p></div>'; } elseif ( $this->does_plugin_require_update( $slug ) ) { if ( ! $automatic ) { if ( ! isset( $_POST['action'] ) ) { echo '<div id="message" class="error"><p>', sprintf( esc_html( $this->strings['plugin_needs_higher_version'] ), '<strong>' . esc_html( $this->plugins[ $slug ]['name'] ) . '</strong>' ), '</p></div>'; } } else { echo '<p>', sprintf( esc_html( $this->strings['plugin_needs_higher_version'] ), esc_html( $this->plugins[ $slug ]['name'] ) ), '</p>'; } } return true; } public function notices() { if ( ( $this->is_buddyforms_members_tgmpa_page() || $this->is_core_update_page() ) || get_user_meta( get_current_user_id(), 'buddyforms_members_tgmpa_dismissed_notice_' . $this->id, true ) || ! current_user_can( apply_filters( 'buddyforms_members_tgmpa_show_admin_notice_capability', 'publish_posts' ) ) ) { return; } $message = array(); $install_link_count = 0; $update_link_count = 0; $activate_link_count = 0; $total_required_action_count = 0; foreach ( $this->plugins as $slug => $plugin ) { if ( $this->is_plugin_active( $slug ) && false === $this->does_plugin_have_update( $slug ) ) { continue; } if ( ! $this->is_plugin_installed( $slug ) ) { if ( current_user_can( 'install_plugins' ) ) { $install_link_count ++; if ( true === $plugin['required'] ) { $message['notice_can_install_required'][] = $slug; } else { $message['notice_can_install_recommended'][] = $slug; } } if ( true === $plugin['required'] ) { $total_required_action_count ++; } } else { if ( ! $this->is_plugin_active( $slug ) && $this->can_plugin_activate( $slug ) ) { if ( current_user_can( 'activate_plugins' ) ) { $activate_link_count ++; if ( true === $plugin['required'] ) { $message['notice_can_activate_required'][] = $slug; } else { $message['notice_can_activate_recommended'][] = $slug; } } if ( true === $plugin['required'] ) { $total_required_action_count ++; } } if ( $this->does_plugin_require_update( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) { if ( current_user_can( 'update_plugins' ) ) { $update_link_count ++; if ( $this->does_plugin_require_update( $slug ) ) { $message['notice_ask_to_update'][] = $slug; } elseif ( false !== $this->does_plugin_have_update( $slug ) ) { $message['notice_ask_to_update_maybe'][] = $slug; } } if ( true === $plugin['required'] ) { $total_required_action_count ++; } } } } unset( $slug, $plugin ); if ( ! empty( $message ) || $total_required_action_count > 0 ) { krsort( $message ); $rendered = ''; $line_template = '<span style="display: block; margin: 0.5em 0.5em 0 0; clear: both;">%s</span>' . "\n"; if ( ! current_user_can( 'activate_plugins' ) && ! current_user_can( 'install_plugins' ) && ! current_user_can( 'update_plugins' ) ) { $rendered = esc_html( $this->strings['notice_cannot_install_activate'] ) . ' ' . esc_html( $this->strings['contact_admin'] ); $rendered .= $this->create_user_action_links_for_notice( 0, 0, 0, $line_template ); } else { if ( ! $this->dismissable && ! empty( $this->dismiss_msg ) ) { $rendered .= sprintf( $line_template, wp_kses_post( $this->dismiss_msg ) ); } foreach ( $message as $type => $plugin_group ) { $linked_plugins = array(); foreach ( $plugin_group as $plugin_slug ) { $linked_plugins[] = $this->get_info_link( $plugin_slug ); } unset( $plugin_slug ); $count = count( $plugin_group ); $linked_plugins = array_map( array( 'TGMPA_Utils', 'wrap_in_em' ), $linked_plugins ); $last_plugin = array_pop( $linked_plugins ); $imploded = empty( $linked_plugins ) ? $last_plugin : ( implode( ', ', $linked_plugins ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'buddyforms_members_tgmpa' ) . ' ' . $last_plugin ); $rendered .= sprintf( $line_template, sprintf( translate_nooped_plural( $this->strings[ $type ], $count, 'buddyforms_members_tgmpa' ), $imploded, $count ) ); } unset( $type, $plugin_group, $linked_plugins, $count, $last_plugin, $imploded ); $rendered .= $this->create_user_action_links_for_notice( $install_link_count, $update_link_count, $activate_link_count, $line_template ); } add_settings_error( 'buddyforms_members_tgmpa', 'buddyforms_members_tgmpa', $rendered, $this->get_admin_notice_class() ); } if ( 'options-general' !== $GLOBALS['current_screen']->parent_base ) { $this->display_settings_errors(); } } protected function create_user_action_links_for_notice( $install_count, $update_count, $activate_count, $line_template ) { $action_links = array( 'install' => '', 'update' => '', 'activate' => '', 'dismiss' => $this->dismissable ? '<a href="' . esc_url( wp_nonce_url( add_query_arg( 'buddyforms_members_tgmpa-dismiss', 'dismiss_admin_notices' ), 'buddyforms_members_tgmpa-dismiss-' . get_current_user_id() ) ) . '" class="dismiss-notice" target="_parent">' . esc_html( $this->strings['dismiss'] ) . '</a>' : '', ); $link_template = '<a href="%2$s">%1$s</a>'; if ( current_user_can( 'install_plugins' ) ) { if ( $install_count > 0 ) { $action_links['install'] = sprintf( $link_template, translate_nooped_plural( $this->strings['install_link'], $install_count, 'buddyforms_members_tgmpa' ), esc_url( $this->get_buddyforms_members_tgmpa_status_url( 'install' ) ) ); } if ( $update_count > 0 ) { $action_links['update'] = sprintf( $link_template, translate_nooped_plural( $this->strings['update_link'], $update_count, 'buddyforms_members_tgmpa' ), esc_url( $this->get_buddyforms_members_tgmpa_status_url( 'update' ) ) ); } } if ( current_user_can( 'activate_plugins' ) && $activate_count > 0 ) { $action_links['activate'] = sprintf( $link_template, translate_nooped_plural( $this->strings['activate_link'], $activate_count, 'buddyforms_members_tgmpa' ), esc_url( $this->get_buddyforms_members_tgmpa_status_url( 'activate' ) ) ); } $action_links = apply_filters( 'buddyforms_members_tgmpa_notice_action_links', $action_links ); $action_links = array_filter( (array) $action_links ); if ( ! empty( $action_links ) ) { $action_links = sprintf( $line_template, implode( ' | ', $action_links ) ); return apply_filters( 'buddyforms_members_tgmpa_notice_rendered_action_links', $action_links ); } else { return ''; } } protected function get_admin_notice_class() { if ( ! empty( $this->strings['nag_type'] ) ) { return sanitize_html_class( strtolower( $this->strings['nag_type'] ) ); } else { if ( version_compare( $this->wp_version, '4.2', '>=' ) ) { return 'notice-warning'; } elseif ( version_compare( $this->wp_version, '4.1', '>=' ) ) { return 'notice'; } else { return 'updated'; } } } protected function display_settings_errors() { global $wp_settings_errors; settings_errors( 'buddyforms_members_tgmpa' ); foreach ( (array) $wp_settings_errors as $key => $details ) { if ( 'buddyforms_members_tgmpa' === $details['setting'] ) { unset( $wp_settings_errors[ $key ] ); break; } } } public function dismiss() { if ( isset( $_GET['buddyforms_members_tgmpa-dismiss'] ) && check_admin_referer( 'buddyforms_members_tgmpa-dismiss-' . get_current_user_id() ) ) { update_user_meta( get_current_user_id(), 'buddyforms_members_tgmpa_dismissed_notice_' . $this->id, 1 ); } } public function register( $plugin ) { if ( empty( $plugin['slug'] ) || empty( $plugin['name'] ) ) { return; } if ( empty( $plugin['slug'] ) || ! is_string( $plugin['slug'] ) || isset( $this->plugins[ $plugin['slug'] ] ) ) { return; } $defaults = array( 'name' => '', 'slug' => '', 'source' => 'repo', 'required' => false, 'version' => '', 'force_activation' => false, 'force_deactivation' => false, 'external_url' => '', 'is_callable' => '', ); $plugin = wp_parse_args( $plugin, $defaults ); $plugin['slug'] = $this->sanitize_key( $plugin['slug'] ); $plugin['version'] = (string) $plugin['version']; $plugin['source'] = empty( $plugin['source'] ) ? 'repo' : $plugin['source']; $plugin['required'] = TGMPA_Utils::validate_bool( $plugin['required'] ); $plugin['force_activation'] = TGMPA_Utils::validate_bool( $plugin['force_activation'] ); $plugin['force_deactivation'] = TGMPA_Utils::validate_bool( $plugin['force_deactivation'] ); $plugin['file_path'] = $this->_get_plugin_basename_from_slug( $plugin['slug'] ); $plugin['source_type'] = $this->get_plugin_source_type( $plugin['source'] ); $this->plugins[ $plugin['slug'] ] = $plugin; $this->sort_order[ $plugin['slug'] ] = $plugin['name']; if ( true === $plugin['force_activation'] ) { $this->has_forced_activation = true; } if ( true === $plugin['force_deactivation'] ) { $this->has_forced_deactivation = true; } } protected function get_plugin_source_type( $source ) { if ( 'repo' === $source || preg_match( self::WP_REPO_REGEX, $source ) ) { return 'repo'; } elseif ( preg_match( self::IS_URL_REGEX, $source ) ) { return 'external'; } else { return 'bundled'; } } public function sanitize_key( $key ) { $raw_key = $key; $key = preg_replace( '`[^A-Za-z0-9_-]`', '', $key ); return apply_filters( 'buddyforms_members_tgmpa_sanitize_key', $key, $raw_key ); } public function config( $config ) { $keys = array( 'id', 'default_path', 'has_notices', 'dismissable', 'dismiss_msg', 'menu', 'parent_slug', 'capability', 'is_automatic', 'message', 'strings', ); foreach ( $keys as $key ) { if ( isset( $config[ $key ] ) ) { if ( is_array( $config[ $key ] ) ) { $this->$key = array_merge( $this->$key, $config[ $key ] ); } else { $this->$key = $config[ $key ]; } } } } public function actions( $install_actions ) { if ( $this->is_buddyforms_members_tgmpa_page() ) { return false; } return $install_actions; } public function flush_plugins_cache( $clear_update_cache = true ) { wp_clean_plugins_cache( $clear_update_cache ); } public function populate_file_path( $plugin_slug = '' ) { if ( ! empty( $plugin_slug ) && is_string( $plugin_slug ) && isset( $this->plugins[ $plugin_slug ] ) ) { $this->plugins[ $plugin_slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $plugin_slug ); } else { foreach ( $this->plugins as $slug => $values ) { $this->plugins[ $slug ]['file_path'] = $this->_get_plugin_basename_from_slug( $slug ); } } } protected function _get_plugin_basename_from_slug( $slug ) { $keys = array_keys( $this->get_plugins() ); foreach ( $keys as $key ) { if ( preg_match( '|^' . $slug . '/|', $key ) ) { return $key; } } return $slug; } public function _get_plugin_data_from_name( $name, $data = 'slug' ) { foreach ( $this->plugins as $values ) { if ( $name === $values['name'] && isset( $values[ $data ] ) ) { return $values[ $data ]; } } return false; } public function get_download_url( $slug ) { $dl_source = ''; switch ( $this->plugins[ $slug ]['source_type'] ) { case 'repo': return $this->get_wp_repo_download_url( $slug ); case 'external': return $this->plugins[ $slug ]['source']; case 'bundled': return $this->default_path . $this->plugins[ $slug ]['source']; } return $dl_source; } protected function get_wp_repo_download_url( $slug ) { $source = ''; $api = $this->get_plugins_api( $slug ); if ( false !== $api && isset( $api->download_link ) ) { $source = $api->download_link; } return $source; } protected function get_plugins_api( $slug ) { static $api = array(); if ( ! isset( $api[ $slug ] ) ) { if ( ! function_exists( 'plugins_api' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; } $response = plugins_api( 'plugin_information', array( 'slug' => $slug, 'fields' => array( 'sections' => false ) ) ); $api[ $slug ] = false; if ( is_wp_error( $response ) ) { wp_die( esc_html( $this->strings['oops'] ) ); } else { $api[ $slug ] = $response; } } return $api[ $slug ]; } public function get_info_link( $slug ) { if ( ! empty( $this->plugins[ $slug ]['external_url'] ) && preg_match( self::IS_URL_REGEX, $this->plugins[ $slug ]['external_url'] ) ) { $link = sprintf( '<a href="%1$s" target="_blank">%2$s</a>', esc_url( $this->plugins[ $slug ]['external_url'] ), esc_html( $this->plugins[ $slug ]['name'] ) ); } elseif ( 'repo' === $this->plugins[ $slug ]['source_type'] ) { $url = add_query_arg( array( 'tab' => 'plugin-information', 'plugin' => urlencode( $slug ), 'TB_iframe' => 'true', 'width' => '640', 'height' => '500', ), self_admin_url( 'plugin-install.php' ) ); $link = sprintf( '<a href="%1$s" class="thickbox">%2$s</a>', esc_url( $url ), esc_html( $this->plugins[ $slug ]['name'] ) ); } else { $link = esc_html( $this->plugins[ $slug ]['name'] ); } return $link; } protected function is_buddyforms_members_tgmpa_page() { return isset( $_GET['page'] ) && $this->menu === $_GET['page']; } protected function is_core_update_page() { if ( ! function_exists( 'get_current_screen' ) ) { return false; } $screen = get_current_screen(); if ( 'update-core' === $screen->base ) { return true; } elseif ( 'plugins' === $screen->base && ! empty( $_POST['action'] ) ) { return true; } elseif ( 'update' === $screen->base && ! empty( $_POST['action'] ) ) { return true; } return false; } public function get_buddyforms_members_tgmpa_url() { static $url; if ( ! isset( $url ) ) { $parent = $this->parent_slug; if ( false === strpos( $parent, '.php' ) ) { $parent = 'admin.php'; } $url = add_query_arg( array( 'page' => urlencode( $this->menu ), ), self_admin_url( $parent ) ); } return $url; } public function get_buddyforms_members_tgmpa_status_url( $status ) { return add_query_arg( array( 'plugin_status' => urlencode( $status ), ), $this->get_buddyforms_members_tgmpa_url() ); } public function is_buddyforms_members_tgmpa_complete() { $complete = true; foreach ( $this->plugins as $slug => $plugin ) { if ( ! $this->is_plugin_active( $slug ) || false !== $this->does_plugin_have_update( $slug ) ) { $complete = false; break; } } return $complete; } public function is_plugin_installed( $slug ) { $installed_plugins = $this->get_plugins(); return ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ] ) ); } public function is_plugin_active( $slug ) { return ( ( ! empty( $this->plugins[ $slug ]['is_callable'] ) && is_callable( $this->plugins[ $slug ]['is_callable'] ) ) || is_plugin_active( $this->plugins[ $slug ]['file_path'] ) ); } public function can_plugin_update( $slug ) { if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) { return true; } $api = $this->get_plugins_api( $slug ); if ( false !== $api && isset( $api->requires ) ) { return version_compare( $this->wp_version, $api->requires, '>=' ); } return true; } public function is_plugin_updatetable( $slug ) { if ( ! $this->is_plugin_installed( $slug ) ) { return false; } else { return ( false !== $this->does_plugin_have_update( $slug ) && $this->can_plugin_update( $slug ) ); } } public function can_plugin_activate( $slug ) { return ( ! $this->is_plugin_active( $slug ) && ! $this->does_plugin_require_update( $slug ) ); } public function get_installed_version( $slug ) { $installed_plugins = $this->get_plugins(); if ( ! empty( $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version'] ) ) { return $installed_plugins[ $this->plugins[ $slug ]['file_path'] ]['Version']; } return ''; } public function does_plugin_require_update( $slug ) { $installed_version = $this->get_installed_version( $slug ); $minimum_version = $this->plugins[ $slug ]['version']; return version_compare( $minimum_version, $installed_version, '>' ); } public function does_plugin_have_update( $slug ) { if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) { if ( $this->does_plugin_require_update( $slug ) ) { return $this->plugins[ $slug ]['version']; } return false; } $repo_updates = get_site_transient( 'update_plugins' ); if ( isset( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version ) ) { return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->new_version; } return false; } public function get_upgrade_notice( $slug ) { if ( 'repo' !== $this->plugins[ $slug ]['source_type'] ) { return ''; } $repo_updates = get_site_transient( 'update_plugins' ); if ( ! empty( $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice ) ) { return $repo_updates->response[ $this->plugins[ $slug ]['file_path'] ]->upgrade_notice; } return ''; } public function get_plugins( $plugin_folder = '' ) { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } return get_plugins( $plugin_folder ); } public function update_dismiss() { delete_metadata( 'user', null, 'buddyforms_members_tgmpa_dismissed_notice_' . $this->id, null, true ); } public function force_activation() { foreach ( $this->plugins as $slug => $plugin ) { if ( true === $plugin['force_activation'] ) { if ( ! $this->is_plugin_installed( $slug ) ) { continue; } elseif ( $this->can_plugin_activate( $slug ) ) { activate_plugin( $plugin['file_path'] ); } } } } public function force_deactivation() { $deactivated = array(); foreach ( $this->plugins as $slug => $plugin ) { if ( true === $plugin['force_deactivation'] && is_plugin_active( $plugin['file_path'] ) ) { deactivate_plugins( $plugin['file_path'] ); $deactivated[ $plugin['file_path'] ] = time(); } } if ( ! empty( $deactivated ) ) { update_option( 'recently_activated', $deactivated + (array) get_option( 'recently_activated' ) ); } } public function show_buddyforms_members_tgmpa_version() { echo '<p style="float: right; padding: 0em 1.5em 0.5em 0;"><strong><small>', esc_html( sprintf( __( 'TGMPA v%s', 'buddyforms_members_tgmpa' ), self::TGMPA_VERSION ) ), '</small></strong></p>'; } public static function get_instance() { if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::$instance = new self(); } return self::$instance; } } if ( ! function_exists( 'load_tgm_plugin_activation' ) ) { function load_tgm_plugin_activation() { $GLOBALS['buddyforms_members_tgmpa'] = TGM_Plugin_Activation::get_instance(); } } if ( did_action( 'plugins_loaded' ) ) { load_tgm_plugin_activation(); } else { add_action( 'plugins_loaded', 'load_tgm_plugin_activation' ); } } if ( ! function_exists( 'buddyforms_members_tgmpa' ) ) { function buddyforms_members_tgmpa( $plugins, $config = array() ) { $instance = call_user_func( array( get_class( $GLOBALS['buddyforms_members_tgmpa'] ), 'get_instance' ) ); foreach ( $plugins as $plugin ) { call_user_func( array( $instance, 'register' ), $plugin ); } if ( ! empty( $config ) && is_array( $config ) ) { if ( isset( $config['notices'] ) ) { _deprecated_argument( __FUNCTION__, '2.2.0', 'The `notices` config parameter was renamed to `has_notices` in TGMPA 2.2.0. Please adjust your configuration.' ); if ( ! isset( $config['has_notices'] ) ) { $config['has_notices'] = $config['notices']; } } if ( isset( $config['parent_menu_slug'] ) ) { _deprecated_argument( __FUNCTION__, '2.4.0', 'The `parent_menu_slug` config parameter was removed in TGMPA 2.4.0. In TGMPA 2.5.0 an alternative was (re-)introduced. Please adjust your configuration. For more information visit the website: http://tgmpluginactivation.com/configuration/#h-configuration-options.' ); } if ( isset( $config['parent_url_slug'] ) ) { _deprecated_argument( __FUNCTION__, '2.4.0', 'The `parent_url_slug` config parameter was removed in TGMPA 2.4.0. In TGMPA 2.5.0 an alternative was (re-)introduced. Please adjust your configuration. For more information visit the website: http://tgmpluginactivation.com/configuration/#h-configuration-options.' ); } call_user_func( array( $instance, 'config' ), $config ); } } } if ( ! class_exists( 'WP_List_Table' ) ) { require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; } if ( ! class_exists( 'TGMPA_List_Table' ) ) { class TGMPA_List_Table extends WP_List_Table { protected $buddyforms_members_tgmpa; public $view_context = 'all'; protected $view_totals = array( 'all' => 0, 'install' => 0, 'update' => 0, 'activate' => 0, ); public function __construct() { $this->buddyforms_members_tgmpa = call_user_func( array( get_class( $GLOBALS['buddyforms_members_tgmpa'] ), 'get_instance' ) ); parent::__construct( array( 'singular' => 'plugin', 'plural' => 'plugins', 'ajax' => false, ) ); if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'install', 'update', 'activate' ), true ) ) { $this->view_context = sanitize_key( $_REQUEST['plugin_status'] ); } add_filter( 'buddyforms_members_tgmpa_table_data_items', array( $this, 'sort_table_items' ) ); } public function get_table_classes() { return array( 'widefat', 'fixed' ); } protected function _gather_plugin_data() { $this->buddyforms_members_tgmpa->admin_init(); $this->buddyforms_members_tgmpa->thickbox(); $plugins = $this->categorize_plugins_to_views(); $this->set_view_totals( $plugins ); $table_data = array(); $i = 0; if ( empty( $plugins[ $this->view_context ] ) ) { $this->view_context = 'all'; } foreach ( $plugins[ $this->view_context ] as $slug => $plugin ) { $table_data[ $i ]['sanitized_plugin'] = $plugin['name']; $table_data[ $i ]['slug'] = $slug; $table_data[ $i ]['plugin'] = '<strong>' . $this->buddyforms_members_tgmpa->get_info_link( $slug ) . '</strong>'; $table_data[ $i ]['source'] = $this->get_plugin_source_type_text( $plugin['source_type'] ); $table_data[ $i ]['type'] = $this->get_plugin_advise_type_text( $plugin['required'] ); $table_data[ $i ]['status'] = $this->get_plugin_status_text( $slug ); $table_data[ $i ]['installed_version'] = $this->buddyforms_members_tgmpa->get_installed_version( $slug ); $table_data[ $i ]['minimum_version'] = $plugin['version']; $table_data[ $i ]['available_version'] = $this->buddyforms_members_tgmpa->does_plugin_have_update( $slug ); $upgrade_notice = $this->buddyforms_members_tgmpa->get_upgrade_notice( $slug ); if ( ! empty( $upgrade_notice ) ) { $table_data[ $i ]['upgrade_notice'] = $upgrade_notice; add_action( "buddyforms_members_tgmpa_after_plugin_row_{$slug}", array( $this, 'wp_plugin_update_row' ), 10, 2 ); } $table_data[ $i ] = apply_filters( 'buddyforms_members_tgmpa_table_data_item', $table_data[ $i ], $plugin ); $i ++; } return $table_data; } protected function categorize_plugins_to_views() { $plugins = array( 'all' => array(), 'install' => array(), 'update' => array(), 'activate' => array(), ); foreach ( $this->buddyforms_members_tgmpa->plugins as $slug => $plugin ) { if ( $this->buddyforms_members_tgmpa->is_plugin_active( $slug ) && false === $this->buddyforms_members_tgmpa->does_plugin_have_update( $slug ) ) { continue; } else { $plugins['all'][ $slug ] = $plugin; if ( ! $this->buddyforms_members_tgmpa->is_plugin_installed( $slug ) ) { $plugins['install'][ $slug ] = $plugin; } else { if ( false !== $this->buddyforms_members_tgmpa->does_plugin_have_update( $slug ) ) { $plugins['update'][ $slug ] = $plugin; } if ( $this->buddyforms_members_tgmpa->can_plugin_activate( $slug ) ) { $plugins['activate'][ $slug ] = $plugin; } } } } return $plugins; } protected function set_view_totals( $plugins ) { foreach ( $plugins as $type => $list ) { $this->view_totals[ $type ] = count( $list ); } } protected function get_plugin_advise_type_text( $required ) { if ( true === $required ) { return __( 'Required', 'buddyforms_members_tgmpa' ); } return __( 'Recommended', 'buddyforms_members_tgmpa' ); } protected function get_plugin_source_type_text( $type ) { $string = ''; switch ( $type ) { case 'repo': $string = __( 'WordPress Repository', 'buddyforms_members_tgmpa' ); break; case 'external': $string = __( 'External Source', 'buddyforms_members_tgmpa' ); break; case 'bundled': $string = __( 'Pre-Packaged', 'buddyforms_members_tgmpa' ); break; } return $string; } protected function get_plugin_status_text( $slug ) { if ( ! $this->buddyforms_members_tgmpa->is_plugin_installed( $slug ) ) { return __( 'Not Installed', 'buddyforms_members_tgmpa' ); } if ( ! $this->buddyforms_members_tgmpa->is_plugin_active( $slug ) ) { $install_status = __( 'Installed But Not Activated', 'buddyforms_members_tgmpa' ); } else { $install_status = __( 'Active', 'buddyforms_members_tgmpa' ); } $update_status = ''; if ( $this->buddyforms_members_tgmpa->does_plugin_require_update( $slug ) && false === $this->buddyforms_members_tgmpa->does_plugin_have_update( $slug ) ) { $update_status = __( 'Required Update not Available', 'buddyforms_members_tgmpa' ); } elseif ( $this->buddyforms_members_tgmpa->does_plugin_require_update( $slug ) ) { $update_status = __( 'Requires Update', 'buddyforms_members_tgmpa' ); } elseif ( false !== $this->buddyforms_members_tgmpa->does_plugin_have_update( $slug ) ) { $update_status = __( 'Update recommended', 'buddyforms_members_tgmpa' ); } if ( '' === $update_status ) { return $install_status; } return sprintf( _x( '%1$s, %2$s', 'Install/Update Status', 'buddyforms_members_tgmpa' ), $install_status, $update_status ); } public function sort_table_items( $items ) { $type = array(); $name = array(); foreach ( $items as $i => $plugin ) { $type[ $i ] = $plugin['type']; $name[ $i ] = $plugin['sanitized_plugin']; } array_multisort( $type, SORT_DESC, $name, SORT_ASC, $items ); return $items; } public function get_views() { $status_links = array(); foreach ( $this->view_totals as $type => $count ) { if ( $count < 1 ) { continue; } switch ( $type ) { case 'all': $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins', 'buddyforms_members_tgmpa' ); break; case 'install': $text = _n( 'To Install <span class="count">(%s)</span>', 'To Install <span class="count">(%s)</span>', $count, 'buddyforms_members_tgmpa' ); break; case 'update': $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count, 'buddyforms_members_tgmpa' ); break; case 'activate': $text = _n( 'To Activate <span class="count">(%s)</span>', 'To Activate <span class="count">(%s)</span>', $count, 'buddyforms_members_tgmpa' ); break; default: $text = ''; break; } if ( ! empty( $text ) ) { $status_links[ $type ] = sprintf( '<a href="%s"%s>%s</a>', esc_url( $this->buddyforms_members_tgmpa->get_buddyforms_members_tgmpa_status_url( $type ) ), ( $type === $this->view_context ) ? ' class="current"' : '', sprintf( $text, number_format_i18n( $count ) ) ); } } return $status_links; } public function column_default( $item, $column_name ) { return $item[ $column_name ]; } public function column_cb( $item ) { return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" id="%3$s" />', esc_attr( $this->_args['singular'] ), esc_attr( $item['slug'] ), esc_attr( $item['sanitized_plugin'] ) ); } public function column_plugin( $item ) { return sprintf( '%1$s %2$s', $item['plugin'], $this->row_actions( $this->get_row_actions( $item ), true ) ); } public function column_version( $item ) { $output = array(); if ( $this->buddyforms_members_tgmpa->is_plugin_installed( $item['slug'] ) ) { $installed = ! empty( $item['installed_version'] ) ? $item['installed_version'] : _x( 'unknown', 'as in: "version nr unknown"', 'buddyforms_members_tgmpa' ); $color = ''; if ( ! empty( $item['minimum_version'] ) && $this->buddyforms_members_tgmpa->does_plugin_require_update( $item['slug'] ) ) { $color = ' color: #ff0000; font-weight: bold;'; } $output[] = sprintf( '<p><span style="min-width: 32px; text-align: right; float: right;%1$s">%2$s</span>' . __( 'Installed version:', 'buddyforms_members_tgmpa' ) . '</p>', $color, $installed ); } if ( ! empty( $item['minimum_version'] ) ) { $output[] = sprintf( '<p><span style="min-width: 32px; text-align: right; float: right;">%1$s</span>' . __( 'Minimum required version:', 'buddyforms_members_tgmpa' ) . '</p>', $item['minimum_version'] ); } if ( ! empty( $item['available_version'] ) ) { $color = ''; if ( ! empty( $item['minimum_version'] ) && version_compare( $item['available_version'], $item['minimum_version'], '>=' ) ) { $color = ' color: #71C671; font-weight: bold;'; } $output[] = sprintf( '<p><span style="min-width: 32px; text-align: right; float: right;%1$s">%2$s</span>' . __( 'Available version:', 'buddyforms_members_tgmpa' ) . '</p>', $color, $item['available_version'] ); } if ( empty( $output ) ) { return ' '; } else { return implode( "\n", $output ); } } public function no_items() { echo esc_html__( 'No plugins to install, update or activate.', 'buddyforms_members_tgmpa' ) . ' <a href="' . esc_url( self_admin_url() ) . '"> ' . esc_html__( 'Return to the Dashboard', 'buddyforms_members_tgmpa' ) . '</a>'; echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>'; } public function get_columns() { $columns = array( 'cb' => '<input type="checkbox" />', 'plugin' => __( 'Plugin', 'buddyforms_members_tgmpa' ), 'source' => __( 'Source', 'buddyforms_members_tgmpa' ), 'type' => __( 'Type', 'buddyforms_members_tgmpa' ), ); if ( 'all' === $this->view_context || 'update' === $this->view_context ) { $columns['version'] = __( 'Version', 'buddyforms_members_tgmpa' ); $columns['status'] = __( 'Status', 'buddyforms_members_tgmpa' ); } return apply_filters( 'buddyforms_members_tgmpa_table_columns', $columns ); } protected function get_default_primary_column_name() { return 'plugin'; } protected function get_primary_column_name() { if ( method_exists( 'WP_List_Table', 'get_primary_column_name' ) ) { return parent::get_primary_column_name(); } else { return $this->get_default_primary_column_name(); } } protected function get_row_actions( $item ) { $actions = array(); $action_links = array(); if ( ! $this->buddyforms_members_tgmpa->is_plugin_installed( $item['slug'] ) ) { $actions['install'] = __( 'Install %2$s', 'buddyforms_members_tgmpa' ); } else { if ( false !== $this->buddyforms_members_tgmpa->does_plugin_have_update( $item['slug'] ) && $this->buddyforms_members_tgmpa->can_plugin_update( $item['slug'] ) ) { $actions['update'] = __( 'Update %2$s', 'buddyforms_members_tgmpa' ); } if ( $this->buddyforms_members_tgmpa->can_plugin_activate( $item['slug'] ) ) { $actions['activate'] = __( 'Activate %2$s', 'buddyforms_members_tgmpa' ); } } foreach ( $actions as $action => $text ) { $nonce_url = wp_nonce_url( add_query_arg( array( 'plugin' => urlencode( $item['slug'] ), 'buddyforms_members_tgmpa-' . $action => $action . '-plugin', ), $this->buddyforms_members_tgmpa->get_buddyforms_members_tgmpa_url() ), 'buddyforms_members_tgmpa-' . $action, 'buddyforms_members_tgmpa-nonce' ); $action_links[ $action ] = sprintf( '<a href="%1$s">' . esc_html( $text ) . '</a>', esc_url( $nonce_url ), '<span class="screen-reader-text">' . esc_html( $item['sanitized_plugin'] ) . '</span>' ); } $prefix = ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) ? 'network_admin_' : ''; return apply_filters( "buddyforms_members_tgmpa_{$prefix}plugin_action_links", array_filter( $action_links ), $item['slug'], $item, $this->view_context ); } public function single_row( $item ) { parent::single_row( $item ); do_action( "buddyforms_members_tgmpa_after_plugin_row_{$item['slug']}", $item['slug'], $item, $this->view_context ); } public function wp_plugin_update_row( $slug, $item ) { if ( empty( $item['upgrade_notice'] ) ) { return; } echo ' 2842 23 <tr class="plugin-update-tr"> 2843 24 <td colspan="', absint( $this->get_column_count() ), '" class="plugin-update colspanchange"> 2844 <div class="update-message">', 2845 esc_html__( 'Upgrade message from the plugin author:', 'buddyforms_members_tgmpa' ), 2846 ' <strong>', wp_kses_data( $item['upgrade_notice'] ), '</strong> 25 <div class="update-message">', esc_html__( 'Upgrade message from the plugin author:', 'buddyforms_members_tgmpa' ), ' <strong>', wp_kses_data( $item['upgrade_notice'] ), '</strong> 2847 26 </div> 2848 27 </td> 2849 </tr>'; 2850 } 2851 2852 /** 2853 * Extra controls to be displayed between bulk actions and pagination. 2854 * 2855 * @since 2.5.0 2856 * 2857 * @param string $which 'top' or 'bottom' table navigation. 2858 */ 2859 public function extra_tablenav( $which ) { 2860 if ( 'bottom' === $which ) { 2861 $this->buddyforms_members_tgmpa->show_buddyforms_members_tgmpa_version(); 2862 } 2863 } 2864 2865 /** 2866 * Defines the bulk actions for handling registered plugins. 2867 * 2868 * @since 2.2.0 2869 * 2870 * @return array $actions The bulk actions for the plugin install table. 2871 */ 2872 public function get_bulk_actions() { 2873 2874 $actions = array(); 2875 2876 if ( 'update' !== $this->view_context && 'activate' !== $this->view_context ) { 2877 if ( current_user_can( 'install_plugins' ) ) { 2878 $actions['buddyforms_members_tgmpa-bulk-install'] = __( 'Install', 'buddyforms_members_tgmpa' ); 2879 } 2880 } 2881 2882 if ( 'install' !== $this->view_context ) { 2883 if ( current_user_can( 'update_plugins' ) ) { 2884 $actions['buddyforms_members_tgmpa-bulk-update'] = __( 'Update', 'buddyforms_members_tgmpa' ); 2885 } 2886 if ( current_user_can( 'activate_plugins' ) ) { 2887 $actions['buddyforms_members_tgmpa-bulk-activate'] = __( 'Activate', 'buddyforms_members_tgmpa' ); 2888 } 2889 } 2890 2891 return $actions; 2892 } 2893 2894 /** 2895 * Processes bulk installation and activation actions. 2896 * 2897 * The bulk installation process looks for the $_POST information and passes that 2898 * through if a user has to use WP_Filesystem to enter their credentials. 2899 * 2900 * @since 2.2.0 2901 */ 2902 public function process_bulk_actions() { 2903 // Bulk installation process. 2904 if ( 'buddyforms_members_tgmpa-bulk-install' === $this->current_action() || 'buddyforms_members_tgmpa-bulk-update' === $this->current_action() ) { 2905 2906 check_admin_referer( 'bulk-' . $this->_args['plural'] ); 2907 2908 $install_type = 'install'; 2909 if ( 'buddyforms_members_tgmpa-bulk-update' === $this->current_action() ) { 2910 $install_type = 'update'; 2911 } 2912 2913 $plugins_to_install = array(); 2914 2915 // Did user actually select any plugins to install/update ? 2916 if ( empty( $_POST['plugin'] ) ) { 2917 if ( 'install' === $install_type ) { 2918 $message = __( 'No plugins were selected to be installed. No action taken.', 'buddyforms_members_tgmpa' ); 2919 } else { 2920 $message = __( 'No plugins were selected to be updated. No action taken.', 'buddyforms_members_tgmpa' ); 2921 } 2922 2923 echo '<div id="message" class="error"><p>', esc_html( $message ), '</p></div>'; 2924 2925 return false; 2926 } 2927 2928 if ( is_array( $_POST['plugin'] ) ) { 2929 $plugins_to_install = (array) $_POST['plugin']; 2930 } elseif ( is_string( $_POST['plugin'] ) ) { 2931 // Received via Filesystem page - un-flatten array (WP bug #19643). 2932 $plugins_to_install = explode( ',', $_POST['plugin'] ); 2933 } 2934 2935 // Sanitize the received input. 2936 $plugins_to_install = array_map( 'urldecode', $plugins_to_install ); 2937 $plugins_to_install = array_map( array( $this->buddyforms_members_tgmpa, 'sanitize_key' ), $plugins_to_install ); 2938 2939 // Validate the received input. 2940 foreach ( $plugins_to_install as $key => $slug ) { 2941 // Check if the plugin was registered with TGMPA and remove if not. 2942 if ( ! isset( $this->buddyforms_members_tgmpa->plugins[ $slug ] ) ) { 2943 unset( $plugins_to_install[ $key ] ); 2944 continue; 2945 } 2946 2947 // For install: make sure this is a plugin we *can* install and not one already installed. 2948 if ( 'install' === $install_type && true === $this->buddyforms_members_tgmpa->is_plugin_installed( $slug ) ) { 2949 unset( $plugins_to_install[ $key ] ); 2950 } 2951 2952 // For updates: make sure this is a plugin we *can* update (update available and WP version ok). 2953 if ( 'update' === $install_type && false === $this->buddyforms_members_tgmpa->is_plugin_updatetable( $slug ) ) { 2954 unset( $plugins_to_install[ $key ] ); 2955 } 2956 } 2957 2958 // No need to proceed further if we have no plugins to handle. 2959 if ( empty( $plugins_to_install ) ) { 2960 if ( 'install' === $install_type ) { 2961 $message = __( 'No plugins are available to be installed at this time.', 'buddyforms_members_tgmpa' ); 2962 } else { 2963 $message = __( 'No plugins are available to be updated at this time.', 'buddyforms_members_tgmpa' ); 2964 } 2965 2966 echo '<div id="message" class="error"><p>', esc_html( $message ), '</p></div>'; 2967 2968 return false; 2969 } 2970 2971 // Pass all necessary information if WP_Filesystem is needed. 2972 $url = wp_nonce_url( 2973 $this->buddyforms_members_tgmpa->get_buddyforms_members_tgmpa_url(), 2974 'bulk-' . $this->_args['plural'] 2975 ); 2976 2977 // Give validated data back to $_POST which is the only place the filesystem looks for extra fields. 2978 $_POST['plugin'] = implode( ',', $plugins_to_install ); // Work around for WP bug #19643. 2979 2980 $method = ''; // Leave blank so WP_Filesystem can populate it as necessary. 2981 $fields = array_keys( $_POST ); // Extra fields to pass to WP_Filesystem. 2982 2983 if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, $fields ) ) ) { 2984 return true; // Stop the normal page form from displaying, credential request form will be shown. 2985 } 2986 2987 // Now we have some credentials, setup WP_Filesystem. 2988 if ( ! WP_Filesystem( $creds ) ) { 2989 // Our credentials were no good, ask the user for them again. 2990 request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, $fields ); 2991 2992 return true; 2993 } 2994 2995 /* If we arrive here, we have the filesystem */ 2996 2997 // Store all information in arrays since we are processing a bulk installation. 2998 $names = array(); 2999 $sources = array(); // Needed for installs. 3000 $file_paths = array(); // Needed for upgrades. 3001 $to_inject = array(); // Information to inject into the update_plugins transient. 3002 3003 // Prepare the data for validated plugins for the install/upgrade. 3004 foreach ( $plugins_to_install as $slug ) { 3005 $name = $this->buddyforms_members_tgmpa->plugins[ $slug ]['name']; 3006 $source = $this->buddyforms_members_tgmpa->get_download_url( $slug ); 3007 3008 if ( ! empty( $name ) && ! empty( $source ) ) { 3009 $names[] = $name; 3010 3011 switch ( $install_type ) { 3012 3013 case 'install': 3014 $sources[] = $source; 3015 break; 3016 3017 case 'update': 3018 $file_paths[] = $this->buddyforms_members_tgmpa->plugins[ $slug ]['file_path']; 3019 $to_inject[ $slug ] = $this->buddyforms_members_tgmpa->plugins[ $slug ]; 3020 $to_inject[ $slug ]['source'] = $source; 3021 break; 3022 } 3023 } 3024 } 3025 unset( $slug, $name, $source ); 3026 3027 // Create a new instance of TGMPA_Bulk_Installer. 3028 $installer = new TGMPA_Bulk_Installer( 3029 new TGMPA_Bulk_Installer_Skin( 3030 array( 3031 'url' => esc_url_raw( $this->buddyforms_members_tgmpa->get_buddyforms_members_tgmpa_url() ), 3032 'nonce' => 'bulk-' . $this->_args['plural'], 3033 'names' => $names, 3034 'install_type' => $install_type, 3035 ) 3036 ) 3037 ); 3038 3039 // Wrap the install process with the appropriate HTML. 3040 echo '<div class="buddyforms_members_tgmpa">', 3041 '<h2 style="font-size: 23px; font-weight: 400; line-height: 29px; margin: 0; padding: 9px 15px 4px 0;">', esc_html( get_admin_page_title() ), '</h2> 3042 <div class="update-php" style="width: 100%; height: 98%; min-height: 850px; padding-top: 1px;">'; 3043 3044 // Process the bulk installation submissions. 3045 add_filter( 'upgrader_source_selection', array( $this->buddyforms_members_tgmpa, 'maybe_adjust_source_dir' ), 1, 3 ); 3046 3047 if ( 'buddyforms_members_tgmpa-bulk-update' === $this->current_action() ) { 3048 // Inject our info into the update transient. 3049 $this->buddyforms_members_tgmpa->inject_update_info( $to_inject ); 3050 3051 $installer->bulk_upgrade( $file_paths ); 3052 } else { 3053 $installer->bulk_install( $sources ); 3054 } 3055 3056 remove_filter( 'upgrader_source_selection', array( $this->buddyforms_members_tgmpa, 'maybe_adjust_source_dir' ), 1 ); 3057 3058 echo '</div></div>'; 3059 3060 return true; 3061 } 3062 3063 // Bulk activation process. 3064 if ( 'buddyforms_members_tgmpa-bulk-activate' === $this->current_action() ) { 3065 check_admin_referer( 'bulk-' . $this->_args['plural'] ); 3066 3067 // Did user actually select any plugins to activate ? 3068 if ( empty( $_POST['plugin'] ) ) { 3069 echo '<div id="message" class="error"><p>', esc_html__( 'No plugins were selected to be activated. No action taken.', 'buddyforms_members_tgmpa' ), '</p></div>'; 3070 3071 return false; 3072 } 3073 3074 // Grab plugin data from $_POST. 3075 $plugins = array(); 3076 if ( isset( $_POST['plugin'] ) ) { 3077 $plugins = array_map( 'urldecode', (array) $_POST['plugin'] ); 3078 $plugins = array_map( array( $this->buddyforms_members_tgmpa, 'sanitize_key' ), $plugins ); 3079 } 3080 3081 $plugins_to_activate = array(); 3082 $plugin_names = array(); 3083 3084 // Grab the file paths for the selected & inactive plugins from the registration array. 3085 foreach ( $plugins as $slug ) { 3086 if ( $this->buddyforms_members_tgmpa->can_plugin_activate( $slug ) ) { 3087 $plugins_to_activate[] = $this->buddyforms_members_tgmpa->plugins[ $slug ]['file_path']; 3088 $plugin_names[] = $this->buddyforms_members_tgmpa->plugins[ $slug ]['name']; 3089 } 3090 } 3091 unset( $slug ); 3092 3093 // Return early if there are no plugins to activate. 3094 if ( empty( $plugins_to_activate ) ) { 3095 echo '<div id="message" class="error"><p>', esc_html__( 'No plugins are available to be activated at this time.', 'buddyforms_members_tgmpa' ), '</p></div>'; 3096 3097 return false; 3098 } 3099 3100 // Now we are good to go - let's start activating plugins. 3101 $activate = activate_plugins( $plugins_to_activate ); 3102 3103 if ( is_wp_error( $activate ) ) { 3104 echo '<div id="message" class="error"><p>', wp_kses_post( $activate->get_error_message() ), '</p></div>'; 3105 } else { 3106 $count = count( $plugin_names ); // Count so we can use _n function. 3107 $plugin_names = array_map( array( 'TGMPA_Utils', 'wrap_in_strong' ), $plugin_names ); 3108 $last_plugin = array_pop( $plugin_names ); // Pop off last name to prep for readability. 3109 $imploded = empty( $plugin_names ) ? $last_plugin : ( implode( ', ', $plugin_names ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'buddyforms_members_tgmpa' ) . ' ' . $last_plugin ); 3110 3111 printf( // WPCS: xss ok. 3112 '<div id="message" class="updated"><p>%1$s %2$s.</p></div>', 3113 esc_html( _n( 'The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, 'buddyforms_members_tgmpa' ) ), 3114 $imploded 3115 ); 3116 3117 // Update recently activated plugins option. 3118 $recent = (array) get_option( 'recently_activated' ); 3119 foreach ( $plugins_to_activate as $plugin => $time ) { 3120 if ( isset( $recent[ $plugin ] ) ) { 3121 unset( $recent[ $plugin ] ); 3122 } 3123 } 3124 update_option( 'recently_activated', $recent ); 3125 } 3126 3127 unset( $_POST ); // Reset the $_POST variable in case user wants to perform one action after another. 3128 3129 return true; 3130 } 3131 3132 return false; 3133 } 3134 3135 /** 3136 * Prepares all of our information to be outputted into a usable table. 3137 * 3138 * @since 2.2.0 3139 */ 3140 public function prepare_items() { 3141 $columns = $this->get_columns(); // Get all necessary column information. 3142 $hidden = array(); // No columns to hide, but we must set as an array. 3143 $sortable = array(); // No reason to make sortable columns. 3144 $primary = $this->get_primary_column_name(); // Column which has the row actions. 3145 $this->_column_headers = array( 3146 $columns, 3147 $hidden, 3148 $sortable, 3149 $primary 3150 ); // Get all necessary column headers. 3151 3152 // Process our bulk activations here. 3153 if ( 'buddyforms_members_tgmpa-bulk-activate' === $this->current_action() ) { 3154 $this->process_bulk_actions(); 3155 } 3156 3157 // Store all of our plugin data into $items array so WP_List_Table can use it. 3158 $this->items = apply_filters( 'buddyforms_members_tgmpa_table_data_items', $this->_gather_plugin_data() ); 3159 } 3160 3161 /* *********** DEPRECATED METHODS *********** */ 3162 3163 /** 3164 * Retrieve plugin data, given the plugin name. 3165 * 3166 * @since 2.2.0 3167 * @deprecated 2.5.0 use {@see TGM_Plugin_Activation::_get_plugin_data_from_name()} instead. 3168 * @see TGM_Plugin_Activation::_get_plugin_data_from_name() 3169 * 3170 * @param string $name Name of the plugin, as it was registered. 3171 * @param string $data Optional. Array key of plugin data to return. Default is slug. 3172 * 3173 * @return string|boolean Plugin slug if found, false otherwise. 3174 */ 3175 protected function _get_plugin_data_from_name( $name, $data = 'slug' ) { 3176 _deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'TGM_Plugin_Activation::_get_plugin_data_from_name()' ); 3177 3178 return $this->buddyforms_members_tgmpa->_get_plugin_data_from_name( $name, $data ); 3179 } 3180 } 3181 } 3182 3183 3184 if ( ! class_exists( 'TGM_Bulk_Installer' ) ) { 3185 3186 /** 3187 * Hack: Prevent TGMPA v2.4.1- bulk installer class from being loaded if 2.4.1- is loaded after 2.5+. 3188 * 3189 * @since 2.5.2 3190 * 3191 * {@internal The TGMPA_Bulk_Installer class was originally called TGM_Bulk_Installer. 3192 * For more information, see that class.}} 3193 */ 3194 class TGM_Bulk_Installer { 3195 } 3196 } 3197 if ( ! class_exists( 'TGM_Bulk_Installer_Skin' ) ) { 3198 3199 /** 3200 * Hack: Prevent TGMPA v2.4.1- bulk installer skin class from being loaded if 2.4.1- is loaded after 2.5+. 3201 * 3202 * @since 2.5.2 3203 * 3204 * {@internal The TGMPA_Bulk_Installer_Skin class was originally called TGM_Bulk_Installer_Skin. 3205 * For more information, see that class.}} 3206 */ 3207 class TGM_Bulk_Installer_Skin { 3208 } 3209 } 3210 3211 /** 3212 * The WP_Upgrader file isn't always available. If it isn't available, 3213 * we load it here. 3214 * 3215 * We check to make sure no action or activation keys are set so that WordPress 3216 * does not try to re-include the class when processing upgrades or installs outside 3217 * of the class. 3218 * 3219 * @since 2.2.0 3220 */ 3221 add_action( 'admin_init', 'buddyforms_members_tgmpa_load_bulk_installer' ); 3222 if ( ! function_exists( 'buddyforms_members_tgmpa_load_bulk_installer' ) ) { 3223 /** 3224 * Load bulk installer 3225 */ 3226 function buddyforms_members_tgmpa_load_bulk_installer() { 3227 // Silently fail if 2.5+ is loaded *after* an older version. 3228 if ( ! isset( $GLOBALS['buddyforms_members_tgmpa'] ) ) { 3229 return; 3230 } 3231 3232 // Get TGMPA class instance. 3233 $buddyforms_members_tgmpa_instance = call_user_func( array( get_class( $GLOBALS['buddyforms_members_tgmpa'] ), 'get_instance' ) ); 3234 3235 if ( isset( $_GET['page'] ) && $buddyforms_members_tgmpa_instance->menu === $_GET['page'] ) { 3236 if ( ! class_exists( 'Plugin_Upgrader', false ) ) { 3237 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 3238 } 3239 3240 if ( ! class_exists( 'TGMPA_Bulk_Installer' ) ) { 3241 3242 /** 3243 * Installer class to handle bulk plugin installations. 3244 * 3245 * Extends WP_Upgrader and customizes to suit the installation of multiple 3246 * plugins. 3247 * 3248 * @since 2.2.0 3249 * 3250 * {@internal Since 2.5.0 the class is an extension of Plugin_Upgrader rather than WP_Upgrader.}} 3251 * {@internal Since 2.5.2 the class has been renamed from TGM_Bulk_Installer to TGMPA_Bulk_Installer. 3252 * This was done to prevent backward compatibility issues with v2.3.6.}} 3253 * 3254 * @package TGM-Plugin-Activation 3255 * @author Thomas Griffin 3256 * @author Gary Jones 3257 */ 3258 class TGMPA_Bulk_Installer extends Plugin_Upgrader { 3259 /** 3260 * Holds result of bulk plugin installation. 3261 * 3262 * @since 2.2.0 3263 * 3264 * @var string 3265 */ 3266 public $result; 3267 3268 /** 3269 * Flag to check if bulk installation is occurring or not. 3270 * 3271 * @since 2.2.0 3272 * 3273 * @var boolean 3274 */ 3275 public $bulk = false; 3276 3277 /** 3278 * TGMPA instance 3279 * 3280 * @since 2.5.0 3281 * 3282 * @var object 3283 */ 3284 protected $buddyforms_members_tgmpa; 3285 3286 /** 3287 * Whether or not the destination directory needs to be cleared ( = on update). 3288 * 3289 * @since 2.5.0 3290 * 3291 * @var bool 3292 */ 3293 protected $clear_destination = false; 3294 3295 /** 3296 * References parent constructor and sets defaults for class. 3297 * 3298 * @since 2.2.0 3299 * 3300 * @param \Bulk_Upgrader_Skin|null $skin Installer skin. 3301 */ 3302 public function __construct( $skin = null ) { 3303 // Get TGMPA class instance. 3304 $this->buddyforms_members_tgmpa = call_user_func( array( get_class( $GLOBALS['buddyforms_members_tgmpa'] ), 'get_instance' ) ); 3305 3306 parent::__construct( $skin ); 3307 3308 if ( isset( $this->skin->options['install_type'] ) && 'update' === $this->skin->options['install_type'] ) { 3309 $this->clear_destination = true; 3310 } 3311 3312 if ( $this->buddyforms_members_tgmpa->is_automatic ) { 3313 $this->activate_strings(); 3314 } 3315 3316 add_action( 'upgrader_process_complete', array( $this->buddyforms_members_tgmpa, 'populate_file_path' ) ); 3317 } 3318 3319 /** 3320 * Sets the correct activation strings for the installer skin to use. 3321 * 3322 * @since 2.2.0 3323 */ 3324 public function activate_strings() { 3325 $this->strings['activation_failed'] = __( 'Plugin activation failed.', 'buddyforms_members_tgmpa' ); 3326 $this->strings['activation_success'] = __( 'Plugin activated successfully.', 'buddyforms_members_tgmpa' ); 3327 } 3328 3329 /** 3330 * Performs the actual installation of each plugin. 3331 * 3332 * @since 2.2.0 3333 * 3334 * @see WP_Upgrader::run() 3335 * 3336 * @param array $options The installation config options. 3337 * 3338 * @return null|array Return early if error, array of installation data on success. 3339 */ 3340 public function run( $options ) { 3341 $result = parent::run( $options ); 3342 3343 // Reset the strings in case we changed one during automatic activation. 3344 if ( $this->buddyforms_members_tgmpa->is_automatic ) { 3345 if ( 'update' === $this->skin->options['install_type'] ) { 3346 $this->upgrade_strings(); 3347 } else { 3348 $this->install_strings(); 3349 } 3350 } 3351 3352 return $result; 3353 } 3354 3355 /** 3356 * Processes the bulk installation of plugins. 3357 * 3358 * @since 2.2.0 3359 * 3360 * {@internal This is basically a near identical copy of the WP Core 3361 * Plugin_Upgrader::bulk_upgrade() method, with minor adjustments to deal with 3362 * new installs instead of upgrades. 3363 * For ease of future synchronizations, the adjustments are clearly commented, but no other 3364 * comments are added. Code style has been made to comply.}} 3365 * 3366 * @see Plugin_Upgrader::bulk_upgrade() 3367 * @see https://core.trac.wordpress.org/browser/tags/4.2.1/src/wp-admin/includes/class-wp-upgrader.php#L838 3368 * (@internal Last synced: Dec 31st 2015 against https://core.trac.wordpress.org/browser/trunk?rev=36134}} 3369 * 3370 * @param array $plugins The plugin sources needed for installation. 3371 * @param array $args Arbitrary passed extra arguments. 3372 * 3373 * @return array|false Install confirmation messages on success, false on failure. 3374 */ 3375 public function bulk_install( $plugins, $args = array() ) { 3376 // [TGMPA + ] Hook auto-activation in. 3377 add_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 ); 3378 3379 $defaults = array( 3380 'clear_update_cache' => true, 3381 ); 3382 $parsed_args = wp_parse_args( $args, $defaults ); 3383 3384 $this->init(); 3385 $this->bulk = true; 3386 3387 $this->install_strings(); // [TGMPA + ] adjusted. 3388 3389 /* [TGMPA - ] $current = get_site_transient( 'update_plugins' ); */ 3390 3391 /* [TGMPA - ] add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4); */ 3392 3393 $this->skin->header(); 3394 3395 // Connect to the Filesystem first. 3396 $res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) ); 3397 if ( ! $res ) { 3398 $this->skin->footer(); 3399 3400 return false; 3401 } 3402 3403 $this->skin->bulk_header(); 3404 3405 /* 3406 * Only start maintenance mode if: 3407 * - running Multisite and there are one or more plugins specified, OR 3408 * - a plugin with an update available is currently active. 3409 * @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible. 3410 */ 3411 $maintenance = ( is_multisite() && ! empty( $plugins ) ); 3412 3413 /* 3414 [TGMPA - ] 3415 foreach ( $plugins as $plugin ) 3416 $maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin] ) ); 3417 */ 3418 if ( $maintenance ) { 3419 $this->maintenance_mode( true ); 3420 } 3421 3422 $results = array(); 3423 3424 $this->update_count = count( $plugins ); 3425 $this->update_current = 0; 3426 foreach ( $plugins as $plugin ) { 3427 $this->update_current ++; 3428 3429 /* 3430 [TGMPA - ] 3431 $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true); 3432 3433 if ( !isset( $current->response[ $plugin ] ) ) { 3434 $this->skin->set_result('up_to_date'); 3435 $this->skin->before(); 3436 $this->skin->feedback('up_to_date'); 3437 $this->skin->after(); 3438 $results[$plugin] = true; 3439 continue; 3440 } 3441 3442 // Get the URL to the zip file. 3443 $r = $current->response[ $plugin ]; 3444 3445 $this->skin->plugin_active = is_plugin_active($plugin); 3446 */ 3447 3448 $result = $this->run( 3449 array( 3450 'package' => $plugin, // [TGMPA + ] adjusted. 3451 'destination' => WP_PLUGIN_DIR, 3452 'clear_destination' => false, // [TGMPA + ] adjusted. 3453 'clear_working' => true, 3454 'is_multi' => true, 3455 'hook_extra' => array( 3456 'plugin' => $plugin, 3457 ), 3458 ) 3459 ); 3460 3461 $results[ $plugin ] = $this->result; 3462 3463 // Prevent credentials auth screen from displaying multiple times. 3464 if ( false === $result ) { 3465 break; 3466 } 3467 } //end foreach $plugins 3468 3469 $this->maintenance_mode( false ); 3470 3471 /** 3472 * Fires when the bulk upgrader process is complete. 3473 * 3474 * @since WP 3.6.0 / TGMPA 2.5.0 3475 * 3476 * @param Plugin_Upgrader $this Plugin_Upgrader instance. In other contexts, $this, might 3477 * be a Theme_Upgrader or Core_Upgrade instance. 3478 * @param array $data { 3479 * Array of bulk item update data. 3480 * 3481 * @type string $action Type of action. Default 'update'. 3482 * @type string $type Type of update process. Accepts 'plugin', 'theme', or 'core'. 3483 * @type bool $bulk Whether the update process is a bulk update. Default true. 3484 * @type array $packages Array of plugin, theme, or core packages to update. 3485 * } 3486 */ 3487 do_action( 'upgrader_process_complete', $this, array( 3488 'action' => 'install', // [TGMPA + ] adjusted. 3489 'type' => 'plugin', 3490 'bulk' => true, 3491 'plugins' => $plugins, 3492 ) ); 3493 3494 $this->skin->bulk_footer(); 3495 3496 $this->skin->footer(); 3497 3498 // Cleanup our hooks, in case something else does a upgrade on this connection. 3499 /* [TGMPA - ] remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin')); */ 3500 3501 // [TGMPA + ] Remove our auto-activation hook. 3502 remove_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 ); 3503 3504 // Force refresh of plugin update information. 3505 wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); 3506 3507 return $results; 3508 } 3509 3510 /** 3511 * Handle a bulk upgrade request. 3512 * 3513 * @since 2.5.0 3514 * 3515 * @see Plugin_Upgrader::bulk_upgrade() 3516 * 3517 * @param array $plugins The local WP file_path's of the plugins which should be upgraded. 3518 * @param array $args Arbitrary passed extra arguments. 3519 * 3520 * @return string|bool Install confirmation messages on success, false on failure. 3521 */ 3522 public function bulk_upgrade( $plugins, $args = array() ) { 3523 3524 add_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 ); 3525 3526 $result = parent::bulk_upgrade( $plugins, $args ); 3527 3528 remove_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 ); 3529 3530 return $result; 3531 } 3532 3533 /** 3534 * Abuse a filter to auto-activate plugins after installation. 3535 * 3536 * Hooked into the 'upgrader_post_install' filter hook. 3537 * 3538 * @since 2.5.0 3539 * 3540 * @param bool $bool The value we need to give back (true). 3541 * 3542 * @return bool 3543 */ 3544 public function auto_activate( $bool ) { 3545 // Only process the activation of installed plugins if the automatic flag is set to true. 3546 if ( $this->buddyforms_members_tgmpa->is_automatic ) { 3547 // Flush plugins cache so the headers of the newly installed plugins will be read correctly. 3548 wp_clean_plugins_cache(); 3549 3550 // Get the installed plugin file. 3551 $plugin_info = $this->plugin_info(); 3552 3553 // Don't try to activate on upgrade of active plugin as WP will do this already. 3554 if ( ! is_plugin_active( $plugin_info ) ) { 3555 $activate = activate_plugin( $plugin_info ); 3556 3557 // Adjust the success string based on the activation result. 3558 $this->strings['process_success'] = $this->strings['process_success'] . "<br />\n"; 3559 3560 if ( is_wp_error( $activate ) ) { 3561 $this->skin->error( $activate ); 3562 $this->strings['process_success'] .= $this->strings['activation_failed']; 3563 } else { 3564 $this->strings['process_success'] .= $this->strings['activation_success']; 3565 } 3566 } 3567 } 3568 3569 return $bool; 3570 } 3571 } 3572 } 3573 3574 if ( ! class_exists( 'TGMPA_Bulk_Installer_Skin' ) ) { 3575 3576 /** 3577 * Installer skin to set strings for the bulk plugin installations.. 3578 * 3579 * Extends Bulk_Upgrader_Skin and customizes to suit the installation of multiple 3580 * plugins. 3581 * 3582 * @since 2.2.0 3583 * 3584 * {@internal Since 2.5.2 the class has been renamed from TGM_Bulk_Installer_Skin to 3585 * TGMPA_Bulk_Installer_Skin. 3586 * This was done to prevent backward compatibility issues with v2.3.6.}} 3587 * 3588 * @see https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/class-wp-upgrader-skins.php 3589 * 3590 * @package TGM-Plugin-Activation 3591 * @author Thomas Griffin 3592 * @author Gary Jones 3593 */ 3594 class TGMPA_Bulk_Installer_Skin extends Bulk_Upgrader_Skin { 3595 /** 3596 * Holds plugin info for each individual plugin installation. 3597 * 3598 * @since 2.2.0 3599 * 3600 * @var array 3601 */ 3602 public $plugin_info = array(); 3603 3604 /** 3605 * Holds names of plugins that are undergoing bulk installations. 3606 * 3607 * @since 2.2.0 3608 * 3609 * @var array 3610 */ 3611 public $plugin_names = array(); 3612 3613 /** 3614 * Integer to use for iteration through each plugin installation. 3615 * 3616 * @since 2.2.0 3617 * 3618 * @var integer 3619 */ 3620 public $i = 0; 3621 3622 /** 3623 * TGMPA instance 3624 * 3625 * @since 2.5.0 3626 * 3627 * @var object 3628 */ 3629 protected $buddyforms_members_tgmpa; 3630 3631 /** 3632 * Constructor. Parses default args with new ones and extracts them for use. 3633 * 3634 * @since 2.2.0 3635 * 3636 * @param array $args Arguments to pass for use within the class. 3637 */ 3638 public function __construct( $args = array() ) { 3639 // Get TGMPA class instance. 3640 $this->buddyforms_members_tgmpa = call_user_func( array( get_class( $GLOBALS['buddyforms_members_tgmpa'] ), 'get_instance' ) ); 3641 3642 // Parse default and new args. 3643 $defaults = array( 3644 'url' => '', 3645 'nonce' => '', 3646 'names' => array(), 3647 'install_type' => 'install', 3648 ); 3649 $args = wp_parse_args( $args, $defaults ); 3650 3651 // Set plugin names to $this->plugin_names property. 3652 $this->plugin_names = $args['names']; 3653 3654 // Extract the new args. 3655 parent::__construct( $args ); 3656 } 3657 3658 /** 3659 * Sets install skin strings for each individual plugin. 3660 * 3661 * Checks to see if the automatic activation flag is set and uses the 3662 * the proper strings accordingly. 3663 * 3664 * @since 2.2.0 3665 */ 3666 public function add_strings() { 3667 if ( 'update' === $this->options['install_type'] ) { 3668 parent::add_strings(); 3669 /* translators: 1: plugin name, 2: action number 3: total number of actions. */ 3670 $this->upgrader->strings['skin_before_update_header'] = __( 'Updating Plugin %1$s (%2$d/%3$d)', 'buddyforms_members_tgmpa' ); 3671 } else { 3672 /* translators: 1: plugin name, 2: error message. */ 3673 $this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while installing %1$s: <strong>%2$s</strong>.', 'buddyforms_members_tgmpa' ); 3674 /* translators: 1: plugin name. */ 3675 $this->upgrader->strings['skin_update_failed'] = __( 'The installation of %1$s failed.', 'buddyforms_members_tgmpa' ); 3676 3677 if ( $this->buddyforms_members_tgmpa->is_automatic ) { 3678 // Automatic activation strings. 3679 $this->upgrader->strings['skin_upgrade_start'] = __( 'The installation and activation process is starting. This process may take a while on some hosts, so please be patient.', 'buddyforms_members_tgmpa' ); 3680 /* translators: 1: plugin name. */ 3681 $this->upgrader->strings['skin_update_successful'] = __( '%1$s installed and activated successfully.', 'buddyforms_members_tgmpa' ) . ' <a href="#" class="hide-if-no-js" onclick="%2$s"><span>' . esc_html__( 'Show Details', 'buddyforms_members_tgmpa' ) . '</span><span class="hidden">' . esc_html__( 'Hide Details', 'buddyforms_members_tgmpa' ) . '</span>.</a>'; 3682 $this->upgrader->strings['skin_upgrade_end'] = __( 'All installations and activations have been completed.', 'buddyforms_members_tgmpa' ); 3683 /* translators: 1: plugin name, 2: action number 3: total number of actions. */ 3684 $this->upgrader->strings['skin_before_update_header'] = __( 'Installing and Activating Plugin %1$s (%2$d/%3$d)', 'buddyforms_members_tgmpa' ); 3685 } else { 3686 // Default installation strings. 3687 $this->upgrader->strings['skin_upgrade_start'] = __( 'The installation process is starting. This process may take a while on some hosts, so please be patient.', 'buddyforms_members_tgmpa' ); 3688 /* translators: 1: plugin name. */ 3689 $this->upgrader->strings['skin_update_successful'] = esc_html__( '%1$s installed successfully.', 'buddyforms_members_tgmpa' ) . ' <a href="#" class="hide-if-no-js" onclick="%2$s"><span>' . esc_html__( 'Show Details', 'buddyforms_members_tgmpa' ) . '</span><span class="hidden">' . esc_html__( 'Hide Details', 'buddyforms_members_tgmpa' ) . '</span>.</a>'; 3690 $this->upgrader->strings['skin_upgrade_end'] = __( 'All installations have been completed.', 'buddyforms_members_tgmpa' ); 3691 /* translators: 1: plugin name, 2: action number 3: total number of actions. */ 3692 $this->upgrader->strings['skin_before_update_header'] = __( 'Installing Plugin %1$s (%2$d/%3$d)', 'buddyforms_members_tgmpa' ); 3693 } 3694 } 3695 } 3696 3697 /** 3698 * Outputs the header strings and necessary JS before each plugin installation. 3699 * 3700 * @since 2.2.0 3701 * 3702 * @param string $title Unused in this implementation. 3703 */ 3704 public function before( $title = '' ) { 3705 if ( empty( $title ) ) { 3706 $title = esc_html( $this->plugin_names[ $this->i ] ); 3707 } 3708 parent::before( $title ); 3709 } 3710 3711 /** 3712 * Outputs the footer strings and necessary JS after each plugin installation. 3713 * 3714 * Checks for any errors and outputs them if they exist, else output 3715 * success strings. 3716 * 3717 * @since 2.2.0 3718 * 3719 * @param string $title Unused in this implementation. 3720 */ 3721 public function after( $title = '' ) { 3722 if ( empty( $title ) ) { 3723 $title = esc_html( $this->plugin_names[ $this->i ] ); 3724 } 3725 parent::after( $title ); 3726 3727 $this->i ++; 3728 } 3729 3730 /** 3731 * Outputs links after bulk plugin installation is complete. 3732 * 3733 * @since 2.2.0 3734 */ 3735 public function bulk_footer() { 3736 // Serve up the string to say installations (and possibly activations) are complete. 3737 parent::bulk_footer(); 3738 3739 // Flush plugins cache so we can make sure that the installed plugins list is always up to date. 3740 wp_clean_plugins_cache(); 3741 3742 $this->buddyforms_members_tgmpa->show_buddyforms_members_tgmpa_version(); 3743 3744 // Display message based on if all plugins are now active or not. 3745 $update_actions = array(); 3746 3747 if ( $this->buddyforms_members_tgmpa->is_buddyforms_members_tgmpa_complete() ) { 3748 // All plugins are active, so we display the complete string and hide the menu to protect users. 3749 echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>'; 3750 $update_actions['dashboard'] = sprintf( 3751 esc_html( $this->buddyforms_members_tgmpa->strings['complete'] ), 3752 '<a href="' . esc_url( self_admin_url() ) . '">' . esc_html__( 'Return to the Dashboard', 'buddyforms_members_tgmpa' ) . '</a>' 3753 ); 3754 } else { 3755 $update_actions['buddyforms_members_tgmpa_page'] = '<a href="' . esc_url( $this->buddyforms_members_tgmpa->get_buddyforms_members_tgmpa_url() ) . '" target="_parent">' . esc_html( $this->buddyforms_members_tgmpa->strings['return'] ) . '</a>'; 3756 } 3757 3758 /** 3759 * Filter the list of action links available following bulk plugin installs/updates. 3760 * 3761 * @since 2.5.0 3762 * 3763 * @param array $update_actions Array of plugin action links. 3764 * @param array $plugin_info Array of information for the last-handled plugin. 3765 */ 3766 $update_actions = apply_filters( 'buddyforms_members_tgmpa_update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info ); 3767 3768 if ( ! empty( $update_actions ) ) { 3769 $this->feedback( implode( ' | ', (array) $update_actions ) ); 3770 } 3771 } 3772 3773 /* *********** DEPRECATED METHODS *********** */ 3774 3775 /** 3776 * Flush header output buffer. 3777 * 3778 * @since 2.2.0 3779 * @deprecated 2.5.0 use {@see Bulk_Upgrader_Skin::flush_output()} instead 3780 * @see Bulk_Upgrader_Skin::flush_output() 3781 */ 3782 public function before_flush_output() { 3783 _deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'Bulk_Upgrader_Skin::flush_output()' ); 3784 $this->flush_output(); 3785 } 3786 3787 /** 3788 * Flush footer output buffer and iterate $this->i to make sure the 3789 * installation strings reference the correct plugin. 3790 * 3791 * @since 2.2.0 3792 * @deprecated 2.5.0 use {@see Bulk_Upgrader_Skin::flush_output()} instead 3793 * @see Bulk_Upgrader_Skin::flush_output() 3794 */ 3795 public function after_flush_output() { 3796 _deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'Bulk_Upgrader_Skin::flush_output()' ); 3797 $this->flush_output(); 3798 $this->i ++; 3799 } 3800 } 3801 } 3802 } 3803 } 3804 } 3805 3806 if ( ! class_exists( 'TGMPA_Utils' ) ) { 3807 3808 /** 3809 * Generic utilities for TGMPA. 3810 * 3811 * All methods are static, poor-dev name-spacing class wrapper. 3812 * 3813 * Class was called TGM_Utils in 2.5.0 but renamed TGMPA_Utils in 2.5.1 as this was conflicting with Soliloquy. 3814 * 3815 * @since 2.5.0 3816 * 3817 * @package TGM-Plugin-Activation 3818 * @author Juliette Reinders Folmer 3819 */ 3820 class TGMPA_Utils { 3821 /** 3822 * Whether the PHP filter extension is enabled. 3823 * 3824 * @see http://php.net/book.filter 3825 * 3826 * @since 2.5.0 3827 * 3828 * @static 3829 * 3830 * @var bool $has_filters True is the extension is enabled. 3831 */ 3832 public static $has_filters; 3833 3834 /** 3835 * Wrap an arbitrary string in <em> tags. Meant to be used in combination with array_map(). 3836 * 3837 * @since 2.5.0 3838 * 3839 * @static 3840 * 3841 * @param string $string Text to be wrapped. 3842 * 3843 * @return string 3844 */ 3845 public static function wrap_in_em( $string ) { 3846 return '<em>' . wp_kses_post( $string ) . '</em>'; 3847 } 3848 3849 /** 3850 * Wrap an arbitrary string in <strong> tags. Meant to be used in combination with array_map(). 3851 * 3852 * @since 2.5.0 3853 * 3854 * @static 3855 * 3856 * @param string $string Text to be wrapped. 3857 * 3858 * @return string 3859 */ 3860 public static function wrap_in_strong( $string ) { 3861 return '<strong>' . wp_kses_post( $string ) . '</strong>'; 3862 } 3863 3864 /** 3865 * Helper function: Validate a value as boolean 3866 * 3867 * @since 2.5.0 3868 * 3869 * @static 3870 * 3871 * @param mixed $value Arbitrary value. 3872 * 3873 * @return bool 3874 */ 3875 public static function validate_bool( $value ) { 3876 if ( ! isset( self::$has_filters ) ) { 3877 self::$has_filters = extension_loaded( 'filter' ); 3878 } 3879 3880 if ( self::$has_filters ) { 3881 return filter_var( $value, FILTER_VALIDATE_BOOLEAN ); 3882 } else { 3883 return self::emulate_filter_bool( $value ); 3884 } 3885 } 3886 3887 /** 3888 * Helper function: Cast a value to bool 3889 * 3890 * @since 2.5.0 3891 * 3892 * @static 3893 * 3894 * @param mixed $value Value to cast. 3895 * 3896 * @return bool 3897 */ 3898 protected static function emulate_filter_bool( $value ) { 3899 // @codingStandardsIgnoreStart 3900 static $true = array( 3901 '1', 3902 'true', 3903 'True', 3904 'TRUE', 3905 'y', 3906 'Y', 3907 'yes', 3908 'Yes', 3909 'YES', 3910 'on', 3911 'On', 3912 'ON', 3913 ); 3914 static $false = array( 3915 '0', 3916 'false', 3917 'False', 3918 'FALSE', 3919 'n', 3920 'N', 3921 'no', 3922 'No', 3923 'NO', 3924 'off', 3925 'Off', 3926 'OFF', 3927 ); 3928 // @codingStandardsIgnoreEnd 3929 3930 if ( is_bool( $value ) ) { 3931 return $value; 3932 } elseif ( is_int( $value ) && ( 0 === $value || 1 === $value ) ) { 3933 return (bool) $value; 3934 } elseif ( ( is_float( $value ) && ! is_nan( $value ) ) && ( (float) 0 === $value || (float) 1 === $value ) ) { 3935 return (bool) $value; 3936 } elseif ( is_string( $value ) ) { 3937 $value = trim( $value ); 3938 if ( in_array( $value, $true, true ) ) { 3939 return true; 3940 } elseif ( in_array( $value, $false, true ) ) { 3941 return false; 3942 } else { 3943 return false; 3944 } 3945 } 3946 3947 return false; 3948 } 3949 } // End of class TGMPA_Utils 3950 } // End of class_exists wrapper 28 </tr>'; } public function extra_tablenav( $which ) { if ( 'bottom' === $which ) { $this->buddyforms_members_tgmpa->show_buddyforms_members_tgmpa_version(); } } public function get_bulk_actions() { $actions = array(); if ( 'update' !== $this->view_context && 'activate' !== $this->view_context ) { if ( current_user_can( 'install_plugins' ) ) { $actions['buddyforms_members_tgmpa-bulk-install'] = __( 'Install', 'buddyforms_members_tgmpa' ); } } if ( 'install' !== $this->view_context ) { if ( current_user_can( 'update_plugins' ) ) { $actions['buddyforms_members_tgmpa-bulk-update'] = __( 'Update', 'buddyforms_members_tgmpa' ); } if ( current_user_can( 'activate_plugins' ) ) { $actions['buddyforms_members_tgmpa-bulk-activate'] = __( 'Activate', 'buddyforms_members_tgmpa' ); } } return $actions; } public function process_bulk_actions() { if ( 'buddyforms_members_tgmpa-bulk-install' === $this->current_action() || 'buddyforms_members_tgmpa-bulk-update' === $this->current_action() ) { check_admin_referer( 'bulk-' . $this->_args['plural'] ); $install_type = 'install'; if ( 'buddyforms_members_tgmpa-bulk-update' === $this->current_action() ) { $install_type = 'update'; } $plugins_to_install = array(); if ( empty( $_POST['plugin'] ) ) { if ( 'install' === $install_type ) { $message = __( 'No plugins were selected to be installed. No action taken.', 'buddyforms_members_tgmpa' ); } else { $message = __( 'No plugins were selected to be updated. No action taken.', 'buddyforms_members_tgmpa' ); } echo '<div id="message" class="error"><p>', esc_html( $message ), '</p></div>'; return false; } if ( is_array( $_POST['plugin'] ) ) { $plugins_to_install = (array) $_POST['plugin']; } elseif ( is_string( $_POST['plugin'] ) ) { $plugins_to_install = explode( ',', $_POST['plugin'] ); } $plugins_to_install = array_map( 'urldecode', $plugins_to_install ); $plugins_to_install = array_map( array( $this->buddyforms_members_tgmpa, 'sanitize_key' ), $plugins_to_install ); foreach ( $plugins_to_install as $key => $slug ) { if ( ! isset( $this->buddyforms_members_tgmpa->plugins[ $slug ] ) ) { unset( $plugins_to_install[ $key ] ); continue; } if ( 'install' === $install_type && true === $this->buddyforms_members_tgmpa->is_plugin_installed( $slug ) ) { unset( $plugins_to_install[ $key ] ); } if ( 'update' === $install_type && false === $this->buddyforms_members_tgmpa->is_plugin_updatetable( $slug ) ) { unset( $plugins_to_install[ $key ] ); } } if ( empty( $plugins_to_install ) ) { if ( 'install' === $install_type ) { $message = __( 'No plugins are available to be installed at this time.', 'buddyforms_members_tgmpa' ); } else { $message = __( 'No plugins are available to be updated at this time.', 'buddyforms_members_tgmpa' ); } echo '<div id="message" class="error"><p>', esc_html( $message ), '</p></div>'; return false; } $url = wp_nonce_url( $this->buddyforms_members_tgmpa->get_buddyforms_members_tgmpa_url(), 'bulk-' . $this->_args['plural'] ); $_POST['plugin'] = implode( ',', $plugins_to_install ); $method = ''; $fields = array_keys( $_POST ); if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, $fields ) ) ) { return true; } if ( ! WP_Filesystem( $creds ) ) { request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, $fields ); return true; } $names = array(); $sources = array(); $file_paths = array(); $to_inject = array(); foreach ( $plugins_to_install as $slug ) { $name = $this->buddyforms_members_tgmpa->plugins[ $slug ]['name']; $source = $this->buddyforms_members_tgmpa->get_download_url( $slug ); if ( ! empty( $name ) && ! empty( $source ) ) { $names[] = $name; switch ( $install_type ) { case 'install': $sources[] = $source; break; case 'update': $file_paths[] = $this->buddyforms_members_tgmpa->plugins[ $slug ]['file_path']; $to_inject[ $slug ] = $this->buddyforms_members_tgmpa->plugins[ $slug ]; $to_inject[ $slug ]['source'] = $source; break; } } } unset( $slug, $name, $source ); $installer = new TGMPA_Bulk_Installer( new TGMPA_Bulk_Installer_Skin( array( 'url' => esc_url_raw( $this->buddyforms_members_tgmpa->get_buddyforms_members_tgmpa_url() ), 'nonce' => 'bulk-' . $this->_args['plural'], 'names' => $names, 'install_type' => $install_type, ) ) ); echo '<div class="buddyforms_members_tgmpa">', '<h2 style="font-size: 23px; font-weight: 400; line-height: 29px; margin: 0; padding: 9px 15px 4px 0;">', esc_html( get_admin_page_title() ), '</h2> 29 <div class="update-php" style="width: 100%; height: 98%; min-height: 850px; padding-top: 1px;">'; add_filter( 'upgrader_source_selection', array( $this->buddyforms_members_tgmpa, 'maybe_adjust_source_dir' ), 1, 3 ); if ( 'buddyforms_members_tgmpa-bulk-update' === $this->current_action() ) { $this->buddyforms_members_tgmpa->inject_update_info( $to_inject ); $installer->bulk_upgrade( $file_paths ); } else { $installer->bulk_install( $sources ); } remove_filter( 'upgrader_source_selection', array( $this->buddyforms_members_tgmpa, 'maybe_adjust_source_dir' ), 1 ); echo '</div></div>'; return true; } if ( 'buddyforms_members_tgmpa-bulk-activate' === $this->current_action() ) { check_admin_referer( 'bulk-' . $this->_args['plural'] ); if ( empty( $_POST['plugin'] ) ) { echo '<div id="message" class="error"><p>', esc_html__( 'No plugins were selected to be activated. No action taken.', 'buddyforms_members_tgmpa' ), '</p></div>'; return false; } $plugins = array(); if ( isset( $_POST['plugin'] ) ) { $plugins = array_map( 'urldecode', (array) $_POST['plugin'] ); $plugins = array_map( array( $this->buddyforms_members_tgmpa, 'sanitize_key' ), $plugins ); } $plugins_to_activate = array(); $plugin_names = array(); foreach ( $plugins as $slug ) { if ( $this->buddyforms_members_tgmpa->can_plugin_activate( $slug ) ) { $plugins_to_activate[] = $this->buddyforms_members_tgmpa->plugins[ $slug ]['file_path']; $plugin_names[] = $this->buddyforms_members_tgmpa->plugins[ $slug ]['name']; } } unset( $slug ); if ( empty( $plugins_to_activate ) ) { echo '<div id="message" class="error"><p>', esc_html__( 'No plugins are available to be activated at this time.', 'buddyforms_members_tgmpa' ), '</p></div>'; return false; } $activate = activate_plugins( $plugins_to_activate ); if ( is_wp_error( $activate ) ) { echo '<div id="message" class="error"><p>', wp_kses_post( $activate->get_error_message() ), '</p></div>'; } else { $count = count( $plugin_names ); $plugin_names = array_map( array( 'TGMPA_Utils', 'wrap_in_strong' ), $plugin_names ); $last_plugin = array_pop( $plugin_names ); $imploded = empty( $plugin_names ) ? $last_plugin : ( implode( ', ', $plugin_names ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'buddyforms_members_tgmpa' ) . ' ' . $last_plugin ); printf( '<div id="message" class="updated"><p>%1$s %2$s.</p></div>', esc_html( _n( 'The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, 'buddyforms_members_tgmpa' ) ), $imploded ); $recent = (array) get_option( 'recently_activated' ); foreach ( $plugins_to_activate as $plugin => $time ) { if ( isset( $recent[ $plugin ] ) ) { unset( $recent[ $plugin ] ); } } update_option( 'recently_activated', $recent ); } unset( $_POST ); return true; } return false; } public function prepare_items() { $columns = $this->get_columns(); $hidden = array(); $sortable = array(); $primary = $this->get_primary_column_name(); $this->_column_headers = array( $columns, $hidden, $sortable, $primary ); if ( 'buddyforms_members_tgmpa-bulk-activate' === $this->current_action() ) { $this->process_bulk_actions(); } $this->items = apply_filters( 'buddyforms_members_tgmpa_table_data_items', $this->_gather_plugin_data() ); } protected function _get_plugin_data_from_name( $name, $data = 'slug' ) { _deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'TGM_Plugin_Activation::_get_plugin_data_from_name()' ); return $this->buddyforms_members_tgmpa->_get_plugin_data_from_name( $name, $data ); } } } if ( ! class_exists( 'TGM_Bulk_Installer' ) ) { class TGM_Bulk_Installer { } } if ( ! class_exists( 'TGM_Bulk_Installer_Skin' ) ) { class TGM_Bulk_Installer_Skin { } } add_action( 'admin_init', 'buddyforms_members_tgmpa_load_bulk_installer' ); if ( ! function_exists( 'buddyforms_members_tgmpa_load_bulk_installer' ) ) { function buddyforms_members_tgmpa_load_bulk_installer() { if ( ! isset( $GLOBALS['buddyforms_members_tgmpa'] ) ) { return; } $buddyforms_members_tgmpa_instance = call_user_func( array( get_class( $GLOBALS['buddyforms_members_tgmpa'] ), 'get_instance' ) ); if ( isset( $_GET['page'] ) && $buddyforms_members_tgmpa_instance->menu === $_GET['page'] ) { if ( ! class_exists( 'Plugin_Upgrader', false ) ) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; } if ( ! class_exists( 'TGMPA_Bulk_Installer' ) ) { class TGMPA_Bulk_Installer extends Plugin_Upgrader { public $result; public $bulk = false; protected $buddyforms_members_tgmpa; protected $clear_destination = false; public function __construct( $skin = null ) { $this->buddyforms_members_tgmpa = call_user_func( array( get_class( $GLOBALS['buddyforms_members_tgmpa'] ), 'get_instance' ) ); parent::__construct( $skin ); if ( isset( $this->skin->options['install_type'] ) && 'update' === $this->skin->options['install_type'] ) { $this->clear_destination = true; } if ( $this->buddyforms_members_tgmpa->is_automatic ) { $this->activate_strings(); } add_action( 'upgrader_process_complete', array( $this->buddyforms_members_tgmpa, 'populate_file_path' ) ); } public function activate_strings() { $this->strings['activation_failed'] = __( 'Plugin activation failed.', 'buddyforms_members_tgmpa' ); $this->strings['activation_success'] = __( 'Plugin activated successfully.', 'buddyforms_members_tgmpa' ); } public function run( $options ) { $result = parent::run( $options ); if ( $this->buddyforms_members_tgmpa->is_automatic ) { if ( 'update' === $this->skin->options['install_type'] ) { $this->upgrade_strings(); } else { $this->install_strings(); } } return $result; } public function bulk_install( $plugins, $args = array() ) { add_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 ); $defaults = array( 'clear_update_cache' => true, ); $parsed_args = wp_parse_args( $args, $defaults ); $this->init(); $this->bulk = true; $this->install_strings(); $this->skin->header(); $res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) ); if ( ! $res ) { $this->skin->footer(); return false; } $this->skin->bulk_header(); $maintenance = ( is_multisite() && ! empty( $plugins ) ); if ( $maintenance ) { $this->maintenance_mode( true ); } $results = array(); $this->update_count = count( $plugins ); $this->update_current = 0; foreach ( $plugins as $plugin ) { $this->update_current ++; $result = $this->run( array( 'package' => $plugin, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => false, 'clear_working' => true, 'is_multi' => true, 'hook_extra' => array( 'plugin' => $plugin, ), ) ); $results[ $plugin ] = $this->result; if ( false === $result ) { break; } } $this->maintenance_mode( false ); do_action( 'upgrader_process_complete', $this, array( 'action' => 'install', 'type' => 'plugin', 'bulk' => true, 'plugins' => $plugins, ) ); $this->skin->bulk_footer(); $this->skin->footer(); remove_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 ); wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); return $results; } public function bulk_upgrade( $plugins, $args = array() ) { add_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 ); $result = parent::bulk_upgrade( $plugins, $args ); remove_filter( 'upgrader_post_install', array( $this, 'auto_activate' ), 10 ); return $result; } public function auto_activate( $bool ) { if ( $this->buddyforms_members_tgmpa->is_automatic ) { wp_clean_plugins_cache(); $plugin_info = $this->plugin_info(); if ( ! is_plugin_active( $plugin_info ) ) { $activate = activate_plugin( $plugin_info ); $this->strings['process_success'] = $this->strings['process_success'] . "<br />\n"; if ( is_wp_error( $activate ) ) { $this->skin->error( $activate ); $this->strings['process_success'] .= $this->strings['activation_failed']; } else { $this->strings['process_success'] .= $this->strings['activation_success']; } } } return $bool; } } } if ( ! class_exists( 'TGMPA_Bulk_Installer_Skin' ) ) { class TGMPA_Bulk_Installer_Skin extends Bulk_Upgrader_Skin { public $plugin_info = array(); public $plugin_names = array(); public $i = 0; protected $buddyforms_members_tgmpa; public function __construct( $args = array() ) { $this->buddyforms_members_tgmpa = call_user_func( array( get_class( $GLOBALS['buddyforms_members_tgmpa'] ), 'get_instance' ) ); $defaults = array( 'url' => '', 'nonce' => '', 'names' => array(), 'install_type' => 'install', ); $args = wp_parse_args( $args, $defaults ); $this->plugin_names = $args['names']; parent::__construct( $args ); } public function add_strings() { if ( 'update' === $this->options['install_type'] ) { parent::add_strings(); $this->upgrader->strings['skin_before_update_header'] = __( 'Updating Plugin %1$s (%2$d/%3$d)', 'buddyforms_members_tgmpa' ); } else { $this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while installing %1$s: <strong>%2$s</strong>.', 'buddyforms_members_tgmpa' ); $this->upgrader->strings['skin_update_failed'] = __( 'The installation of %1$s failed.', 'buddyforms_members_tgmpa' ); if ( $this->buddyforms_members_tgmpa->is_automatic ) { $this->upgrader->strings['skin_upgrade_start'] = __( 'The installation and activation process is starting. This process may take a while on some hosts, so please be patient.', 'buddyforms_members_tgmpa' ); $this->upgrader->strings['skin_update_successful'] = __( '%1$s installed and activated successfully.', 'buddyforms_members_tgmpa' ) . ' <a href="#" class="hide-if-no-js" onclick="%2$s"><span>' . esc_html__( 'Show Details', 'buddyforms_members_tgmpa' ) . '</span><span class="hidden">' . esc_html__( 'Hide Details', 'buddyforms_members_tgmpa' ) . '</span>.</a>'; $this->upgrader->strings['skin_upgrade_end'] = __( 'All installations and activations have been completed.', 'buddyforms_members_tgmpa' ); $this->upgrader->strings['skin_before_update_header'] = __( 'Installing and Activating Plugin %1$s (%2$d/%3$d)', 'buddyforms_members_tgmpa' ); } else { $this->upgrader->strings['skin_upgrade_start'] = __( 'The installation process is starting. This process may take a while on some hosts, so please be patient.', 'buddyforms_members_tgmpa' ); $this->upgrader->strings['skin_update_successful'] = esc_html__( '%1$s installed successfully.', 'buddyforms_members_tgmpa' ) . ' <a href="#" class="hide-if-no-js" onclick="%2$s"><span>' . esc_html__( 'Show Details', 'buddyforms_members_tgmpa' ) . '</span><span class="hidden">' . esc_html__( 'Hide Details', 'buddyforms_members_tgmpa' ) . '</span>.</a>'; $this->upgrader->strings['skin_upgrade_end'] = __( 'All installations have been completed.', 'buddyforms_members_tgmpa' ); $this->upgrader->strings['skin_before_update_header'] = __( 'Installing Plugin %1$s (%2$d/%3$d)', 'buddyforms_members_tgmpa' ); } } } public function before( $title = '' ) { if ( empty( $title ) ) { $title = esc_html( $this->plugin_names[ $this->i ] ); } parent::before( $title ); } public function after( $title = '' ) { if ( empty( $title ) ) { $title = esc_html( $this->plugin_names[ $this->i ] ); } parent::after( $title ); $this->i ++; } public function bulk_footer() { parent::bulk_footer(); wp_clean_plugins_cache(); $this->buddyforms_members_tgmpa->show_buddyforms_members_tgmpa_version(); $update_actions = array(); if ( $this->buddyforms_members_tgmpa->is_buddyforms_members_tgmpa_complete() ) { echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>'; $update_actions['dashboard'] = sprintf( esc_html( $this->buddyforms_members_tgmpa->strings['complete'] ), '<a href="' . esc_url( self_admin_url() ) . '">' . esc_html__( 'Return to the Dashboard', 'buddyforms_members_tgmpa' ) . '</a>' ); } else { $update_actions['buddyforms_members_tgmpa_page'] = '<a href="' . esc_url( $this->buddyforms_members_tgmpa->get_buddyforms_members_tgmpa_url() ) . '" target="_parent">' . esc_html( $this->buddyforms_members_tgmpa->strings['return'] ) . '</a>'; } $update_actions = apply_filters( 'buddyforms_members_tgmpa_update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info ); if ( ! empty( $update_actions ) ) { $this->feedback( implode( ' | ', (array) $update_actions ) ); } } public function before_flush_output() { _deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'Bulk_Upgrader_Skin::flush_output()' ); $this->flush_output(); } public function after_flush_output() { _deprecated_function( __FUNCTION__, 'TGMPA 2.5.0', 'Bulk_Upgrader_Skin::flush_output()' ); $this->flush_output(); $this->i ++; } } } } } } if ( ! class_exists( 'TGMPA_Utils' ) ) { class TGMPA_Utils { public static $has_filters; public static function wrap_in_em( $string ) { return '<em>' . wp_kses_post( $string ) . '</em>'; } public static function wrap_in_strong( $string ) { return '<strong>' . wp_kses_post( $string ) . '</strong>'; } public static function validate_bool( $value ) { if ( ! isset( self::$has_filters ) ) { self::$has_filters = extension_loaded( 'filter' ); } if ( self::$has_filters ) { return filter_var( $value, FILTER_VALIDATE_BOOLEAN ); } else { return self::emulate_filter_bool( $value ); } } protected static function emulate_filter_bool( $value ) { static $true = array( '1', 'true', 'True', 'TRUE', 'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON', ); static $false = array( '0', 'false', 'False', 'FALSE', 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF', ); if ( is_bool( $value ) ) { return $value; } elseif ( is_int( $value ) && ( 0 === $value || 1 === $value ) ) { return (bool) $value; } elseif ( ( is_float( $value ) && ! is_nan( $value ) ) && ( (float) 0 === $value || (float) 1 === $value ) ) { return (bool) $value; } elseif ( is_string( $value ) ) { $value = trim( $value ); if ( in_array( $value, $true, true ) ) { return true; } elseif ( in_array( $value, $false, true ) ) { return false; } else { return false; } } return false; } } } -
buddyforms-members/trunk/includes/templates/buddyforms/members/members-post-create.php
r1611925 r2412106 1 1 <div id="item-body"> 2 2 <?php 3 4 if ( ! defined( 'ABSPATH' ) ) { exit; } 5 3 6 global $bp, $buddyforms, $buddyforms_member_tabs; 4 7 -
buddyforms-members/trunk/includes/templates/buddyforms/members/members-post-display.php
r2208138 r2412106 1 1 <div id="item-body"> 2 2 <?php 3 4 if ( ! defined( 'ABSPATH' ) ) { exit; } 5 3 6 global $wp_query, $current_user, $the_lp_query, $bp, $buddyforms, $buddyforms_member_tabs, $form_slug, $paged; 4 7 -
buddyforms-members/trunk/includes/templates/buddyforms/registration-form.php
r2063039 r2412106 1 1 <?php 2 3 if ( ! defined( 'ABSPATH' ) ) { exit; } 4 2 5 3 6 /** -
buddyforms-members/trunk/loader.php
r2305563 r2412106 1 1 <?php 2 2 3 if ( !defined( 'ABSPATH' ) ) { 4 exit; 5 } 3 6 /** 4 7 * Plugin Name: BuddyForms Members 5 8 * Plugin URI: http://buddyforms.com/downloads/buddyforms-members/ 6 9 * Description: The BuddyForms Members Component. Let your members write right out of their profiles. 7 * Version: 1.4.1 010 * Version: 1.4.12 8 11 * Author: ThemeKraft 9 12 * Author URI: https://themekraft.com/buddyforms/ … … 52 55 require dirname( __FILE__ ) . '/includes/resources/tgm/class-tgm-plugin-activation.php'; 53 56 // Hook required plugins function to the tgmpa_register action 54 add_action( 'buddyforms_members_tgmpa ', function () {57 add_action( 'buddyforms_members_tgmpa_register', function () { 55 58 $plugins = array(); 56 59 $is_buddyboss_theme_active = buddyforms_members_is_buddyboss_theme_active(); … … 68 71 'slug' => 'buddyforms', 69 72 'required' => true, 73 'version' => '2.5.23-beta.2', 70 74 ); 71 75 } -
buddyforms-members/trunk/readme.txt
r2305563 r2412106 4 4 Requires at least: 3.9 5 5 Tested up to: 5.4 6 Stable tag: 1.4.1 06 Stable tag: 1.4.12 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 105 105 106 106 == Changelog == 107 = 1.4.12 - 3 November 2020 = 108 * Added: New option to integrate a form as a member contact form. 109 * Feature: Show notice when the Send Message to Member feature is enabled and Send Email to Member has not been checked on any Notification. 110 * Fixed: Add missing validation in the code to avoid warnings and notices. 111 * Fixed: Spelling correction. 112 * Fixed: add missing pro labels and restriction over te form builder related to Member Type, xProfile Field, and xProfile Group. 113 107 114 = 1.4.10 - 17 May 2020 = 108 115 * Fixed error code related to the tmpga library.
Note: See TracChangeset
for help on using the changeset viewer.