Last active
February 23, 2017 17:14
-
-
Save anthonybudd/7f1582def34d4a653e3de14120d56a5e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
Product::register(); | |
function randomString($length = 10) { | |
return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)) )),1,$length); | |
} | |
function seedButton($wp_admin_bar){ | |
$wp_admin_bar->add_node([ | |
'id' => 'seed-button', | |
'title' => 'Seed', | |
'href' => admin_url('?'. http_build_query(['seed' => 'true'])), | |
]); | |
} | |
add_action('admin_bar_menu', 'seedButton', 50); | |
function seedHook(){ | |
if(isset($_REQUEST['seed']) && | |
$_REQUEST['seed'] == 'true'){ | |
for($i = 0; $i < 50; $i++){ | |
Product::insert([ | |
'title' => randomString(), | |
'price' => rand(50, 2000), | |
// 'color' => 'DEFAULT', This will fallback to the deafult value | |
]); | |
} | |
add_action('admin_notices', 'seedSuccess'); | |
} | |
} | |
add_action('init', 'seedHook'); | |
function seedSuccess(){ | |
?> | |
<div class="notice notice-success is-dismissible"> | |
<p>Products seeded with 50 new posts</p> | |
</div> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment