Created
April 7, 2021 16:33
-
-
Save ozh/6455d192ac443c2a12379cc94f607b43 to your computer and use it in GitHub Desktop.
YOURLS : add fake links (for test installs)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Insert Fake Links | |
Plugin URI: http://yourls.org/ | |
Description: Populate DB with fake links for tests | |
Version: 1.0 | |
Author: Ozh | |
Author URI: http://ozh.org/ | |
*/ | |
yourls_add_action( 'plugins_loaded', 'ozh_yourls_ifl_add_page' ); | |
function ozh_yourls_ifl_add_page() { | |
yourls_register_plugin_page( 'ozh_ifl', 'Add Fake Links', 'ozh_yourls_ifl_do_page' ); | |
} | |
// Display admin page | |
function ozh_yourls_ifl_do_page() { | |
if( isset( $_POST['action'] ) && $_POST['action'] == 'insert_fake_links' ) { | |
ozh_yourls_ifl_process(); | |
} else { | |
ozh_yourls_ifl_form(); | |
} | |
} | |
// Display form | |
function ozh_yourls_ifl_form() { | |
$nonce = yourls_create_nonce('insert_fake_links'); | |
echo <<<HTML | |
<h2>Insert Links</h2> | |
<form method="post"> | |
<input type="hidden" name="action" value="insert_fake_links" /> | |
<input type="hidden" name="nonce" value="$nonce" /> | |
<p>Insert <input type="text" name="number" /> links</p> | |
<p><input type="submit" value="Insert" /></p> | |
</form> | |
HTML; | |
} | |
function ozh_yourls_ifl_process() { | |
// Check nonce | |
yourls_verify_nonce( 'insert_fake_links' ); | |
$number = abs( intval( $_POST['number'] ) ); | |
for ($i = 1; $i <= $number; $i++) { | |
$title = $url = 'http://127.0.0.1/' . yourls_rnd_string( mt_rand(2, 10) ); | |
yourls_add_new_link( $url, '', $title ); | |
} | |
echo "<p>$number links added</p>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a simple CLI script if you want to insert very quickly a very large number of fake rows (here, 10 000 rows at once)
(everything is hard coded, edit and customize)
Example to add 1 million links :