OK Full Code:
<?php
//check to see whether the user is an admin or not.
if (is_admin()) {
function wpsc_display_products_seo(){
global $wpdb;
$productList = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_PRODUCT_LIST . " ORDER BY name ASC");
echo get_admin_page_parent();
$path = 'admin.php?page=wpsc_product_seo_details';
$url = admin_url($path);
?>
<h2><?php _e('Products List','wpsc'); ?></h2>
<p>Below is a list of products. Select a product to edit it's SEO properties.</p>
<table>
<tr>
<td></td>
<td>Product Name</td>
<td>Meta Title</td>
<td>Meta Description</td>
<td>Edit</td>
</tr>
</table>
<table>
<?php if($productList) : ?>
<?php foreach($productList as $product) : ?>
<?php $meta = getProductMeta($product->id); ?>
<tr style="background:#fff;">
<td width="200"><?php echo $product->name; ?></td>
<td width="300"><?php getVal($meta, 'meta_title'); ?></td>
<td width="200"><?php getVal($meta, 'meta_description'); ?></td>
<td width="200"><?php getVal($meta, 'meta_keywords'); ?></td>
<td width="200"><a href="<?php echo $url; ?>">Edit</a></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</table>
<?php
}
function wpsc_product_seo_details()
{
echo "<h2>Hello</h2>";
}
function getProductMeta($id)
{
global $wpdb;
$meta = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_PRODUCT_META . " WHERE product_id = $id");
if($meta)
{
return $meta;
} else {
return null;
}
}
function getVal($RS, $key)
{
if($RS)
{
if (property_exists($RS, $key))
{
return $RS->$key;
}
}
return null;
}
function wpsc_add_seo_admin_pages($page_hooks, $base_page) {
$page_hooks[] = add_submenu_page($base_page, __('SEO For Products','wpsc'), __('SEO For Products','wpsc'), 7, 'wpsc-module-seo', 'wpsc_display_products_seo');
return $page_hooks;
}
add_filter('wpsc_additional_pages', 'wpsc_add_seo_admin_pages',10, 2);
}
?>
OLD POST
Hi Guys,
I am currently writing a plugin for my client in wordpress. The issue I am having is when a user clicks on edit to change a record I am not sure how to create the admin link to do this.
i.e.
<a href="<?php echo get_bloginfo('url'); ?>/wp-admin/admin.php?page=wpsc_product_seo_details">Edit</a>
function wpsc_product_seo_details()
{
echo "<h2>Hello</h2>";
}
I know my markup for the tag is probably wrong but I was just testing. Do I need to register a hook to do this.
I am not sure what you are trying to do.
Admin links can be conveniently created with
admin_url()
function, like this:What exactly do you have problem with?
Do you have problems creating the administration page?
Just some information to tag onto the discussion, and this may be useful to you later..
When you’re on a plugin page, various admin variables are set, you can build a base URL from those variables and generate links from there, assuming you want them to point at the current plugin page..
Want to add your own query vars onto that URL, simply add them to the variable created above using
add_query_arg
…It should work in theory at least, i didn’t test the code, but i see no reason it wouldn’t work.. 🙂
Resolved!
Try to overcomplicate things when a simple conditional would of done the trick in the main function called from the page.