Plugin Directory

Changeset 2364265


Ignore:
Timestamp:
08/18/2020 07:41:38 PM (6 years ago)
Author:
tferry
Message:

feature: adds links to plugin list table and assets for directory listing

Location:
wp-edit-homepage/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wp-edit-homepage/trunk

    • Property svn:ignore set to
      phpcs.xml.dist
      .git
  • wp-edit-homepage/trunk/includes/class-wp-edit-homepage-plugin.php

    r2354426 r2364265  
    2727            add_action( 'admin_head', array( $this, 'add_global_wp_admin_submenu_filter' ), 15 );
    2828
    29             // Add the homepage edit link.
     29            // Add the homepage edit link to WP admin menu.
    3030            add_filter( 'wpedh_filter_global_wp_admin_submenu', array( $this, 'add_homepage_edit_link' ) );
     31
     32            // Add the homepage edit link to plugins page item.
     33            if ( defined( 'WP_EDIT_HOMEPAGE_BASENAME' ) ) {
     34                add_filter( 'plugin_action_links_' . WP_EDIT_HOMEPAGE_BASENAME, array( $this, 'add_plugins_page_link' ) );
     35            }
    3136        }
    3237
     
    5560         *
    5661         * @param array $submenu An array of WP admin menu items.
     62         *
     63         * @return array The filtered WP admin menu with the home page edit link added (if possible).
    5764         */
    5865        public function add_homepage_edit_link( $submenu ) {
    59 
    60             // Bail early - no 'static' homepage.
    61             if ( get_option( 'show_on_front' ) !== 'page' ) {
    62                 return $submenu;
    63             }
    64 
    65             $homepage_id = get_option( 'page_on_front', 0 );
    66 
    67             // Bail early - homepage not set.
    68             if ( empty( $homepage_id ) ) {
    69                 return $submenu;
    70             }
    71 
    72             // Get admin relative page edit URL.
    73             $homepage_edit_link = get_edit_post_link( $homepage_id );
     66            // Get homepage edit link.
     67            $homepage_edit_link = $this->get_edit_homepage_link();
    7468
    7569            // Bail early - no edit link found.
     
    9084            return $submenu;
    9185        }
     86
     87        /**
     88         * Generates a link to the homepage edit screen.
     89         *
     90         * @return string The link to the homepage edit screen. Empty string on failure.
     91         */
     92        public function get_edit_homepage_link() {
     93            $homepage_edit_link = '';
     94
     95            // Bail early - no 'static' homepage.
     96            if ( get_option( 'show_on_front' ) !== 'page' ) {
     97                return $homepage_edit_link;
     98            }
     99
     100            $homepage_id = get_option( 'page_on_front', 0 );
     101
     102            // Bail early - invalid homepage ID somehow.
     103            if ( empty( $homepage_id ) ) {
     104                return $homepage_edit_link;
     105            }
     106
     107            // Get homepage edit URL.
     108            $homepage_edit_link = get_edit_post_link( $homepage_id );
     109
     110            return $homepage_edit_link;
     111        }
     112
     113        /**
     114         * Filters the list of action links displayed for this plugin in the Plugins list table.
     115         *
     116         * @param array $links An array of plugin action links.
     117         *
     118         * @return array The filtered array of plugin action links.
     119         */
     120        public function add_plugins_page_link( $links ) {
     121            $link = $this->get_edit_homepage_link();
     122            $text = __( 'Edit Homepage', 'wp-edit-homepage' );
     123
     124            // No homepage set - add fallback link to reading page.
     125            if ( empty( $link ) ) {
     126                $link = admin_url( 'options-reading.php' );
     127                $text = __( 'Set Homepage', 'wp-edit-homepage' );
     128            }
     129
     130            // Create the link.
     131            $plugins_page_link = '<a href="' . esc_url( $link ) . '">' . esc_html( $text ) . '</a>';
     132
     133            // Adds the link to the start of the array.
     134            array_unshift( $links, $plugins_page_link );
     135
     136            return $links;
     137        }
    92138    }
    93139}
  • wp-edit-homepage/trunk/readme.txt

    r2354426 r2364265  
    33Tags: edit, homepage, page, admin
    44Requires at least: 5.0
    5 Tested up to: 5.4
    6 Stable tag: 1.0
     5Tested up to: 5.5
     6Stable tag: 1.1
    77Requires PHP: 7.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 A simple WordPress plugin that adds a homepage edit link to the admin sidebar
     11A simple WordPress plugin that adds a homepage edit link to the admin sidebar.
    1212
    1313== Description ==
    1414
    15 This plugin adds a link to the edit screen of your homepage. The link is added in the admin sidebar underneath the default 'Pages' menu item.
     15Bored of hunting down the edit button for your homepage?
    1616
    17 If you don't have a static homepage set, the link will not appear as there's no page to edit.
     17This plugin adds an 'Edit Homepage' link to the WP admin sidebar. The edit link can be found in the admin sidebar: 'Pages > Edit Homepage'.
     18
     19If you don't have a homepage set, the link will simply not appear.
    1820
    1921== Changelog ==
    2022
     23= 1.1 =
     24* Adds edit/set homepage links in plugin list table.
     25* Adds image assets for plugin directory listing.
     26
    2127= 1.0 =
    2228* Adds the homepage edit link to the admin sidebar.
     29
     30== Screenshots ==
     311. Homepage edit link shown as Pages > Edit Homepage
     322. Admin homepage settings on the Settings > Reading screen.
  • wp-edit-homepage/trunk/wp-edit-homepage.php

    r2354426 r2364265  
    77 * @wordpress-plugin
    88 * Plugin Name: WP Edit Homepage
     9 * Plugin URI: https://github.com/tommyferry/wp-edit-homepage
    910 * Description: A simple WordPress plugin that adds a homepage edit link to the admin sidebar
    10  * Version: 1.0
     11 * Version: 1.1
    1112 * Author: Tommy Ferry
    1213 * License: GPLv2 or later
     
    3435}
    3536
     37if ( ! defined( 'WP_EDIT_HOMEPAGE_BASENAME' ) ) {
     38    define( 'WP_EDIT_HOMEPAGE_BASENAME', plugin_basename( __FILE__ ) );
     39}
     40
    3641require_once 'includes/class-wp-edit-homepage-plugin.php';
    3742
Note: See TracChangeset for help on using the changeset viewer.