| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* get_templates_dir function. |
| 5 |
* |
| 6 |
* The function returns template dir path. |
| 7 |
* |
| 8 |
* @since 1.2.1.3 |
| 9 |
* |
| 10 |
* @return string Templates dir path. |
| 11 |
*/ |
| 12 |
function uwp_get_templates_dir() { |
| 13 |
return USERSWP_PATH . 'templates'; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* get_templates_url function. |
| 18 |
* |
| 19 |
* The function returns template dir url. |
| 20 |
* |
| 21 |
* @since 1.2.1.3 |
| 22 |
* |
| 23 |
* @return string Templates dir url. |
| 24 |
*/ |
| 25 |
function uwp_get_templates_url() { |
| 26 |
return USERSWP_PLUGIN_URL . '/templates'; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* get_theme_template_dir_name function. |
| 31 |
* |
| 32 |
* The function returns theme template dir name. |
| 33 |
* |
| 34 |
* @since 1.2.1.3 |
| 35 |
* |
| 36 |
* @return string Theme template dir name. |
| 37 |
*/ |
| 38 |
function uwp_get_theme_template_dir_name() { |
| 39 |
return untrailingslashit( apply_filters( 'uwp_templates_dir', 'userswp' ) ); |
| 40 |
} |
| 41 |
|
| 42 |
/* |
| 43 |
* Function to include the template file. |
| 44 |
* |
| 45 |
* @param string $type Template type. |
| 46 |
* @param string $template_path Template path. (default: ''). |
| 47 |
* |
| 48 |
* @deprecated 1.2.1.3 Use uwp_get_template() |
| 49 |
* |
| 50 |
*/ |
| 51 |
function uwp_locate_template($type, $template_path = "" ){ |
| 52 |
|
| 53 |
if(!$template_path){ |
| 54 |
$template_path = uwp_get_templates_dir(); |
| 55 |
} |
| 56 |
|
| 57 |
$template = locate_template(array("userswp/".$type.".php")); |
| 58 |
if (!$template) { |
| 59 |
$template = untrailingslashit( $template_path ) . '/' .$type.'.php'; |
| 60 |
} |
| 61 |
|
| 62 |
$template = apply_filters('uwp_template_'.$type, $template, $template_path); |
| 63 |
|
| 64 |
if (file_exists($template)) { |
| 65 |
include($template); |
| 66 |
} |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Function to display no user found message from template. |
| 72 |
*/ |
| 73 |
function uwp_no_users_found($args = array()){ |
| 74 |
$design_style = uwp_get_option("design_style",'bootstrap'); |
| 75 |
$template = $design_style ? $design_style."/no-users-found.php" : "no-users-found.php"; |
| 76 |
uwp_get_template( $template, $args ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Get other templates passing attributes and including the file. |
| 81 |
* |
| 82 |
* @param string $template_name Template name. |
| 83 |
* @param array $args Arguments. (default: array). |
| 84 |
* @param string $template_path Template path. (default: ''). |
| 85 |
* @param string $default_path Default path. (default: ''). |
| 86 |
*/ |
| 87 |
function uwp_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
| 88 |
if ( ! empty( $args ) && is_array( $args ) ) { |
| 89 |
extract( $args ); |
| 90 |
} |
| 91 |
|
| 92 |
$located = UsersWP_Templates::locate_template( $template_name, $template_path, $default_path ); |
| 93 |
|
| 94 |
if ( ! file_exists( $located ) ) { |
| 95 |
uwp_doing_it_wrong( __FUNCTION__, sprintf( __( '%s does not exist.', 'userswp' ), '<code>' . $located . '</code>' ), '2.1' ); |
| 96 |
|
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
// Allow 3rd party plugin filter template file from their plugin. |
| 101 |
$located = apply_filters( 'uwp_get_template', $located, $template_name, $args, $template_path, $default_path ); |
| 102 |
|
| 103 |
do_action( 'uwp_before_template_part', $template_name, $template_path, $located, $args ); |
| 104 |
|
| 105 |
include( $located ); |
| 106 |
|
| 107 |
do_action( 'uwp_after_template_part', $template_name, $template_path, $located, $args ); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Like uwp_get_template, but returns the HTML instead of outputting. |
| 112 |
* |
| 113 |
* @see uwp_get_template |
| 114 |
* @since 1.2.1.3 |
| 115 |
* @param string $template_name Template name. |
| 116 |
* @param array $args Arguments. (default: array). |
| 117 |
* @param string $template_path Template path. (default: ''). |
| 118 |
* @param string $default_path Default path. (default: ''). |
| 119 |
* |
| 120 |
* @return string |
| 121 |
*/ |
| 122 |
function uwp_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
| 123 |
ob_start(); |
| 124 |
uwp_get_template( $template_name, $args, $template_path, $default_path ); |
| 125 |
return ob_get_clean(); |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* doing_it_wrong function. |
| 130 |
* |
| 131 |
* A function is called when mark something as being incorrectly called. |
| 132 |
* |
| 133 |
* @since 1.2.1.3 |
| 134 |
* |
| 135 |
* @param string $function The function that was called. |
| 136 |
* @param string $message A message explaining what has been done incorrectly. |
| 137 |
* @param string $version The version of WordPress where the message was added. |
| 138 |
*/ |
| 139 |
function uwp_doing_it_wrong( $function, $message, $version ) { |
| 140 |
$message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
| 141 |
|
| 142 |
if ( defined( 'DOING_AJAX' ) ) { |
| 143 |
do_action( 'doing_it_wrong_run', $function, $message, $version ); |
| 144 |
uwp_error_log( $function . ' was called incorrectly. ' . $message . '. This message was added in version ' . $version . '.' ); |
| 145 |
} else { |
| 146 |
_doing_it_wrong( $function, $message, $version ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
function uwp_password_strength_inline_js() { |
| 151 |
wp_enqueue_script( 'password-strength-meter' ); // add scripts |
| 152 |
?> |
| 153 |
<script> |
| 154 |
jQuery( document ).ready( function( $ ) { |
| 155 |
|
| 156 |
$( 'body' ).on( 'keyup', 'input[name=password], input[name=confirm_password]', |
| 157 |
function( event ) { |
| 158 |
var $form = $(this).closest('form'); |
| 159 |
if( ! $form.hasClass('uwp-login-form') ) { |
| 160 |
uwp_checkPasswordStrength( |
| 161 |
$form.find('input[name=password]'), |
| 162 |
$form.find('input[name=confirm_password]'), |
| 163 |
$form.find('#uwp-password-strength'), |
| 164 |
$form.find('button[type="submit"], input[type="submit"]'), |
| 165 |
['black', 'listed', 'word'] |
| 166 |
); |
| 167 |
} |
| 168 |
} |
| 169 |
); |
| 170 |
}); |
| 171 |
</script> |
| 172 |
<?php |
| 173 |
} |
| 174 |
|
| 175 |
/** |
| 176 |
* Get all UsersWP screen ids. |
| 177 |
* |
| 178 |
* @since 1.2.3.22 |
| 179 |
* |
| 180 |
* @return array UsersWP screen IDs |
| 181 |
*/ |
| 182 |
function uwp_get_screen_ids() { |
| 183 |
$screen_ids = array( |
| 184 |
'toplevel_page_userswp', |
| 185 |
'userswp_page_uwp_form_builder', |
| 186 |
'userswp_page_uwp_tools', |
| 187 |
'userswp_page_uwp_status', |
| 188 |
'userswp_page_uwp-addons', |
| 189 |
'userswp_page_uwp_user_types', |
| 190 |
'profile', |
| 191 |
'users', |
| 192 |
'user-edit', |
| 193 |
); |
| 194 |
|
| 195 |
// Check for translated screen id. |
| 196 |
$uwp_screen_id = sanitize_title( __( 'UsersWP', 'userswp' ) ); |
| 197 |
|
| 198 |
if ( $uwp_screen_id != 'userswp' ) { |
| 199 |
$screen_ids[] = 'toplevel_page_' . $uwp_screen_id; |
| 200 |
$screen_ids[] = $uwp_screen_id . '_page_uwp_form_builder'; |
| 201 |
$screen_ids[] = $uwp_screen_id . '_page_uwp_tools'; |
| 202 |
$screen_ids[] = $uwp_screen_id . '_page_uwp_status'; |
| 203 |
$screen_ids[] = $uwp_screen_id . '_page_uwp-addons'; |
| 204 |
$screen_ids[] = $uwp_screen_id . '_page_uwp-user_types'; |
| 205 |
} |
| 206 |
|
| 207 |
return apply_filters( 'uwp_screen_ids', $screen_ids ); |
| 208 |
} |