← Back
Editing: class-bb-theme-builder.php
<?php namespace GD_cORe\handlers\plugin_configs; if ( ! defined( 'ABSPATH' ) ) { exit; } /** * The admin-specific functionality of the plugin. * * * @package GD_cORe * @subpackage GD_cORe/admin */ class bb_theme_builder extends Main { public function __construct() { parent::__construct(); } /** * Install default 2020 Beaver Builder theme layouts. * * @since 3.3.1 */ public static function install_layouts( $jsonFilePath ) { if ( !$jsonFilePath ) { return; } $layouts = json_decode( file_get_contents( $jsonFilePath ) ); /* * Iterate each layout item * * @since 3.3.1 */ foreach ( $layouts->item as $layout ) { /* * Short-circuit if layout has already been created. * * @since 3.3.1 */ if ( get_page_by_title( $layout->title, OBJECT, $layout->post_type->__cdata ) ) { continue; } /** * Iterate the content for each layout. * Handles array of content objects. * * @since 3.3.1 */ $content = ''; foreach ( $layout->encoded as $content_object ) { $content = $content.$content_object->__cdata; } /** * Insert custom post type using parsed arguments. * Preserve new post ID to handle custom taxonomies and meta. * * @since 3.3.1 */ $inserted_post_id = wp_insert_post( [ 'post_title' => $layout->title, 'post_name' => $layout->post_name->__cdata, 'post_content' => wp_slash( $content ), 'post_type' => $layout->post_type->__cdata, 'post_status' => $layout->status->__cdata, 'comment_status' => $layout->comment_status->__cdata, 'ping_status' => $layout->ping_status->__cdata, 'post_parent' => $layout->post_parent->__text, 'menu_order' => $layout->menu_order->__text, ] ); /* * Iterate the post meta for each layout after insertion. * Unserialize meta values and add slashes where needed in post meta. * * @since 3.3.1 */ foreach ( $layout->postmeta as $meta_object ) { $key = $meta_object->meta_key->__cdata; $unserialize_value = maybe_unserialize( $meta_object->meta_value->__cdata ); add_post_meta( $inserted_post_id, wp_slash( $key ), wp_slash_strings_only( $unserialize_value ) ); } } // Reset permalinks for the new post type. flush_rewrite_rules(); } // TODO: combine all templates into one file and remove the need for this function. public function findFilePath( $siteType ) { $site_types = array( 4 => 'premium', 5 => 'premiumStore' ); if ( array_key_exists( $siteType, $site_types ) ) { return GD_cORe_ROOT_PATH.'admin/assets/data/themer-layouts/'.$site_types[ $siteType ].'_templates.json'; } return null; } public function runConfig() { // TODO: combine all templates into one file and remove the need for siteType specific files. $siteType = 5; $all_site_templates = GD_cORe_ROOT_PATH.'admin/assets/data/themer-layouts/allSites_templates.json'; $this->install_layouts( $all_site_templates ); $this->install_layouts( $this->findFilePath( $siteType ) ); } }
Save File
Cancel