Here's the branch of code I've isolated...
if ( !is_search()
&& (get_option('option1')
&& !(is_page()
|| get_option('option2')
|| get_option('option3')
|| in_category('excludeme', $post )
)
)
)
I've inserted...
<?php print "Hi, Mom!\n"; exit; ?>
above and below this line to isolate the cause of the crash
Try breaking out your code into chunks to further isolate the problem:
This is obviously a WordPress template, and even though you may think the problem is not in the core WordPress code, you may need to put debugging output inside the core functions to find out exactly where the problem is happening. In other words, you need to go inside these functions calls to find out what is causing the problem - you might find a solution to your problem at that point.
<?php
echo '<pre>';
echo PHP_EOL . 'is_search' . PHP_EOL;
var_dump( is_search() );
echo PHP_EOL . 'get option 1' . PHP_EOL;
var_dump( get_option('option1') );
echo PHP_EOL . 'is_page' . PHP_EOL;
var_dump( is_page() );
echo PHP_EOL . 'get option 2' . PHP_EOL;
var_dump( get_option('option2') );
echo PHP_EOL . 'get option 3' . PHP_EOL;
var_dump( get_option('option3') );
echo PHP_EOL . 'in category' . PHP_EOL;
var_dump( in_category('excludeme', $post ) );
Related
I'm currently trying to keep to WordPress coding standards for an important exercise/job with an index page that loops through random posts, I'm using PHP Code Sniffer and getting this error:
Detected usage of a non-sanitized input variable: $_GET['my_posts_per_page']
Here is my code:
function my_random_posts() {
$my_posts_per_page = ! empty( wp_verify_nonce( $_GET['my_posts_per_page'] ) ) ? wp_verify_nonce( $_GET['my_posts_per_page'] ) : 10;
$randomised_posts = wp_get_random_posts( $number = $my_posts_per_page );
$output = '';
foreach ($randomised_posts as $randomised_post) {
$output .= '<li>';
$output .= '<h3>' . wptexturize( $randomised_post->post_title ) . '</h3>
<p>' . wptexturize( $randomised_post->post_content ) . '</p>
' . 'Read More' . '
</li>';
}
$output = '<ul class="randome_post">' . $output . '</ul>';
echo esc_html($output);
};
Also on the same line I'm getting this error:
Notice: Undefined index: my_posts_per_page
I've been scratching my head for hours here. Also, using the escape function on echo esc_html($output); now just brings all the code in (I know this is the purpose of the escaping function), though what's the point of this for Security when it shows the HTML without any embedded li, p, h3 tags, just the tag itself, for example:
<ul class="random_post"><li><h3>Hello world!</h3>
What do I do with the escaped HTML to get it to render correctly? And why am I getting an Undefined index?
For the actual post content, you might want to consider using WordPress function wp_kses_post( ), such as:
echo wp_kses_post( $content );
If it is just a small attribute for use within a tag, try using the WordPress function esc_attr( ), such as:
echo esc_attr( $attribute );
These will remove PHP code sniffer errors.
I have a simple echo statement that's supposed to display a link on the web page, but all it's doing is showing exactly "<a href=website.com>Link</a>" (without the quotes). To me, this should work with no problem. I thought maybe it's because the HTML for the website is in one file while the PHP is in another file.
foreach ($output as $output)
{
echo 'DATE: ' . $output['date'] . "\n";
echo 'TO: ' . $output['to'] . "\n";
echo 'FROM: ' . $output['from'] . "\n";
echo 'SUBJECT: ' . $output['subject'] . "\n";
echo "<a href=website.com>Link</a>\n\n";
}
Your loop isn't a valid one, you have $output as $output.
I also suggest printing $output before looping through it, to see if it even contains what you think it should.
In your 'a' tag, the actual URL needs to be in quotes
<a href='http://www.website.com'>
I've created a delete post button on the front end for a Wordpress site. It deletes the post fine but then tries to reload the post again causing a 404. Is there a way I redirect it after deleting to a specific url? This is my code:
function wp_delete_post_link($link = 'Delete This', $before = '', $after = '') {
global $post;
$link = "<a href='" . wp_nonce_url( get_bloginfo('url') . "/wp-admin/post.php?action=delete&post=" . $post->ID, 'delete-post_' . $post->ID) . "'>".$link."</a>";
echo $before . $link . $after;
}
Then on the template:
<?php wp_delete_post_link('Delete This', '<p>', '</p>'); ?>
I think you are looking for the wp_redirect function.
$location = 'http://domainname.com/pagename/';
$status = '301';
wp_redirect( $location, $status );
exit;
Just place after your successful delete code.
How about running this function right after your echo:
header( 'Location: yournewURL.html' ) ;
Replace 'yournewURL.html' with the page you need to redirect to.
I created a bp-custom.php and regrouped the menu items fine. But now i am trying to add a link to go to /site/members. It list all the members.
When i add it though it goes under the profile I am viewing. I am redirecting to a wordpress page if that helps. Or is there a better way to do this.
Ex :
http://website.com/log-in/members/username/members/
I want it to go just here
http://website.com/log-in/members/
I would love to learn how to just put a url and no slug but whatever works. I do not know why it keeps referencing that signed in /member/username. I have even tried parent url and that did not work. I might have been using parent url syntax wrong.
Here is the function
function mb_bp_profile_menu_posts() {
global $bp;
bp_core_new_nav_item(
array(
'name' => 'Members',
'slug' => 'members',
'position' => 60,
)
);
}
I know that i can create .htaccess for this. But I don't want to do it.
May i know what is the clean way (alternate way) to do this?
I have tried what the user said in comment below and found in bp-members-template this function. I then added the part in bold to add the link but that did not work. I am just adding a google link for testing only.
function bp_get_displayed_user_nav() {
global $bp;
foreach ( (array) $bp->bp_nav as $user_nav_item ) {
if ( empty( $user_nav_item['show_for_displayed_user'] ) && !bp_is_my_profile() )
continue;
$selected = '';
if ( bp_is_current_component( $user_nav_item['slug'] ) ) {
$selected = ' class="current selected"';
}
if ( bp_loggedin_user_domain() ) {
$link = str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $user_nav_item['link'] );
} else {
$link = trailingslashit( bp_displayed_user_domain() . $user_nav_item['link'] );
}
echo apply_filters_ref_array( 'bp_get_displayed_user_nav_' . $user_nav_item['css_id'], array( '<li id="' . $user_nav_item['css_id'] . '-personal-li" ' . $selected . '><a id="user-' . $user_nav_item['css_id'] . '" href="' . $link . '">' . $user_nav_item['name'] . '</a></li>', &$user_nav_item ) );
**echo "<a href='http://www.google.com'>Google</a>"; }**
}
The bp_core_new_nav_item function is used to add a link to the user's navigation which explains why you're seeing URLs like /members/username/members/ when clicking on the tab. I don't think bp_core_new_nav_item is the right approach here.
An alternative approach would be to replace the function in your theme template that outputs the navigation with your own custom menu.
See this article on the BP Template Hierarchy which shows you how you can set up your own templates:
http://codex.buddypress.org/themes/theme-compatibility-1-7/template-hierarchy/
im trying to use joomla mailer to send emails but it doesent work, any suggestions? what am i missing? i've searched around the web and SO, but it didnt help.
the only error i get is 500, and i cant understand why...
this is the actual code:
<?php
//framework joomla
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__) . "/../"));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
$mainframe =& JFactory::getApplication('site');
//get vars
$session =& JFactory::getSession();
$num1 = $session->get('variable1');
$num2 = $session->get('variable2');
$val= $session->get('variable3');
$uq= $session->get('unique');
$sendto= $session->get('mail');
//mail
$mailer =& JFactory::getMailer();
$mailer->setSender('some1#domain.com');
$recipient = array($sendto, 'some1else#domain.com');
$mailer->addRecipient($recipient);
$body = '<h2>sometext</h2>'
. '<div>sometext</div>'
. '<div> blabla' echo $num1 'blabla </div>'
. '<div> texttext' echo $num2 'texet </div>'
. '<div> texttext' echo $val 'text </div>';
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
$mailer->AddEmbeddedImage("$uq".".gif", "image_0", "", "base64", "image/gif");
$mailer->addAttachment("$uq".".gif");
//send
$send =& $mailer->Send();
if ( $send !== true ) {
//Elimina .gif
$mask = "*.gif";
array_map( "unlink", glob( $mask ) );
unset($mailer);
echo 'error: ' . $send->message;
} else {
unset($mailer);
//Elimina .gif
$mask = "*.gif";
array_map( "unlink", glob( $mask ) );
echo 'done';
}
?>
forgot to add specs about the platform:
PHP Version 5.3.22
Joomla! Version 2.5.9
if you need any other info just ask.
update:
i tried another joomla! version, a simplified version of the code without variables and with a single email, plain text emails... nothing seems to work.
internal server error (500) with a blank error log... (wierd, but the installation it's inside a subdirectory with many other installation, and my webhosting allow me to see only the "root" log, so i think this is the problem of the blank error log...)
Not quite sure whether this is the root of your problem. But $mail->setSender() accepts an array. Example : $mail->setSender(array('SENDER EMAIL', 'SENDER NAME'));
AND
$mail->addRecipient() accepts a string OR an array. Use an array if you are sending the email to multiple recipients and the string when you are sending the email to only 1 recipient.
Hope this helps
ok, solved!
this might help someone else so, here is how:
$config =& JFactory::getConfig();
this line grabs the email configuration of Joomla, without this Jmail will not send emails.
//body email
$body .= "<h2>Texttext</h2>" . "\n";
$body .= "<div>TexttextTexttextTexttext" . $blockh . " Texttext " . $blockd . "\n";
$body .= "<div> TexttextTexttext <span> " . $num1 . " </span> Texttext </div>" . "\n";
$body .= "<div>TexttextTexttextTexttext <span> " . $val . " </span> Texttext </div>";
previus concatenation of the body was not working, it seems that double quotes are needed to work...
$mailer->isHTML();
the "true" inside is not necessary since true is the default value..
In answer to KentaS comment of
previus concatenation of the body was not working, it seems that double quotes are needed to work...
It has nothing to do with single or double quotes.
In your original post you had:
$body = '<h2>sometext</h2>'
. '<div>sometext</div>'
. '<div> blabla' echo $num1 'blabla </div>'
. '<div> texttext' echo $num2 'texet </div>'
. '<div> texttext' echo $val 'text </div>';
the part:
'<div> blabla' echo $num1 'blabla </div>'
causes a syntax error (string, followed, without concatenation, by a call to "echo", followed, without concatenation, by a string...!
Somthing which works with single quotes:
$body = '<h2>sometext</h2>'
. '<div>sometext</div>'
. '<div> blabla' . $num1 . 'blabla </div>'
. '<div> texttext' . $num2 . 'texet </div>'
. '<div> texttext' . $val . 'text </div>';
And with double quotes you can do even shorter:
$body = "<h2>sometext</h2>"
. "<div>sometext</div>"
. "<div> blabla $num1 blabla </div>"
. "<div> texttext $num2 texet </div>"
. "<div> texttext $val text </div>";
Cheers,
Dom