function block($instance) { extract($instance); $unique = wp_rand(0, 1000); echo '<div id="map-' . $unique . '-' . $block_id . '" class="map"></div>'; echo "<script type='text/javascript'>\n\t\t\t\tjQuery(document).ready(function(\$){\n\t\t\t\t'use strict';\n\t\t\t\t\n\t\t\t\t\tjQuery('#map-" . $unique . "-" . $block_id . "').goMap({ address: \"{$title}\",\n\t\t\t\t\t zoom: 14,\n\t\t\t\t\t mapTypeControl: false,\n\t\t\t\t draggable: false,\n\t\t\t\t scrollwheel: false,\n\t\t\t\t streetViewControl: true,\n\t\t\t\t maptype: 'ROADMAP',\n\t\t\t \t markers: [\n\t\t\t \t\t{ 'address' : \"{$title}\" }\n\t\t\t \t ],\n\t\t\t\t\t icon: '{$image}', \n\t\t\t\t\t addMarker: false\n\t\t\t\t\t});\n\t\t\t\t\n\t\t\t\t});\n\t\t\t</script>"; }
function mm_ux_log($args = array()) { $url = "https://ssl.google-analytics.com/collect"; global $title; if (empty($_SERVER['REQUEST_URI'])) { return; } $path = explode('wp-admin', $_SERVER['REQUEST_URI']); if (empty($path) || empty($path[1])) { $path = array("", " "); } $defaults = array('v' => '1', 'tid' => 'UA-39246514-3', 't' => 'pageview', 'cid' => md5(get_option('siteurl')), 'uid' => md5(get_option('siteurl') . get_current_user_id()), 'cn' => 'mojo_wp_plugin', 'cs' => 'mojo_wp_plugin', 'cm' => 'plugin_admin', 'ul' => get_locale(), 'dp' => $path[1], 'sc' => '', 'ua' => @$_SERVER['HTTP_USER_AGENT'], 'dl' => $path[1], 'dh' => get_option('siteurl'), 'dt' => $title, 'ec' => '', 'ea' => '', 'el' => '', 'ev' => ''); if (isset($_SERVER['REMOTE_ADDR'])) { $defaults['uip'] = $_SERVER['REMOTE_ADDR']; } $params = wp_parse_args($args, $defaults); $test = get_transient('mm_test', ''); if (isset($test['key']) && isset($test['name'])) { $params['cm'] = $params['cm'] . "_" . $test['name'] . "_" . $test['key']; } //use test account for testing if (defined('WP_DEBUG') && WP_DEBUG) { $params['tid'] = 'UA-19617272-27'; } $z = wp_rand(0, 1000000000); $query = http_build_query(array_filter($params)); $args = array('body' => $query, 'method' => 'POST', 'blocking' => false); $url = add_query_arg(array('z' => $z), $url); wp_remote_post($url, $args); }
/** * The Shortcode */ function ebor_tabs_shortcode($atts, $content = null) { global $ebor_tabs_content; global $ebor_tabs_count; global $rand; $rand = false; $ebor_tabs_count = 0; $ebor_tabs_content = false; extract(shortcode_atts(array('type' => ''), $atts)); $output = false; $rand = wp_rand(0, 10000); $output .= ' <ul id="tab' . $rand . '" class="nav nav-tabs">' . do_shortcode($content) . '</ul><div id="myTabContent' . $rand . '" class="tab-content">' . $ebor_tabs_content . '</div> <script type="text/javascript"> jQuery(document).ready(function() { jQuery(\'#tab' . $rand . '\').tabCollapse({ tabsClass: \'hidden-sm hidden-xs\', accordionClass: \'visible-sm visible-xs\' }); jQuery(\'#tab' . $rand . '\').on(\'shown-accordion.bs.tabcollapse\', function(){ jQuery(\'.panel-group\').find(\'.panel-default:has(".in")\').addClass(\'panel-active\'); jQuery(\'.panel-group\').on(\'shown.bs.collapse\', function(e) { jQuery(e.target).closest(\'.panel-default\').addClass(\' panel-active\'); }).on(\'hidden.bs.collapse\', function(e) { jQuery(e.target).closest(\'.panel-default\').removeClass(\' panel-active\'); }); }); }); </script> '; return $output; }
/** * Set session cookie */ function set_verifyne_cookie() { global $pagenow; # Only set session cookie on profile and login page if ($pagenow === "profile.php" || $pagenow === "wp-login.php") { # Check if session is set if (isset($_COOKIE["vf_session_id"])) { return; } # Generate a new session ID $vf_session_id = ''; for ($i = 0; $i < 32; $i++) { $vf_session_id .= chr(wp_rand(65, 90)); # A-Z } # Set cookie setcookie("vf_session_id", $vf_session_id); } else { if (!isset($_COOKIE["vf_session_id"])) { return; } # Delete cookie unset($_COOKIE["vf_session_id"]); setcookie("vf_session_id", "", time() - 86400); return; } }
/** * The Shortcode */ function ebor_progress_circle_shortcode($atts, $content = null) { extract(shortcode_atts(array('title' => '', 'percent' => '0.4', 'color' => '#7bc4e6'), $atts)); $id = wp_rand(0, 1000); $output = ' <div class="circle-progress-wrapper bm40 wow fadeIn" data-wow-duration="1s" data-wow-delay="0.0s"> <div class="circle-progress circle circle' . esc_attr($id) . '"> <h4>' . $title . '</h4> </div> </div> <script type="text/javascript"> jQuery(window).load(function() { var circle' . esc_attr($id) . ' = new ProgressBar.Circle(".circle.circle' . esc_attr($id) . '", { color: "' . $color . '", trailColor: "rgba(255,255,255,0.1)", strokeWidth: 2, trailWidth: 2, duration: 4500, easing: "easeInOut", text: { value: "' . esc_js($percent) . '" }, step: function(state, bar) { bar.setText((bar.value() * 100).toFixed(0)); } }); circle' . esc_attr($id) . '.animate(' . esc_js($percent) . '); }); </script> '; return $output; }
function xt_generate_guid() { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $password = ''; for ($i = 0; $i < 4; $i++) { $password .= substr($chars, wp_rand(0, strlen($chars) - 1), 1); } // random_password filter was previously in random_password function which was deprecated return apply_filters('random_password', $password); }
/** * The Shortcode */ function ebor_map_block_shortcode($atts, $content = null) { extract(shortcode_atts(array('height' => '480', 'address' => '', 'image' => ''), $atts)); $block_id = wp_rand(0, 1000); $image = wp_get_attachment_image_src($image, 'full'); if (!isset($image[0])) { $image[0] = false; } $output = '<div class="map-wrapper"><div id="map" class="' . esc_attr($block_id) . '" style="height: ' . (int) esc_attr($height) . 'px;"> </div></div>'; $output .= "<script type='text/javascript'>\n\t\t\t\t\tjQuery(document).ready(function(\$){\n\t\t\t\t\t'use strict';\n\t\t\t\t\t\n\t\t\t\t\t\tjQuery('#map." . esc_attr($block_id) . "').goMap({ address: '" . esc_js($address) . "',\n\t\t\t\t\t\t zoom: 15,\n\t\t\t\t\t\t mapTypeControl: true,\n\t\t\t\t\t draggable: false,\n\t\t\t\t\t scrollwheel: false,\n\t\t\t\t\t streetViewControl: true,\n\t\t\t\t\t maptype: 'ROADMAP',\n\t\t\t\t \t markers: [\n\t\t\t\t \t\t{ 'address' : '" . esc_js($address) . "' }\n\t\t\t\t \t ],\n\t\t\t\t\t\t icon: '" . esc_url($image[0]) . "', \n\t\t\t\t\t\t addMarker: false,\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t\tvar styles = [{stylers:[{saturation:-100},{gamma:1}]},{elementType:'labels.text.stroke',stylers:[{visibility:'off'}]},{featureType:'poi.business',elementType:'labels.text',stylers:[{visibility:'off'}]},{featureType:'poi.business',elementType:'labels.icon',stylers:[{visibility:'off'}]},{featureType:'poi.place_of_worship',elementType:'labels.text',stylers:[{visibility:'off'}]},{featureType:'poi.place_of_worship',elementType:'labels.icon',stylers:[{visibility:'off'}]},{featureType:'road',elementType:'geometry',stylers:[{visibility:'simplified'}]},{featureType:'water',stylers:[{visibility:'on'},{saturation:50},{gamma:0},{hue:'#50a5d1'}]},{featureType:'administrative.neighborhood',elementType:'labels.text.fill',stylers:[{color:'#333333'}]},{featureType:'road.local',elementType:'labels.text',stylers:[{weight:0.5},{color:'#333333'}]},{featureType:'transit.station',elementType:'labels.icon',stylers:[{gamma:1},{saturation:50}]}];\n\t\t\t\t\t\t\n\t\t\t\t\t\tjQuery.goMap.setMap({styles: styles});\n\t\t\t\t\t\n\t\t\t\t\t});\n\t\t\t </script>"; return $output; }
function rand_string($length = 12, $special_chars = true) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; if ($special_chars) { $chars .= '!@#$%^&*()'; } $password = ''; for ($i = 0; $i < $length; $i++) { $password .= substr($chars, wp_rand(0, strlen($chars) - 1), 1); } return $password; }
/** * Create User * * Function to add connected users to the WordPress users database * and add the role subscriber * * @package Social Deals Engine * @since 1.0.0 */ public function wps_deals_social_add_wp_user($criteria) { global $wp_version; $prefix = 'wps_user_'; $username = $prefix . wp_rand(100, 9999999); while (username_exists($username)) { // avoid duplicate user name $username = $prefix . wp_rand(100, 9999999); } $name = $criteria['name']; $first_name = $criteria['first_name']; $last_name = $criteria['last_name']; $password = wp_generate_password(12, false); $email = $criteria['email']; $wp_id = 0; //create the WordPress user if (version_compare($wp_version, '3.1', '<')) { require_once ABSPATH . WPINC . '/registration.php'; } //check user id is exist or not if (email_exists($email) == false) { $wp_id = wp_create_user($username, $password, $email); if (!empty($wp_id)) { //if user is created then update some data $role = 'subscriber'; $user = new WP_User($wp_id); $user->set_role($role); wp_new_user_notification($wp_id, $password); } } else { //get user from email $userdata = get_user_by('email', $email); if (!empty($userdata)) { //check user is exit or not $wp_id = $userdata->ID; } } return $wp_id; }
/** * The Shortcode */ function ebor_tabs_shortcode($atts, $content = null) { global $ebor_tabs_content; global $ebor_tabs_count; $ebor_tabs_count = 0; $ebor_tabs_content = false; extract(shortcode_atts(array('type' => ''), $atts)); $output = false; $rand = wp_rand(0, 10000); $output .= ' <div class="tabs tabs-top left tab-container ebor-' . $rand . ' ' . esc_attr($type) . '"><ul class="etabs">' . do_shortcode($content) . '</ul><div class="panel-container">' . $ebor_tabs_content . '</div></div> <script type="text/javascript"> jQuery(document).ready(function() { jQuery(\'.tabs.tabs-top.ebor-' . $rand . '\').easytabs({ animationSpeed: 300, updateHash: false }); }); </script> '; return $output; }
function get_stock_feature_info($size){ global $lastimg; $id = 0; while($id == 0){ $num = wp_rand(1, 8); if($num == 1 && num != lastimg): $id = 2220; elseif($num == 2 && num != lastimg): $id = 2214; endif; } if($size == 'thumbnail'): $info = wp_get_attachment_image_src($id); elseif($size == 'medium'): $info = wp_get_attachment_image_src($id, 'medium'); elseif($size == 'large'): $info = wp_get_attachment_image_src($id, 'large'); else: $info = wp_get_attachment_image_src($id, 'full'); endif; $lastimg = $num; return $info; }
/** * The Shortcode */ function ebor_toggles_shortcode($atts, $content = null) { global $ebor_toggles_count; global $rand; $ebor_toggles_count = 0; $rand = false; $output = false; $rand = wp_rand(0, 10000); $output .= ' <div class="panel-group ebor-' . $rand . '" id="accordion-' . $rand . '">' . do_shortcode($content) . '</div> <script type="text/javascript"> jQuery(document).ready(function() { jQuery(\'.panel-group.ebor-' . $rand . '\').find(\'.panel-default:has(".in")\').addClass(\'panel-active\'); jQuery(\'.panel-group.ebor-' . $rand . '\').on(\'shown.bs.collapse\', function(e) { jQuery(e.target).closest(\'.panel-default\').addClass(\' panel-active\'); }).on(\'hidden.bs.collapse\', function(e) { jQuery(e.target).closest(\'.panel-default\').removeClass(\' panel-active\'); }); }); </script> '; return $output; }
function generate_key($length = 40) { $keyset = 'abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/'; $key = ''; for ($i = 0; $i < $length; $i++) { $key .= substr($keyset, wp_rand(0, strlen($keyset) - 1), 1); } return $key; }
/** * Set autosync schedule * * @since 1.0.0 * * @param int $user_id [required] * @param int $interval [required] * @return string $hash */ public function set_autosync_schedule($user_id = null, $interval = 0) { /* if ( ! in_array( $interval, array( 'hourly', 'twicedaily', 'daily' ) ) ) $interval = 'daily'; */ $_timezone = get_option('timezone_string'); date_default_timezone_set($_timezone); $_now = time(); $_hash = md5($user_id . $_now . wp_rand()); //wp_schedule_event( $_now, $interval, 'wpqt/autosync', array( $user_id, $_hash ) ); wp_schedule_single_event($_now + $interval, 'wpqt/autosync', array($user_id, $_hash)); return $_hash; }
function debug() { echo "<pre>\n"; var_dump(wp_rand(1, 100000)); die("debug: " . __METHOD__); }
function wpcf7_generate_captcha($options = null) { if (!($captcha = wpcf7_init_captcha())) { return false; } if (!is_dir($captcha->tmp_dir) || !wp_is_writable($captcha->tmp_dir)) { return false; } $img_type = imagetypes(); if ($img_type & IMG_PNG) { $captcha->img_type = 'png'; } elseif ($img_type & IMG_GIF) { $captcha->img_type = 'gif'; } elseif ($img_type & IMG_JPG) { $captcha->img_type = 'jpeg'; } else { return false; } if (is_array($options)) { if (isset($options['img_size'])) { $captcha->img_size = $options['img_size']; } if (isset($options['base'])) { $captcha->base = $options['base']; } if (isset($options['font_size'])) { $captcha->font_size = $options['font_size']; } if (isset($options['font_char_width'])) { $captcha->font_char_width = $options['font_char_width']; } if (isset($options['fg'])) { $captcha->fg = $options['fg']; } if (isset($options['bg'])) { $captcha->bg = $options['bg']; } } $prefix = wp_rand(); $captcha_word = $captcha->generate_random_word(); return $captcha->generate_image($prefix, $captcha_word); }
/** * Create a new random secret for the Google Authenticator app. * 16 characters, randomly chosen from the allowed Base32 characters * equals 10 bytes = 80 bits, as 256^10 = 32^16 = 2^80 */ function create_secret() { $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'; // allowed characters in Base32 $secret = ''; for ($i = 0; $i < 16; $i++) { $secret .= substr($chars, wp_rand(0, strlen($chars) - 1), 1); } return $secret; }
/** * * From WordPress !!! * * Generates a random password drawn from the defined set of characters. * * @since 2.5 * * @param int $length The length of password to generate * @param bool $special_chars Whether to include standard special characters. Default true. * @param bool $extra_special_chars Whether to include other special characters. Used when * generating secret keys and salts. Default false. * @return string The random password **/ function wp_generate_password($length = 12, $special_chars = true, $extra_special_chars = false) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; if ($special_chars) { $chars .= '!@#$%^&*()'; } if ($extra_special_chars) { $chars .= '-_ []{}<>~`+=,.;:/?|'; } $password = ''; for ($i = 0; $i < $length; $i++) { $password .= substr($chars, wp_rand(0, strlen($chars) - 1), 1); } return $password; }
function rtmb_generate_message_id($post_id, $email_id, $type = 'post') { if ('comment' == $type) { $comment = get_comment($post_id); $post_id = $comment->comment_post_ID; } $domain_name = preg_replace('/^www\\./', '', $_SERVER['SERVER_NAME']); $domain_name = '@' . $domain_name; $post_date = current_time('mysql'); $unique_id = md5('rt_lib_' . get_post_type($post_id) . '_' . $post_date . '_' . $post_id . '-' . $email_id . '-' . wp_rand()); return '<' . $post_id . '-' . $unique_id . $domain_name . '>'; }
/** * Create User Name for VK.com / Instagram * * Function to check type is vk/instagram then create user name based on user id. * * @package Easy Digital Downloads - Social Login * @since 1.3.0 */ public function edd_slg_create_username($criteria) { global $edd_options; //Initilize username $username = ''; //Get base of username $edd_user_base = isset($edd_options['edd_slg_base_reg_username']) ? $edd_options['edd_slg_base_reg_username'] : ''; switch ($edd_user_base) { case 'realname': //Get first name $first_name = isset($criteria['first_name']) ? strtolower($criteria['first_name']) : ''; //Get last name $last_name = isset($criteria['last_name']) ? strtolower($criteria['last_name']) : ''; //Get username using fname and lname $username = $this->edd_slg_username_by_fname_lname($first_name, $last_name); break; case 'emailbased': //Get user email $user_email = isset($criteria['email']) ? $criteria['email'] : ''; //Create username using email $username = $this->edd_slg_username_by_email($user_email); break; default: break; } if (empty($username)) { //If username get empty //Get username prefix $prefix = EDD_SLG_USER_PREFIX; if ($criteria['type'] == 'vk' || $criteria['type'] == 'instagram') { // if service is vk.com OR instagram then create username with unique id $username = $prefix . $criteria['id']; } else { // else create create username with random string $username = $prefix . wp_rand(100, 9999999); } } //Apply filter to modify username logic $username = apply_filters('edd_slg_social_username', $username, $criteria); //Assign username to temporary variable $temp_user_name = $username; //Make sure the name is unique: if we've already got a user with this name, append a number to it. $counter = 1; if (username_exists($temp_user_name)) { //If username is exist do { $username = $temp_user_name; $counter++; $username = $username . $counter; } while (username_exists($username)); } else { $username = $temp_user_name; } return $username; }
/** * Prints a hidden form field to prevent multiple form submits during checkout * * @return string */ public static function nonce_field() { $user = wp_get_current_user(); $uid = (int) $user->ID; $nonce = wp_hash(wp_rand() . 'pstsnonce' . $uid, 'nonce'); ProSites_Helper_Session::session('_psts_nonce', $nonce); return '<input type="hidden" name="_psts_nonce" value="' . $nonce . '" />'; }
function block($instance) { extract($instance); $unique = wp_rand(0, 10000); if ($title) { echo '<h3>' . htmlspecialchars_decode($title) . '</h3>'; } if ($type == 'tab') { ?> <div class="tabs tabs-top left tab-container" id="tabs-<?php echo $unique; ?> "> <ul class="etabs"> <?php foreach ($tabs as $key => $tab) { echo '<li class="tab"><a href="#tab-' . $unique . '-' . $key . '">' . htmlspecialchars_decode($tab['title']) . '</a></li> '; } ?> </ul> <div class="panel-container"> <?php foreach ($tabs as $key => $tab) { echo '<div class="tab-block" id="tab-' . $unique . '-' . $key . '">' . wpautop(do_shortcode(htmlspecialchars_decode($tab['content']))) . '</div>'; } ?> </div> </div> <script type="text/javascript"> jQuery(document).ready(function () { "use strict"; jQuery('#tabs-<?php echo $unique; ?> ').easytabs({ animationSpeed: 300, updateHash: false }); }); </script> <?php } elseif ($type == 'toggle') { ?> <div class="panel-group" id="accordion-<?php echo $unique; ?> "> <?php foreach ($tabs as $key => $tab) { ?> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a data-toggle="collapse" class="panel-toggle <?php if ($key == '1') { echo 'active'; } ?> " data-parent="#accordion-<?php echo $unique; ?> " href="<?php echo '#tab-' . $unique . '-' . $key; ?> "> <?php echo htmlspecialchars_decode($tab['title']); ?> </a> </h4> </div> <div id="<?php echo 'tab-' . $unique . '-' . $key; ?> " class="panel-collapse collapse <?php if ($key == '1') { echo 'in'; } ?> "> <div class="panel-body"> <?php echo wpautop(do_shortcode(htmlspecialchars_decode($tab['content']))); ?> </div> </div> </div> <?php } ?> </div> <?php } //end type check }
/** * Create a new wordpress user * * Ref: http://codex.wordpress.org/Function_Reference/wp_insert_user */ function wsl_process_login_create_wp_user($provider, $hybridauth_user_profile, $requested_user_login, $requested_user_email) { // HOOKABLE: do_action("wsl_process_login_create_wp_user_start", $provider, $hybridauth_user_profile, $requested_user_login, $requested_user_email); $user_login = ''; $user_email = ''; // if coming from "complete registration form" if ($requested_user_login) { $user_login = $requested_user_login; } if ($requested_user_email) { $user_email = $requested_user_email; } if (!$user_login) { // attempt to generate user_login from hybridauth user profile display name $user_login = $hybridauth_user_profile->displayName; // sanitize user login $user_login = sanitize_user($user_login, true); // remove spaces and dots $user_login = trim(str_replace(array(' ', '.'), '_', $user_login)); $user_login = trim(str_replace('__', '_', $user_login)); // if user profile display name is not provided if (empty($user_login)) { $user_login = strtolower($provider) . "_user"; } // user name should be unique if (username_exists($user_login)) { $i = 1; $user_login_tmp = $user_login; do { $user_login_tmp = $user_login . "_" . $i++; } while (username_exists($user_login_tmp)); $user_login = $user_login_tmp; } } if (!$user_email) { $user_email = $hybridauth_user_profile->email; // generate an email if none if (!isset($user_email) or !is_email($user_email)) { $user_email = strtolower($provider . "_user_" . $user_login) . '@example.com'; } // email should be unique if (wsl_wp_email_exists($user_email)) { do { $user_email = md5(uniqid(wp_rand(10000, 99000))) . '@example.com'; } while (wsl_wp_email_exists($user_email)); } } $display_name = $hybridauth_user_profile->displayName; if ($requested_user_login) { $display_name = sanitize_user($requested_user_login, true); } if (empty($display_name)) { $display_name = strtolower($provider) . "_user"; } $userdata = array('user_login' => $user_login, 'user_email' => $user_email, 'display_name' => $display_name, 'first_name' => $hybridauth_user_profile->firstName, 'last_name' => $hybridauth_user_profile->lastName, 'user_url' => $hybridauth_user_profile->profileURL, 'description' => $hybridauth_user_profile->description, 'user_pass' => wp_generate_password()); // Bouncer::Membership level $wsl_settings_bouncer_new_users_membership_default_role = get_option('wsl_settings_bouncer_new_users_membership_default_role'); // if level eq "default", we set role to wp default user role if ($wsl_settings_bouncer_new_users_membership_default_role == "default") { $userdata['role'] = get_option('default_role'); } elseif ($wsl_settings_bouncer_new_users_membership_default_role && $wsl_settings_bouncer_new_users_membership_default_role != 'wslnorole') { $userdata['role'] = $wsl_settings_bouncer_new_users_membership_default_role; } // Bouncer::User Moderation // > if Bouncer::User Moderation is enabled (Yield to Theme My Login), then we overwrite the user role to 'pending' # http://www.jfarthing.com/development/theme-my-login/user-moderation/ if (get_option('wsl_settings_bouncer_new_users_moderation_level') > 100) { $userdata['role'] = "pending"; } // HOOKABLE: change the user data $userdata = apply_filters('wsl_hook_process_login_alter_wp_insert_user_data', $userdata, $provider, $hybridauth_user_profile); // DEPRECIATED: as of 2.2.3 // $userdata = apply_filters( 'wsl_hook_process_login_alter_userdata', $userdata, $provider, $hybridauth_user_profile ); // HOOKABLE: This action runs just before creating a new wordpress user. do_action('wsl_hook_process_login_before_wp_insert_user', $userdata, $provider, $hybridauth_user_profile); // DEPRECIATED: as of 2.2.3 // do_action( 'wsl_hook_process_login_before_insert_user', $userdata, $provider, $hybridauth_user_profile ); // HOOKABLE: This action runs just before creating a new wordpress user, it delegate user insert to a custom function. $user_id = apply_filters('wsl_hook_process_login_delegate_wp_insert_user', $userdata, $provider, $hybridauth_user_profile); // Create a new WordPress user if (!$user_id || !is_integer($user_id)) { $user_id = wp_insert_user($userdata); } // do not continue without user_id if (!$user_id || !is_integer($user_id)) { if (is_wp_error($user_id)) { return wsl_process_login_render_notice_page(_wsl__("An error occurred while creating a new user: "******"An error occurred while creating a new user!", 'wordpress-social-login')); } // Send notifications if (get_option('wsl_settings_users_notification') == 1) { wsl_admin_notification($user_id, $provider); } // HOOKABLE: This action runs just after a wordpress user has been created // > Note: At this point, the user has been added to wordpress database, but NOT CONNECTED. do_action('wsl_hook_process_login_after_wp_insert_user', $user_id, $provider, $hybridauth_user_profile); // DEPRECIATED: as of 2.2.3 // do_action( 'wsl_hook_process_login_after_create_wp_user', $user_id, $provider, $hybridauth_user_profile ); // returns the user created user id return $user_id; }
function wsl_process_login() { if (!isset($_REQUEST['action']) || $_REQUEST['action'] != "wordpress_social_login") { return; } if (isset($_REQUEST['redirect_to']) && $_REQUEST['redirect_to'] != '') { $redirect_to = $_REQUEST['redirect_to']; // Redirect to https if user wants ssl if (isset($secure_cookie) && $secure_cookie && false !== strpos($redirect_to, 'wp-admin')) { $redirect_to = preg_replace('|^http://|', 'https://', $redirect_to); } if (strpos($redirect_to, 'wp-admin')) { $redirect_to = get_option('wsl_settings_redirect_url'); } } if (empty($redirect_to)) { $redirect_to = get_option('wsl_settings_redirect_url'); } if (empty($redirect_to)) { $redirect_to = site_url(); } try { // load hybridauth require_once dirname(__FILE__) . "/../hybridauth/Hybrid/Auth.php"; // selected provider name $provider = @trim(strip_tags($_REQUEST["provider"])); // build required configuratoin for this provider if (!get_option('wsl_settings_' . $provider . '_enabled')) { throw new Exception('Unknown or disabled provider'); } $config = array(); $config["base_url"] = plugins_url() . '/' . basename(dirname(__FILE__)) . '/hybridauth/'; $config["providers"] = array(); $config["providers"][$provider] = array(); $config["providers"][$provider]["enabled"] = true; // provider application id ? if (get_option('wsl_settings_' . $provider . '_app_id')) { $config["providers"][$provider]["keys"]["id"] = get_option('wsl_settings_' . $provider . '_app_id'); } // provider application key ? if (get_option('wsl_settings_' . $provider . '_app_key')) { $config["providers"][$provider]["keys"]["key"] = get_option('wsl_settings_' . $provider . '_app_key'); } // provider application secret ? if (get_option('wsl_settings_' . $provider . '_app_secret')) { $config["providers"][$provider]["keys"]["secret"] = get_option('wsl_settings_' . $provider . '_app_secret'); } // create an instance for Hybridauth $hybridauth = new Hybrid_Auth($config); // try to authenticate the selected $provider if ($hybridauth->isConnectedWith($provider)) { $adapter = $hybridauth->getAdapter($provider); $hybridauth_user_profile = $adapter->getUserProfile(); } else { throw new Exception('User not connected with ' . $provider . '!'); } $user_email = $hybridauth_user_profile->email; } catch (Exception $e) { die("Unspecified error. #" . $e->getCode()); } $user_id = null; // if the user email is verified, then try to map to legacy account if exist // > Currently only Facebook, Google, Yhaoo and Foursquare do provide the verified user email. if (!empty($hybridauth_user_profile->emailVerified)) { $user_id = (int) email_exists($hybridauth_user_profile->emailVerified); } // try to get user by meta if not if (!$user_id) { $user_id = (int) wsl_get_user_by_meta($provider, $hybridauth_user_profile->identifier); } // if user found if ($user_id) { $user_data = get_userdata($user_id); $user_login = $user_data->user_login; } else { // generate a valid user login $user_login = str_replace(' ', '_', strtolower($hybridauth_user_profile->displayName)); if (!validate_username($user_login)) { $user_login = strtolower($provider) . "_user_" . md5($hybridauth_user_profile->identifier); } // user name should be unique if (username_exists($user_login)) { $i = 1; $user_login_tmp = $user_login; do { $user_login_tmp = $user_login . "_" . $i++; } while (username_exists($user_login_tmp)); $user_login = $user_login_tmp; } // generate an email if none if (!isset($user_email) or !is_email($user_email)) { $user_email = strtolower($provider . "_user_" . $user_login) . "@example.com"; } // email should be unique if (email_exists($user_email)) { do { $user_email = md5(uniqid(wp_rand(10000, 99000))) . "@example.com"; } while (email_exists($user_email)); } $userdata = array('user_login' => $user_login, 'user_email' => $user_email, 'first_name' => $hybridauth_user_profile->firstName, 'last_name' => $hybridauth_user_profile->lastName, 'user_nicename' => $hybridauth_user_profile->displayName, 'display_name' => $hybridauth_user_profile->displayName, 'user_url' => $hybridauth_user_profile->profileURL, 'description' => $hybridauth_user_profile->description, 'user_pass' => wp_generate_password()); // Create a new user $user_id = wp_insert_user($userdata); // update user metadata if ($user_id && is_integer($user_id)) { update_user_meta($user_id, $provider, $hybridauth_user_profile->identifier); } else { die("An error occurred while creating a new user!"); } } $user_age = $hybridauth_user_profile->age; // not that precise you say... well welcome to my world if (!$user_age && (int) $hybridauth_user_profile->birthYear) { $user_age = (int) date("Y") - (int) $hybridauth_user_profile->birthYear; } update_user_meta($user_id, 'wsl_user', $provider); update_user_meta($user_id, 'wsl_user_gender', $hybridauth_user_profile->gender); update_user_meta($user_id, 'wsl_user_age', $user_age); update_user_meta($user_id, 'wsl_user_image', $hybridauth_user_profile->photoURL); wp_set_auth_cookie($user_id); wp_safe_redirect($redirect_to); exit; }
/** * Generate a rand hash * * @since 2.4.0 * @return string */ function wc_rand_hash() { if (function_exists('openssl_random_pseudo_bytes')) { return bin2hex(openssl_random_pseudo_bytes(20)); } else { return sha1(wp_rand()); } }
function nonce_field() { $user = wp_get_current_user(); $uid = (int) $user->ID; $nonce = wp_hash(wp_rand() . 'pstsnonce' . $uid, 'nonce'); update_user_meta($uid, '_psts_nonce', $nonce); return '<input type="hidden" name="_psts_nonce" value="' . $nonce . '" />'; }
/** * Generates a random password drawn from the defined set of characters. * * @since 2.5.0 * * @param int $length Optional. The length of password to generate. Default 12. * @param bool $special_chars Optional. Whether to include standard special characters. * Default true. * @param bool $extra_special_chars Optional. Whether to include other special characters. * Used when generating secret keys and salts. Default false. * @return string The random password. */ function wp_generate_password($length = 12, $special_chars = true, $extra_special_chars = false) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; if ($special_chars) { $chars .= '!@#$%^&*()'; } if ($extra_special_chars) { $chars .= '-_ []{}<>~`+=,.;:/?|'; } $password = ''; for ($i = 0; $i < $length; $i++) { $password .= substr($chars, wp_rand(0, strlen($chars) - 1), 1); } /** * Filter the randomly-generated password. * * @since 3.0.0 * * @param string $password The generated password. */ return apply_filters('random_password', $password); }
/** * Generates a random password drawn from the defined set of characters. * * @since 2.5 * * @param int $length The length of password to generate * @param bool $special_chars Whether to include standard special characters. Default true. * @param bool $extra_special_chars Whether to include other special characters. Used when * generating secret keys and salts. Default false. * @return string The random password **/ function wp_generate_password($length = 12, $special_chars = true, $extra_special_chars = false) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; if ($special_chars) { $chars .= '!@#$%^&*()'; } if ($extra_special_chars) { $chars .= '-_ []{}<>~`+=,.;:/?|'; } $password = ''; for ($i = 0; $i < $length; $i++) { $password .= substr($chars, wp_rand(0, strlen($chars) - 1), 1); } // random_password filter was previously in random_password function which was deprecated return apply_filters('random_password', $password); }
/** * Create a random email */ function oa_social_login_create_rand_email() { do { //Create a random email. $email = md5(uniqid(wp_rand(10000, 99000))) . "@example.com"; //Allow it to be customized. $email = apply_filters('oa_social_login_filter_create_random_email', $email); } while (email_exists($email)); //Done return $email; }
/** * Custom gallery shortcode * * Filters the standard WordPress gallery shortcode. * * @since 1.0.0 */ function ebor_post_gallery($output, $attr) { global $post, $wp_locale; static $instance = 0; $instance++; // We're trusting author input, so let's at least make sure it looks like a valid orderby statement if (isset($attr['orderby'])) { $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); if (!$attr['orderby']) { unset($attr['orderby']); } } extract(shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => 'div', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, 'size' => 'large', 'include' => '', 'exclude' => ''), $attr)); $id = intval($id); if ('RAND' == $order) { $orderby = 'none'; } if (!empty($include)) { $include = preg_replace('/[^0-9,]+/', '', $include); $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); $attachments = array(); foreach ($_attachments as $key => $val) { $attachments[$val->ID] = $_attachments[$key]; } } elseif (!empty($exclude)) { $exclude = preg_replace('/[^0-9,]+/', '', $exclude); $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); } else { $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); } if (empty($attachments)) { return ''; } if (is_feed()) { $output = "\n"; foreach ($attachments as $att_id => $attachment) { $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; } return $output; } if ($columns == 1) { $columns = 12; } elseif ($columns == 2) { $columns = 6; } elseif ($columns == 3) { $columns = 4; } elseif ($columns == 4) { $columns = 3; } elseif ($columns == 5 || $columns == 6) { $columns = 2; } else { $columns = 1; } $unique = wp_rand(0, 10000); $output = "<div class='row ebor-blog-gallery' id='gallery" . $unique . "'>"; foreach ($attachments as $id => $attachment) { $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_url($id, 'full', false, false) : wp_get_attachment_url($id, 'full', true, false); $attachment = get_post($id); $output .= "<{$itemtag} class='item col-sm-{$columns}'>"; $output .= '<figure> <a href="' . $link . '" class="fancybox-media" data-rel="portfolio" data-title-id="title-' . $id . '"> <div class="text-overlay"> <div class="info">' . get_option('blog_view_larger', 'View Larger') . '</div> </div> ' . wp_get_attachment_image($id, $size) . ' </a> </figure>'; if ($attachment->post_excerpt) { $output .= '<div id="title-' . $id . '" class="info hidden"><h2>' . $attachment->post_title . '</h2><div class="fancybody">' . wpautop($attachment->post_excerpt) . '</div></div>'; $output .= '<span class="caption">' . $attachment->post_excerpt . '</span>'; } $output .= "</{$itemtag}>"; } $output .= ' <script type="text/javascript">jQuery(window).load(function () { var $container = jQuery("#gallery' . $unique . '"); $container.isotope({ itemSelector: ".item" }); jQuery(window).on("resize", function () { jQuery("#gallery' . $unique . '").isotope("layout") }); }); </script>'; $output .= "</div>\n"; return $output; }