Skip to content

Instantly share code, notes, and snippets.

@pixelbart
Created August 27, 2020 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelbart/658b5b213275cc37b01352c8c07d3eb5 to your computer and use it in GitHub Desktop.
Save pixelbart/658b5b213275cc37b01352c8c07d3eb5 to your computer and use it in GitHub Desktop.
Enables you to enter votes for the Helpful WordPress Plugin. The votes count as real votes!

Force a certain number of votes for the Helpful Plugin.

This snippet is used to enter a desired number of votes into the Helpful database. The votes count as correct(!) votes and can only be recognized in the database by the "_cheating".

ATTENTION: This process is reversible and consumes a lot of power depending on how many posts exist and how many votes are to be created!

Helpful is not designed to create votes just like that. This is more of a "cheating" process and is actually not rated by Helpful.

The votes added in this way are also counted in the statistics. With such a high number of votes (300 in this case), this can break the statistics because the votes are all created for the current time!

Translated with www.DeepL.com/Translator (free version)

Usage

Here you can find out how to run PHP in WordPress: https://helpful-plugin.info/documentation/execute-php-code/

WordPress Plugin

https://wordpress.org/plugins/helpful/

<?php // functions.php
/**
* Start Value
*/
$amount = 300;
/**
* Helpful Post Types set in the Helpful settings.
*/
$post_types = get_option( 'helpful_post_types' );
/**
* Query arguments for our custom WP_Query.
*/
$args = [
'post_type' => $post_types, // helpful post types
'fields' => 'ids', // return only ids
'posts_per_page' => -1, // all posts
];
$query = new WP_Query( $args );
if ( $query->posts ) {
foreach ( $query->posts as $post_id ) :
/**
* Current amount of pros by post_id.
*/
$pro = intval( helpful_get_pro( $post_id ) );
/**
* If the post already has 300 or more votes,
* continue with the next post.
*/
if ( $amount <= $pro ) {
continue;
}
/**
* Run through the total number and until you reach the Helpful amount,
* add Helpful to the database and create a random user ID so the
* vote does not count twice.
*
* A "_cheating" is added to the ID. So that it can be distinguished
* from the correct ones in the database.
*/
for ( $i = 1; $i <= $amount; $i++ ) :
$user = bin2hex( openssl_random_pseudo_bytes( 5 ) ) . '_cheating';
Helpful_Helper_Values::insertPro( $user, $post_id );
endfor;
endforeach;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment