| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * Generate notices in the WordPress admin |
||||
| 4 | * |
||||
| 5 | * @class Object_Sync_Sf_Admin_Notice |
||||
| 6 | * @package Object_Sync_Salesforce |
||||
| 7 | */ |
||||
| 8 | |||||
| 9 | defined( 'ABSPATH' ) || exit; |
||||
| 10 | |||||
| 11 | /** |
||||
| 12 | * Object_Sync_Sf_Admin_Notice class. |
||||
| 13 | */ |
||||
| 14 | class Object_Sync_Sf_Admin_Notice { |
||||
| 15 | |||||
| 16 | /** |
||||
| 17 | * The main plugin file |
||||
| 18 | * |
||||
| 19 | * @var string |
||||
| 20 | */ |
||||
| 21 | public $file; |
||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * The condition the notice is checking |
||||
| 25 | * |
||||
| 26 | * @var bool |
||||
| 27 | */ |
||||
| 28 | public $condition; |
||||
| 29 | |||||
| 30 | /** |
||||
| 31 | * The message that is being displayed |
||||
| 32 | * |
||||
| 33 | * @var string |
||||
| 34 | */ |
||||
| 35 | public $message; |
||||
| 36 | |||||
| 37 | /** |
||||
| 38 | * What type of notice it is |
||||
| 39 | * |
||||
| 40 | * @var string |
||||
| 41 | */ |
||||
| 42 | public $type; |
||||
| 43 | |||||
| 44 | /** |
||||
| 45 | * Whether the notice is dismisable or not |
||||
| 46 | * |
||||
| 47 | * @var bool |
||||
| 48 | */ |
||||
| 49 | public $dismissible; |
||||
| 50 | |||||
| 51 | /** |
||||
| 52 | * Which template is used for display |
||||
| 53 | * |
||||
| 54 | * @var string |
||||
| 55 | */ |
||||
| 56 | public $template; |
||||
| 57 | |||||
| 58 | /** |
||||
| 59 | * Constructor for admin notice class |
||||
| 60 | * |
||||
| 61 | * @param bool $condition whether the condition for the notice was met. |
||||
| 62 | * @param string $message the message to show to the user. |
||||
| 63 | * @param bool $dismissible whether the user can dismiss this message. |
||||
| 64 | * @param string $type what type of message this is. |
||||
| 65 | * @param string $template the template to render this message. |
||||
| 66 | */ |
||||
| 67 | public function __construct( $condition, $message, $dismissible, $type, $template ) { |
||||
| 68 | |||||
| 69 | $this->file = object_sync_for_salesforce()->file; |
||||
| 70 | |||||
| 71 | $this->condition = $condition; |
||||
| 72 | $this->message = $message; |
||||
| 73 | $this->dismissible = $dismissible; |
||||
| 74 | $this->type = $type; |
||||
| 75 | $this->template = $template; |
||||
| 76 | |||||
| 77 | add_action( 'admin_notices', array( $this, 'render' ) ); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 78 | |||||
| 79 | } |
||||
| 80 | |||||
| 81 | /** |
||||
| 82 | * Render an admin notice |
||||
| 83 | */ |
||||
| 84 | public function render() { |
||||
| 85 | |||||
| 86 | $default_template = plugin_dir_path( $this->file ) . '/templates/admin/notice.php'; |
||||
|
0 ignored issues
–
show
The function
plugin_dir_path was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 87 | |||||
| 88 | // class for the notice to use. |
||||
| 89 | $class = ''; |
||||
| 90 | if ( '' !== $this->type ) { |
||||
| 91 | $class = ' notice-' . $this->type; |
||||
| 92 | } |
||||
| 93 | |||||
| 94 | $dismissible = ''; |
||||
| 95 | if ( true === $this->dismissible ) { |
||||
| 96 | $dismissible = ' is-dismissible'; |
||||
| 97 | } |
||||
| 98 | |||||
| 99 | // template for notice has a default. |
||||
| 100 | if ( '' === $this->template || ! file_exists( $template ) ) { |
||||
| 101 | $template = $default_template; |
||||
| 102 | } else { |
||||
| 103 | $template = $this->template; |
||||
| 104 | } |
||||
| 105 | |||||
| 106 | $condition = $this->condition; |
||||
| 107 | $message = $this->message; |
||||
| 108 | |||||
| 109 | require_once $template; |
||||
| 110 | |||||
| 111 | } |
||||
| 112 | |||||
| 113 | } |
||||
| 114 |