Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

VladimirPanek on "RSS WP HTTP Error: A valid URL was not provided. 'reject_unsafe_urls'"

$
0
0

Hello,

I have RSS feed on the same server that I need to display on my WP site.

I was looking around and found only one solution.
Add this code in the function.php to accept any bad urls

function http_request_local( $args ) {
$args['reject_unsafe_urls'] = false;
return $args;
}
add_filter( 'http_request_args', 'http_request_local' );

Is there a way to set this so that this script allow only one url and works for the rest?


Baki Goxhaj on "Why does pre_get_comments hook only runs for non logged-in users?"

$
0
0

I'm trying too change the order of the comments on my posts and I spent hours battling with the pre_get_comments only to figure out that it did not run at all in front-end.

Is this the designed behaviour of this hook or is this a bug?

Thanks.

Attiq on "Access External Database"

$
0
0

I have retrive Data from external database using get_results function which is working fine on my local server but same code is not running on the online server it make an error like

Warning: Invalid argument supplied for foreach()in .....

my code is

<?php
    if (isset($_POST['submit'])) {
        $id = $_POST['userid'];
        $mydb = new wpdb('$dbusername', '$dbpassword', '$dbname', '$dbhost');
        $rows = $mydb->get_results("SELECT * FROM admin WHERE id=$id;");
        echo "<ul>";
        foreach ($rows as $obj) :
            echo "<li>" . $obj->username . "</li>";
        endforeach;
        echo "</ul>";
    }
    ?>

pixieblitz on "Temporary Username and One-Time Change"

$
0
0

I'm running a multisite installation with buddypress, and I ended up with a list of names and e-mails of people that want to join. It's not *huge*, so technically I could set a temporary username for all of them, and ask them to let me know what to change it to, then go in and update the database accordingly... But obviously that's a bit clunky and also not a smooth user experience.

Anyway, does anyone know of a way to enable a one-time username change from the admin area for users after their first login? It's just really convenient to have a sign up sheet at events, and if I could reduce the number of steps, that'd be awesome. If not I could always just e-mail them asking to register themselves after the event, but again, that's an extra step that I'd love to eliminate.

Thank you guys!

Ari_Johns on "Spinning my wheels advice needed"

$
0
0

This is a random difficult to explain problem, but basically what I am attempting to do with wordpress is change a shopping cart plug in to allow for each entry to the cart to print out as a separate thing, basically if you ordered ten of the same item it would list that item ten times on the cart. I have tried everything I can think of to get the array to print like that, but I am at a loss. I am currently trying to hack apart woocommerce cart.php and their wc-formating-functions.php to try and get this done. Am I even looking in the correct place? Any help with this would be greatly appreciated. The ultimate goal is to be able to put in a series of similar instruments and issue a certificate for those intruments on the page.

Cheers!

Blue_Dragon360 on "How can I detect whether a comment is a reply and nest it?"

$
0
0

