Custom Fonts - Version 1.3.7

Version Description

  • Fix: Custom font's CSS not applying in responsive previews of WordPress block editor.
Download this release

Release Info

Developer brainstormworg
Plugin Icon 128x128 Custom Fonts
Version 1.3.7
Comparing to
See all releases

Code changes from version 1.3.6 to 1.3.7

assets/js/custom-fonts-preview.js ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.body.addEventListener('mousedown', function () {
2
+ let cust_font = document.getElementById('cst_font_data');
3
+ let cstfont = null !== cust_font ? cust_font.cloneNode(true) : null;
4
+
5
+ setTimeout( function() {
6
+
7
+ let tabletPreview = document.getElementsByClassName('is-tablet-preview');
8
+ let mobilePreview = document.getElementsByClassName('is-mobile-preview');
9
+
10
+ if (0 !== tabletPreview.length || 0 !== mobilePreview.length) {
11
+ let preview = tabletPreview[0] || mobilePreview[0];
12
+
13
+ let iframe = preview.getElementsByTagName('iframe')[0];
14
+ let iframeDocument = iframe.contentWindow.document || iframe.contentDocument;
15
+ iframeDocument.head.appendChild( cstfont );
16
+
17
+ }
18
+ }, 1000);
19
+
20
+ });
classes/class-bsf-custom-fonts-render.php CHANGED
@@ -228,6 +228,16 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Render' ) ) :
228
  if ( is_admin() && ! is_customize_preview() ) {
229
  add_action( 'enqueue_block_assets', array( $this, 'add_style' ) );
230
  }
 
 
 
 
 
 
 
 
 
 
231
  }
232
 
233
  /**
@@ -242,7 +252,7 @@ if ( ! class_exists( 'Bsf_Custom_Fonts_Render' ) ) :
242
  $this->render_font_css( $load_font_name );
243
  }
244
  ?>
245
- <style type="text/css">
246
  <?php echo wp_strip_all_tags( $this->font_css ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
247
  </style>
248
  <?php
228
  if ( is_admin() && ! is_customize_preview() ) {
229
  add_action( 'enqueue_block_assets', array( $this, 'add_style' ) );
230
  }
231
+ add_action( 'enqueue_block_editor_assets', array( $this, 'enque_data' ) );
232
+ }
233
+
234
+ /**
235
+ * Enqueue iFrame Preview Script.
236
+ *
237
+ * @since 1.3.7
238
+ */
239
+ public function enque_data() {
240
+ wp_enqueue_script( 'bsf-custom-block-js', BSF_CUSTOM_FONTS_URI . 'assets/js/custom-fonts-preview.js', array(), BSF_CUSTOM_FONTS_VER, true );
241
  }
242
 
243
  /**
252
  $this->render_font_css( $load_font_name );
253
  }
254
  ?>
255
+ <style type="text/css" id="cst_font_data">
256
  <?php echo wp_strip_all_tags( $this->font_css ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
257
  </style>
258
  <?php
custom-fonts.php CHANGED
@@ -6,7 +6,7 @@
6
  * Author: Brainstorm Force
7
  * Author URI: http://www.brainstormforce.com
8
  * Text Domain: custom-fonts
9
- * Version: 1.3.6
10
  *
11
  * @package Bsf_Custom_Fonts
12
  */
@@ -25,7 +25,7 @@ define( 'BSF_CUSTOM_FONTS_FILE', __FILE__ );
25
  define( 'BSF_CUSTOM_FONTS_BASE', plugin_basename( BSF_CUSTOM_FONTS_FILE ) );
26
  define( 'BSF_CUSTOM_FONTS_DIR', plugin_dir_path( BSF_CUSTOM_FONTS_FILE ) );
27
  define( 'BSF_CUSTOM_FONTS_URI', plugins_url( '/', BSF_CUSTOM_FONTS_FILE ) );
28
- define( 'BSF_CUSTOM_FONTS_VER', '1.3.6' );
29
 
30
  /**
31
  * BSF Custom Fonts
6
  * Author: Brainstorm Force
7
  * Author URI: http://www.brainstormforce.com
8
  * Text Domain: custom-fonts
9
+ * Version: 1.3.7
10
  *
11
  * @package Bsf_Custom_Fonts
12
  */
25
  define( 'BSF_CUSTOM_FONTS_BASE', plugin_basename( BSF_CUSTOM_FONTS_FILE ) );
26
  define( 'BSF_CUSTOM_FONTS_DIR', plugin_dir_path( BSF_CUSTOM_FONTS_FILE ) );
27
  define( 'BSF_CUSTOM_FONTS_URI', plugins_url( '/', BSF_CUSTOM_FONTS_FILE ) );
28
+ define( 'BSF_CUSTOM_FONTS_VER', '1.3.7' );
29
 
