emove the template ID and template node ID for standard templates. else { foreach ( $nodes as $node_id => $node ) { if ( isset( $nodes[ $node_id ]->template_id ) ) { unset( $nodes[ $node_id ]->template_id ); } if ( isset( $nodes[ $node_id ]->template_node_id ) ) { unset( $nodes[ $node_id ]->template_node_id ); } if ( isset( $nodes[ $node_id ]->template_root_node ) ) { unset( $nodes[ $node_id ]->template_root_node ); } } } // Save the template layout data. self::update_layout_data( $nodes, 'published', $post_id ); self::update_layout_data( $nodes, 'draft', $post_id ); // Enable the builder for this template. update_post_meta( $post_id, '_fl_builder_enabled', true ); // Add the template ID post meta. We use a custom ID for node // templates in case templates are imported since their WordPress // IDs will change, breaking global templates. update_post_meta( $post_id, '_fl_builder_template_id', $template_id ); // Add the template global flag post meta. update_post_meta( $post_id, '_fl_builder_template_global', $settings['global'] ); // Delete the existing node and apply the template for global templates. if ( $settings['global'] ) { // Delete the existing node. self::delete_node( $template_node_id ); // Apply the global template. $root_node = self::apply_node_template( $template_id, $original_parent, $original_position ); } // Return an array of template settings. return array( 'id' => $template_id, 'global' => $settings['global'] ? true : false, 'link' => add_query_arg( 'fl_builder', '', get_permalink( $post_id ) ), 'name' => $settings['name'], 'type' => $root_node->type, 'layout' => $settings['global'] ? FLBuilderAJAXLayout::render( $root_node->node, $template_node_id ) : null ); } /** * Sets the default type for a node template when created in wp-admin. * * @since 1.6.3 * @param int $post_ID The post ID for the template. * @param object $post The post object for the template. * @param bool $update Whether this is a new post or an update. * @return void */ static public function set_node_template_default_type( $post_id, $post, $update ) { if ( $update || 'fl-builder-template' != $post->post_type ) { return; } $type = wp_get_post_terms( $post_id, 'fl-builder-template-type' ); if ( 0 === count( $type ) ) { wp_set_post_terms( $post_id, 'layout', 'fl-builder-template-type' ); } } /** * Deletes a node template via AJAX. * * @since 1.6.3 * @param string $template_id The ID of node template to delete. * @return void */ static public function delete_node_template( $template_id ) { // Make sure we have a template ID. if ( ! isset( $template_id ) ) { return; } // Get the post ID for the template. $template_post_id = self::get_node_template_post_id( $template_id ); // Bail if we don't have a post ID. if ( ! $template_post_id ) { return; } // Unlink if this is a global template. self::unlink_global_node_template_from_all_posts( $template_post_id ); // Delete the template post. wp_delete_post( $template_post_id, true ); } /** * Unlinks all instances of a global node template in all posts. * * @since 1.6.3 * @param int $template_post_id The post ID of the template to unlink. * @return void */ static public function unlink_global_node_template_from_all_posts( $template_post_id ) { if ( self::is_post_global_node_template( $template_post_id ) ) { $posts = self::get_posts_with_global_node_template( $template_post_id ); $template_id = get_post_meta( $template_post_id, '_fl_builder_template_id', true ); foreach ( $posts as $post ) { self::unlink_global_node_template_from_post( 'published', $post->ID, $template_post_id, $template_id ); self::unlink_global_node_template_from_post( 'draft', $post->ID, $template_post_id, $template_id ); self::delete_all_asset_cache( $post->ID ); } } } /** * Unlinks all instances of a global node template from a post's * layout data with the specified status. Since only the root node * of a global template is saved to a posts layout data, the child * nodes will be saved to the post when the global template is unlinked. * * @since 1.6.3 * @param string $status The status of the layout data. Either draft or published. * @param int $post_id The ID of the post to unlink from. * @param string $template_post_id The post ID of the template to unlink from the layout data. * @param string $template_id The ID of the template to unlink from the layout data. * @return void */ static public function unlink_global_node_template_from_post( $status, $post_id, $template_post_id, $template_id ) { $template_data = self::get_layout_data( $status, $template_post_id ); $layout_data = self::get_layout_data( $status, $post_id ); $update = false; // Loop through the layout data. foreach ( $layout_data as $node_id => $node ) { // Check to see if this is the global template node to unlink. if ( isset( $node->template_id ) && $node->template_id == $template_id ) { // Generate new node ids for the template data. $new_data = self::generate_new_node_ids( $template_data ); // Get the root node from the template data. $root_node = self::get_node_template_root( $node->type, $new_data ); // Remove the root node from the template data since it's already in the layout. unset( $new_data[ $root_node->node ] ); // Update the settings for the root node in this layout. $layout_data[ $node_id ]->settings = $root_node->settings; // Update children with the new parent node ID. foreach ( $new_data as $i => $n ) { if ( $n->parent == $root_node->node ) { $new_data[ $i ]->parent = $node->node; } } // Add the template data to the layout data. $layout_data = array_merge( $layout_data, $new_data ); // Set the update flag. $update = true; } } // Only update if we need to. if ( $update ) { // Remove template info from the layout data. foreach ( $layout_data as $node_id => $node ) { unset( $layout_data[ $node_id ]->template_id ); unset( $layout_data[ $node_id ]->template_post_id ); unset( $layout_data[ $node_id ]->template_root_node ); } // Update the layout data. self::update_layout_data( $layout_data, $status, $post_id ); } } /** * Deletes all instances of a global node template from all posts. * * @since 1.6.3 * @param int $template_post_id The post ID of the template to delete. * @return void */ static public function delete_global_node_template_from_all_posts( $template_post_id ) { if ( self::is_post_global_node_template( $template_post_id ) ) { $posts = self::get_posts_with_global_node_template( $template_post_id ); $template_id = get_post_meta( $template_post_id, '_fl_builder_template_id', true ); foreach ( $posts as $post ) { self::delete_global_node_template_from_post( 'published', $post->ID, $template_id ); self::delete_global_node_template_from_post( 'draft', $post->ID, $template_id ); self::delete_all_asset_cache( $post->ID ); } } } /** * Deletes all instances of a global node template from a post's * layout data with the specified status. * * @since 1.6.3 * @param string $status The status of the layout data. Either draft or published. * @param int $post_id The ID of the post to delete from. * @param string $template_id The ID of the template to delete from the layout data. * @return void */ static public function delete_global_node_template_from_post( $status, $post_id, $template_id ) { $layout_data = self::get_layout_data( $status, $post_id ); $update = false; // Loop through the nodes. foreach ( $layout_data as $node_id => $node ) { $siblings = array(); $position = 0; // Check to see if this is the global template node to delete. if ( isset( $node->template_id ) && $node->template_id == $template_id ) { // Unset thr-swimmers-ear-product/">Sèch zòrèy - Zòrèy sèk ak AIR lis cho pou diminye ...