@@ -178,8 +178,8 @@ public static function ap_default_options($defaults) {
178178 public function value ($ name ) {
179179 $ settings = ap_opt ();
180180 if ( isset ( $ settings [ $ name ] ) ) {
181- return str_replace ( " // " , "" , $ settings [ $ name ] );
182- }
181+ return str_replace ( ' // ' , '' , $ settings [ $ name ] );
182+ }
183183
184184 return '' ;
185185 }
@@ -192,11 +192,10 @@ public function register_option() {
192192 // Register general settings.
193193 ap_register_option_group ('email ' , __ ( 'Email ' , 'AnsPress_Email ' ) , array (
194194 array (
195- 'name ' => 'anspress_opt[ notify_admin_email] ' ,
195+ 'name ' => 'notify_admin_email ' ,
196196 'label ' => __ ( 'Admin email ' , 'AnsPress_Email ' ),
197197 'desc ' => __ ( 'Enter email where admin notification should be sent ' , 'AnsPress_Email ' ),
198198 'type ' => 'text ' ,
199- 'value ' => $ this ->value ( 'notify_admin_email ' ),
200199 'show_desc_tip ' => false ,
201200 ),
202201
@@ -206,59 +205,52 @@ public function register_option() {
206205 'html ' => '<span class="ap-form-separator"> ' . __ ( 'Notify admin ' , 'AnsPress_Email ' ) . '</span> ' ,
207206 ) ,
208207 array (
209- 'name ' => 'anspress_opt[ notify_admin_new_question] ' ,
208+ 'name ' => 'notify_admin_new_question ' ,
210209 'label ' => __ ( 'New question ' , 'AnsPress_Email ' ),
211210 'desc ' => __ ( 'Send email to admin for every new question. ' , 'AnsPress_Email ' ),
212211 'type ' => 'checkbox ' ,
213- 'value ' => $ this ->value ( 'notify_admin_new_question ' ),
214212 'show_desc_tip ' => false ,
215213 ),
216214 array (
217- 'name ' => 'anspress_opt[ notify_admin_new_answer] ' ,
215+ 'name ' => 'notify_admin_new_answer ' ,
218216 'label ' => __ ( 'New answer ' , 'AnsPress_Email ' ),
219217 'desc ' => __ ( 'Send email to admin for every new answer. ' , 'AnsPress_Email ' ),
220218 'type ' => 'checkbox ' ,
221- 'value ' => $ this ->value ( 'notify_admin_new_answer ' ),
222219 'show_desc_tip ' => false ,
223220 ),
224221 array (
225- 'name ' => 'anspress_opt[ notify_admin_new_comment] ' ,
222+ 'name ' => 'notify_admin_new_comment ' ,
226223 'label ' => __ ( 'New comment ' , 'AnsPress_Email ' ),
227224 'desc ' => __ ( 'Send email to admin for every new comment. ' , 'AnsPress_Email ' ),
228225 'type ' => 'checkbox ' ,
229- 'value ' => $ this ->value ( 'notify_admin_new_comment ' ),
230226 'show_desc_tip ' => false ,
231227 ),
232228 array (
233- 'name ' => 'anspress_opt[ notify_admin_edit_question] ' ,
229+ 'name ' => 'notify_admin_edit_question ' ,
234230 'label ' => __ ( 'Edit question ' , 'AnsPress_Email ' ),
235231 'desc ' => __ ( 'Send email to admin when question is edited ' , 'AnsPress_Email ' ),
236232 'type ' => 'checkbox ' ,
237- 'value ' => $ this ->value ( 'notify_admin_edit_question ' ),
238233 'show_desc_tip ' => false ,
239234 ),
240235 array (
241- 'name ' => 'anspress_opt[ notify_admin_edit_answer] ' ,
236+ 'name ' => 'notify_admin_edit_answer ' ,
242237 'label ' => __ ( 'Edit answer ' , 'AnsPress_Email ' ),
243238 'desc ' => __ ( 'Send email to admin when answer is edited ' , 'AnsPress_Email ' ),
244239 'type ' => 'checkbox ' ,
245- 'value ' => $ this ->value ( 'notify_admin_edit_answer ' ),
246240 'show_desc_tip ' => false ,
247241 ),
248242 array (
249- 'name ' => 'anspress_opt[ notify_admin_trash_question] ' ,
243+ 'name ' => 'notify_admin_trash_question ' ,
250244 'label ' => __ ( 'Delete question ' , 'AnsPress_Email ' ),
251245 'desc ' => __ ( 'Send email to admin when question is trashed ' , 'AnsPress_Email ' ),
252246 'type ' => 'checkbox ' ,
253- 'value ' => $ this ->value ( 'notify_admin_trash_question ' ),
254247 'show_desc_tip ' => false ,
255248 ),
256249 array (
257- 'name ' => 'anspress_opt[ notify_admin_trash_answer] ' ,
250+ 'name ' => 'notify_admin_trash_answer ' ,
258251 'label ' => __ ( 'Delete answer ' , 'AnsPress_Email ' ),
259252 'desc ' => __ ( 'Send email to admin when asnwer is trashed ' , 'AnsPress_Email ' ),
260253 'type ' => 'checkbox ' ,
261- 'value ' => $ this ->value ( 'notify_admin_trash_answer ' ),
262254 'show_desc_tip ' => false ,
263255 ),
264256 array (
@@ -267,17 +259,15 @@ public function register_option() {
267259 'html ' => '<span class="ap-form-separator"> ' . __ ( 'New question ' , 'AnsPress_Email ' ) . '</span> ' ,
268260 ),
269261 array (
270- 'name ' => 'anspress_opt[ new_question_email_subject] ' ,
262+ 'name ' => 'new_question_email_subject ' ,
271263 'label ' => __ ( 'Subject ' , 'AnsPress_Email ' ),
272264 'type ' => 'text ' ,
273- 'value ' => $ this ->value ( 'new_question_email_subject ' ),
274265 'attr ' => 'style="width:80%" ' ,
275266 ),
276267 array (
277- 'name ' => 'anspress_opt[ new_question_email_body] ' ,
268+ 'name ' => 'new_question_email_body ' ,
278269 'label ' => __ ( 'Body ' , 'AnsPress_Email ' ),
279270 'type ' => 'textarea ' ,
280- 'value ' => $ this ->value ( 'new_question_email_body ' ),
281271 'attr ' => 'style="width:100%;min-height:200px" ' ,
282272 ),
283273 array (
@@ -286,17 +276,15 @@ public function register_option() {
286276 'html ' => '<span class="ap-form-separator"> ' . __ ( 'New Answer ' , 'AnsPress_Email ' ) . '</span> ' ,
287277 ),
288278 array (
289- 'name ' => 'anspress_opt[ new_answer_email_subject] ' ,
279+ 'name ' => 'new_answer_email_subject ' ,
290280 'label ' => __ ( 'Subject ' , 'AnsPress_Email ' ),
291281 'type ' => 'text ' ,
292- 'value ' => $ this ->value ( 'new_answer_email_subject ' ),
293282 'attr ' => 'style="width:80%" ' ,
294283 ),
295284 array (
296- 'name ' => 'anspress_opt[ new_answer_email_body] ' ,
285+ 'name ' => 'new_answer_email_body ' ,
297286 'label ' => __ ( 'Body ' , 'AnsPress_Email ' ),
298287 'type ' => 'textarea ' ,
299- 'value ' => $ this ->value ( 'new_answer_email_body ' ),
300288 'attr ' => 'style="width:100%;min-height:200px" ' ,
301289 ),
302290 array (
@@ -305,17 +293,15 @@ public function register_option() {
305293 'html ' => '<span class="ap-form-separator"> ' . __ ( 'Select Answer ' , 'AnsPress_Email ' ) . '</span> ' ,
306294 ),
307295 array (
308- 'name ' => 'anspress_opt[ select_answer_email_subject] ' ,
296+ 'name ' => 'select_answer_email_subject ' ,
309297 'label ' => __ ( 'Subject ' , 'AnsPress_Email ' ),
310298 'type ' => 'text ' ,
311- 'value ' => $ this ->value ( 'select_answer_email_subject ' ),
312299 'attr ' => 'style="width:80%" ' ,
313300 ),
314301 array (
315- 'name ' => 'anspress_opt[ select_answer_email_body] ' ,
302+ 'name ' => 'select_answer_email_body ' ,
316303 'label ' => __ ( 'Body ' , 'AnsPress_Email ' ),
317304 'type ' => 'textarea ' ,
318- 'value ' => $ this ->value ( 'select_answer_email_body ' ),
319305 'attr ' => 'style="width:100%;min-height:200px" ' ,
320306 ),
321307 array (
@@ -324,17 +310,15 @@ public function register_option() {
324310 'html ' => '<span class="ap-form-separator"> ' . __ ( 'New comment ' , 'AnsPress_Email ' ) . '</span> ' ,
325311 ),
326312 array (
327- 'name ' => 'anspress_opt[ new_comment_email_subject] ' ,
313+ 'name ' => 'new_comment_email_subject ' ,
328314 'label ' => __ ( 'Subject ' , 'AnsPress_Email ' ),
329315 'type ' => 'text ' ,
330- 'value ' => $ this ->value ( 'new_comment_email_subject ' ),
331316 'attr ' => 'style="width:80%" ' ,
332317 ),
333318 array (
334- 'name ' => 'anspress_opt[ new_comment_email_body] ' ,
319+ 'name ' => 'new_comment_email_body ' ,
335320 'label ' => __ ( 'Body ' , 'AnsPress_Email ' ),
336321 'type ' => 'textarea ' ,
337- 'value ' => $ this ->value ( 'new_comment_email_body ' ),
338322 'attr ' => 'style="width:100%;min-height:200px" ' ,
339323 ),
340324 array (
@@ -343,17 +327,15 @@ public function register_option() {
343327 'html ' => '<span class="ap-form-separator"> ' . __ ( 'Edit question ' , 'AnsPress_Email ' ) . '</span> ' ,
344328 ),
345329 array (
346- 'name ' => 'anspress_opt[ edit_question_email_subject] ' ,
330+ 'name ' => 'edit_question_email_subject ' ,
347331 'label ' => __ ( 'Subject ' , 'AnsPress_Email ' ),
348332 'type ' => 'text ' ,
349- 'value ' => $ this ->value ( 'edit_question_email_subject ' ),
350333 'attr ' => 'style="width:80%" ' ,
351334 ),
352335 array (
353- 'name ' => 'anspress_opt[ edit_question_email_body] ' ,
336+ 'name ' => 'edit_question_email_body ' ,
354337 'label ' => __ ( 'Body ' , 'AnsPress_Email ' ),
355338 'type ' => 'textarea ' ,
356- 'value ' => $ this ->value ( 'edit_question_email_body ' ),
357339 'attr ' => 'style="width:100%;min-height:200px" ' ,
358340 ),
359341 array (
@@ -362,17 +344,15 @@ public function register_option() {
362344 'html ' => '<span class="ap-form-separator"> ' . __ ( 'Edit answer ' , 'AnsPress_Email ' ) . '</span> ' ,
363345 ),
364346 array (
365- 'name ' => 'anspress_opt[ edit_answer_email_subject] ' ,
347+ 'name ' => 'edit_answer_email_subject ' ,
366348 'label ' => __ ( 'Subject ' , 'AnsPress_Email ' ),
367349 'type ' => 'text ' ,
368- 'value ' => $ this ->value ( 'edit_answer_email_subject ' ),
369350 'attr ' => 'style="width:80%" ' ,
370351 ),
371352 array (
372- 'name ' => 'anspress_opt[ edit_answer_email_body] ' ,
353+ 'name ' => 'edit_answer_email_body ' ,
373354 'label ' => __ ( 'Body ' , 'AnsPress_Email ' ),
374355 'type ' => 'textarea ' ,
375- 'value ' => $ this ->value ( 'edit_answer_email_body ' ),
376356 'attr ' => 'style="width:100%;min-height:200px" ' ,
377357 ),
378358 ));
@@ -439,16 +419,17 @@ public function ap_after_new_question($question_id) {
439419
440420 $ this ->emails [] = ap_opt ( 'notify_admin_email ' );
441421
442- /*if ( ($answer->post_status != 'private_post' || $answer->post_status != 'moderate') ) {
443- $users = ap_get_subscribers( $question_id, 'q_all', 100 );
444-
445- if ( $users ) {
446- foreach ( $users as $user ) {
447- // Dont send email to poster
448- if ( $user->user_email != $current_user->user_email ) {
449- $this->emails[] = $user->user_email; }
450- }
451- }
422+ /*
423+ if ( ($answer->post_status != 'private_post' || $answer->post_status != 'moderate') ) {
424+ $users = ap_get_subscribers( $question_id, 'q_all', 100 );
425+
426+ if ( $users ) {
427+ foreach ( $users as $user ) {
428+ // Dont send email to poster
429+ if ( $user->user_email != $current_user->user_email ) {
430+ $this->emails[] = $user->user_email; }
431+ }
432+ }
452433 }*/
453434
454435 $ this ->initiate_send_email ();
@@ -481,7 +462,7 @@ public function ap_after_new_answer($answer_id) {
481462 $ this ->emails [] = ap_opt ( 'notify_admin_email ' );
482463 }
483464
484- if ( ( $ answer ->post_status != 'private_post ' || $ answer ->post_status != 'moderate ' ) ) {
465+ if ( $ answer ->post_status != 'private_post ' && $ answer ->post_status != 'moderate ' ) {
485466 $ subscribers = ap_get_subscribers ( $ answer ->post_parent , 'q_all ' , 100 , true );
486467 if ( $ subscribers ) {
487468 foreach ( $ subscribers as $ s ) {
@@ -567,7 +548,7 @@ public function new_comment($comment) {
567548 if ( $ subscribers ) {
568549 foreach ( $ subscribers as $ s ) {
569550 if ( $ s ->user_email != $ current_user ->user_email ) {
570- $ this ->emails [] = $ s ->user_email ;
551+ $ this ->emails [] = $ s ->user_email ;
571552 }
572553 }
573554 }
@@ -587,7 +568,7 @@ public function ap_after_update_question($question_id) {
587568 $ this ->emails [] = ap_opt ( 'notify_admin_email ' );
588569 }
589570
590- $ subscribers = ap_get_subscribers ( $ question_id , array ('q_post ' , 'q_all ' ), 100 , true );
571+ $ subscribers = ap_get_subscribers ( $ question_id , array ( 'q_post ' , 'q_all ' ), 100 , true );
591572
592573 $ post_author = get_user_by ( 'id ' , $ post ->post_author );
593574
@@ -597,8 +578,8 @@ public function ap_after_update_question($question_id) {
597578
598579 if ( $ subscribers ) {
599580 foreach ( $ subscribers as $ s ) {
600- if ( !empty ($ s ->user_email ) && $ s ->user_email != $ current_user ->user_email ) {
601- $ this ->emails [] = $ s ->user_email ;
581+ if ( ! empty ($ s ->user_email ) && $ s ->user_email != $ current_user ->user_email ) {
582+ $ this ->emails [] = $ s ->user_email ;
602583 }
603584 }
604585 }
@@ -650,7 +631,7 @@ public function ap_after_update_answer($answer_id) {
650631
651632 if ( $ subscribers ) {
652633 foreach ( $ subscribers as $ s ) {
653- if ( !empty ($ s ->user_email ) && $ s ->user_email != $ current_user ->user_email ) {
634+ if ( ! empty ($ s ->user_email ) && $ s ->user_email != $ current_user ->user_email ) {
654635 $ this ->emails [] = $ s ->user_email ;
655636 }
656637 }
@@ -744,19 +725,27 @@ public function ap_trash_answer($post) {
744725 */
745726
746727function anspress_ext_AnsPress_Email () {
728+ if ( ! defined ( 'AP_VERSION ' ) || ! version_compare ( AP_VERSION , '3.0.0 ' , '>= ' ) ) {
729+ function ap_email_admin_error_notice () {
730+ echo '<div class="update-nag error"> <p> ' .sprintf ( __ ( 'Email extension require AnsPress 3.0.0 or above. Download from Github %shttp://github.com/anspress/anspress-email%s ' , 'tags-for-anspress ' , 'categories-for-anspress ' ), '<a target="_blank" href="http://github.com/anspress/anspress-email"> ' , '</a> ' ).'</p></div> ' ;
731+ }
732+ add_action ( 'admin_notices ' , 'ap_email_admin_error_notice ' );
733+ return ;
734+ }
735+
747736 if ( apply_filters ( 'anspress_load_ext ' , true , 'anspress-email ' ) ) {
748737 $ anspress_ext_AnsPress_Email = new AnsPress_Ext_AnsPress_Email ();
749738 }
750739}
751- add_action ( 'plugins_loaded ' , 'anspress_ext_AnsPress_Email ' );
740+ add_action ( 'anspress_loaded ' , 'anspress_ext_AnsPress_Email ' );
752741
753742
754743/**
755744 * Load extensions files before loading AnsPress
756745 * @return void
757746 * @since 1.0
758747 */
759- function anspress_loaded_anspress_email () {
748+ function anspress_loaded_anspress_email () {
760749 add_filter ( 'ap_default_options ' , array ( 'AnsPress_Ext_AnsPress_Email ' , 'ap_default_options ' ) );
761750}
762- add_action ( 'before_loading_anspress ' , 'anspress_loaded_anspress_email ' );
751+ add_action ( 'before_loading_anspress ' , 'anspress_loaded_anspress_email ' );
0 commit comments