diff --git a/README.md b/README.md index b9cbed5..8fdfa69 100755 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -[![Build Status](https://travis-ci.org/barzik/wp-notice.svg)](https://travis-ci.org/barzik/wp-notice) +[![Build Status](https://travis-ci.org/barzik/wp-notice.svg?branch=master)](https://travis-ci.org/barzik/wp-notice) # WP Notice -WP Notice plugin enable every admin to post animated announcement or messages on top of posts based on tags, categories or date. +WP Notice plugin enable every admin to post animated announcement or messages in posts based on tags, categories or date. You can assign several messages for the several posts. There are several custom designs based on BootStrap styles. Along with the styles, you can also add to every message one of hundreds icons based on Font Awesome repository and -also choose animation type, duration and number of repetition. +also choose animation type, duration and number of repetition. You can choose the position of the notices. # Installation and other information diff --git a/README.txt b/README.txt index 638f396..2993a69 100755 --- a/README.txt +++ b/README.txt @@ -1,8 +1,8 @@ === WordPress Notice === Contributors: barzik Tags: notification, posts, obsolete, notice, messages, notice based on category, animation, font awesome -Requires at least: 3.7 -Tested up to: 4.3.1 +Requires at least: 3.8 +Tested up to: 4.4 Stable tag: trunk License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -11,10 +11,10 @@ WP Notice Plugin enables site admin to display custom animated announcements in == Description == -WP Notice plugin enable every website manager to display animated announcement or messages on top of posts based on tags, categories or date. -You can assign several messages for the several posts. There are several custom designs based on Twitter BootStrap styles. +WP Notice plugin enable every admin to post animated announcement or messages in posts based on tags, categories or date. +You can assign several messages for the several posts. There are several custom designs based on BootStrap styles. Along with the styles, you can also add to every message one of hundreds icons based on Font Awesome repository and -also choose animation type, duration and number of repetition. You can preview the message with the animation before saving it. +also choose animation type, duration and number of repetition. You can choose the position of the notices. Ideal for technical sites that need to post deprecated notice on old posts and any other sites that need to show messages to users based on categories, tags or date and get attention to the message by using icons and animation if needed. @@ -59,6 +59,11 @@ GitHub: https://github.com/barzik/wp-notice == Changelog == += 1.3.4 = +* Adding Position choice: before content, after content or both. +* Added PHPUnit test case. +* Removed tests from production to testing. + = 1.3.2 = * Fix for link posting in messages. * Added PHPUnit test case for the link issues. @@ -103,6 +108,11 @@ GitHub: https://github.com/barzik/wp-notice == Upgrade Notice == += 1.3.4 = +* Adding Position choice: before content, after content or both. +* Added PHPUnit test case. +* Removed tests from production to testing. + = 1.3.2 = Fix for issue with link being inserted to message and got malformed. diff --git a/admin/assets/css/admin.css b/admin/assets/css/admin.css index debc279..811c5ac 100755 --- a/admin/assets/css/admin.css +++ b/admin/assets/css/admin.css @@ -44,6 +44,10 @@ fieldset.wp_notice > div.wp_notice_style > label { display: inline; } +fieldset.wp_notice > div.wp_notice_position > label { + display: inline; +} + .wp_notice_animation.form-group > span { display: inline-block; } diff --git a/admin/class-wp-notice-admin.php b/admin/class-wp-notice-admin.php index 64247e0..b09219c 100755 --- a/admin/class-wp-notice-admin.php +++ b/admin/class-wp-notice-admin.php @@ -305,6 +305,11 @@ private function prepare_wp_notice_post() { $wp_notice_options_raw['animation'][ $i ]['duration'] = ''; $wp_notice_options_raw['animation'][ $i ]['repeat'] = ''; } + if ( isset( $wp_notice_options_raw['position'][ $i ] ) ) { + $wp_notice_options[ $i ]['position'] = sanitize_text_field( $wp_notice_options_raw['position'][ $i ] ); + } else { + $wp_notice_options[ $i ]['position'] = 'before'; + } } return $wp_notice_options; } @@ -390,7 +395,7 @@ private function get_all_fieldsets( $wp_notice_options ) { $html .= $this->build_fieldset( $key, $wp_notice_option['tag'], $wp_notice_option['cat'], $wp_notice_option['wp_notice_time'], $wp_notice_option['wp_notice_text'], $wp_notice_option['style'], - $wp_notice_option['font'], $wp_notice_option['animation'] + $wp_notice_option['font'], $wp_notice_option['animation'], $wp_notice_option['position'] ); } return $html; @@ -416,7 +421,7 @@ private function generate_category_list( $number = 0, $selected_category = array $category_list .= ""; + $position_list .= ''; + $position_list .= ''; + $position_list .= ''; + $position_list .= ' '; + + return $position_list; + } + /** * * Generating the animation for the fieldset in the admin options menu @@ -552,21 +578,24 @@ private function generate_animation( $number = 0, $selected_animation = array() * @param string $selected_style The style string. * @param string $selected_font The font string for fontAwsome. * @param array $selected_animation Array for fonts. + * @param string $selected_position - The position of the notice. * @return string */ private function build_fieldset( $number = 0, $selected_tag = array(), $selected_category = array(), $time = null, - $text = '', $selected_style = 'wp-notice-regular', $selected_font = 'none', $selected_animation = array() ) { - - $category_list = $this->generate_category_list( $number, $selected_category ); - $tag_list = $this->generate_tag_list( $number, $selected_tag ); - $style_list = $this->generate_style_list( $number, $selected_style ); - $fonts_list = $this->generate_fonts_list( $number, $selected_font ); - $animation = $this->generate_animation( $number, $selected_animation ); - $text_label = __( 'The Notice', $this->plugin_slug ); - $time_label = __( 'Show in all posts that were created before:', $this->plugin_slug ); - $text_place_holder = __( 'Insert the text of the notice here. It can be HTML or text string', $this->plugin_slug ); - $time_place_holder = __( 'DD/MM/YYYY', $this->plugin_slug ); - $fieldset = <<generate_category_list( $number, $selected_category ); + $tag_list = $this->generate_tag_list( $number, $selected_tag ); + $style_list = $this->generate_style_list( $number, $selected_style ); + $fonts_list = $this->generate_fonts_list( $number, $selected_font ); + $animation = $this->generate_animation( $number, $selected_animation ); + $position = $this->generate_position( $number, $selected_position ); + $text_label = __( 'The Notice', $this->plugin_slug ); + $time_label = __( 'Show in all posts that were created before:', $this->plugin_slug ); + $text_place_holder = __( 'Insert the text of the notice here. It can be HTML or text string', $this->plugin_slug ); + $time_place_holder = __( 'DD/MM/YYYY', $this->plugin_slug ); + $fieldset = <<
@@ -585,6 +614,9 @@ private function build_fieldset( $number = 0, $selected_tag = array(), $selected
$animation
+
+ $position +
@@ -592,7 +624,7 @@ private function build_fieldset( $number = 0, $selected_tag = array(), $selected EOD; - return $fieldset; + return $fieldset; } /** diff --git a/languages/wp-notice-he_IL.mo b/languages/wp-notice-he_IL.mo index b2425d5..2511237 100755 Binary files a/languages/wp-notice-he_IL.mo and b/languages/wp-notice-he_IL.mo differ diff --git a/languages/wp-notice-he_IL.po b/languages/wp-notice-he_IL.po index 20f324c..8834e76 100644 --- a/languages/wp-notice-he_IL.po +++ b/languages/wp-notice-he_IL.po @@ -4,8 +4,8 @@ msgid "" msgstr "" "Project-Id-Version: wp-notice 1\n" "Report-Msgid-Bugs-To: http://wordpress.org/plugins/plugin-name\n" -"POT-Creation-Date: 2015-09-19 13:32+0200\n" -"PO-Revision-Date: 2015-09-24 18:50+0200\n" +"POT-Creation-Date: 2015-12-12 14:49+0200\n" +"PO-Revision-Date: 2015-12-12 14:52+0200\n" "Last-Translator: Ran Bar-Zik \n" "Language-Team: \n" "Language: he_IL\n" @@ -20,113 +20,139 @@ msgstr "" "X-Poedit-SourceCharset: UTF-8\n" "X-Poedit-SearchPath-0: .\n" -#: admin/class-wp-notice-admin.php:79 admin/class-wp-notice-admin.php:90 -#: public/class-wp-notice.php:82 public/class-wp-notice.php:93 +#: admin/class-wp-notice-admin.php:115 admin/class-wp-notice-admin.php:126 +#: public/class-wp-notice.php:98 public/class-wp-notice.php:109 msgid "Cheatin’ huh?" -msgstr "" +msgstr "לרמות זה לא יפה." -#: admin/class-wp-notice-admin.php:152 +#: admin/class-wp-notice-admin.php:175 msgid "Done" msgstr "בוצע" -#: admin/class-wp-notice-admin.php:153 +#: admin/class-wp-notice-admin.php:176 msgid "Today" msgstr "היום" -#: admin/class-wp-notice-admin.php:156 +#: admin/class-wp-notice-admin.php:179 msgid "Show a different month" msgstr "הראה חודש אחר" -#: admin/class-wp-notice-admin.php:184 +#: admin/class-wp-notice-admin.php:204 msgid "WP Notice Setting page" msgstr "מסך ההגדרות של WP Notice" -#: admin/class-wp-notice-admin.php:200 +#: admin/class-wp-notice-admin.php:205 +msgid "WP Notice" +msgstr "הודעות וורדפרס" + +#: admin/class-wp-notice-admin.php:224 msgid "Insert the notice and the conditions" msgstr "הכניסו את ההודעה ואת התנאים" -#: admin/class-wp-notice-admin.php:331 +#: admin/class-wp-notice-admin.php:374 msgid "WP Notice Settings Updated" msgstr "ההגדרות של WP Notice עודכנו" -#: admin/class-wp-notice-admin.php:333 +#: admin/class-wp-notice-admin.php:376 #, fuzzy msgid "WP Notice Error! You did change the form, right? please try again." msgstr "שגיאה ב Wp Notice אנא נסו שוב." -#: admin/class-wp-notice-admin.php:371 admin/class-wp-notice-admin.php:400 +#: admin/class-wp-notice-admin.php:420 admin/class-wp-notice-admin.php:451 msgid "Show in all posts that belongs to : " msgstr "הראה בכל הפוסטים ששייכים אל:" -#: admin/class-wp-notice-admin.php:373 +#: admin/class-wp-notice-admin.php:422 msgid "Do not use categories" msgstr "אל תשתמש בקטגוריות" -#: admin/class-wp-notice-admin.php:402 +#: admin/class-wp-notice-admin.php:453 msgid "Do not use tags" msgstr "אל תשתמש בתגיות" -#: admin/class-wp-notice-admin.php:427 +#: admin/class-wp-notice-admin.php:477 msgid "Select the style of the notice : " msgstr "בחרו את עיצוב ההודעה : " -#: admin/class-wp-notice-admin.php:455 +#: admin/class-wp-notice-admin.php:497 +msgid "Select icon for the notice : " +msgstr "בחרו אייקון שיופיע בהודעה" + +#: admin/class-wp-notice-admin.php:499 +#, fuzzy +msgid "Do not use font" +msgstr "אל תשתמש בתגיות" + +#: admin/class-wp-notice-admin.php:519 +#, fuzzy +msgid "Select position for the notice : " +msgstr "בחרו אייקון שיופיע בהודעה" + +#: admin/class-wp-notice-admin.php:521 +msgid "Before" +msgstr "לפני" + +#: admin/class-wp-notice-admin.php:522 +msgid "After" +msgstr "אחרי" + +#: admin/class-wp-notice-admin.php:523 +msgid "Both" +msgstr "גם וגם" + +#: admin/class-wp-notice-admin.php:550 +msgid "Select animation type : " +msgstr "בחרו את סוג האנימציה" + +#: admin/class-wp-notice-admin.php:552 +msgid "None" +msgstr "ללא" + +#: admin/class-wp-notice-admin.php:559 +msgid "Select animation duration (seconds) : " +msgstr "משך האנימציה בשניות" + +#: admin/class-wp-notice-admin.php:563 +msgid "Select animation repetition, -1 for infinite : " +msgstr "מספר החזרות. -1 עבור אינסוף" + +#: admin/class-wp-notice-admin.php:594 msgid "The Notice" msgstr "ההודעה" -#: admin/class-wp-notice-admin.php:456 +#: admin/class-wp-notice-admin.php:595 msgid "Show in all posts that were created before:" msgstr "הצג בכל הפוסטים שנוצרו לפני:" -#: admin/class-wp-notice-admin.php:457 +#: admin/class-wp-notice-admin.php:596 msgid "Insert the text of the notice here. It can be HTML or text string" msgstr "הכנס את הטקסט של ההודעה כאן. הטקסט יכול להיות HTML" -#: admin/class-wp-notice-admin.php:458 +#: admin/class-wp-notice-admin.php:597 #, fuzzy msgid "DD/MM/YYYY" msgstr "DD/MM/YY" -#: admin/class-wp-notice-admin.php:489 +#: admin/class-wp-notice-admin.php:639 msgid "Settings" msgstr "הגדרות" -#: admin/views/admin.php:26 +#: admin/views/admin.php:30 msgid "" "Please fill in the notice text and the proper conditions that need to be " "fulfilled in order to make the notice to appear" msgstr "אנא מלאו את ההודעה ואת התנאים שצריכים להתקיים על מנת שהיא תופיע" -#: admin/views/admin.php:27 +#: admin/views/admin.php:31 msgid "You can combine several conditions and create several notices" msgstr "אפשר לשלב מספר תנאים וליצור מספר הודעות" -#: admin/views/admin.php:32 +#: admin/views/admin.php:41 msgid "Submit" msgstr "שלח" msgid "Plugin to display notice and messages on posts" msgstr "תוסף להצגת הודעות ומסרים בפוסטים שונים" -msgid "Select icon for the notice : " -msgstr "בחרו אייקון שיופיע בהודעה" - -msgid "Select animation type : " -msgstr "בחרו את סוג האנימציה" - -msgid "None" -msgstr "ללא" - -msgid "Select animation duration (seconds) : " -msgstr "משך האנימציה בשניות" - -msgid "Select animation repetition, -1 for infinite : " -msgstr "מספר החזרות. -1 עבור אינסוף" - -#. Author of the plugin/theme msgid "Ran Bar-Zik " msgstr "רן בר-זיק " - -#. Plugin name -msgid "WP Notice" -msgstr "הודעות וורדפרס" diff --git a/public/class-wp-notice.php b/public/class-wp-notice.php index 416e4b5..3ce9d28 100755 --- a/public/class-wp-notice.php +++ b/public/class-wp-notice.php @@ -181,8 +181,19 @@ public function wp_notice_add_message( $content ) { $messages_array = $this->wp_notice_options_decider(); foreach ( $messages_array as $key => $message ) { $messages_html .= $this->create_message_block( $message['text'], $key, $message['style'], $message['font'], $message['animation'] ); + switch ( $message['position'] ) { + case 'after': + $content = $content.$messages_html; + break; + case 'both': + $content = $messages_html.$content.$messages_html; + break; + default: + $content = $messages_html.$content; + break; + } } - $content = $messages_html.$content; + return $content; } @@ -242,13 +253,19 @@ private function wp_notice_options_decider() { $found = false; if ( isset( $sort_option['tag'] ) && ! empty( $sort_option['tag'] ) ) { foreach ( $sort_option['tag'] as $tag ) { - if ( in_array( $tag, $current_tags ) ) { - $messages[] = array( + if ( in_array( $tag, $current_tags, true ) ) { + $temp_message = array( 'text' => $sort_option['wp_notice_text'], 'style' => $sort_option['style'], 'font' => $sort_option['font'], 'animation' => $sort_option['animation'], ); + if ( isset( $sort_option['position'] ) ) { + $temp_message['position'] = $sort_option['position']; + } else { + $temp_message['position'] = 'before'; + } + $messages[] = $temp_message; $found = true; break; } @@ -261,13 +278,19 @@ private function wp_notice_options_decider() { if ( isset( $sort_option['cat'] ) && ! empty( $sort_option['cat'] ) ) { foreach ( $sort_option['cat'] as $cat ) { - if ( in_array( $cat, $current_categories ) ) { - $messages[] = array( + if ( in_array( $cat, $current_categories, true ) ) { + $temp_message = array( 'text' => $sort_option['wp_notice_text'], 'style' => $sort_option['style'], 'font' => $sort_option['font'], 'animation' => $sort_option['animation'], ); + if ( isset( $sort_option['position'] ) ) { + $temp_message['position'] = $sort_option['position']; + } else { + $temp_message['position'] = 'before'; + } + $messages[] = $temp_message; $found = true; break; } @@ -282,12 +305,18 @@ private function wp_notice_options_decider() { $dt = DateTime::createFromFormat( 'd/m/Y', $options[ $key ]['wp_notice_time'] ); $ts = $dt->getTimestamp(); if ( $ts > get_the_time( 'U' ) ) { - $messages[] = array( + $temp_message = array( 'text' => $sort_option['wp_notice_text'], 'style' => $sort_option['style'], 'font' => $sort_option['font'], 'animation' => $sort_option['animation'], ); + if ( isset( $sort_option['position'] ) ) { + $temp_message['position'] = $sort_option['position']; + } else { + $temp_message['position'] = 'before'; + } + $messages[] = $temp_message; } } } diff --git a/tests/bin/router.php b/tests/bin/router.php index 2ec72b0..239d0e7 100644 --- a/tests/bin/router.php +++ b/tests/bin/router.php @@ -1,5 +1,7 @@ factory->user->create( array( 'role' => 'administrator' ) ) ); + wp_set_current_user( $user->ID ); + // fetching options, validate it is empty + $wp_notice_settings = get_option( 'wp_notice_settings_information', array() ); + + $this->assertEmpty( $wp_notice_settings ); + + $i = 0; + $cat_id = $this->generate_category(); + // generate $_POST data + $this->create_valid_post_data( $i, $cat_id, NULL, NULL , 'wp-notice-regular', 'none', array('duration' => '', 'repeat' => '', 'type' => 'none'), 'after' ); + + // checking the admin page with $_POST - should insert it to the options + $this->plugin_admin->display_plugin_admin_page(); + + // fetching options, now it is not empty + $wp_notice_settings = get_option( 'wp_notice_settings_information', array() ); + + $this->assertNotEmpty( $wp_notice_settings ); + + $options_data = unserialize( $wp_notice_settings ); + $this->assertInternalType( 'array', $options_data[ $i ] ); + $this->assertEmpty( $options_data[ $i ]['wp_notice_time']); + $this->assertEmpty( $options_data[ $i ]['tag']); + $this->assertEquals( $options_data[ $i ]['position'], 'after'); + + $this->assertEquals( $options_data[ $i ]['wp_notice_text'], 'This is notice #'.$i.' message' ); + $this->assertEquals( $options_data[ $i ]['style'], 'wp-notice-regular' ); + $this->assertEquals( $options_data[ $i ]['font'], 'none' ); + $this->assertEquals( $options_data[ $i ]['position'], 'after' ); + + // now test it with real post - it should not contain message and not errors + // notice, warnings and errors will drop tests - added convertErrorsToExceptions = "true" + //convertNoticesToExceptions = "true" + //convertWarningsToExceptions = "true" + // in phpunit.xml + // create one post + $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_status' => 'publish', 'post_title' => 'POST1', 'post_content' => 'POST CONTENT', 'post_excerpt'=> 'POST CONTENT', 'post_date' => date( 'Y-m-d H:i:s', time() ) ) ); + + // go to this post + $this->go_to( get_permalink( $post_id ) ); + // fetch the content + $post_content_with_notice = get_echo( 'the_content' ); + + } + function test_plugin_delete_all_options() { $user = new WP_User( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); @@ -493,7 +545,7 @@ class_exists('WP_notice_Admin'), } - function create_valid_post_data( $i = 0, $cat_id = 0, $term_id = 0, $date = '', $style = 'wp-notice-regular', $font = 'none', $animation = array('duration' => '', 'repeat' => '', 'type' => 'none') ) { + function create_valid_post_data( $i = 0, $cat_id = 0, $term_id = 0, $date = '', $style = 'wp-notice-regular', $font = 'none', $animation = array('duration' => '', 'repeat' => '', 'type' => 'none'), $position = 'before' ) { global $_POST; $_POST['wp_notice'] = wp_create_nonce( 'submit_notice' ); @@ -516,6 +568,8 @@ function create_valid_post_data( $i = 0, $cat_id = 0, $term_id = 0, $date = '', $_POST['animation'][ $i ] = $animation; + $_POST['position'][ $i ] = $position; + } public function generate_category() { diff --git a/wp-notice.php b/wp-notice.php index bea068a..8e7df5e 100755 --- a/wp-notice.php +++ b/wp-notice.php @@ -12,7 +12,7 @@ * Plugin Name: WP Notice * Plugin URI: http://internet-israel.com * Description: WP Notice Plugin enables admin to put custom animated announcements in the beginning of posts based on date, categories or tags. - * Version: 1.3.2 + * Version: 1.3.4 * Author: Ran Bar-Zik * Author URI: http://internet-israel.com * Text Domain: wp-notice