Plugin Directory

Changeset 2967453


Ignore:
Timestamp:
09/15/2023 11:04:02 AM (3 years ago)
Author:
jlil
Message:

adminbarLink

Location:
postpeek
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • postpeek/trunk/postpeek.php

    r2967398 r2967453  
    33/**
    44 * Plugin Name: PostPeek
    5  * Description: PostPeek: Immediate Post Insights, a convenient plugin that adds a direct link to search console stats for each post within your WordPress dashboard.
    6  * Version: 1.0.4
     5 * Description: PostPeek: Immediate Post Insights, a convenient plugin that adds a direct link to search console stats for each post.
     6 * Version: 1.1.1
    77 * Tested up to: 6.3
    88 * Author: Jlil
     
    3737        add_action('admin_menu', array($this, 'postpeek_options_page'));
    3838        add_action('admin_init', array($this, 'postpeek_settings_init'));
    39     }
     39
     40        // Hook the function into the 'admin_bar_menu' action
     41        add_action('admin_bar_menu', array($this, 'add_admin_bar_search_console_link'), 999);
     42    }
     43
     44
     45    public function add_admin_bar_search_console_link($wp_admin_bar)
     46    {
     47        // Check if the user has the necessary capabilities.
     48        if (!$this->user_has_capability()) {
     49            return;
     50        }
     51
     52        // Fetch plugin options
     53        $options = get_option('postpeek_options', array());
     54
     55        // Determine account type
     56        $site_type = isset($options['site_type']) ? $options['site_type'] : 'url_prefix';
     57
     58        // Create the resource identifier based on the account type
     59        $home_url = home_url(); // Get the full URL
     60        $parsed_url = parse_url($home_url); // Parse the URL
     61        $host = $parsed_url['host']; // Extract the host component
     62
     63        // When using [domain_property], must extract only the host, [example.com], not [https://example.com]
     64        $resource_id = ($site_type === 'domain_property') ? "sc-domain:$host" : home_url();
     65
     66        // Get default_date_period from options, or set it to 7 days if not set
     67        $default_date_period = isset($options['default_date_period']) ? $options['default_date_period'] : 'num_of_days=7';
     68
     69        // Define the link based on whether the user is in the admin area or the frontend
     70        // Determine the URL to point to based on the current page context
     71        if (is_admin()) {
     72            $page_url = '&page=!' . esc_url($home_url);
     73        } elseif (is_home() || is_front_page() || is_search()) {
     74            $page_url = '&page=!' . esc_url($home_url);
     75        } elseif (is_single() || is_page()) {
     76            $page_url = '&page=!' . esc_url(get_permalink());
     77        } elseif (is_category() || is_tag() || is_tax()) {
     78            $term = get_queried_object();
     79            $page_url = '&page=!' . esc_url(get_term_link($term));
     80        } else {
     81            $page_url = '&page=!' . esc_url($home_url); // Fallback to home URL
     82        }
     83
     84        // Create the complete URL
     85        $search_console_url = "https://search.google.com/search-console/performance/search-analytics?resource_id=" . $resource_id . $page_url . "&" . esc_attr($default_date_period);
     86
     87        // Add the Search Console link to the admin bar
     88        $args = array(
     89            'id' => 'search_console',
     90            'title' => 'Search Console',
     91            'href' => $search_console_url,
     92            'meta' => array(
     93                'target' => '_blank',
     94                'class' => 'google_link'
     95            )
     96        );
     97        $wp_admin_bar->add_node($args);
     98    }
     99
     100
     101
     102
     103
    40104
    41105    public function postpeek_settings_init()
     
    54118        add_settings_field(
    55119            'postpeek_site_type',
    56             'Search Console Account Type',
     120            'Search Console Site Type',
    57121            array($this, 'postpeek_site_type_render'),
    58122            'postpeek',
  • postpeek/trunk/readme.txt

    r2967398 r2967453  
    1 === PostPeek: One-Click Access to Your Search Console Stats ===
     1=== PostPeek - One-Click Access to Your Search Console ===
    22
    33Contributors: jlil
     
    55Requires at least: 4.0
    66Tested up to: 6.3
    7 Stable tag: 1.0.4
     7Stable tag: 1.1.1
    88License: GPL-2.0-or-later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    30302. **User Role Filter**: Specify which user roles can see the "Search Console" link in the Quick Actions menu.
    31313. **Default Report Timeframe**: Set the default time period for the report displayed when accessing Google Search Console.
     32
     33== New Feature: Admin Bar Search Console Link ==
     34
     35Admin Bar Quick Access to Google Search Console
     36
     37We've introduced a new feature that allows you to quickly access Google Search Console directly from your WordPress Admin Bar. This link dynamically updates based on where you are in the WordPress dashboard or the frontend of your site:
     38
     391. **Admin Area**: The link directs you to Search Console statistics for your homepage.
     402. **Frontend**: If you're on a post, page, category, or tag, the link directs you to the relevant Search Console statistics.
     41
     42This saves you time and provides immediate insights without having to leave your website.
    3243
    3344== How to Use ==
     
    61721. PostPeek-search-console-link Example
    62732. PostPeek Settings
     743. Admin Bar Search Console Link
    6375
    6476== Installation ==
     
    7486== Changelog ==
    7587
    76 = 1.0.4 =
     88= 1.1.1 [15-09-2023] =
     89* Added "Admin Bar Search Console Link" feature.
     90
     91= 1.1.0 [15-09-2023] =
    7792* Added "Default Report Timeframe" feature.
    7893* Fixed a minor bug related to user role permissions.
    7994* Updated plugin description and documentation.
    8095
    81 = 1.0.3 =
     96= 1.0.3 [14-09-2023] =
    8297* Fixed a minor bug.
    8398
    84 = 1.0.2 =
     99= 1.0.2 [14-09-2023] =
    85100* Introduced "User Role Filter" to specify which roles can see the "Search Console" link.
    86101
    87 = 1.0.1 =
     102= 1.0.1 [13-09-2023] =
    88103* Added the "Site Type Selection" option for Google Search Console.
    89104* Initial public release after beta testing.
Note: See TracChangeset for help on using the changeset viewer.