Plugin Function Permissions – Newbie Help
-
Hi folks,
So, I’m a newbie developer when it comes to wordpress plugins and have only had to start doing it recently due to staff changes.
Anyway, I’ve written a basic plugin for a client. The aim of the plugin is to allow admin users to create lists of people and the services they offer, and then add search functions so that we can add a search facility to a template that searches this new database list of people.
This all works fine.
I’m now trying to extend the functionality so that the list of services is controllable from the admin backend.
I’ve written functions to add new services, add a service to a person etc and I’ve got those working. However, I’m trying to write a function to remove a service from a person but every time I call it, I get a permission denied error. I suspect I’m missing some sort of add_action or register function.
My function:
public function people_finder_service_remove($service_id = null, $people_id = null) { if($service_id != null and $people_id != null) { global $wpdb; $wpdb->delete('wp_pf_people_service', array('service_id' => $service_id, 'people_id' => $people_id)); } wp_redirect("/wp-admin/admin.php?page=people-finder-admin"); }
As you can see, it doesn’t do much at the moment, I just need it to delete a database entry then return the user to index function for people.
I’m calling the function in the following way:
<table> <thead> <tr> <th>Service Provided By This Person</th> <th></th> </tr> </thead> <tbody> <?php foreach($my_services as $service): ?> <tr> <td><?php echo $service->name; ?></td> <td><a href="/wp-admin/admin.php?page=people-finder-service-remove&id=<?php echo $service->id; ?>&personid=<?php echo $id; ?>">Delete</a></td> </tr> <?php endforeach; ?> </tbody> </table>
Now, it seems that this will only work if I’ve added my function as a submenu using the add_submenu_page function. However, I don’t want to do this as a menu item makes no sense for this function.
What function do I need to call to register my new function so that I can call it using a URL? Is it even possible?
If needed, I can turn each row in my table into a form that posts back to the page I’m on but I was hoping for a better way.
Many thanks for your help
-Alex
- The topic ‘Plugin Function Permissions – Newbie Help’ is closed to new replies.