I want to insert this sortcode:
echo do_shortcode('[AUTHORIMAGE-CIRCLE]');
and replace it with the ua1 class on this php line:
$STRING .= $b_f.''.$CORE->_e(array('head','4')).''.$b_a;
This is the real code. the full one is:
if( $canShowBar ){
if(!$isTop){
$STRING .= "<div class='breadcrumb'>";
}
if(isset($userdata) && $userdata->ID){
if(isset($GLOBALS['CORE_THEME']['links'])){
// my account
$STRING .= $b_f.''.$CORE->_e(array('head','4')).''.$b_a;
}
}
}
when working on local host and try to modify the code, after refreshing the whole page is turning blank
Related
I'm trying out something like below. I get to successfully display the $Message without the PHP script that you see in the middle.
$Message = "<table><tr><td>" <?php code A ?>"</td></tr></table>";
The "Code A" PHP script meant to pull some date from an SQL database and present inside a table as you would see.
I see with this code not working, the issue is the way I place the PHP script inside $Message.
Would like to know, first is this really possible to have a script running attempting to pull data from an mySQL database and assign the output to a variable and if so how should the script look like otherwise?
Here's the full code which represent Code A, if that helps in understanding the issue better.
<?php
if(!isset($_POST['savedata']))
{
echo 'some text message';
}
else
{
include ('dbconnect/index.php');
$SQLuserpw="SELECT * FROM USER WHERE EMAIL = '".htmlspecialchars($email)."'";
$user=mysqli_query($conn, $SQLuserpw) or die ('SQL Error');
$pendingRow=mysqli_num_rows($user);
if($pendingRow == '')
{ echo 'some text here';} else
{
while ($reK = mysqli_fetch_array($user))
{
$wec = $reK['FNAME']; $wec2 = $reK['LNAME']; $wec3 = $reK['EMAIL'];
echo '<table>';
echo '<tr><td>First Name</td><td> : </td><td>'.$reK['FNAME'].'</td></tr>';
echo '<tr><td>Last Name</td><td> : </td><td>'.$reK['LNAME'].'</td></tr>';
echo '<tr><td>Email</td><td> : </td><td>'.$reK['EMAIL'].'</td></tr>';
}
echo '</table>';
}
}
?>
UPDATE
Suggestion made by #ADyson works.
if the code piece you've shared is working, do it like that,
$message = '<table>';
$message .= '<tr><td>First Name</td><td> : </td><td>'.$reK['FNAME'].'</td></tr>';
$message .= '<tr><td>Last Name</td><td> : </td><td>'.$reK['LNAME'].'</td></tr>';
$message .= '<tr><td>Email</td><td> : </td><td>'.$reK['EMAIL'].'</td></tr>';
}
$message.= '</table>';
the use $message wherever you want.
I have problem with simple link function. On submission form, there is textbox where user can include url. This url is then taken and changed into working link and placed in post. This part works fine. If user include http/https in front of url it will work fine. But if they don't include http/https or only www, then it will open link as example below:
mysiteexample.com/UrlTheyPasted.com
mysiteexample.com/www.UrlTheyPasted.com
(This should open as link to Video/Image/Site,..)
Here is code:
$output .= '<DIV CLASS="'.$outerclass.'">';
$output .= '<DIV CLASS="'.$innertclass.'">'.$title.'</DIV>';
$output .= '<DIV CLASS="'.$innervclass.'">'.$value.'</DIV>';
$output .= '</DIV>';
Anyone know solution for this or why is this happening?
During the processing of the user input, use parse_url() to find out if they have put the protocol on or not and act accordingly.
$url = 'test.com';
$urlscheme = parse_url($url, PHP_URL_SCHEME);
if (empty($urlscheme)) {
$url = 'http://'.$url;
}
die('<pre>'.print_r($url,true));
so for instance, just before your code, put the example:
$scheme = parse_url($value, PHP_URL_SCHEME);
if (empty($scheme)) $value = 'http://'.$value;
$output .= '<DIV CLASS="'.$outerclass.'">';
$output .= '<DIV CLASS="'.$innertclass.'">'.$title.'</DIV>';
$output .= '<DIV CLASS="'.$innervclass.'">'.$value.'</DIV>';
$output .= '</DIV>';
I am writing a php plugin for wordpress. I'm trying to be mindful of clean coding and want to know the best practice for returning several lines of HTML code in an IF statement.
Obviously I know about echo but I thought I had seen a technique like this used, but it doesn't seem to work for me. The idea being that you create several $content variables and then return it outside of the IF statement.
function signup() {
if(!Skizzar_Registration::is_skizzar_site_active()) {
$content = '<div class="signup">';
$content .= '<h1>Sign up</h1>';
$content .= '</div>';
} else {
$content = '<div class="signed_up">you are already signed up</div>';
}
return $content;
}
Currently though this returns nothing when I call the function
As you have already discovered, the specific issue is that you are not ecxhoing the data.
As per your followon question (which is prefered, return or echo), in wordpress there seems to be a convention where both options are offered with the functions named accordingly:
//echos
function the_signup_form(){
echo get_the_signup_form();
}
//returns
function get_the_signup_form(){
if(!Skizzar_Registration::is_skizzar_site_active()) {
$content = '<div class="signup">';
$content .= '<h1>Sign up</h1>';
$content .= '</div>';
} else {
$content = '<div class="signed_up">you are already signed up</div>';
}
return $content;
}
Complete newbie to PHP, not quite sure how to handle this.
I have a hyperlink that I would like to modify the text of once it has been clicked. So:
$linktext = 'Click Me!"';
echo $linktext;
if (isset($_GET["foo"])) {
$linktext = "Click Me AGAIN!";
}
But this does not change the text of the original hyperlink. If I add another echo $linktext; to the end, it just prints an additional hyperlink. Is there any way to go back and modify the original text?
Personally, I'd hold the name of the line outside of it in a variable and include it.
This stops replication of the link section.
Something like this;
$link = 'Click Me!';
if (array_key_exists('foo', $_GET)) {
$link = 'Click Again!';
}
$linktext = '' . $link . '';
echo $linktext;
You will want to make the text dynamic by putting it in to a variable. By using the original code, I made the required modification:
$text = "Click Me";
if (isset($_GET["foo"]))
{
$text = "Click Me AGAIN!";
}
$linktext = ''.$text.'';
echo $linktext;
Do observe that there now is a $text variable that holds the text and will be modified if foo has been set.
I'm trying to make a WordPress plugin. Well, actually it's done and fully working, except one thing.
I have added a shortcode for the plugin. But no matter where in the content I call this shortcode, the contents it gets are always on top of the post, instead of where I placed the tag.
The code that outputs something:
public static function showIncomingSearches(){
global $id;
$arSearches = self::getArObj(array('wp_post_id' => $id));
ob_start();
if(!empty($arSearches)){
$str = '<ul>' . PHP_EOL;
foreach($arSearches as $oSearch){
$str .= '<li>'.htmlspecialchars($oSearch->searchterm).'</li>' . PHP_EOL;
}
$str .= '</ul>';
if(!empty($arSearches))
echo $str;
} else {
echo ' ';
}
return ob_get_clean();
}
And the shortcode functionality:
add_shortcode('show_incoming_searches', 'checkReferrer');
function checkReferrer(){
incomingSearches::checkReferrer();
echo incomingSearches::showIncomingSearches();
}
What I want to know though, is why it is always on top of the content?
Your shortcode code needs to return the content, not echo it.
function checkReferrer(){
incomingSearches::checkReferrer();
return incomingSearches::showIncomingSearches();
}