WordPress-Plugin-Template icon indicating copy to clipboard operation
WordPress-Plugin-Template copied to clipboard

Settings Image Won't Add

Open rizedr opened this issue 8 years ago • 1 comments

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.

rizedr avatar Jun 15 '16 07:06 rizedr

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 ()

deweydb avatar Aug 05 '16 02:08 deweydb