Hi shariyaar_shah,whooami
Im stuck trying this methord but using my own database table i cant seem to pull info from my table with shariyaar_shah code but works for options table.. here is my code what am i doing wrong ?
<?php
/*
Plugin Name: wp-html-profile-adder
Plugin URI: https://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: https://www.swipedstudio.com/
*/
/* Copyright 2009 Sam Miller (email : [email protected])
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 . " (
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);
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();
}
?>