@artemsemkin/wp-headers 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +45 -4
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -10,7 +10,7 @@ npm install @artemsemkin/wp-headers
10
10
 
11
11
  ## What it does
12
12
 
13
- Reads `wp.theme` or `wp.plugin` fields from a `package.json` and writes properly formatted WordPress header comments to the corresponding files (`style.css`, plugin PHP, `readme.txt`). Also patches version strings in TGM-style plugin arrays.
13
+ Reads `wp.theme` or `wp.plugin` fields from a `package.json` and generates or updates WordPress header comments in target files (`style.css`, plugin PHP, `readme.txt`). If a file already contains a header comment, it replaces it in place. If not, it writes a new one. Also patches version strings in TGM-style PHP plugin arrays.
14
14
 
15
15
  ## Examples
16
16
 
@@ -85,7 +85,7 @@ Given this in your plugin's `package.json`:
85
85
  }
86
86
  ```
87
87
 
88
- Running `processMapping({ type: 'plugin', slug: 'flavor-core', entityDir: '/path/to/plugin' })` generates this at the top of `flavor-core.php`:
88
+ Running `processMapping({ type: 'plugin', slug: 'flavor-core', entityDir: '/path/to/plugin' })` generates or updates the header at the top of `flavor-core.php`:
89
89
 
90
90
  ```php
91
91
  /**
@@ -103,6 +103,47 @@ Running `processMapping({ type: 'plugin', slug: 'flavor-core', entityDir: '/path
103
103
  */
104
104
  ```
105
105
 
106
+ ### TGM version patching
107
+
108
+ WordPress themes commonly use TGMPA to register required plugins with minimum version constraints. When a plugin's `package.json` includes `wp.plugin.loadPluginsFile`, the tool finds the matching slug in the TGM PHP file and patches its version string.
109
+
110
+ Given this TGM registration file in your theme:
111
+
112
+ ```php
113
+ <?php
114
+
115
+ add_action( 'tgmpa_register', 'flavor_tgm_register_required_plugins' );
116
+ function flavor_tgm_register_required_plugins() {
117
+ $plugins = array(
118
+ array(
119
+ 'name' => 'Flavor Core',
120
+ 'slug' => 'flavor-core',
121
+ 'source' => esc_url( $core_plugin_url ),
122
+ 'required' => true,
123
+ 'version' => '1.0.0',
124
+ ),
125
+ array(
126
+ 'name' => 'Flavor Elementor',
127
+ 'slug' => 'flavor-elementor',
128
+ 'source' => esc_url( $elementor_plugin_url ),
129
+ 'required' => true,
130
+ 'version' => '1.0.0',
131
+ ),
132
+ );
133
+
134
+ tgmpa( $plugins, $config );
135
+ }
136
+ ```
137
+
138
+ When `flavor-core`'s `package.json` has `"version": "2.0.0"`, processing updates only the matching entry:
139
+
140
+ ```diff
141
+ - 'version' => '1.0.0',
142
+ + 'version' => '2.0.0',
143
+ ```
144
+
145
+ Whitespace alignment, quote styles, nested function calls, and other plugin entries are preserved.
146
+
106
147
  ## Usage
107
148
 
108
149
  ```ts
@@ -112,10 +153,10 @@ processMapping({
112
153
  type: 'plugin',
113
154
  slug: 'my-plugin',
114
155
  entityDir: '/path/to/plugin',
115
- tgmBasePath: '/path/to/theme/src/php', // optional: patches TGM version arrays
156
+ tgmBasePath: '/path/to/theme/src/php',
116
157
  })
117
158
  ```
118
159
 
119
160
  ## Vite integration
120
161
 
121
- Use [`@artemsemkin/vite-plugin-wp-headers`](https://github.com/artkrsk/vite-plugin-wp-headers) to run header generation during Vite's build lifecycle and watch for changes during dev.
162
+ Use [`@artemsemkin/vite-plugin-wp-headers`](https://www.npmjs.com/package/@artemsemkin/vite-plugin-wp-headers) to automate header generation during Vite's build lifecycle and watch for changes during dev.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artemsemkin/wp-headers",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Generate and patch WordPress file headers (style.css, plugin PHP, readme.txt, TGM)",
5
5
  "license": "MIT",
6
6
  "author": "Artem Semkin",