/** * Get the Page Builder data for the current admin page. * @return array * @since 0.9.0 */ public function get_current_admin_panels_data() { $screen = get_current_screen(); global $post; $panels_data = get_post_meta($post->ID, 'panels_data', true); $panels_data = apply_filters('siteorigin_panels_data', $panels_data, $post->ID); if (empty($panels_data)) { $panels_data = array(); } //Set default styles if none if (isset($panels_data['widgets'])) { foreach ($panels_data['widgets'] as &$widget) { if (isset($widget['info'])) { if (!isset($widget['info']['style'])) { $widget['info']['style'] = ppb_default_content_block_style(); } } } } return $panels_data; }
/** * Opens the content block container with styles and classes * * @param $block_info * @param $gi * @param $ci * @param $pi * @param $blocks_num * @param $post_id * * @action ppb_panels_render_content_block * @since 1.0.0 */ public function open_block($block_info, $gi, $ci, $pi, $blocks_num, $post_id) { $styleArray = $widgetStyle = isset($block_info['info']['style']) ? json_decode($block_info['info']['style'], true) : ppb_default_content_block_style(); //Classes for this content block $classes = array('panel'); if (0 == $pi) { $classes[] = 'panel-first-child'; } if ($blocks_num - 1 == $pi) { $classes[] = 'panel-last-child'; } //Id for this content block $id = 'panel-' . $post_id . '-' . $gi . '-' . $ci . '-' . $pi; $inlineStyle = ''; $widgetStyleFields = ppb_block_styling_fields(); $styleWithSelector = ''; foreach ($widgetStyleFields as $key => $field) { if ($field['type'] == 'border') { // a border field has 2 settings $key1 = $key . '-width'; $key2 = $key . '-color'; if (isset($styleArray[$key1]) && $styleArray[$key1] != '') { if (!is_array($field['css'])) { $cssArr = array($field['css']); } else { $cssArr = $field['css']; } foreach ($cssArr as $cssProperty) { $inlineStyle .= $cssProperty . '-width: ' . $styleArray[$key1] . 'px; border-style: solid;'; } } if (isset($styleArray[$key2]) && $styleArray[$key2] != '') { if (!is_array($field['css'])) { $cssArr = array($field['css']); } else { $cssArr = $field['css']; } foreach ($cssArr as $cssProperty) { $inlineStyle .= $cssProperty . '-color: ' . $styleArray[$key2] . ';'; } } } elseif ($key == 'inline-css') { if (!empty($styleArray[$key])) { $inlineStyle .= $styleArray[$key]; } } else { if (isset($styleArray[$key]) && $styleArray[$key] != '') { if (!is_array($field['css'])) { $cssArr = array($field['css']); } else { $cssArr = $field['css']; } foreach ($cssArr as $cssProperty) { if (isset($field['unit'])) { $unit = $field['unit']; } else { $unit = ''; } if (!isset($field['selector'])) { $inlineStyle .= $cssProperty . ': ' . $styleArray[$key] . $unit . ';'; } else { $styleWithSelector .= '#' . $id . ' > ' . $field['selector'] . ' { ' . $cssProperty . ': ' . $styleArray[$key] . $unit . '; }'; } } } } } if ($styleWithSelector != '') { echo "<style>\n"; echo str_replace('display', 'display:none;display', $styleWithSelector); echo "</style>\n"; } echo '<div class="' . esc_attr(implode(' ', $classes)) . '" id="' . $id . '" style="' . $inlineStyle . '" >'; }
/** * Convert form post data into more efficient panels data. * @param $form_post * @return array */ function siteorigin_panels_get_panels_data_from_post($form_post) { $panels_data = array(); $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_widget = new $info['class'](); if (method_exists($the_widget, 'update') && !empty($info['raw'])) { $widget = $the_widget->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 = ppb_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('siteorigin_panels_panels_data_from_post', $panels_data); }