Noptin_Automation_Rules::create_rule( array $rule )
Creates a new rule.
Parameters Parameters
- $rule
(array) (Required) The rule arguments.
Return Return
(bool|Noptin_Automation_Rule)
Source Source
File: includes/automation-rules/class-noptin-automation-rules.php
public function create_rule( $rule ) { global $wpdb; // Ensure that we have an array. if ( ! is_array( $rule ) ) { $rule = array(); } // Our database fields with defaults set. $fields = array( 'action_id' => '', 'action_settings' => array(), 'trigger_id' => '', 'trigger_settings' => array(), 'status' => 1, // Active. 'times_run' => 0, 'created_at' => current_time( 'mysql' ), 'updated_at' => current_time( 'mysql' ), ); foreach ( array_keys( $fields ) as $key ) { if ( isset( $rule[ $key ] ) ) { $fields[ $key ] = $rule[ $key ]; } $fields[ $key ] = maybe_serialize( $fields[ $key ] ); } if ( ! $wpdb->insert( $this->get_table(), $fields, '%s' ) ) { log_noptin_message( $wpdb->last_query ); log_noptin_message( $wpdb->last_error ); return false; } return new Noptin_Automation_Rule( $wpdb->insert_id ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.2.8 | Introduced. |