Plugin Directory

Changeset 3479064


Ignore:
Timestamp:
03/10/2026 12:40:07 PM (3 weeks ago)
Author:
Marc4
Message:

v1.2.5

Location:
toys-for-playground
Files:
9 added
1 deleted
4 edited

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>
    31<?php
     2// Retrieve all plugins and themes, both active and inactive.
     3function 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' => [] ];
    48
    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;
    2418            }
    2519        }
    26 
    27         return $plugins_data;
    2820    }
    2921
    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}
    3424
    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             ];
     25function toys_for_playground_get_all_themes() {
     26    $all_themes   = wp_get_themes();
     27    $active_theme = wp_get_theme();
     28    $themes_data  = [ 'active' => [], 'inactive' => [] ];
    4029
    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;
    4640        }
    47 
    48         return $themes_data;
    4941    }
    5042
    51     // Render the plugin configuration page.
     43    return $themes_data;
     44}
    5245
    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.
     47function toys_for_playground_render_cloner_page() {
     48    $plugins = toys_for_playground_get_all_plugins();
     49    $themes  = toys_for_playground_get_all_themes();
    5650
    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' ];
    6054
    61         ob_start(); ?>
     55    ob_start(); ?>
     56
     57    <div class="wrap">
     58        <h1><?php esc_html_e( 'Cloner', 'toys-for-playground' ); ?></h1>
    6259
    6360        <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>
    6562        </div>
    6663
    6764        <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' ); ?>
    7166
    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/>
    7472            <?php endforeach; ?>
    7573
    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>
    7876
    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/>
    8179            <?php endforeach; ?>
    8280
    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>
    8583
    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/>
    8886            <?php endforeach; ?>
    8987
    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>
    9290
    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/>
    9593            <?php endforeach; ?>
    9694
    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>
    9997
    10098            <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>
    104102                <?php endforeach; ?>
    105103            </select>
    106104
    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>
    109107
    110108            <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>
    114112                <?php endforeach; ?>
    115113            </select>
    116114
    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>
    119117            <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>
    121119            <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>
    123121
    124122            <script>
     
    142140
    143141            <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>
    146144        </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' ) ) : ?>
    148147            <script>
    149148                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 ) ); ?>&";
    153153                <?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 ) ); ?>&";
    157158                <?php endforeach; ?>
    158159
    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 ); ?>&";
    161163                }
    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 ); ?>&";
    164167                }
    165168
    166169                url += "url=/wp-admin/index.php&mode=seamless";
    167170
    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' ) : ?>
    169172                    url += "&storage=browser";
    170                 <?php else: ?>
     173                <?php else : ?>
    171174                    url += "&storage=none";
    172175                <?php endif; ?>
     
    174177                window.open(url);
    175178            </script>
    176         <?php endif;
    177         echo ob_get_clean();
    178     }
     179        <?php endif; ?>
    179180
    180     toys_for_playground_render_cloner_page();
     181    </div>
    181182
    182     echo "</div>";
     183    <?php
     184    echo ob_get_clean();
     185}
     186
     187toys_for_playground_render_cloner_page();
  • toys-for-playground/trunk/generator.php

    r3479038 r3479064  
    8080            <?php endforeach; ?>
    8181
    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'] ) ); ?>&";
    8484
    8585            <?php $_POST['wp_version'] = sanitize_text_field($_POST['wp_version']); ?>
  • toys-for-playground/trunk/readme.txt

    r3479038 r3479064  
    66Requires PHP: 7.4
    77Tested PHP: 8.3
    8 Stable tag: 1.2.4
     8Stable tag: 1.2.5
    99License: GNU General Public License v2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4444
    4545== 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.
    4655
    4756= [1.2.4] - 2026-10-03 =
  • toys-for-playground/trunk/toys-for-playground.php

    r3479038 r3479064  
    44Plugin URI: https://wordpress.org/plugins/toys-for-playground/
    55Description: 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.4
     6Version: 1.2.5
    77Requires at least: 6.3
    88Tested up to: 6.9
     
    1717if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    1818
    19 define( 'TOYSPG_VERSION', '1.2.4' );
     19define( 'TOYSPG_VERSION', '1.2.5' );
    2020
    2121
    2222// Add settings link to plugin page
    2323function 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>';
    2525    array_unshift($links, $settings_link);
    2626    return $links;
     
    9898            <h2><?php esc_html_e('Sharer', 'toys-for-playground'); ?></h2>
    9999            <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 ); ?>
    101101            <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'); ?>">
    104104            </form>
    105105        </div>
     
    116116// Function to include sharer.php in the footer
    117117function 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' );
    120121    }
    121122}
Note: See TracChangeset for help on using the changeset viewer.