Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Image Uploader
- *
- * author: Arthur Gareginyan www.arthurgareginyan.com
- * Modified by Andy Warren - Original here: https://mycyberuniverse.com/integration-wordpress-media-uploader-plugin-options-page.html
- */
- function arthur_image_uploader($optionName) {
- // Set variables
- $options = get_option($optionName);
- $default_image = 'https://www.placehold.it/115x115';
- if (!empty($options)) {
- $image_attributes = wp_get_attachment_image_src($options, 'full');
- $src = $image_attributes[0];
- $value = $options;
- } else {
- $src = $default_image;
- $value = '';
- }
- // Print HTML field
- echo '
- <div class="upload" style="max-width:400px;">
- <img data-src="' . $default_image . '" src="' . $src . '" style="max-width:100%; height:auto;" />
- <div>
- <input type="hidden" name="' . $optionName . '" id="' . $optionName . '" value="' . $value . '" />
- <button type="submit" class="upload_image_button button">' . __('Upload', 'igsosd') . '</button>
- <button type="submit" class="remove_image_button button">×</button>
- </div>
- </div>
- ';
- }
- /*********
- Usage:
- Call the function with arthur_image_uploader('igsosd_logo'); and replace the "igsosd_logo" with the name of the option field you're saving to
- to retrieve the image in a template file use $igsosdLogo = get_option('igsosd_logo'); then display it with wp_get_attachment_url($igsosdLogo); while making sure to change igsosd_logo in the get_option() call to be what your field name is.
- *********/
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement