13

How do I get the [View details] link to appear on the Plugin admin page in the Description area?

The plugin is working fine, the version and authors (with links) show up fine, but no [View details] like most other plugins.

Perhaps I'm asking the wrong question, but I'm working on a plugin and I would like to show the readme.txt and screenshots like I see in so many plugins. How do I get this link to appear and show the contents of the readme.txt file?

I've been reading through Professional WordPress Plugin Development, but I can't find this reference. I can refer to an external URI, but I would like the nice and concise panel that shows on other plugins.

0

4 Answers 4

11

The 'View details' link in the installed plugins list table is only shown for plugins that are hosted in the WordPress.org plugin repository. If you take a look at the source for WP_Plugins_List_Table->single_row(), you'll see that the details link is only generated if there's API data present, e.g. the slug is set:

// Details link using API info, if available
if ( isset( $plugin_data['slug'] ) && current_user_can( 'install_plugins' ) ) {
    $plugin_meta[] = sprintf( '<a href="%s" class="thickbox" aria-label="%s" data-title="%s">%s</a>',
        esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] .
            '&TB_iframe=true&width=600&height=550' ) ),
        esc_attr( sprintf( __( 'More information about %s' ), $plugin_name ) ),
        esc_attr( $plugin_name ),
        __( 'View details' )
    );
} elseif ( ! empty( $plugin_data['PluginURI'] ) ) {
    $plugin_meta[] = sprintf( '<a href="%s">%s</a>',
        esc_url( $plugin_data['PluginURI'] ),
        __( 'Visit plugin site' )
    );
}
1

You didn't mention if your plugin is/isn't hosted on WordPress.org, neither if you installed the plug-in from WordPress Plugin Directory or just a local ZIP copy of it (which is the equivalent of a private-hosted plug-in).

As already answered earlier the "View details" link appears only for the plugins which has the slug hosted at WordPress.org.

I just want to emphasize that there are situations when you may not see the "View details" even for a plug-in which is in fact hosted by WordPress.org.

How? In which situation?

Example: just imagine that your plug-in is hosted by them but actually you didn't installed the plugin from WordPress Plugin Directory, instead you installed a local ZIP file (a fresh copy of it while testing a new fix/tweak for instance).

In my example above the installed copy represents the same plug-in but is not installed from WordPress Plugin Directory. It was installed from a local ZIP file which is the equivalent of private-hosted plug-in.

1

If you really want to, you can hook into plugin_row_meta and add your own link.

The problem is that the parsed README is hosted on the WordPress Plugin Directory.
The standard "View Details" link includes /wp-admin/plugin-install.php?tab=plugin-information which calls http://api.wordpress.org/plugins/info/ by default.

Solution / Workaround

  1. Supply your own link.
  2. (Optional) Hook into the WordPress API Response.

Supplying your own link

Assuming you're in your main plugin file, add this:

add_filter(
    'plugin_row_meta',
    function( $plugin_meta, $plugin_file, $plugin_data ) {
        if ( __FILE__ === path_join( WP_PLUGIN_DIR, $plugin_file ) ) {
            // Here you supply the link to your README. 
            // I've converted my `readme.txt` to HTML. More on that later...
            $url = plugins_url( 'readme.html', __FILE__ );

            // This is an adaptation of part of `WP_Plugins_List_Table->single_row()`.
            $plugin_meta[] = sprintf(
                '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
                add_query_arg( 'TB_iframe', 'true', $url ),
                esc_attr( sprintf( __( 'More information about %s' ), $plugin_data['Name'] ) ),
                esc_attr( $plugin_data['Name'] ),
                __( 'View details' )
            );
        }
        return $plugin_meta;
    },
    10,
    3
);

Hooking into the WordPress API Response.

Again, assuming you're in your main plugin file, you have to add the link and hook into the API response:

$slug = 'slug-of-your-plugin-or-some-id';

add_filter(
    'plugin_row_meta',
    function( $plugin_meta, $plugin_file, $plugin_data ) {
        if ( __FILE__ === path_join( WP_PLUGIN_DIR, $plugin_file ) ) {
            // This is an adaptation of part of `WP_Plugins_List_Table->single_row()`.
            $plugin_meta[] = sprintf(
                '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
                esc_url(
                    network_admin_url(
                        "plugin-install.php?tab=plugin-information&plugin=$slug&TB_iframe=true&width=600&height=550"
                    )
                ),
                esc_attr( sprintf( __( 'More information about %s' ), $plugin_data['Name'] ) ),
                esc_attr( $plugin_data['Name'] ),
                __( 'View details' )
            );
        }
        return $plugin_meta;
    },
    10,
    3
);

add_filter(
    'plugins_api',
    function( $response, $action, $args ) {
        if ( 'plugin_information' === $action && $slug === $args->slug ) {
            return (object) array(
                // Mock the response from the WordPress Plugin Directory.
                // For an example request inspect
                // https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request[slug]=classic-editor
            );
        }
        return $response;
    },
    10,
    3
);

Appendix: Converting an existing README

If you've already written your readme.txt without realizing that it won't show (like myself...), you could convert it to HTML and use the first snippet from above.

Put this in your package.json:

{
  "main": "Gruntfile.js",
  "scripts": {
    "readme": "grunt readme"
  },
  "devDependencies": {
    "grunt": "^1.6.1",
    "grunt-md2html": "^0.6.1",
    "grunt-wp-readme-to-markdown": "^2.1.0"
  }
}

And this goes into your Gruntfile.js:

module.exports = function (grunt) {

    grunt.initConfig({

        pkg: grunt.file.readJSON('package.json'),

        wp_readme_to_markdown: {
            your_target: {
                files: {
                    'README.md': 'readme.txt',
                },
            },
            options: {
                // Optional: Only if you want to include screenshots.
                screenshot_url: 'assets/{screenshot}.png',
            },
        },

        md2html: {
            your_target: {
                files: {
                    'readme.html': 'README.md',
                },
            },
        },
    });

    grunt.loadNpmTasks('grunt-wp-readme-to-markdown');
    grunt.loadNpmTasks('grunt-md2html');
    grunt.registerTask('readme', ['wp_readme_to_markdown', 'md2html']);

};

Now run npm install && npm run readme and you'll see a readme.html in your plugin directory.

0

If you rename the folder that the plugin files are contained in... WordPress will use your Plugin URI stated in the header of the main plugin file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.