开发者

I tried to write a Wordpress plugin, but I failed [closed]

开发者 https://www.devze.com 2023-01-11 09:20 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I write a simple wordpress plugins ..

it is for friend blogs , using wordpres 3

but I don't know where is the problem ..

this is the code ..

<?
/*
Plugin Name:  RandFriendB
Plugin URI: http://www.abosami.com
Description: Show your frineds blogs ..
Version: 1.0
Author: abosami
Author URI: http://www.abosami.com
*/
load_plugin_textdomain('randfriendb', "/wp-content/plugins/randfriendb/");
function randfriendb_admin()
    {
function table_exists ($table, $db=DB_NAME) {
        $tables = mysql_list_tables ($db);
        while (list ($temp) = mysql_fetch_array ($tables)) {
                if ($temp == $table) {
                        return TRUE;
                }
        }
        return FALSE;
}
if (!table_exists("wp_randfb"))
        {
        $create = mysql_query("CREATE TABLE `wp_randfb` (
                    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
                    `blog_title` VARCHAR(200) NOT NULL,
                    `blog_url` VARCHAR(200) NOT NULL,
                    `blog_desc` VARCHAR(200) NOT NULL
                    )
                    ");
            if ($create)
                {
                 echo '<div class="wrap"><h2>'.__("The table is created","randfriendb").'</h2></div><br />'.__("please wait ...","randfriendb");
                echo '<META HTTP-EQUIV="refresh" CONTENT="1; URL=admin.php?page=randfriendb/randfriendb.php&action=add">';
                }else{
                         echo '<div class="wrap"><h2>'.__("error","randfriendb").'</h2></div>';
                         echo mysql_error();
                }
        }else{
        if (!isset($_GET['action']) || $_GET['action'] == "add")
            {
                echo '<form method="POST" action="admin.php?page=randfriendb/randfriendb.php&action=insert">
                <div class="wrap"><h2>'.__("Add New blog:","randfriendb").'</h2></div><br />
                <table class="form-table">
                <tr>
                <th>'.__("Blog Title:","randfriendb"). '<span class="description"></span></th>
                <td><input type="text" name="blog_title" class="regular-text" /></td>
                </tr>
                <tr>
                <th>'.__("Blog URL:","randfriendb").'<span class="description"></span></th>
                <td><input type="text" name="blog_url" class="regular-text" /></td>
                </tr>
                <tr>
                <th>'.__("Description:","randfriendb").' <span class="description"></span></th>
                <td><textarea name="blog_desc" rows="5" cols="30"></textarea></td>
                </tr>

                </table>
                <p class="submit">
                <input type="submit" class="button-primary" value="'.__("Add","randfriendb").'" name="submit" />
                </p>

                </div>
                </form>
                ';

            }elseif($_GET['action'] == "edit")
                    {
                    global $wpdb;
                    $blogs = $wpdb->get_results("SELECT * FROM `wp_randfb`",ARRAY_A);

                    if ($blogs)
                        {
                        echo '
                        <br/><table class="widefat post fixed" cellspacing="0">
                        <thead>
                        <tr>
                        <th scope="col" class="manage-column column-title" style="">'.__("Blog Title:","randfriendb").'</th>
                        <th scope="col" class="manage-column column-author" style="">'.__("Blog URL:","randfriendb").'</th>
                        <th scope="col" class="manage-column column-categories" style="">'.__("Description:","randfriendb").'</th>
                        <th scope="col" class="manage-column column-tags" style="">'.__("Delete","randfriendb").'</th>
                        </tr>
                        </thead>
                        <tbody>
                        ';
                        foreach($blogs as $blog){
                        echo '<tr id="post-1" class="alternate author-self status-publish iedit" valign="top">
                        <td>'.$blog['blog_title'].'</td>';
                        echo '<td>'.$blog['blog_url'].'</td>';
                        echo '<td>'.$blog['blog_desc'].'</td>';
                        echo '<td><a href="admin.php?page=randfriendb/randfriendb.php&action=del&id='.$blog[id].'">'.__("Delete","randfriendb").'</a></td></tr>';
                        }
                        echo '  <tfoot>
                                <tr >
                                    <th colspan="4"></th>
                                </tr>
                                </tfoot>
                                </table>';
                        }else{
                        echo '<h3>'.__("No found new blogs","randfriendb").'</h3>';
                        }


                    }elseif($_GET['action'] == "del")
                        {
                        global $wpdb;
                        $id = intval($_GET['id']);
                        $del = $wpdb->query("DELETE FROM `wp_randfb` WHERE id='" . $id . "'");
                        if ($del)
                            {
                            echo '<div class="wrap"><h2>'.__("The blog is deleted","randfriendb").'</h2></div><br />'.__("Please waith ...","randfriendb");
                            echo '<META HTTP-EQUIV="refresh" CONTENT="1; URL=admin.php?page=randfriendb/randfriendb.php&action=edit">';
                            }else{
                            echo '<div class="wrap"><h2>'.__("Error","randfriendb").'</h2></div><br />';
                            }

                        }elseif($_GET['action'] == "insert")
                            {
                            if(empty($_POST['blog_title']) || empty($_POST['blog_url']) || empty($_POST['blog_desc']))
                                {
                                echo '<h2>'.__("Please write the information","randfriendb").'</h2>';
                                }else{
                                global $wpdb;
                                $insert = $wpdb->query("INSERT INTO `wp_randfb` VALUES(NULL,'" . $_POST['blog_title'] . "','" . $_POST['blog_url'] . "','" . $_POST['blog_desc'] . "')");
                                if ($insert)
                                    {
                                    echo '<div class="wrap"><h2>'.__("The blog is added","randfriendb").'</h2></div><br />'.__("Please wait ...","randfriendb");
                                    echo '<META HTTP-EQUIV="refresh" CONTENT="1; URL=admin.php?page=randfriendb/randfriendb.php&action=edit">';
                                    }else{
                                    echo '<div class="wrap"><h2>'.__("Error","randfriendb").'</h2></div><br />';                                    
                                    }

                                }

                            }



            }



    }   
function randfriendb_add_admin() {
add_menu_page(__("Friend Blogs","randfriendb"),__("Friend Blogs","randfriendb"), 8, __FILE__, "randfriendb_admin");
add_submenu_page(__FILE__, __("New Blog","randfriendb"), __("New Blog","randfriendb"), 8,__FILE__ , "randfriendb_admin");
add_submenu_page(__FILE__, __("Control","randfriendb"), __("Control","randfriendb"), 8, __FILE__ ."&action=edit", "randfriendb_admin");
}
add_action('admin_menu', 'randfriendb_add_admin');  
 function randfriendb_main($args)
    {
    extract($args);
    global $wpdb;
    $get_blogs = $wpdb->get_results("SELECT * FROM `wp_randfb` order by rand() limit 0,1",ARRAY_A);
    foreach($get_blogs as $get_blog){
    echo $before_widget;
    echo $before_title;
     _e("Friend Blogs","randfriendb");
     echo $after_title;
    echo '<a href="'.$get_blog['blog_url'].'">'.$get_blog['blog_title'].'</a><p>'.$get_blog['blog_desc'].'</p>'.$after_widget;
    }
    }


    register_sidebar_widget(__("Friend Blogs开发者_高级运维","randfriendb"),'randfriendb_main');





?>


After looking at your code and the screenshot I noticed you're using short tags <?. Your server may not have this enabled, hence why your code is spilling out all over your page. Try <?php instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消