Add Another Source Option #100

Closed
wpsmith opened this Issue May 20, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@wpsmith

wpsmith commented May 20, 2012

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:

  • How does source and external link differ?
  • Why does External Source take precendent over source?

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

This comment has been minimized.

Show comment Hide comment
@wpsmith

wpsmith May 20, 2012

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']
        ),
    );
}

wpsmith commented May 20, 2012

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']
        ),
    );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment