Skip to content

Instantly share code, notes, and snippets.

@anthonybudd
Last active March 16, 2017 22:05
Show Gist options
  • Select an option

  • Save anthonybudd/f7efa8b8dfef75ef5fc3c1e439d95890 to your computer and use it in GitHub Desktop.

Select an option

Save anthonybudd/f7efa8b8dfef75ef5fc3c1e439d95890 to your computer and use it in GitHub Desktop.
<?php
function seedHook(){
if(@$_REQUEST['seed'] === 'true'){
for($i = 0; $i < 50; $i++){
Product::insert([
"title" => "Product ". (count(Product::all())+1),
"color" => array_values(["green", "red", "blue"])[rand(0, 2)],
"price" => rand(50, 2000),
]);
}
}
}
add_action('init', 'seedHook');
function seedButton($wp_admin_bar){
$wp_admin_bar->add_node([
'id' => 'seed-button',
'title' => 'Seed',
'href' => admin_url('/edit.php?'. http_build_query(['seed' => 'true', 'post_type' => Product::getPostType()])),
]);
}
add_action('admin_bar_menu', 'seedButton', 50);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment