• nkarkeine

    (@nkarkeine)


    Been using this plugin for many years now and I love it.

    Is there another field that triggers the actual expiration? I use Formidable Forms and it seems, that even the post look ok in wp admin the post does not expire. I have only updated the _expiration-date field with a date (unix format). If i manually save the post created throiugh a form, the expiration works…

Viewing 1 replies (of 1 total)
  • I was having a similar problem. I was creating a custom post type and setting the expiration date with Formidable Forms. When I went to the actual posts, I found that the expiration dates were being set correctly, and I even double checked them in the database. Everything looked exactly as it should, but the expiration wasn’t being scheduled, and there was no evidence of any such event in the debug logs. And if I manually saved the post, the expiration dates worked fine.

    So I went digging in the plugin’s files (post-expirator.php), and I found a function called _scheduleExpiratorEvent. In my own functions.php file, I required the post-expirator.php file, and then called the _scheduleExpiratorEvent function at the end of my function. It’s been working great so far.

    function formidable_set_expiration ( $entry_id, $form_id ) {
      if ( $form_id == 2 ) { 
        //require the plugin file to gain access to its functions
        require_once(ABSPATH . 'wp-content/plugins/post-expirator/post-expirator.php');
    
        // get the post info
        $entry = FrmEntry::getOne( $entry_id );
        $post = $entry->post_id;
    
        //Set the variables
        $now = new DateTime();
        $current_date = $now->getTimestamp();
        $end_date = $_POST['item_meta'][80];
        $end_time = $_POST['item_meta'][107] ?: "11:59 PM";
    
        $expires = $end_date . " " . $end_time;
        $gmt_end_date = get_gmt_from_date("$expires", 'U');
        $opts['expireType'] = "trash";
        $opts['id'] = $post;
    
        // Add expiration date
        update_post_meta( $post, '_expiration-date', $gmt_end_date );
        update_post_meta( $post, '_expiration-date-options', $opts );  
        update_post_meta( $post, '_expiration-date-status','saved' );
    
        // Revive trashed posts if updated date/time is valid
        if( get_post_status( $post ) == 'trash' && $current_date < intval($gmt_end_date)){
          wp_untrash_post( intval($post) );
        }
    
        // Call the plugin function
        _scheduleExpiratorEvent($post,$gmt_end_date,$opts);
      }
    }
    add_action('frm_after_create_entry', 'formidable_set_expiration', 30, 2);
    add_action('frm_after_update_entry', 'formidable_set_expiration', 10, 2);
Viewing 1 replies (of 1 total)
  • The topic ‘Formidabele Forms, do i need to update otehr field than _expiration-date to get’ is closed to new replies.