Support » Fixing WordPress » Gebruiker id
Gebruiker id
-
Ik heb de gebruiker-id nodig van de ingelogde gebruiker, heb alles geprobeerd: get_current_user_id()
deze verwijst aan een ander functie, die ook weer verwijs naar een ander functie tot 4 php includes diep: aan het eind krijg ik nog steeds gebruiker-id 0 terwijl ik zelf ben ingelogd.
Is er een globale variabele voor gebruiker-id en wie weet hoe ik anders hieraan kom
-
Please show your code.
$Gebruiker_ID = get_current_user_id();
OK, not funny. Please show your code in context.
was niet als grappig bedoelt
<?php include 'user.php'; include 'pluggable.php'; include 'plugin.php'; include 'class-wp-user.php'; $Gebruiker_ID = 0; $Gebruiker_ID = get_current_user_id(); $Doel_map = '/home/tessagaakeer/domains/swolliestestomgeving.nl/public_html/wp-content/gallery/Maandfotos/'; echo '| ' . $Gebruiker_ID . ' |'; // Gebruiker_ID = 142; if(isset($_POST["submit"])) { $DoelBestand = $_FILES['fileToUpload']['name']; $tmpPad = $_FILES['fileToUpload']['tmp_name']; $fileNameCmps = explode(".", $DoelBestand); $BestandSoort = strtolower(end($fileNameCmps)); $OudBestand = $Doel_map . 'tmpfoto-'. $Gebruiker_ID . '.' . $BestandSoort; $DoelBestand = $DoelBestand . $BestandSoort; echo '|' . $Gebruiker_ID . '|'; if(move_uploaded_file($tmpPad, $OudBestand)) $OudBestand = $Doel_map . 'Maandfoto-'. $Gebruiker_ID . '.jpg'; if (file_exists($OudBestand)) unlink ($OudBestand); $OudBestand = $Doel_map . 'Maandfoto-'. $Gebruikers_ID . '.jpeg'; if (file_exists($OudBestand)) unlink ($OudBestand); $OudBestand = $Doel_map . 'Maandfoto-'. $Gebruikers_ID . '.png'; if (file_exists($OudBestand)) unlink ($OudBestand); $OudBestand = $Doel_map . 'Maandfoto-'. $Gebruiker_ID . '.' . $BestandSoort; $DoelBestand = $Doel_map . 'tmpfoto-'. $Gebruiker_ID . '.' . $BestandSoort; rename ($DoelBestand,$OudBestand); //header( "Refresh:1; //url=https://www.swolliestestomgeving.nl/laad%20jouw%20foto%20van%20de%20maand", true, 303); }
.
Ik ben met pensioen en webmaster geworden van een fotoclub waarbij ik het een en ander wil aanpassen en automatiseren.
eerste op een testsiteThe code looks good; how is it called? Is this part of a page template? Plugin?
<form action="/wp-includes/uploadMaandfoto.php" method="post" enctype="multipart/form-data" target="_blank"> <input type="file" name="fileToUpload" id="fileToUpload" acceptpattern="*.jpg, *.png, *.jpeg" accept="image/*"> <input type="submit" value="Laad je foto" name="submit"> </form>;
de vorige code is van uploadmaandfoto.php
-
This reply was modified 1 year, 7 months ago by
Steven Stern (sterndata).
sorry, van een pagina
There are no errors other than the function returning zero?
Have you enabled debugging?
debugging = on
no errors anymore
still get 0It would appear that the problem is because it’s being called directly before WP has instantiated the user object. The form action is also going to a file in wp-includes/uploadMaandfoto, which isn’t a core file, so you’ll want to uplaod to some kind of identifiable string, and then in your plugin hook into init, check for the upload path and handle it there.
ja, ongeveer
De gebruiker kan 1 foto uploaden, als hij een ander upload, moet de 1e overschreven worden.
Na de upload moet de foto zichtbaar worden op de upload pagina samen met een gallery die alle foto’s in die map laat zien
Voor de volgende maand wordt de map leeg gemaakt en start het proces overnieuwWaar kan ik een globale variabele aanmaken voor het ID van de ingelogde gebruiker, zodat deze overal kan worden aangeroepen
The issue is not the lack of a global variable; the issue is that your form code seems to be called before the current user is set. This is a “how you design a plugin” issue. I’m going to back out of this and ask some folks wiht more dev experience to take a look.
ok
bedankt -
This reply was modified 1 year, 7 months ago by
- The topic ‘Gebruiker id’ is closed to new replies.