i want to show the status of commentator in comment page of wordpress
i am trying to display simple message [online/offline] according to its status.
right now i am using below code
<?php
$user_id = get_comment(get_comment_ID())->user_id;
if ( is_user_logged_in($user_id) )
{
echo 'Online';
} else {
echo 'Offline';
}
?>
but the above code is not working. it only show text (Online) and not working properly. i think there is some error in above code can anybody correct it for me.
Related
I have a Wordpress page where a user can book language classes. There are different booking options, so I built the page in a way that the booking form charges dinamically from URL. The DOM charges 16 different shortcodes but in front-end it's only displayed the one that user enters in the URL by setting some parameters. The only problem about this is that the page takes a lot of time to charge and display the form.
I'm trying to figure out a way to charge only one shortcode and only set dinamically the value that differs between all shortcodes. After some researching (as my PHP knowledge is limited), I tried this code, and it worked:
function php_insert() {
if( is_page( 645 ) ) {
$awQueryString = $_SERVER['QUERY_STRING'];
parse_str($awQueryString, $awQueryStringParams);
$language = $awQueryStringParams['lang'];
$pack = $awQueryStringParams['pack'];
if (empty($awQueryString)) {
echo 'The URL entered is invalid. Please refresh the page with the correct URL or contact the web admin.';
}
else if ($language == 'english') {
if ($pack == '5') {
echo do_shortcode('[ameliacatalog package=13]');
}
if ($pack == '10') {
echo do_shortcode('[ameliacatalog package=14]');
}
if ($pack == '25') {
echo do_shortcode('[ameliacatalog package=15]');
}
}
}
}
add_action('wp_enqueue_scripts', 'php_insert');
The problem now is that this page is protected by password, and this snippet charges the code at the top of the page and it doesn't wait to check that the password is correct.
I don't know if this is the best way to do this workaround. Also don't know how can I do to solve the password check and location problem.
I hope I have explained everything well.
Thanks
please can anyone find and improve in my code that where i am missing when i am trying to redirect on my login page https://localhost/sms/login.php when the session is not set but page getting error like below showing the screenshot
and my code below what i am trying to achieve please check
<?php
session_start();
$ulr='';
$adminurl=ROOTdir.'admin/adminDash.php';
$loginurl=ROOTdir.'login.php';
if(!isset($_SERVER['HTTPS']) && !isset($_SERVER['HTTP'])){
//echo "both are null";
$ulr="https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}else if(empty($_SERVER['HTTPS']) || empty($_SERVER['HTTP']) ){
$ulr="https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}
if(isset($_SESSION['uid']) && $ulr == "https://".$_SERVER['HTTP_HOST'].'/sms/' ){
if(isset($adminurl)){
header("location:".$adminurl);
echo "ddsa";
}
}else if(isset($_SESSION['uid'])){
header("location:".$adminurl);
}
if (!isset($_SESSION['uid'])){
if(isset($loginurl)){
//echo $loginurl;
header("Location:https://localhost/sms/login.php");
}
// echo "session is not setsss";
// header("location:".$adminurl);
}
?>
your any participation would be very helpful.
after deleting that above code and i rewrite again to session not set but the same problem occuring like previous as after redirecting on https://localhost/sms/login.php the login page not opening and getting error like
enter image description here
updated is here below
code of session.php
enter image description here
code of session.php
enter image description here
code of adminDash.php
enter image description here
i want when we go on link like https://localhost/sms/admin/adminDash.php if there the session is to be not set then after it will redirect to https://localhost/sms/login.php
it say too many redirect, probably you are into a loop.
I'm looking to hide some page of a website between 10 AM AND 20 PM each day
I add the code below on the file function.php
<?php
if (date('H')>10 && date('H')<20{echo 'url page';}
?>
This code breaks the website. I'm looking for the correct code to add.
Besides syntax errors mentioned in comments, I guess you need to check whether it is the particular page you need to lock down, so you won't do that to the entire site. If that page is some WordPress post, you can block access by post ID, like this:
function blockAccessFromPost($post) {
$post_id = $post->ID;
$hours = intval(date('H'));
if ($hours >= 9 && $hours < 20 && $post_id === 1123) {
echo 'Please wait...';
exit; // exit is required so no further code is executed.
}
}
add_action('the_post', 'blockAccessFromPost');
In case if you don't know where to find the post/page id, here's the article.
The previous version of the answer was wrong, because it was unable to get access to the post data right away, WordPress was not initalized. the_post hook helps to execute the code in the moment when current post data has just loaded.
Still the same, I really don't know with, your code look perfect. When I use it, the post disappear in the list and I can see wirtten "Please wait...1391". But widget footer etc disappear.
I post you back the code below to be sure to use it well..
function blockAccessFromPost($post) {
$post_id = $post->ID;
$hours = intval(date('H'));
if ($hours >= 9 && $hours < 20 && $post_id === 1391) {
echo 'Please wait...';
echo $post->ID;
exit; // exit is required so no further code is executed.
}
return $post;}
add_action('the_post', 'blockAccessFromPost');
?>```
I have an issue regarding viewing of data. I'm working on some real estate project where there is a Code Page (to enter the code for House Status) and a Status Page (where details of house are displayed). Now, I can block the users from redirecting to Status Page on entering wrong code until they enter the correct one. What if the user tries to enter some random code in the URL of Status Page, then in case of wrong code, the page displays errors. How can I avoid this? And how can I just redirect the user back to Code Page in this case?
Updated:
I have used the condition on my View Page:
<body id="status-page">
<?php
if($listing[0]['code'] != $listing_code){
die();
}else{ ?>
<!-- Content -->
<div class="page-loader-wrapper">
....
</div>
<?php } ?>
Controller:
function index(){
$listing_code = $this->uri->segment(3);
$result = $this->status_model->get_listing($listing_code);
$data['listing'] = $result;
$data['listing_code'] = $listing_code;
}
Model:
function get_listing($listing_code){
$this->db->select('*');
$this->db->from($this->listings_table);
$this->db->where('code',$listing_code);
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
Everything's working fine except that when i change the url code for a wrong one then instead of terminating the Page, it displays errors....
You have different options
1 ) Generate a hard code to guess , you can do that by using something like this
$code = substr(md5(rand(16, time())), 0, 16);
In case the user types in a wrong code and it displace error
use an if command to kill the rest of the pageif(condition to check if code exists ) {die();}
2) Or create a login and create a table listing the people who can use the code
I need to insert some markup inside page based on whether a URL Query Var exists or not. I'm trying to insert the code inside a shortcode like so:
//Create Shortcode for join page error message
add_shortcode( 'join_error', 'av_join_error' );
function av_join_error(){
$joinresult = $_GET["result"];
if($joinresult){
echo "<p class='alert'>Your payment was declined. Please double check your details and try again.</p>";
}
}
It's not working, hopefully someone can point me in the right direction!
The code you posted is mostly fine, you will need to post more.
First do print_r($_GET) and make sure the array is actually being set.
Also, shortcodes should always return and not echo. Using return keeps the shortcode output where it is in the document/page (echo will output it to the top).
more about that here under Output: http://codex.wordpress.org/Shortcode_API
Try
//Create Shortcode for join page error message
function av_join_error(){
$joinresult = $_GET["result"];
if($joinresult){
echo "<p class='alert'>Your payment was declined. Please double check your details and try again.</p>";
}
}
add_shortcode( 'join_error', 'av_join_error' );