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

romualdv on "Woocommerce Place Order Hack"

$
0
0

Hi,

I would like to find out how to (and if possible) do the following:

On our ecommerce site when we are on the 'checkout' page a customer can select a payment method and then click on 'place order' for the purchase to go through and all the details are written to the database.

We have a payment method called 'Account Funds'. These funds are inserted manually on a customers account by the site admin. We have created a custom database table cs_account_funds that we are busy developing a front-end user form for to write the values to those specific db_metas.

My question: If the Account Funds payment method is used and a customer clicks on Place Order, how then can we write that specific order total as a negative to the cs_account_funds table as well as to wherever the values are captured on the DB?


siknoidas on "how do Login with query string? Test or user in in DB"

$
0
0

Hello,

I wanna create simple query string to check or user is registred in wordpress site or no. I need this for apps communicate with WP DB.

How create something like - wp-login.php?log=testuser&pwd=password ?

I just need get output from WP just - OK or NO (Ok - let in)

Tryed json, but it don't have that function. Or i missed?
https://wordpress.org/plugins/json-api-auth/

Thank you.

dilipcom2010 on "Does using get_posts() to fetch all the post data affect the host site?"

$
0
0

I'm making a plugin which extracts all the data from wordpress blog when the user activates the plugin and hits my database api. The code I'm using is as under:

$allposts=get_posts($args);
			echo "TotalLength: ".sizeof($allposts).";";
			if($allposts)
			{
				$str=array();
				$cnt=0;
				$cnt1=0;
				foreach($allposts as $post)
				{
					$cnt = $cnt + 1;
					array_push($str,post_detail($post));
					if($cnt == 10)
					{
						//echo "Count ".$cnt1." = ".$cnt;
						$cnt1 = $cnt1 + 1;	

						$cnt =0 ;
						$str =array();
					}
				}
				if($cnt>0)
				{
					//echo "Count ".$cnt1." = ".$cnt;
					$jsonl = json_encode($str);
					echo'<script type="text/javascript">hit_pd_server('.$jsonl.');</script>';
				}
			}

I checked other related post plugin and found some of them using this method. However, my concern is if a blog contains tens of thousands of posts, would using get_posts() affect their site. I can handle the traffic on my api but I'm not sure if their blog can handle the requests made by get_posts().
Also, what are the alternatives to get_posts() that can ensure that I fetch the data from client's site one by one or be able to fetch them in batches instead of fetching all of them once.
Any best practices on making related post type plugins that you can share will also be appreciated ?

salihkulangara on "Filter Content for Attachment and Modify it"

$
0
0

I want to do this, just search the content for any attachments, and if attachments, usually the embedded images inside post, show the Custom size versions(that i have defined in functions.php) of those image in front end. I think we want to do a filter on, the_content, wp_get_attachment_image , etc.... . I am not sure about that, So if there anyone who can help me??

revxx14 on "Walker to count number of child classes and add number to parent classes"

$
0
0

I've got a walker that counts the number of the class "break" appear in $depth = 1 unordered lists. I need to add this number as a class to each unordered lists parent <li>, but by the time I've counted the number of breaks in the child unordered list, the parent list item has already been generated, so I can't add the class. I'm' so close to finishing this walker, I've got to be missing something really small. Please help!

// mega menu walker
/*
	ONE REMAINING BUG:
	- Need to add class to LI containing mega-menu-columns-#
*/
class megaMenuWalker extends Walker_Nav_Menu {
	private $column_limit = 3; /* needs to be set for each site */
    private $show_widget = false;
	private $column_count = 0;
    static $li_count = 0;
    function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
        $classes = empty($item->classes) ? array() : (array) $item->classes;
        $item_id = $item->ID;
        if ($depth == 0) self::$li_count = 0;
        if ($depth == 0 && in_array("widget", $classes)) {
            $this->show_widget = true;
			$this->column_count++;
        }
		if ($depth == 1 && self::$li_count == 1) {
			$this->column_count++;
		}
        if ($depth == 1 && in_array("break", $classes) && self::$li_count != 1 && $this->column_count < $this->column_limit) {
            $output .= "</ul><ul class=\"sub-menu\">";
			$this->column_count++;
        }
		if ($depth == 0 && $this->column_count > 0) {
			// always returns 0 unless there's a widget
			$mega_menu_class = " mega-menu-columns-" . $this->column_count;
		}
        $class_names = join(" ", apply_filters("nav_menu_css_class", array_filter($classes), $item));
        $class_names = " class=\"" . esc_attr($class_names . $mega_menu_class) . "\"";
        $output .= sprintf(
            "<li id=\"menu-item-%s\"%s><a href=\"%s\">%s</a>",
            $item_id,
            $class_names,
            $item->url,
            $item->title
        );
        self::$li_count++;
    }
    function start_lvl(&$output, $depth = 0, $args = array()) {
        if ($depth == 0) {
			$output .= "<section>";
        }
        $output .= "<ul class=\"sub-menu\">";
    }
    function end_lvl(&$output, $depth = 0, $args = array()) {
        $output .= "</ul>";
        if ($depth == 0) {
            if ($this->show_widget) {
                ob_start();
                dynamic_sidebar("Navigation Callout");
                $widget = ob_get_contents();
                ob_end_clean();
                $output .= $widget;
                $this->show_widget = false;
            }
            $output .= "</section>";
        }
    }
    function end_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
		if ($depth == 0 && $this->column_count > 0) {
			/* needs to be added to opening level 0 li */
			$column_count_class = " mega-menu-columns-" . $this->column_count;
			$output .= $column_count_class;
			/* end */
			$this->column_count = 0;
		}
        $output .= "</li>";
    }
}