30
  /**
31
  * BSF Custom Fonts
languages/custom-fonts.pot CHANGED
@@ -1,14 +1,14 @@
1
- # Copyright (C) 2020 Brainstorm Force
2
  # This file is distributed under the same license as the Custom Fonts package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Custom Fonts 1.2.3\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/custom-fonts\n"
7
- "POT-Creation-Date: 2020-08-18 09:16:20+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
- "PO-Revision-Date: 2020-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
  "Language: en\n"
@@ -65,11 +65,11 @@ msgstr ""
65
  msgid "Learn More."
66
  msgstr ""
67
 
68
- #: classes/class-bsf-custom-fonts-render.php:106
69
  msgid "Custom"
70
  msgstr ""
71
 
72
- #: classes/class-bsf-custom-fonts-render.php:298
73
  #. translators: 1: Astra theme from wordpress.org
74
  msgid "Custom Fonts Plugin requires minimum 1.0.16 version of the Astra Theme."
75
  msgstr ""
@@ -78,82 +78,147 @@ msgstr ""
78
  msgid "Custom Fonts"
79
  msgstr ""
80
 
81
- #: includes/class-bsf-custom-fonts-admin.php:107
82
  msgid "The name of the font as it appears in the customizer options."
83
  msgstr ""
84
 
85
- #: includes/class-bsf-custom-fonts-admin.php:141
86
- #: includes/class-bsf-custom-fonts-admin.php:170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  msgid "Font .woff2"
88
  msgstr ""
89
 
90
- #: includes/class-bsf-custom-fonts-admin.php:141
91
- #: includes/class-bsf-custom-fonts-admin.php:170
92
  msgid "Upload the font's woff2 file or enter the URL."
93
  msgstr ""
94
 
95
- #: includes/class-bsf-custom-fonts-admin.php:142
96
- #: includes/class-bsf-custom-fonts-admin.php:171
97
  msgid "Font .woff"
98
  msgstr ""
99
 
100
- #: includes/class-bsf-custom-fonts-admin.php:142
101
- #: includes/class-bsf-custom-fonts-admin.php:171
102
  msgid "Upload the font's woff file or enter the URL."
103
  msgstr ""
104
 
105
- #: includes/class-bsf-custom-fonts-admin.php:143
106
- #: includes/class-bsf-custom-fonts-admin.php:172
107
  msgid "Font .ttf"
108
  msgstr ""
109
 
110
- #: includes/class-bsf-custom-fonts-admin.php:143
111
- #: includes/class-bsf-custom-fonts-admin.php:172
112
  msgid "Upload the font's ttf file or enter the URL."
113
  msgstr ""
114
 
115
- #: includes/class-bsf-custom-fonts-admin.php:144
116
- #: includes/class-bsf-custom-fonts-admin.php:173
117
  msgid "Font .eot"
118
  msgstr ""
119
 
120
- #: includes/class-bsf-custom-fonts-admin.php:144
121
- #: includes/class-bsf-custom-fonts-admin.php:173
122
  msgid "Upload the font's eot file or enter the URL."
123
  msgstr ""
124
 
125
- #: includes/class-bsf-custom-fonts-admin.php:145
126
- #: includes/class-bsf-custom-fonts-admin.php:174
127
  msgid "Font .svg"
128
  msgstr ""
129
 
130
- #: includes/class-bsf-custom-fonts-admin.php:145
131
- #: includes/class-bsf-custom-fonts-admin.php:174
132
  msgid "Upload the font's svg file or enter the URL."
133
  msgstr ""
134
 
135
- #: includes/class-bsf-custom-fonts-admin.php:146
136
- #: includes/class-bsf-custom-fonts-admin.php:175
137
  msgid "Font .otf"
138
  msgstr ""
139
 
140
- #: includes/class-bsf-custom-fonts-admin.php:146
141
- #: includes/class-bsf-custom-fonts-admin.php:175
142
  msgid "Upload the font's otf file or enter the URL."
143
  msgstr ""
144
 
145
- #: includes/class-bsf-custom-fonts-admin.php:150
146
- #: includes/class-bsf-custom-fonts-admin.php:179
147
- msgid "Font Display"
148
- msgstr ""
149
-
150
- #: includes/class-bsf-custom-fonts-admin.php:151
151
- #: includes/class-bsf-custom-fonts-admin.php:181
152
- msgid "Select font-display property for this font"
153
- msgstr ""
154
-
155
- #: includes/class-bsf-custom-fonts-admin.php:207
156
- #: includes/class-bsf-custom-fonts-admin.php:288
157
  msgid "Upload"
158
  msgstr ""
159
 
@@ -197,6 +262,10 @@ msgstr ""
197
  msgid "No fonts found"
198
  msgstr ""
199
 
 
 
 
 
200
  #: includes/white-label.php:18 includes/white-label.php:23
201
  msgid "Custom Fonts Branding"
202
  msgstr ""
@@ -209,7 +278,7 @@ msgstr ""
209
  msgid "Plugin Description:"
210
  msgstr ""
211
 
212
- #: lib/notices/class-astra-notices.php:125
213
  msgid "WordPress Nonce not validated."
214
  msgstr ""
215
 
1
+ # Copyright (C) 2022 Brainstorm Force
2
  # This file is distributed under the same license as the Custom Fonts package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Custom Fonts 1.3.7\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/custom-fonts\n"
7
+ "POT-Creation-Date: 2022-08-19 10:52:21+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2022-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
  "Language: en\n"
65
  msgid "Learn More."
66
  msgstr ""
67
 
68
+ #: classes/class-bsf-custom-fonts-render.php:149
69
  msgid "Custom"
70
  msgstr ""
71
 
72
+ #: classes/class-bsf-custom-fonts-render.php:459
73
  #. translators: 1: Astra theme from wordpress.org
74
  msgid "Custom Fonts Plugin requires minimum 1.0.16 version of the Astra Theme."
75
  msgstr ""
78
  msgid "Custom Fonts"
79
  msgstr ""
80
 
81
+ #: includes/class-bsf-custom-fonts-admin.php:117
82
  msgid "The name of the font as it appears in the customizer options."
83
  msgstr ""
84
 
85
+ #: includes/class-bsf-custom-fonts-admin.php:191
86
+ #: includes/class-bsf-custom-fonts-admin.php:279
87
+ msgid "Font Fallback"
88
+ msgstr ""
89
+
90
+ #: includes/class-bsf-custom-fonts-admin.php:191
91
+ #: includes/class-bsf-custom-fonts-admin.php:279
92
+ msgid "Add the font's fallback names with comma(,) separator. eg. Arial, Serif"
93
+ msgstr ""
94
+
95
+ #: includes/class-bsf-custom-fonts-admin.php:195
96
+ #: includes/class-bsf-custom-fonts-admin.php:283
97
+ msgid "Font Display"
98
+ msgstr ""
99
+
100
+ #: includes/class-bsf-custom-fonts-admin.php:196
101
+ #: includes/class-bsf-custom-fonts-admin.php:284
102
+ msgid "Select font-display property for this font"
103
+ msgstr ""
104
+
105
+ #: includes/class-bsf-custom-fonts-admin.php:215
106
+ #: includes/class-bsf-custom-fonts-admin.php:314
107
+ msgid "Font weight"
108
+ msgstr ""
109
+
110
+ #: includes/class-bsf-custom-fonts-admin.php:216
111
+ #: includes/class-bsf-custom-fonts-admin.php:315
112
+ msgid "Select font-weight property for this font"
113
+ msgstr ""
114
+
115
+ #: includes/class-bsf-custom-fonts-admin.php:218
116
+ #: includes/class-bsf-custom-fonts-admin.php:317
117
+ msgid "Thin 100"
118
+ msgstr ""
119
+
120
+ #: includes/class-bsf-custom-fonts-admin.php:219
121
+ #: includes/class-bsf-custom-fonts-admin.php:318
122
+ msgid "Extra-Light 200"
123
+ msgstr ""
124
+
125
+ #: includes/class-bsf-custom-fonts-admin.php:220
126
+ #: includes/class-bsf-custom-fonts-admin.php:319
127
+ msgid "Light 300"
128
+ msgstr ""
129
+
130
+ #: includes/class-bsf-custom-fonts-admin.php:221
131
+ #: includes/class-bsf-custom-fonts-admin.php:320
132
+ msgid "Normal 400"
133
+ msgstr ""
134
+
135
+ #: includes/class-bsf-custom-fonts-admin.php:222
136
+ #: includes/class-bsf-custom-fonts-admin.php:321
137
+ msgid "Medium 500"
138
+ msgstr ""
139
+
140
+ #: includes/class-bsf-custom-fonts-admin.php:223
141
+ #: includes/class-bsf-custom-fonts-admin.php:322
142
+ msgid "Semi-Bold 600"
143
+ msgstr ""
144
+
145
+ #: includes/class-bsf-custom-fonts-admin.php:224
146
+ #: includes/class-bsf-custom-fonts-admin.php:323
147
+ msgid "Bold 700"
148
+ msgstr ""
149
+
150
+ #: includes/class-bsf-custom-fonts-admin.php:225
151
+ #: includes/class-bsf-custom-fonts-admin.php:324
152
+ msgid "Extra-Bold 800"
153
+ msgstr ""
154
+
155
+ #: includes/class-bsf-custom-fonts-admin.php:226
156
+ #: includes/class-bsf-custom-fonts-admin.php:325
157
+ msgid "Ultra-Bold 900"
158
+ msgstr ""
159
+
160
+ #: includes/class-bsf-custom-fonts-admin.php:229
161
+ #: includes/class-bsf-custom-fonts-admin.php:332
162
  msgid "Font .woff2"
163
  msgstr ""
164
 
165
+ #: includes/class-bsf-custom-fonts-admin.php:229
166
+ #: includes/class-bsf-custom-fonts-admin.php:332
167
  msgid "Upload the font's woff2 file or enter the URL."
168
  msgstr ""
169
 
170
+ #: includes/class-bsf-custom-fonts-admin.php:230
171
+ #: includes/class-bsf-custom-fonts-admin.php:334
172
  msgid "Font .woff"
173
  msgstr ""
174
 
175
+ #: includes/class-bsf-custom-fonts-admin.php:230
176
+ #: includes/class-bsf-custom-fonts-admin.php:334
177
  msgid "Upload the font's woff file or enter the URL."
178
  msgstr ""
179
 
180
+ #: includes/class-bsf-custom-fonts-admin.php:231
181
+ #: includes/class-bsf-custom-fonts-admin.php:336
182
  msgid "Font .ttf"
183
  msgstr ""
184
 
185
+ #: includes/class-bsf-custom-fonts-admin.php:231
186
+ #: includes/class-bsf-custom-fonts-admin.php:336
187
  msgid "Upload the font's ttf file or enter the URL."
188
  msgstr ""
189
 
190
+ #: includes/class-bsf-custom-fonts-admin.php:232
191
+ #: includes/class-bsf-custom-fonts-admin.php:338
192
  msgid "Font .eot"
193
  msgstr ""
194
 
195
+ #: includes/class-bsf-custom-fonts-admin.php:232
196
+ #: includes/class-bsf-custom-fonts-admin.php:338
197
  msgid "Upload the font's eot file or enter the URL."
198
  msgstr ""
199
 
200
+ #: includes/class-bsf-custom-fonts-admin.php:233
201
+ #: includes/class-bsf-custom-fonts-admin.php:340
202
  msgid "Font .svg"
203
  msgstr ""
204
 
205
+ #: includes/class-bsf-custom-fonts-admin.php:233
206
+ #: includes/class-bsf-custom-fonts-admin.php:340
207
  msgid "Upload the font's svg file or enter the URL."
208
  msgstr ""
209
 
210
+ #: includes/class-bsf-custom-fonts-admin.php:234
211
+ #: includes/class-bsf-custom-fonts-admin.php:342
212
  msgid "Font .otf"
213
  msgstr ""
214
 
215
+ #: includes/class-bsf-custom-fonts-admin.php:234
216
+ #: includes/class-bsf-custom-fonts-admin.php:342
217
  msgid "Upload the font's otf file or enter the URL."
218
  msgstr ""
219
 
220
+ #: includes/class-bsf-custom-fonts-admin.php:396
221
+ #: includes/class-bsf-custom-fonts-admin.php:556
 
 
 
 
 
 
 
 
 
 
222
  msgid "Upload"
223
  msgstr ""
224
 
262
  msgid "No fonts found"
263
  msgstr ""
264
 
265
+ #: includes/class-bsf-custom-fonts-taxonomy.php:95
266
+ msgid "← Go to Fonts"
267
+ msgstr ""
268
+
269
  #: includes/white-label.php:18 includes/white-label.php:23
270
  msgid "Custom Fonts Branding"
271
  msgstr ""
278
  msgid "Plugin Description:"
279
  msgstr ""
280
 
281
+ #: lib/notices/class-astra-notices.php:119
282
  msgid "WordPress Nonce not validated."
283
  msgstr ""
284
 
lib/notices/class-astra-notices.php CHANGED
@@ -1,18 +1,11 @@
1
  <?php
2
  /**
3
- * Astra Sites Notices
4
  *
5
- * Closing notice on click on `astra-notice-close` class.
6
  *
7
- * If notice has the data attribute `data-repeat-notice-after="%2$s"` then notice close for that SPECIFIC TIME.
8
- * If notice has NO data attribute `data-repeat-notice-after="%2$s"` then notice close for the CURRENT USER FOREVER.
9
- *
10
- * > Create custom close notice link in the notice markup. E.g.
11
- * `<a href="#" data-repeat-notice-after="<?php echo MONTH_IN_SECONDS; ?>" class="astra-notice-close">`
12
- * It close the notice for 30 days.
13
- *
14
- * @package Astra Sites
15
- * @since 1.2.2
16
  */
