Noptin_Automation_Rules::create_rule( array $rule )

Creates a new rule.


Parameters Parameters

$rule

(array) (Required) The rule arguments.


Top ↑

Return Return

(bool|Noptin_Automation_Rule)


Top ↑

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 );

    }


Top ↑

Changelog Changelog

Changelog
VersionDescription
1.2.8Introduced.

Top ↑

User Contributed Notes User Contributed Notes

30 day money back guarantee
Safe & Secure online payment
Custom CSS Slide Example
Custom Animation Example
Default Animation