| Conditions | 4 |
| Paths | 4 |
| Total Lines | 56 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php namespace EmailLog\Core\UI\Component; |
||
| 113 | protected function render_addon( $addon, $bundle_license_active ) { |
||
| 114 | $addon_title = $addon['info']['title']; |
||
| 115 | $addon_thumbnail = $addon['info']['thumbnail']; |
||
| 116 | $addon_description = $addon['info']['excerpt']; |
||
| 117 | $addon_link = $addon['info']['permalink']; |
||
| 118 | $addon_slug = 'email-log-' . $addon['info']['slug']; |
||
| 119 | $addon_file = sprintf( '%1$s/%1$s.php', $addon_slug ); |
||
| 120 | ?> |
||
| 121 | <div class="el-addon"> |
||
| 122 | <h3 class="el-addon-title"> |
||
| 123 | <?php echo esc_html( $addon_title ); ?> |
||
| 124 | </h3> |
||
| 125 | |||
| 126 | <a href="<?php echo esc_url( $addon_link ); ?>" title="<?php echo esc_attr( $addon_title ); ?>"> |
||
| 127 | <img src="<?php echo esc_url( $addon_thumbnail ); ?>" class="attachment-showcase wp-post-image" |
||
| 128 | alt="<?php echo esc_attr( $addon_title ); ?>" title="<?php echo esc_attr( $addon_title ); ?>"> |
||
| 129 | </a> |
||
| 130 | |||
| 131 | <p> |
||
| 132 | <?php echo esc_html( $addon_description ); ?> |
||
| 133 | </p> |
||
| 134 | |||
| 135 | <?php |
||
| 136 | if ( $bundle_license_active ) { |
||
| 137 | $installed_plugins = array_keys( get_plugins() ); |
||
| 138 | |||
| 139 | if ( in_array( $addon_file, $installed_plugins, true ) ) { |
||
| 140 | $actions = '<a disabled class="button button-secondary">' . _x( 'Installed', 'Installed on website but not activated', 'email-log' ); |
||
| 141 | if ( is_plugin_active( $addon_file ) ) { |
||
| 142 | $actions .= ' & ' . _x( 'Activated', 'Installed and activated on website', 'email-log' ) . '</a>'; |
||
| 143 | } else { |
||
| 144 | $activate_url = wp_nonce_url( network_admin_url( 'plugins.php?action=activate&plugin=' . $addon_file ), 'activate-plugin_' . $addon_file ); |
||
| 145 | $actions .= sprintf( '</a> <a class="button button-primary" href="%s">%s</a>', $activate_url, _x( 'Activate', 'Enable addon so it may be used', 'email-log' ) ); |
||
| 146 | } |
||
| 147 | } else { |
||
| 148 | // TODO: Make sure WordPress core can handle add-on installation. |
||
| 149 | $install_url = wp_nonce_url( network_admin_url( 'update.php?action=install-plugin&plugin=' . $addon_slug ), 'install-plugin_' . $addon_slug ); |
||
| 150 | $actions = sprintf( '<a class="button button-primary" href="%s">%s</a>', $install_url, _x( 'Install', 'Download and activate addon', 'email-log' ) ); |
||
| 151 | } |
||
| 152 | |||
| 153 | // TODO: Link correct download url. |
||
| 154 | $download_url = ''; |
||
| 155 | $actions .= sprintf( ' <a class="button button-secondary" href="%s">%s</a>', $download_url, _x( 'Download', 'Download to your computer', 'email-log' ) ); |
||
| 156 | } else { |
||
| 157 | $actions = sprintf( |
||
| 158 | '<a disabled class="button-secondary" title="%s" href="#">%s</a>', |
||
| 159 | __( 'You need an active license to install the add-on', 'email-log' ), |
||
| 160 | _x( 'Install', 'Download and activate addon', 'email-log' ) |
||
| 161 | ); |
||
| 162 | } |
||
| 163 | |||
| 164 | echo $actions; |
||
| 165 | ?> |
||
| 166 | </div> <!-- .el-addon --> |
||
| 167 | <?php |
||
| 168 | } |
||
| 169 | |||
| 186 |