Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 days ago.
Improve this question
I need to allow access to one specific WordPress page for one IP. It works fine in normal browser, but in anonymous browser with VPN i can still open the page.
This is my code:
function restrict_access_by_ip_address() {
$allowed_ips = array( '11.11.11.111' ); // replace with your own IP addresses
$current_ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'];
if ( ! in_array( $current_ip, $allowed_ips ) && is_page( '2533' ) ) {
wp_die( 'Access Denied' );
}
}```
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have created a custom router. For Example
$istek = $_SERVER['REQUEST_URI'];
switch ($istek) {
case '/' :
$title = "Anasayfa";
require base . 'views/index.php';
break;
So I want to pass the example id variable with $_GET. But the router blocks it and redirects to the 404 page. how can I pass this variable without getting any errors or redirecting to 404?
The reason is that $_SERVER['REQUEST_URI'] includes everything, not just the / so your switch will fail.
To fix, use parse_url, / is the PHP_URL_PATH, whilst ?id= would be in PHP_URL_QUERY.
So you could use something like this to get what you want from $_SERVER['REQUEST_URI']:
<?php
// example
$_SERVER['REQUEST_URI'] = '/controller/action?id=123';
$uri = $_SERVER['REQUEST_URI'];
$uri = parse_url($uri);
$route = explode('/', ltrim($uri['path'], '/'));
print_r($route);
parse_str($uri['query'], $query);
print_r($query);
Result:
Array
(
[0] => controller
[1] => action
)
Array
(
[id] => 123
)
https://3v4l.org/UMFQF
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm struggling with printing the logged in user name on the My Account page of Woocommerce. I have a function that looks like this:
add_action( 'woocommerce_order_details_before_order_table_items', function() {
_e('<p class="you-ordered">Hey! Here\'s what you ordered:</div></p>');
} );
I'm trying to get it to say: "Hey, Jim! Here's what you ordered:".
I've tried:
add_action( 'woocommerce_order_details_before_order_table_items', function() {
_e('<p class="you-ordered">Hey! '.$current_user->display_name.' Here\'s what you ordered:</div></p>');
} );
But that didn't work. Any ideas?
Here's the solution:
add_action('woocommerce_order_details_before_order_table_items', function() {
$current_user = wp_get_current_user();
_e('<p class="you-ordered">Hey! ' . $current_user->display_name .
' Here\'s what you ordered:</div></p>');
});
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have created a new user role named student_role I want to redirect the user with this role to form page(which I created from wp front end) when he logs in.
I tried peter login redirect plugin but failed.
Try this :
function rohil_login_redirect_based_on_roles($user_login, $user) {
if( in_array( 'student_role',$user->roles ) ){
exit( wp_redirect('Your page link goes here' ) );
}
}
add_action( 'wp_login', 'rohil_login_redirect_based_on_roles', 10, 2);
Explanation
If you look at the codex, you will find that wp_login provides two parameter: 1) $user_login which will return a string and 2) $user will return an object containing all the details.
But you need to make sure that you also pass priority to that parameters otherwise It will give you an error.
If you want to see what data are into that parameter, you can run below code for learning purpose only.
function rohil_login_redirect_based_on_roles($user_login, $user) {
var_dump($user); // Will give you an object
var_dump($user_login); //Will give you a string
die();
}
add_action( 'wp_login', 'rohil_login_redirect_based_on_roles', 10, 2);
Make sure you delete above code from functions.php after checking what data it contains
So as you can $user object contains roles which shows current logged in user's role. So I simple checked that if($user->roles[0] === 'student_role') if current logged in user is having student_role then wp_redirect('Your page link goes here') redirect them to some page.
Let me know if you have any doubt.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
In my site i want to free and paid membership.
I am new in paypal integration. How to use paypal payment system please help me.
After insert this detail in database and how to redirect on paypal.
Duration : 1year, 2year and lifetime membership
Prize :$10 ,$20, $100
Here is my PHP code
function payment_info()
{
global $obj;
$jobseeker_id = $_SESSION['jobseeker_logged_in_id'];
$s=$obj->FetchObject("SELECT * FROM candidate_registration WHERE jobseeker_id='".$jobseeker_id."'");
$fname =$s->candidate_fname;
$candidate_lname =$s->candidate_lname;
$candidate_name =$fname.' '.$candidate_lname;
$candidate_current_location =$s->candidate_current_location;
$candidate_mob =$s->candidate_mob;
$candidate_dob =$s->candidate_dob;
$candidate_gender =$s->candidate_gender;
$email_id =$s->email_id;
$duration = $_REQUEST['item_name'];
$pid = $_REQUEST['item_number'];
$prize = $_REQUEST['amount'];
$sql_data_array=array('pid'=>$pid,
'jobseeker_id'=>$jobseeker_id,
'duration'=>$duration,
'prize'=>$prize,
'email_id'=>$email_id,
'jobseeker_name'=>$candidate_name,
'candidate_current_location'=>$candidate_current_location,
'candidate_mob'=>$candidate_mob,
'candidate_gender'=>$candidate_gender,
'candidate_dob'=>$candidate_dob,
'membership_status'=>'1',
'membership_date'=>'now()');
$obj->Insert('jobseeker_member',$sql_data_array);
$_SESSION['success']="user detail added successfully";
header("location:");
}
on the above code after this line $obj->Insert('jobseeker_member',$sql_data_array); you want to set your paypal integration which are redirect to paypal with all the elements in paypal.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Hi i am totally new here and title says it all ..
i want to reply to a tweet using abraham/twitteroauth library for twitter .. update for the twitte is working fine but i am unable to do reply thing .
I am doing this ..
$status = $connection->post('statuses/update', array("status" =>
$dataa, "in_reply_to_status_id" =>$id));
twitteroauth_row('statuses/update', $status, $connection->http_code,
$parameters);
this code also updates the account with value in $dataa variable but do not reply to the tweet defined in $id
Please help .
Sorry for my bad english .This is my first post.
Thanks
yap . there was mistake from my side while updating the post .. after reading api document .. i found that without #username sign to perticular user it won't appear in his reply section ..
hamdoulilah the solution is so easy
you need just to add #username for who you want to replay to
$status_id = '480775609728385024';
$twitt_reply = '#username the replay text';
$responce = $connection->post('statuses/update', array('in_reply_to_status_id'=> $status_id , 'status' => $twitt_reply ));