prefix . ‘tp_ads’; $charset = $wpdb->get_charset_collate(); $sql = “CREATE TABLE $table ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), age INT, description TEXT, image VARCHAR(255), featured INT DEFAULT 0, created_at DATETIME DEFAULT CURRENT_TIMESTAMP ) $charset;”; require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’); dbDelta($sql); } register_activation_hook(__FILE__, ‘tp_install’); /* ========================= 2. CSS (ilus layout) ========================= */ function tp_styles() { echo ‘ ‘; } /* ========================= 3. SHORTCODE ========================= */ function tp_shortcode() { global $wpdb; $table = $wpdb->prefix . ‘tp_ads’; tp_styles(); /* ========================= 4. FORM SUBMIT ========================= */ if (isset($_POST[‘tp_submit’])) { $name = sanitize_text_field($_POST[‘name’]); $age = intval($_POST[‘age’]); $desc = sanitize_textarea_field($_POST[’description’]); $image_url = ”; if (!empty($_FILES[’image’][‘name’])) { require_once(ABSPATH . ‘wp-admin/includes/file.php’); $uploaded = wp_handle_upload($_FILES[’image’], [‘test_form’ => false]); if (!isset($uploaded[‘error’])) { $image_url = $uploaded[‘url’]; } } $wpdb->insert($table, [ ‘name’ => $name, ‘age’ => $age, ’description’ => $desc, ’image’ => $image_url, ‘featured’ => isset($_POST[‘featured’]) ? 1 : 0 ]); echo “

Kuulutus lisatud!

“; } /* ========================= 5. KUULUTUSED ========================= */ $ads = $wpdb->get_results(“SELECT * FROM $table ORDER BY featured DESC, id DESC”); ob_start(); ?>

Lisa kuulutus

ESILE TÕSTETUD
image): ?>

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!


Posted

in

by

Tags:

Comments

Üks vastus teemale “Hello world!”

  1. Autori A WordPress Commenter avatar

    Hi, this is a comment.
    To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
    Commenter avatars come from Gravatar.

Lisa kommentaar

Sinu e-postiaadressi ei avaldata. Nõutavad väljad on tähistatud *-ga