AngularJS store PHP username -
i'm developing angularjs questionnaire form, grabs users username wordpress install.
i have managed receive users username, when changing views, refreshing browser looses username! if don't refresh browser username visible throughout views.
how prevent loosing users username?
js
appctrl.controller('onectrl', ['$scope', '$localstorage', '$http', function($scope, $localstorage, $http) { $localstorage.$reset(); $scope.$storage = $localstorage; $http({ method: 'post', url: 'https://app.com/user.php', headers: { 'content-type': 'application/x-www-form-urlencoded' } }).success(function(data, status, headers, config) { username = data; }).error(function(data, status, headers, config) { alert(data); }); }]); appctrl.controller('twoctrl', ['$scope', '$localstorage', function($scope, $localstorage) { $scope.username = username; }]); appctrl.controller('threectrl', ['$scope', '$localstorage', function($scope, $localstorage) { $scope.username = username; }]);
php
<?php require_once('/home/app/public_html/wp-load.php' ); global $current_user; get_currentuserinfo(); if ( is_user_logged_in() ) { $username = $current_user->user_login; echo $username; } ?>
solution
<?php $username = $current_user->user_login; if($username) { echo "<script>var username = '".$username."';</script>"; } ?>
pass username in <script>var username='<?php echo "tralala";?>';</stript>
on each page(it can template) , username
available globaly on site
Thanks for give us valuable information
ReplyDeleteWordPress Support Australia
WordPress Support Number
Very Helpful. Thanks for such Information
ReplyDeleteWP Help
WordPress Support Services