Exemplo n.º 1
0
 /**
  * Restore a Backup from the Layers Widget Revisions
  */
 public function restore_backup($post_id, $revision_id)
 {
     $post = get_post($post_id, OBJECT);
     if ('page' == $post->post_type && LAYERS_BUILDER_TEMPLATE !== get_post_meta($post_id, '_wp_page_template', true)) {
         return;
     }
     // Get the revision information
     $revision = get_post($revision_id, OBJECT);
     $layers_migrator = new Layers_Widget_Migrator();
     $widget_data = $revision->post_content_filtered;
     if (is_wp_error(unserialize($widget_data))) {
         return;
     }
     // Check for errors.
     if ('' == $widget_data || is_wp_error(unserialize($widget_data))) {
         return;
     }
     $widget_data_array = unserialize($widget_data);
     // Check if our data is empty.
     if (empty($widget_data_array)) {
         return;
     }
     $import = $layers_migrator->import(unserialize($widget_data), TRUE, TRUE);
     // Update widget order on the post
     $widget_order = get_metadata('post', $revision_id, '_layers_widget_order', true);
     $latest_revisions = wp_get_post_revisions($post_id, array('post_type' => 'page'));
     $latest_revision = reset($latest_revisions);
     if (false !== $widget_order) {
         add_metadata('post', $latest_revision->ID, '_layers_widget_order', $widget_order);
         update_post_meta($post_id, '_layers_widget_order', $widget_order);
     }
 }