Gets a specific instance of a widget

@param string $widget_id The widget id
@return AbstractWidget|bool
425799
public static function get_widget_instance( $widget_id ) {
		global $wp_registered_widgets;

		if ( ! isset( $wp_registered_widgets[ $widget_id ] ) ) {
			return false;
		}

		$model = $wp_registered_widgets[ $widget_id ]['callback'][0];

		if ( ! is_a( $model, 'Lean\Widgets\Models\AbstractWidget' ) ) {
			return false;
		}

		$key = $wp_registered_widgets[ $widget_id ]['params'][0]['number'];

		$model->_set( $key );

		return $model;
	}
969151
public function getWidgets()
    {
        if ($this->widgets === null || !array_key_exists('value', $this->widgets)) {
            return;
        }

        //return an array, no matter one or many widget defined
        if (count($this->widgets['value']) > 1) {
            return $this->widgets['value'];
        } else {
            return [$this->widgets['value']];
        }
    }
555143
protected function getHash(Widget $widget)
    {
        $hash = null;
        if (!$widget instanceof WidgetSlotInterface) {
            if ($widget->getMode() == Widget::MODE_BUSINESS_ENTITY
                && ($entity = $widget->getEntity())
                && method_exists($widget->getEntity(), 'getUpdatedAt')) {
                $hash = $this->generateBusinessEntityHash($widget);
            } elseif ($widget->getMode() == Widget::MODE_STATIC) {
                $hash = $this->generateHash($widget);
            }
        }

        return $hash;
    }
724563
public function getExtraCssClass(Widget $widget)
    {
        $cssClass = 'v-widget--'.strtolower($this->container->get('victoire_widget.widget_helper')->getWidgetName($widget));

        return $cssClass;
    }
1050141
public I_CmsWidget getWidgetObject() {

        if (getWidget() == null) {
            if (m_params == null) {
                return new CmsInputWidget();
            } else {
                return new CmsInputWidget(m_params);
            }
        }
        try {
            if (m_params == null) {
                return (I_CmsWidget)Class.forName(getWidget()).newInstance();
            }
            Class<?> clazz = Class.forName(getWidget());
            Constructor<?> ctor = clazz.getConstructor(new Class[] {String.class});
            return (I_CmsWidget)ctor.newInstance(new Object[] {m_params});
        } catch (Exception e) {
            return new CmsInputWidget();
        }
    }
247540
protected function widgetFactory()
    {
        if ($this->widgetFactory === null) {
            throw new RuntimeException(sprintf(
                'Widget Factory is not defined for "%s"',
                get_class($this)
            ));
        }

        return $this->widgetFactory;
    }
65547
private static function register_widget( $widget_class ) {
		register_widget( $widget_class );

		$callback = [ $widget_class, 'post_registration' ];
		if ( is_callable( $callback, true ) ) {
			call_user_func( $callback );
		}
	}
687357
protected function _resolveWidget($widget)
    {
        $type = gettype($widget);
        if ($type === 'object') {
            return $widget;
        }

        if ($type === 'string') {
            $widget = [$widget];
        }

        $class = array_shift($widget);
        $className = App::className($class, 'View/Widget', 'Widget');
        if ($className === false || !class_exists($className)) {
            throw new RuntimeException(sprintf('Unable to locate widget class "%s"', $class));
        }
        if ($type === 'array' && count($widget)) {
            $reflection = new ReflectionClass($className);
            $arguments = [$this->_templates];
            foreach ($widget as $requirement) {
                $arguments[] = $this->get($requirement);
            }
            $instance = $reflection->newInstanceArgs($arguments);
        } else {
            $instance = new $className($this->_templates);
        }
        if (!($instance instanceof WidgetInterface)) {
            throw new RuntimeException(sprintf('"%s" does not implement the WidgetInterface', $className));
        }

        return $instance;
    }
528692
public static function get_instance($site_id)
    {
        global $wpdb;

        $site_id = (int) $site_id;
        if (! $site_id) {
            return false;
        }

        $_site = wp_cache_get($site_id, 'sites');

        if (! $_site) {
            $_site = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id));

            if (empty($_site) || is_wp_error($_site)) {
                return false;
            }

            wp_cache_add($site_id, $_site, 'sites');
        }

        return new WP_Site($_site);
    }
1238497
public function getUniqueId()
    {
        $parameters = $this->getParameters();
        unset($parameters['module']);
        unset($parameters['action']);

        return WidgetsList::getWidgetUniqueId($this->getModule(), $this->getAction(), $parameters);
    }
1053182
public function searchWidget()
    {
        $widget = $this->widgetFactory()->create(SearchWidget::class);
        $widget->setObjType($this->objType());

        $listIdent = $this->metadataListIdent();

        // Note that if the ident doesn't match a list,
        // it will return basicly every properties of the object
        $widget->setCollectionIdent($listIdent);

        return $widget;
    }
591065
public function hasWidget($widget)
    {
        if ($widget instanceof Model) {
            $widget = $widget->id;
        }

        return $this->widgets()->where('widget_id', $widget)->exists();
    }
913884
public function getWidgetQueryBuilder(Widget $widget)
    {
        //get the base query
        $itemsQueryBuilder = $this->queryHelper->getQueryBuilder($widget, $this->entityManager);

        // Filter only visibleOnFront
        $itemsQueryBuilder->andWhere('main_item.visibleOnFront = true');

        //add the query of the widget
        return $this->queryHelper->buildWithSubQuery($widget, $itemsQueryBuilder, $this->entityManager);
    }
1115011
public function parameters($id, $widget)
    {
        $widget    = Widget::withoutGlobalScope('menu_assignment')->findOrNew($widget);
        $extension = $this->repository->findOrFail($id);
        $formView  = $extension->param('form');

        if (view()->exists($formView)) {
            return view($formView, compact('widget'));
        }

        return view('widgets.partials.none');
    }
23111
public static function instance($id)
	{
		$class = get_called_class();

		if (empty(static::$instances[$class][$id]))
		{
			static::$instances[$class][$id] = new static($id);
		}

		return static::$instances[$class][$id];
	}
523101
public function getWidgetStaticContent(Widget $widget)
    {
        $reflect = new \ReflectionClass($widget);
        $widgetProperties = $reflect->getProperties();
        $parameters = ['widget' => $widget];
        $accessor = PropertyAccess::createPropertyAccessor();

        foreach ($widgetProperties as $property) {
            if (!$property->isStatic()) {
                $value = $accessor->getValue($widget, $property->getName());
                $parameters[$property->getName()] = $value;
            }
        }

        return $parameters;
    }
1272583
private function compareWidget($module, $widget)
    {
        $res = array();
        
        try {
            $w = Application::getInstance()->getWidget( $widget['widgetAlias'] );
        } catch (\Exception $e) {
      		  $res[] = array(
      				'error'  => self::WIDGET_NOT_EXISTS,
      				'widget' => $widget['widgetAlias'],
      				'module' => $module
      			);
        }
        
        return $res;  
    }