Tagged: ,

Viewing 8 reply threads
  • Author
    Posts
    • #1967
      chrissoutham
      Member

      I’ve noticed this a couple of times and wondered if it can be replicated by anyone.
      If you are using the media uploader, the first time (and every time after that if you don’t make a change) the file output is a string, for instance:
      'company_logo' => string '1701' (length=4)

      But if you remove the image and attach another (or the same one) then it changes to an array:

      'company_logo' => 
          array (size=1)
            0 => string '1701' (length=4)

      Means you have to write a case for an array or not, as well the additional steps to extract the image details.

      Example of the field setup:

      piklist('field', [
      	'type' => 'file',
      	'field' => 'company_logo',
      	'label' => 'Logo',
      	'options' => [
      		'title' => 'Add Logo',
      		'button' => 'Add Logo',
      		'modal_title' => 'Add Logo'
      	]
      ]);

      I’m running the latest version of the plugin v0.9.3.6.

    • #1968
      chrissoutham
      Member

      Actually I believe the expected behaviour is it saves as a single post ID for that image – in which case the oddity is if you swap it for another then it turns into an array, and then if you save again (with no changes) it’ll return to being a string.

    • #1969
      Steve
      Keymaster

      @chrissoutham– Where are you placing the uploader… Posts, Settings, Users, Widgets, Terms?

    • #1970
      chrissoutham
      Member

      Sorry Steve, my bad. It’s under piklist > parts > settings.
      If you add more than one image then I’m guessing it becomes an array, but sometimes when it’s a single image it’s either an array or a string. Not impossible to check for, just a little oddity.

    • #1971
      Steve
      Keymaster

      @chrissoutham– Thanks Chris. We were able to reproduce. Will work on a fix.

    • #1973
      chrissoutham
      Member

      Thanks Steve, much appreciated. Keep up the amazing work… seriously! 🙂

    • #1975
      Steve
      Keymaster

      @chrissoutham– Thank you for using Piklist and spreading the word.

    • #1976
      chrissoutham
      Member

      No problem, it’s a really pleasure – literally!
      I’ve started working on some open source WordPress starter developer themes with it integrated.
      Very much in the alpha phase at the moment but here for example: https://github.com/DeveloperThemes/

    • #1977
      Steve
      Keymaster

      Let us know when they are ready for prime time. We’d love to try them out.

Viewing 8 reply threads
  • The topic ‘Media uploader saves as a string first time’ is closed to new replies.