Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 47 additions & 56 deletions class-tgm-plugin-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -810,36 +810,9 @@ public function notices() {
// Loop through the plugin names to make the ones pulled from the .org repo linked.
foreach ( $plugin_group as $plugin_slug ) {

if ( ! empty( $this->plugins[ $plugin_slug ]['external_url'] ) && preg_match( self::EXT_REPO_REGEX, $this->plugins[ $plugin_slug ]['external_url'] ) ) {
$linked_plugins[] = sprintf(
'<a href="%1$s" target="_blank">%2$s</a>',
esc_url( $this->plugins[ $plugin_slug ]['external_url'] ),
esc_html( $this->plugins[ $plugin_slug ]['name'] )
);

} elseif ( 'repo' === $this->plugins[ $plugin_slug ]['source'] || preg_match( self::WP_REPO_REGEX, $this->plugins[ $plugin_slug ]['source'] ) ) {
$url = add_query_arg(
array(
'tab' => 'plugin-information',
'plugin' => urlencode( $plugin_slug ),
'TB_iframe' => 'true',
'width' => '640',
'height' => '500',
),
self_admin_url( 'plugin-install.php' )
);

$linked_plugins[] = sprintf(
'<a href="%1$s" class="thickbox">%2$s</a>',
esc_url( $url ),
esc_html( $this->plugins[ $plugin_slug ]['name'] )
);

} else {
$linked_plugins[] = esc_html( $this->plugins[ $plugin_slug ]['name'] ); // No hyperlink.
}
$linked_plugins[] = $this->get_info_link( $plugin_slug );
}
unset( $plugin_slug, $url );
unset( $plugin_slug );

$count = count( $plugin_group );
$last_plugin = array_pop( $linked_plugins ); // Pop off last name to prep for readability.
Expand Down Expand Up @@ -1182,6 +1155,50 @@ protected function get_wp_repo_download_url( $slug ) {

}

/**
* Retrieve a link to a plugin information page.
*
* @since 2.5.0
*
* @param string $slug Plugin slug
*
* @return string Fully formed html link to a plugin information page if available or the plugin name if not.
*/
public function get_info_link( $slug ) {
$link = '';

if ( ! empty( $this->plugins[ $slug ]['external_url'] ) && preg_match( self::EXT_REPO_REGEX, $this->plugins[ $slug ]['external_url'] ) ) {
$link = sprintf(
'<a href="%1$s" target="_blank">%2$s</a>',
esc_url( $this->plugins[ $slug ]['external_url'] ),
esc_html( $this->plugins[ $slug ]['name'] )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, but as a side note for future consideration.

With all of these "get some value about a single plugin", it might be nice to have the plugins registered as arrays, but stored as a TGM_Plugin, so that each value can grabbed as a property (either actual properties, or via __get() with whitelist etc.

// top of this function
$plugin = $this->plugins[ $slug ];

// This line:
esc_url( $plugin->external_url ),
esc_html( $plugin->name )

(Yes, the "top of this function" shortcut could be used anyway.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, same for abstracting the whole notices functionality to it's own class. There's plenty to do, but not everything needs to be done now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hence "for future consideration".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to open issues for all the 'for future consideration' improvements. Makes more sense to me then burying them in PRs which will be merged & closed soon.

);

} elseif ( 'repo' === $this->plugins[ $slug ]['source'] || preg_match( self::WP_REPO_REGEX, $this->plugins[ $slug ]['source'] ) ) {
$url = add_query_arg(
array(
'tab' => 'plugin-information',
'plugin' => urlencode( $slug ),
'TB_iframe' => 'true',
'width' => '640',
'height' => '500',
),
self_admin_url( 'plugin-install.php' )
);

$link = sprintf(
'<a href="%1$s" class="thickbox">%2$s</a>',
esc_url( $url ),
esc_html( $this->plugins[ $slug ]['name'] )
);

} else {
$link = esc_html( $this->plugins[ $slug ]['name'] ); // No hyperlink.
}

return $link;
}

/**
* Determine if we're on the TGMPA Install page.
*
Expand Down Expand Up @@ -1428,33 +1445,7 @@ protected function _gather_plugin_data() {

$table_data[ $i ]['sanitized_plugin'] = $plugin['name'];
$table_data[ $i ]['slug'] = $slug;

if ( ! empty( $plugin['external_url'] ) && preg_match( TGM_Plugin_Activation::EXT_REPO_REGEX, $plugin['external_url'] ) ) {
$table_data[ $i ]['plugin'] = sprintf(
'<strong><a href="%1$s" target="_blank">%2$s</a></strong>',
esc_url( $plugin['external_url'] ),
esc_html( $plugin['name'] )
);
} elseif ( 'repo' === $plugin['source'] || preg_match( TGM_Plugin_Activation::WP_REPO_REGEX, $plugin['source'] ) ) {
$url = add_query_arg(
array(
'tab' => 'plugin-information',
'plugin' => urlencode( $slug ),
'TB_iframe' => 'true',
'width' => '640',
'height' => '500',
),
self_admin_url( 'plugin-install.php' )
);

$table_data[ $i ]['plugin'] = sprintf(
'<strong><a href="%1$s" class="thickbox">%2$s</a></strong>',
esc_url( $url ),
esc_html( $plugin['name'] )
);
} else {
$table_data[ $i ]['plugin'] = '<strong>' . esc_html( $plugin['name'] ) . '</strong>'; // No hyperlink.
}
$table_data[ $i ]['plugin'] = '<strong>' . $this->tgmpa->get_info_link( $slug ) . '</strong>';

if ( 'repo' !== $plugin['source'] && preg_match( TGM_Plugin_Activation::WP_REPO_REGEX, $plugin['source'] ) !== 1 ) {
if ( preg_match( TGM_Plugin_Activation::EXT_REPO_REGEX, $plugin['source'] ) ) {
Expand Down