I'm beginner to wordpress I'm writing Business Directory Plugin for test from scratch.
I have category page with database. how to add image support for categories?
I got error while uploading images.
"File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini."
I made changes to post_max_size & upload_max_filesize but not working
Please help me to complete Business Directory Plugin
Database
CREATE TABLE IF NOT EXISTS `lstngs_mbl_categories` (
`id` mediumint(11) NOT NULL,
`name` varchar(55) COLLATE utf8_unicode_ci NOT NULL,
`description` text COLLATE utf8_unicode_ci NOT NULL,
`image` tinytext COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
plugin structure
**main plugin folder**
my-business-directory
=> my-business-directory.php /*main plugin file inside my-business-directory*/
=> cat-img /*folder inside my-business-directory*/
=> css /*folder inside my-business-directory*/
=> images /*folder inside my-business-directory*/
=> inc /*folder inside my-business-directory*/
inside inc folder
=> inc_mbl_categories_page
=> inc_mbl_listings_page
=> inc_mbl_settings_page
my-business-directory.php
<?php
/*
Plugin Name: My Business Listings
Plugin URI: http://www.hrushi9.com/
Version: 0.1
Author: hrushi9
Description: My Business Directory Plugin
*/
function incAdminCSS()
{
echo '<link type="text/css" rel="stylesheet" href="' . plugins_url() . '/my-business-directory/css/mbl-admin.css" />' . "\n";
}
function incPublicCSS()
{
echo '<link type="text/css" rel="stylesheet" href="' . plugins_url() . '/my-business-directory/css/mbl-sc.css" />' . "\n";
}
add_action('admin_head', 'incAdminCSS');
add_action('wp_head', 'incPublicCSS');
add_action('admin_menu', 'mbl_menu');
function mbl_menu()
{
// create new top-level menu
add_menu_page('Business Listings', 'My Business Listings', 'administrator', 'mbl_settings', 'mbl_settings_page', plugins_url() . '/my-business-directory/images/accessibility-directory.png');
// create new submenus
add_submenu_page('mbl_settings', 'Categories', 'Listings Categories', 'administrator', 'mbl_settings_categories', 'mbl_categories_page');
add_submenu_page('mbl_settings', 'Listings', 'Business Listings', 'administrator', 'mbl_settings_listings', 'mbl_listings_page');
add_submenu_page('', 'Edit Listings', 'Edit Listings', 'administrator', 'mbl_settings_edit_listings', 'mbl_edit_listing_page');
// call register settings function
// add_action('admin_init','register_mbl_settings');
}
include ("inc/inc_mbl_settings_page.php");
include ("inc/inc_mbl_categories_page.php");
include ("inc/inc_mbl_listings_page.php");
?>
inc_mbl_settings_page.php
<?php
function mbl_settings_page()
{
?>
<h2>General Settings</h2>
<h3>About My Business Listings</h3>
<p>This plugin provides functionality to display business listings based on the category.
<?php
}
?>
inc_mbl_categories_page.php
<?php
function mbl_categories_page()
{
global $wpdb;
if ($_POST['action'] == "add_category")
{
$name = mysql_real_escape_string(stripslashes($_POST['mbl_category_name']));
$description = mysql_real_escape_string(stripslashes($_POST['mbl_category_description']));
$image = mysql_real_escape_string(stripslashes($_POST['mbl_category_image']));
$wpdb->insert($wpdb->prefix . 'mbl_categories', array(
'name' => $name,
'description' => $description,
'image' => $image
));
//path to store and retrieve images
echo $mbl_category_imagepath = '' . plugins_url() . '/my-business-directory/cat-img';
}
if ($_POST['action'] == "delete_category")
{
$id = $_POST['mbl_category_id'];
$wpdb->query("DELETE FROM " . $wpdb->prefix . "mbl_categories WHERE id=$id");
}
?>
<div class="wrap">
<h3>Create A New Category</h3>
<form method="post" name="test_form">
<input type="hidden" name="action" value="add_category" />
<table class="form-table">
<tr valign="top">
<th scope="row"><strong>Category Name</strong></th>
<td><input type="text" name="mbl_category_name" value="" size="56" /></td>
</tr>
<tr valign="top">
<th scope="row"><strong>Category Description</strong></th>
<td><textarea name="mbl_category_description" cols="50" rows="2"></textarea></td>
</tr>
<tr valign="top">
<th scope="row"><strong>Category image</strong></th>
<td><input type="file" name="mbl_category_image" /></td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="Create Category" />
</p>
</form>
<h2>Paid Business Listings Categories</h2>
<table class="mbladmin">
<tr class="headrow">
<td>ID</td>
<td> </td>
<td>Image</td>
<td>Category Name</td>
<td width="300">Description</td>
<td>Shortcode</td>
<td> </td>
</tr>
<?php
global $wpdb;
$categories = $wpdb->get_results("SELECT id,name,description,image FROM " . $wpdb->prefix . "mbl_categories");
foreach($categories as $cat)
{
$id = $cat->id;
$name = stripslashes($cat->name);
$description = stripslashes($cat->description);
$image = stripslashes($cat->image);
$mbl_category_imagepath = '' . plugins_url() . '/my-business-directory/cat-img';
echo "<tr class='datarow'><td>$id</td><td><img src=$mbl_category_imagepath/$image' width='65'></td><td>$name</td><td>$description</td><td>[mbl-listings category=\"$id\"]</td><td><form method='post'><input type='hidden' name='action' value='delete_category' /><input type='hidden' name='mbl_category_id' value='$id' /><input type='submit' class='button-secondary' value='Delete Category' /></form></td></tr>";
}
?>
</table>
<?php
}
?>
inc_mbl_listings_page
<?php
function mbl_listings_page() {
?>
<h2>Show Business Listings Page</h2>
<?php
}
?>