Changeset 3479064
- Timestamp:
- 03/10/2026 12:40:07 PM (3 weeks ago)
- Location:
- toys-for-playground
- Files:
-
- 9 added
- 1 deleted
- 4 edited
-
tags/1.2.2 (deleted)
-
tags/1.2.5 (added)
-
tags/1.2.5/cloner.php (added)
-
tags/1.2.5/generator.php (added)
-
tags/1.2.5/plugin-explorer.js (added)
-
tags/1.2.5/readme.txt (added)
-
tags/1.2.5/sharer.php (added)
-
tags/1.2.5/theme-explorer.js (added)
-
tags/1.2.5/toys-for-playground.php (added)
-
tags/1.2.5/uninstall.php (added)
-
trunk/cloner.php (modified) (3 diffs)
-
trunk/generator.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/toys-for-playground.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
toys-for-playground/trunk/cloner.php
r3479038 r3479064 1 <div class='wrap'>2 <h1><?php esc_html_e('Cloner', 'toys-for-playground'); ?></h1>3 1 <?php 2 // Retrieve all plugins and themes, both active and inactive. 3 function toys_for_playground_get_all_plugins() { 4 $main_plugin_basename = defined( 'TOYSPG_MAIN_PLUGIN_BASENAME' ) ? TOYSPG_MAIN_PLUGIN_BASENAME : plugin_basename( __FILE__ ); 5 $all_plugins = get_plugins(); 6 $active_plugins = get_option( 'active_plugins', [] ); 7 $plugins_data = [ 'active' => [], 'inactive' => [] ]; 4 8 5 // Retrieve all plugins and themes, both active and inactive. 6 function toys_for_playground_get_all_plugins() { 7 $main_plugin_basename = defined('TOYSPG_MAIN_PLUGIN_BASENAME') ? TOYSPG_MAIN_PLUGIN_BASENAME : plugin_basename(__FILE__); 8 $all_plugins = get_plugins(); 9 $active_plugins = get_option('active_plugins', []); 10 $plugins_data = ['active' => [], 'inactive' => []]; 11 12 $plugin_basename = plugin_basename(__FILE__); 13 14 foreach($all_plugins as $plugin_path => $plugin) { 15 // Exclude the own plugin 16 if ($plugin_path !== $main_plugin_basename) { 17 $slug = explode('/', $plugin_path)[0]; 18 $plugin['slug'] = sanitize_key($slug); 19 if (in_array($plugin_path, $active_plugins)) { 20 $plugins_data['active'][] = $plugin; 21 } else { 22 $plugins_data['inactive'][] = $plugin; 23 } 9 foreach ( $all_plugins as $plugin_path => $plugin ) { 10 // Exclude the own plugin. 11 if ( $plugin_path !== $main_plugin_basename ) { 12 $slug = explode( '/', $plugin_path )[0]; 13 $plugin['slug'] = sanitize_key( $slug ); 14 if ( in_array( $plugin_path, $active_plugins ) ) { 15 $plugins_data['active'][] = $plugin; 16 } else { 17 $plugins_data['inactive'][] = $plugin; 24 18 } 25 19 } 26 27 return $plugins_data;28 20 } 29 21 30 function toys_for_playground_get_all_themes() { 31 $all_themes = wp_get_themes(); 32 $active_theme = wp_get_theme(); 33 $themes_data = ['active' => [], 'inactive' => []]; 22 return $plugins_data; 23 } 34 24 35 foreach($all_themes as $theme) { 36 $theme_data = [ 37 'name' => sanitize_text_field($theme->get('Name')), 38 'slug' => sanitize_key(strtolower($theme->get('TextDomain'))), 39 ]; 25 function toys_for_playground_get_all_themes() { 26 $all_themes = wp_get_themes(); 27 $active_theme = wp_get_theme(); 28 $themes_data = [ 'active' => [], 'inactive' => [] ]; 40 29 41 if($active_theme->get('Name') === $theme->get('Name')) { 42 $themes_data['active'][] = $theme_data; 43 } else { 44 $themes_data['inactive'][] = $theme_data; 45 } 30 foreach ( $all_themes as $theme ) { 31 $theme_data = [ 32 'name' => sanitize_text_field( $theme->get( 'Name' ) ), 33 'slug' => sanitize_key( strtolower( $theme->get( 'TextDomain' ) ) ), 34 ]; 35 36 if ( $active_theme->get( 'Name' ) === $theme->get( 'Name' ) ) { 37 $themes_data['active'][] = $theme_data; 38 } else { 39 $themes_data['inactive'][] = $theme_data; 46 40 } 47 48 return $themes_data;49 41 } 50 42 51 // Render the plugin configuration page. 43 return $themes_data; 44 } 52 45 53 function toys_for_playground_render_cloner_page() { 54 $plugins = toys_for_playground_get_all_plugins('toys-for-playground/toys-for-playground.php'); 55 $themes = toys_for_playground_get_all_themes(); 46 // Render the plugin configuration page. 47 function toys_for_playground_render_cloner_page() { 48 $plugins = toys_for_playground_get_all_plugins(); 49 $themes = toys_for_playground_get_all_themes(); 56 50 57 // Define WordPress and PHP versions.58 $wp_versions = ['6.3', '6.4', '6.5', '6.6', '6.7', '6.8', '6.9', 'nightly', 'latest', 'beta'];59 $php_versions = ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'];51 // Define WordPress and PHP versions. 52 $wp_versions = [ '6.3', '6.4', '6.5', '6.6', '6.7', '6.8', '6.9', 'nightly', 'latest', 'beta' ]; 53 $php_versions = [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]; 60 54 61 ob_start(); ?> 55 ob_start(); ?> 56 57 <div class="wrap"> 58 <h1><?php esc_html_e( 'Cloner', 'toys-for-playground' ); ?></h1> 62 59 63 60 <div class="notice notice-warning"> 64 <p><?php esc_html_e( 'Alert: Uncheck non-repository plugins or themes (e.g. premium or custom) for Playground to load correctly. The API can only load content from the repository.', 'toys-for-playground'); ?></p>61 <p><?php esc_html_e( 'Alert: Uncheck non-repository plugins or themes (e.g. premium or custom) for Playground to load correctly. The API can only load content from the repository.', 'toys-for-playground' ); ?></p> 65 62 </div> 66 63 67 64 <form method="post" action=""> 68 <?php wp_nonce_field("toys_for_playground_action", "toys_for_playground_nonce"); ?> 69 <h2><?php esc_html_e('Active Plugins', 'toys-for-playground'); ?></h2> 70 <p><?php esc_html_e('Active plugins are checked by default.', 'toys-for-playground'); ?></p> 65 <?php wp_nonce_field( 'toys_for_playground_action', 'toys_for_playground_nonce' ); ?> 71 66 72 <?php foreach($plugins['active'] as $plugin): ?> 73 <label><input type="checkbox" name="plugins[]" value="<?php echo esc_attr($plugin['slug']) ?>" checked /> <?php echo esc_html($plugin['Name']) ?></label><br/> 67 <h2><?php esc_html_e( 'Active Plugins', 'toys-for-playground' ); ?></h2> 68 <p><?php esc_html_e( 'Active plugins are checked by default.', 'toys-for-playground' ); ?></p> 69 70 <?php foreach ( $plugins['active'] as $plugin ) : ?> 71 <label><input type="checkbox" name="plugins[]" value="<?php echo esc_attr( $plugin['slug'] ); ?>" checked /> <?php echo esc_html( $plugin['Name'] ); ?></label><br/> 74 72 <?php endforeach; ?> 75 73 76 <h2><?php esc_html_e( 'Inactive Plugins', 'toys-for-playground'); ?></h2>77 <p><?php esc_html_e( 'Inactive plugins are unchecked by default.', 'toys-for-playground'); ?></p>74 <h2><?php esc_html_e( 'Inactive Plugins', 'toys-for-playground' ); ?></h2> 75 <p><?php esc_html_e( 'Inactive plugins are unchecked by default.', 'toys-for-playground' ); ?></p> 78 76 79 <?php foreach ($plugins['inactive'] as $plugin): ?>80 <label><input type="checkbox" name="plugins[]" value="<?php echo esc_attr( $plugin['slug']) ?>" /> <?php echo esc_html($plugin['Name'])?></label><br/>77 <?php foreach ( $plugins['inactive'] as $plugin ) : ?> 78 <label><input type="checkbox" name="plugins[]" value="<?php echo esc_attr( $plugin['slug'] ); ?>" /> <?php echo esc_html( $plugin['Name'] ); ?></label><br/> 81 79 <?php endforeach; ?> 82 80 83 <h2><?php esc_html_e( 'Active Theme', 'toys-for-playground'); ?></h2>84 <p><?php esc_html_e( 'Active theme are checked by default. Only one theme can be uploaded per Playground API request.', 'toys-for-playground'); ?></p>81 <h2><?php esc_html_e( 'Active Theme', 'toys-for-playground' ); ?></h2> 82 <p><?php esc_html_e( 'Active theme are checked by default. Only one theme can be uploaded per Playground API request.', 'toys-for-playground' ); ?></p> 85 83 86 <?php foreach ($themes['active'] as $theme): ?>87 <label><input type="checkbox" name="themes[]" value="<?php echo esc_attr( $theme['slug']) ?>" checked /> <?php echo esc_html($theme['name'])?></label><br/>84 <?php foreach ( $themes['active'] as $theme ) : ?> 85 <label><input type="checkbox" name="themes[]" value="<?php echo esc_attr( $theme['slug'] ); ?>" checked /> <?php echo esc_html( $theme['name'] ); ?></label><br/> 88 86 <?php endforeach; ?> 89 87 90 <h2><?php esc_html_e( 'Inactive Themes', 'toys-for-playground'); ?></h2>91 <p><?php esc_html_e( 'Inactive themes are unchecked by default. Only one theme can be uploaded per Playground API request.', 'toys-for-playground'); ?></p>88 <h2><?php esc_html_e( 'Inactive Themes', 'toys-for-playground' ); ?></h2> 89 <p><?php esc_html_e( 'Inactive themes are unchecked by default. Only one theme can be uploaded per Playground API request.', 'toys-for-playground' ); ?></p> 92 90 93 <?php foreach ($themes['inactive'] as $theme): ?>94 <label><input type="checkbox" name="themes[]" value="<?php echo esc_attr( $theme['slug']) ?>" /> <?php echo esc_html($theme['name'])?></label><br/>91 <?php foreach ( $themes['inactive'] as $theme ) : ?> 92 <label><input type="checkbox" name="themes[]" value="<?php echo esc_attr( $theme['slug'] ); ?>" /> <?php echo esc_html( $theme['name'] ); ?></label><br/> 95 93 <?php endforeach; ?> 96 94 97 <h2><?php esc_html_e( 'WordPress Version', 'toys-for-playground'); ?></h2>98 <p><?php esc_html_e( 'Select the WordPress version for your generated Playground.', 'toys-for-playground'); ?></p>95 <h2><?php esc_html_e( 'WordPress Version', 'toys-for-playground' ); ?></h2> 96 <p><?php esc_html_e( 'Select the WordPress version for your generated Playground.', 'toys-for-playground' ); ?></p> 99 97 100 98 <select name="wp_version"> 101 <option value=""><?php esc_html_e( 'WP Version', 'toys-for-playground'); ?></option>102 <?php foreach ($wp_versions as $version): ?>103 <option value="<?php echo esc_attr( $version) ?>"><?php echo esc_html($version)?></option>99 <option value=""><?php esc_html_e( 'WP Version', 'toys-for-playground' ); ?></option> 100 <?php foreach ( $wp_versions as $version ) : ?> 101 <option value="<?php echo esc_attr( $version ); ?>"><?php echo esc_html( $version ); ?></option> 104 102 <?php endforeach; ?> 105 103 </select> 106 104 107 <h2><?php esc_html_e( 'PHP Version', 'toys-for-playground'); ?></h2>108 <p><?php esc_html_e( 'Select the PHP version for your generated Playground.', 'toys-for-playground'); ?></p>105 <h2><?php esc_html_e( 'PHP Version', 'toys-for-playground' ); ?></h2> 106 <p><?php esc_html_e( 'Select the PHP version for your generated Playground.', 'toys-for-playground' ); ?></p> 109 107 110 108 <select name="php_version"> 111 <option value=""><?php esc_html_e( 'PHP Version', 'toys-for-playground'); ?></option>112 <?php foreach ($php_versions as $version): ?>113 <option value="<?php echo esc_attr( $version) ?>"><?php echo esc_html($version)?></option>109 <option value=""><?php esc_html_e( 'PHP Version', 'toys-for-playground' ); ?></option> 110 <?php foreach ( $php_versions as $version ) : ?> 111 <option value="<?php echo esc_attr( $version ); ?>"><?php echo esc_html( $version ); ?></option> 114 112 <?php endforeach; ?> 115 113 </select> 116 114 117 <h2><?php esc_html_e( 'Storage', 'toys-for-playground'); ?></h2>118 <p><?php esc_html_e( 'Select the storage type for your generated Playground.', 'toys-for-playground'); ?></p>115 <h2><?php esc_html_e( 'Storage', 'toys-for-playground' ); ?></h2> 116 <p><?php esc_html_e( 'Select the storage type for your generated Playground.', 'toys-for-playground' ); ?></p> 119 117 <input type="checkbox" id="none" name="storage_none" value="none" checked> 120 <label for="none"><?php esc_html_e( 'None: changes will be lost on page refresh.', 'toys-for-playground'); ?></label><br>118 <label for="none"><?php esc_html_e( 'None: changes will be lost on page refresh.', 'toys-for-playground' ); ?></label><br> 121 119 <input type="checkbox" id="browser" name="storage_browser" value="browser"> 122 <label for="browser"><?php esc_html_e( 'Browser: stored in this browser (cookies).', 'toys-for-playground'); ?></label><br>120 <label for="browser"><?php esc_html_e( 'Browser: stored in this browser (cookies).', 'toys-for-playground' ); ?></label><br> 123 121 124 122 <script> … … 142 140 143 141 <br/> 144 <input type="submit" name="generate" class="button button-primary button-hero" value="<?php esc_attr_e( 'Clone', 'toys-for-playground'); ?>" />145 <p><?php esc_html_e( "Opens in a new window. Enable pop-ups in your browser if it doesn't.", 'toys-for-playground'); ?></p>142 <input type="submit" name="generate" class="button button-primary button-hero" value="<?php esc_attr_e( 'Clone', 'toys-for-playground' ); ?>" /> 143 <p><?php esc_html_e( "Opens in a new window. Enable pop-ups in your browser if it doesn't.", 'toys-for-playground' ); ?></p> 146 144 </form> 147 <?php if (current_user_can('manage_options') && isset($_POST["generate"]) && wp_verify_nonce($_POST["toys_for_playground_nonce"], "toys_for_playground_action")): ?> 145 146 <?php if ( current_user_can( 'manage_options' ) && isset( $_POST['generate'] ) && wp_verify_nonce( $_POST['toys_for_playground_nonce'], 'toys_for_playground_action' ) ) : ?> 148 147 <script> 149 148 var url = "https://playground.wordpress.net/?"; 150 <?php $_POST['plugins'] = array_map('sanitize_text_field', (array) $_POST['plugins']); 151 foreach($_POST['plugins'] as $plugin_slug): ?> 152 url += "plugin=<?php echo esc_js(sanitize_key($plugin_slug)) ?>&"; 149 <?php 150 $post_plugins = array_map( 'sanitize_text_field', (array) ( isset( $_POST['plugins'] ) ? $_POST['plugins'] : [] ) ); 151 foreach ( $post_plugins as $plugin_slug ) : ?> 152 url += "plugin=<?php echo esc_js( sanitize_key( $plugin_slug ) ); ?>&"; 153 153 <?php endforeach; ?> 154 <?php $_POST['themes'] = array_map('sanitize_text_field', (array) $_POST['themes']); 155 foreach($_POST['themes'] as $theme_slug): ?> 156 url += "theme=<?php echo esc_js(sanitize_key($theme_slug)) ?>&"; 154 <?php 155 $post_themes = array_map( 'sanitize_text_field', (array) ( isset( $_POST['themes'] ) ? $_POST['themes'] : [] ) ); 156 foreach ( $post_themes as $theme_slug ) : ?> 157 url += "theme=<?php echo esc_js( sanitize_key( $theme_slug ) ); ?>&"; 157 158 <?php endforeach; ?> 158 159 159 if ("<?php echo esc_html(sanitize_text_field($_POST['wp_version'])) ?>" !== "") { 160 url += "wp=<?php echo esc_js(sanitize_text_field($_POST['wp_version'])) ?>&"; 160 <?php $wp_version = isset( $_POST['wp_version'] ) ? sanitize_text_field( $_POST['wp_version'] ) : ''; ?> 161 if ("<?php echo esc_js( $wp_version ); ?>" !== "") { 162 url += "wp=<?php echo esc_js( $wp_version ); ?>&"; 161 163 } 162 if ("<?php echo esc_html(sanitize_text_field($_POST['php_version'])) ?>" !== "") { 163 url += "php=<?php echo esc_js(sanitize_text_field($_POST['php_version'])) ?>&"; 164 <?php $php_version = isset( $_POST['php_version'] ) ? sanitize_text_field( $_POST['php_version'] ) : ''; ?> 165 if ("<?php echo esc_js( $php_version ); ?>" !== "") { 166 url += "php=<?php echo esc_js( $php_version ); ?>&"; 164 167 } 165 168 166 169 url += "url=/wp-admin/index.php&mode=seamless"; 167 170 168 <?php if ( isset($_POST['storage_browser']) && sanitize_text_field($_POST['storage_browser']) === 'browser'): ?>171 <?php if ( isset( $_POST['storage_browser'] ) && sanitize_text_field( $_POST['storage_browser'] ) === 'browser' ) : ?> 169 172 url += "&storage=browser"; 170 <?php else : ?>173 <?php else : ?> 171 174 url += "&storage=none"; 172 175 <?php endif; ?> … … 174 177 window.open(url); 175 178 </script> 176 <?php endif; 177 echo ob_get_clean(); 178 } 179 <?php endif; ?> 179 180 180 toys_for_playground_render_cloner_page();181 </div> 181 182 182 echo "</div>"; 183 <?php 184 echo ob_get_clean(); 185 } 186 187 toys_for_playground_render_cloner_page(); -
toys-for-playground/trunk/generator.php
r3479038 r3479064 80 80 <?php endforeach; ?> 81 81 82 <?php $_POST['theme'] = sanitize_text_field($_POST['theme']); ?>83 url += "theme=<?php echo esc_js( sanitize_key($_POST['theme']))?>&";82 <?php $_POST['theme'] = isset( $_POST['theme'] ) ? sanitize_text_field( $_POST['theme'] ) : ''; ?> 83 url += "theme=<?php echo esc_js( sanitize_key( $_POST['theme'] ) ); ?>&"; 84 84 85 85 <?php $_POST['wp_version'] = sanitize_text_field($_POST['wp_version']); ?> -
toys-for-playground/trunk/readme.txt
r3479038 r3479064 6 6 Requires PHP: 7.4 7 7 Tested PHP: 8.3 8 Stable tag: 1.2. 48 Stable tag: 1.2.5 9 9 License: GNU General Public License v2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 44 44 45 45 == Changelog == 46 47 = [1.2.5] - 2026-10-03 = 48 49 * Security: Escaped Settings link with esc_html__() in plugin action links. 50 * Fix: Added isset() guards for $_POST['themes'], $_POST['wp_version'], $_POST['php_version'] in cloner.php to prevent PHP warnings. 51 * Fix: Added isset() guard for $_POST['theme'] in generator.php to prevent PHP warnings. 52 * Code: Removed unused $plugin_basename variable from cloner.php. 53 * Code: cloner.php now starts with <?php and closes the wrap div in HTML. 54 * Performance: get_option('enable_sharer') stored in variable to avoid repeated calls. 46 55 47 56 = [1.2.4] - 2026-10-03 = -
toys-for-playground/trunk/toys-for-playground.php
r3479038 r3479064 4 4 Plugin URI: https://wordpress.org/plugins/toys-for-playground/ 5 5 Description: Toys for Playground allows you to set up development, training, and testing environments in WordPress Playground easily. No Playground API knowledge needed. 6 Version: 1.2. 46 Version: 1.2.5 7 7 Requires at least: 6.3 8 8 Tested up to: 6.9 … … 17 17 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly 18 18 19 define( 'TOYSPG_VERSION', '1.2. 4' );19 define( 'TOYSPG_VERSION', '1.2.5' ); 20 20 21 21 22 22 // Add settings link to plugin page 23 23 function toys_for_playground_add_settings_link($links) { 24 $settings_link = '<a href="admin.php?page=toys-playground">' . __('Settings', 'toys-for-playground') . '</a>';24 $settings_link = '<a href="admin.php?page=toys-playground">' . esc_html__( 'Settings', 'toys-for-playground' ) . '</a>'; 25 25 array_unshift($links, $settings_link); 26 26 return $links; … … 98 98 <h2><?php esc_html_e('Sharer', 'toys-for-playground'); ?></h2> 99 99 <p><?php esc_html_e('Generate a Playground link of your current WordPress page for debugging or sharing.', 'toys-for-playground'); ?></p> 100 100 <?php $sharer_enabled = (bool) get_option( 'enable_sharer', 0 ); ?> 101 101 <form method="post" action=""> 102 <input type="hidden" name="toggle_sharer" value="<?php echo get_option('enable_sharer', 0)? '0' : '1'; ?>">103 <input type="submit" class="button" value="<?php echo get_option('enable_sharer', 0)? esc_html_e('Disable Sharer', 'toys-for-playground') : esc_html_e('Enable Sharer', 'toys-for-playground'); ?>">102 <input type="hidden" name="toggle_sharer" value="<?php echo $sharer_enabled ? '0' : '1'; ?>"> 103 <input type="submit" class="button" value="<?php $sharer_enabled ? esc_html_e('Disable Sharer', 'toys-for-playground') : esc_html_e('Enable Sharer', 'toys-for-playground'); ?>"> 104 104 </form> 105 105 </div> … … 116 116 // Function to include sharer.php in the footer 117 117 function toys_for_playground_include_sharer_in_footer() { 118 if (get_option('enable_sharer') == 1) { 119 include_once(plugin_dir_path(__FILE__) . 'sharer.php'); 118 $sharer_enabled = (bool) get_option( 'enable_sharer', 0 ); 119 if ( $sharer_enabled ) { 120 include_once( plugin_dir_path( __FILE__ ) . 'sharer.php' ); 120 121 } 121 122 }
Note: See TracChangeset
for help on using the changeset viewer.