--- a/wp-registration/debug-install.php
+++ b/wp-registration/debug-install.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Debug helper for WP Registration Plugin
+ * Add this to wp-config.php to enable: define('WPR_DEBUG_INSTALL', true);
+ */
+
+if (defined('WPR_DEBUG_INSTALL') && WPR_DEBUG_INSTALL) {
+
+ add_action('admin_notices', 'wpr_debug_installation_status');
+
+ function wpr_debug_installation_status() {
+ if (!current_user_can('manage_options')) return;
+
+ $default_form_id = get_option('wpr_default_signup_form');
+ $is_installed = get_option('wpr_is_installed');
+ $cpt_exists = post_type_exists('wpr');
+
+ echo '<div class="notice notice-info">';
+ echo '<h3>WP Registration Debug Info</h3>';
+ echo '<p><strong>Default Form ID:</strong> ' . ($default_form_id ? $default_form_id : 'Not set') . '</p>';
+ echo '<p><strong>Installation Status:</strong> ' . ($is_installed ? 'Installed' : 'Not installed') . '</p>';
+ echo '<p><strong>CPT Registered:</strong> ' . ($cpt_exists ? 'Yes' : 'No') . '</p>';
+
+ if ($default_form_id) {
+ $form_exists = get_post($default_form_id);
+ echo '<p><strong>Form Exists:</strong> ' . ($form_exists ? 'Yes' : 'No') . '</p>';
+ if ($form_exists) {
+ echo '<p><strong>Form Title:</strong> ' . $form_exists->post_title . '</p>';
+ echo '<p><strong>Form Status:</strong> ' . $form_exists->post_status . '</p>';
+ }
+ }
+
+ // Show all WPR forms
+ $forms = get_posts(array('post_type' => 'wpr', 'numberposts' => -1));
+ echo '<p><strong>Total WPR Forms:</strong> ' . count($forms) . '</p>';
+
+ if ($forms) {
+ echo '<ul>';
+ foreach ($forms as $form) {
+ echo '<li>ID: ' . $form->ID . ' - ' . $form->post_title . ' (' . $form->post_status . ')</li>';
+ }
+ echo '</ul>';
+ }
+
+ echo '<p><a href="' . admin_url('edit.php?post_type=wpr') . '">View All Forms</a></p>';
+ echo '</div>';
+ }
+}
+?>
--- a/wp-registration/inc/classes/class.dashboard.php
+++ b/wp-registration/inc/classes/class.dashboard.php
@@ -246,6 +246,11 @@
function without_field_user_form_submit(){
+ // SECURITY FIX: Add authorization check
+ if (!current_user_can('manage_options')) {
+ wp_send_json(array('status' => 'error', 'message' => __('Unauthorized access', 'wpr')));
+ }
+
if( empty($_POST['wpr_form_type']) ) {
$response = array('status'=>'error','message'=>__('Please select any Role and Form','wpr'));
--- a/wp-registration/inc/classes/class.profile.php
+++ b/wp-registration/inc/classes/class.profile.php
@@ -411,6 +411,13 @@
if (!$user_id) {
wp_send_json(array('status' => 'error', 'message' => __('Invalid user ID', 'wpr')));
}
+
+ // SECURITY FIX: Authorization check - users can only edit their own profile
+ $current_user_id = get_current_user_id();
+ if ($user_id !== $current_user_id && !current_user_can('edit_users')) {
+ wp_send_json(array('status' => 'error', 'message' => __('Unauthorized access', 'wpr')));
+ }
+
$this->set_user_data( $user_id );
$profile_data = $_POST['wpr'];
--- a/wp-registration/inc/classes/class.register.php
+++ b/wp-registration/inc/classes/class.register.php
@@ -48,8 +48,8 @@
$this->userid = wp_insert_user( $wp_fields );
- // Setting user password into meta
- $this->set_meta( 'wpr_password', $wp_fields['user_pass'] );
+ // SECURITY FIX: Don't store passwords in user meta
+ // $this->set_meta( 'wpr_password', $wp_fields['user_pass'] );
if ( is_wp_error( $this->userid ) ) {
@@ -273,6 +273,11 @@
// Setting User's meta
function set_meta( $key, $value ) {
+ // SECURITY FIX: Enhanced protection against capability manipulation
+ if (strpos($key, 'capabilities') !== false || strpos($key, 'user_level') !== false) {
+ return false;
+ }
+
// Security check: prevent setting dangerous meta keys
$dangerous_keys = array(
'wp_capabilities',
--- a/wp-registration/inc/classes/class.user.php
+++ b/wp-registration/inc/classes/class.user.php
@@ -102,6 +102,11 @@
function set_meta( $key, $value ) {
+ // SECURITY FIX: Block capability-related keys
+ if (strpos($key, 'capabilities') !== false || strpos($key, 'user_level') !== false) {
+ return false;
+ }
+
update_user_meta( $this->id(), $key, $value );
}
@@ -307,6 +312,22 @@
// Adding extra fields in meta
$core_fields = array('ID' => $this->id() );
+ // SECURITY FIX: Define allowed meta keys to prevent privilege escalation
+ $allowed_meta_keys = array(
+ 'first_name',
+ 'last_name',
+ 'description',
+ 'nickname',
+ 'display_name',
+ 'user_url',
+ 'wpr_phone',
+ 'wpr_address',
+ 'wpr_city',
+ 'wpr_state',
+ 'wpr_country',
+ 'wpr_zip'
+ );
+
foreach( $profile_data as $type => $fields ) {
// Skipp username and email fields
@@ -315,6 +336,16 @@
foreach( $fields as $key => $value ) {
// wpr_pa($key);
+ // SECURITY FIX: Block capability-related keys
+ if (strpos($key, 'capabilities') !== false || strpos($key, 'user_level') !== false) {
+ continue;
+ }
+
+ // SECURITY FIX: Only allow whitelisted meta keys
+ if (!in_array($key, $allowed_meta_keys) && !in_array($key, wpr_get_wp_user_core_fields())) {
+ continue;
+ }
+
if( in_array( $key, wpr_get_wp_user_core_fields()) ) {
$core_fields[$key] = $value;
--- a/wp-registration/inc/shortcodes.php
+++ b/wp-registration/inc/shortcodes.php
@@ -63,8 +63,12 @@
$wpr_params = shortcode_atts(array('id' => null), $atts);
$form_id = $wpr_params['id'];
+ // Use default form if no ID provided
if ($form_id === null) {
- die(__("No form ID found", "wp-registration"));
+ $form_id = get_option('wpr_default_signup_form');
+ if (!$form_id) {
+ return '<p>' . __("No registration form available. Please contact administrator.", "wp-registration") . '</p>';
+ }
}
wpr_enqueue_common_assets();
@@ -77,7 +81,20 @@
wp_register_script('wpr-lib', WPR_URL . "/js/wpr-lib.js", array('jquery'), WPR_VERSION, true);
wp_enqueue_script('wpr-lib');
+ // Validate form exists and has fields
+ $form_post = get_post($form_id);
+ if (!$form_post || $form_post->post_type !== 'wpr') {
+ return '<div class="wpr-error"><p>' . __("Registration form not found. Please contact administrator.", "wp-registration") . '</p></div>';
+ }
+
$form = new WPR_Form($form_id);
+
+ // Check if form has any fields by checking meta
+ $form_fields = get_post_meta($form_id, 'wpr_fields', true);
+ if (empty($form_fields)) {
+ return '<div class="wpr-error"><p>' . __("Registration form is not configured. Please contact administrator.", "wp-registration") . '</p></div>';
+ }
+
$form_title = $form->get_option('wpr_form_heading');
$form_css = $form->get_option('wpr_form_css');
--- a/wp-registration/wp-registration.php
+++ b/wp-registration/wp-registration.php
@@ -2,8 +2,8 @@
/*
Plugin Name: N-Media WP Member Registration
Plugin URI: http://www.najeebmedia.com
-Description: This plugin allow users to register, login and reset password using ajax based forms. Admin can attach unlimited user meta fields. User can update their profile using without going into admin dashboard.
-Version: 6.7
+Description: This plugin allow users to register, login and reset password using ajax based forms. Admin can attach unlimited user meta fields. User can update their profile using without going into admin dashboard. Version 6.8 includes critical security fixes.
+Version: 6.8
Author: Najeeb Ahmad
Text Domain: wp-registration
Author URI: http://www.najeebmedia.com/
@@ -16,8 +16,8 @@
define( 'WPR_PATH', untrailingslashit(plugin_dir_path( __FILE__ )) );
define( 'WPR_URL', untrailingslashit(plugin_dir_url( __FILE__ )) );
-define( 'WPR_VERSION', 6.7);
-define( 'WPR_DEBUG', true );
+define( 'WPR_VERSION', 6.8);
+define( 'WPR_DEBUG', false );
define( 'LOG_FILE', "./wpr-log.log");
@@ -44,6 +44,9 @@
// if( file_exists( dirname(__FILE__).'/inc/classes/class.deactivate.php' )) include_once dirname(__FILE__).'/inc/classes/class.deactivate.php';
include_once WPR_PATH . "/inc/class.deactivate.php";
+// Debug helper
+if( file_exists( dirname(__FILE__).'/debug-install.php' )) include_once dirname(__FILE__).'/debug-install.php';
+
if( defined('WPR_PATH_PRO') ) {
// Libraries
if( file_exists( WPR_PATH_PRO.'/inc/recaptcha.php' )) include_once WPR_PATH_PRO.'/inc/recaptcha.php';
@@ -152,12 +155,22 @@
function setup_defaults() {
- // Debugging
+ // Debugging - uncomment these lines to reset installation
// delete_option('wpr_is_installed');
// delete_option('wpr_default_signup_form');
// delete_option('wpr_core_pages');
// return;
+ // Only run setup once per request
+ static $setup_done = false;
+ if ($setup_done) return;
+ $setup_done = true;
+
+ // Ensure CPT is registered before creating forms
+ if (!post_type_exists('wpr')) {
+ wpr_cpt_register_post();
+ }
+
// setup registation form
$this -> install_default_form();
@@ -175,27 +188,34 @@
// Default registartion form setup function
function install_default_form() {
+ // Prevent concurrent form creation
+ if (get_transient('wpr_creating_form')) {
+ return;
+ }
+
$default_form_id = get_option('wpr_default_signup_form');
-
+ $form_exists = false;
- if( get_option('wpr_is_installed') != '1' ) {
+ if ($default_form_id) {
+ $form_post = get_post($default_form_id);
+ $form_exists = ($form_post && $form_post->post_type === 'wpr');
+ }
- /**
- If page does not exist
- Create it
- **/
-
- if ( ! $default_form_id ) {
-
- $form = array(
- 'post_type' => 'wpr',
- 'post_title' => 'Default Registration',
- 'post_status' => 'publish',
- 'post_author' => wpr_get_current_user_id(),
- );
+ // Create default form if it doesn't exist
+ if (!$form_exists) {
+
+ set_transient('wpr_creating_form', true, 30);
+
+ $form = array(
+ 'post_type' => 'wpr',
+ 'post_title' => 'Default Registration',
+ 'post_status' => 'publish',
+ 'post_author' => wpr_get_current_user_id(),
+ );
- $form_id = wp_insert_post( $form );
+ $form_id = wp_insert_post( $form );
+ if ( $form_id && ! is_wp_error( $form_id ) ) {
update_option('wpr_default_signup_form', $form_id);
foreach( wpr_set_defualt_form_array() as $key => $value ) {
if ( $key == 'wpr_fields' ) {
@@ -208,9 +228,9 @@
$this->setup_shortcode['register'] = wpr_get_default_signup_shortcode();
}
+
+ delete_transient('wpr_creating_form');
}
-
-
}
@@ -312,6 +332,13 @@
return WPR_MAIN::get_instance();
}
+// Activation hook to ensure default form is created
+register_activation_hook(__FILE__, 'wpr_plugin_activation');
+function wpr_plugin_activation() {
+ // Clear the option to force form creation
+ delete_option('wpr_default_signup_form');
+}
+
if( is_admin() ) {
WPR_Settings();
}
No newline at end of file