Note that I copied the original text to a clean text file. I tried each of your suggestions, and none seemed to work (tested by loading the http://www.adamsleatherworks.com/wp-content/plugins/top-10/top-10-addcount.js.php?top_ten_id=8 page). Before I tried one of your other suggestions, I first reverted back to the original code I copied to the text file.
I went back and edited lines 12-16 like you said, and also went back and added the initial code snippet (not realizing it was necessary to replace it in addition to the 12-16 edit)$wp_config_path = dirname ( dirname( dirname( dirname( __FILE__ ) ) ) );
That seems to work. Here is the entire file’s code:
<?php
//"top-10-addcount.js.php" Add count to database
Header("content-type: application/x-javascript");
// Force a short-init since we just need core WP, not the entire framework stack
define( 'SHORTINIT', true );
// Build the wp-config.php path from a plugin/theme
$wp_config_path = dirname ( dirname( dirname( dirname( __FILE__ ) ) ) );
$wp_config_filename = '/wp-config.php';
// Check if the file exists in the root or one level up
if( !file_exists( $wp_config_path . $wp_config_filename ) ) {
// Define ABSPATH since the wp-config.php file is one level up
define( 'ABSPATH', $wp_config_path . "/" );
// Just in case the user may have placed wp-config.php one more level up from the root
$wp_config_filename = dirname( $wp_config_path ) . $wp_config_filename;
}
// Require the wp-config.php file
require( $wp_config_filename );
// Include the now instantiated global $wpdb Class for use
global $wpdb;
// Ajax Increment Counter
tptn_inc_count();
function tptn_inc_count() {
global $wpdb;
$table_name = $wpdb->prefix . "top_ten";
$top_ten_daily = $wpdb->prefix . "top_ten_daily";
$id = intval($_GET['top_ten_id']);
if($id > 0) {
$wpdb->query("INSERT INTO $table_name (postnumber, cntaccess) VALUES('$id', '1') ON DUPLICATE KEY UPDATE cntaccess= cntaccess+1 ");
$current_date = gmdate( 'Y-m-d', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
$wpdb->query("INSERT INTO $top_ten_daily (postnumber, cntaccess, dp_date) VALUES('$id', '1', '$current_date' ) ON DUPLICATE KEY UPDATE cntaccess= cntaccess+1 ");
}
}
?>
It seems to be working fine now, and I’m not getting the sucuri warning anymore. Thanks for all your help!! 🙂
Plugin Author
Ajay
(@ajay)
Good news indeed!
Glad to know this work. I’ll test the code above on my installations as well and will put through a fix for Top 10.
The visits should be counting properly now. Let me know if this isn’t the case.
Thanks for testing it out.