I've decided to integrate wordpress into the site I'm building, and am currently working on the main page (on a localhost, so I can't share the link). I've set withcomments=0 and added a comments loop to display 3 comments under each post on the home page. This works well, but I'm having a problem: Comment replies aren't nested. Is there a function or something I can use to make this happen?

Also, I'm having trouble getting the reply and edit links to work. When I use comment_reply_link and edit_comment_link nothing displays. What do I need to do?

Here's my comments loop:

<?php
				//defines $args variables
				$args = array(
					'number' => '3',
					'post_id' => get_the_ID(),
				);
				//starts the comment loop
				$comments = get_comments($args);
				foreach($comments as $comment) :
					//echos the HTML layout
					echo("<div class='commentContainer'><div class='avatarContainer'><div class='commentAvatar'>".
						//gets the avatar
						get_avatar($comment,90).
						//gets the author
						"</div><div class='commentAuthor'>".
							$comment->comment_author.
								"</div>");
						//checks to see if the author is the main post author
					if ( $post = get_post($post_id) ) {
					            if ( $comment->user_id === $post->post_author ){
									//echos a special "author tag" under the avatar of the author's post
					            	echo ("<div class = 'commentPostAuthor'>Post Author</div>");
					            }

					        }
									//gets the comment content
									echo ("</div><div class='commentContent'>".
									$comment->comment_content.
										//echos the comment action bar, a bar that comes up when hovering on the comment that contains the edit, reply, and permalink links
										"<div class='commentActions'> ");
									echo "<div class = 'editLink'>";
									//edit link (brokem)
									edit_comment_link('Edit');
									//reply link (broken)
									echo "</div><div class = 'replyLink'>";
									comment_reply_link();
									//<div class = "commentPermalink" (placeholder)
									echo "</div>";

									echo("</div>".
										"</div></div>" );
				//ends the loop
				endforeach;
				?>

Here's my full loop on Pastebin:
http://pastebin.com/R2n9bFN1

EDIT: Did someone move this to the hacks section? If not I think I'm going crazy, I could've sworn I put it in how to and troubleshooting :P

mortonc on "Front end posting overwriting custom meta fields"

$
0
0

I've created this page in my theme which allows users to edit their posts. It changes the information which there are fields for in the page BUT it overwrites all the other custom meta fields which are not in the edit page. Any ideas of where I'm going wrong?

<?php /* Template Name: Edit Posts2 */ 

$query = new WP_Query(array('post_type' => 'customtype’, 'posts_per_page' =>'-1', 'post_status' => array('publish', 'pending', 'draft') ) );

if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();

	if(isset($_GET['post'])) {

		if($_GET['post'] == $post->ID)
		{
			$current_post = $post->ID;

			$title = get_the_title();
			$content = get_the_content();

			$custom_one = get_post_meta($current_post, 'custom_meta_1', true);
			$custom_two = get_post_meta($current_post, 'custom_meta_2', true);
			$custom_three = get_post_meta($current_post, 'custom_meta_3', true);
			$custom_four = get_post_meta($current_post, 'custom_meta_4', true);
			$custom_five = get_post_meta($current_post, 'custom_meta_5', true);

		}
	}

endwhile; endif;
wp_reset_query();

global $current_post;

$postTitleError = '';

if(isset($_POST['submitted']) && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {

	if(trim($_POST['postTitle']) === '') {
		$postTitleError = 'Please enter a title.';
		$hasError = true;
	} else {
		$postTitle = trim($_POST['postTitle']);
	}

	$post_information = array(
		'ID' => $current_post,
		'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
		'post_content' => esc_attr(strip_tags($_POST['postContent'])),
		'post-type' => 'customtype',
		'post_status' => 'publish'
	);

	$post_id = wp_update_post($post_information);

	if($post_id)
	{

		// Update Custom Meta
		update_post_meta($post_id, 'custom_meta_1', esc_attr(strip_tags($_POST['customMetaOne'])));
		update_post_meta($post_id, 'custom_meta_2', esc_attr(strip_tags($_POST['customMetaTwo'])));
		update_post_meta($post_id, 'custom_meta_3', esc_attr(strip_tags($_POST['customMetaThree'])));
		update_post_meta($post_id, 'custom_meta_4', esc_attr(strip_tags($_POST['customMetaFour'])));
		update_post_meta($post_id, 'custom_meta_5', esc_attr(strip_tags($_POST['customMetaFive'])));

		wp_redirect( home_url().'/?p=56' ); exit;
	}

}

?>

<?php get_header(); ?>

	<!-- #primary BEGIN -->
	<div id="primary">

		<form action="" id="primaryPostForm" method="POST">

			<fieldset style="border:none;">

				<label for="postTitle"><?php _e('Post\'s Title:', 'framework') ?></label>

				<input type="text" name="postTitle" id="postTitle" value="<?php echo $title; ?>" class="required" />

			</fieldset>

			<?php if($postTitleError != '') { ?>
				<span class="error"><?php echo $postTitleError; ?></span>
				<div class="clearfix"></div>
			<?php } ?>

			<fieldset style="border:none;">

				<label for="customMetaFour"><?php _e(‘Custom 4:’, 'framework') ?></label>

				<input type="text" name="customMetaFour" id="customMetaFour" value="<?php echo $custom_four; ?>" />

			</fieldset>

			<fieldset style="border:none;">

				<label for="postContent"><?php _e('Post\'s Content:', 'framework') ?></label>

				<textarea name="postContent" id="postContent" rows="8" cols="30"><?php echo $content; ?></textarea>

			</fieldset>

		<fieldset style="border:none;">

				<label for="customMetaOne"><?php _e(‘Custom 1:’, 'framework') ?></label>

				<input type="text" name="customMetaOne" id="customMetaOne" value="<?php echo $custom_one; ?>" />

			</fieldset>

			<fieldset style="border:none;">

				<label for="customMetaTwo"><?php _e(‘Custom 2:’, 'framework') ?></label>

				<input type="text" name="customMetaTwo" id="customMetaTwo" value="<?php echo $custom_two; ?>" />

			</fieldset>

		<fieldset style="border:none;">

				<label for="customMetaThree"><?php _e(‘Custom 3:’, 'framework') ?></label>

				<input type="text" name="customMetaThree" id="customMetaThree" value="<?php echo $custom_three; ?>" />

			</fieldset>

            <b> Booking Toggle:</b>
            </br>

      		<fieldset style="border:none;">
       			 <span class="toggle">

				<input type="checkbox" name="customMetaFive" id="customMetaFive" value="checked" <?php if($custom_five=="checked"){echo "checked";} ?> />

				<label for="customMetaFive" data-off="OFF" data-on="ON"></label>

                </span>
		</fieldset>     

			<fieldset style="border:none;">

				<?php wp_nonce_field('post_nonce', 'post_nonce_field'); ?>

				<input type="hidden" name="submitted" id="submitted" value="true" />
				<button type="submit"><?php _e('Update Post', 'framework') ?></button>

			</fieldset>

		</form>

	</div><!-- #primary END -->

<?php get_footer(); ?>

greatsb on "Automatic Insertion of External References in website showing spam text at googl"

$
0
0

Hi,

When I see my wordpress website "http://techliebe.com" in a mobile then i see the spam text such as "privatsex sex cam chat sex cam deluxe" at the starting of posts, also it gets displayed in the google search results for each post, When the website is opened from computer then it doesnt show this spam text/ hides it. How to remove this spam text from website?

The Bad External References to my site:

http://tinyurl.com/obkloty
http://bit.ly/1jJFCiz
http://berjadigi.com/7A2

When i search a string "privatsex sex cam chat sex cam deluxe" in google i get About 1,77,000 results in advance search with this exact phrase means so many websites are caused by this hack.

Which element is causing this problem? wordpress or theme or plugin?

How to solve this problem, is this a hack? How to prevent such hacks?

Regards,
greatsb


MI on "WP Query - odd/even and post types"

$
0
0

Hi,

I want that odd and even posts would be different post types in one loop. How can i make it work? Here is the test query, which i think should work with getting odd and even ones, but how can i attach different post type here?

$args( 'post_type' => 'TYPE' );

$query = new WP_Query( $args );

<?php while (have_posts()): the_post() ?>
    <?php if ($wp_query->current_post % 2 == 0): ?>
        odd
    <?php else: ?>
        even
    <?php endif ?>
<?php endwhile ?>

Thanks

mortonc on "wp_db get 2 most recent items"

$
0
0

in my theme I've got a wp_db query which fetches the most recent resut from a table and then sets this as a variable.

What I would like to be able to do is get the two most recent results and set those as separate variables. How can I go about doing this?

abdul wahab12 on "i want to block urls in comments."

$
0
0

please tell me some kind of php code for blocking curls in comments are. like if some one puts any url in comment an error comments that you cannot put urls of hyperlinks here.

xymalf on "Local WAMP server says function undefined"

$
0
0

$azonassoc = amazon_assoc_tag;
$azonsecret = amazon_secret;
$azonaccess = amazon_access;

catching_var.php('$azonassoc','$azonsecret','$azonaccess');

I want to pass values from a FORM i have created to amazonapi.php but Wordpress shouting Function not defined.
I also would like to pass a film title to Amazon how do I do it? This is on a seperate PHP page than the settings page.

martin.kreativermoment on "Strip Shortcodes from RSS"

$
0
0

Hi, I'm not sure if this is the right section.
If not not, please move.

I got this template to create my rss, but all shortcodes are shown in plaintext.

<?php
/*
Template Name: Custom Feed
*/

$numposts = 10;

function yoast_rss_date( $timestamp = null ) {
  $timestamp = ($timestamp==null) ? time() : $timestamp;
  echo date(DATE_RSS, $timestamp);
}

function yoast_rss_text_limit($string, $length, $replacer = '...') {
  $string = strip_tags($string);
  if(strlen($string) > $length)
    return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer;
  return $string;
}

$posts = query_posts('showposts=5');

$lastpost = $numposts -1;

header("Content-Type: application/rss+xml; charset=UTF-8");
echo '<?xml version="1.0"?>';
?><rss version="2.0">
<channel>
  <title></title>
  <link></link>
  <description></description>
  <language>de_DE</language>

<?php foreach ($posts as $post) { ?>

  <item>

    <title><?php echo get_the_title($post->ID); ?></title>
	    <link><?php echo get_permalink($post->ID); ?></link>
	<description><![CDATA[ <br /> ]]><?php echo '<![CDATA[' .get_the_post_thumbnail($post->ID, 'thumbnail') .']]>' ?><![CDATA[ <br /> ]]><?php echo '<![CDATA['.yoast_rss_text_limit($post->post_content, 500).'<br/><br/>Weiterlesen: <a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a>'.']]>';  ?></description>
    <pubDate><?php yoast_rss_date( strtotime($post->post_date_gmt) ); ?></pubDate>
    <guid><?php echo get_permalink($post->ID); ?></guid>
  </item>

 <?php } ?>
</channel>
</rss>

Tried to use strip_shortcodes but I don't know where to place this. It dives me an empty page, or (on another position) it changes nothing.

Please help me out

Thanks

xymalf on "Wordpress plugin - menu's"

$
0
0

When developing a plugin how do you create the plugin name in your dashboard with a submenu for settings and one for the application please?

xymalf on "Forms and Menus"

$
0
0
* Register and add settings
     */
    public function page_init()
    {
        register_setting(
            'my_option_group', // Option group
            'my_option_name', // Option name
            array( $this, 'sanitize' ) // Sanitize
        );

        add_settings_section(
            'setting_section_id', // ID
            'My Custom Settings', // Title
            array( $this, 'print_section_info' ), // Callback
            'my-setting-admin' // Page
        );  

        add_settings_field(
            'id_number', // ID
            'Amazon Affiliate', // Title
            array( $this, 'id_number_callback' ), // Callback
            'my-setting-admin', // Page
            'setting_section_id' // Section
        );      

        add_settings_field(
            'id_number',
            'Amazon Access',
            array( $this, 'id_number_callback' ),
            'my-setting-admin',
            'setting_section_id'
        );  

	add_settings_field(
            'title',
            'Amazon secret',
            array( $this, 'title_callback' ),
            'my-setting-admin',
            'setting_section_id'
        );

    }

[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

I have wrote the above code but it is only displaying Amazon access and secret on my screen not the affiliate field.
How do I correct this please?
How do I pass the variable to my amazonapi.php code?


saltandpepper on "get_user_by slug isn't working"

$
0
0

This is the code I have and get_user_by seems to be returning an empty object

global $this_player;
$player_name = strtolower(str_replace(" ","",trim(str_replace(range(0,9),'',get_the_title($id)))));
$this_player = get_user_by('slug', $player_name);
if ( !$this_player ) die('No valid user found!');

Now I can't past the if statement, however if I manually replace $player_name with 'nicename' then it works, I have confirmed that $player_name is holding nicename so I am a little confused.

Thanks

dgmstuart on "Version number isn't showing up on the plugin directory page"

$
0
0

I'm the developer of

On the directory page (http://wordpress.org/plugins/dxw-security/) the version number isn't displayed. It should be in two places:

  1. on the download button (it isn't - it just says "Download Version")
  2. the default value in the compatibility section (the latest version is there in the list but isn't shown as the "current version")

I've checked everything I can think of:

I'm stumped as to what I might be doing wrong. Can anyone point me in the right direction?

SLAFmultimedia on "Custom Navigations Menus"

$
0
0

Hey WordPress Community,

I'm presently doing a website for a client using WordPress. The way he wants it is a 2 sections website. There will be a splash page where the user's going to chose the section he wants to go to.

Each section is going to have a different navigation menu and I'm not sure how to do it. I think I got the logic right but don't know how to apply it.

The way I would do it is by creating a global variable and as soon as the user select a section, give that global variable the name of the section. Then, call the specific menu associated with that variable. Don't know if this makes sense.

The problem is I don't know how to call a specific menu that I created in the dashboard for a specific section. I also don't know where to instantiate my global variables.

If you guys want more information or could help me, it would be very appreciated.

Thanks in advance.

SLAF

wpsamantha on "Redirect/forward page to latest taxonomy"

$
0
0

I have created a basic page with the slug /journal/.
I also have a custom taxonomy called 'issue' with terms that generates slugs in the following format:
* /journal/issue20/
* /journal/issue21/
* Etc...

I would like the page at /journal/ to redirect to the latest issue so in the above case, /journal/ would forward to /journal/issue21/ as long as 'issue21' has content and is not an empty term.

What is the best way to go about this without creating duplicate content?

My first thought was to setup a custom page template. The template would search the taxonomy terms from highest->lowest and the first one that has content would be queried. The page template would then include the taxonomy template. However, this would create duplicate content at /journal/ and /journal/issue21/.

My second thought was to setup a canonical redirect. Again, I would write code to determine the latest issue and then redirect to that issue. My concern here is that over time, the redirect will change as new issues are published. In my mind, a canonical redirect doesn't change over time.

Thoughts? Best practices?

In summary, I am trying to configure a 'latest issue' landing page without duplicating content.

xymalf on "Plug in menu causing fatal error"

$
0
0
/*
  Plugin Name: options menu
  Plugin URI:
  Description: Companion to recipe 'Implementing the plugin menu'
  Author: adrian
  Version: 1.0
  Author URI: http://www.xymalf.com
 */

<?php // display the admin options page
function plugin_options_page() {

<div>
<h2>My custom plugin</h2>
Options relating to the Custom Plugin.
<form action="options.php" method="post">
 settings_fields('plugin_options');
 do_settings_sections('plugin'); 

<input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); " />
</form></div>

}

 // add the admin settings and such
add_action('admin_init', 'plugin_admin_init');
function plugin_admin_init(){
register_setting( 'plugin_options', 'plugin_options', 'plugin_options_validate' );
add_settings_section('plugin_main', 'Main Settings', 'plugin_section_text', 'plugin');
add_settings_field('plugin_text_string', 'Plugin Text Input', 'plugin_setting_string', 'plugin', 'plugin_main');

 function plugin_section_text() {
echo '<p>Main description of this section here.</p>';
} 

<?php function plugin_setting_string() {
$options = get_option('plugin_options');
echo "<input id='plugin_text_string' name='plugin_options[text_string]' size='40' type='text' value='{$options['text_string']}' />";
} 

 // validate our options
function plugin_options_validate($input) {
$options = get_option('plugin_options');
$options['text_string'] = trim($input['text_string']);
if(!preg_match('/^[a-z0-9]{32}$/i', $options['text_string'])) {
$options['text_string'] = '';
}
return $options;
}
?>

[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

Viewing all 8245 articles
Browse latest View live




Latest Images