Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image upload #3

Merged
merged 5 commits into from Jun 22, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -0,0 +1,23 @@
// The "Upload" button
$('.upload_image_button').click(function() {
var send_attachment_bkp = wp.media.editor.send.attachment;
var button = $(this);
wp.media.editor.send.attachment = function(props, attachment) {
$(button).parent().prev().attr('src', attachment.url);
$(button).prev().val(attachment.id);
wp.media.editor.send.attachment = send_attachment_bkp;
};
wp.media.editor.open(button);
return false;
});

// The "Remove" button (remove the value from input type='hidden')
$('.remove_image_button').click(function() {
var answer = confirm('Are you sure?');
if (answer === true) {
var src = $(this).parent().prev().attr('data-src');
$(this).parent().prev().attr('src', src);
$(this).prev().prev().val('');
}
return false;
});
@@ -14,8 +14,13 @@
include dirname( __FILE__ ) . '/includes/class-form-handler.php';
include dirname( __FILE__ ) . '/includes/amazin-product-box-functions.php';
// WordPress image upload library
wp_enqueue_media();
$jsurl = plugin_dir_url(__FILE__) . 'admin.js';
wp_enqueue_script('admin', $jsurl, array( 'jquery' ), 1.1, true);
$cssurl = plugin_dir_url(__FILE__) . 'styles.css';
wp_enqueue_style( 'amazin-stylesheet', $cssurl, array(), 1.23 );
wp_enqueue_style( 'amazin-stylesheet', $cssurl, array(), 1.30 );
register_post_type('amazin_product_box',
array(
@@ -59,9 +64,9 @@ function amazin_product_box_render_in_post($productBox) {
<div class="amazin-product-box" id="<?php echo 'amazin-product-box-id-'.$id; ?>">
<p class="amazin-product-box-recommend-text">We recommend</p>
<h3 class="amazin-product-box-product-name"><?php echo $productBoxTitle ?></h3>
<div class="row">
<div class="row amazin-product-box-image-row">
<div class="amazin-product-box-column amazin-product-box-left">
Picture placeholder
<img src="<?php echo wp_get_attachment_url( $content['productImage'] ) ?>"/>
</div>
<div class="amazin-product-box-column amazin-product-box-right">
<p class="amazin-product-box-tagline"><?php echo $content['productTagline'] ?></p>
@@ -72,4 +72,3 @@ function apb_delete_product_boxes ( $ids ) {
return $wpdb->query( $delQuery );
}
@@ -23,6 +23,9 @@ public function admin_menu() {
add_menu_page( __( 'AmazinProductBox', 'apb' ), __( 'Amazin\' Product Box', 'apb' ), 'manage_options', 'amazinProductBox', array( $this, 'plugin_page' ), 'dashicons-grid-view', null );
add_submenu_page( 'amazinProductBox', __( 'AmazinProductBox', 'apb' ), __( 'AmazinProductBox', 'apb' ), 'manage_options', 'amazinProductBox', array( $this, 'plugin_page' ) );
wp_enqueue_media();
}
/**
@@ -42,6 +42,7 @@ public function handle_form() {
$field_description = isset( $_POST['Description'] ) ? wp_kses_post( $_POST['Description'] ) : '';
$field_url = isset( $_POST['URL'] ) ? sanitize_text_field( $_POST['URL'] ) : '';
$field_buttonText = isset( $_POST['Button-Text'] ) ? sanitize_text_field( $_POST['Button-Text'] ) : '';
$field_productImage = isset( $_POST['Product-Image'] ) ? sanitize_text_field( $_POST['Product-Image'] ) : '';
// some basic validation
if ( ! $field_productName ) {
@@ -77,7 +78,8 @@ public function handle_form() {
'productTagline' => $field_tagline,
'productDescription' => $field_description,
'productUrl' => $field_url,
'productButtonText' => $field_buttonText
'productButtonText' => $field_buttonText,
'productImage' => $field_productImage //ID of media attachment
);
$product_box = array(
Binary file not shown.
@@ -5,37 +5,66 @@
$item = apb_get_product_box( $_GET['id'] );
$stripped = stripslashes($item->post_content);
$content = json_decode($stripped, true);
$phURL = esc_url( plugins_url('ph.png', __FILE__ ) ) ;
$image = esc_attr( wp_get_attachment_url( $content['productImage'] ) );
if (!$image) {
$image = $phURL;
}
?>

<form action="" method="post">

<table class="form-table">
<tbody>
<tr class="row-Product Name">

<tr class="row-productName">
<th scope="row">
<label for="Product-Name"><?php _e( 'Product-Name', 'apb' ); ?></label>
<label for="Product-Name"><?php _e( 'Product name', 'apb' ); ?></label>
</th>
<td>
<input type="text" name="Product-Name" id="Product-Name" class="regular-text" placeholder="<?php echo esc_attr( '', 'apb' ); ?>" value="<?php echo esc_attr( $item->post_title ); ?>" required="required" />
<span class="description"><?php _e('Name help', 'apb' ); ?></span>
<br/>
<span class="description"><?php _e('Product name, model, etc.', 'apb' ); ?></span>
</td>
</tr>
<tr class="row-Tagline">

<tr class="row-Product-Image">
<th scope="row">
<label for="Product-Name"><?php _e( 'Product image', 'apb' ); ?></label>
</th>
<td>
<div class="upload">
<img data-src="<?php echo $phURL ?>" src="<?php echo $image; ?>" width="120px" height="120px" />
<div>
<input type="hidden" name="Product-Image" id="Product-Image" value="" />
<button type="submit" class="upload_image_button button"><?php _e( 'Upload/Choose', 'apb' ); ?></button>
<button type="submit" class="remove_image_button button"><?php _e( 'Clear', 'apb' ); ?></button>
</div>
</div>
</td>
</tr>

<tr class="row-tagline">
<th scope="row">
<label for="Tagline"><?php _e( 'Tagline', 'apb' ); ?></label>
</th>
<td>
<input type="text" name="Tagline" id="Tagline" class="regular-text" placeholder="<?php echo esc_attr( '', 'apb' ); ?>" value="<?php echo esc_attr( $content['productTagline'] ); ?>" required="required" />
<span class="description"><?php _e('Tagline help', 'apb' ); ?></span>
<br/>
<span class="description"><?php _e('A tagline is short and memorable (3-6 words)', 'apb' ); ?></span>
</td>
</tr>
<tr class="row-Description">
<tr class="row-description">
<th scope="row">
<label for="Description"><?php _e( 'Description', 'apb' ); ?></label>
</th>
<td>
<textarea name="Description" id="Description"placeholder="<?php echo esc_attr( '', 'apb' ); ?>" rows="5" cols="30" required="required"><?php echo esc_textarea( $content['productDescription'] ); ?></textarea>
<p class="description"><?php _e('Description help', 'apb' ); ?></p>
<textarea name="Description" id="Description"placeholder="<?php echo esc_attr( '', 'apb' ); ?>" rows="6" cols="46" required="required"><?php echo esc_textarea( $content['productDescription'] ); ?></textarea>
<br/>
<span class="description"><?php _e('Write about 20-30 words (~200 characters) enticing your visitor to choose this product', 'apb' ); ?></span>
</td>
</tr>
<tr class="row-URL">
@@ -44,16 +73,18 @@
</th>
<td>
<input type="text" name="URL" id="URL" class="regular-text" placeholder="<?php echo esc_attr( '', 'apb' ); ?>" value="<?php echo esc_attr( $content['productUrl'] ); ?>" required="required" />
<span class="description"><?php _e('Enter your affiliate link', 'apb' ); ?></span>
<br/>
<span class="description"><?php _e('Product affiliate link, including https://', 'apb' ); ?></span>
</td>
</tr>
<tr class="row-buttonText">
<th scope="row">
<label for="Button-Text"><?php _e( 'Button-Text', 'apb' ); ?></label>
<label for="Button-Text"><?php _e( 'Button text', 'apb' ); ?></label>
</th>
<td>
<input type="text" name="Button-Text" id="Button-Text" class="regular-text" placeholder="<?php echo esc_attr( '', 'apb' ); ?>" value="<?php echo esc_attr( $content['productButtonText'] ); ?>" required="required" />
<span class="description"><?php _e('Enter your button text', 'apb' ); ?></span>
<br/>
<span class="description"><?php _e('Complete text as it should appear on the button', 'apb' ); ?></span>
</td>
</tr>
</tbody>
@@ -3,33 +3,59 @@

<form action="" method="post">

<?php
$default_image = '';
$phURL = esc_url( plugins_url('ph.png', __FILE__ ) ) ;
?>

<table class="form-table">
<tbody>
<tr class="row-Product Name">

<tr class="row-productName">
<th scope="row">
<label for="Product-Name"><?php _e( 'Product-Name', 'apb' ); ?></label>
<label for="Product-Name"><?php _e( 'Product name', 'apb' ); ?></label>
</th>
<td>
<input type="text" name="Product-Name" id="Product-Name" class="regular-text" placeholder="<?php echo esc_attr( '', 'apb' ); ?>" value="" required="required" />
<span class="description"><?php _e('Name help', 'apb' ); ?></span>
<br/>
<span class="description"><?php _e('Product name, model, etc.', 'apb' ); ?></span>
</td>
</tr>
<tr class="row-Tagline">

<tr class="row-Product-Image">
<th scope="row">
<label for="Product-Name"><?php _e( 'Product image', 'apb' ); ?></label>
</th>
<td>
<div class="upload">
<img data-src="<?php echo $phURL ?>" src="<?php echo $phURL ?>" width="120px" height="120px" />
<div>
<input type="hidden" name="Product-Image" id="Product-Image" value="" />
<button type="submit" class="upload_image_button button"><?php _e( 'Upload/Choose', 'apb' ); ?></button>
<button type="submit" class="remove_image_button button"><?php _e( 'Clear', 'apb' ); ?></button>
</div>
</div>
</td>
</tr>

<tr class="row-tagline">
<th scope="row">
<label for="Tagline"><?php _e( 'Tagline', 'apb' ); ?></label>
</th>
<td>
<input type="text" name="Tagline" id="Tagline" class="regular-text" placeholder="<?php echo esc_attr( '', 'apb' ); ?>" value="" required="required" />
<span class="description"><?php _e('Tagline help', 'apb' ); ?></span>
<br/>
<span class="description"><?php _e('A tagline is short and memorable (3-6 words)', 'apb' ); ?></span>
</td>
</tr>
<tr class="row-Description">
<tr class="row-description">
<th scope="row">
<label for="Description"><?php _e( 'Description', 'apb' ); ?></label>
</th>
<td>
<textarea name="Description" id="Description"placeholder="<?php echo esc_attr( '', 'apb' ); ?>" rows="5" cols="30" required="required"></textarea>
<p class="description"><?php _e('Description help', 'apb' ); ?></p>
<textarea name="Description" id="Description"placeholder="<?php echo esc_attr( '', 'apb' ); ?>" rows="6" cols="46" required="required"></textarea>
<br/>
<span class="description"><?php _e('Write about 20-30 words (~200 characters) enticing your visitor to choose this product', 'apb' ); ?></span>
</td>
</tr>
<tr class="row-URL">
@@ -38,16 +64,18 @@
</th>
<td>
<input type="text" name="URL" id="URL" class="regular-text" placeholder="<?php echo esc_attr( '', 'apb' ); ?>" value="" required="required" />
<span class="description"><?php _e('Enter your affiliate link', 'apb' ); ?></span>
<br/>
<span class="description"><?php _e('Product affiliate link, including https://', 'apb' ); ?></span>
</td>
</tr>
<tr class="row-buttonText">
<th scope="row">
<label for="Button-Text"><?php _e( 'Button-Text', 'apb' ); ?></label>
<label for="Button-Text"><?php _e( 'Button text', 'apb' ); ?></label>
</th>
<td>
<input type="text" name="Button-Text" id="Button-Text" class="regular-text" placeholder="<?php echo esc_attr( '', 'apb' ); ?>" value="" required="required" />
<span class="description"><?php _e('Enter your button text', 'apb' ); ?></span>
<br/>
<span class="description"><?php _e('Complete text as it should appear on the button', 'apb' ); ?></span>
</td>
</tr>
</tbody>
@@ -3,18 +3,29 @@
border:1px solid grey;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
padding:28px;
/* width:700px; */ /* uncomment to center in post */
/* margin:0 auto !important;*/ /* uncomment to center in post */
}

.amazin-product-box-column {
float:left;
}

.amazin-product-box-image-row {
display:flex;
margin-bottom:20px;
}

.amazin-product-box-left {
width:50%;
display:flex;
justify-content:center;
align-items:center;
}

.amazin-product-box-right {
width:50%;
width:45%;
margin-left:20px;
}

.amazin-product-box-recommend-text {
@@ -44,7 +55,7 @@
text-align:center;
}

.amazin-product-box a, .amazin-product-box a:visited {
.amazin-product-box a, .amazin-product-box a:visited, .amazin-product-box a:hover {
color:white;
text-decoration:none !important;
}
@@ -58,3 +69,14 @@
margin:10px;
font-family:sans-serif;
}

@media screen and (max-width: 979px) {
.amazin-product-box-left {
width:100%;
}

.amazin-product-box-right {
width:100%;
margin-left:0;
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.