۷ حسین نوروزی فر
کیف پولم تو این قسمت خطا میده
جامعه وردپرس (برنامه نویسی) ایجاد شده در ۱۲ اردیبهشت ۱۴۰۱
Warning: number_format() expects parameter 1 to be float, array given in C:\\xampp\\htdocs\\hosein.exp\\wp-content\\plugins\\wordpress.apis\\tpl\\admin\\menus\\users\\users.php on line 27
تومان

سلام. دوست عزیز

با یک خط کد که نمیشه مشکل کار رو فهمید. کدهاتون رو کامل قرار بدید

بهترین پاسخ
احمد اسماعیلی ۱۲ اردیبهشت ۱۴۰۱، ۱۴:۰۹

add_action('admin_menu','wp_apis_register_menus');
function wp_apis_register_menus()
{
    add_menu_page(
      'پلاگین سفارشی',
      'پلاگین سفارشی',
          'manage_options',
          'wp_apis_admin',
          'wp_apis_main_menu_handler'
          
    );
    add_submenu_page(
      'wp_apis_admin',
      'کاربران',
      'کاربران',
      'manage_options',
      'wp_apis_users',
      'wp_apis_users_page'
    );
    add_submenu_page(
  'wp_apis_admin',
  'تنظیمات',
  'تنظیمات',
  'manage_options',
  'wp_apis_general',
  'wp_apis_general_page'
);
//add_submenu_page(
  //'wp_apis_admin',
  //'خصوصی',
  //'خصوصی',
  //'manage_options',
 // 'wp_apis_general',
 // 'wp_apis_general_page'
//);
}
function wp_apis_main_menu_handler()
{
global $wpdb;
$action =$_GET['action'];
if($action == "delete")
{
  $item = intval($_GET['item']);
  if($item > 0)
  {
    $wpdb->delete($wpdb->prefix.'hosein',['ID'=> $item]);
  }
}
if($action == "add")
{
  if(isset($_POST['saveData'])) {
$wpdb->insert($wpdb->prefix .'hosein', [
'firstName' => $_POST['firstName'],
'lastName' => $_POST ['lastName'],
'mobile' => $_POST['mobile'],
'age' => $_POST['age']
]);
 }
  include WP_APIS_TPL.'admin/menus/add.php';
}
else
{
  $hoseins= $wpdb->get_results("SELECT * FROM {$wpdb->prefix}hosein");  
  include WP_APIS_TPL.'admin/menus/main.php';
}
}
     function wp_apis_general_page()
  {   
    if(isset($_POST['saveSettings']))
    {
      if(isset($_POST['is_plugin_active']))
      {
//$is_plugin_active =isset($_POST['is_plugin_active']) ? 1 : 0;
//add_option('wp_apis_is_active',$is_plugin_active);
//update_option('wp_apis_is_active',$is_plugin_active);
update_option('wp_apis_is_active',$is_plugin_active);
    }
    else
    {
      delete_option('wp_apis_is_active');
    }
    }
    $current_plugin_status= get_option('wp_apis_is_active',$is_plugin_active);
  include WP_APIS_TPL.'admin/menus/general.php';   
}
function wp_apis_users_page(){
  $newPassword = wp_generate_password(10);
  $userEmail = "hoseinitblss@gmail.com";
 $userEmailData = explode('@',$userEmail);
  //wp_create_user($userEmailData[0],$newPassword,"$userEmail");
  $new_user_result = wp_insert_user(
    [
  wp_updata_users()
]
);
     global $wpdb;
     if(isset($_GET['action']) && $_GET['action'] == 'edit')
     {
        $userID = intval($_GET['id']);
       if(isset($_POST['saveUserInfo'])){
       $mobile = $_POST['mobile'];
       $wallet = $_POST['wallet'];
       if(!empty($mobile))
       {
         update_user_meta($userID,'mobile',$mobile);
       }
       if(!empty($wallet))
       {
         update_user_meta($userID,'wallet',$wallet);
       }
      }
       $mobile = get_user_meta($userID,'mobile',true);
       $wallet = get_user_meta($userID,'wallet',true);
       include WP_APIS_TPL.'admin/menus/users/edit.php';
       return;
    } 
       if(isset($_GET['action']) && $_GET['action'] == 'removeMobileAndWallet')
       {$userID = intval($_GET['id']);
        delete_user_meta($userID,'mobile');
        delete_user_meta($userID,'wallet');
     }
       $users= $wpdb->get_results("SELECT ID,user_email,display_name FROM {$wpdb->users}");
        include WP_APIS_TPL.'admin/menus/users/users.php'; 
}

این قسمت menus

حسین نوروزی فر ۱۲ اردیبهشت ۱۴۰۱، ۱۴:۱۳
<div class="wrap">
    <h1><span class="dashicons dashicons-admin-users">span>کاربران ویژهh1>
    <table class="widefat">
        <thead>
        <tr>
            <th>شناسهth>
            <th>نام کاملth>
            <th>ایمیلth>
            <th>شماره همراهth>
            <th>کبف پولth>
            <th>عملیاتth>
tr>
thead>
<tbody>
 foreach($users as $user): ?>
    
    $userWallet = get_user_meta($user->ID,'wallet',true);
    $userWallet = empty($userWallet) ? 0 : $userWallet;
 ?>
       
        <tr>
        
        <td> echo $user->ID; ?>td>
        <td> echo $user->display_name; ?>td>
        <td> echo $user->user_email; ?>td>
        <td> echo get_user_meta($user->ID,'mobile' ,true); ?>td>
        <td> echo number_format(get_user_meta($userWallet)).' تومان '?>td>
        <td>
        <a href=" echo add_query_arg(['action' => 'edit','id' => $user->ID]); ?>">
        <span class="dashicons dashicons-edit">span>
