|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BetterOptin Misc Admin Functions |
|
4
|
|
|
* |
|
5
|
|
|
* @package BetterOptin/Misc Admin |
|
6
|
|
|
* @author ThemeAvenue <[email protected]> |
|
7
|
|
|
* @license GPL-2.0+ |
|
8
|
|
|
* @link http://themeavenue.net |
|
9
|
|
|
* @copyright 2015 ThemeAvenue |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// If this file is called directly, abort. |
|
13
|
|
|
if ( ! defined( 'WPINC' ) ) { |
|
14
|
|
|
die; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
add_action( 'admin_init', 'wpbo_disable_autosave' ); |
|
18
|
|
|
/** |
|
19
|
|
|
* Disable auto-save for this post type. |
|
20
|
|
|
* |
|
21
|
|
|
* Autosave is causing issues when user clicks the "Customize" button |
|
22
|
|
|
* directly in the template selection metabox. |
|
23
|
|
|
* |
|
24
|
|
|
* Moreover, in our case, auto-save will only affect the popup title |
|
25
|
|
|
* which is not critical. |
|
26
|
|
|
* |
|
27
|
|
|
* @since 1.0.0 |
|
28
|
|
|
* @return null |
|
29
|
|
|
*/ |
|
30
|
|
|
function wpbo_disable_autosave() { |
|
31
|
|
|
|
|
32
|
|
|
if ( isset( $_GET['post_type'] ) && 'wpbo-popup' == $_GET['post_type'] || isset( $_GET['post'] ) && 'wpbo-popup' == get_post_type( intval( $_GET['post'] ) ) ) { |
|
33
|
|
|
wp_deregister_script( 'autosave' ); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
add_filter( 'plugin_action_links_' . WPBO_BASENAME, 'wpbo_add_action_links' ); |
|
39
|
|
|
/** |
|
40
|
|
|
* Add settings action link to the plugins page. |
|
41
|
|
|
* |
|
42
|
|
|
* @since 1.0.0 |
|
43
|
|
|
*/ |
|
44
|
|
|
function wpbo_add_action_links( $links ) { |
|
45
|
|
|
|
|
46
|
|
|
return array_merge( |
|
47
|
|
|
array( |
|
48
|
|
|
'settings' => '<a href="' . add_query_arg( array( 'post_type' => 'wpbo-popup', 'page' => 'edit.php?post_type=wpbo-popup-settings' ), admin_url( 'edit.php' ) ) . '">' . __( 'Settings', 'betteroptin' ) . '</a>' |
|
49
|
|
|
), |
|
50
|
|
|
$links |
|
51
|
|
|
); |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
add_filter( 'post_row_actions', 'wpbo_row_action', 10, 2 ); |
|
57
|
|
|
/** |
|
58
|
|
|
* Add link to action row. |
|
59
|
|
|
* |
|
60
|
|
|
* Add a direct link to customizer in the post |
|
61
|
|
|
* action row. |
|
62
|
|
|
* |
|
63
|
|
|
* @param array $actions List of available actions |
|
64
|
|
|
* @param opject $post Post currently parsed |
|
65
|
|
|
* @return array List of actions containing the customizer link |
|
66
|
|
|
*/ |
|
67
|
|
|
function wpbo_row_action( $actions, $post ) { |
|
68
|
|
|
|
|
69
|
|
|
/* Only add the link for our post type */ |
|
70
|
|
|
if( 'wpbo-popup' != $post->post_type ) |
|
71
|
|
|
return $actions; |
|
72
|
|
|
|
|
73
|
|
|
/* Only add the link if a template is set */ |
|
74
|
|
|
if( '' != get_post_meta( $post->ID, 'wpbo_template', true ) ) { |
|
75
|
|
|
|
|
76
|
|
|
$actions['wpbo_customize'] = sprintf( '<a href="%s" class="google_link">%s</a>', add_query_arg( array( 'post_type' => 'wpbo-popup', 'page' => 'wpbo-customizer', 'wpbo_popup' => $post->ID ), admin_url( 'edit.php' ) ), __( 'Customize', 'betteroptin' ) ); |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$actions['wpbo_analytics'] = sprintf( '<a href="%s" class="google_link">%s</a>', add_query_arg( array( 'post_type' => 'wpbo-popup', 'page' => 'wpbo-analytics', 'popup' => $post->ID, 'period' => 'today' ), admin_url( 'edit.php' ) ), __( 'Stats', 'betteroptin' ) ); |
|
81
|
|
|
|
|
82
|
|
|
return $actions; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
add_filter( 'gettext', 'wpbo_change_publish_button_label', 10, 2 ); |
|
86
|
|
|
/** |
|
87
|
|
|
* Change publish button label. |
|
88
|
|
|
* |
|
89
|
|
|
* Change Publish button label to Save on new popups |
|
90
|
|
|
* as the button action is now save as draft instead of publish. |
|
91
|
|
|
* |
|
92
|
|
|
* @since 1.0.0 |
|
93
|
|
|
* @see Better_Optin_Admin::save_before_publish() |
|
94
|
|
|
* |
|
95
|
|
|
* @param string $translation Current text string |
|
96
|
|
|
* @param string $text String translation |
|
97
|
|
|
* |
|
98
|
|
|
* @return string New label |
|
99
|
|
|
*/ |
|
100
|
|
|
function wpbo_change_publish_button_label( $translation, $text ) { |
|
101
|
|
|
|
|
102
|
|
|
global $typenow; |
|
103
|
|
|
|
|
104
|
|
|
if ( 'wpbo-popup' == $typenow ) { |
|
105
|
|
|
if ( ( ! isset( $_GET['post'] ) || isset( $_GET['post'] ) && '' == get_post_meta( intval( $_GET['post'] ), '_wpbo_template_display', true ) ) && 'Publish' == $text ) { |
|
106
|
|
|
$translation = __( 'Save', 'betteroptin' ); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
return apply_filters( 'wpbo_publish_button_label', $translation, $text ); |
|
111
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
add_filter( 'admin_footer_text', 'wpbo_copyright', 10, 2 ); |
|
115
|
|
|
/** |
|
116
|
|
|
* Add copyright. |
|
117
|
|
|
* |
|
118
|
|
|
* Add a copyright text at the bottom of all plugin pages. |
|
119
|
|
|
* |
|
120
|
|
|
* @since 1.0.0 |
|
121
|
|
|
* |
|
122
|
|
|
* @param string $text WordPress footer text |
|
123
|
|
|
* |
|
124
|
|
|
* @return string |
|
125
|
|
|
*/ |
|
126
|
|
|
function wpbo_copyright( $text ) { |
|
127
|
|
|
|
|
128
|
|
|
if ( ! wpbo_is_plugin_page() ) { |
|
129
|
|
|
return $text; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
return sprintf( __( '<a %s>BetterOptin</a> was made with ❤ by <a %s>ThemeAvenue</a>.', 'betteroptin' ), 'href="https://betteropt.in" target="_blank"', 'href="https://themeavenue.net" target="_blank"' ); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
add_action( 'plugins_loaded', 'wpbo_remote_notices', 11 ); |
|
136
|
|
|
/** |
|
137
|
|
|
* Enable Remote Dashboard Notifications |
|
138
|
|
|
* |
|
139
|
|
|
* @since 1.0.0 |
|
140
|
|
|
*/ |
|
141
|
|
|
function wpbo_remote_notices() { |
|
142
|
|
|
|
|
143
|
|
|
/* Load RDN class */ |
|
144
|
|
|
if ( ! class_exists( 'TAV_Remote_Notification_Client' ) ) { |
|
145
|
|
|
require_once( WPBO_PATH . 'includes/admin/class-remote-notification.php' ); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/* Instantiate the class */ |
|
149
|
|
|
new TAV_Remote_Notification_Client( 5, '278afa858b56d071', 'http://api.themeavenue.net?post_type=notification' ); |
|
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Check if Tour was Completed |
|
155
|
|
|
* |
|
156
|
|
|
* Check the user dismissed pointers and verify if |
|
157
|
|
|
* the tour was already completed (or dismissed). |
|
158
|
|
|
* |
|
159
|
|
|
* @since 1.0.0 |
|
160
|
|
|
* @return boolean True if completed, false otherwise |
|
161
|
|
|
*/ |
|
162
|
|
|
function wpbo_is_tour_completed() { |
|
163
|
|
|
|
|
164
|
|
|
$user_id = get_current_user_id(); |
|
165
|
|
|
|
|
166
|
|
|
/* Make sure we have a user */ |
|
167
|
|
|
if ( 0 === $user_id ) { |
|
168
|
|
|
return false; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/* Get dismissed pointers */ |
|
172
|
|
|
$dismissed = get_user_meta( $user_id, 'dismissed_wp_pointers', true ); |
|
173
|
|
|
$pointers = explode( ',', $dismissed ); |
|
174
|
|
|
|
|
175
|
|
|
if ( in_array( 'wpbo_tour', $pointers ) ) { |
|
176
|
|
|
return true; |
|
177
|
|
|
} else { |
|
178
|
|
|
return false; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Get link to the plugin settings page |
|
185
|
|
|
* |
|
186
|
|
|
* @since 2.0 |
|
187
|
|
|
* |
|
188
|
|
|
* @param string $tab Optional tab to link to |
|
189
|
|
|
* |
|
190
|
|
|
* @return string |
|
191
|
|
|
*/ |
|
192
|
|
|
function wpbo_get_settings_page_link( $tab = '' ) { |
|
193
|
|
|
|
|
194
|
|
|
$args = array( 'post_type' => 'wpbo-popup', 'page' => 'wpbo-settings' ); |
|
195
|
|
|
|
|
196
|
|
|
if ( ! empty( $tab ) ) { |
|
197
|
|
|
$args['tab'] = sanitize_text_field( $tab ); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
return esc_url( add_query_arg( $args, admin_url( 'edit.php' ) ) ); |
|
201
|
|
|
|
|
202
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: