Why my image upload button is not working in wordpress widget area?

During making addv. widget I facing a problem.When I am clicking the uploading button then it is not redirecting to media library.How to solve this problem?

<?php  add_action('widgets_init','personalblog_300x600_add_widgets');  function personalblog_300x600_add_widgets(){         register_widget("pb_300x600_add_widget"); }  class pb_300x600_add_widget extends WP_widget{  // Initialize the widget      public function pb_300x600_add_widget(){         $widget_ops = array( 'classname' => 'pb_300x600_add_widget', 'description' => esc_html__( 'Strawberry: A widget that shows 300x600 Adv.' , 'strawberry') );         parent::__construct('pb_300x600_add_widget', esc_html__('Strawberry: Add 300x600', 'strawberry'), $widget_ops);     }      public function widget( $args, $instance ) {         extract( $args );         $title    = apply_filters('widget_title', $instance['title'] );         $adv_href = esc_url($instance['adv_href']);         $adv_img  = esc_attr($instance['adv_img']);         $image_id = esc_attr($instance['image_id']);         $adv_code = $instance['adv_code'];?>         <div class="advertising">             <?php if ($adv_code == "") {                 if ($adv_href != "") {?><a href="<?php echo esc_url($adv_href)?>"><?php }?>                     <img alt="" src="<?php echo ($adv_img)?>">                 <?php if ($adv_href != "") {?></a><?php }?>             <?php }else {                 echo ($adv_code);             }?>         </div><!-- End advertising -->         <div class="clearfix"></div>         <?php     }      public function update( $new_instance, $old_instance ) {         $instance             = $old_instance;         $instance['title']    = strip_tags( $new_instance['title'] );         $instance['adv_code'] = $new_instance['adv_code'];         $instance['adv_img']  = $new_instance['adv_img'];         $instance['image_id'] = $new_instance['image_id'];         $instance['adv_href'] = $new_instance['adv_href'];         return $instance;     }      public function form( $instance ) {         $defaults = array( 'title' => 'Adv 300x600' );         $instance = wp_parse_args( (array) $instance, $defaults ); ?>          <p>             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e('Title :', 'strawberry'); ?></label>             <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo (isset($instance['title'])?esc_attr($instance['title']):""); ?>" class="widefat" type="text">         </p>         <p>             <label for="<?php echo $this->get_field_id( 'adv_img' ); ?>"><?php esc_html_e('Image URL :', 'strawberry'); ?> </label>             <input id="<?php echo $this->get_field_id( 'adv_img' ); ?>" name="<?php echo $this->get_field_name( 'adv_img' ); ?>" value="<?php echo (isset($instance['adv_img'])?$instance['adv_img']:"");?>" class="widefat upload" type="text">             <br><br>             <input class="custom_media_button button upload-button-2 upload-button-widget" type="button" value="Upload">             <br><br>             <input id="<?php echo $this->get_field_id( 'image_id' ); ?>" name="<?php echo $this->get_field_name( 'image_id' ); ?>" value="<?php echo (isset($instance['image_id'])?$instance['image_id']:"");?>" class="widefat image_id" type="hidden">         </p>         <p>             <label for="<?php echo $this->get_field_id( 'adv_href' ); ?>"><?php esc_html_e('Advertising url : ', 'strawberry'); ?></label>             <input id="<?php echo $this->get_field_id( 'adv_href' ); ?>" name="<?php echo $this->get_field_name( 'adv_href' ); ?>" value="<?php echo (isset($instance['adv_href'])?esc_attr($instance['adv_href']):""); ?>" class="widefat" type="text">         </p>          <em style="display:block; border-bottom:1px solid #CCC; margin-bottom:15px;">OR</em>          <p>             <label for="<?php echo $this->get_field_id( 'adv_code' ); ?>"><?php esc_html_e('Advertising Code html ( Ex: Google ads) :', 'strawberry'); ?> </label>             <textarea id="<?php echo $this->get_field_id( 'adv_code' ); ?>" name="<?php echo $this->get_field_name( 'adv_code' ); ?>" class="widefat"><?php echo (isset($instance['adv_code'])?esc_attr($instance['adv_code']):""); ?></textarea>         </p>     <?php     } } ?> 

Script:

 function media_upload(.custom_media_button.button) {         var _custom_media = true,         _orig_send_attachment = wp.media.editor.send.attachment;          $('body').on('click', button_class, function(e) {             var button_id ='#'+$(this).attr('id');             var self = $(button_id);             var send_attachment_bkp = wp.media.editor.send.attachment;             var button = $(button_id);             var id = button.attr('id').replace('_button', '');             _custom_media = true;             wp.media.editor.send.attachment = function(props, attachment){                 if ( _custom_media  ) {                     $('.custom_media_id').val(attachment.id);                     $('.custom_media_url').val(attachment.url);                     $('.custom_media_image').attr('src',attachment.url).css('display','block');                 } else {                     return _orig_send_attachment.apply( button_id, [props, attachment] );                 }             }             wp.media.editor.open(button);                 return false;         }); 

Thanks

Replay

I see a couple of things. First your missing the closing bracket for your js function. Also, in WP you need to use jQuery() rather than $() for jQuery calls. Finally, make sure your script is inside a jQuery(document).ready(function() { });block.

Category: php Time: 2016-07-30 Views: 11

Related post

  • Image uploading button is not appearing for authenticated users,only for admin 2014-02-06

    When using Filtered HTML on a body text, the image uploading button is only appearing for admin users under Tinymce, but not for authenticated users. How can I fix that? --------------Solutions------------- I just had the same issue and this is what

  • jQuery UI Accordion not working in WordPress widget backend 2016-01-19

    I'm working in a plugin where I need to create a sortable accordion with jQuery UI Accordion. I tried with the basic accordion from jQuery UI's API. But the accordion didn't fire. I used the jQuery(document).ready() event in there. What's the best jQ

  • Built-in spell checker not working in Wordpress 3.3.1 2013-12-05

    I am using WP 3.3.1 and have noticed that the built-in spell checker (ABC button) does not work, even when there are mis-spelt words. I have read a number of forum posts that essentially recommend using a standalone plugin to handle spell checking, h

  • Vmware vCloud director browse button do not work 2014-04-23

    I am using vmware director and i want to upload an iso image but the browse button do not work as you would expect it to. i took this screenshot I have masked the company details for privacy reasons.I am using firefox and my java plugin for firefox i

  • Adding a Image Upload Button in CKEditor 2012-10-28

    I have installed CKEditor in Wysiwyg profiles. While publishing any node if i click on the image upload button it shows options to add images by a image link, but what is the way to add a dynamic image upload button so that users will be able to Brow

  • Webform submit button does not work 2015-12-04

    I have created a webform block. After I enter all the info in the webform, I clicked the Submit button. Nothing happens. Do you know why the Submmit button is not working? This webform block's submit button works: http://godrupal.info/?q=contact-us A

  • SP Gridview link button column not working 2010-05-17

    I have one sharepoint custom page application which is rendering from a user control. In the user control page, i had used SPGridview for displaying data. My first column is Title Column (link button column), when the user click on the link, then one

  • Software Center shows the name of the software in a list, but install button does not work 2011-10-16

    Two days ago I performed a clean installation of Oneiric Ocelot on my Acer Extensa 4620. After installation I updated it first. Then I tried to install some other software packages like GIMP, Chrome, Pychess etc. But Software Center acted strangely.

  • Why does my Event Receiver (sandboxed) not work on Sharepoint Online, but works perfect on premise 2012-07-17

    using System; using System.Security.Permissions; using Microsoft.SharePoint; using Microsoft.SharePoint.Security; using Microsoft.SharePoint.Utilities; using Microsoft.SharePoint.Workflow; namespace Change_Title_Event.Change_Title { /// <summary> //

  • Recompilled Nginx 1.1.19 for chunked upload but still not working- 2012-07-17

    I can not get the chunked uploading to work. Even after recompiling Nginx. I am using nginx 1.1.19 on ubuntu 12.04. I downloaded the source code of nginx 1.1.19 and module for chunked uploading and compiled it as follows. ./configure --prefix=/etc/ng

  • Why is using two imbricate UpdateCursor not working? 2012-10-19

    I hope my question is not redundant. I wrote a script to Update a table using two imbricate cursors. The goal was: to read a records, update some of its values Make a selection based on this record (e.g. closest neighbors) Update the neighbors I have

  • Why the georeferencing in UTM does not work with the QGIS georeferencer? 2012-11-01

    First time here, sorry if this looks simple. I use QGIS on Windows 7. I georeferenced a toposheet with geographic references to UTM. When I superimpose a UTM raster, the toposheet is near the origin and the rater far away but properly imported. I the

  • Add more button does not worked any more 2013-03-03

    I added date field with unlimited values,it was working perfectly but suddenly it's stop adding new values. when click on in just the first time the blue circle appear for second and nothing happen after that, then the button does not work. sory for

  • Reset button is not working after previewing the webform 2014-01-12

    Reset button is not working after previewing the webform. Means when we click on preview button on webform, then on edit button of webform and then if we click on reset button. it does not work at all. What could be the reason, kindly suggest any sol

  • iPhone 5 stuck on spinning wheel (power button does not work) 2014-04-21

    I have a jailbroken iPhone 5. I accidentally tried to reset my settings through my phone instead of iTunes. It has been stuck on the spinning wheel since 10am today (it is now 6:44pm). I've been told to wait until it dies since my POWER BUTTON does N

  • Why does this use of `\expandafter` not work? 2014-05-14

    I've written the following code: \newif\ifconsecutive \consecutivefalse \newcommand{\myfirst}[1]{#1\consecutivetrue\expandafter\consecutivefalse} \newcommand{\mysecond}[1]{\ifconsecutive $\longrightarrow$\fi #1} The idea was that if I write \myfirst{

  • Can i decline iphone call when the screen was locked AND power button Does not work? 2014-11-29

    Can any body help? i use iphone 5, the power button does not work, what shall i do to decline the call when the screen was locked? are any software? or some combinations? --------------Solutions------------- on your iPhone, go to: settings > general

  • Iphone 4 won't turn on and home button does not work 2015-02-18

    My iPhone is dead in black screen. I was walking on the street when it was the last time i used the iphone normally. The next time back home, i realized that after trying to use the phone again by pressing just once on the turn on/ wake button, the p

  • Creating new folder from document list, showing two save button, footer save button does not work whereas upper save button works 2015-10-13

    When we create new folder from document list, pop up shows two save buttons. Upper save button works properly and post backed to list page whereas bottom save button does not work, doesn't post backed into list. Please suggest solution. I have tried

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 1.436 (s). 13 q(s)