wordpress/wp-content/themes/basic/themify/themify-builder/classes/class-themify-global-styles.php
/**
	 * Insert new Global Style
	 *
	 * @access static
	 * @param array $args
	 * @return Mixed return false if fails or array of info about inserted post if success
	 */
Insert new Global Style
@access static
@param array $args
@return Mixed return false if fails or array of info about inserted post if success
Insert new Global Style @access static @param array $args @return Mixed return false if fails or array of info about inserted post if success
public static function add_new( $args,$action = 'new' ) {
		if ( empty( $args['style-name'] ) ) {
			return false;
		}
		$name = sanitize_text_field( $args['style-name'] );
		$type = sanitize_text_field( $args['style-type'] );
		if($type==='subcolumn'){
			$type='column';
		}
		$module_type = 'row' === $type || 'column' === $type || 'subrow' === $type? 'text' : $type;
		$module = isset( Themify_Builder_Model::$modules[ $module_type ] ) ? Themify_Builder_Model::$modules[ $module_type ] : null;
		$rowStyling = $colStyling = $moduleStyling = '{}';
		if ( is_null( $module ) ) {
			$modules = Themify_Builder_Model::get_modules();
			require_once $modules[ $module_type ]['dirname'] . '/' . $modules[ $module_type ]['basename'];
			$module = Themify_Builder_Model::$modules[ $module_type ];
		}
		$default = $module->get_live_default();
		$default = is_array( $default ) ? $default : array();
		if ( isset( $default['content_text'] ) && 'text' === $module_type ) {
			$default['content_text'] = '<h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3><h4>Heading 4</h4><p>This is a sample Text module.</p>';
		}
		if ( !empty( $args['styles'] ) ) {
			switch ( $type ) {
				case 'subrow':
				case 'row':
				$rowStyling = json_encode( $args['styles'] );
					break;
				case 'column':
				$colStyling = json_encode( $args['styles'] );
					break;
				default:
				$args['styles'] = array_merge( $default, $args['styles'] );
				$moduleStyling = json_encode( $args['styles'] );
			}
		} else {
			$moduleStyling = json_encode( $default );
		}
		if ( 'row' === $type || 'column' === $type || 'subrow' === $type ) {
			$moduleStyling = json_encode( $default );
		}
		$id = uniqid();
		$builder_content = '[{"element_id":"row' . $id . '","styling":' . $rowStyling . ',"cols":[{"element_id":"col' . $id . '","grid_class":"col-full","styling":' . $colStyling . ',"modules":[{"element_id":"mod' . $id . '","mod_name":"' . $module_type . '","mod_settings":' . $moduleStyling . '}]}]}]';
		if('import' === $action){
			$new_id = $args['id'];
			update_post_meta( $new_id, 'themify_global_style_type', $type );
		}else{
		$new_id = wp_insert_post( array(
			'post_status' => 'publish',
			'post_type' => self::$post_type,
			'post_title' => $name,
			'post_name'=>!empty($args['slug'])?$args['slug']:'',
			'meta_input' => array(
				'themify_global_style_type' => $type,
				'hide_page_title' => 'yes'
			),
		) );
		}
		if ( !is_wp_error( $new_id ) ) {
			ThemifyBuilder_Data_Manager::save_data( $builder_content, $new_id );
			$post_slug = !empty( $args['slug'] ) ? $args['slug'] : 'tb_gs' . $new_id . substr( uniqid(), 0, 3 );
			if(empty($args['slug'])){
				$post_slug='tb_gs' . $new_id . substr( uniqid(), 0, 3 );
				wp_update_post( array(
					'ID' => $new_id,
					'post_name' => $post_slug
				) );
			}
			else{
				$post_slug = $args['slug'];
			}
			global $ThemifyBuilder;
			if('import' === $action){
				$result = array(
						'builder_data'=>$ThemifyBuilder->get_builder_data( $new_id ),
						'gsType'=>$type
				);
			}else{
				$result = array(
				'id' => $new_id,
				'class' => $post_slug,
				'title' => $name,
				'type' => $type,
				'url' => get_post_permalink( $new_id ),
				'data' => $ThemifyBuilder->get_builder_data( $new_id ),
			);
			}
		} else {
			$result = false;
		}
		return $result;
	}
