PluginProbe
Parse.ly / 3.24.2
Parse.ly v3.24.2
3.24.2 3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 All 106 releases
← All changes | src/UI/class-admin-bar.php +31 -15 3.2.1 → 3.24.2 View file →
@@ -1,10 +1,12 @@
1 1 <?php
2 2 /**
3 - * Parsely tweaks to WordPress admin bar
3 + * UI: Admin bar class
4 4 *
5 + * Enhances the WordPress admin bar with Parse.ly tweaks.
6 + *
5 7 * @package Parsely
6 - * @since 3.1.0
8 + * @since 3.1.0
7 9 */
8 10
9 11 declare(strict_types=1);
10 12
@@ -9,14 +11,15 @@
9 11 declare(strict_types=1);
10 12
11 13 namespace Parsely\UI;
12 14
15 +use WP_Post;
13 16 use WP_Admin_Bar;
14 17 use Parsely\Parsely;
15 18 use Parsely\Dashboard_Link;
16 19
17 20 /**
18 - * Render Parse.ly related buttons in the WordPress administrator top bar.
21 + * Renders Parse.ly related buttons in the WordPress administrator top bar.
19 22 *
20 23 * @since 3.1.0
21 24 */
22 25 final class Admin_Bar {
@@ -36,17 +39,16 @@
36 39 $this->parsely = $parsely;
37 40 }
38 41
39 42 /**
40 - * Register admin bar buttons.
43 + * Registers admin bar buttons.
41 44 *
42 45 * @since 3.1.0
43 - *
44 - * @return void
45 46 */
46 47 public function run(): void {
47 48 /**
48 - * Filter whether the Open on Parse.ly button is enabled or not on the admin bar menu.
49 + * Filter whether the Open on Parse.ly button is enabled or not on the
50 + * admin bar menu.
49 51 *
50 52 * @since 3.1.2
51 53 *
52 54 * @param bool $enabled True if enabled, false if not.
@@ -57,24 +59,38 @@
57 59 }
58 60 }
59 61
60 62 /**
61 - * Adds the `Parse.ly Stats` button on the admin bar when the current object is a post or a page.
63 + * Adds the "Parse.ly Stats" button on the admin bar when the current object
64 + * is a post or a page.
62 65 *
63 66 * @param WP_Admin_Bar $admin_bar WP_Admin_Bar instance, passed by reference.
64 - *
65 - * @return void
66 67 */
67 68 public function admin_bar_parsely_stats_button( WP_Admin_Bar $admin_bar ): void {
68 - $current_object = $GLOBALS['wp_the_query']->get_queried_object();
69 + /**
70 + * The result of calling get_queried_object().
71 + *
72 + * Although it shouldn't return false per the documentation, it can
73 + * happen in practice.
74 + *
75 + * @var \WP_Term|\WP_Post_Type|WP_Post|\WP_User|null|false
76 + */
77 + $queried_object = $GLOBALS['wp_the_query']->get_queried_object();
69 78
70 - if ( null === $current_object || empty( $current_object->post_type ) ) {
79 + if ( ! $queried_object instanceof WP_Post ) {
71 80 return;
72 81 }
73 82
74 - $post_type_object = get_post_type_object( $current_object->post_type );
75 - if ( null !== $post_type_object && $post_type_object->show_in_admin_bar && Dashboard_Link::can_show_link( $current_object, $this->parsely ) ) {
76 - $href = Dashboard_Link::generate_url( $current_object, $this->parsely->get_api_key(), 'wp-page-single', 'admin-bar' );
83 + /**
84 + * Variable.
85 + *
86 + * @var WP_Post
87 + */
88 + $current_post = $queried_object;
89 +
90 + $post_type_object = get_post_type_object( $current_post->post_type );
91 + if ( null !== $post_type_object && $post_type_object->show_in_admin_bar && Dashboard_Link::can_show_link( $current_post, $this->parsely ) ) {
92 + $href = Dashboard_Link::generate_url( $current_post, $this->parsely->get_site_id(), 'wp-page-single', 'admin-bar' );
77 93
78 94 // Not adding the link if there were issues generating the URL.
79 95 if ( '' !== $href ) {
80 96 $admin_bar->add_node(