Changeset 10214 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
- Timestamp:
- 08/28/2020 05:36:38 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r10119 r10214 587 587 add_shortcode( 'readme-validator', array( __NAMESPACE__ . '\Shortcodes\Readme_Validator', 'display' ) ); 588 588 add_shortcode( 'block-validator', array( __NAMESPACE__ . '\Shortcodes\Block_Validator', 'display' ) ); 589 590 add_shortcode( Shortcodes\Release_Confirmation::SHORTCODE, array( __NAMESPACE__ . '\Shortcodes\Release_Confirmation', 'display' ) ); 591 add_action( 'template_redirect', array( __NAMESPACE__ . '\Shortcodes\Release_Confirmation', 'template_redirect' ) ); 589 592 } 590 593 … … 603 606 'readme-validator', 604 607 'block-validator', 608 'release-confirmation', 605 609 ); 606 610 … … 1504 1508 1505 1509 return $content_pages; 1510 } 1511 1512 /** 1513 * Get a list of all Plugin Releases. 1514 */ 1515 public static function get_releases( $plugin ) { 1516 $plugin = self::get_plugin_post( $plugin ); 1517 $releases = get_post_meta( $plugin->ID, 'releases', true ); 1518 1519 // Meta doesn't exist yet? Lets fill it out. 1520 if ( false === $releases || ! is_array( $releases ) ) { 1521 update_post_meta( $plugin->ID, 'releases', [] ); 1522 1523 $tags = get_post_meta( $plugin->ID, 'tags', true ); 1524 if ( $tags ) { 1525 foreach ( $tags as $tag_version => $tag ) { 1526 self::add_release( $plugin, [ 1527 'date' => strtotime( $tag['date'] ), 1528 'tag' => $tag['tag'], 1529 'version' => $tag_version, 1530 'committer' => [ $tag['author'] ], 1531 'confirmations_required' => 0, // Old release, assume it's released. 1532 ] ); 1533 } 1534 } else { 1535 // Pull from SVN directly. 1536 $svn_tags = Tools\SVN::ls( "https://plugins.svn.wordpress.org/{$plugin->post_name}/tags/", true ) ?: []; 1537 foreach ( $svn_tags as $entry ) { 1538 // Discard files 1539 if ( 'dir' !== $entry['kind'] ) { 1540 continue; 1541 } 1542 1543 $tag = $entry['filename']; 1544 1545 // Prefix the 0 for plugin versions like 0.1 1546 if ( '.' == substr( $tag, 0, 1 ) ) { 1547 $tag = "0{$tag}"; 1548 } 1549 1550 self::add_release( $plugin, [ 1551 'date' => strtotime( $entry['date'] ), 1552 'tag' => $entry['filename'], 1553 'version' => $tag, 1554 'committer' => [ $entry['author'] ], 1555 'confirmations_required' => 0, // Old release, assume it's released. 1556 ] ); 1557 } 1558 } 1559 1560 $releases = get_post_meta( $plugin->ID, 'releases', true ) ?: []; 1561 } 1562 1563 return $releases; 1564 } 1565 1566 /** 1567 * Fetch a specific release of the plugin, by tag. 1568 */ 1569 public static function get_release( $plugin, $tag ) { 1570 $releases = self::get_releases( $plugin ); 1571 1572 $filtered = wp_list_filter( $releases, compact( 'tag' ) ); 1573 1574 if ( $filtered ) { 1575 return array_shift( $filtered ); 1576 } 1577 1578 return false; 1579 } 1580 1581 /** 1582 * Add a Plugin Release to the internal storage. 1583 */ 1584 public static function add_release( $plugin, $data ) { 1585 if ( ! isset( $data['tag'] ) ) { 1586 return false; 1587 } 1588 $plugin = self::get_plugin_post( $plugin ); 1589 1590 $release = self::get_release( $plugin, $data['tag'] ) ?: [ 1591 'date' => time(), 1592 'tag' => '', 1593 'version' => '', 1594 'zips_built' => false, 1595 'confirmations' => [], 1596 // Confirmed by default if no release confiration. 1597 'confirmed' => ! $plugin->release_confirmation, 1598 'confirmations_required' => (int) $plugin->release_confirmation, 1599 'committer' => [], 1600 'revision' => [], 1601 ]; 1602 1603 // Fill 1604 foreach ( $data as $k => $v ) { 1605 $release[ $k ] = $v; 1606 } 1607 1608 $releases = self::get_releases( $plugin ); 1609 1610 $releases[] = $release; 1611 1612 // Sort releases most recent first. 1613 uasort( $releases, function( $a, $b ) { 1614 return $b['date'] <=> $a['date']; 1615 } ); 1616 1617 return update_post_meta( $plugin->ID, 'releases', $releases ); 1506 1618 } 1507 1619
Note: See TracChangeset
for help on using the changeset viewer.