miowebdesigns on "Extra spaces in vcard download file"

$
0
0

I have a vcard program that I have never used within Wordpress. It is the basic vcard creation that you can find on any website.

print <<<END
BEGIN:VCARD
VERSION:3.0
N:$last;$first;$middle;;;
FN:$fullname
TITLE:$title
PHOTO;VALUE=URL;TYPE=JPG:$path$photo
ORG:$office
TEL;WORK;VOICE:$tel
TEL;WORK;FAX:$fax
EMAIL;TYPE=PREF;INTERNET:$attorney_email
ADR;WORK;ENCODING=QUOTED-PRINTABLE:;;$address=0D=0A$address2;$city;$state;$zip;$country;
URL;TYPE=WORK:http://criminallawsexcrimessacramento.com/
END:VCARD
END;

$output = ob_get_contents();

header('Content-Type: text/x-vcard');
header('Content-Disposition: attachment; filename=vCard_' . $filename . '.vcf');
echo trim($output);
exit();

The problem is the output has extra leading zeros. When I use this code on a php site, not Wordpress, the output has no extra spaces. Not sure why the extra spaces are happening or how to remove them. As you can see in the code I am using trim().
example of file
"
BEGIN:VCARD
VERSION:3.0
N:Daly;Kresta;N.;;;
FN:Kresta N. Daly
TITLE:Partner
PHOTO;VALUE=URL;TYPE=JPG:http://kd.bothwip2013.com//images/attorney_photos/kresta-image.png
ORG:Sacramento
TEL;WORK;VOICE:(916) 440-8600
TEL;WORK;FAX:(916) 440-9610
EMAIL;TYPE=PREF;INTERNET:kdaly@barth-daly.com
ADR;WORK;ENCODING=QUOTED-PRINTABLE:;;431 I Street, Suite 201=0D=0A;Sacramento;CA;95814;United States;
URL;TYPE=WORK:http://criminallawsexcrimessacramento.com/
END:VCARD"

Thanks for any suggestions.
Michael

Gannet on "Multiple custom Rss Feed"

$
0
0

Hi everyone!

I added two custom Rss Feed to a WP site. In wp-content/theme/themename/functions.php I added this lines:

add_filter('init','init_feed_1');
function init_feed_1() {
    add_feed('feed1','feed_1');
}
function feed_1{
...
}
add_filter('init','init_feed_2');
function init_feed_2() {
    add_feed('feed2','feed_2');
}
function feed_2{
...
}

the first feed has no problem while the second one shows me "unknown page" error. Someone can help me?
Thanks in advance.

aldhaf on "How to apply sliding effect between page ?"

$
0
0

Hi there,

I'm quite new with wordpress, PHP, and stuff. i usually just tweak css from theme a little.

what i want to ask is,

how can i achieve same effect like on this website :

http://bozkie6.wix.com/axan

using wordpress?

i tried "page scroll to id" plugin but i still can't understand

can anyone help me?

thanks before,
Al


Mjedrzejczyk on "jQuery Autocomplete Not Working in Chrome/Firefox"

$
0
0

Hello,

I've made use of the code at https://github.com/stephenh1988/WordPress-AutoComplete-Search to add autocomplete to my Wordpress search.

