public function postStatusChange($new_status, $old_status, $post)
 {
     // get all widgets linked to this post and mark them as not published
     $statuses = array("inherit", "publish");
     // we don't handle "inherit" status because it not the real post, but the revision
     // we don't handle "publish" status because it's handled in: "kaltura_publish_post"
     if (!in_array($new_status, $statuses)) {
         $widgets = Kaltura_WPModel::getWidgetsByPost($post->ID);
         Kaltura_WPModel::unpublishWidgets($widgets);
     }
 }
 public static function deleteUnusedWidgetsByPost($post_id, $used_widgets)
 {
     global $wpdb;
     $table = $wpdb->prefix . Kaltura_WPDB::WIDGET_TABLE;
     $wid_ids = array();
     $entry_ids = array();
     $current_widgets = Kaltura_WPModel::getWidgetsByPost($post_id);
     foreach ($current_widgets as $temp_widget) {
         $should_delete = true;
         foreach ($used_widgets as $wid_entry_id) {
             $wid = $wid_entry_id[0];
             $entry_id = $wid_entry_id[1];
             if ($temp_widget["id"] == $wid && $temp_widget["entry_id"] == $entry_id) {
                 $should_delete = false;
             }
         }
         if ($should_delete) {
             $query = $wpdb->prepare("DELETE FROM " . $table . " WHERE post_id = %d AND id = %s and entry_id = %s", $post_id, $temp_widget["id"], $temp_widget["entry_id"]);
             $wpdb->query($query);
         }
     }
 }