5 if ( ! defined(
'GRAVITYVIEW_DIR' ) ) {
22 public function add( $widget ) {
23 if ( ! $widget instanceof
Widget ) {
24 gravityview()->log->error(
'Widget_Collections can only contain objects of type \GV\Widget.' );
27 parent::add( $widget );
40 public function get( $widget_uid ) {
41 foreach ( $this->all() as $widget ) {
42 if ( $widget->UID == $widget_uid ) {
61 $widgets =
new self();
63 $search = implode(
'.*', array_map(
'preg_quote', explode(
'*', $position ) ) );
65 foreach ( $this->all() as $widget ) {
66 if ( preg_match(
"#^{$search}$#", $widget->position ) ) {
67 $widgets->add( $widget );
84 $widgets =
new self();
86 foreach ( $this->all() as $widget ) {
87 if ( $id == $widget->get_widget_id() ) {
88 $widgets->add( $widget );
120 $widgets =
new self();
121 foreach ( $configuration as $position => $_widgets ) {
123 if ( empty( $_widgets ) || ! is_array( $_widgets ) ) {
127 foreach ( $_widgets as $uid => $_configuration ) {
128 if ( ! $widget = Widget::from_configuration( $_configuration ) ) {
133 $widget->position = $position;
135 $widgets->add( $widget );
146 public function as_configuration() {
147 $configuration = array();
152 foreach ( $this->all() as $widget ) {
153 if ( empty( $configuration[ $widget->position ] ) ) {
154 $configuration[ $widget->position ] = array();
157 $configuration[ $widget->position ][ $widget->UID ] = $widget->as_configuration();
159 return $configuration;
If this file is called directly, abort.
gravityview()
The main GravityView wrapper function.