a>
        <a title="حذف کردن شماره موبایل و کیف پول" href=" echo add_query_arg(['action' => 'removeMobileAndWallet','id' => $user->ID]); ?>">
        <span class="dashicons dashicons-trash">span>
            a>
          td>
       tr>
     endforeach ?>
    tbody>
    table>

اینم قسمت users.php

حسین نوروزی فر ۱۲ اردیبهشت ۱۴۰۱، ۱۴:۱۴

add_action('admin_menu','wp_apis_register_menus');
function wp_apis_register_menus()
{
    add_menu_page(
      'پلاگین سفارشی',
      'پلاگین سفارشی',
          'manage_options',
          'wp_apis_admin',
          'wp_apis_main_menu_handler'
          
    );
    add_submenu_page(
      'wp_apis_admin',
      'کاربران',
      'کاربران',
      'manage_options',
      'wp_apis_users',
      'wp_apis_users_page'
    );
    add_submenu_page(
  'wp_apis_admin',
  'تنظیمات',
  'تنظیمات',
  'manage_options',
  'wp_apis_general',
  'wp_apis_general_page'
);
//add_submenu_page(
  //'wp_apis_admin',
  //'خصوصی',
  //'خصوصی',
  //'manage_options',
 // 'wp_apis_general',
 // 'wp_apis_general_page'
//);
}
function wp_apis_main_menu_handler()
{
global $wpdb;
$action =$_GET['action'];
if($action == "delete")
{
  $item = intval($_GET['item']);
  if($item > 0)
  {
    $wpdb->delete($wpdb->prefix.'hosein',['ID'=> $item]);
  }
}
if($action == "add")
{
  if(isset($_POST['saveData'])) {
$wpdb->insert($wpdb->prefix .'hosein', [
'firstName' => $_POST['firstName'],
'lastName' => $_POST ['lastName'],
'mobile' => $_POST['mobile'],
'age' => $_POST['age']
]);
 }
  include WP_APIS_TPL.'admin/menus/add.php';
}
else
{
  $hoseins= $wpdb->get_results("SELECT * FROM {$wpdb->prefix}hosein");  
  include WP_APIS_TPL.'admin/menus/main.php';
}
}
     function wp_apis_general_page()
  {   
    if(isset($_POST['saveSettings']))
    {
      if(isset($_POST['is_plugin_active']))
      {
//$is_plugin_active =isset($_POST['is_plugin_active']) ? 1 : 0;
//add_option('wp_apis_is_active',$is_plugin_active);
//update_option('wp_apis_is_active',$is_plugin_active);
update_option('wp_apis_is_active',$is_plugin_active);
    }
    else
    {
      delete_option('wp_apis_is_active');
    }
    }
    $current_plugin_status= get_option('wp_apis_is_active',$is_plugin_active);
  include WP_APIS_TPL.'admin/menus/general.php';   
}
function wp_apis_users_page(){
  $newPassword = wp_generate_password(10);
  $userEmail = "hoseinitbls@gmail.com";
 $userEmailData = explode('@',$userEmail);
  //wp_create_user($userEmailData[0],$newPassword,"$userEmail");
  $new_user_result = wp_insert_user(
    [
 'user_pass' => $newPassword,
 'user_email' => $userEmail,
 'user_login' => $userEmailData[0],
 'display_name' => 'یک کاربر جدید'
    ]
);
     global $wpdb;
     if(isset($_GET['action']) && $_GET['action'] == 'edit')
     {
        $userID = intval($_GET['id']);
       if(isset($_POST['saveUserInfo'])){
       $mobile = $_POST['mobile'];
       $wallet = $_POST['wallet'];
       if(!empty($mobile))
       {
         update_user_meta($userID,'mobile',$mobile);
       }
       if(!empty($wallet))
       {
         update_user_meta($userID,'wallet',$wallet);
       }
      }
       $mobile = get_user_meta($userID,'mobile',true);
       $wallet = get_user_meta($userID,'wallet',true);
       include WP_APIS_TPL.'admin/menus/users/edit.php';
       return;
    } 
       if(isset($_GET['action']) && $_GET['action'] == 'removeMobileAndWallet')
       {$userID = intval($_GET['id']);
        delete_user_meta($userID,'mobile');
        delete_user_meta($userID,'wallet');
     }
       $users= $wpdb->get_results("SELECT ID,user_email,display_name FROM {$wpdb->users}");
        include WP_APIS_TPL.'admin/menus/users/users.php'; 
}

menus.php

حسین نوروزی فر ۱۲ اردیبهشت ۱۴۰۱، ۱۴:۲۶

2820-2022-05-02 (1).png

قسمت موبایل ویرایش میشه ولی کیف پول رو این خطا میده بعد ویرایش

حسین نوروزی فر ۱۲ اردیبهشت ۱۴۰۱، ۱۴:۳۱

اشتباه سینتکسی زیادی توی پروژه تون هست.

به تلگرام پیام بدید تا بیام روی سیستمتون.

احمد اسماعیلی ۱۲ اردیبهشت ۱۴۰۱، ۱۴:۵۷

مشکل شما خطای سینتکسی بود که رفع شد.

احمد اسماعیلی ۱۲ اردیبهشت ۱۴۰۱، ۱۵:۲۲