public static function add_new ( $ args , $ action = 'new' ) { if ( empty ( $ args [ 'style-name' ] ) ) { return false ; } $ name = sanitize_text_field ( $ args [ 'style-name' ] ) ; $ type = sanitize_text_field ( $ args [ 'style-type' ] ) ; if ( $ type === 'subcolumn' ) { $ type = 'column' ; } $ module_type = 'row' === $ type || 'column' === $ type || 'subrow' === $ type ? 'text' : $ type ; $ module = isset ( Themify_Builder_Model :: $ modules [ $ module_type ] ) ? Themify_Builder_Model :: $ modules [ $ module_type ] : null ; $ rowStyling = $ colStyling = $ moduleStyling = '{}' ; if ( is_null ( $ module ) ) { $ modules = Themify_Builder_Model :: get_modules ( ) ; require_once $ modules [ $ module_type ] [ 'dirname' ] . '/' . $ modules [ $ module_type ] [ 'basename' ] ; $ module = Themify_Builder_Model :: $ modules [ $ module_type ] ; } $ default = $ module -> get_live_default ( ) ; $ default = is_array ( $ default ) ? $ default : array ( ) ; if ( isset ( $ default [ 'content_text' ] ) && 'text' === $ module_type ) { $ default [ 'content_text' ] = '<h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3><h4>Heading 4</h4><p>This is a sample Text module.</p>' ; } if ( ! empty ( $ args [ 'styles' ] ) ) { switch ( $ type ) { case 'subrow' : case 'row' : $ rowStyling = json_encode ( $ args [ 'styles' ] ) ; break ; case 'column' : $ colStyling = json_encode ( $ args [ 'styles' ] ) ; break ; default : $ args [ 'styles' ] = array_merge ( $ default , $ args [ 'styles' ] ) ; $ moduleStyling = json_encode ( $ args [ 'styles' ] ) ; } } else { $ moduleStyling = json_encode ( $ default ) ; } if ( 'row' === $ type || 'column' === $ type || 'subrow' === $ type ) { $ moduleStyling = json_encode ( $ default ) ; } $ id = uniqid ( ) ; $ builder_content = '[{"element_id":"row' . $ id . '","styling":' . $ rowStyling . ',"cols":[{"element_id":"col' . $ id . '","grid_class":"col-full","styling":' . $ colStyling . ',"modules":[{"element_id":"mod' . $ id . '","mod_name":"' . $ module_type . '","mod_settings":' . $ moduleStyling . '}]}]}]' ; if ( 'import' === $ action ) { $ new_id = $ args [ 'id' ] ; update_post_meta ( $ new_id , 'themify_global_style_type' , $ type ) ; } else { $ new_id = wp_insert_post ( array ( 'post_status' => 'publish' , 'post_type' => self :: $ post_type , 'post_title' => $ name , 'post_name' => ! empty ( $ args [ 'slug' ] ) ? $ args [ 'slug' ] : '' , 'meta_input' => array ( 'themify_global_style_type' => $ type , 'hide_page_title' => 'yes' ) , ) ) ; } if ( ! is_wp_error ( $ new_id ) ) { ThemifyBuilder_Data_Manager :: save_data ( $ builder_content , $ new_id ) ; $ post_slug = ! empty ( $ args [ 'slug' ] ) ? $ args [ 'slug' ] : 'tb_gs' . $ new_id . substr ( uniqid ( ) , 0 , 3 ) ; if ( empty ( $ args [ 'slug' ] ) ) { $ post_slug = 'tb_gs' . $ new_id . substr ( uniqid ( ) , 0 , 3 ) ; wp_update_post ( array ( 'ID' => $ new_id , 'post_name' => $ post_slug ) ) ; } else { $ post_slug = $ args [ 'slug' ] ; } global $ ThemifyBuilder ; if ( 'import' === $ action ) { $ result = array ( 'builder_data' => $ ThemifyBuilder -> get_builder_data ( $ new_id ) , 'gsType' => $ type ) ; } else { $ result = array ( 'id' => $ new_id , 'class' => $ post_slug , 'title' => $ name , 'type' => $ type , 'url' => get_post_permalink ( $ new_id ) , 'data' => $ ThemifyBuilder -> get_builder_data ( $ new_id ) , ) ; } } else { $ result = false ; } return $ result ; }
Insert new Global Style
 @access static
 @param array $args
 @return Mixed return false if fails or array of info about inserted post if success
Insert new Global Style @access static @param array $args @return Mixed return false if fails or array of info about inserted post if success
//there was an error in the post insertion,