Replacing the token value in the HTML text content - drupal

I have a token value
echo variable_get('some_count', '');exit;
This prints 23. But if I try to use the same in the HTML code. I am getting error.
$sone_cnt = '
<div>
<p class="sub-heading">How to help , '
echo variable_get('provider_count', '');
'number of people</p>
</div>';
I am new to PHP. Let me know, if anything else is needed to be done here to get this value in the html content.

You have to break out of the string to call the function, and concatenate with the dot
$sone_cnt = '
<div>
<p class="sub-heading">How to help , '.
variable_get('provider_count', '').
'number of people</p>
</div>';

Related

I'm developing a WordPress theme and using custom fields. I'm facing the following problem

My code
<`li><img src="<?php echo get_post_meta($post->ID, '_for-gallery', true); ?> " alt=""></li>`
The code should give this:-
<img src="Array" alt="" draggable="false">
But the code is giving this:-
<img src=" " alt="" draggable="false">
Look at the code reference for get_post_meta() - it says that the function will return an array if the 3rd parameter ($single) is false:
Return: (mixed) An array if $single is false. The value of the meta
field if $single is true. False for an invalid $post_id.
In your code you're sending true, try this instead:
get_post_meta($post->ID, '_for-gallery', false);
More info here: https://developer.wordpress.org/reference/functions/get_post_meta/
When you use get_post_meta function with $single as true just get the first element, but false get all elements separated by comma.
Looking your code, i suppose that custom_field is an url, in that case, why you need get an array as a url? you must get a string...
You can check here: https://developer.wordpress.org/reference/functions/get_post_meta/

DomCrawler filterXpath for emails

In my project I am trying to use filterXPath for emails. So I get an E-Mail via IMAP and put the mail body into my DomCrawler.
$crawler = new Crawler();
$crawler->addHtmlContent($mail->textHtml); //mail html content utf8
Now to my issue. I only want the plain text of the mail body, but still remain all new lines spaces etc - the exact same as the mail looks just in plain text without html (still with \n\r etc).
For that reason I tried using $crawler->filterXPath('//body/descendant-or-self::*/text()') to get every text node inside the mail.
However my test-mail containts html like:
<p>
<u>
<span>
<a href="mailto:mail#example.com">
<span style="color:#0563C1">mail#example.com</span>
</a>
</span>
</u>
<span>
</span>
<span>·</span>
<span>
<b>
<a href="http://www.example.com">
<span style="color:#0563C1">www.example.com</span>
</a>
</b>
<p/>
</span>
</p>
In my mail this looks like mail#example.com · www.example.com (in one single line).
With my filterXPath I get multiple nodes which result in following (multiple lines):
mail#example.com
· wwww.example.com
I know that probably the 
 might be the problem, which is a \r, but since I can't change the html in the mail, I need another solution - as mentioned before in the mail it is only a single line.
Please keep in mind, that my solution has to work for every mail - I do not know how the mail html looks like - it can change every time. So I need a generic solution.
I already tried using strip_tags too - this does not change the result at all.
My current approach:
$crawler = new Crawler();
$crawler->addHtmlContent($mail->textHtml);
$text = "";
foreach ($crawler->filterXPath('//body/descendant-or-self::*/text()') as $element) {
$part = trim($element->textContent);
if($part) {
$text .= "|".$part."|\n"; //to see whitespaces etc
}
}
echo $text;
//OUTPUT
|mail#example.com|
|·|
| |
|www.example.com|
| |
I believe something like this should work:
$xpath = new DOMXpath($crawler);
$result = $xpath->query('(//span[not(descendant::*)])');
$text = "";
foreach ($result as $element) {
$part = trim($element->textContent);
if($part) {
$text .= "|".$part."|"; //to see whitespaces etc
}
}
echo $text;
Output:
|mail#example.com||·||www.example.com|
Do note that you are dealing with two different ways to treat whitespace only text nodes: HTML has its own rules about if those are rendered (the difference are mainly between block elements and inline elements and also includes normalization) and XPATH works over a document tree provided by a parser (or DOM API) which has its own configuration about preserving or not those whitespace only text nodes. Taking this into account, one solution could be to use the string() function to get the string value of the element containing the email:
For this input:
<root>
<p>
<u>
<span>
<a href="mailto:mail#example.com">
<span style="color:#0563C1">mail#example.com</span>
</a>
</span>
</u>
<span>
</span>
<span>·</span>
<span>
<b>
<a href="http://www.example.com">
<span style="color:#0563C1">www.example.com</span>
</a>
</b>
<p/>
</span>
</p>
</root>
This XPath expresion:
string(/root)
Outputs:
mail#example.com
·
www.example.com
Check in here

