dbDelta only creates the last table

Run dbDelta for each SQL statement seperately: function myplugin_install(){ global $wpdb; $table_name = $wpdb->prefix . “vehicles”; require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’); $sql = “CREATE TABLE IF NOT EXISTS $table_name ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, description VARCHAR(25) NOT NULL, PRIMARY KEY (id) ); “; dbDelta($sql); $sql2 = “CREATE TABLE IF NOT EXISTS $table_name1 ( … )”; … Read more

How do I programatically insert a new menu item?

Before being printed, all the menu items get run through a filter. You can target the wp_nav_menu_items filter to tack things on to the menu: // Filter wp_nav_menu() to add additional links and other output function new_nav_menu_items($items) { $homelink = ‘<li class=”home”><a href=”‘ . home_url( “https://wordpress.stackexchange.com/” ) . ‘”>’ . __(‘Home’) . ‘</a></li>’; // add … Read more

How to call a plugin function from index.php

The same way you would any other: foo(); Active plugins are loaded before the theme files You may want to check that your plugin is activated and the function is available so things dont go pear-shaped if you forget to activate it, like: if(function_exists(‘foo’)){ foo(); } else { echo “oh dear you haven’t activated/installed ‘myplugin’, … Read more

Create a table in custom plugin on the activating it?

You have to include wpadmin/upgrade-functions.php file to create a table example function create_plugin_database_table() { global $table_prefix, $wpdb; $tblname=”pin”; $wp_track_table = $table_prefix . “$tblname “; #Check to see if the table exists already, if not, then create it if($wpdb->get_var( “show tables like ‘$wp_track_table'” ) != $wp_track_table) { $sql = “CREATE TABLE `”. $wp_track_table . “` ( … Read more

Export data as CSV in back end with proper HTTP headers

Do not point the URL to admin.php, use admin-post.php instead: ‘<a href=”‘ . admin_url( ‘admin-post.php?action=print.csv’ ) . ‘”>’ In your plugin register a callback for that action: add_action( ‘admin_post_print.csv’, ‘print_csv’ ); function print_csv() { if ( ! current_user_can( ‘manage_options’ ) ) return; header(‘Content-Type: application/csv’); header(‘Content-Disposition: attachment; filename=example.csv’); header(‘Pragma: no-cache’); // output the CSV data } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)