17
 
18
  if ( ! defined( 'ABSPATH' ) ) {
@@ -24,7 +17,7 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
24
  /**
25
  * Astra_Notices
26
  *
27
- * @since 1.2.2
28
  */
29
  class Astra_Notices {
30
 
@@ -33,16 +26,16 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
33
  *
34
  * @access private
35
  * @var array Notices.
36
- * @since 1.2.2
37
  */
38
- private static $version = '1.1.5';
39
 
40
  /**
41
  * Notices
42
  *
43
  * @access private
44
  * @var array Notices.
45
- * @since 1.2.2
46
  */
47
  private static $notices = array();
48
 
@@ -51,14 +44,14 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
51
  *
52
  * @access private
53
  * @var object Class object.
54
- * @since 1.2.2
55
  */
56
  private static $instance;
57
 
58
  /**
59
  * Initiator
60
  *
61
- * @since 1.2.2
62
  * @return object initialized object of class.
63
  */
64
  public static function get_instance() {
@@ -71,7 +64,7 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
71
  /**
72
  * Constructor
73
  *
74
- * @since 1.2.2
75
  */
76
  public function __construct() {
77
  add_action( 'admin_notices', array( $this, 'show_notices' ), 30 );
@@ -83,10 +76,10 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
83
  /**
84
  * Filters and Returns a list of allowed tags and attributes for a given context.
85
  *
86
- * @param Array $allowedposttags Array of allowed tags.
87
- * @param String $context Context type (explicit).
88
- * @since 1.2.2
89
- * @return Array
90
  */
91
  public function add_data_attributes( $allowedposttags, $context ) {
92
  $allowedposttags['a']['data-repeat-notice-after'] = true;
@@ -97,7 +90,7 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
97
  /**
98
  * Add Notice.
99
  *
100
- * @since 1.2.2
101
  * @param array $args Notice arguments.
102
  * @return void
103
  */
@@ -108,18 +101,19 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
108
  /**
109
  * Dismiss Notice.
110
  *
111
- * @since 1.2.2
112
  * @return void
113
  */
114
  public function dismiss_notice() {
115
-
116
- if ( ! apply_filters( 'astra_notices_user_cap_check', current_user_can( 'manage_options' ) ) ) {
117
- return;
118
- }
119
-
120
  $notice_id = ( isset( $_POST['notice_id'] ) ) ? sanitize_key( $_POST['notice_id'] ) : '';
121
  $repeat_notice_after = ( isset( $_POST['repeat_notice_after'] ) ) ? absint( $_POST['repeat_notice_after'] ) : '';
122
  $nonce = ( isset( $_POST['nonce'] ) ) ? sanitize_key( $_POST['nonce'] ) : '';
 
 
 
 
 
 
123
 
124
  if ( false === wp_verify_nonce( $nonce, 'astra-notices' ) ) {
125
  wp_send_json_error( esc_html_e( 'WordPress Nonce not validated.', 'custom-fonts' ) );
@@ -143,11 +137,12 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
143
  /**
144
  * Enqueue Scripts.
145
  *
146
- * @since 1.2.2
147
  * @return void
148
  */
149
  public function enqueue_scripts() {
150
- wp_register_script( 'astra-notices', self::_get_uri() . 'notices.js', array( 'jquery' ), self::$version, true );
 
151
  wp_localize_script(
152
  'astra-notices',
153
  'astraNotices',
@@ -158,32 +153,67 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
158
  }
159
 
160
  /**
161
- * Rating priority sort
 
162
  *
163
  * @since 1.5.2
164
- * @param array $array1 array one.
165
- * @param array $array2 array two.
166
  * @return array
167
  */
168
- public function sort_notices( $array1, $array2 ) {
169
- if ( ! isset( $array1['priority'] ) ) {
170
- $array1['priority'] = 10;
171
  }
172
- if ( ! isset( $array2['priority'] ) ) {
173
- $array2['priority'] = 10;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  }
175
 
176
- return $array1['priority'] - $array2['priority'];
 
 
 
 
 
 
 
 
177
  }
178
 
179
  /**
180
- * Notice Types
181
  *
182
- * @since 1.2.2
183
  * @return void
184
  */
185
  public function show_notices() {
186
-
187
  $defaults = array(
188
  'id' => '', // Optional, Notice ID. If empty it set `astra-notices-id-<$array-index>`.
189
  'type' => 'info', // Optional, Notice type. Default `info`. Expected [info, warning, notice, error].
@@ -195,20 +225,22 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
195
  'priority' => 10, // Priority of the notice.
196
  'display-with-other-notices' => true, // Should the notice be displayed if other notices are being displayed from Astra_Notices.
197
  'is_dismissible' => true,
 
198
  );
199
 
200
  // Count for the notices that are rendered.
201
  $notices_displayed = 0;
 
202
 
203
- // sort the array with priority.
204
- usort( self::$notices, array( $this, 'sort_notices' ) );
205
-
206
- foreach ( self::$notices as $key => $notice ) {
207
-
208
  $notice = wp_parse_args( $notice, $defaults );
209
 
210
- $notice['id'] = self::get_notice_id( $notice, $key );
 
 
 
211
 
 
212
  $notice['classes'] = self::get_wrap_classes( $notice );
213
 
214
  // Notices visible after transient expire.
@@ -230,23 +262,23 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
230
  }
231
 
232
  /**
233
- * Markup Notice.
234
  *
235
- * @since 1.2.2
236
  * @param array $notice Notice markup.
237
  * @return void
238
  */
239
  public static function markup( $notice = array() ) {
240
-
241
  wp_enqueue_script( 'astra-notices' );
 
242
 
243
  do_action( 'astra_notice_before_markup' );
244
 
245
  do_action( "astra_notice_before_markup_{$notice['id']}" );
246
 
247
  ?>
248
- <div id="<?php echo esc_attr( $notice['id'] ); ?>" class="<?php echo esc_attr( $notice['classes'] ); ?>" data-repeat-notice-after="<?php echo esc_attr( $notice['repeat-notice-after'] ); ?>">
249
- <div class="notice-container">
250
  <?php do_action( "astra_notice_inside_markup_{$notice['id']}" ); ?>
251
  <?php echo wp_kses_post( $notice['message'] ); ?>
252
  </div>
@@ -256,13 +288,12 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
256
  do_action( "astra_notice_after_markup_{$notice['id']}" );
257
 
258
  do_action( 'astra_notice_after_markup' );
259
-
260
  }
261
 
262
  /**
263
- * Notice classes.
264
  *
265
- * @since 1.2.2
266
  *
267
  * @param array $notice Notice arguments.
268
  * @return array Notice wrapper classes.
@@ -283,13 +314,13 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
283
  }
284
 
285
  /**
286
- * Get Notice ID.
287
  *
288
- * @since 1.2.2
289
  *
290
  * @param array $notice Notice arguments.
291
- * @param int $key Notice array index.
292
- * @return string Notice id.
293
  */
294
  private static function get_notice_id( $notice, $key ) {
295
  if ( isset( $notice['id'] ) && ! empty( $notice['id'] ) ) {
@@ -300,9 +331,9 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
300
  }
301
 
302
  /**
303
- * Is notice expired?
304
  *
305
- * @since 1.2.2
306
  *
307
  * @param array $notice Notice arguments.
308
  * @return boolean
@@ -335,24 +366,19 @@ if ( ! class_exists( 'Astra_Notices' ) ) :
335
  }
336
 
337
  /**
338
- * Get URI
339
  *
340
  * @return mixed URL.
341
  */
342
- public static function _get_uri() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
343
- $path = wp_normalize_path( dirname( __FILE__ ) );
344
- $theme_dir = wp_normalize_path( get_template_directory() );
345
- $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
346
 
347
  if ( strpos( $path, $theme_dir ) !== false ) {
348
  return trailingslashit( get_template_directory_uri() . str_replace( $theme_dir, '', $path ) );
349
- } elseif ( strpos( $path, $plugin_dir ) !== false ) {
350
- return plugin_dir_url( __FILE__ );
351
- } elseif ( strpos( $path, dirname( plugin_basename( __FILE__ ) ) ) !== false ) {
352
  return plugin_dir_url( __FILE__ );
353
  }
354
-
355
- return; // phpcs:ignore Squiz.PHP.NonExecutableCode.ReturnNotRequired
356
  }
357
 
358
  }
1
  <?php
2
  /**
3
+ * Astra Notices
4
  *
5
+ * An easy to use PHP Library to add dismissible admin notices in the WordPress admin.
6
  *
7
+ * @package Astra Notices
8
+ * @since 1.0.0
 
 
 
 
 
 
 
9
  */
10
 
11
  if ( ! defined( 'ABSPATH' ) ) {
17
  /**
18
  * Astra_Notices
19
  *
20
+ * @since 1.0.0
21
  */
22
  class Astra_Notices {
23
 
26
  *
27
  * @access private
28
  * @var array Notices.
29
+ * @since 1.0.0
30
  */
31
+ private static $version = '1.1.11';
32
 
33
  /**
34
  * Notices
35
  *
36
  * @access private
37
  * @var array Notices.
38
+ * @since 1.0.0
39
  */
40
  private static $notices = array();
41
 
44
  *
45
  * @access private
46
  * @var object Class object.
47
+ * @since 1.0.0
48
  */
49
  private static $instance;
50
 
51
  /**
52
  * Initiator
53
  *
54
+ * @since 1.0.0
55
  * @return object initialized object of class.
56
  */
57
  public static function get_instance() {
64
  /**
65
  * Constructor
66
  *
67
+ * @since 1.0.0
68
  */
69
  public function __construct() {
70
  add_action( 'admin_notices', array( $this, 'show_notices' ), 30 );
76
  /**
77
  * Filters and Returns a list of allowed tags and attributes for a given context.
78
  *
79
+ * @param array $allowedposttags array of allowed tags.
80
+ * @param string $context Context type (explicit).
81
+ * @since 1.0.0
82
+ * @return array
83
  */
84
  public function add_data_attributes( $allowedposttags, $context ) {
85
  $allowedposttags['a']['data-repeat-notice-after'] = true;
90
  /**
91
  * Add Notice.
92
  *
93
+ * @since 1.0.0
94
  * @param array $args Notice arguments.
95
  * @return void
96
  */
101
  /**
102
  * Dismiss Notice.
103
  *
104
+ * @since 1.0.0
105
  * @return void
106
  */
107
  public function dismiss_notice() {
 
 
 
 
 
108
  $notice_id = ( isset( $_POST['notice_id'] ) ) ? sanitize_key( $_POST['notice_id'] ) : '';
109
  $repeat_notice_after = ( isset( $_POST['repeat_notice_after'] ) ) ? absint( $_POST['repeat_notice_after'] ) : '';
110
  $nonce = ( isset( $_POST['nonce'] ) ) ? sanitize_key( $_POST['nonce'] ) : '';
111
+ $notice = $this->get_notice_by_id( $notice_id );
112
+ $capability = isset( $notice['capability'] ) ? $notice['capability'] : 'manage_options';
113
+
114
+ if ( ! apply_filters( 'astra_notices_user_cap_check', current_user_can( $capability ) ) ) {
115
+ return;
116
+ }
117
 
118
  if ( false === wp_verify_nonce( $nonce, 'astra-notices' ) ) {
119
  wp_send_json_error( esc_html_e( 'WordPress Nonce not validated.', 'custom-fonts' ) );
137
  /**
138
  * Enqueue Scripts.
139
  *
140
+ * @since 1.0.0
141
  * @return void
142
  */
143
  public function enqueue_scripts() {
144
+ wp_register_style( 'astra-notices', self::get_url() . 'notices.css', array(), self::$version );
145
+ wp_register_script( 'astra-notices', self::get_url() . 'notices.js', array( 'jquery' ), self::$version, true );
146
  wp_localize_script(
147
  'astra-notices',
148
  'astraNotices',
153
  }
154
 
155
  /**
156
+ * Sort the notices based on the given priority of the notice.
157
+ * This function is called from usort()
158
  *
159
  * @since 1.5.2
160
+ * @param array $notice_1 First notice.
161
+ * @param array $notice_2 Second Notice.
162
  * @return array
163
  */
164
+ public function sort_notices( $notice_1, $notice_2 ) {
165
+ if ( ! isset( $notice_1['priority'] ) ) {
166
+ $notice_1['priority'] = 10;
167
  }
168
+ if ( ! isset( $notice_2['priority'] ) ) {
169
+ $notice_2['priority'] = 10;
170
+ }
171
+
172
+ return $notice_1['priority'] - $notice_2['priority'];
173
+ }
174
+
175
+ /**
176
+ * Get all registered notices.
177
+ * Since v1.1.8 it is recommended to register the notices on
178
+ *
179
+ * @return array|null
180
+ */
181
+ private function get_notices() {
182
+ usort( self::$notices, array( $this, 'sort_notices' ) );
183
+
184
+ return self::$notices;
185
+ }
186
+
187
+ /**
188
+ * Get notice by notice_id
189
+ *
190
+ * @param string $notice_id Notice id.
191
+ *
192
+ * @return array notice based on the notice id.
193
+ */
194
+ private function get_notice_by_id( $notice_id ) {
195
+ if ( empty( $notice_id ) ) {
196
+ return array();
197
  }
198
 
199
+ $notices = $this->get_notices();
200
+ $notice = wp_list_filter(
201
+ $notices,
202
+ array(
203
+ 'id' => $notice_id,
204
+ )
205
+ );
206
+
207
+ return ! empty( $notice ) ? $notice[0] : array();
208
  }
209
 
210
  /**
211
+ * Display the notices in the WordPress admin.
212
  *
213
+ * @since 1.0.0
214
  * @return void
215
  */
216
  public function show_notices() {
 
217
  $defaults = array(
218
  'id' => '', // Optional, Notice ID. If empty it set `astra-notices-id-<$array-index>`.
219
  'type' => 'info', // Optional, Notice type. Default `info`. Expected [info, warning, notice, error].
225
  'priority' => 10, // Priority of the notice.
226
  'display-with-other-notices' => true, // Should the notice be displayed if other notices are being displayed from Astra_Notices.
227
  'is_dismissible' => true,
228
+ 'capability' => 'manage_options', // User capability - This capability is required for the current user to see this notice.
229
  );
230
 
231
  // Count for the notices that are rendered.
232
  $notices_displayed = 0;
233
+ $notices = $this->get_notices();
234
 
235
+ foreach ( $notices as $key => $notice ) {
 
 
 
 
236
  $notice = wp_parse_args( $notice, $defaults );
237
 
238
+ // Show notices only for users with `manage_options` cap.
239
+ if ( ! current_user_can( $notice['capability'] ) ) {
240
+ continue;
241
+ }
242
 
243
+ $notice['id'] = self::get_notice_id( $notice, $key );
244
  $notice['classes'] = self::get_wrap_classes( $notice );
245
 
246
  // Notices visible after transient expire.
262
  }
263
 
264
  /**
265
+ * Render a notice.
266
  *
267
+ * @since 1.0.0
268
  * @param array $notice Notice markup.
269
  * @return void
270
  */
271
  public static function markup( $notice = array() ) {
 
272
  wp_enqueue_script( 'astra-notices' );
273
+ wp_enqueue_style( 'astra-notices' );
274
 
275
  do_action( 'astra_notice_before_markup' );
276
 
277
  do_action( "astra_notice_before_markup_{$notice['id']}" );
278
 
279
  ?>
280
+ <div id="<?php echo esc_attr( $notice['id'] ); ?>" class="<?php echo 'astra-notice-wrapper ' . esc_attr( $notice['classes'] ); ?>" data-repeat-notice-after="<?php echo esc_attr( $notice['repeat-notice-after'] ); ?>">
281
+ <div class="astra-notice-container">
282
  <?php do_action( "astra_notice_inside_markup_{$notice['id']}" ); ?>
283
  <?php echo wp_kses_post( $notice['message'] ); ?>
284
  </div>
288
  do_action( "astra_notice_after_markup_{$notice['id']}" );
289
 
290
  do_action( 'astra_notice_after_markup' );
 
291
  }
292
 
293
  /**
294
+ * Get wrapper classes for a notice.
295
  *
296
+ * @since 1.0.0
297
  *
298
  * @param array $notice Notice arguments.
299
  * @return array Notice wrapper classes.
314
  }
315
 
316
  /**
317
+ * Get HTML ID for a given notice.
318
  *
319
+ * @since 1.0.0
320
  *
321
  * @param array $notice Notice arguments.
322
+ * @param int $key Notice array index.
323
+ * @return string HTML if for the notice.
324
  */
325
  private static function get_notice_id( $notice, $key ) {
326
  if ( isset( $notice['id'] ) && ! empty( $notice['id'] ) ) {
331
  }
332
 
333
  /**
334
+ * Check if the notice is expires.
335
  *
336
+ * @since 1.0.0
337
  *
338
  * @param array $notice Notice arguments.
339
  * @return boolean
366
  }
367
 
368
  /**
369
+ * Get base URL for the astra-notices.
370
  *
371
  * @return mixed URL.
372
  */
373
+ public static function get_url() {
374
+ $path = wp_normalize_path( dirname( __FILE__ ) );
375
+ $theme_dir = wp_normalize_path( get_template_directory() );
 
376
 
377
  if ( strpos( $path, $theme_dir ) !== false ) {
378
  return trailingslashit( get_template_directory_uri() . str_replace( $theme_dir, '', $path ) );
379
+ } else {
 
 
380
  return plugin_dir_url( __FILE__ );
381
  }
 
 
382
  }
383
 
384
  }
lib/notices/notices.css ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .astra-review-notice-container {
2
+ display: flex;
3
+ align-items: center;
4
+ padding-top: 10px;
5
+ }
6
+
7
+ .astra-review-notice-container .dashicons {
8
+ font-size: 1.4em;
9
+ padding-left: 10px;
10
+ }
11
+
12
+ .astra-review-notice-container a {
13
+ padding-left: 5px;
14
+ text-decoration: none;
15
+ }
16
+
17
+ .astra-review-notice-container .dashicons:first-child {
18
+ padding-left: 0;
19
+ }
20
+
21
+ .astra-notice-container .notice-image img {
22
+ max-width: 90px;
23
+ }
24
+
25
+ .astra-notice-container .notice-content .notice-heading {
26
+ padding-bottom: 5px;
27
+ }
28
+
29
+ .astra-notice-container .notice-content {
30
+ margin-left: 15px;
31
+ }
32
+
33
+ .astra-notice-container {
34
+ padding-top: 10px;
35
+ padding-bottom: 10px;
36
+ display: flex;
37
+ justify-content: left;
38
+ align-items: center;
39
+ }
lib/notices/notices.js CHANGED
@@ -9,7 +9,7 @@
9
  /**
10
  * Helper class for the main Customizer interface.
11
  *
12
- * @since 1.2.2
13
  * @class ASTCustomizer
14
  */
15
  AstraNotices = {
@@ -17,7 +17,7 @@
17
  /**
18
  * Initializes our custom logic for the Customizer.
19
  *
20
- * @since 1.2.2
21
  * @method init
22
  */
23
  init: function()
@@ -28,7 +28,7 @@
28
  /**
29
  * Binds events for the Astra Portfolio.
30
  *
31
- * @since 1.2.2
32
  * @access private
33
  * @method _bind
34
  */
9
  /**
10
  * Helper class for the main Customizer interface.
11
  *
12
+ * @since 1.0.0
13
  * @class ASTCustomizer
14
  */
15
  AstraNotices = {
17
  /**
18
  * Initializes our custom logic for the Customizer.
19
  *
20
+ * @since 1.0.0
21
  * @method init
22
  */
23
  init: function()
28
  /**
29
  * Binds events for the Astra Portfolio.
30
  *
31
+ * @since 1.0.0
32
  * @access private
33
  * @method _bind
34
  */
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: brainstormforce
3
  Donate link: https://www.paypal.me/BrainstormForce
4
  Tags: Beaver Builder, Elementor, Astra, woff2, woff, ttf, svg, eot, otf, Custom Fonts, Font, Typography
5
  Requires at least: 4.4
6
- Tested up to: 6.0.1
7
- Stable tag: 1.3.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -42,6 +42,9 @@ If you're not using any of the supported plugins and theme, you can write the cu
42
 
43
 
44
  == Changelog ==
 
 
 
45
  = 1.3.6 =
46
  - Improvement: Compatibility with Spectra editor.
47
 
3
  Donate link: https://www.paypal.me/BrainstormForce
4
  Tags: Beaver Builder, Elementor, Astra, woff2, woff, ttf, svg, eot, otf, Custom Fonts, Font, Typography
5
  Requires at least: 4.4
6
+ Tested up to: 6.1
7
+ Stable tag: 1.3.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
42
 
43
 
44
  == Changelog ==
45
+ = 1.3.7 =
46
+ - Fix: Custom font's CSS not applying in responsive previews of WordPress block editor.
47
+
48
  = 1.3.6 =
49
  - Improvement: Compatibility with Spectra editor.
50