/** * Create a new widget instance * * @param int $owner_guid GUID of entity that owns this widget * @param string $handler The handler for this widget * @param string $context The context for this widget * @param int $access_id If not specified, it is set to the default access level * * @return int|false Widget GUID or false on failure * @since 1.8.0 */ function elgg_create_widget($owner_guid, $handler, $context, $access_id = null) { if (empty($owner_guid) || empty($handler) || !elgg_is_widget_type($handler)) { return false; } $owner = get_entity($owner_guid); if (!$owner) { return false; } $widget = new ElggWidget(); $widget->owner_guid = $owner_guid; $widget->container_guid = $owner_guid; // @todo - will this work for group widgets if (isset($access_id)) { $widget->access_id = $access_id; } else { $widget->access_id = get_default_access(); } if (!$widget->save()) { return false; } // private settings cannot be set until ElggWidget saved $widget->handler = $handler; $widget->context = $context; return $widget->getGUID(); }
/** * Determines whether or not widgets with the specified handler have been defined * * @param string $handler The widget handler identifying string * * @return bool Whether or not those widgets exist * @deprecated 1.8 Use elgg_is_widget_type */ function widget_type_exists($handler) { elgg_deprecated_notice("widget_type_exists deprecated for elgg_is_widget_type", 1.8); return elgg_is_widget_type($handler); }