(It's based on the tutorial at: http://wp.tutsplus.com/tutorials/theme-development/add-jquery-autocomplete-to-your-sites-search/)

It works in Safari and does nothing in Chrome and Firefox.

Unfortunately, I have limited knowledge of javascript. I'm assuming that the problem lies in the following code since, clearly, the backend is doing its job and I'm getting results in Safari.

<script type="text/javascript">
	jQuery(document).ready(function ($){
		var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ); ?>';
        	var ajaxaction = '<?php echo self::$action ?>';
        	$("#secondary #searchform #s").autocomplete({
			delay: 0,
			minLength: 3,
			source: function(req, response){
				$.getJSON(ajaxurl+'?callback=?&action='+ajaxaction, req, response);
			},
            		select: function(event, ui) {
                		window.location.href=ui.item.link;
            		},
        	});
   	 });
    </script>

Anyone have an idea of what the problem is?

maxita on "can you do me this code, it is possible? (see post by user)"

$
0
0

Hello,

Sorry for my english..

Well, how can I do to do this in the sidebar.
I just want to see posts from only a single member, by a choice in the user's list

1. I select the user (author) I want to see posts
2. I see every member's posts sorted by category and in alphabetical order

it's possible? whith a code?

thank you ;)

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(); ?>

ProStone on "Rewrite Attachments Page URL"

$
0
0

Hi,
how can i change Attachment Pages URL to something like this
example.com/photos/attachment_ID/post_name/attachment_name
currently I added on functions.php file the following code

function wpd_attachment_link( $link, $post_id ){
    $post = get_post( $post_id );
    return home_url( '/photos/' . $post->ID . $post->post_name );
}
add_filter( 'attachment_link', 'wpd_attachment_link', 20, 2 );

source
but it is showing me as domain.com/photos/Attachment_IDattachment_name
thank you

ajcke on "wp_list_pages Output Parent and Child Pages"

$
0
0

I've been using the code below to auto display pages and child pages in a sidebar. Our site has a few parent pages and the rest of the pages are all nested within these. Right now the code displays the parent page, child pages, and all grandchildren pages no matter what page a user is on. I would like to modify the code to display the parent page for the title and child pages ONLY in the ul. It would also be cool to be able to leave out a page if needed.

<?php
  if($post->post_parent) {
  $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
  $titlenamer = get_the_title($post->post_parent);
  }

  else {
  $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
  $titlenamer = get_the_title($post->ID);
  }
  if ($children) { ?>

  <h2> <?php echo $titlenamer ?> </h2>
  <ul>
  <?php echo $children; ?>
  </ul>
<?php } ?>

Example of Output
If a user is on any of the pages below the menu looks the same:
<h2>Athletics</h2>

  • Baseball
    • HS Baseball
  • Basketball
    • HS Basketball – Boys
    • HS Basketball – Girls
    • JH Basketball – Boys
    • JH Basketball – Girls
  • Cheerleading
    • HS Cheerleading
    • JH Cheerleading
  • Football
    • HS Football
    • JH Football
  • Softball
    • HS Softball
  • Track & Field
    • HS Track & Field – Boys
    • HS Track & Field – Girls
    • Indoor Track
    • JH Track & Field – Boys
    • JH Track & Field – Girls
  • Volleyball
    • HS Volleyball
    • JH Volleyball

Desired Output Example
If a user is on the basketball page the menu only looks like this:
<h2>Basketball</h2>

  • HS Basketball – Boys
  • HS Basketball – Girls
  • JH Basketball – Boys
  • JH Basketball – Girls

If a user is on the athletic root parent page the menu would look like this:
<h2>Athletics</h2>

  • Baseball
  • Basketball
  • Cheerleading
  • Football
  • Softball
  • Track & Field
  • Volleyball

dangleraction on "Blank admin dashboard. Am I using wp_enqueue correctly on my child theme?"

$
0
0

Hello,

I have never had this problem before until I forced myself to use wp_enqueue_scripts. I think it's a really cool way of doing things, by the way. I'm a web designer and beginner at java programming.

My issue is just what the title says: Blank pages on my whole website, including the Dashboard. When the site does work, I see the blank page again whenever updating pages, configuring plugins, etc. It always crashes when "&_wpnonce=" is affixed the the end of my url.

When the parent theme is active, my Dashboard and all functions work fine, except my WP Admin bar is not showing on the front end. One problem at a time though.

My question is; What is the best way to arrange the wp_enqueue function to add specific scripts & stylesheets to specific pages?

I will share what my functions.php looks like in another comment, but for right now, can you tell me if this a good way to approach what I want to do?

