TGMPA / TGM-Plugin-Activation

TGM Plugin Activation is a PHP library that allows you to easily require or recommend plugins for your WordPress themes (and plugins). It allows your users to install, update and even automatically activate plugins in singular or bulk fashion using native WordPress classes, functions and interfaces. You can reference bundled plugins, plugins from the WordPress Plugin Repository or even plugins hosted elsewhere on the internet.
http://tgmpluginactivation.com/
GNU General Public License v2.0
1.76k stars 429 forks source link

Add Another Source Option #100

Closed wpsmith closed 10 years ago

wpsmith commented 12 years ago

Currently, to me the differences between external_link and source are so subtle and I am not sure the functional difference. According to tgmpa.com:

source - The source of the plugin. This parameter is required if the plugin you are referencing is not from the WordPress Plugin Repository. You can reference either pre-packaged plugins or plugins elsewhere on the internet from this parameter. external_url - An external URL for the plugin. By default, plugins referenced from the WordPress Plugin Repository are linked to their plugin information via thickbox. This parameter overrides this default behavior and allows you to specify any URL for the plugin.

So I think tgmpa should answer the following questions:

And regardless, I think the class needs something different from these. Consider the user who would like to use the class to recommend other premium plugins from CodeCanyon or even Soliloquywp.com. I believe an additional option is needed, one that does not add an Install hover link but a Purchase hover link.

Here are some options

  1. Check the source URL to see if there is a *.zip (if not, add purchase); however, I think that too is shortsighted (e.g., URLs that use parameters, etc).
  2. Add another arg like source_type to the plugins array. This allows the user to short-circuit everything.
  3. Assume if external_url and source are both set that it refers to a purchase of some plugin instead; however, with the confusion btw the two, this may not be the best approach.

Assuming option #2:

if ( isset( $plugin['source_type'] ) ) {
    /** The plugin is linked to an external source */
    $table_data[$i]['source'] = $plugin['source_type'];
}
elseif ( isset( $plugin['external_url'] ) ) {
    /** The plugin is linked to an external source */
    $table_data[$i]['source'] = __( 'External Link', TGM_Plugin_Activation::$instance->domain );
}

Assuming option #3:

if ( isset( $plugin['external_url'] ) && isset( $plugin['source'] ) ) {
    /** The plugin is linked to an external source */
    $table_data[$i]['source'] = __( 'Private External Link', TGM_Plugin_Activation::$instance->domain );
}
elseif ( isset( $plugin['external_url'] ) ) {
    /** The plugin is linked to an external source */
    $table_data[$i]['source'] = __( 'External Link', TGM_Plugin_Activation::$instance->domain );
}

I favor option 2.

wpsmith commented 12 years ago

Then this will impact the Install link, so something like this should be added:

/** We need to display the 'Purchase' hover link %% */
if ( isset( $item['source'] ) && (
        __( 'External Link', TGM_Plugin_Activation::$instance->domain ) != $item['source'] ||
        __( 'Private Repository', TGM_Plugin_Activation::$instance->domain ) != $item['source'] ||
        __( 'Pre-Packaged', TGM_Plugin_Activation::$instance->domain ) != $item['source'] ||
        __( 'WordPress Repository', TGM_Plugin_Activation::$instance->domain ) != $item['source']
    )
    ) {
    $actions = array(
        'install' => sprintf(
            '<a href="%1$s" title="' . __( 'Purchase', TGM_Plugin_Activation::$instance->domain ) . ' %2$s">' . __( 'Purchase', TGM_Plugin_Activation::$instance->domain ) . '</a>',
            wp_nonce_url(
                add_query_arg(
                    array(
                        'page'          => TGM_Plugin_Activation::$instance->menu,
                        'plugin'        => $item['slug'],
                        'plugin_name'   => $item['sanitized_plugin'],
                        'plugin_source' => $item['url'],
                        'tgmpa-install' => 'install-plugin',
                    ),
                    admin_url( TGM_Plugin_Activation::$instance->parent_url_slug )
                ),
                'tgmpa-install'
            ),
            $item['sanitized_plugin']
        ),
    );
}
/** We need to display the 'Install' hover link */
elseif ( ! isset( $installed_plugins[$item['file_path']] ) ) {
    $actions = array(
        'install' => sprintf(
            '<a href="%1$s" title="Install %2$s">Install</a>',
            wp_nonce_url(
                add_query_arg(
                    array(
                        'page'          => TGM_Plugin_Activation::$instance->menu,
                        'plugin'        => $item['slug'],
                        'plugin_name'   => $item['sanitized_plugin'],
                        'plugin_source' => $item['url'],
                        'tgmpa-install' => 'install-plugin',
                    ),
                    admin_url( TGM_Plugin_Activation::$instance->parent_url_slug )
                ),
                'tgmpa-install'
            ),
            $item['sanitized_plugin']
        ),
    );
}