GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 563189...ded6c2 )
by Brad
02:25
created

FooGallery_Admin_Notices::display_rating_notice()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 40
rs 9.28
c 0
b 0
f 0
1
<?php
2
/*
3
 * FooGallery Admin Notices class
4
 */
5
6
if ( ! class_exists( 'FooGallery_Admin_Notices' ) ) {
7
8
    class FooGallery_Admin_Notices {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
10
        public function __construct() {
11
            add_action( 'admin_notices', array( $this, 'display_thumb_test_notice') );
12
			add_action( 'admin_notices', array( $this, 'display_rating_notice') );
13
            add_action( 'foogallery_thumbnail_generation_test', array( $this, 'save_test_results') );
14
15
			add_action( 'wp_ajax_foogallery_admin_rating_notice_dismiss', array( $this, 'admin_rating_notice_dismiss' ) );
16
        }
17
18
        function should_run_tests() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
19
            $option = get_option( FOOGALLERY_OPTION_THUMB_TEST );
20
            $option_value = $this->generate_option_value();
21
22
            if ( !isset( $option ) ) {
23
                //we have never run tests before
24
                return true;
25
            } else {
26
                $option_key = $option['key'];
27
                if ( $option_value !== $option_key ) {
28
                    //either the PHP version or Host has changed. In either case, we should run tests again!
29
                    return true;
30
                }
31
            }
32
33
            return false;
34
        }
35
36
        function should_show_alert() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
            $option = get_option( FOOGALLERY_OPTION_THUMB_TEST );
38
39
            if ( isset( $option ) && array_key_exists( 'results', $option ) ) {
40
                $results = $option['results'];
41
                //should show the alert if the tests were not a success
42
                return !$results['success'];
43
            }
44
45
            return false;
46
        }
47
48
        function generate_option_value() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
49
            $php_version = phpversion();
50
            $host = home_url();
51
            return "php$($php_version}-{$host}";
52
        }
53
54
        function save_test_results($results) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
55
            update_option( FOOGALLERY_OPTION_THUMB_TEST, array (
56
                'key' => $this->generate_option_value(),
57
                'results' => $results
58
            ));
59
        }
60
61
		/**
62
		 * Dismiss the admin rating notice forever
63
		 */
64
		function admin_rating_notice_dismiss() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
65
			if ( check_admin_referer( 'foogallery_admin_rating_notice_dismiss' ) ) {
66
				update_option( 'foogallery_admin_rating_notice_dismiss', 'hide' );
67
			}
68
		}
69
70
        function should_show_rating_message() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
71
			//first try to get the saved option
72
			$show_message = get_option( 'foogallery_admin_rating_notice_dismiss', 0 );
73
74
			if ( 'hide' === $show_message ) {
75
				return false; //never show - user has dismissed
76
			}
77
78
			if ( 'show' === $show_message ) {
79
				return true; //always show - user has created 5 or more galleries
80
			}
81
82
83
			//we must show the message - get out early
84
			if ( 0 === $show_message ) {
85
				$gallery_count = count( get_posts( array(
86
					'post_type'     => FOOGALLERY_CPT_GALLERY,
87
					'post_status'	=> array( 'publish', 'draft' ),
88
					'cache_results' => false,
89
					'nopaging'      => true,
90
				) ) );
91
92
				if ( $gallery_count >= 5 ) {
93
					update_option( 'foogallery_admin_rating_notice_dismiss', 'show' );
94
				}
95
			}
96
		}
97
98
		function display_rating_notice() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
99
			if ( $this->should_show_rating_message() ) {
100
101
				$url = 'https://fooplugins.link/please-rate-foogallery';
102
				?>
103
				<script type="text/javascript">
104
					(function ($) {
105
						$(document).ready(function () {
106
							$('.foogallery-rating-notice.is-dismissible')
107
								.on('click', '.notice-dismiss', function (e) {
108
									e.preventDefault();
109
									$.post(ajaxurl, {
110
										action  : 'foogallery_admin_rating_notice_dismiss',
111
										url     : '<?php echo admin_url( 'admin-ajax.php' ); ?>',
112
										_wpnonce: '<?php echo wp_create_nonce( 'foogallery_admin_rating_notice_dismiss' ); ?>'
113
									});
114
								});
115
						});
116
					})(jQuery);
117
				</script>
118
				<style>
119
					.foogallery-rating-notice {
120
						border-left-color: #ff69b4;
121
					}
122
123
					.foogallery-rating-notice .dashicons-heart {
124
						color: #ff69b4;
125
					}
126
				</style>
127
				<div class="foogallery-rating-notice notice notice-success is-dismissible">
128
					<p>
129
						<strong><?php _e('Thanks for using FooGallery') ?> <span class="dashicons dashicons-heart"></span></strong><br />
130
						<?php _e('We noticed you have created 5 galleries in FooGallery. If you love FooGallery, please consider giving it a 5 star rating on WordPress.org. Your positive ratings help spread the word and help us grow.', 'foogallery'); ?><br />
131
						<br/>
132
						<a class="button button-primary button-large" target="_blank" href="<?php echo $url; ?>"><?php _e( 'Rate FooGallery on WordPress.org', 'foogallery' ); ?></a>
133
					</p>
134
				</div>
135
				<?php
136
			}
137
		}
138
139
        function display_thumb_test_notice() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
140
            //check if we are on specific admin pages
141
            if ( FOOGALLERY_CPT_GALLERY === foo_current_screen_post_type() ) {
142
143
                if ($this->should_run_tests()) {
144
                    $thumbs = new FooGallery_Thumbnails();
145
                    $thumbs->run_thumbnail_generation_tests();
146
                }
147
148
                if ($this->should_show_alert()) {
149
                    ?>
150
                    <div class="notice error">
151
                        <p>
152
                            <strong><?php _e('Thumbnail Generation Alert!', 'foogallery'); ?></strong><br/>
153
                            <?php _e('There is a problem generating thumbnails for your gallery. Please check that your hosting provider has the GD Image Library extension installed and enabled.' , 'foogallery'); ?><br />
154
                            <?php _e('If thumbnails cannot be generated, then full-sized, uncropped images will be used instead. This will result in slow page load times, and thumbnails that do not look correct.', 'foogallery'); ?>
155
                            <br/>
156
                        </p>
157
                    </div>
158
                    <?php
159
                }
160
            }
161
        }
162
    }
163
164
}