/var/www/html_uk/wp-content/plugins/automatewoo/includes/Notifications/AbstractNotification.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php

namespace AutomateWoo\Notifications;

use 
Automattic\WooCommerce\Admin\Notes\Note;

defined'ABSPATH' ) || exit;

/**
 * Abstract class outlining requirements for AutomateWoo Notifications.
 *
 * @since 5.8.5
 *
 * @package AutomateWoo\Notifications
 */
abstract class AbstractNotification {

    
/**
     * When the notification should be processed. Options: instant, scheduled, activate_or_update
     *
     * @return string
     */
    
abstract public function notification_type(): string;

    
/**
     * Get the title of the notification.
     *
     * @return string
     */
    
abstract public static function get_title(): string;

    
/**
     * Get the contents of the notification.
     *
     * @return string
     */
    
abstract public static function get_content(): string;

    
/**
     * Check if the notification should be added.
     *
     * @return bool
     */
    
abstract public function should_be_added(): bool;

    
/**
     * Return Note object.
     *
     * @see Automattic\WooCommerce\Admin\Notes\Note
     *
     * @return Note
     */
    
public static function get_note(): Note {
        
$note = new Note();
        
$note->set_source'automatewoo' );
        
$note->set_name( static::NOTE_NAME );
        
$note->set_title( static::get_title() );
        
$note->set_content( static::get_content() );
        
$note->set_content_data( (object) array() );
        
$note->set_typeNote::E_WC_ADMIN_NOTE_WARNING );

        return 
$note;
    }

    
/**
     * Process this notification and add it if it should be added.
     *
     * @throws \Automattic\WooCommerce\Admin\Notes\NotesUnavailableException Throws exception when notes are unavailable.
     *
     * @return void
     */
    
public function process(): void {
        
// AbstractNotification relies on methods from \Automattic\WooCommerce\Admin\Notes\NoteTraits.
        // If the required trait methods aren't available in classes that extend AbstractNotification then abort.
        
if (
            ! 
is_callable( static::class . '::note_exists' ) ||
            ! 
is_callable( static::class . '::possibly_delete_note' ) ||
            ! 
is_callable( static::class . '::can_be_added' ) ) {
            return;
        }

        
$note = static::get_note();

        
// If the note shouldn't be added but exists then delete it.
        
if ( static::note_exists() && ! static::should_be_added() ) {
            
$this->delete_existing_note();
            return;
        }

        if ( ! static::
can_be_added() || ! static::should_be_added() ) {
            return;
        }

        
$note->save();
    }

    
/**
     * Wrapper for \Automattic\WooCommerce\Admin\Notes\NoteTraits::note_exists().
     *
     * @throws \Automattic\WooCommerce\Admin\Notes\NotesUnavailableException Throws exception when notes are unavailable.
     *
     * @return void
     */
    
public function delete_existing_note(): void {
        static::
possibly_delete_note();
    }

    
/**
     * Optional method which will run when AutomateWoo is deactivated
     */
    
public function deactivation() { }
}