Noptin_Automation_Rules::update_rule( int|Noptin_Automation_Rule $rule, array $to_update )

Updates a rule.


Parameters Parameters

$rule

(int|Noptin_Automation_Rule) (Required) The rule to update

$to_update

(array) (Required) The new $arguments.


Top ↑

Return Return

(bool|Noptin_Automation_Rule)


Top ↑

Source Source

File: includes/automation-rules/class-noptin-automation-rules.php

    public function update_rule( $rule, $to_update ) {
        global $wpdb;

        $rule = new Noptin_Automation_Rule( $rule );

        // Does the rule exist?
        if ( ! $rule->exists() ) {
            return false;
        }

        // Our database fields with defaults set.
        $fields = array(
            'action_id'        => $rule->action_id,
            'action_settings'  => $rule->action_settings,
            'trigger_id'       => $rule->trigger_id,
            'trigger_settings' => $rule->trigger_settings,
            'status'           => $rule->status,
            'times_run'        => $rule->times_run,
            'created_at'       => $rule->created_at,
        );

        foreach ( array_keys( $fields ) as $key ) {
            
            if ( isset( $to_update[ $key ] ) ) {
                $fields[ $key ] = $to_update[ $key ];
                $fields[ $key ] = maybe_serialize( $fields[ $key ] );
            } else {
                unset( $fields[ $key ] );
            }

        }

        $fields['updated_at'] = current_time( 'mysql' );

        if ( ! $wpdb->update( $this->get_table(), $fields, array( 'id' => $rule->id ) ) ) {
            return false;
        }

        wp_cache_delete( $rule->id, 'noptin_automation_rules' );
        return new Noptin_Automation_Rule( $rule->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