how to edit $woo_options['woo_featured_height'

I have a old wordpress site that is defining some CSS using this code:
$fixed_height = ' style="height: ' . $woo_options['woo_featured_height'] . 'px;"';
<div class="slide <?php echo $css_class; ?>"<?php echo $fixed_height; ?>>
I cannot figure out where the $woo_options['woo_featured_height'] is defined. I have searched the entire codebase and there is no such value.
That's a woocommerce options array and most likely the option you are looking for comes from a database table and won't exists in your codebase. See this link for more information.

WordPress pods pagination not taking limit parameter

I’m new using the pods plugin so maybe it’s a misuse of the pagination function.
I have a simple code where I call in a custom template page a pods taxonomy, I list them and then I put the pagination. In my request I put a limit of 20 object by request, as I understand it, this parameter should be passed on to the pagination function and the display should be of 20 entries by page.
Or when navigating , I have a random number of entries depdending on the letter I’m trying to display (9,14,12,10).
I would like to be able to lock it at 20 if possible, could you help me finding what I'm doing wrong?
The code in question:
if(isset($_GET["let"])){
$let = $_GET["let"];
$params = array(
"limit" => 20, // -1 Return all rows
"where" => "t.name LIKE '".$let."%'"
);
}else{
$let = "all";
$params = array(
'limit' => 20 // -1 Return all rows
);
}
$adherents = pods("adherent",$params);
echo "<div class='row'>
<div class='col-lg-5' id='cibe-adherent-title'>
<h1>Nos Adhérents</h1>
</div>
</div>
<div class='row' id='cibe-annuaire-tri'>
<div class='col-lg-12 text-lg-center'>
<a href='".get_permalink()."'";
if($let == "all") echo " class='cibe-active-link'";
echo ">Tous</a> ";
for ($i=65; $i<=90; $i++) {
echo "<a href='".get_permalink()."/annuaire-des-adherents/?let=".chr($i)."'";
if($let == chr($i)) echo " class='cibe-active-link'";
echo ">".chr($i)."</a> ";
}
echo " </div>
</div>";
while($adherents->fetch()){
$current_url = add_query_arg('term_id', $adherents->field("term_id"), get_permalink());
if($adherents->field("adherent") == 1)
echo "<div class='row'>
<div class='col-lg-11 offset-lg-1'>
<a href='".$current_url."'>".$adherents->field("name")."</a>
</div>
</div>";
}
echo "<div class='row' id='cibe-annuaire-pagination'>
<div class='col-lg-12 text-lg-center'>
".$adherents->pagination()."
</div>
</div>";
As I said in my post, it may be a misuse, and it is! Thinking on my code, I have this condition
if($adherents->field("adherent") == 1)
That is why some are not displaying.
I did this at the beginning when I didn't know you could use where condition in the pods parameters.
If I correct this it should work.

display multiple feature images through custom post type with shortcode

I have a shortcode/multiple feature image problem I'm hoping for a bit of help on.
My custom post type called rubow_medarbejder is displayed on a page with a shortcode. This works fine.
I need to add a second feature image. I've used the Multiple Featured Images plugin to do this. Problem is I can't get the image to display through my shortcode.
kd_mfi_get_featured_image_id() shows the id perfectly but when I type kd_mfi_get_featured_image() it brings this error message
Fatal error: Call to undefined function kd_mfi_get_featured_image() in /var/www/www.rubowarkitekter.dk/www/wp-content/plugins/Medarbejdere/medarbejdere_post_type_shortcode.php on line 22
The output part of my shortcode that provokes this error looks like this
$output .= '
<div id="medarbejder">
<div id="medarbejder-page-content-gray">' . kd_mfi_get_featured_image( 'hover-medarbejder-image-grayscale', 'rubow_medarbejder') . '</div>
<div id="medarbejder-page-content-img">' . get_the_post_thumbnail() . '</div>
<div id="medarbejder-page-content-navn">' . $meta['rubow_medarbejder_navn'][0] . '</div>
<div id="medarbejder-page-content-titel">' . $meta['rubow_medarbejder_titel'][0] . '</div>
<div id="medarbejder-page-content-telefon">' . $meta['rubow_medarbejder_telefon'][0] . '</div>
<div id="medarbejder-page-content-mail">' . get_the_content() . '</div>
</div>
';
Any hints to get this solved would be highly appreciated. Thanks!
Use Advanced Custom Fields plugin. Then add as much custom fields as you need. and use
echo get_field('my-other-featured-image');
To output.
You need to select image url and size in plugin to output like that.

Resources