@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package GetPaid |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Generates a users select dropdown. |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | * @param array $args |
| 17 | 17 | * @see wp_dropdown_users |
| 18 | 18 | */ |
| 19 | -function wpinv_dropdown_users( $args = '' ) { |
|
| 19 | +function wpinv_dropdown_users($args = '') { |
|
| 20 | 20 | |
| 21 | - if ( is_array( $args ) && ! empty( $args['show'] ) && 'display_name_with_email' == $args['show'] ) { |
|
| 21 | + if (is_array($args) && !empty($args['show']) && 'display_name_with_email' == $args['show']) { |
|
| 22 | 22 | $args['show'] = 'display_name_with_login'; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - return wp_dropdown_users( $args ); |
|
| 25 | + return wp_dropdown_users($args); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | * @return string capability to check against |
| 33 | 33 | * @param string $capalibilty Optional. The alternative capability to check against. |
| 34 | 34 | */ |
| 35 | -function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
|
| 35 | +function wpinv_get_capability($capalibilty = 'manage_invoicing') { |
|
| 36 | 36 | |
| 37 | - if ( current_user_can( 'manage_options' ) ) { |
|
| 37 | + if (current_user_can('manage_options')) { |
|
| 38 | 38 | return 'manage_options'; |
| 39 | 39 | }; |
| 40 | 40 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @return bool |
| 49 | 49 | */ |
| 50 | 50 | function wpinv_current_user_can_manage_invoicing() { |
| 51 | - return current_user_can( wpinv_get_capability() ); |
|
| 51 | + return current_user_can(wpinv_get_capability()); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -57,17 +57,17 @@ discard block |
||
| 57 | 57 | * @since 1.0.19 |
| 58 | 58 | * @return int|WP_Error |
| 59 | 59 | */ |
| 60 | -function wpinv_create_user( $email ) { |
|
| 60 | +function wpinv_create_user($email) { |
|
| 61 | 61 | |
| 62 | 62 | // Prepare user values. |
| 63 | 63 | $args = array( |
| 64 | - 'user_login' => wpinv_generate_user_name( $email ), |
|
| 64 | + 'user_login' => wpinv_generate_user_name($email), |
|
| 65 | 65 | 'user_pass' => wp_generate_password(), |
| 66 | 66 | 'user_email' => $email, |
| 67 | 67 | 'role' => 'subscriber', |
| 68 | 68 | ); |
| 69 | 69 | |
| 70 | - return wp_insert_user( $args ); |
|
| 70 | + return wp_insert_user($args); |
|
| 71 | 71 | |
| 72 | 72 | } |
| 73 | 73 | |
@@ -77,22 +77,22 @@ discard block |
||
| 77 | 77 | * @since 1.0.19 |
| 78 | 78 | * @return bool|WP_User |
| 79 | 79 | */ |
| 80 | -function wpinv_generate_user_name( $prefix = '' ) { |
|
| 80 | +function wpinv_generate_user_name($prefix = '') { |
|
| 81 | 81 | |
| 82 | 82 | // If prefix is an email, retrieve the part before the email. |
| 83 | - $prefix = strtok( $prefix, '@' ); |
|
| 83 | + $prefix = strtok($prefix, '@'); |
|
| 84 | 84 | |
| 85 | 85 | // Trim to 4 characters max. |
| 86 | - $prefix = sanitize_user( $prefix ); |
|
| 86 | + $prefix = sanitize_user($prefix); |
|
| 87 | 87 | |
| 88 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
| 89 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
| 88 | + $illegal_logins = (array) apply_filters('illegal_user_logins', array()); |
|
| 89 | + if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) { |
|
| 90 | 90 | $prefix = 'gtp'; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - $username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
| 94 | - if ( username_exists( $username ) ) { |
|
| 95 | - return wpinv_generate_user_name( $username ); |
|
| 93 | + $username = $prefix . '_' . zeroise(wp_rand(0, 9999), 4); |
|
| 94 | + if (username_exists($username)) { |
|
| 95 | + return wpinv_generate_user_name($username); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | return $username; |
@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | // Slug - invoices. |
| 112 | 112 | 'gp-invoices' => array( |
| 113 | - 'label' => __( 'Invoices', 'invoicing' ), // Name of the tab. |
|
| 113 | + 'label' => __('Invoices', 'invoicing'), // Name of the tab. |
|
| 114 | 114 | 'content' => '[wpinv_history]', // Content of the tab. Or specify "callback" to provide a callback instead. |
| 115 | 115 | 'icon' => 'fas fa-file-invoice', // Shown on some profile plugins. |
| 116 | 116 | ), |
| 117 | 117 | |
| 118 | 118 | 'gp-subscriptions' => array( |
| 119 | - 'label' => __( 'Subscriptions', 'invoicing' ), |
|
| 119 | + 'label' => __('Subscriptions', 'invoicing'), |
|
| 120 | 120 | 'content' => '[wpinv_subscriptions]', |
| 121 | 121 | 'icon' => 'fas fa-redo', |
| 122 | 122 | ) |
| 123 | 123 | ); |
| 124 | 124 | |
| 125 | - return apply_filters( 'getpaid_user_content_tabs', $tabs ); |
|
| 125 | + return apply_filters('getpaid_user_content_tabs', $tabs); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -132,19 +132,19 @@ discard block |
||
| 132 | 132 | * @param array $tab |
| 133 | 133 | * @return array |
| 134 | 134 | */ |
| 135 | -function getpaid_prepare_user_content_tab( $tab ) { |
|
| 135 | +function getpaid_prepare_user_content_tab($tab) { |
|
| 136 | 136 | |
| 137 | - if ( ! empty( $tab['callback'] ) ) { |
|
| 138 | - return call_user_func( $tab['callback'] ); |
|
| 137 | + if (!empty($tab['callback'])) { |
|
| 138 | + return call_user_func($tab['callback']); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if ( ! empty( $tab['content'] ) ) { |
|
| 142 | - return convert_smilies( capital_P_dangit( wp_filter_content_tags( do_shortcode( shortcode_unautop( wpautop( wptexturize( do_blocks( $tab['content'] ) ) ) ) ) ) ) ); |
|
| 141 | + if (!empty($tab['content'])) { |
|
| 142 | + return convert_smilies(capital_P_dangit(wp_filter_content_tags(do_shortcode(shortcode_unautop(wpautop(wptexturize(do_blocks($tab['content'])))))))); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $notice = aui()->alert( |
| 146 | 146 | array( |
| 147 | - 'content' => __( 'This tab has no content or content callback.', 'invoicing' ), |
|
| 147 | + 'content' => __('This tab has no content or content callback.', 'invoicing'), |
|
| 148 | 148 | 'type' => 'error', |
| 149 | 149 | ) |
| 150 | 150 | ); |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | * @param string $default |
| 161 | 161 | * @return array |
| 162 | 162 | */ |
| 163 | -function getpaid_get_tab_url( $tab, $default ) { |
|
| 163 | +function getpaid_get_tab_url($tab, $default) { |
|
| 164 | 164 | global $getpaid_tab_url; |
| 165 | 165 | |
| 166 | - if ( empty( $getpaid_tab_url ) ) { |
|
| 166 | + if (empty($getpaid_tab_url)) { |
|
| 167 | 167 | return $default; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - return sprintf( $getpaid_tab_url, $tab ); |
|
| 170 | + return sprintf($getpaid_tab_url, $tab); |
|
| 171 | 171 | |
| 172 | 172 | } |
| 173 | 173 | |
@@ -186,27 +186,27 @@ discard block |
||
| 186 | 186 | * @param array $tabs |
| 187 | 187 | * @return array |
| 188 | 188 | */ |
| 189 | -function getpaid_filter_userswp_account_tabs( $tabs ) { |
|
| 189 | +function getpaid_filter_userswp_account_tabs($tabs) { |
|
| 190 | 190 | |
| 191 | 191 | // Abort if the integration is inactive. |
| 192 | - if ( ! getpaid_is_userswp_integration_active() ) { |
|
| 192 | + if (!getpaid_is_userswp_integration_active()) { |
|
| 193 | 193 | return $tabs; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - $new_tabs = array(); |
|
| 196 | + $new_tabs = array(); |
|
| 197 | 197 | |
| 198 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
| 198 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
| 199 | 199 | |
| 200 | - $new_tabs[ $slug ] = array( |
|
| 201 | - 'title' => $tab[ 'label'], |
|
| 202 | - 'icon' => $tab[ 'icon'], |
|
| 200 | + $new_tabs[$slug] = array( |
|
| 201 | + 'title' => $tab['label'], |
|
| 202 | + 'icon' => $tab['icon'], |
|
| 203 | 203 | ); |
| 204 | 204 | |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - return array_merge( $tabs, $new_tabs ); |
|
| 207 | + return array_merge($tabs, $new_tabs); |
|
| 208 | 208 | } |
| 209 | -add_filter( 'uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs' ); |
|
| 209 | +add_filter('uwp_account_available_tabs', 'getpaid_filter_userswp_account_tabs'); |
|
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | 212 | * Display our UsersWP account tabs. |
@@ -215,18 +215,18 @@ discard block |
||
| 215 | 215 | * @param array $tabs |
| 216 | 216 | * @return array |
| 217 | 217 | */ |
| 218 | -function getpaid_display_userswp_account_tabs( $tab ) { |
|
| 218 | +function getpaid_display_userswp_account_tabs($tab) { |
|
| 219 | 219 | global $getpaid_tab_url; |
| 220 | 220 | |
| 221 | 221 | $our_tabs = getpaid_get_user_content_tabs(); |
| 222 | 222 | |
| 223 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
| 224 | - $getpaid_tab_url = add_query_arg( 'type', '%s', uwp_get_account_page_url() ); |
|
| 225 | - echo getpaid_prepare_user_content_tab( $our_tabs[ $tab ] ); |
|
| 223 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
| 224 | + $getpaid_tab_url = add_query_arg('type', '%s', uwp_get_account_page_url()); |
|
| 225 | + echo getpaid_prepare_user_content_tab($our_tabs[$tab]); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | } |
| 229 | -add_action( 'uwp_account_form_display', 'getpaid_display_userswp_account_tabs' ); |
|
| 229 | +add_action('uwp_account_form_display', 'getpaid_display_userswp_account_tabs'); |
|
| 230 | 230 | |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -237,17 +237,17 @@ discard block |
||
| 237 | 237 | * @param string $tab Current tab. |
| 238 | 238 | * @return string Title. |
| 239 | 239 | */ |
| 240 | -function getpaid_filter_userswp_account_title( $title, $tab ) { |
|
| 240 | +function getpaid_filter_userswp_account_title($title, $tab) { |
|
| 241 | 241 | |
| 242 | - $our_tabs = getpaid_get_user_content_tabs(); |
|
| 242 | + $our_tabs = getpaid_get_user_content_tabs(); |
|
| 243 | 243 | |
| 244 | - if ( getpaid_is_userswp_integration_active() && isset( $our_tabs[ $tab ] ) ) { |
|
| 245 | - return $our_tabs[ $tab ]['label']; |
|
| 244 | + if (getpaid_is_userswp_integration_active() && isset($our_tabs[$tab])) { |
|
| 245 | + return $our_tabs[$tab]['label']; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | return $title; |
| 249 | 249 | } |
| 250 | -add_filter( 'uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2 ); |
|
| 250 | +add_filter('uwp_account_page_title', 'getpaid_filter_userswp_account_title', 10, 2); |
|
| 251 | 251 | |
| 252 | 252 | /** |
| 253 | 253 | * Registers the UsersWP integration settings. |
@@ -256,26 +256,26 @@ discard block |
||
| 256 | 256 | * @param array $settings An array of integration settings. |
| 257 | 257 | * @return array |
| 258 | 258 | */ |
| 259 | -function getpaid_register_userswp_settings( $settings ) { |
|
| 259 | +function getpaid_register_userswp_settings($settings) { |
|
| 260 | 260 | |
| 261 | - if ( defined( 'USERSWP_PLUGIN_FILE' ) ) { |
|
| 261 | + if (defined('USERSWP_PLUGIN_FILE')) { |
|
| 262 | 262 | |
| 263 | 263 | $settings[] = array( |
| 264 | 264 | |
| 265 | 265 | 'id' => 'userswp', |
| 266 | - 'label' => __( 'UsersWP', 'invoicing' ), |
|
| 266 | + 'label' => __('UsersWP', 'invoicing'), |
|
| 267 | 267 | 'settings' => array( |
| 268 | 268 | |
| 269 | 269 | 'userswp_settings' => array( |
| 270 | 270 | 'id' => 'userswp_settings', |
| 271 | - 'name' => '<h3>' . __( 'UsersWP', 'invoicing' ) . '</h3>', |
|
| 271 | + 'name' => '<h3>' . __('UsersWP', 'invoicing') . '</h3>', |
|
| 272 | 272 | 'type' => 'header', |
| 273 | 273 | ), |
| 274 | 274 | |
| 275 | 275 | 'enable_userswp' => array( |
| 276 | 276 | 'id' => 'enable_userswp', |
| 277 | - 'name' => __( 'Enable Integration', 'invoicing' ), |
|
| 278 | - 'desc' => __( 'Display GetPaid items on UsersWP account page.', 'invoicing' ), |
|
| 277 | + 'name' => __('Enable Integration', 'invoicing'), |
|
| 278 | + 'desc' => __('Display GetPaid items on UsersWP account page.', 'invoicing'), |
|
| 279 | 279 | 'type' => 'checkbox', |
| 280 | 280 | 'std' => 1, |
| 281 | 281 | ) |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | |
| 289 | 289 | return $settings; |
| 290 | 290 | } |
| 291 | -add_filter( 'getpaid_integration_settings', 'getpaid_register_userswp_settings' ); |
|
| 291 | +add_filter('getpaid_integration_settings', 'getpaid_register_userswp_settings'); |
|
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | 294 | * Checks if the integration is enabled. |
@@ -297,6 +297,6 @@ discard block |
||
| 297 | 297 | * @return bool |
| 298 | 298 | */ |
| 299 | 299 | function getpaid_is_userswp_integration_active() { |
| 300 | - $enabled = wpinv_get_option( 'enable_userswp', 1 ); |
|
| 301 | - return defined( 'USERSWP_PLUGIN_FILE' ) && ! empty( $enabled ); |
|
| 300 | + $enabled = wpinv_get_option('enable_userswp', 1); |
|
| 301 | + return defined('USERSWP_PLUGIN_FILE') && !empty($enabled); |
|
| 302 | 302 | } |