-
Notifications
You must be signed in to change notification settings - Fork 3
/
comment-mention.php
184 lines (157 loc) · 4.92 KB
/
comment-mention.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* Plugin Name: Comment Mention
* Description: Mention user in comments. Mentioned user will get email notification
* Author: Bunty
* Author URI: https://bhargavb.com
* Text Domain: comment-mention
* Domain Path: /languages
* Version: 1.7.14
*
* @package Comment_Mention
*/
/**
* Main file, contains the plugin metadata and activation processes
*
* @package Comment_Mention
* @subpackage Main
*/
if ( ! defined( 'CMT_MNTN_VERSION' ) ) {
/**
* The version of the plugin.
*/
define( 'CMT_MNTN_VERSION', '1.7.14' );
}
if ( ! defined( 'CMT_MNTN_PATH' ) ) {
/**
* The server file system path to the plugin directory.
*/
define( 'CMT_MNTN_PATH', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'CMT_MNTN_URL' ) ) {
/**
* The url to the plugin directory.
*/
define( 'CMT_MNTN_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'CMT_MNTN_BASE_NAME' ) ) {
/**
* The url to the plugin directory.
*/
define( 'CMT_MNTN_BASE_NAME', plugin_basename( __FILE__ ) );
}
/**
* Function to identify if plugin is active.
*
* @return bool
*/
function cmt_mntn_plugin_active() {
__return_true();
}
/**
* Setting link for plugin.
*
* @param array $links Array of plugin setting link.
* @return array
*/
function cmt_mntn_setting_page_link( $links ) {
$settings_link = sprintf(
'<a href="%1$s">%2$s</a> | <a href="%3$s" target="_blank">%4$s</a>',
esc_url( admin_url( 'admin.php?page=comment-mention' ) ),
esc_html__( 'Settings', 'comment-mention' ),
esc_url( 'https://checkout.freemius.com/mode/dialog/plugin/10495/plan/17738/' ),
esc_html__( 'Go Pro', 'comment-mention' )
);
array_push( $links, $settings_link );
return $links;
}
add_filter( 'plugin_action_links_' . CMT_MNTN_BASE_NAME, 'cmt_mntn_setting_page_link' );
/**
* Show admin notice.
*
* @return void
*/
function sample_admin_notice__success() {
// Check if notice is dismissed.
$notice_dissmissed = get_option( 'dismiss-cm-notice' );
// If notice is dismissed, then don't display it.
if ( ! empty( $notice_dissmissed ) && 1 == $notice_dissmissed ) {
return;
}
?>
<div class="notice notice-success is-dismissible">
<?php
echo sprintf(
'<p>%1$s</p><a href="%2$s" target="_blank">%3$s</a> | <a href="%4$s">%5$s</a>',
esc_html__( 'Do you like Comment Mention plugin? Checkout our Pro plugin.', 'comment-mention' ),
'https://biliplugins.com/comment-mention-pro-product/',
esc_html__( 'Go Pro', 'comment-mention' ),
esc_url( wp_nonce_url( add_query_arg( 'dismiss-cm-notice', '1' ), 'dismiss-cm-notice-' . get_current_user_id() ) ),
esc_html__( 'Dismiss this notice', 'comment-mention' )
);
?>
</div>
<?php
}
add_action( 'admin_notices', 'sample_admin_notice__success' );
/**
* Register dismissal of admin notices.
*/
function cmt_mntn_dismiss() {
if ( isset( $_GET['dismiss-cm-notice'] ) && check_admin_referer( 'dismiss-cm-notice-' . get_current_user_id() ) ) {
update_option( 'dismiss-cm-notice', 1 );
}
}
add_action( 'admin_init', 'cmt_mntn_dismiss' );
/**
* Reset admin notice on plugin upgrade.
*
* @param object $upgrader_object Upgrade object.
* @param array $options Array of plugin related data.
* @return void
*/
function cmt_mntn_upgrade_function( $upgrader_object, $options ) {
$current_plugin_path_name = plugin_basename( __FILE__ );
if ( $options['action'] == 'update' && $options['type'] == 'plugin' ) {
foreach ( $options['plugins'] as $each_plugin ) {
if ( $each_plugin == $current_plugin_path_name ) {
$notice_dissmissed = get_option( 'dismiss-cm-notice' );
if ( ! empty( $notice_dissmissed ) ) {
delete_option( 'dismiss-cm-notice' );
}
}
}
}
}
add_action( 'upgrader_process_complete', 'cmt_mntn_upgrade_function', 10, 2 );
/**
* Reset option to show admin notice.
*/
function cmt_mntn_deactivation_callback() {
// Check if notice is dismisses.
$notice_dissmissed = get_option( 'dismiss-cm-notice' );
// If dismissed, then reset to show when plugin is re-activate.
if ( ! empty( $notice_dissmissed ) ) {
delete_option( 'dismiss-cm-notice' );
}
}
register_deactivation_hook( __FILE__, 'cmt_mntn_deactivation_callback' );
register_activation_hook( __FILE__, 'cmt_mntn_deactivation_callback' );
/**
* Apply transaltion file as per WP language.
*/
function cmt_mntn_text_domain_loader() {
// Get mo file as per current locale.
$mofile = CMT_MNTN_PATH . 'languages/' . get_locale() . '.mo';
// If file does not exists, then applu default mo.
if ( ! file_exists( $mofile ) ) {
$mofile = CMT_MNTN_PATH . 'languages/default.mo';
}
load_textdomain( 'comment-mention', $mofile );
}
add_action( 'plugins_loaded', 'cmt_mntn_text_domain_loader' );
// Include admin functions file.
require CMT_MNTN_PATH . 'app/includes/common-functions.php';
require CMT_MNTN_PATH . 'app/main/class-comment-mention.php';
require CMT_MNTN_PATH . 'app/main/class-bbpress-user-mention.php';
require CMT_MNTN_PATH . 'app/admin/class-admin-comment-mention.php';