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

notification system #498

Open
wants to merge 2 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
11 changes: 3 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
"env": {
"browser": true,
"es6": true,
"node": true,
"jquery": true
},
"globals": {
"wp": true,
"jQuery": true
"node": true
},
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:react/recommended",
"plugin:jsx-a11y/recommended",
"plugin:@wordpress/eslint-plugin/recommended",
"plugin:@wordpress/eslint-plugin/recommended-with-formatting",
"plugin:@tanstack/eslint-plugin-query/recommended"
],
"parserOptions": {
Expand All @@ -25,7 +20,7 @@
"jsx": true
}
},
"ignorePatterns": [ "node_modules/" ],
"ignorePatterns": ["node_modules/"],
"plugins": [
"react",
"import",
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Install Subversion
run: sudo apt-get update && sudo apt-get install -y subversion

- name: Checkout code
uses: actions/checkout@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ assets/dist/
**.zip
.standard.json
.vscode
admin/wpchill-notifications/scripts/*

# assets/dist/
package-lock.json
#################
Expand Down
126 changes: 3 additions & 123 deletions admin/admin-notices.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
/**
* Admin notices
*/

* Backwards compatibility - Admin notices
*/

/**
* Dismiss persistent notices.
Expand Down Expand Up @@ -34,7 +33,7 @@ function wpmtst_admin_notices() {
}

foreach ( $notices as $key => $notice ) {
$message = apply_filters( 'wpmtst_admin_notice', '', $key );
$message = apply_filters( 'wpmtst_' . $key . '_notice', '' );
if ( $message ) {
echo wp_kses_post( $message );
}
Expand All @@ -45,97 +44,6 @@ function wpmtst_admin_notices() {
}
add_action( 'admin_notices', 'wpmtst_admin_notices' );


/**
* Return specific admin notice text.
*
* @since 2.28.5
* @param string $html
* @param $key
*
* @return string
*/
function wpmtst_admin_notice_text( $html, $key, $persist = false ) {

switch ( $key ) {
case 'defaults-restored':
ob_start();
?>
<div class="wpmtst notice notice-success is-dismissible" data-key="<?php echo esc_attr( $key ); ?>">
<p>
<?php esc_html_e( 'Defaults restored.', 'strong-testimonials' ); ?>
</p>
</div>
<?php
$html = ob_get_clean();
break;

case 'fields-saved':
ob_start();
?>
<div class="wpmtst notice notice-success is-dismissible" data-key="<?php echo esc_attr( $key ); ?>">
<p>
<?php esc_html_e( 'Fields saved.', 'strong-testimonials' ); ?>
</p>
</div>
<?php
$html = ob_get_clean();
break;

case 'changes-cancelled':
ob_start();
?>
<div class="wpmtst notice notice-success is-dismissible" data-key="<?php echo esc_attr( $key ); ?>">
<p>
<?php esc_html_e( 'Changes cancelled.', 'strong-testimonials' ); ?>
</p>
</div>
<?php
$html = ob_get_clean();
break;

case 'captcha-options-changed':
$tags = array(
'a' => array(
'class' => array(),
'href' => array(),
),
);

$settings_url = admin_url( '?action=captcha-options-changed' );

$settings_link = sprintf(
wp_kses(
// translators: %1$s is the URL to the settings page, and %2$s is the text "settings".
__( 'Please check your <a href="%1$s">%2$s</a>.', 'strong-testimonials' ),
$tags
),
esc_url( $settings_url ),
esc_html__( 'settings', 'strong-testimonials' )
);

ob_start();
?>
<div class="wpmtst notice notice-warning is-dismissible" data-key="<?php echo esc_attr( $key ); ?>">
<p>
<?php echo wp_kses_post( __( 'Captcha options have changed in <strong>Strong Testimonials</strong>.', 'strong-testimonials' ) ); ?>
<?php echo esc_url( $settings_link ); ?>
</p>
</div>
<?php
$html = ob_get_clean();
break;

default:
$html = apply_filters( 'wpmtst_' . $key . '_notice', '' );
// nothing
}

return $html;
}
add_filter( 'wpmtst_admin_notice', 'wpmtst_admin_notice_text', 10, 2 );


/**
* Add admin notice to queue.
*
Expand Down Expand Up @@ -165,31 +73,3 @@ function wpmtst_delete_admin_notice( $key ) {
update_option( 'wpmtst_admin_notices', $notices, 'no' );
}
}


/**
* Automatically dismiss specific notices when settings are saved.
*
* @since 2.29.0
* @param $option
* @param $old_value
* @param $value
*/
function wpmtst_auto_dismiss_notices( $option, $old_value, $value ) {
if ( ! function_exists( 'get_current_screen' ) ) {
return;
}

$screen = get_current_screen();
if ( $screen && 'options' === $screen->base ) {
if ( 'wpmtst_form_options' === $option ) {
$notices = get_option( 'wpmtst_admin_notices', array() );
if ( isset( $notices['captcha-options-changed'] ) ) {
unset( $notices['captcha-options-changed'] );
update_option( 'wpmtst_admin_notices', $notices, 'no' );
}
}
}
}
add_action( 'update_option', 'wpmtst_auto_dismiss_notices', 10, 3 );

44 changes: 0 additions & 44 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,6 @@ function wpmtst_admin_init() {

add_action( 'admin_init', 'wpmtst_admin_init' );

/**
* Custom action link in admin notice.
*
* @since 2.29.0
*/
function wpmtst_action_captcha_options_changed() {
wpmtst_delete_admin_notice( 'captcha-options-changed' );
wp_redirect( admin_url( 'edit.php?post_type=wpm-testimonial&page=testimonial-settings&tab=form#captcha-section' ) );
exit;
}

add_action( 'admin_action_captcha-options-changed', 'wpmtst_action_captcha_options_changed' );

/**
* Are we on a testimonial admin screen?
*
Expand Down Expand Up @@ -169,37 +156,6 @@ function wpmtst_updated_option( $option, $old_value, $value ) {
}
add_action( 'updated_option', 'wpmtst_updated_option', 10, 3 );


/**
* Store configuration error.
*
* @since 2.24.0
* @param $key
*/
function wpmtst_add_config_error( $key ) {
$errors = get_option( 'wpmtst_config_errors', array() );
$errors[] = $key;
update_option( 'wpmtst_config_errors', array_unique( $errors ), 'no' );

wpmtst_add_admin_notice( $key, true );
}


/**
* Delete configuration error.
*
* @since 2.24.0
* @param $key
*/
function wpmtst_delete_config_error( $key ) {
$errors = get_option( 'wpmtst_config_errors', array() );
$errors = array_diff( $errors, array( $key ) );
update_option( 'wpmtst_config_errors', $errors, 'no' );

wpmtst_delete_admin_notice( $key );
}


/**
* Save a View.
*
Expand Down
100 changes: 53 additions & 47 deletions admin/class-strong-testimonials-review.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,48 @@ private function value() {

public function five_star_wp_rate_notice() {

$url = sprintf( $this->link, $this->slug );
$url = sprintf( $this->link, $this->slug );
$url = apply_filters( 'wpmtst_review_link', $url );
$this->messages = apply_filters( 'wpmtst_review_messages', $this->messages );

$notice = array(
'title' => 'Rate Us',
'message' => sprintf( esc_html( $this->messages['notice'] ), esc_html( $this->value ) ),
'status' => 'success',
'dismissible' => false,
'actions' => array(
array(
'label' => esc_html( $this->messages['rated'] ),
'id' => 'strong-testimonials-later',
'class' => 'strong-testimonials-review-button',
'dismiss' => true,
'callback' => 'handleStButtonClick',
),
array(
'label' => esc_html( $this->messages['no_rate'] ),
'id' => 'strong-testimonials-no-rate',
'class' => 'strong-testimonials-review-button',
'dismiss' => true,
'callback' => 'handleStButtonClick',
),
array(
'label' => esc_html( $this->messages['rate'] ),
'id' => 'strong-testimonials-rate',
'url' => esc_url( $url ),
'class' => 'strong-testimonials-review-button',
'variant' => 'primary',
'target' => '_BLANK',
'dismiss' => true,
'callback' => 'handleStButtonClick',
),
),
'source' => array(
'slug' => 'strong-testimonials',
'name' => 'Strong Testimonials',
),
);

?>
<div id="<?php echo esc_attr( $this->slug ); ?>-strong-testimonials-review-notice" class="notice notice-success is-dismissible" style="margin-top:30px;">
<p><?php echo sprintf( esc_html( $this->messages['notice'] ), esc_attr( $this->value ) ); ?></p>
<p class="actions">
<a id="strong-testimonials-rate" href="<?php echo esc_url( $url ); ?>" target="_blank" class="button button-primary strong-testimonials-review-button">
<?php echo esc_html( $this->messages['rate'] ); ?>
</a>
<a id="strong-testimonials-later" href="#" style="margin-left:10px" class="strong-testimonials-review-button"><?php echo esc_html( $this->messages['rated'] ); ?></a>
<a id="strong-testimonials-no-rate" href="#" style="margin-left:10px" class="strong-testimonials-review-button"><?php echo esc_html( $this->messages['no_rate'] ); ?></a>
</p>
</div>
<?php
WPChill_Notifications::add_notification( 'wpmtst-five-star-rate', $notice );
}

public function ajax() {
Expand All @@ -89,12 +117,10 @@ public function ajax() {

$time = get_option( 'strong-testimonials-rate-time' );

if ( 'strong-testimonials-rate' === $_POST['check'] ) {
$time = time() + YEAR_IN_SECONDS * 1;
} elseif ( 'strong-testimonials-later' === array( 'check' ) ) {
if ( 'strong-testimonials-rate' === $_POST['check'] || 'strong-testimonials-no-rate' === $_POST['check'] ) {
$time = time() + YEAR_IN_SECONDS * 5;
} else {
$time = time() + WEEK_IN_SECONDS;
} elseif ( 'strong-testimonials-no-rate' === $_POST['check'] ) {
$time = time() + YEAR_IN_SECONDS * 1;
}

update_option( 'strong-testimonials-rate-time', $time );
Expand All @@ -110,39 +136,19 @@ public function ajax_script() {
$ajax_nonce = wp_create_nonce( 'strong-testimonials-review' );

?>

<script type="text/javascript">
jQuery( document ).ready( function( $ ){

$( '.strong-testimonials-review-button' ).on('click', function( evt ){
var href = $(this).attr('href'),
id = $(this).attr('id');

if ( 'strong-testimonials-rate' != id ) {
evt.preventDefault();
}

var data = {
action: 'strong-testimonials_review',
security: '<?php echo $ajax_nonce; ?>',
check: id
};
function handleStButtonClick( element ) {
console.error('clicky');
var data = {
action: 'strong-testimonials_review',
security: '<?php echo esc_js( $ajax_nonce ); ?>',
check: element.url ? 'strong-testimonials-rate' : element.id
};

if ( 'strong-testimonials-rated' === id ) {
data['strong-testimonials-review'] = 1;
}

$.post( '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', data, function( response ) {
$( '#<?php echo esc_attr( $this->slug ); ?>-strong-testimonials-review-notice' ).slideUp( 'fast', function() {
$( this ).remove();
} );
});

} );

});
jQuery.post('<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', data );
}
</script>

<?php
}

Expand Down
5 changes: 0 additions & 5 deletions admin/class-strong-testimonials-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,6 @@ public static function update_log() {
update_option( 'wpmtst_update_log', $log );
}

public static function update_admin_notices() {
wpmtst_add_admin_notice( 'feedback-notice', true );
wpmtst_add_admin_notice( 'upsell-notice', true );
}

/**
* Return admin role.
*
Expand Down
Loading