July 26, 200917 yr Hi All , Im trying to make a plugin for wordpress but im having trouble with the database part of getting my database content. I have found a way to pull database info from the options table that wordpress installs i copyed this and added my own table but using the same code it wont pull from mine even though i copyed the table design. here is my complete code. <?php /* Plugin Name: wp-html-profile-adder Plugin URI: http://www.swipedstudio.com/wp_plugin/ Description: Plugin for adding html/xhtml code at the bottom of profile page. Version: 0.1 Author: Sam Miller Author URI: http://www.swipedstudio.com/ */ /* Copyright 2009 Sam Miller (email : skdsounds@hotmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // Create a table for our plugin to hold the new/old html for profile page. $jal_db_version = "0.1"; // create the tables needed or activation of plugin. register_activation_hook(__FILE__,'jal_install'); function jal_install () { global $wpdb; global $jal_db_version; $table_name = $wpdb->prefix . "profile_adder"; if($wpdb->get_var("show tables like '$table_name'") != $table_name) { $sql = "CREATE TABLE " . $table_name . " ( option_id mediumint(9) NOT NULL AUTO_INCREMENT, option_name text NOT NULL, option_value text NOT NULL, UNIQUE KEY id (option_id) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); $new_text = "new profile page."; $old_text = "old profile page."; $insert = "INSERT INTO " . $table_name . " (option_name, option_value) " . "VALUES ('" . $wpdb->escape('new_text') . "','" . $wpdb->escape($new_text) . "')"; $results = $wpdb->query( $insert ); $insert = "INSERT INTO " . $table_name . " (option_name, option_value) " . "VALUES ('" . $wpdb->escape('old_text') . "','" . $wpdb->escape($old_text) . "')"; $results = $wpdb->query( $insert ); add_option("jal_db_version", $jal_db_version); $installed_ver = get_option( "jal_db_version" ); if( $installed_ver != $jal_db_version ) { $sql = "CREATE TABLE " . $table_name . " ( id mediumint(9) NOT NULL AUTO_INCREMENT, time bigint(11) DEFAULT '0' NOT NULL, name tinytext NOT NULL, text text NOT NULL, url VARCHAR(100) NOT NULL, UNIQUE KEY id (id) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); update_option( "jal_db_version", $jal_db_version ); } } } // adding menus to the admin panel for editing the database add_action('admin_menu', 'my_plugin_menu'); /// adding the menu form to for the plugin function my_plugin_menu() { add_options_page('My Plugin Options', 'Profile html', 9, 'profile_adder_id', 'my_plugin_options'); } function my_plugin_options() { echo '<div class="wrap">'; echo '<h2>html for the bottom of the profile page.</h2>'; echo '<p>This plugin allows you to add some html or text to the bottom of the profile page, I use this for help panel in proflie page and made this plugin so when i upgrade wordpress i dont have to edit the page manualy.</p><br />'; echo '<h3>New html header for profile page.</h3>'; echo '<form method="post"><textarea style="width: 600px; height: 120px;"></textarea><br /><br /><input type="submit" name="submit" value="Submit" /></form>'; echo '<h3>Old html header for profile page.</h3>'; echo '<textarea style="width: 600px; height: 120px;"></textarea>'; echo '</div>'; function sample_function() { global $wpdb; // wordpress pull data this works ! $res = $wpdb->get_results("SELECT option_value FROM $wpdb->options WHERE option_id = '4'"); foreach ($res as $rs) { echo $rs->option_value; } // my pull data this dont work! $ress = $wpdb->get_results("SELECT option_value FROM $wpdb->profile_adder WHERE option_id = '1'"); foreach ($ress as $rss) { echo $rss->option_value; } } sample_function(); } ?>
Create an account or sign in to comment