i am tring grab the $instance varible inside the __construct function of a widget.
i need this so i can create a dynamic widget name

I tried:

  • printing out the $instance
  • Printing out $this

Here is an example __construct function i am using in one of my widgets

function __construct() {

    $widget_ops = array(
        'classname'     => 'sg_image_widg', 
        'description'   => __('Custom Image widget by SITEIT', 'siteitsob')

    parent::__construct('sgImageWidget', __('Image Widget', 'siteitsob'), $widget_ops);

    add_action('admin_enqueue_scripts', array($this, 'upload_scripts'));    

Ideas anyone?

  • It doesn’t really make any sense for a specific jnstance to be referenced in the constructor. That’s not how widgets work. What do you want to do with it? There’s probably a better way to do it. – Jacob Peattie Jul 31 '18 at 10:21
  • I want to change of the widget dynamically based on the users input inside the widget fields - this means i only need accesible information meaning after it was saved... just dont know how to reach any information inside that __construct func. – Sagive SEO Aug 21 '18 at 11:24
  • Why does it need to be in the constructor? Can’t you just make th changes in form() and widget()? – Jacob Peattie Aug 21 '18 at 11:51
  • what do you mean? i dont want to use jQuery after page load.. can i re-set the widget "name" in this case __('Image Widget', 'siteitsob') inside the form / widget function? – Sagive SEO Aug 22 '18 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.