WordPress SQL injection

The insert method of $wpdb already scapes the data taking care of SQL injection. What you should worry about is about data sanitization and validation. For exmpla: Sanitization What type of data do you accept in $votes? A integer value? If so, be sure $votes contains a integer value. You cuold do it, for exmaple, … Read more

Security: blocking direct access of php files

In my opinion, the only way to do this (within the context of WordPress) is: if ( ! defined( ‘ABSPATH’ ) ) // Or some other WordPress constant exit; The second technique is vague and does give the same level of checking (it only checks that the filename of the main PHP file matches itself, … Read more

Can you use a WordPress front-end only and have rest of pages as pure PHP

It is a little hard to grasp how much of WordPress you really want to replace. WordPress at front-end will typically take care of following steps: parse the requested URL (typically “pretty”) determine the current context of request (query variables) query the required set of posts determine and load which theme template fits bets proceed … Read more

db converts decimal number wrong

Within $wpdb->insert, you are using %d which is used to store integer, use %f instead which will store float/decimal values. $registrering = $wpdb->insert( $wpdb->prefix . ‘registreringer’, array( ‘fiske_vaegt’ => $fiske_vaegt ), array( ‘%f’ ) );

get_the_title() gets printed out twice

Your conditional is always true. To understand why, consider what happens in this function when there is no post parent: function get_top_ancestor_id() { global $post; // no parent so this doesn’t run: // if($post->post_parent) { // $ancestors = array_reverse(get_post_ancestors($post->ID)); // return $ancestors[0]; // } return $post->ID; } Which simplifies to: function get_top_ancestor_id() { global $post; … Read more

Shortcode to show the code

get_footer() echos the contents of the footer.php file. add_shortcode() requires that the callback return the contents of the shortcode and not echo it. I suppose you could do something like this if you really want. function show_footer() { ob_start(); get_footer(); return ob_get_clean(); } add_shortcode( ‘show_f’, ‘show_footer’ );