AdminNotices.php
5 years ago
AjaxHandler.php
5 years ago
Autologin.php
5 years ago
BuddyPressBbPress.php
5 years ago
EditUserProfile.php
5 years ago
ExtensionManager.php
5 years ago
FileUploader.php
5 years ago
FormPreviewHandler.php
5 years ago
FormRepository.php
5 years ago
FormShortcodeDefaults.php
5 years ago
GDPR.php
5 years ago
GlobalSiteAccess.php
5 years ago
ImageUploader.php
5 years ago
LoginAuth.php
5 years ago
Miscellaneous.php
5 years ago
ModifyRedirectDefaultLinks.php
5 years ago
PPRESS_Session.php
5 years ago
PROFILEPRESS_sql.php
5 years ago
PasswordReset.php
5 years ago
ProfileUrlRewrite.php
5 years ago
RegistrationAuth.php
5 years ago
SendEmail.php
5 years ago
ShortcodeThemeFactory.php
5 years ago
UserAvatar.php
5 years ago
UserSignupLocationListingPage.php
5 years ago
UsernameEmailRestrictLogin.php
5 years ago
WelcomeEmailAfterSignup.php
5 years ago
default-email-template.php
5 years ago
index.php
5 years ago
AdminNotices.php
195 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Classes; |
| 4 | |
| 5 | use PAnD; |
| 6 | |
| 7 | class AdminNotices |
| 8 | { |
| 9 | public function __construct() |
| 10 | { |
| 11 | add_action('admin_init', function () { |
| 12 | |
| 13 | if (ppress_is_admin_page()) { |
| 14 | remove_all_actions('admin_notices'); |
| 15 | } |
| 16 | |
| 17 | add_action('admin_notices', [$this, 'admin_notices_bucket']); |
| 18 | |
| 19 | add_filter('removable_query_args', [$this, 'removable_query_args']); |
| 20 | }); |
| 21 | |
| 22 | if (class_exists('PAnD')) { |
| 23 | // persist admin notice dismissal initialization |
| 24 | add_action('admin_init', array('PAnD', 'init')); |
| 25 | } |
| 26 | add_action('admin_init', array($this, 'act_on_request')); |
| 27 | } |
| 28 | |
| 29 | public function admin_notices_bucket() |
| 30 | { |
| 31 | do_action('ppress_admin_notices'); |
| 32 | |
| 33 | $this->registration_disabled_notice(); |
| 34 | |
| 35 | $this->create_plugin_pages(); |
| 36 | |
| 37 | $this->review_plugin_notice(); |
| 38 | |
| 39 | $this->wp_user_avatar_now_ppress_notice(); |
| 40 | } |
| 41 | |
| 42 | public function act_on_request() |
| 43 | { |
| 44 | if ( ! empty($_GET['ppress_admin_action'])) { |
| 45 | |
| 46 | if ($_GET['ppress_admin_action'] == 'dismiss_leave_review_forever') { |
| 47 | update_option('ppress_dismiss_leave_review_forever', true); |
| 48 | } |
| 49 | |
| 50 | if ($_GET['ppress_admin_action'] == 'dismiss_wp_user_avatar_now_ppress') { |
| 51 | |
| 52 | PAnD::set_admin_notice_cache('wp_user_avatar_now_ppress_notice', 'forever'); |
| 53 | } |
| 54 | |
| 55 | wp_safe_redirect(esc_url_raw(remove_query_arg('ppress_admin_action'))); |
| 56 | exit; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Display one-time admin notice to review plugin at least 7 days after installation |
| 62 | */ |
| 63 | public function review_plugin_notice() |
| 64 | { |
| 65 | if ( ! PAnD::is_admin_notice_active('ppress-review-plugin-notice-forever')) return; |
| 66 | |
| 67 | if (get_option('ppress_dismiss_leave_review_forever', false)) return; |
| 68 | |
| 69 | $install_date = get_option('ppress_install_date', ''); |
| 70 | |
| 71 | if (empty($install_date)) return; |
| 72 | |
| 73 | $diff = round((time() - strtotime($install_date)) / 24 / 60 / 60); |
| 74 | |
| 75 | if ($diff < 7) return; |
| 76 | |
| 77 | $review_url = 'https://wordpress.org/support/plugin/wp-user-avatar/reviews/?filter=5#new-post'; |
| 78 | |
| 79 | $dismiss_url = esc_url_raw(add_query_arg('ppress_admin_action', 'dismiss_leave_review_forever')); |
| 80 | |
| 81 | $notice = sprintf( |
| 82 | __('Hey, I noticed you have been using ProfilePress for at least 7 days now - that\'s awesome! Could you please do us a BIG favor and give it a %1$s5-star rating on WordPress?%2$s This will help us spread the word and boost our motivation - thanks!', 'wp-user-avatar'), |
| 83 | '<a href="' . $review_url . '" target="_blank">', |
| 84 | '</a>' |
| 85 | ); |
| 86 | $label = __('Sure! I\'d love to give a review', 'wp-user-avatar'); |
| 87 | |
| 88 | $dismiss_label = __('Dimiss Forever', 'wp-user-avatar'); |
| 89 | |
| 90 | $notice .= "<div style=\"margin:10px 0 0;\"><a href=\"$review_url\" target='_blank' class=\"button-primary\">$label</a></div>"; |
| 91 | $notice .= "<div style=\"margin:10px 0 0;\"><a href=\"$dismiss_url\">$dismiss_label</a></div>"; |
| 92 | |
| 93 | echo '<div data-dismissible="ppress-review-plugin-notice-forever" class="update-nag notice notice-warning is-dismissible">'; |
| 94 | echo "<p>$notice</p>"; |
| 95 | echo '</div>'; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Let user avatar plugin users know it is now ProfilePress |
| 100 | */ |
| 101 | public function wp_user_avatar_now_ppress_notice() |
| 102 | { |
| 103 | if ( ! PAnD::is_admin_notice_active('wp_user_avatar_now_ppress_notice-forever')) return; |
| 104 | |
| 105 | if (get_option('ppress_is_from_wp_user_avatar', false) != 'true') return; |
| 106 | |
| 107 | $dismiss_url = esc_url_raw(add_query_arg('ppress_admin_action', 'dismiss_wp_user_avatar_now_ppress')); |
| 108 | |
| 109 | $notice = sprintf( |
| 110 | __('Important news! %1$sWP User Avatar%2$s is now %1$sProfilePress%2$s. We added new features such as member directories, frontend user registration & login forms, user profile, content protection and more. %3$sCheck Them Out%5$s | %4$sDismiss Notice%5$s', 'wp-user-avatar'), |
| 111 | '<strong>', '</strong>', |
| 112 | '<a href="' . PPRESS_SETTINGS_SETTING_PAGE . '">', '<a href="' . $dismiss_url . '">', '</a>' |
| 113 | ); |
| 114 | |
| 115 | echo '<div data-dismissible="wp_user_avatar_now_ppress_notice-forever" class="update-nag notice notice-warning is-dismissible">'; |
| 116 | echo "<p>$notice</p>"; |
| 117 | echo '</div>'; |
| 118 | } |
| 119 | |
| 120 | public function create_plugin_pages() |
| 121 | { |
| 122 | if ( ! PAnD::is_admin_notice_active('ppress-create-plugin-pages-notice-forever')) { |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | $create_page_url = esc_url(add_query_arg(['ppress_create_pages' => 'true', 'ppress_nonce' => wp_create_nonce('ppress_create_pages')])); |
| 127 | |
| 128 | $class = 'notice notice-info is-dismissible'; |
| 129 | $message = __('ProfilePress needs to create several pages (User Profiles, My Account, Registration, Login, Password Reset, Member Directory) to function correctly.', 'wp-user-avatar'); |
| 130 | $buttons = sprintf( |
| 131 | '<a href="%s" class="button button-primary">%s</a> <a href="#" class="button-secondary dismiss-this">%s</a>', |
| 132 | $create_page_url, esc_html__('Create Pages', 'wp-user-avatar'), esc_html__('No Thanks', 'wp-user-avatar') |
| 133 | ); |
| 134 | |
| 135 | printf('<div data-dismissible="ppress-create-plugin-pages-notice-forever" class="%1$s"><p>%2$s</p><p>%3$s</p></div>', esc_attr($class), esc_html($message), $buttons); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Notice when user registration is disabled. |
| 140 | */ |
| 141 | function registration_disabled_notice() |
| 142 | { |
| 143 | if ( ! current_user_can('manage_options')) return; |
| 144 | |
| 145 | if (get_option('users_can_register') || apply_filters('ppress_remove_registration_disabled_notice', false)) { |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | if ( ! class_exists('PAnD')) return; |
| 150 | |
| 151 | if ( ! PAnD::is_admin_notice_active('pp-registration-disabled-notice-forever')) { |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | $url = is_multisite() ? network_admin_url('settings.php') : admin_url('options-general.php'); |
| 156 | |
| 157 | ?> |
| 158 | <div data-dismissible="pp-registration-disabled-notice-forever" id="message" class="updated notice is-dismissible"> |
| 159 | <p> |
| 160 | <?php printf(__('User registration currently disabled. To enable, Go to <a href="%1$s">Settings -> General</a>, and under Membership, check "Anyone can register"', 'wp-user-avatar'), $url); ?> |
| 161 | . </p> |
| 162 | </div> |
| 163 | <?php |
| 164 | } |
| 165 | |
| 166 | public function removable_query_args($args = []) |
| 167 | { |
| 168 | $args[] = 'settings-updated'; |
| 169 | $args[] = 'rule-updated'; |
| 170 | $args[] = 'settings-added'; |
| 171 | $args[] = 'field-edited'; |
| 172 | $args[] = 'field-added'; |
| 173 | $args[] = 'updated-contact-info'; |
| 174 | $args[] = 'form-added'; |
| 175 | $args[] = 'form-edited'; |
| 176 | $args[] = 'user-profile-added'; |
| 177 | $args[] = 'user-profile-edited'; |
| 178 | $args[] = 'melange-edited'; |
| 179 | $args[] = 'melange-added'; |
| 180 | $args[] = 'license'; |
| 181 | |
| 182 | return $args; |
| 183 | } |
| 184 | |
| 185 | public static function get_instance() |
| 186 | { |
| 187 | static $instance = null; |
| 188 | |
| 189 | if (is_null($instance)) { |
| 190 | $instance = new self(); |
| 191 | } |
| 192 | |
| 193 | return $instance; |
| 194 | } |
| 195 | } |