| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class that handles displaying of review notice |
| 5 |
* |
| 6 |
* @since 4.1.3 |
| 7 |
*/ |
| 8 |
class RM_Review_Message { |
| 9 |
|
| 10 |
/** |
| 11 |
* Variable to hold how many results needed to show message |
| 12 |
* |
| 13 |
* @since 4.1.3 |
| 14 |
*/ |
| 15 |
public $trigger = -1; |
| 16 |
|
| 17 |
/** |
| 18 |
* Main Construct Function |
| 19 |
* |
| 20 |
* Adds the notice check to init and then check to display message |
| 21 |
* |
| 22 |
* @since 4.1.3 |
| 23 |
*/ |
| 24 |
function __construct() { |
| 25 |
$this->add_hooks(); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Adds check message to admin_init hook |
| 30 |
* |
| 31 |
* @since 4.1.3 |
| 32 |
*/ |
| 33 |
public function add_hooks() { |
| 34 |
add_action( 'admin_init', array( $this, 'check_message_display' ) ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Checks if message should be displayed |
| 39 |
* |
| 40 |
* @since 4.1.3 |
| 41 |
*/ |
| 42 |
public function check_message_display() { |
| 43 |
$this->admin_notice_check(); |
| 44 |
$this->trigger = $this->check_message_trigger(); |
| 45 |
if ( $this->trigger !== -1 ) { |
| 46 |
$amount = $this->check_results_amount(); |
| 47 |
if ( $amount >= $this->trigger ) { |
| 48 |
add_action( 'admin_notices', array( $this, 'display_admin_message' ) ); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Retrieves what the next trigger value is |
| 55 |
* |
| 56 |
* @since 4.1.3 |
| 57 |
* @return int The amount of menus needed to display message |
| 58 |
*/ |
| 59 |
public function check_message_trigger() { |
| 60 |
$trigger = get_option( 'rm_review_message_trigger' ); |
| 61 |
if ( empty( $trigger ) || is_null( $trigger ) ) { |
| 62 |
add_option('rm_review_message_trigger', 1 ); |
| 63 |
return 1; |
| 64 |
} |
| 65 |
return intval( $trigger ); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Checks the amount of Menus |
| 70 |
* |
| 71 |
* @return int The amount of menus |
| 72 |
*/ |
| 73 |
public function check_results_amount() { |
| 74 |
global $wpdb; |
| 75 |
$amount = $wpdb->get_var("SELECT COUNT(*) FROM `". $wpdb->prefix ."posts` |
| 76 |
WHERE post_type = 'rmp_menu'"); |
| 77 |
return $amount; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Displays the message |
| 82 |
* |
| 83 |
* Displays the message asking for review |
| 84 |
* |
| 85 |
* |
| 86 |
*/ |
| 87 |
public function display_admin_message() { |
| 88 |
$already_url = esc_url( add_query_arg( 'rm_review_notice_check', 'already_did' ) ); |
| 89 |
$nope_url = esc_url( add_query_arg( 'rm_review_notice_check', 'remove_message' ) ); |
| 90 |
echo "<div class='updated'><br />"; |
| 91 |
echo sprintf( __('Greetings! I just noticed that you have created %d Menus. That is |
| 92 |
awesome! Could you please help me out by giving this plugin a 5-star rating on WordPress? This |
| 93 |
will help us by helping other users discover this plugin. %s', 'responsive-menu-pro'), |
| 94 |
$this->check_results_amount(), |
| 95 |
'<br /><strong><em>~ RM Team</em></strong><br /><br />' |
| 96 |
); |
| 97 |
echo ' <a target="_blank" href="https://wordpress.org/support/plugin/responsive-menu/reviews/#new-topic-0" class="button-primary">' . __( 'Yeah, you deserve it!', 'responsive-menu-pro' ) . '</a>'; |
| 98 |
echo ' <a href="' . esc_url( $already_url ) . '" class="button-secondary">' . __( 'I already did!', 'responsive-menu-pro' ) . '</a>'; |
| 99 |
echo ' <a href="' . esc_url( $nope_url ) . '" class="button-secondary">' . __( 'No, this plugin is not good enough', 'responsive-menu-pro' ) . '</a>'; |
| 100 |
echo "<br /><br /></div>"; |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Checks if a link in the admin message has been clicked |
| 105 |
* |
| 106 |
* @since 4.1.3 |
| 107 |
*/ |
| 108 |
public function admin_notice_check() { |
| 109 |
if ( isset( $_GET["rm_review_notice_check"] ) && $_GET["rm_review_notice_check"] == 'remove_message' ) { |
| 110 |
$this->trigger = $this->check_message_trigger(); |
| 111 |
$update_trigger = -1; |
| 112 |
if ( $this->trigger === -1 ) { |
| 113 |
exit; |
| 114 |
} else if ( $this->trigger === 1 ) { |
| 115 |
$update_trigger = 5; |
| 116 |
} else if ( $this->trigger === 5 ) { |
| 117 |
$update_trigger = 10; |
| 118 |
} else if ( $this->trigger === 10 ) { |
| 119 |
$update_trigger = -1; |
| 120 |
} |
| 121 |
update_option( 'rm_review_message_trigger', $update_trigger ); |
| 122 |
} |
| 123 |
if ( isset( $_GET["rm_review_notice_check"] ) && $_GET["rm_review_notice_check"] == 'already_did' ) { |
| 124 |
update_option( 'rm_review_message_trigger', -1 ); |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
$rm_review_message = new RM_Review_Message(); |