Created
May 28, 2026 02:34
-
-
Save jasperf/d78b76f589e51dd4d047c5b556b5be5f to your computer and use it in GitHub Desktop.
Claude using python script to update admin form fields order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with open('/Users/user/code/warder-cookie-consent/warder-cookie-consent.php', 'r') as f: | |
| content = f.read() | |
| # 1. Replace the "Add Cookie" button div + category section closing </div> | |
| # with the button + inline container + closing </div> | |
| old_button_section = ''' \t\t\t\t\t<div style="margin-top: 10px;"> | |
| \t\t\t\t\t\t<button type="button" class="button show-add-cookie-form" data-category="<?php echo esc_attr( \$category_id ); ?>"> | |
| \t\t\t\t\t\t\t<?php esc_html_e( 'Add Cookie to this Category', 'warder-cookie-consent' ); ?> | |
| \t\t\t\t\t\t</button> | |
| \t\t\t\t\t</div> | |
| \t\t\t\t</div> | |
| \t\t\t\t\t<?php | |
| \t\t\tendforeach;''' | |
| new_button_section = ''' \t\t\t\t\t<div style="margin-top: 10px;"> | |
| \t\t\t\t\t\t<button type="button" class="button show-add-cookie-form" data-category="<?php echo esc_attr( \$category_id ); ?>"> | |
| \t\t\t\t\t\t\t<?php esc_html_e( 'Add Cookie to this Category', 'warder-cookie-consent' ); ?> | |
| \t\t\t\t\t\t</button> | |
| \t\t\t\t\t</div> | |
| \t\t\t\t\t<div class="warder-add-cookie-form-container" style="margin-top: 10px; display: none;" | |
| \t\t\t\t\tid="warder-add-cookie-form-<?php echo esc_attr( \$category_id ); ?>"> | |
| \t\t\t\t\t\t<div style="padding: 15px; background: #f5f5f5; border: 1px solid #ddd;"> | |
| \t\t\t\t\t\t\t<h4> | |
| \t\t\t\t\t\t\t\t<?php | |
| \t\t\t\t\t\t\t\t/* translators: %s: cookie category title. */ | |
| \t\t\t\t\t\t\t\tprintf( esc_html__( 'Add Cookie to "%s"', 'warder-cookie-consent' ), esc_html( \$category['title'] ) ); | |
| \t\t\t\t\t\t\t\t?> | |
| \t\t\t\t\t\t\t</h4> | |
| \t\t\t\t\t\t\t<div class="scc-add-cookie-form-fields"> | |
| \t\t\t\t\t\t\t\t<?php wp_nonce_field( 'warder_add_cookie', 'warder_cookie_nonce' ); ?> | |
| \t\t\t\t\t\t\t\t<input type="hidden" name="category_id" value="<?php echo esc_attr( \$category_id ); ?>" /> | |
| \t\t\t\t\t\t\t\t<table class="form-table"> | |
| \t\t\t\t\t\t\t\t\t<tr> | |
| \t\t\t\t\t\t\t\t\t\t<th scope="row"><?php esc_html_e( 'Cookie Name/Pattern', 'warder-cookie-consent' ); ?></th> | |
| \t\t\t\t\t\t\t\t\t\t<td> | |
| \t\t\t\t\t\t\t\t\t\t\t<input type="text" name="cookie_name" placeholder="<?php esc_attr_e( 'e.g., _ga or /^_ga/', | |
| 'twarder-cookie-consent' ); ?>" class="regular-text" /> | |
| \t\t\t\t\t\t\t\t\t\t\t<p class="description"><?php esc_html_e( 'Enter a specific cookie name or a pattern to match multiple cookies.', 'warder-cookie-consent' ); ?></p> | |
| \t\t\t\t\t\t\t\t\t\t</td> | |
| \t\t\t\t\t\t\t\t\t</tr> | |
| \t\t\t\t\t\t\t\t\t<tr> | |
| \t\t\t\t\t\t\t\t\t\t<th scope="row"><?php esc_html_e( 'Match Type', 'warder-cookie-consent' ); ?></th> | |
| \t\t\t\t\t\t\t\t\t\t<td> | |
| \t\t\t\t\t\t\t\t\t\t\t<label> | |
| \t\t\t\t\t\t\t\t\t\t\t\t<input type="checkbox" name="is_regex" /> | |
| \t\t\t\t\t\t\t\t\t\t\t\t<?php esc_html_e( 'Regular Expression', 'warder-cookie-consent' ); ?> | |
| \t\t\t\t\t\t\t\t\t\t\t</label> | |
| \t\t\t\t\t\t\t\t\t\t\t<p class="description"><?php esc_html_e( 'Check if using a pattern like /^_ga/ to match multiple cookies.', 'warder-cookie-consent' ); ?></p> | |
| \t\t\t\t\t\t\t\t\t\t</td> | |
| \t\t\t\t\t\t\t\t\t</tr> | |
| \t\t\t\t\t\t\t\t</table> | |
| \t\t\t\t\t\t\t\t<p> | |
| \t\t\t\t\t\t\t\t\t<button type="button" class="button button-primary do-add-cookie"><?php esc_attr_e( 'Add Cookie', 'warder-cookie-consent' ); ?></button> | |
| \t\t\t\t\t\t\t\t\t<button type="button" class="button button-secondary cancel-add-cookie"><?php esc_html_e( 'Cancel', 'warder-cookie-consent' ); ?></button> | |
| \t\t\t\t\t\t\t\t</p> | |
| \t\t\t\t\t\t\t\t<h5><?php esc_html_e( 'Common Cookie Patterns', 'warder-cookie-consent' ); ?></h5> | |
| \t\t\t\t\t\t\t\t<ul class="cookie-pattern-examples"> | |
| \t\t\t\t\t\t\t\t\t<li><strong>Google Analytics:</strong> <code>/^_ga/</code>, <code>_gid</code>, <code>_gat</code></li> | |
| \t\t\t\t\t\t\t\t\t<li><strong>Facebook:</strong> <code>/^_fb/</code>, <code>/^fb_/</code>, <code>_fbp</code></li> | |
| \t\t\t\t\t\t\t\t\t<li><strong>Google Ads:</strong> <code>_gcl_au</code>, <code>/^_gcl_/</code></li> | |
| \t\t\t\t\t\t\t\t\t<li><strong>Matomo:</strong> <code>/^_pk_/</code>, <code>/^mtm_/</code></li> | |
| \t\t\t\t\t\t\t\t</ul> | |
| \t\t\t\t\t\t\t</div> | |
| \t\t\t\t\t\t</div> | |
| \t\t\t\t\t</div> | |
| \t\t\t\t</div> | |
| \t\t\t\t\t<?php | |
| \t\t\tendforeach;''' | |
| if old_button_section in content: | |
| content = content.replace(old_button_section, new_button_section, 1) | |
| print("Step 1: button section replaced OK") | |
| else: | |
| print("Step 1: MATCH FAILED") | |
| # Debug: find |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment