3v4l.org

run code in 500+ PHP versions simultaneously
<?php <?php /** * Plugin Name: CNMG Shop Ghana MLM Hierarchy * Plugin URI: https://example.com/cnmg-mlm * Description: Custom MLM registration system for CNMG Shop Ghana district hierarchy (District Aggregator → Zonal Agents → Community Agents). * Version: 1.0.0 * Author: Grok by xAI * License: GPL-2.0+ */ // If this file is called directly, abort. if ( ! defined( 'WPINC' ) ) { die; } define( 'CNMG_MLM_VERSION', '1.0.0' ); define( 'CNMG_MLM_PATH', plugin_dir_path( __FILE__ ) ); define( 'CNMG_MLM_URL', plugin_dir_url( __FILE__ ) ); /* === Activate: Create Custom Roles === */ function cnmg_mlm_activate() { add_role( 'district_aggregator', 'District Aggregator', array( 'read' => true ) ); add_role( 'zonal_agent', 'Zonal Agent', array( 'read' => true ) ); add_role( 'community_agent', 'Community Agent', array( 'read' => true ) ); } register_activation_hook( __FILE__, 'cnmg_mlm_activate' ); /* === User Profile Fields === */ function cnmg_mlm_user_profile_fields( $user ) { ?> <h3>CNMG MLM Hierarchy Info</h3> <table class="form-table"> <tr> <th><label>Sponsor ID</label></th> <td><input type="text" name="sponsor_id" value="<?php echo esc_attr( get_user_meta( $user->ID, 'sponsor_id', true ) ); ?>" class="regular-text" /></td> </tr> <tr> <th><label>Agent Type</label></th> <td> <select name="agent_type"> <option value="district_aggregator" <?php selected( get_user_meta( $user->ID, 'agent_type', true ), 'district_aggregator' ); ?>>District Aggregator</option> <option value="zonal_agent" <?php selected( get_user_meta( $user->ID, 'agent_type', true ), 'zonal_agent' ); ?>>Zonal Agent</option> <option value="community_agent" <?php selected( get_user_meta( $user->ID, 'agent_type', true ), 'community_agent' ); ?>>Community Agent</option> </select> </td> </tr> <tr> <th><label>District</label></th> <td><input type="text" name="district" value="<?php echo esc_attr( get_user_meta( $user->ID, 'district', true ) ); ?>" class="regular-text" /></td> </tr> <tr> <th><label>Zone</label></th> <td><input type="text" name="zone" value="<?php echo esc_attr( get_user_meta( $user->ID, 'zone', true ) ); ?>" class="regular-text" /></td> </tr> </table> <?php } add_action( 'show_user_profile', 'cnmg_mlm_user_profile_fields' ); add_action( 'edit_user_profile', 'cnmg_mlm_user_profile_fields' ); function cnmg_mlm_save_user_profile( $user_id ) { if ( ! current_user_can( 'edit_user', $user_id ) ) return; update_user_meta( $user_id, 'sponsor_id', sanitize_text_field( $_POST['sponsor_id'] ?? '' ) ); update_user_meta( $user_id, 'agent_type', sanitize_text_field( $_POST['agent_type'] ?? '' ) ); update_user_meta( $user_id, 'district', sanitize_text_field( $_POST['district'] ?? '' ) ); update_user_meta( $user_id, 'zone', sanitize_text_field( $_POST['zone'] ?? '' ) ); } add_action( 'personal_options_update', 'cnmg_mlm_save_user_profile' ); add_action( 'edit_user_profile_update', 'cnmg_mlm_save_user_profile' ); /* === Registration Form Shortcode === */ function cnmg_mlm_registration_form() { ob_start(); ?> <form method="post" style="max-width:600px; margin:30px auto; padding:20px; border:1px solid #ddd;"> <?php wp_nonce_field( 'cnmg_register', 'cnmg_nonce' ); ?> <p><label>Username<br><input type="text" name="username" required style="width:100%;"></label></p> <p><label>Email<br><input type="email" name="email" required style="width:100%;"></label></p> <p><label>Password<br><input type="password" name="password" required style="width:100%;"></label></p> <p><label>Sponsor ID<br><input type="text" name="sponsor_id" required style="width:100%;"></label></p> <p><label>Agent Type<br> <select name="agent_type" required style="width:100%;"> <option value="community_agent">Community Agent</option> <option value="zonal_agent">Zonal Agent</option> <option value="district_aggregator">District Aggregator</option> </select> </label></p> <p><label>District<br><input type="text" name="district" required style="width:100%;"></label></p> <p><label>Zone (optional)<br><input type="text" name="zone" style="width:100%;"></label></p> <input type="submit" name="cnmg_register" value="Register as Agent" style="padding:10px 20px;"> </form> <?php return ob_get_clean(); } add_shortcode( 'cnmg_registration_form', 'cnmg_mlm_registration_form' ); /* === Handle Registration === */ function cnmg_mlm_handle_registration() { if ( ! isset( $_POST['cnmg_register'] ) || ! wp_verify_nonce( $_POST['cnmg_nonce'], 'cnmg_register' ) ) { return; } $username = sanitize_user( $_POST['username'] ); $email = sanitize_email( $_POST['email'] ); $password = $_POST['password']; $sponsor_id = sanitize_text_field( $_POST['sponsor_id'] ); $agent_type = sanitize_text_field( $_POST['agent_type'] ); $district = sanitize_text_field( $_POST['district'] ); $zone = sanitize_text_field( $_POST['zone'] ); if ( username_exists( $username ) || email_exists( $email ) ) { echo '<p style="color:red;">Username or email already exists.</p>'; return; } $user_id = wp_create_user( $username, $password, $email ); if ( is_wp_error( $user_id ) ) { echo '<p style="color:red;">' . $user_id->get_error_message() . '</p>'; return; } $user = new WP_User( $user_id ); $user->set_role( $agent_type ); update_user_meta( $user_id, 'sponsor_id', $sponsor_id ); update_user_meta( $user_id, 'agent_type', $agent_type ); update_user_meta( $user_id, 'district', $district ); update_user_meta( $user_id, 'zone', $zone ); echo '<p style="color:green; font-weight:bold;">Registration successful! Your Agent ID is: <strong>' . $user_id . '</strong></p>'; } add_action( 'template_redirect', 'cnmg_mlm_handle_registration' );
Output for git.master_jit, git.master
Parse error: syntax error, unexpected token "<", expecting end of file in /in/sq7WZ on line 3
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
52.31 ms | 770 KiB | 3 Q