Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme review notice #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions css/admin/message.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
position: relative;
border-left-color: #2ea2cc !important;
}

.envince-message a.button-primary,
.envince-message a.button-secondary {
text-decoration: none !important;
}

.envince-message a.envince-message-close {
position: absolute;
top: 0;
Expand All @@ -16,10 +18,28 @@
line-height: 1.23076923;
text-decoration: none;
}

.envince-message a.envince-message-close:before {
position: absolute;
top: 8px;
left: 0;
-webkit-transition: all .1s ease-in-out;
transition: all .1s ease-in-out;
}

/* Review Notice */
.notice.updated.theme-review-notice {
padding-right: 40px;
}

.theme-review-notice .links {
margin: 0.5em 0;
}

.theme-review-notice .links a {
margin: 2px;
}

.theme-review-notice .links .dashicons {
line-height: 30px;
}
1 change: 1 addition & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
if ( is_admin() ) {
require get_template_directory() . '/inc/admin/class-envince-admin.php';
require get_template_directory() . '/inc/admin/class-envince-tdi-notice.php';
require get_template_directory() . '/inc/admin/class-envince-theme-review-notice.php';
}

/* Do theme setup on the 'after_setup_theme' hook. */
Expand Down
175 changes: 175 additions & 0 deletions inc/admin/class-envince-theme-review-notice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?php
/**
* Envince Theme Review Notice Class.
*
* @author ThemeGrill
* @package Envince
* @since 1.2.6
*/

// Exit if directly accessed.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Class to display the theme review notice for this theme after certain period.
*
* Class Envince_Theme_Review_Notice
*/
class Envince_Theme_Review_Notice {

/**
* Constructor function to include the required functionality for the class.
*
* Envince_Theme_Review_Notice constructor.
*/
public function __construct() {

add_action( 'after_setup_theme', array( $this, 'envince_theme_rating_notice' ) );
add_action( 'switch_theme', array( $this, 'envince_theme_rating_notice_data_remove' ) );

}

/**
* Set the required option value as needed for theme review notice.
*/
public function envince_theme_rating_notice() {

// Set the installed time in `envince_theme_installed_time` option table.
$option = get_option( 'envince_theme_installed_time' );
if ( ! $option ) {
update_option( 'envince_theme_installed_time', time() );
}

add_action( 'admin_notices', array( $this, 'envince_theme_review_notice' ), 0 );
add_action( 'admin_init', array( $this, 'envince_ignore_theme_review_notice' ), 0 );
add_action( 'admin_init', array( $this, 'envince_ignore_theme_review_notice_partially' ), 0 );

}

/**
* Display the theme review notice.
*/
public function envince_theme_review_notice() {

$user_id = get_current_user_id();
$current_user = wp_get_current_user();
$ignored_notice = get_user_meta( $user_id, 'envince_ignore_theme_review_notice', true );
$ignored_notice_partially = get_user_meta( $user_id, 'nag_envince_ignore_theme_review_notice_partially', true );

/**
* Return from notice display if:
*
* 1. The theme installed is less than 15 days.
* 2. If the user has ignored the message partially for 15 days.
* 3. Dismiss always if clicked on 'I Already Did' button.
*/
if ( ( get_option( 'envince_theme_installed_time' ) > strtotime( '-15 day' ) ) || ( $ignored_notice_partially > strtotime( '-15 day' ) ) || ( $ignored_notice ) ) {
return;
}
?>

<div class="notice updated theme-review-notice" style="position:relative;">
<p>
<?php
printf(
/* Translators: %1$s current user display name. */
esc_html__(
'Howdy, %1$s! It seems that you have been using this theme for more than 15 day. We hope you are happy with everything that the theme has to offer. If you can spare a minute, please help us by leaving a 5-star review on WordPress.org. By spreading the love, we can continue to develop new amazing features in the future, for free!', 'envince'
),
'<strong>' . esc_html( $current_user->display_name ) . '</strong>'
);
?>
</p>

<div class="links">
<a href="https://wordpress.org/support/theme/envince/reviews/?filter=5#new-post" class="btn button-primary" target="_blank">
<span class="dashicons dashicons-thumbs-up"></span>
<span><?php esc_html_e( 'Sure', 'envince' ); ?></span>
</a>

<a href="?nag_envince_ignore_theme_review_notice_partially=0" class="btn button-secondary">
<span class="dashicons dashicons-calendar"></span>
<span><?php esc_html_e( 'Maybe later', 'envince' ); ?></span>
</a>

<a href="?nag_envince_ignore_theme_review_notice=0" class="btn button-secondary">
<span class="dashicons dashicons-smiley"></span>
<span><?php esc_html_e( 'I already did', 'envince' ); ?></span>
</a>

<a href="<?php echo esc_url( 'https://themegrill.com/support-forum/forum/envince-free/' ); ?>" class="btn button-secondary" target="_blank">
<span class="dashicons dashicons-edit"></span>
<span><?php esc_html_e( 'Got theme support question?', 'envince' ); ?></span>
</a>
</div>

<a class="notice-dismiss" style="text-decoration:none;" href="?nag_envince_ignore_theme_review_notice=0"></a>
</div>

<?php
}

/**
* Function to remove the theme review notice permanently as requested by the user.
*/
public function envince_ignore_theme_review_notice() {

$user_id = get_current_user_id();

/* If user clicks to ignore the notice, add that to their user meta */
if ( isset( $_GET['nag_envince_ignore_theme_review_notice'] ) && '0' == $_GET['nag_envince_ignore_theme_review_notice'] ) {
add_user_meta( $user_id, 'envince_ignore_theme_review_notice', 'true', true );
}

}

/**
* Function to remove the theme review notice partially as requested by the user.
*/
public function envince_ignore_theme_review_notice_partially() {

$user_id = get_current_user_id();

/* If user clicks to ignore the notice, add that to their user meta */
if ( isset( $_GET['nag_envince_ignore_theme_review_notice_partially'] ) && '0' == $_GET['nag_envince_ignore_theme_review_notice_partially'] ) {
update_user_meta( $user_id, 'nag_envince_ignore_theme_review_notice_partially', time() );
}

}

/**
* Remove the data set after the theme has been switched to other theme.
*/
public function envince_theme_rating_notice_data_remove() {

$get_all_users = get_users();
$theme_installed_time = get_option( 'envince_theme_installed_time' );

// Delete options data.
if ( $theme_installed_time ) {
delete_option( 'envince_theme_installed_time' );
}

// Delete user meta data for theme review notice.
foreach ( $get_all_users as $user ) {
$ignored_notice = get_user_meta( $user->ID, 'envince_ignore_theme_review_notice', true );
$ignored_notice_partially = get_user_meta( $user->ID, 'nag_envince_ignore_theme_review_notice_partially', true );

// Delete permanent notice remove data.
if ( $ignored_notice ) {
delete_user_meta( $user->ID, 'envince_ignore_theme_review_notice' );
}

// Delete partial notice remove data.
if ( $ignored_notice_partially ) {
delete_user_meta( $user->ID, 'nag_envince_ignore_theme_review_notice_partially' );
}

}
}

}

new Envince_Theme_Review_Notice();
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Envince WordPress Theme, Copyright (c) 2015, ThemeGrill
Envince is distributed under the terms of the GNU GPL

== Changelog ==
= Version TBD =
* Tweak - Add review notice message.

= Version 1.2.5 - 2020-02-20 =
* Tweak - Update `screen-reader-text` CSS.

Expand Down