Blocks
1 month ago
MenuService.php
1 month ago
SBR_About_Builder.php
1 month ago
SBR_Admin_Notice.php
1 month ago
SBR_Collections_Builder.php
1 month ago
SBR_New_User.php
1 month ago
SBR_Notifications.php
1 month ago
SBR_Plugin_Insltaller.php
1 month ago
SBR_Support_Builder.php
1 month ago
SBR_Support_Tool.php
1 month ago
SBR_Admin_Notice.php
89 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * SBR Admin Notice |
| 5 | */ |
| 6 | |
| 7 | namespace SmashBalloon\Reviews\Common\Admin; |
| 8 | |
| 9 | if (! defined('ABSPATH')) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | use Smashballoon\Stubs\Services\ServiceProvider; |
| 14 | |
| 15 | class SBR_Admin_Notice extends ServiceProvider{ |
| 16 | public function register() |
| 17 | { |
| 18 | $this->init(); |
| 19 | } |
| 20 | |
| 21 | public function init() |
| 22 | { |
| 23 | if (! is_admin()) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | add_action('admin_notices', [$this, 'apikey_limit_notice']); |
| 28 | add_action('wp_ajax_sbr_dismiss_license_notice', [ $this, 'sbr_dismiss_license_notice' ]); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | public static function check_menu_notice_bubble() |
| 33 | { |
| 34 | $is_admin_bubble = false; |
| 35 | $api_limits = get_option('sbr_apikeys_limit', []); |
| 36 | |
| 37 | if (is_array($api_limits) && sizeof($api_limits) > 0) { |
| 38 | $is_admin_bubble = true; |
| 39 | } |
| 40 | |
| 41 | |
| 42 | return $is_admin_bubble; |
| 43 | } |
| 44 | |
| 45 | public function apikey_limit_notice() |
| 46 | { |
| 47 | $api_limits = get_option('sbr_apikeys_limit', []); |
| 48 | $should_show_notice = is_array($api_limits) && sizeof($api_limits) > 0; |
| 49 | if (! $should_show_notice) { |
| 50 | return; |
| 51 | } |
| 52 | ?> |
| 53 | <div class="notice notice-error"> |
| 54 | <p> |
| 55 | <?php |
| 56 | echo wp_kses( |
| 57 | sprintf( |
| 58 | /* translators: first %s is the name of a review provider (Yelp): The 2nd and third %s are opening and closing anchor HTML tags */ |
| 59 | __('You have reached the review source limit for (%s). In order to add additional sources you\'ll need to create and enter an API key. Please add API key %shere%s.', 'reviews-feed'), |
| 60 | esc_html(ucfirst(join(", ", $api_limits))), |
| 61 | '<a href="' . esc_url(admin_url('admin.php?page=sbr-settings')) . '">', |
| 62 | '</a>' |
| 63 | ), |
| 64 | array( 'a' => array( 'href' => array() ) ) |
| 65 | ); |
| 66 | ?> |
| 67 | </p> |
| 68 | </div> |
| 69 | <?php |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * CFF Dismiss Notice |
| 74 | * |
| 75 | * @since 1.1 |
| 76 | */ |
| 77 | public function sbr_dismiss_license_notice() |
| 78 | { |
| 79 | check_ajax_referer('sbr-admin', 'nonce'); |
| 80 | if (! sbr_current_user_can('manage_reviews_feed_options')) { |
| 81 | wp_send_json_error(); // This auto-dies. |
| 82 | } |
| 83 | |
| 84 | global $current_user; |
| 85 | $user_id = $current_user->ID; |
| 86 | update_user_meta($user_id, 'sbr_ignore_dashboard_license_notice', true); |
| 87 | } |
| 88 | |
| 89 | } |