Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Settings Image Won't Add #40

Open
rizedr opened this issue Jun 15, 2016 · 1 comment
Open

Settings Image Won't Add #40

rizedr opened this issue Jun 15, 2016 · 1 comment

Comments

@rizedr
Copy link

rizedr commented Jun 15, 2016

First of all, go in the plugin's settings page.
The following steps are to reproduce the issue:

  1. Add an image using "Upload new image"
  2. The image thumbnail will show.
  3. Remove the image using "Remove image"
  4. Add a new image using "Upload new image"
  5. The image won't add.
@deweydb
Copy link

deweydb commented Aug 5, 2016

Actually the image does add, and if you look with inspector the value of the input field will change, its just that the thumbnail is not being displayed anymore because the container was deleted, and there was nothing written to handle re-adding it.

The changes need to happen in the /assets/settings.js file, but then this file should be minified, and the /assets/settings.min.js contents replaced (if you don't do this step it won't work!).
So, in /assets/settings.js change:
Line: 52
jQuery("#"+preview_id).attr('src',attachment.sizes.thumbnail.url);
To:
jQuery("#"+preview_id).attr('src',attachment.sizes.thumbnail.url).show();

Line: 67
jQuery(this).closest('td').find( '.image_preview' ).remove();
To:
jQuery(this).closest('td').find( '.image_preview' ).hide();

Please note that wordpress caches admin javascript files, so it is advisable to add some cache busting for a development of a wordpress plugin, i.e. in /includes/class-your-plugin.php
around 190, change:
public function admin_enqueue_scripts ( $hook = '' ) { wp_register_script( $this->_token . '-admin', esc_url( $this->assets_url ) . 'js/admin' . $this->script_suffix . '.js', array( 'jquery' ), $this->_version ); wp_enqueue_script( $this->_token . '-admin' ); } // End admin_enqueue_scripts ()
to:
public function admin_enqueue_scripts ( $hook = '' ) { wp_register_script( $this->_token . '-admin', esc_url( $this->assets_url ) . 'js/admin' . $this->script_suffix . '.js?t='.time(), array( 'jquery' ), $this->_version ); wp_enqueue_script( $this->_token . '-admin' ); } // End admin_enqueue_scripts ()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants