layers_backup_page_sidebars_widgets

The Layers layers backup page sidebars widgets function.

Description

layers_backup_page_sidebars_widgets( (constant) $page = NULL, (bool) $no_revisions = false ); 

Parameters (2)

0. $page — Optional. (constant) => NULL
The page.
1. $no_revisions — Optional. (bool) => false
The no revisions.

Usage

  1. if ( !function_exists( 'layers_backup_page_sidebars_widgets' ) ) { 
  2. require_once '/core/widgets/init.php'; 
  3.  
  4. // The page. 
  5. $page = NULL; 
  6.  
  7. // The no revisions. 
  8. $no_revisions = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = layers_backup_page_sidebars_widgets($page, $no_revisions); 
  12.  

Defined (1)

The function is defined in the following location(s).

/core/widgets/init.php  
  1. function layers_backup_page_sidebars_widgets( $page = NULL, $no_revisions = FALSE ) { 
  2.  
  3. // If the migrator class does not exist, then force load the migrator.php file 
  4. if( !class_exists( 'Layers_Widget_Migrator' ) ) { 
  5. require get_template_directory() . '/core/helpers/migrator.php'; 
  6.  
  7. // Prep the migrator 
  8. $migrator = new Layers_Widget_Migrator(); 
  9.  
  10. if( NULL == $page || !is_object( $page ) ) return; 
  11.  
  12. $raw_export_data = $migrator->export_data( $page ); 
  13.  
  14. $export_data = $migrator->page_widget_data( $page ); 
  15.  
  16. if( !empty( $export_data ) ) { 
  17.  
  18. // Create a hash key so that we can know if this page is unique or not 
  19. if( '' == get_post_meta( $page->ID, '_layers_hash', true ) ) { 
  20. $page_hash_key = 'layers_page_' . md5( $page->post_name . '-' . $page->ID ); 
  21. update_post_meta( $page->ID, '_layers_hash', $page_hash_key, false ); 
  22. } else { 
  23. $page_hash_key = get_post_meta( $page->ID, '_layers_hash', true ); 
  24.  
  25. // Save the raw widget data 
  26. $page_raw_widget_data = array( 
  27. 'post_id' => $page->ID,  
  28. 'post_hash' => $page_hash_key,  
  29. 'post_title' => esc_attr( $page->post_title ),  
  30. 'widget_data' => $raw_export_data 
  31. ); 
  32.  
  33. // Generate the post content 
  34. $post = (array) $page; 
  35. $post[ 'post_content_filtered' ] = serialize( $page_raw_widget_data ); 
  36. $post[ 'post_content' ] = layers_get_builder_page_content( $page->ID ); 
  37.  
  38. // Update the backup post & get the revision ID 
  39. $post_id = wp_update_post( $post ); 
  40. $revisions = wp_get_post_revisions( $page->ID, array( 'posts_per_page' => 1 ) ); 
  41. $latest_revision = reset( $revisions ); 
  42.  
  43. // Add widget order field 
  44. update_post_meta( $page->ID, '_layers_widget_order', $migrator->page_widgets_as_content( $export_data ), true ); 
  45. add_metadata( 'post', $latest_revision->ID, '_layers_widget_order', $migrator->page_widgets_as_content( $export_data ), true ); 
  46.  
  47. $return = array( 
  48. 'post_id' => $post_id,  
  49. 'revision_id' => $latest_revision->ID 
  50. ); 
  51.  
  52. return $return;