Plugin Directory

Changeset 2591047


Ignore:
Timestamp:
08/30/2021 07:44:40 PM (4 years ago)
Author:
rinatkhaziev
Message:

Merge 7f2c9f1cbfdbeef0dba2f32d6c8952484bd861ca

Location:
frontend-uploader/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • frontend-uploader/trunk

    • Property svn:ignore set to
      tests
  • frontend-uploader/trunk/frontend-uploader.php

    r2590623 r2591047  
    55Author: Rinat Khaziev, Daniel Bachhuber
    66Version: 1.3.2
    7 Author URI: http://digitallyconscious.com
     7Author URI: https://rinat.dev/
    88Text Domain: frontend-uploader
     9Requires at least: 4.6
     10Requires PHP: 7.2
    911
    1012GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
  • frontend-uploader/trunk/lib/php/akismet.php

    r1971315 r2591047  
    2222    // Permalink of the post with upload form, fallback to wp_get_referer()
    2323    // Fallback is used to
    24     $content['permalink'] = isset( $_POST['form_post_id'] ) ? get_permalink( sanitize_text_area( $_POST['form_post_id'] ) ) : wp_get_referer();
     24    $content['permalink'] = isset( $_POST['form_post_id'] ) ? get_permalink( sanitize_textarea_field( $_POST['form_post_id'] ) ) : wp_get_referer();
    2525
    2626    // Set required Akismet values
  • frontend-uploader/trunk/readme.md

    r2590623 r2591047  
    1212
    13131. `git clone https://github.com/rinatkhaziev/wp-frontend-uploader.git` in your WP plugins directory
    14 1. `git submodule update --init --recursive` in the plugin dir to get dependencies
    15141. Activate the plugin
    16151. Set the settings
     
    2019
    21201. Pull as usual
    22 2. Do `git submodule -q foreach git pull -q origin master` to update submodules
    23 3. ...
    24 4. Profit
     212. ...
     223. Profit
    2523
    2624## Developers
  • frontend-uploader/trunk/readme.txt

    r2590623 r2591047  
    44Tags: frontend, image, images, media, uploader, upload, video, audio, photo, photos, picture, pictures, file, user generated content, ugc, frontend upload
    55Requires at least: 4.6
    6 Tested up to: 5.0
     6Requires PHP: 7.2
     7Tested up to: 5.8
    78Stable tag: 1.3.2
    89License: GPLv2 or later
     
    1819**Security**
    1920
    20 Allowing uploads from unauthenticated users is inherently risky. The plugin relies on the core allow list for files. However, we explicitly remove HTML, JS and PHP files even if they're in the allow list. To modify the list of allowed file types please refer to *fu_allowed_mime_types* configuration filter section for additional details.
     21Allowing uploads from unauthenticated users is inherently risky. The plugin relies on the core allow list for files. However, we explicitly remove HTML, JS and PHP files even if they're in the allow list. To modify the list of allowed file types and tweak it to your own desire either use the plugin's settings or refer to *fu_allowed_mime_types* configuration filter section for additional details.
     22
     23For additional protection we recommend enabling file name obfuscation in plugin settings.
    2124
    2225= Exploring Customizations =
     
    2427* You can modify the submission form as needed, and have users submit posts. Please visit the FAQ page for more information.
    2528* This plugin can be applied to Posts, Pages, and Custom Post Types. You can enable this via Settings > Frontend Uploader Settings.
    26 * Form can be used in 3 modes: upload files, submit posts/custom post types, and mixed - submit a post and attach files to it.
    27 * Form supports following fields: text, textarea, select, radio buttons, and checkboxes
     29* Form can be used in three modes:
     30    - Submit files
     31    - Submit posts/pages/custom post types
     32    - Submit a post and attach files to it
     33
     34* The form supports following fields: text, textarea, select, radio buttons, and checkboxes
    2835
    2936**Customizing Your Form with Shortcode Parameters**
     
    3239
    3340At it's most basic form, the shortcode would look like this
    34 `[fu-upload-form]`
     41**[fu-upload-form]**
    3542
    3643This will render a default form for media upload that has title, description and upload fields. (See screenshot 2)
     
    3845The same shortcode with some customizations would look like this:
    3946
    40 `[fu-upload-form class="html-wrapper-class"
    41 form_layout="media" title="Upload your media"]
    42 [input type="text" name="post_title" id="title"
    43 class="required" description="Title"]
    44 [textarea name="post_content" class="textarea"
    45 id="my-textarea" description="Description (optional)"]
    46 [input type="file" name="photo" id="my-photo-submission"
    47 class="required" description="Your Photo" multiple="multiple"]
    48 [input type="submit" class="btn" value="Submit"]
     47`[fu-upload-form class="html-wrapper-class" form_layout="media" title="Upload your media"]
     48
     49    [input type="text" name="post_title" id="title"
     50     class="required" description="Title"]
     51
     52    [textarea name="post_content" class="textarea"
     53     id="my-textarea" description="Description (optional)"]
     54
     55    [input type="file" name="photo" id="my-photo-submission"
     56     class="required" description="Your Photo" multiple="multiple"]
     57
     58    [input type="submit" class="btn" value="Submit"]
    4959[/fu-upload-form]`
    5060
    5161As you can see, form elements are represented by shortcodes: [input], [textarea], [radio], [checkboxes], [file]. Each of them has a set of attributes, e.g. `id, class, name, value, values, type, description, minlength, maxlength. Please refer to "Form Elements" section of this readme for more details on elements and their attributes.
    5262
    53 = Main shortcode: [fu-upload-form] =
     63## Main shortcode: [fu-upload-form] ##
    5464
    5565The main shortcode, it has many important parameters that modify form behavior.
    5666
    57 In the following example we are creating a form with title "Upload your story and image". The form will allow to submit a custom post type *story* with an image which is going to be automatically inserted at the end of the story. The story will have a category with ID 1. On successful submission user will be redirected to http://example.com/success-page/
    58 
    59 `[fu-upload-form form_layout="post_media" title="Upload your story and image"
    60 class="my-class validate" post_type="story" append_to_post="true"
    61 success_page="http://example.com/success-page/" category="1" ][/fu-upload-form]`
    62 
    63 **The list of all parameters for [fu-upload-form]**
    64 
    65 *form_layout*
     67In the following example we are creating a form with title "Upload your story and image". The form will allow to submit a custom post type *story* with a file which is going to be automatically inserted at the end of the story. The story will have a category with ID 1. On successful submission user will be redirected to http://example.com/success-page/
     68
     69`[fu-upload-form
     70    form_layout="post_media"
     71    title="Upload your story and image"
     72    class="my-class validate"
     73    post_type="story"
     74    append_to_post="true"
     75    success_page="http://example.com/success-page/"
     76    category="1"
     77][/fu-upload-form]`
     78
     79### The list of all parameters for [fu-upload-form] ###
     80
     81**form_layout**
    6682
    6783This determines whether the form is saved as a post/custom post type (‘post’), as a media file (`media`), or as a post with images (`post_media`).  Default value is `media`.
    68 Example:
     84
     85Example:
     86
    6987`[fu-upload-form form_layout=”post”]`
    7088
    71 *title*
     89**title**
    7290
    7391Add this *[fu-upload-form]* shortcode, and this will be the Headline that will be displayed before the form.
    74 Example:
    75 `fu-upload-form class="your-class" title="Upload your media"]`
    76 
    77 *class*
     92
     93Example:
     94
     95`[fu-upload-form class="your-class" title="Upload your media"]`
     96
     97**class**
    7898
    7999HTML class of the form, defaults to 'validate'. If you want your form being validated - do not remove validate class. If you would like to item to be required before a user can submit, you can set it to ‘required.’
    80 Example:
     100
     101Example:
     102
    81103`[input type="text" name="post_title" id="title" class="required"]`
    82104
    83 *post_type*
    84 
    85 Any post whitelisted in settings post type. Defaults to 'post'.
    86 Example:
     105**post_type**
     106
     107Set the post type of the upload to one in the plugin settings Allow list. Defaults to 'post'.
     108
     109Example:
     110
    87111`[fu-upload-form post_type="my-custom-post-type-slug"]`
    88112
    89 *append_to_post*
    90 
    91 Automatically insert images into uploaded post *(true or false)*
    92 
    93 *success_page*
     113**append_to_post**
     114
     115Automatically insert images into the uploaded post content *(true or false)*
     116
     117Example:
     118
     119`[fu-upload-form append_to_post="true"]`
     120
     121
     122**success_page**
    94123
    95124URL to redirect on successful submission, defaults to the URL where the form is being displayed. For security reasons this should be an URL on your site (no external links). You can use `[fu-upload-response]` shortcode to display success/error messages on the redirect page.
    96125
    97 *category*
     126Example:
     127
     128`[fu-upload-form success_page="https://example.com/thank-you-for-your-submission/"]`
     129
     130**category**
    98131
    99132ID of category the post should be attached (only in post or post+media mode).
    100133
    101 *post_id*
     134Example:
     135
     136`[fu-upload-form category="1"]`
     137
     138**post_id**
    102139
    103140ID of the post the image should be attached to. Defaults to the post ID of the post the shortcode is on.
    104141
    105 *suppress_default_fields*
     142Example:
     143
     144`[fu-upload-form post_id="103037"]`
     145
     146**suppress_default_fields**
    106147
    107148Override global setting for supressing default form fields *(true or false)*.
    108 Example:
     149
     150Example:
     151
    109152`[fu-upload-form suppress_default_fields="true"] ... inner shortcodes omitted... [/fu-upload-form]`
    110153
    111 
    112 = Form Elements =
    113 
    114 Following are form elements you can use, please refer to *Field Attributes* section for more details on what attributes can be used.
     154### Form Elements ###
     155
     156The following are form elements you can use, please refer to *Field Attributes* section for more details on what attributes can be used.
    115157
    116158Text box for one line of text:
     159
    117160`[input type="text" name="post_title" class="my-class" ]`
    118161
    119162Text box for multiple lines of text:
     163
    120164`[textarea name="post_content" class="my-text-area"]`
    121165
    122166File upload field:
     167
    123168`[input type="file" name="my-file"]`
    124169
    125170Set of checkboxes:
     171
    126172`[checkboxes name="fruits" values="value:Description,124:Banana,cherry:Cherry"]`
    127173
    128174Set of radio buttons:
     175
    129176`[radio name="fruit" class="checkboxes" description="Pick a fruit" values="value:Description,124:Banana,cherry:Cherry"]`
    130177
    131178Select:
     179
    132180`[select name="select-fruit" class="select" description="Pick a fruit" values="apple:Apple,banana:Banana,cherry:Cherry"]`
    133181
    134182Submit button:
     183
    135184`[input type="submit" class="btn" value="Submit"]`
    136185
    137186Recaptcha:
     187
    138188`[recaptcha]`
    139189
    140190**Field Attributes**
    141191
    142 `id` - id of element
    143 
    144 `name` - name of element
    145 
    146 `class` - extra classes you want to add
    147 
    148 `type` - text or file or submit
    149 
    150 `required` - This attribute specifies that the user must fill in a value before submitting a form.
    151 
    152 `minlength` - minimum amount of characters for field value
    153 
    154 `maxlength` - maximum amount of characters for field value
    155 
    156 `min` - The minimum (numeric or date-time) value for this item, which must not be greater than its maximum (max attribute) value.
    157 
    158 `max` - The maximum (numeric or date-time) value for this item, which must not be less than its minimum (min attribute) value.
    159 
    160 `multiple` - allow multiple file uploads (only for file inputs)
    161 
    162 `placeholder` - A hint to the user of what can be entered in the control.
    163 
    164 `readonly` - This attribute indicates that the user cannot modify the value of the control.
    165 
    166 `disabled` - This Boolean attribute indicates that the form control is not available for interaction
    167 
    168 `value` - input value
    169 
    170 `description` - input label
    171 
    172 `help` - input help text displayed underneath
    173 
    174 `values` - multiple option inputs (checkboxes,select,radio) values in format *value:description, another_value:anotherdescription*
    175 
    176 `wysiwyg_enabled` - enable TinyMCE for textareas
     192Please refer to the excellent [MDN reference](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types "") for input attributes. Generally speaking, any HTML5 attribute should be supported.
     193
     194* **id** - id of element
     195
     196* **name** - name of element
     197
     198* **class** - extra classes you want to add
     199
     200* **type** - text or file or submit
     201
     202* **required** - This attribute specifies that the user must fill in a value before submitting a form.
     203
     204* **minlength** - minimum amount of characters for field value
     205
     206* **maxlength** - maximum amount of characters for field value
     207
     208* **min** - The minimum (numeric or date-time) value for this item, which must not be greater than its maximum (max attribute) value.
     209
     210* **max** - The maximum (numeric or date-time) value for this item, which must not be less than its minimum (min attribute) value.
     211
     212* **multiple** - allow multiple file uploads (only for file inputs)
     213
     214* **placeholder** - A hint to the user of what can be entered in the control.
     215
     216* **readonly** - This attribute indicates that the user cannot modify the value of the control.
     217
     218* **disabled** - This Boolean attribute indicates that the form control is not available for interaction
     219
     220* **value** - input value
     221
     222* **description** - input label
     223
     224* **help** - input help text displayed underneath
     225
     226* **values** - Comma-separated values for the multiple option inputs (checkboxes, select, radio)  in the format of **value:description, another_value:anotherdescription**
     227
     228* **wysiwyg_enabled** - enable TinyMCE for textareas.
    177229
    178230
     
    180232
    181233Please make sure to read this readme including FAQ section before posting in support forum.
    182 
    183234
    184235**Development**
     
    234285
    235286= Are other filetypes supported? =
    236 In addition to the WordPress whitelisted file types, Frontend Uploader also supports uploading of Microsoft Office and Adobe files, as well as various video and audio files. You can enable these file types via Settings > Frontend Uploader Settings.
     287
     288By default every file type that WordPress allows to upload except HTML and JS are enabled.
     289However, you can tweak what's allowed in the Options -> Frontend Uploader Settings.
     290If you want to handle some other file type please refer to **fu_allowed_mime_types** filter section.
    237291
    238292= Where does the user submitted content go? =
     
    245299
    246300
    247 = I want to be allow users to upload mp3, psd, or any other file restricted by default. =
    248 You are able to do that within Frontend Uploader Settings admin page. The settings there cover the most popular extensions/MIME-types.
    249 The trick is that the same file might have several different mime-types based on setup of server/client.
    250 If you're experiencing any issues, you can set WP_DEBUG to true in your wp-config.php or put
    251 `add_filter( 'fu_is_debug', '__return_true' );` in your theme's functions.php to see what MIME-types you are having troubles with.
    252 
    253 [FileExt](http://filext.com/) is a good place to find MIME-types for specific file extension.
    254 
    255 Let's say we want to be able to upload 3gp media files.
    256 
    257 First we look up all MIME-types for 3gp: http://filext.com/file-extension/3gp
    258 
    259 Now that we have all possible MIME-types for .3gp, we can allow the files to be uploaded.
    260 
    261 Following code whitelists 3gp files, if it makes sense to you, you can modify it for other extensions/mime-types.
    262 If it confuses you, please don't hesitate to post on support forum.
     301= I want to allow users to upload a file type that's not listed in the plugin settings. =
     302
     303By default we rely on [wp_get_mime_types](https://developer.wordpress.org/reference/functions/wp_get_mime_types/) function to populate the values for the allow list.
     304
     305It covers the absolute majority of widely used file formats, but let's say you want to allow uploading a source file of a program written in [Pascal](https://en.wikipedia.org/wiki/Pascal_(programming_language).
     306It can be using either **.pas`** or **.p**
     307It can have MIME type of `text/pascal` or `text/x-pascal`
     308
     309[FileExt](http://filext.com/) is a good place to find out more about the file types, but, unfortunately it stopped showing MIME-types somewhere between the first and current version of this readme.
     310
     311So we'll have to resort to a search engine and query for "PAS MIME-type". As said earlier, those files can have two MIME-types.
     312
     313Now comes the tricky part, WordPress expects the mime types defined in a particular format of a regex pattern for extensions as an array key and MIME-type as a value.
     314
     315Needless to say, associative array keys are unique, so we need to apply a little trick:
     316
     317`$mime_types['p|pas'] = 'text/pascal';
     318$mime_types['pas|p'] = 'text/x-pascal';`
     319
     320This way we can side-step the unique key requirement while handling both of the MIME-types.
     321
    263322Put this in your theme's functions.php
     323
    264324`add_filter( 'fu_allowed_mime_types', 'my_fu_allowed_mime_types' );
    265325function my_fu_allowed_mime_types( $mime_types ) {
    266     // Array of 3gp mime types
    267     // From http://filext.com (there might be more)
    268     $mimes = array( 'audio/3gpp', 'video/3gpp' );
    269     // Iterate through all mime types and add this specific mime to allow it
    270     foreach( $mimes as $mime ) {
    271         // Preserve the mime_type
    272         $orig_mime = $mime;
    273         // Leave only alphanumeric characters (needed for unique array key)
    274         preg_replace("/[^0-9a-zA-Z ]/", "", $mime );
    275         // Workaround for unique array keys
    276         // If you-re going to modify it for your files
    277         // Don't forget to change extension in array key
    278         // E.g. $mime_types['pdf|pdf_' . $mime ] = $orig_mime
    279         $mime_types['3gp|3gp_' . $mime ] = $orig_mime;
    280     }
     326    $mime_types['p|pas'] = 'text/pascal';
     327    $mime_types['pas|p'] = 'text/x-pascal';
     328
    281329    return $mime_types;
    282330}`
    283331
     332Unfortunately, that's not all. Sometimes, depending on a server configuration you might get unexpected results for certain file extensions.
     333If you’re experiencing any issues, you can set WP_DEBUG to true in your wp-config.php or put
     334
     335`add_filter( ‘fu_is_debug’, ‘__return_true’ );`
     336
     337in your theme’s functions.php to see what MIME-types you are having troubles with.
     338
    284339= What about spam protection? =
    285340The plugin supports Akismet (must be installed and configured properly) and Recaptcha. Just enable it in plugin settings.
     
    290345
    291346By default Frontend Uploader could be managed with 'edit_posts' capability, if you want to change permissions, this is the right filter
     347
    292348`add_filter( 'fu_manage_permissions', create_function( '$cap', 'return "edit_others_posts"; ) );`
    293349
     
    345401== Changelog ==
    346402
     403= 1.3.3 (Aug 28, 2021) =
     404* Re-worked the way file type allow list works
     405* Readme formatting updates to hopefully make it clearer
     406
    347407= 1.3.2 (Nov 2, 2018) =
    348408* Bugfix: allow multiple forms to be properly validated if they're rendered on the same page.
     
    538598
    539599* Initial release and poorly written readme
     600
     601 == Upgrade Notice ==
     602
     603 As of 1.3.3 the minimum requirement for PHP is bumped to 7.0, it reached the end of life on 10 Jan 2019, so if, somehow, you're still running it you should upgrade.
Note: See TracChangeset for help on using the changeset viewer.