<?php
if (!is_admin()) {
    add_action( 'wp_enqueue_scripts', 'miosa_theme_scripts' );
    function miosa_theme_scripts() {
            if ( is_page_template('page-slider.php') ) {
                wp_register_script('...');
                wp_register_script('...');
                wp_register_script('...');
                wp_enqueue_script('modernizr');
                wp_enqueue_script('slider-jquery');
                wp_enqueue_script('slider-config');
            }
            elseif ( is_page_template('page-photo.php') ) {
                wp_register_script('...') );
                wp_register_script('...') );
                wp_enqueue_script('isotope-jquery');
                wp_enqueue_script('isotope-config');
            }
    }
}

That is a generalized version for my javascript. There is another one for my stylesheets and they all have a unique $handle

I am using the (!is_admin) condition because I thought these scripts were causing my WP Dashboard to be blank. It could be something else? I have no idea. But between this and my browser cache and server cache, this website development is taking a lot longer than I wanted it to. I would really appreciate to hear other peoples' advise because this is the first time I'm using the wp_enqueue_scripts constructor.

Thanks,
Rick

Luke Janicke on "How to customize "Insert Media" output?"

$
0
0

I want my editors to be able to use the default "Insert Media" feature but I want to customize the output. By default, "Insert Media" produces something like this:

[caption id="attachment_414" align="aligncenter" width="600"]<a href="http://www.theharbiner.com/?attachment_id=414" rel="attachment wp-att-414"><img src="http://www.theharbiner.com/media/2014/06/baskets-of-tea-1-600x397.jpg" alt="Baskets of Tea" width="600" height="397" class="size-medium wp-image-414" /></a> Varieties of tea on display and for purchase.[/caption]

Wow! That’s a lot. And it contains a mix of shortcode, hardcoded HTML and a lot of hard-coded attributes.

What I want the output to be is (for a single image):

[image id="414"]

Simple!

This would be easier for my editors (who don’t know HTML) and it’s future proof – I can regenerate images at different sizes and change HTML and attributes any time as I develop the theme. It also looks good alongside the Markdown that I’m making all my editors use.

I have already written the shortcode functions to output the desired HTML in my theme. What I need to do is filter the returned output of the actual "Insert Media" function in the post editor.

Is this possible? What is the filter to use?

Note: The answer is not img_caption_shortcode. That filter is for modifying the HTML output by the theme.


rechazame on "Whento use 'init' and when to use a function in functions.php?"

$
0
0

Let's say I want to disable users from viewing the dashboard.

I can add the following to functions.php:

function hide_dashboard_init() {
	if ( is_admin() && !current_user_can( 'manage_options' ) ) {
		wp_redirect( home_url() );
		exit;
	}
}
add_action( 'init', 'hide_dashboard_init' );

But why not just add a regular function to functions.php? Something like that:

function hide_dashboard() {
if ( is_admin() && !current_user_can( 'manage_options' ) ) {
wp_redirect( home_url() );
}
}

otti.steinhauer on "How to send a SMS"

$
0
0

Hello,
at my plugin I'm already sending automatic mails with wp_mail() function. Now I want to send SMS and I don't know how to do that.
I have got via a form the number of a mobile phone and I can create the message via code. So what is the best way to send the message as SMS to the number?

Thanks

Ottilie

jetm3ist3r on "Wordpress site hacked into, DID NOT BACK UP. PLEASE HELP"

$
0
0

Hello,

I am new to web development. I created a website and did not back up the theme and content. Is there ANYWAY to retrieving my work? Please help. Any advice is Greatly appreciated!

hannahhayes on "Adding classes to Woocommerce widget"

$
0
0

Hi there,

I'm trying to add the classes 'first' and 'last' to the first and last thumbnails in each row on this page which is using the WooCommerce products widget:

http://www.hannahhayes.co.uk/shop/

The effect I'm trying to achieve is similar to what is seen here:

http://www.hannahhayes.co.uk/product-category/curious-artefacts/

which uses the ordinary WooCommerce products loop.

I'm afraid my knowledge of php is terrible/non-existent so any point in the right direction would be much appreciated.

rakesh 7846 on "how to use grep or findstr"

$
0
0

my site is also hacked my this meta refresh but i don't see the any code <meta http-equiv="refresh" content="0; url=http://www.youtube.com/watch?v=RFngSCaY5nA"> in the page source of the redirected page.
how is this possible ?
I am having access to backend of my site but it is mearly helpful cause how can i use gref or findstr?
I lost google adsense account and also my google rankings are lost please help me..
how can i use grep or findstr using FTP please give me a tutorials..
Thanks Regards..

Viewing all 8245 articles
Browse latest View live




Latest Images