mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * WordPress Plugin Install Administration API
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * Retrieve plugin installer pages from WordPress Plugins API.
mp-wp_genesis 11 *
mp-wp_genesis 12 * It is possible for a plugin to override the Plugin API result with three
mp-wp_genesis 13 * filters. Assume this is for plugins, which can extend on the Plugin Info to
mp-wp_genesis 14 * offer more choices. This is very powerful and must be used with care, when
mp-wp_genesis 15 * overridding the filters.
mp-wp_genesis 16 *
mp-wp_genesis 17 * The first filter, 'plugins_api_args', is for the args and gives the action as
mp-wp_genesis 18 * the second parameter. The hook for 'plugins_api_args' must ensure that an
mp-wp_genesis 19 * object is returned.
mp-wp_genesis 20 *
mp-wp_genesis 21 * The second filter, 'plugins_api', is the result that would be returned.
mp-wp_genesis 22 *
mp-wp_genesis 23 * @since 2.7.0
mp-wp_genesis 24 *
mp-wp_genesis 25 * @param string $action
mp-wp_genesis 26 * @param array|object $args Optional. Arguments to serialize for the Plugin Info API.
mp-wp_genesis 27 * @return mixed
mp-wp_genesis 28 */
mp-wp_genesis 29 function plugins_api($action, $args = null) {
mp-wp_genesis 30
mp-wp_genesis 31 if( is_array($args) )
mp-wp_genesis 32 $args = (object)$args;
mp-wp_genesis 33
mp-wp_genesis 34 if ( !isset($args->per_page) )
mp-wp_genesis 35 $args->per_page = 24;
mp-wp_genesis 36
mp-wp_genesis 37 $args = apply_filters('plugins_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter.
mp-wp_genesis 38 $res = apply_filters('plugins_api', false, $action, $args); //NOTE: Allows a plugin to completely override the builtin WordPress.org API.
mp-wp_genesis 39
mp-wp_genesis 40 if ( ! $res ) {
mp-wp_genesis 41 $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) );
mp-wp_genesis 42 if ( is_wp_error($request) ) {
mp-wp_genesis 43 $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occured during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message() );
mp-wp_genesis 44 } else {
mp-wp_genesis 45 $res = unserialize($request['body']);
mp-wp_genesis 46 if ( ! $res )
mp-wp_genesis 47 $res = new WP_Error('plugins_api_failed', __('An unknown error occured'), $request['body']);
mp-wp_genesis 48 }
mp-wp_genesis 49 }
mp-wp_genesis 50
mp-wp_genesis 51 return apply_filters('plugins_api_result', $res, $action, $args);
mp-wp_genesis 52 }
mp-wp_genesis 53
mp-wp_genesis 54 /**
mp-wp_genesis 55 * Retrieve popular WordPress plugin tags.
mp-wp_genesis 56 *
mp-wp_genesis 57 * @since 2.7.0
mp-wp_genesis 58 *
mp-wp_genesis 59 * @param array $args
mp-wp_genesis 60 * @return array
mp-wp_genesis 61 */
mp-wp_genesis 62 function install_popular_tags( $args = array() ) {
mp-wp_genesis 63 if ( ! ($cache = wp_cache_get('popular_tags', 'api')) && ! ($cache = get_option('wporg_popular_tags')) )
mp-wp_genesis 64 add_option('wporg_popular_tags', array(), '', 'no'); ///No autoload.
mp-wp_genesis 65
mp-wp_genesis 66 if ( $cache && $cache->timeout + 3 * 60 * 60 > time() )
mp-wp_genesis 67 return $cache->cached;
mp-wp_genesis 68
mp-wp_genesis 69 $tags = plugins_api('hot_tags', $args);
mp-wp_genesis 70
mp-wp_genesis 71 if ( is_wp_error($tags) )
mp-wp_genesis 72 return $tags;
mp-wp_genesis 73
mp-wp_genesis 74 $cache = (object) array('timeout' => time(), 'cached' => $tags);
mp-wp_genesis 75
mp-wp_genesis 76 update_option('wporg_popular_tags', $cache);
mp-wp_genesis 77 wp_cache_set('popular_tags', $cache, 'api');
mp-wp_genesis 78
mp-wp_genesis 79 return $tags;
mp-wp_genesis 80 }
mp-wp_genesis 81 add_action('install_plugins_search', 'install_search', 10, 1);
mp-wp_genesis 82
mp-wp_genesis 83 /**
mp-wp_genesis 84 * Display search results and display as tag cloud.
mp-wp_genesis 85 *
mp-wp_genesis 86 * @since 2.7.0
mp-wp_genesis 87 *
mp-wp_genesis 88 * @param string $page
mp-wp_genesis 89 */
mp-wp_genesis 90 function install_search($page) {
mp-wp_genesis 91 $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
mp-wp_genesis 92 $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
mp-wp_genesis 93
mp-wp_genesis 94 $args = array();
mp-wp_genesis 95
mp-wp_genesis 96 switch( $type ){
mp-wp_genesis 97 case 'tag':
mp-wp_genesis 98 $args['tag'] = sanitize_title_with_dashes($term);
mp-wp_genesis 99 break;
mp-wp_genesis 100 case 'term':
mp-wp_genesis 101 $args['search'] = $term;
mp-wp_genesis 102 break;
mp-wp_genesis 103 case 'author':
mp-wp_genesis 104 $args['author'] = $term;
mp-wp_genesis 105 break;
mp-wp_genesis 106 }
mp-wp_genesis 107
mp-wp_genesis 108 $args['page'] = $page;
mp-wp_genesis 109
mp-wp_genesis 110 $api = plugins_api('query_plugins', $args);
mp-wp_genesis 111
mp-wp_genesis 112 if ( is_wp_error($api) )
mp-wp_genesis 113 wp_die($api);
mp-wp_genesis 114
mp-wp_genesis 115 add_action('install_plugins_table_header', 'install_search_form');
mp-wp_genesis 116
mp-wp_genesis 117 display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
mp-wp_genesis 118
mp-wp_genesis 119 return;
mp-wp_genesis 120 }
mp-wp_genesis 121
mp-wp_genesis 122 add_action('install_plugins_dashboard', 'install_dashboard');
mp-wp_genesis 123 function install_dashboard() {
mp-wp_genesis 124 ?>
mp-wp_genesis 125 <p><?php _e('Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the <a href="http://wordpress.org/extend/plugins/">WordPress Plugin Directory</a> or upload a plugin in .zip format via this page.') ?></p>
mp-wp_genesis 126
mp-wp_genesis 127 <h4><?php _e('Search') ?></h4>
mp-wp_genesis 128 <?php install_search_form('<a href="' . add_query_arg('show-help', !isset($_REQUEST['show-help'])) .'" onclick="jQuery(\'#search-help\').toggle(); return false;">' . __('[need help?]') . '</a>') ?>
mp-wp_genesis 129 <div id="search-help" style="display: <?php echo isset($_REQUEST['show-help']) ? 'block' : 'none'; ?>;">
mp-wp_genesis 130 <p> <?php _e('You may search based on 3 criteria:') ?><br />
mp-wp_genesis 131 <?php _e('<strong>Term:</strong> Searches plugins names and descriptions for the specified term') ?><br />
mp-wp_genesis 132 <?php _e('<strong>Tag:</strong> Searches for plugins tagged as such') ?><br />
mp-wp_genesis 133 <?php _e('<strong>Author:</strong> Searches for plugins created by the Author, or which the Author contributed to.') ?></p>
mp-wp_genesis 134 </div>
mp-wp_genesis 135
mp-wp_genesis 136 <h4><?php _e('Install a plugin in .zip format') ?></h4>
mp-wp_genesis 137 <p><?php _e('If you have a plugin in a .zip format, You may install it by uploading it here.') ?></p>
mp-wp_genesis 138 <form method="post" enctype="multipart/form-data" action="<?php echo admin_url('plugin-install.php?tab=upload') ?>">
mp-wp_genesis 139 <?php wp_nonce_field( 'plugin-upload') ?>
mp-wp_genesis 140 <input type="file" name="pluginzip" />
mp-wp_genesis 141 <input type="submit" class="button" value="<?php _e('Install Now') ?>" />
mp-wp_genesis 142 </form>
mp-wp_genesis 143
mp-wp_genesis 144 <h4><?php _e('Popular tags') ?></h4>
mp-wp_genesis 145 <p><?php _e('You may also browse based on the most popular tags in the Plugin Directory:') ?></p>
mp-wp_genesis 146 <?php
mp-wp_genesis 147
mp-wp_genesis 148 $api_tags = install_popular_tags();
mp-wp_genesis 149
mp-wp_genesis 150 //Set up the tags in a way which can be interprated by wp_generate_tag_cloud()
mp-wp_genesis 151 $tags = array();
mp-wp_genesis 152 foreach ( (array)$api_tags as $tag )
mp-wp_genesis 153 $tags[ $tag['name'] ] = (object) array(
mp-wp_genesis 154 'link' => clean_url( admin_url('plugin-install.php?tab=search&type=tag&s=' . urlencode($tag['name'])) ),
mp-wp_genesis 155 'name' => $tag['name'],
mp-wp_genesis 156 'id' => sanitize_title_with_dashes($tag['name']),
mp-wp_genesis 157 'count' => $tag['count'] );
mp-wp_genesis 158 echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%d plugin'), 'multiple_text' => __('%d plugins') ) );
mp-wp_genesis 159 }
mp-wp_genesis 160
mp-wp_genesis 161 /**
mp-wp_genesis 162 * Display search form for searching plugins.
mp-wp_genesis 163 *
mp-wp_genesis 164 * @since 2.7.0
mp-wp_genesis 165 */
mp-wp_genesis 166 function install_search_form(){
mp-wp_genesis 167 $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
mp-wp_genesis 168 $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
mp-wp_genesis 169
mp-wp_genesis 170 ?><form id="search-plugins" method="post" action="<?php echo admin_url('plugin-install.php?tab=search') ?>">
mp-wp_genesis 171 <select name="type" id="typeselector">
mp-wp_genesis 172 <option value="term"<?php selected('term', $type) ?>><?php _e('Term') ?></option>
mp-wp_genesis 173 <option value="author"<?php selected('author', $type) ?>><?php _e('Author') ?></option>
mp-wp_genesis 174 <option value="tag"<?php selected('tag', $type) ?>><?php _e('Tag') ?></option>
mp-wp_genesis 175 </select>
mp-wp_genesis 176 <input type="text" name="s" id="search-field" value="<?php echo attribute_escape($term) ?>" />
mp-wp_genesis 177 <input type="submit" name="search" value="<?php echo attribute_escape(__('Search')) ?>" class="button" />
mp-wp_genesis 178 </form><?php
mp-wp_genesis 179 }
mp-wp_genesis 180
mp-wp_genesis 181 add_action('install_plugins_featured', 'install_featured', 10, 1);
mp-wp_genesis 182 /**
mp-wp_genesis 183 * Display featured plugins.
mp-wp_genesis 184 *
mp-wp_genesis 185 * @since 2.7.0
mp-wp_genesis 186 *
mp-wp_genesis 187 * @param string $page
mp-wp_genesis 188 */
mp-wp_genesis 189 function install_featured($page = 1) {
mp-wp_genesis 190 $args = array('browse' => 'featured', 'page' => $page);
mp-wp_genesis 191 $api = plugins_api('query_plugins', $args);
mp-wp_genesis 192 if ( is_wp_error($api) )
mp-wp_genesis 193 wp_die($api);
mp-wp_genesis 194 display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
mp-wp_genesis 195 }
mp-wp_genesis 196
mp-wp_genesis 197 add_action('install_plugins_popular', 'install_popular', 10, 1);
mp-wp_genesis 198 /**
mp-wp_genesis 199 * Display popular plugins.
mp-wp_genesis 200 *
mp-wp_genesis 201 * @since 2.7.0
mp-wp_genesis 202 *
mp-wp_genesis 203 * @param string $page
mp-wp_genesis 204 */
mp-wp_genesis 205 function install_popular($page = 1) {
mp-wp_genesis 206 $args = array('browse' => 'popular', 'page' => $page);
mp-wp_genesis 207 $api = plugins_api('query_plugins', $args);
mp-wp_genesis 208 display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
mp-wp_genesis 209 }
mp-wp_genesis 210
mp-wp_genesis 211 add_action('install_plugins_new', 'install_new', 10, 1);
mp-wp_genesis 212 /**
mp-wp_genesis 213 * Display new plugins.
mp-wp_genesis 214 *
mp-wp_genesis 215 * @since 2.7.0
mp-wp_genesis 216 *
mp-wp_genesis 217 * @param string $page
mp-wp_genesis 218 */
mp-wp_genesis 219 function install_new($page = 1) {
mp-wp_genesis 220 $args = array('browse' => 'new', 'page' => $page);
mp-wp_genesis 221 $api = plugins_api('query_plugins', $args);
mp-wp_genesis 222 if ( is_wp_error($api) )
mp-wp_genesis 223 wp_die($api);
mp-wp_genesis 224 display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
mp-wp_genesis 225 }
mp-wp_genesis 226 add_action('install_plugins_updated', 'install_updated', 10, 1);
mp-wp_genesis 227
mp-wp_genesis 228
mp-wp_genesis 229 /**
mp-wp_genesis 230 * Display recently updated plugins.
mp-wp_genesis 231 *
mp-wp_genesis 232 * @since 2.7.0
mp-wp_genesis 233 *
mp-wp_genesis 234 * @param string $page
mp-wp_genesis 235 */
mp-wp_genesis 236 function install_updated($page = 1) {
mp-wp_genesis 237 $args = array('browse' => 'updated', 'page' => $page);
mp-wp_genesis 238 $api = plugins_api('query_plugins', $args);
mp-wp_genesis 239 display_plugins_table($api->plugins, $api->info['page'], $api->info['pages']);
mp-wp_genesis 240 }
mp-wp_genesis 241
mp-wp_genesis 242 /**
mp-wp_genesis 243 * Display plugin content based on plugin list.
mp-wp_genesis 244 *
mp-wp_genesis 245 * @since 2.7.0
mp-wp_genesis 246 *
mp-wp_genesis 247 * @param array $plugins List of plugins.
mp-wp_genesis 248 * @param string $page
mp-wp_genesis 249 * @param int $totalpages Number of pages.
mp-wp_genesis 250 */
mp-wp_genesis 251 function display_plugins_table($plugins, $page = 1, $totalpages = 1){
mp-wp_genesis 252 $type = isset($_REQUEST['type']) ? stripslashes( $_REQUEST['type'] ) : '';
mp-wp_genesis 253 $term = isset($_REQUEST['s']) ? stripslashes( $_REQUEST['s'] ) : '';
mp-wp_genesis 254
mp-wp_genesis 255 $plugins_allowedtags = array('a' => array('href' => array(),'title' => array(), 'target' => array()),
mp-wp_genesis 256 'abbr' => array('title' => array()),'acronym' => array('title' => array()),
mp-wp_genesis 257 'code' => array(), 'pre' => array(), 'em' => array(),'strong' => array());
mp-wp_genesis 258
mp-wp_genesis 259 ?>
mp-wp_genesis 260 <div class="tablenav">
mp-wp_genesis 261 <div class="alignleft actions">
mp-wp_genesis 262 <?php do_action('install_plugins_table_header'); ?>
mp-wp_genesis 263 </div>
mp-wp_genesis 264 <?php
mp-wp_genesis 265 $url = clean_url($_SERVER['REQUEST_URI']);
mp-wp_genesis 266 if ( ! empty($term) )
mp-wp_genesis 267 $url = add_query_arg('s', $term, $url);
mp-wp_genesis 268 if ( ! empty($type) )
mp-wp_genesis 269 $url = add_query_arg('type', $type, $url);
mp-wp_genesis 270
mp-wp_genesis 271 $page_links = paginate_links( array(
mp-wp_genesis 272 'base' => add_query_arg('paged', '%#%', $url),
mp-wp_genesis 273 'format' => '',
mp-wp_genesis 274 'prev_text' => __('«'),
mp-wp_genesis 275 'next_text' => __('»'),
mp-wp_genesis 276 'total' => $totalpages,
mp-wp_genesis 277 'current' => $page
mp-wp_genesis 278 ));
mp-wp_genesis 279
mp-wp_genesis 280 if ( $page_links )
mp-wp_genesis 281 echo "\t\t<div class='tablenav-pages'>$page_links</div>";
mp-wp_genesis 282 ?>
mp-wp_genesis 283 <br class="clear" />
mp-wp_genesis 284 </div>
mp-wp_genesis 285 <table class="widefat" id="install-plugins" cellspacing="0">
mp-wp_genesis 286 <thead>
mp-wp_genesis 287 <tr>
mp-wp_genesis 288 <th scope="col" class="name"><?php _e('Name'); ?></th>
mp-wp_genesis 289 <th scope="col" class="num"><?php _e('Version'); ?></th>
mp-wp_genesis 290 <th scope="col" class="num"><?php _e('Rating'); ?></th>
mp-wp_genesis 291 <th scope="col" class="desc"><?php _e('Description'); ?></th>
mp-wp_genesis 292 <th scope="col" class="action-links"><?php _e('Actions'); ?></th>
mp-wp_genesis 293 </tr>
mp-wp_genesis 294 </thead>
mp-wp_genesis 295
mp-wp_genesis 296 <tfoot>
mp-wp_genesis 297 <tr>
mp-wp_genesis 298 <th scope="col" class="name"><?php _e('Name'); ?></th>
mp-wp_genesis 299 <th scope="col" class="num"><?php _e('Version'); ?></th>
mp-wp_genesis 300 <th scope="col" class="num"><?php _e('Rating'); ?></th>
mp-wp_genesis 301 <th scope="col" class="desc"><?php _e('Description'); ?></th>
mp-wp_genesis 302 <th scope="col" class="action-links"><?php _e('Actions'); ?></th>
mp-wp_genesis 303 </tr>
mp-wp_genesis 304 </tfoot>
mp-wp_genesis 305
mp-wp_genesis 306 <tbody class="plugins">
mp-wp_genesis 307 <?php
mp-wp_genesis 308 if( empty($plugins) )
mp-wp_genesis 309 echo '<tr><td colspan="5">', __('No plugins match your request.'), '</td></tr>';
mp-wp_genesis 310
mp-wp_genesis 311 foreach( (array) $plugins as $plugin ){
mp-wp_genesis 312 if ( is_object($plugin) )
mp-wp_genesis 313 $plugin = (array) $plugin;
mp-wp_genesis 314
mp-wp_genesis 315 $title = wp_kses($plugin['name'], $plugins_allowedtags);
mp-wp_genesis 316 $description = wp_kses($plugin['description'], $plugins_allowedtags);
mp-wp_genesis 317 $version = wp_kses($plugin['version'], $plugins_allowedtags);
mp-wp_genesis 318
mp-wp_genesis 319 $name = strip_tags($title . ' ' . $version);
mp-wp_genesis 320
mp-wp_genesis 321 $author = $plugin['author'];
mp-wp_genesis 322 if( ! empty($plugin['author']) )
mp-wp_genesis 323 $author = ' <cite>' . sprintf( __('By %s'), $author ) . '.</cite>';
mp-wp_genesis 324
mp-wp_genesis 325 $author = wp_kses($author, $plugins_allowedtags);
mp-wp_genesis 326
mp-wp_genesis 327 if( isset($plugin['homepage']) )
mp-wp_genesis 328 $title = '<a target="_blank" href="' . attribute_escape($plugin['homepage']) . '">' . $title . '</a>';
mp-wp_genesis 329
mp-wp_genesis 330 $action_links = array();
mp-wp_genesis 331 $action_links[] = '<a href="' . admin_url('plugin-install.php?tab=plugin-information&plugin=' . $plugin['slug'] .
mp-wp_genesis 332 '&TB_iframe=true&width=600&height=800') . '" class="thickbox onclick" title="' .
mp-wp_genesis 333 attribute_escape($name) . '">' . __('Install') . '</a>';
mp-wp_genesis 334
mp-wp_genesis 335 $action_links = apply_filters('plugin_install_action_links', $action_links, $plugin);
mp-wp_genesis 336 ?>
mp-wp_genesis 337 <tr>
mp-wp_genesis 338 <td class="name"><?php echo $title; ?></td>
mp-wp_genesis 339 <td class="vers"><?php echo $version; ?></td>
mp-wp_genesis 340 <td class="vers">
mp-wp_genesis 341 <div class="star-holder" title="<?php printf(__ngettext('(based on %s rating)', '(based on %s ratings)', $plugin['num_ratings']), number_format_i18n($plugin['num_ratings'])) ?>">
mp-wp_genesis 342 <div class="star star-rating" style="width: <?php echo attribute_escape($plugin['rating']) ?>px"></div>
mp-wp_genesis 343 <div class="star star5"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('5 stars') ?>" /></div>
mp-wp_genesis 344 <div class="star star4"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('4 stars') ?>" /></div>
mp-wp_genesis 345 <div class="star star3"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('3 stars') ?>" /></div>
mp-wp_genesis 346 <div class="star star2"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('2 stars') ?>" /></div>
mp-wp_genesis 347 <div class="star star1"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('1 star') ?>" /></div>
mp-wp_genesis 348 </div>
mp-wp_genesis 349 </td>
mp-wp_genesis 350 <td class="desc"><p><?php echo $description, $author; ?></p></td>
mp-wp_genesis 351 <td class="action-links"><?php if ( !empty($action_links) ) echo implode(' | ', $action_links); ?></td>
mp-wp_genesis 352 </tr>
mp-wp_genesis 353 <?php
mp-wp_genesis 354 }
mp-wp_genesis 355 ?>
mp-wp_genesis 356 </tbody>
mp-wp_genesis 357 </table>
mp-wp_genesis 358
mp-wp_genesis 359 <div class="tablenav">
mp-wp_genesis 360 <?php if ( $page_links )
mp-wp_genesis 361 echo "\t\t<div class='tablenav-pages'>$page_links</div>"; ?>
mp-wp_genesis 362 <br class="clear" />
mp-wp_genesis 363 </div>
mp-wp_genesis 364
mp-wp_genesis 365 <?php
mp-wp_genesis 366 }
mp-wp_genesis 367
mp-wp_genesis 368 add_action('install_plugins_pre_plugin-information', 'install_plugin_information');
mp-wp_genesis 369
mp-wp_genesis 370 /**
mp-wp_genesis 371 * Display plugin information in dialog box form.
mp-wp_genesis 372 *
mp-wp_genesis 373 * @since 2.7.0
mp-wp_genesis 374 */
mp-wp_genesis 375 function install_plugin_information() {
mp-wp_genesis 376 global $tab;
mp-wp_genesis 377
mp-wp_genesis 378 $api = plugins_api('plugin_information', array('slug' => stripslashes( $_REQUEST['plugin'] ) ));
mp-wp_genesis 379
mp-wp_genesis 380 if ( is_wp_error($api) )
mp-wp_genesis 381 wp_die($api);
mp-wp_genesis 382
mp-wp_genesis 383 $plugins_allowedtags = array('a' => array('href' => array(), 'title' => array(), 'target' => array()),
mp-wp_genesis 384 'abbr' => array('title' => array()), 'acronym' => array('title' => array()),
mp-wp_genesis 385 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(),
mp-wp_genesis 386 'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(),
mp-wp_genesis 387 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
mp-wp_genesis 388 'img' => array('src' => array(), 'class' => array(), 'alt' => array()));
mp-wp_genesis 389 //Sanitize HTML
mp-wp_genesis 390 foreach ( (array)$api->sections as $section_name => $content )
mp-wp_genesis 391 $api->sections[$section_name] = wp_kses($content, $plugins_allowedtags);
mp-wp_genesis 392 foreach ( array('version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug') as $key )
mp-wp_genesis 393 $api->$key = wp_kses($api->$key, $plugins_allowedtags);
mp-wp_genesis 394
mp-wp_genesis 395 $section = isset($_REQUEST['section']) ? stripslashes( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English.
mp-wp_genesis 396 if( empty($section) || ! isset($api->sections[ $section ]) )
mp-wp_genesis 397 $section = array_shift( $section_titles = array_keys((array)$api->sections) );
mp-wp_genesis 398
mp-wp_genesis 399 iframe_header( __('Plugin Install') );
mp-wp_genesis 400 echo "<div id='$tab-header'>\n";
mp-wp_genesis 401 echo "<ul id='sidemenu'>\n";
mp-wp_genesis 402 foreach ( (array)$api->sections as $section_name => $content ) {
mp-wp_genesis 403
mp-wp_genesis 404 $title = $section_name;
mp-wp_genesis 405 $title = ucwords(str_replace('_', ' ', $title));
mp-wp_genesis 406
mp-wp_genesis 407 $class = ( $section_name == $section ) ? ' class="current"' : '';
mp-wp_genesis 408 $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) );
mp-wp_genesis 409 $href = clean_url($href);
mp-wp_genesis 410 $san_title = attribute_escape(sanitize_title_with_dashes($title));
mp-wp_genesis 411 echo "\t<li><a name='$san_title' target='' href='$href'$class>$title</a></li>\n";
mp-wp_genesis 412 }
mp-wp_genesis 413 echo "</ul>\n";
mp-wp_genesis 414 echo "</div>\n";
mp-wp_genesis 415 ?>
mp-wp_genesis 416 <div class="alignright fyi">
mp-wp_genesis 417 <?php if ( ! empty($api->download_link) ) : ?>
mp-wp_genesis 418 <p class="action-button">
mp-wp_genesis 419 <?php
mp-wp_genesis 420 //Default to a "new" plugin
mp-wp_genesis 421 $type = 'install';
mp-wp_genesis 422 //Check to see if this plugin is known to be installed, and has an update awaiting it.
mp-wp_genesis 423 $update_plugins = get_option('update_plugins');
mp-wp_genesis 424 foreach ( (array)$update_plugins->response as $file => $plugin ) {
mp-wp_genesis 425 if ( $plugin->slug === $api->slug ) {
mp-wp_genesis 426 $type = 'update_available';
mp-wp_genesis 427 $update_file = $file;
mp-wp_genesis 428 break;
mp-wp_genesis 429 }
mp-wp_genesis 430 }
mp-wp_genesis 431 if ( 'install' == $type && is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) {
mp-wp_genesis 432 $installed_plugin = get_plugins('/' . $api->slug);
mp-wp_genesis 433 if ( ! empty($installed_plugin) ) {
mp-wp_genesis 434 $key = array_shift( $key = array_keys($installed_plugin) ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers
mp-wp_genesis 435 if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '>') ){
mp-wp_genesis 436 $type = 'latest_installed';
mp-wp_genesis 437 } elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) {
mp-wp_genesis 438 $type = 'newer_installed';
mp-wp_genesis 439 $newer_version = $installed_plugin[ $key ]['Version'];
mp-wp_genesis 440 } else {
mp-wp_genesis 441 //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh
mp-wp_genesis 442 delete_option('update_plugins');
mp-wp_genesis 443 $update_file = $api->slug . '/' . $key; //This code branch only deals with a plugin which is in a folder the same name as its slug, Doesnt support plugins which have 'non-standard' names
mp-wp_genesis 444 $type = 'update_available';
mp-wp_genesis 445 }
mp-wp_genesis 446 }
mp-wp_genesis 447 }
mp-wp_genesis 448
mp-wp_genesis 449 switch ( $type ) :
mp-wp_genesis 450 default:
mp-wp_genesis 451 case 'install':
mp-wp_genesis 452 if ( current_user_can('install_plugins') ) :
mp-wp_genesis 453 ?><a href="<?php echo wp_nonce_url(admin_url('plugin-install.php?tab=install&plugin=' . $api->slug), 'install-plugin_' . $api->slug) ?>" target="_parent"><?php _e('Install Now') ?></a><?php
mp-wp_genesis 454 endif;
mp-wp_genesis 455 break;
mp-wp_genesis 456 case 'update_available':
mp-wp_genesis 457 if ( current_user_can('update_plugins') ) :
mp-wp_genesis 458 ?><a href="<?php echo wp_nonce_url(admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file) ?>" target="_parent"><?php _e('Install Update Now') ?></a><?php
mp-wp_genesis 459 endif;
mp-wp_genesis 460 break;
mp-wp_genesis 461 case 'newer_installed':
mp-wp_genesis 462 if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) :
mp-wp_genesis 463 ?><a><?php printf(__('Newer Version (%s) Installed'), $newer_version) ?></a><?php
mp-wp_genesis 464 endif;
mp-wp_genesis 465 break;
mp-wp_genesis 466 case 'latest_installed':
mp-wp_genesis 467 if ( current_user_can('install_plugins') || current_user_can('update_plugins') ) :
mp-wp_genesis 468 ?><a><?php _e('Latest Version Installed') ?></a><?php
mp-wp_genesis 469 endif;
mp-wp_genesis 470 break;
mp-wp_genesis 471 endswitch; ?>
mp-wp_genesis 472 </p>
mp-wp_genesis 473 <?php endif; ?>
mp-wp_genesis 474 <h2 class="mainheader"><?php _e('FYI') ?></h2>
mp-wp_genesis 475 <ul>
mp-wp_genesis 476 <?php if ( ! empty($api->version) ) : ?>
mp-wp_genesis 477 <li><strong><?php _e('Version:') ?></strong> <?php echo $api->version ?></li>
mp-wp_genesis 478 <?php endif; if ( ! empty($api->author) ) : ?>
mp-wp_genesis 479 <li><strong><?php _e('Author:') ?></strong> <?php echo links_add_target($api->author, '_blank') ?></li>
mp-wp_genesis 480 <?php endif; if ( ! empty($api->last_updated) ) : ?>
mp-wp_genesis 481 <li><strong><?php _e('Last Updated:') ?></strong> <span title="<?php echo $api->last_updated ?>"><?php
mp-wp_genesis 482 printf( __('%s ago'), human_time_diff(strtotime($api->last_updated)) ) ?></span></li>
mp-wp_genesis 483 <?php endif; if ( ! empty($api->requires) ) : ?>
mp-wp_genesis 484 <li><strong><?php _e('Requires WordPress Version:') ?></strong> <?php printf(__('%s or higher'), $api->requires) ?></li>
mp-wp_genesis 485 <?php endif; if ( ! empty($api->tested) ) : ?>
mp-wp_genesis 486 <li><strong><?php _e('Compatible up to:') ?></strong> <?php echo $api->tested ?></li>
mp-wp_genesis 487 <?php endif; if ( ! empty($api->downloaded) ) : ?>
mp-wp_genesis 488 <li><strong><?php _e('Downloaded:') ?></strong> <?php printf(__ngettext('%s time', '%s times', $api->downloaded), number_format_i18n($api->downloaded)) ?></li>
mp-wp_genesis 489 <?php endif; if ( ! empty($api->slug) ) : ?>
mp-wp_genesis 490 <li><a target="_blank" href="http://wordpress.org/extend/plugins/<?php echo $api->slug ?>/"><?php _e('WordPress.org Plugin Page »') ?></a></li>
mp-wp_genesis 491 <?php endif; if ( ! empty($api->homepage) ) : ?>
mp-wp_genesis 492 <li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage »') ?></a></li>
mp-wp_genesis 493 <?php endif; ?>
mp-wp_genesis 494 </ul>
mp-wp_genesis 495 <h2><?php _e('Average Rating') ?></h2>
mp-wp_genesis 496 <div class="star-holder" title="<?php printf(__ngettext('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)); ?>">
mp-wp_genesis 497 <div class="star star-rating" style="width: <?php echo attribute_escape($api->rating) ?>px"></div>
mp-wp_genesis 498 <div class="star star5"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('5 stars') ?>" /></div>
mp-wp_genesis 499 <div class="star star4"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('4 stars') ?>" /></div>
mp-wp_genesis 500 <div class="star star3"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('3 stars') ?>" /></div>
mp-wp_genesis 501 <div class="star star2"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('2 stars') ?>" /></div>
mp-wp_genesis 502 <div class="star star1"><img src="<?php echo admin_url('images/star.gif'); ?>" alt="<?php _e('1 star') ?>" /></div>
mp-wp_genesis 503 </div>
mp-wp_genesis 504 <small><?php printf(__ngettext('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)); ?></small>
mp-wp_genesis 505 </div>
mp-wp_genesis 506 <div id="section-holder" class="wrap">
mp-wp_genesis 507 <?php
mp-wp_genesis 508 if ( version_compare($GLOBALS['wp_version'], $api->tested, '>') )
mp-wp_genesis 509 echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>';
mp-wp_genesis 510 else if ( version_compare($GLOBALS['wp_version'], $api->requires, '<') )
mp-wp_genesis 511 echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has not been marked as <strong>compatible</strong> with your version of WordPress.') . '</p></div>';
mp-wp_genesis 512 foreach ( (array)$api->sections as $section_name => $content ) {
mp-wp_genesis 513 $title = $section_name;
mp-wp_genesis 514 $title[0] = strtoupper($title[0]);
mp-wp_genesis 515 $title = str_replace('_', ' ', $title);
mp-wp_genesis 516
mp-wp_genesis 517 $content = links_add_base_url($content, 'http://wordpress.org/extend/plugins/' . $api->slug . '/');
mp-wp_genesis 518 $content = links_add_target($content, '_blank');
mp-wp_genesis 519
mp-wp_genesis 520 $san_title = attribute_escape(sanitize_title_with_dashes($title));
mp-wp_genesis 521
mp-wp_genesis 522 $display = ( $section_name == $section ) ? 'block' : 'none';
mp-wp_genesis 523
mp-wp_genesis 524 echo "\t<div id='section-{$san_title}' class='section' style='display: {$display};'>\n";
mp-wp_genesis 525 echo "\t\t<h2 class='long-header'>$title</h2>";
mp-wp_genesis 526 echo $content;
mp-wp_genesis 527 echo "\t</div>\n";
mp-wp_genesis 528 }
mp-wp_genesis 529 echo "</div>\n";
mp-wp_genesis 530
mp-wp_genesis 531 iframe_footer();
mp-wp_genesis 532 exit;
mp-wp_genesis 533 }
mp-wp_genesis 534
mp-wp_genesis 535
mp-wp_genesis 536 add_action('install_plugins_upload', 'upload_plugin');
mp-wp_genesis 537 function upload_plugin() {
mp-wp_genesis 538
mp-wp_genesis 539 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
mp-wp_genesis 540 wp_die($uploads['error']);
mp-wp_genesis 541
mp-wp_genesis 542 if ( !empty($_FILES) )
mp-wp_genesis 543 $filename = $_FILES['pluginzip']['name'];
mp-wp_genesis 544 else if ( isset($_GET['package']) )
mp-wp_genesis 545 $filename = $_GET['package'];
mp-wp_genesis 546
mp-wp_genesis 547 check_admin_referer('plugin-upload');
mp-wp_genesis 548
mp-wp_genesis 549 echo '<div class="wrap">';
mp-wp_genesis 550 echo '<h2>', sprintf( __('Installing Plugin from file: %s'), basename($filename) ), '</h2>';
mp-wp_genesis 551
mp-wp_genesis 552 //Handle a newly uploaded file, Else assume it was
mp-wp_genesis 553 if ( !empty($_FILES) ) {
mp-wp_genesis 554 $filename = wp_unique_filename( $uploads['basedir'], $filename );
mp-wp_genesis 555 $local_file = $uploads['basedir'] . '/' . $filename;
mp-wp_genesis 556
mp-wp_genesis 557 // Move the file to the uploads dir
mp-wp_genesis 558 if ( false === @ move_uploaded_file( $_FILES['pluginzip']['tmp_name'], $local_file) )
mp-wp_genesis 559 wp_die( sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path']));
mp-wp_genesis 560 } else {
mp-wp_genesis 561 $local_file = $uploads['basedir'] . '/' . $filename;
mp-wp_genesis 562 }
mp-wp_genesis 563
mp-wp_genesis 564 do_plugin_install_local_package($local_file, $filename);
mp-wp_genesis 565 echo '</div>';
mp-wp_genesis 566 }
mp-wp_genesis 567
mp-wp_genesis 568 add_action('install_plugins_install', 'install_plugin');
mp-wp_genesis 569
mp-wp_genesis 570 /**
mp-wp_genesis 571 * Display plugin link and execute install.
mp-wp_genesis 572 *
mp-wp_genesis 573 * @since 2.7.0
mp-wp_genesis 574 */
mp-wp_genesis 575 function install_plugin() {
mp-wp_genesis 576
mp-wp_genesis 577 $plugin = isset($_REQUEST['plugin']) ? stripslashes( $_REQUEST['plugin'] ) : '';
mp-wp_genesis 578
mp-wp_genesis 579 check_admin_referer('install-plugin_' . $plugin);
mp-wp_genesis 580 $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.
mp-wp_genesis 581
mp-wp_genesis 582 if ( is_wp_error($api) )
mp-wp_genesis 583 wp_die($api);
mp-wp_genesis 584
mp-wp_genesis 585 echo '<div class="wrap">';
mp-wp_genesis 586 echo '<h2>', sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version ), '</h2>';
mp-wp_genesis 587
mp-wp_genesis 588 do_plugin_install($api->download_link, $api);
mp-wp_genesis 589 echo '</div>';
mp-wp_genesis 590
mp-wp_genesis 591 }
mp-wp_genesis 592
mp-wp_genesis 593 /**
mp-wp_genesis 594 * Retrieve plugin and install.
mp-wp_genesis 595 *
mp-wp_genesis 596 * @since 2.7.0
mp-wp_genesis 597 *
mp-wp_genesis 598 * @param string $download_url Download URL.
mp-wp_genesis 599 * @param object $plugin_information Optional. Plugin information
mp-wp_genesis 600 */
mp-wp_genesis 601 function do_plugin_install($download_url, $plugin_information = null) {
mp-wp_genesis 602 global $wp_filesystem;
mp-wp_genesis 603
mp-wp_genesis 604 if ( empty($download_url) ) {
mp-wp_genesis 605 show_message( __('No plugin Specified') );
mp-wp_genesis 606 return;
mp-wp_genesis 607 }
mp-wp_genesis 608
mp-wp_genesis 609 $plugin = isset($_REQUEST['plugin']) ? stripslashes( $_REQUEST['plugin'] ) : '';
mp-wp_genesis 610
mp-wp_genesis 611 $url = 'plugin-install.php?tab=install';
mp-wp_genesis 612 $url = add_query_arg(array('plugin' => $plugin, 'plugin_name' => stripslashes( $_REQUEST['plugin_name'] ), 'download_url' => stripslashes( $_REQUEST['download_url'] ) ), $url);
mp-wp_genesis 613
mp-wp_genesis 614 $url = wp_nonce_url($url, 'install-plugin_' . $plugin);
mp-wp_genesis 615 if ( false === ($credentials = request_filesystem_credentials($url)) )
mp-wp_genesis 616 return;
mp-wp_genesis 617
mp-wp_genesis 618 if ( ! WP_Filesystem($credentials) ) {
mp-wp_genesis 619 request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again
mp-wp_genesis 620 return;
mp-wp_genesis 621 }
mp-wp_genesis 622
mp-wp_genesis 623 if ( $wp_filesystem->errors->get_error_code() ) {
mp-wp_genesis 624 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
mp-wp_genesis 625 show_message($message);
mp-wp_genesis 626 return;
mp-wp_genesis 627 }
mp-wp_genesis 628
mp-wp_genesis 629 $result = wp_install_plugin( $download_url, 'show_message' );
mp-wp_genesis 630
mp-wp_genesis 631 if ( is_wp_error($result) ) {
mp-wp_genesis 632 show_message($result);
mp-wp_genesis 633 show_message( __('Installation Failed') );
mp-wp_genesis 634 } else {
mp-wp_genesis 635 show_message( sprintf(__('Successfully installed the plugin <strong>%s %s</strong>.'), $plugin_information->name, $plugin_information->version) );
mp-wp_genesis 636 $plugin_file = $result;
mp-wp_genesis 637
mp-wp_genesis 638 $install_actions = apply_filters('install_plugin_complete_actions', array(
mp-wp_genesis 639 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . attribute_escape(__('Activate this plugin')) . '" target="_parent">' . __('Activate Plugin') . '</a>',
mp-wp_genesis 640 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . attribute_escape(__('Goto plugins page')) . '" target="_parent">' . __('Return to Plugins page') . '</a>'
mp-wp_genesis 641 ), $plugin_information, $plugin_file);
mp-wp_genesis 642 if ( ! empty($install_actions) )
mp-wp_genesis 643 show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));
mp-wp_genesis 644 }
mp-wp_genesis 645 }
mp-wp_genesis 646
mp-wp_genesis 647 /**
mp-wp_genesis 648 * Install a plugin from a local file.
mp-wp_genesis 649 *
mp-wp_genesis 650 * @since 2.7.0
mp-wp_genesis 651 *
mp-wp_genesis 652 * @param string $package Local Plugin zip
mp-wp_genesis 653 * @param string $filename Optional. Original filename
mp-wp_genesis 654 * @param object $plugin_information Optional. Plugin information
mp-wp_genesis 655 */
mp-wp_genesis 656 function do_plugin_install_local_package($package, $filename = '') {
mp-wp_genesis 657 global $wp_filesystem;
mp-wp_genesis 658
mp-wp_genesis 659 if ( empty($package) ) {
mp-wp_genesis 660 show_message( __('No plugin Specified') );
mp-wp_genesis 661 return;
mp-wp_genesis 662 }
mp-wp_genesis 663
mp-wp_genesis 664 if ( empty($filename) )
mp-wp_genesis 665 $filename = basename($package);
mp-wp_genesis 666
mp-wp_genesis 667 $url = 'plugin-install.php?tab=upload';
mp-wp_genesis 668 $url = add_query_arg(array('package' => $filename), $url);
mp-wp_genesis 669
mp-wp_genesis 670 $url = wp_nonce_url($url, 'plugin-upload');
mp-wp_genesis 671 if ( false === ($credentials = request_filesystem_credentials($url)) )
mp-wp_genesis 672 return;
mp-wp_genesis 673
mp-wp_genesis 674 if ( ! WP_Filesystem($credentials) ) {
mp-wp_genesis 675 request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again
mp-wp_genesis 676 return;
mp-wp_genesis 677 }
mp-wp_genesis 678
mp-wp_genesis 679 if ( $wp_filesystem->errors->get_error_code() ) {
mp-wp_genesis 680 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
mp-wp_genesis 681 show_message($message);
mp-wp_genesis 682 return;
mp-wp_genesis 683 }
mp-wp_genesis 684
mp-wp_genesis 685 $result = wp_install_plugin_local_package( $package, 'show_message' );
mp-wp_genesis 686
mp-wp_genesis 687 if ( is_wp_error($result) ) {
mp-wp_genesis 688 show_message($result);
mp-wp_genesis 689 show_message( __('Installation Failed') );
mp-wp_genesis 690 } else {
mp-wp_genesis 691 show_message( __('Successfully installed the plugin.') );
mp-wp_genesis 692 $plugin_file = $result;
mp-wp_genesis 693
mp-wp_genesis 694 $install_actions = apply_filters('install_plugin_complete_actions', array(
mp-wp_genesis 695 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
mp-wp_genesis 696 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . __('Goto plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
mp-wp_genesis 697 ), array(), $plugin_file);
mp-wp_genesis 698 if ( ! empty($install_actions) )
mp-wp_genesis 699 show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));
mp-wp_genesis 700 }
mp-wp_genesis 701 }
mp-wp_genesis 702
mp-wp_genesis 703 /**
mp-wp_genesis 704 * Install plugin.
mp-wp_genesis 705 *
mp-wp_genesis 706 * @since 2.7.0
mp-wp_genesis 707 *
mp-wp_genesis 708 * @param string $package
mp-wp_genesis 709 * @param string $feedback Optional.
mp-wp_genesis 710 * @return mixed.
mp-wp_genesis 711 */
mp-wp_genesis 712 function wp_install_plugin($package, $feedback = '') {
mp-wp_genesis 713 global $wp_filesystem;
mp-wp_genesis 714
mp-wp_genesis 715 if ( !empty($feedback) )
mp-wp_genesis 716 add_filter('install_feedback', $feedback);
mp-wp_genesis 717
mp-wp_genesis 718 // Is a filesystem accessor setup?
mp-wp_genesis 719 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )
mp-wp_genesis 720 WP_Filesystem();
mp-wp_genesis 721
mp-wp_genesis 722 if ( ! is_object($wp_filesystem) )
mp-wp_genesis 723 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
mp-wp_genesis 724
mp-wp_genesis 725 if ( $wp_filesystem->errors->get_error_code() )
mp-wp_genesis 726 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
mp-wp_genesis 727
mp-wp_genesis 728 //Get the base plugin folder
mp-wp_genesis 729 $plugins_dir = $wp_filesystem->wp_plugins_dir();
mp-wp_genesis 730 if ( empty($plugins_dir) )
mp-wp_genesis 731 return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.'));
mp-wp_genesis 732
mp-wp_genesis 733 //And the same for the Content directory.
mp-wp_genesis 734 $content_dir = $wp_filesystem->wp_content_dir();
mp-wp_genesis 735 if( empty($content_dir) )
mp-wp_genesis 736 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));
mp-wp_genesis 737
mp-wp_genesis 738 $plugins_dir = trailingslashit( $plugins_dir );
mp-wp_genesis 739 $content_dir = trailingslashit( $content_dir );
mp-wp_genesis 740
mp-wp_genesis 741 if ( empty($package) )
mp-wp_genesis 742 return new WP_Error('no_package', __('Install package not available.'));
mp-wp_genesis 743
mp-wp_genesis 744 // Download the package
mp-wp_genesis 745 apply_filters('install_feedback', sprintf(__('Downloading plugin package from %s'), $package));
mp-wp_genesis 746 $download_file = download_url($package);
mp-wp_genesis 747
mp-wp_genesis 748 if ( is_wp_error($download_file) )
mp-wp_genesis 749 return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message());
mp-wp_genesis 750
mp-wp_genesis 751 $working_dir = $content_dir . 'upgrade/' . basename($package, '.zip');
mp-wp_genesis 752
mp-wp_genesis 753 // Clean up working directory
mp-wp_genesis 754 if ( $wp_filesystem->is_dir($working_dir) )
mp-wp_genesis 755 $wp_filesystem->delete($working_dir, true);
mp-wp_genesis 756
mp-wp_genesis 757 apply_filters('install_feedback', __('Unpacking the plugin package'));
mp-wp_genesis 758 // Unzip package to working directory
mp-wp_genesis 759 $result = unzip_file($download_file, $working_dir);
mp-wp_genesis 760
mp-wp_genesis 761 // Once extracted, delete the package
mp-wp_genesis 762 @unlink($download_file);
mp-wp_genesis 763
mp-wp_genesis 764 if ( is_wp_error($result) ) {
mp-wp_genesis 765 $wp_filesystem->delete($working_dir, true);
mp-wp_genesis 766 return $result;
mp-wp_genesis 767 }
mp-wp_genesis 768
mp-wp_genesis 769 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
mp-wp_genesis 770 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
mp-wp_genesis 771
mp-wp_genesis 772 if( $wp_filesystem->exists( $plugins_dir . $filelist[0] ) ) {
mp-wp_genesis 773 $wp_filesystem->delete($working_dir, true);
mp-wp_genesis 774 return new WP_Error('install_folder_exists', __('Folder already exists.'), $filelist[0] );
mp-wp_genesis 775 }
mp-wp_genesis 776
mp-wp_genesis 777 apply_filters('install_feedback', __('Installing the plugin'));
mp-wp_genesis 778 // Copy new version of plugin into place.
mp-wp_genesis 779 $result = copy_dir($working_dir, $plugins_dir);
mp-wp_genesis 780 if ( is_wp_error($result) ) {
mp-wp_genesis 781 $wp_filesystem->delete($working_dir, true);
mp-wp_genesis 782 return $result;
mp-wp_genesis 783 }
mp-wp_genesis 784
mp-wp_genesis 785 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
mp-wp_genesis 786 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
mp-wp_genesis 787
mp-wp_genesis 788 // Remove working directory
mp-wp_genesis 789 $wp_filesystem->delete($working_dir, true);
mp-wp_genesis 790
mp-wp_genesis 791 if( empty($filelist) )
mp-wp_genesis 792 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
mp-wp_genesis 793
mp-wp_genesis 794 $folder = $filelist[0];
mp-wp_genesis 795 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
mp-wp_genesis 796 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
mp-wp_genesis 797
mp-wp_genesis 798 //Return the plugin files name.
mp-wp_genesis 799 return $folder . '/' . $pluginfiles[0];
mp-wp_genesis 800 }
mp-wp_genesis 801
mp-wp_genesis 802 /**
mp-wp_genesis 803 * Install plugin from local package
mp-wp_genesis 804 *
mp-wp_genesis 805 * @since 2.7.0
mp-wp_genesis 806 *
mp-wp_genesis 807 * @param string $package
mp-wp_genesis 808 * @param string $feedback Optional.
mp-wp_genesis 809 * @return mixed.
mp-wp_genesis 810 */
mp-wp_genesis 811 function wp_install_plugin_local_package($package, $feedback = '') {
mp-wp_genesis 812 global $wp_filesystem;
mp-wp_genesis 813
mp-wp_genesis 814 if ( !empty($feedback) )
mp-wp_genesis 815 add_filter('install_feedback', $feedback);
mp-wp_genesis 816
mp-wp_genesis 817 // Is a filesystem accessor setup?
mp-wp_genesis 818 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )
mp-wp_genesis 819 WP_Filesystem();
mp-wp_genesis 820
mp-wp_genesis 821 if ( ! is_object($wp_filesystem) )
mp-wp_genesis 822 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
mp-wp_genesis 823
mp-wp_genesis 824 if ( $wp_filesystem->errors->get_error_code() )
mp-wp_genesis 825 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
mp-wp_genesis 826
mp-wp_genesis 827 //Get the base plugin folder
mp-wp_genesis 828 $plugins_dir = $wp_filesystem->wp_plugins_dir();
mp-wp_genesis 829 if ( empty($plugins_dir) )
mp-wp_genesis 830 return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.'));
mp-wp_genesis 831
mp-wp_genesis 832 //And the same for the Content directory.
mp-wp_genesis 833 $content_dir = $wp_filesystem->wp_content_dir();
mp-wp_genesis 834 if( empty($content_dir) )
mp-wp_genesis 835 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));
mp-wp_genesis 836
mp-wp_genesis 837 $plugins_dir = trailingslashit( $plugins_dir );
mp-wp_genesis 838 $content_dir = trailingslashit( $content_dir );
mp-wp_genesis 839
mp-wp_genesis 840 if ( empty($package) )
mp-wp_genesis 841 return new WP_Error('no_package', __('Install package not available.'));
mp-wp_genesis 842
mp-wp_genesis 843 $working_dir = $content_dir . 'upgrade/' . basename($package, '.zip');
mp-wp_genesis 844
mp-wp_genesis 845 // Clean up working directory
mp-wp_genesis 846 if ( $wp_filesystem->is_dir($working_dir) )
mp-wp_genesis 847 $wp_filesystem->delete($working_dir, true);
mp-wp_genesis 848
mp-wp_genesis 849 apply_filters('install_feedback', __('Unpacking the plugin package'));
mp-wp_genesis 850 // Unzip package to working directory
mp-wp_genesis 851 $result = unzip_file($package, $working_dir);
mp-wp_genesis 852
mp-wp_genesis 853 // Once extracted, delete the package
mp-wp_genesis 854 unlink($package);
mp-wp_genesis 855
mp-wp_genesis 856 if ( is_wp_error($result) ) {
mp-wp_genesis 857 $wp_filesystem->delete($working_dir, true);
mp-wp_genesis 858 return $result;
mp-wp_genesis 859 }
mp-wp_genesis 860
mp-wp_genesis 861 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
mp-wp_genesis 862 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
mp-wp_genesis 863
mp-wp_genesis 864 if( $wp_filesystem->exists( $plugins_dir . $filelist[0] ) ) {
mp-wp_genesis 865 $wp_filesystem->delete($working_dir, true);
mp-wp_genesis 866 return new WP_Error('install_folder_exists', __('Folder already exists.'), $filelist[0] );
mp-wp_genesis 867 }
mp-wp_genesis 868
mp-wp_genesis 869 apply_filters('install_feedback', __('Installing the plugin'));
mp-wp_genesis 870 // Copy new version of plugin into place.
mp-wp_genesis 871 $result = copy_dir($working_dir, $plugins_dir);
mp-wp_genesis 872 if ( is_wp_error($result) ) {
mp-wp_genesis 873 $wp_filesystem->delete($working_dir, true);
mp-wp_genesis 874 return $result;
mp-wp_genesis 875 }
mp-wp_genesis 876
mp-wp_genesis 877 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
mp-wp_genesis 878 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
mp-wp_genesis 879
mp-wp_genesis 880 // Remove working directory
mp-wp_genesis 881 $wp_filesystem->delete($working_dir, true);
mp-wp_genesis 882
mp-wp_genesis 883 if( empty($filelist) )
mp-wp_genesis 884 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
mp-wp_genesis 885
mp-wp_genesis 886 $folder = $filelist[0];
mp-wp_genesis 887 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
mp-wp_genesis 888 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
mp-wp_genesis 889
mp-wp_genesis 890 //Return the plugin files name.
mp-wp_genesis 891 return $folder . '/' . $pluginfiles[0];
mp-wp_genesis 892 }
mp-wp_genesis 893
mp-wp_genesis 894 ?>