Skip to content
Snippets Groups Projects
Commit d2bd6efa authored by potreb's avatar potreb
Browse files

scope: added new field

parent ec574cc6
No related branches found
No related tags found
1 merge request!14scope: added new field
Pipeline #5718 passed
{ {
"name": "wpdesk/wp-forms", "name": "wpdesk/wp-forms",
"description": "WP Forms",
"authors": [ "authors": [
{ {
"name": "Marcin", "name": "Marcin",
...@@ -8,6 +9,10 @@ ...@@ -8,6 +9,10 @@
{ {
"name": "Krzysiek", "name": "Krzysiek",
"email": "krzysiek@wpdesk.pl" "email": "krzysiek@wpdesk.pl"
},
{
"name": "Piotr Potrebka",
"email": "piotr.potrebka@wpdesk.pl"
} }
], ],
"require": { "require": {
...@@ -31,6 +36,13 @@ ...@@ -31,6 +36,13 @@
}, },
"autoload-dev": { "autoload-dev": {
}, },
"extra": {
"text-domain": "wp-forms",
"translations-folder": "lang",
"po-files": {
"pl_PL": "pl_PL.po"
}
},
"scripts": { "scripts": {
"phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never", "phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never",
"phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage", "phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage",
......
File added
msgid ""
msgstr ""
"Project-Id-Version: WP Forms\n"
"POT-Creation-Date: 2021-05-24 10:07+0200\n"
"PO-Revision-Date: 2021-05-24 10:07+0200\n"
"Last-Translator: Piotr Po <potreb@gmail.com>\n"
"Language-Team: Piotr Potrebka <piotr.potrebka@gmail.com>\n"
"Language: pl_PL\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.3\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
"|| n%100>=20) ? 1 : 2);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
"_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-SearchPath-1: src\n"
"X-Poedit-SearchPathExcluded-0: *.js\n"
"X-Poedit-SearchPathExcluded-1: vendor\n"
"X-Poedit-SearchPathExcluded-2: vendor_prefixed\n"
#: templates/input-image.php:24
msgid "Set image"
msgstr "Wstaw obraz"
#: templates/input-image.php:29
msgid "Remove image"
msgstr "Usuń obraz"
#: templates/input-image.php:50
msgid "Select or Upload Media"
msgstr "Wybierz lub prześlij media"
#: templates/input-image.php:52
msgid "Use this media"
msgstr "Wybierz"
#: templates/product-select.php:13
msgid "Search for a product&hellip;"
msgstr "Szukaj produktu&hellip;"
<?php
namespace WPDesk\Forms\Field;
class ImageInputField extends \WPDesk\Forms\Field\BasicField {
public function __construct() {
parent::__construct();
$this->set_default_value( '' );
$this->set_attribute( 'type', 'text' );
}
/**
* @return string
*/
public function get_template_name() {
return 'input-image';
}
}
<?php
/**
* @var \WPDesk\Forms\Field $field
* @var string $name_prefix
* @var string $value
*/
?>
<?php
$media_container_id = 'media_' . sanitize_key( $field->get_id() );
?>
<div class="media-input-wrapper" id="<?php echo $media_container_id; ?>">
<input type="hidden" class="image-field-value" value="<?php echo \esc_html( $value ); ?>"
name="<?php echo \esc_attr( $name_prefix ) . '[' . \esc_attr( $field->get_name() ) . ']'; ?>"
id="<?php echo \esc_attr( $field->get_id() ); ?>"/>
<div class="custom-img-container">
<?php if ( $value ) : ?>
<img src="<?php echo $value ?>" alt="" width="100"/>
<?php endif; ?>
</div>
<p class="hide-if-no-js">
<a class="upload-custom-img <?php if ( $value ) {
echo 'hidden';
} ?>" href="<?php echo $value ?>">
<?php _e( 'Set image', 'wp-forms' ) ?>
</a>
<a class="delete-custom-img <?php if ( ! $value ) {
echo 'hidden';
} ?>" href="#">
<?php _e( 'Remove image', 'wp-forms' ) ?>
</a>
</p>
</div>
<script>
jQuery( function ( $ ) {
var frame,
metaBox = $( '#<?php echo $media_container_id; ?>' ),
addImgLink = metaBox.find( '.upload-custom-img' ),
delImgLink = metaBox.find( '.delete-custom-img' ),
imgContainer = metaBox.find( '.custom-img-container' ),
imgIdInput = metaBox.find( '.image-field-value' );
addImgLink.on( 'click', function ( event ) {
event.preventDefault();
if ( frame ) {
frame.open();
return;
}
frame = wp.media( {
title: <?php _e( 'Select or Upload Media', 'wp-forms' ); ?>,
button: {
text: <?php _e( 'Use this media', 'wp-forms' ); ?>
},
library: {
type: ['image']
},
multiple: false
} );
frame.on( 'select', function () {
var attachment = frame.state().get( 'selection' ).first().toJSON();
imgContainer.append( '<img src="' + attachment.url + '" alt="" width="100" />' );
imgIdInput.val( attachment.url );
addImgLink.addClass( 'hidden' );
delImgLink.removeClass( 'hidden' );
} );
frame.open();
} );
delImgLink.on( 'click', function () {
imgContainer.html( '' );
addImgLink.removeClass( 'hidden' );
delImgLink.addClass( 'hidden' );
imgIdInput.val( '' );
return false;
} );
} );
</script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment