bbMenu 1.1 programming problem (advanced!)
-
Hi,
I am currently upgrading my bbMenu plugin. You can now edit the titles en safe them to you db. The problem is, the last part I can’t get the saving to work.
In the JS file I have now:
var url = 'edit.php';
This file (edit.php) is called when someone renames the menu item and has the following code:
<?php
$id = $_POST['id'];
$content = $_POST['content'];
echo stripslashes(htmlentities($content)); ?>Now I don’t want to have an external file so I copy past this code into my bbmenu.php and changed the var url in the JS file too:
var url = '../my-plugins/bbmenu.php';
So it now calls the bbmenu.php but this gives some errors, cause it will reload the plugin file:
Fatal error: Call to undefined function add_action() in /bbpress/my-plugins/bbmenu.phpon line 30
How to solve this?
If this aint possible what do I need to add to edit.php so it also safes the stuff to the db?
Hope you guys can help me out
-
The errors stem from the fact that plugins aren’t designed to be called in isolation. They are included into the rest of bbPress when they are loaded. Meaning that if you try to run the plugin in isolation, then you won’t have access to the whole bbPress API (including the add_action() function and all the bbdb class).
If you take a look at how tag addition works in the core, you will probably get an insight into the best way to do this.
Hmm well so the easiest way is to keep the external file containing:
<?php
$id = $_POST['id'];
$content = $_POST['content'];
echo stripslashes(htmlentities($content)); ?>This file returns the edited text (this works), but how can I let it safe the variables to the database at the same time?
It’ll have to save: $content to the table bb_menu -> item
where $id = edit_id
Tried some stuff, but couldn’t get this updated into the db
Include the following at the top of the new file:
require_once('../bb-load.php');
You may have to adjust the path a little to correctly reference the file.
That should give you access to the whole API, including the $bbdb object for manipulating the database.
Got now this:
<?php
require_once('../bb-load.php');
global $bbdb, $bb_table_prefix;
$id = $_POST['id'];
$content = $_POST['content'];
$bbdb->query("UPDATE ".$bb_table_prefix."menu SET item = '". $_POST['content'] ."' WHERE item_id = '". $_POST['id'] ."'");
echo stripslashes(htmlentities($content));
?>This should work?
- You must be logged in to reply to this topic.