Changeset 7801 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-make-core-pot.php
- Timestamp:
- 10/28/2018 02:07:44 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-make-core-pot.php
r7792 r7801 11 11 12 12 const PACKAGE_NAME = 'WordPress'; 13 14 /** 15 * WordPress directory to scan for string extraction. 16 * 17 * @var string 18 */ 19 protected $source; 20 21 /** 22 * Directory to store resulting POT files. 23 * 24 * @var string 25 */ 26 protected $destination; 13 27 14 28 /** … … 27 41 */ 28 42 public function __invoke( $args, $assoc_args ) { 29 $source = trailingslashit( realpath( $args[0] ) ); 30 $destination = trailingslashit( realpath( $args[1] ) ); 43 $this->source = realpath( $args[0] ); 44 $this->destination = realpath( $args[1] ); 45 46 $wp_version = $this->get_wp_version(); 47 if ( ! $wp_version ) { 48 WP_CLI::error( 'WordPress version not found.' ); 49 } 50 51 if ( version_compare( $wp_version, '3.7-beta', '<' ) ) { 52 WP_CLI::error( 'Unsupported WordPress version. Use makepot.php.' ); 53 } 31 54 32 55 $dry_run = Utils\get_flag_value( $assoc_args, 'dry-run', false ); … … 43 66 44 67 // Continents and cities. 45 $command = 'i18n make-pot ' . escapeshellarg( $ source );46 $command .= ' ' . escapeshellarg( $ destination . 'wordpress-continents-cities.pot' );68 $command = 'i18n make-pot ' . escapeshellarg( $this->source ); 69 $command .= ' ' . escapeshellarg( $this->destination . '/wordpress-continents-cities.pot' ); 47 70 $command .= ' --include="wp-admin/includes/continents-cities.php"'; 48 71 $command .= ' --package-name=' . escapeshellarg( self::PACKAGE_NAME ); … … 56 79 57 80 // Front end. 58 $command = 'i18n make-pot ' . escapeshellarg( $ source );59 $command .= ' ' . escapeshellarg( $ destination . 'wordpress.pot' );81 $command = 'i18n make-pot ' . escapeshellarg( $this->source ); 82 $command .= ' ' . escapeshellarg( $this->destination . '/wordpress.pot' ); 60 83 $command .= ' --exclude="wp-admin/*,wp-content/themes/*,wp-includes/class-pop3.php,wp-content/plugins/akismet/"'; 61 84 $command .= ' --package-name=' . escapeshellarg( self::PACKAGE_NAME ); … … 71 94 $hello_dolly_pot = wp_tempnam( 'hello-dolly.pot' ); 72 95 73 $command = 'i18n make-pot ' . escapeshellarg( $ source . 'wp-content/plugins' );96 $command = 'i18n make-pot ' . escapeshellarg( $this->source . '/wp-content/plugins' ); 74 97 $command .= ' ' . escapeshellarg( $hello_dolly_pot ); 75 98 $command .= ' --exclude="akismet/*"'; … … 84 107 ! $dry_run && WP_CLI::runcommand( $command/*, [ 'launch' => false ]*/ ); 85 108 86 # Admin. 87 $command = 'i18n make-pot ' . escapeshellarg( $source ); 88 $command .= ' ' . escapeshellarg( $destination . 'wordpress-admin.pot' ); 89 $command .= ' --exclude="wp-admin/network/*,wp-admin/network.php,wp-admin/includes/class-wp-ms*,wp-admin/includes/network.php,wp-admin/includes/continents-cities.php"'; 109 // Admin. 110 $admin_network_files = [ 111 'wp-admin/network/*', 112 'wp-admin/network.php', 113 ]; 114 115 // See https://core.trac.wordpress.org/ticket/34910. 116 if ( version_compare( $wp_version, '4.5-beta', '>=' ) ) { 117 $admin_network_files = array_merge( $admin_network_files, [ 118 'wp-admin/includes/class-wp-ms*', 119 'wp-admin/includes/network.php', 120 ] ); 121 } 122 123 $command = 'i18n make-pot ' . escapeshellarg( $this->source ); 124 $command .= ' ' . escapeshellarg( $this->destination . '/wordpress-admin.pot' ); 125 $command .= ' --exclude=' . escapeshellarg( implode( ',', array_merge( [ 'wp-admin/includes/continents-cities.php' ], $admin_network_files ) ) ); 90 126 $command .= ' --include="wp-admin/*"'; 91 127 $command .= ' --merge=' . escapeshellarg( $hello_dolly_pot ); 92 $command .= ' --subtract=' . escapeshellarg( $ destination . 'wordpress.pot' );128 $command .= ' --subtract=' . escapeshellarg( $this->destination . '/wordpress.pot' ); 93 129 $command .= ' --package-name=' . escapeshellarg( self::PACKAGE_NAME ); 94 130 $command .= ' --headers=' . escapeshellarg( $headers ); … … 102 138 unlink( $hello_dolly_pot ); 103 139 104 #Admin Network.105 $command = 'i18n make-pot ' . escapeshellarg( $ source );106 $command .= ' ' . escapeshellarg( $ destination . 'wordpress-admin-network.pot' );107 $command .= ' --include= "wp-admin/network/*,wp-admin/network.php,wp-admin/includes/class-wp-ms*,wp-admin/includes/network.php"';108 $command .= ' --subtract=' . escapeshellarg( sprintf( '%1$s wordpress.pot,%1$swordpress-admin.pot', $destination ) );140 // Admin Network. 141 $command = 'i18n make-pot ' . escapeshellarg( $this->source ); 142 $command .= ' ' . escapeshellarg( $this->destination . '/wordpress-admin-network.pot' ); 143 $command .= ' --include=' . escapeshellarg( implode( ',', $admin_network_files ) ); 144 $command .= ' --subtract=' . escapeshellarg( sprintf( '%1$s/wordpress.pot,%1$s/wordpress-admin.pot', $this->destination ) ); 109 145 $command .= ' --package-name=' . escapeshellarg( self::PACKAGE_NAME ); 110 146 $command .= ' --headers=' . escapeshellarg( $headers ); … … 116 152 ! $dry_run && WP_CLI::runcommand( $command/*, [ 'launch' => false ]*/ ); 117 153 } 154 155 /** 156 * Extracts the WordPress version number from wp-includes/version.php. 157 * 158 * @return string|false Version number on success, false otherwise. 159 */ 160 private function get_wp_version() { 161 $version_php = $this->source . '/wp-includes/version.php'; 162 if ( ! file_exists( $version_php ) || ! is_readable( $version_php ) ) { 163 return false; 164 } 165 166 return preg_match( '/\$wp_version\s*=\s*\'(.*?)\';/', file_get_contents( $version_php ), $matches ) ? $matches[1] : false; 167 } 118 168 }
Note: See TracChangeset
for help on using the changeset viewer.