Skip to content

Commit 94e1800

Browse files
author
David Ryan
committed
filter
1 parent ebc53e8 commit 94e1800

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

app/admin/class-product-machine.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ class Product_Machine {
2222
* @param array $config
2323
*/
2424
public function __construct( $filename, $origin_dir, $tmp_dir, $data, $config ) {
25-
add_filter( 'wp_phx_plugingen_file_contents', array( $this, 'process_file_contents_via_filter' ) );
25+
/**
26+
* Each file gets passed through this filter for processing
27+
*/
28+
add_filter(
29+
'wp_phx_plugingen_file_contents',
30+
array( $this, 'process_file_contents_via_filter' )
31+
);
2632
self::make_zip_download( $filename, $origin_dir, $tmp_dir, $data, $config );
2733
}
2834

2935
/**
3036
* Create a .ZIP download for the plugin generator
31-
* @todo: abstract to use for multiple generators
3237
*
3338
* @param $filename
3439
* @param $origin_dir
@@ -48,7 +53,8 @@ static function make_zip_download( $filename, $origin_dir, $tmp_dir, $data, $con
4853
// check we have filesystem write access
4954
if ( $creation_success ) {
5055
// write json containing configuration data
51-
$zip->addFromString( 'plugin-data.json', json_encode( array( 'data' => $data, 'config' => $config ) ) );
56+
$plugin_data = apply_filter( 'wp_phx_plugingen_datazip', array( 'data' => $data, 'config' => $config ) );
57+
$zip->addFromString( 'plugin-data.json', json_encode( $plugin_data ) );
5258
// maybe include license
5359
if ( 'gpl' === $data['plugin_license'] ) {
5460
$zip->addFromString( 'LICENSE', file_get_contents( dirname( __FILE__ ) . '/templates/gpl.txt' ) );
@@ -129,7 +135,12 @@ static function process_file_contents( $file ) {
129135
$contents = str_ireplace( '<%= US_SLUG %>', strtolower( str_ireplace( '-', '_', $sanitized_name ) ), $contents );
130136
$contents = str_ireplace( '<%= PKG %>', str_ireplace( '-', '_', ucwords( $sanitized_name ) ), $contents );
131137

132-
if ( 'main.php' === $filename || 'README.md' === $filename ) {
138+
$important_files = apply_filters( 'wp_phx_plugingen_file_contents', array(
139+
'main.php',
140+
'README.md',
141+
) );
142+
143+
if ( in_array( $filename, $important_files ) ) {
133144
$contents = str_ireplace( '<%= AUTHORS %>', $d['plugin_authors'], $contents );
134145
$contents = str_ireplace( '<%= TEAM %>', ! empty( $d['plugin_teamorg'] ) ? ' - ' . $d['plugin_teamorg'] : '', $contents );
135146
$contents = str_ireplace( '<%= LICENSE_TEXT %>', self::version_text( $d ), $contents );

0 commit comments

Comments
 (0)