/** * Adds default styles to content block if not set * @param $widgets * @return array * @since 0.1.0 */ public function add_default_styles_to_blocks(&$widgets) { //Set default styles if none foreach ($widgets as &$widget) { //If content block info is set but style info ain't if (!empty($widget['info']) && empty($widget['info']['style'])) { //Set default style $widget['info']['style'] = pootlepb_default_content_block_style(); } } }
/** * Convert form post data into more efficient panels data. * @param $form_post * @return array * @since 0.1.0 */ function pootlepb_get_panels_data_from_post($form_post = null) { if (null == $form_post) { $form_post = $_POST; } $panels_data = array(); if (!empty($_POST['pootlepb_noPB'])) { return $panels_data; } $panels_data['widgets'] = array_values(stripslashes_deep(isset($form_post['widgets']) ? $form_post['widgets'] : array())); foreach ($panels_data['widgets'] as $i => $widget) { if (empty($widget['info'])) { continue; } $info = $widget['info']; $widget = json_decode($widget['data'], true); if (class_exists($info['class'])) { $the_block = new $info['class'](); if (method_exists($the_block, 'update') && !empty($info['raw'])) { $widget = $the_block->update($widget, $widget); } } unset($info['raw']); $widget['info'] = $info; // if widget style is not present in $_POST, set a default if (!isset($info['style'])) { $widgetStyle = pootlepb_default_content_block_style(); $info['style'] = $widgetStyle; } $panels_data['widgets'][$i] = $widget; } $panels_data['grids'] = array_values(stripslashes_deep(isset($form_post['grids']) ? $form_post['grids'] : array())); $panels_data['grid_cells'] = array_values(stripslashes_deep(isset($form_post['grid_cells']) ? $form_post['grid_cells'] : array())); return apply_filters('pootlepb_panels_data_from_post', $panels_data); }