Plugin for wordpress

1

I am trying to make a plugin for wordpress in which I show the client the account status of their clients. What I do is simple, a query to a database in which there is a list of clients and the status of them, whether they are active or not.

<?php
/**
* Plugin Name: Clienre
* Plugin URI: http://cliente.com.ar/
* Description: Sistema de usuarios para cliente.
* Version: 1.0
* Author: cliente
* Author URI: http://cliente.com.ar/
* Text Domain: cliente
* License: GLP2
* @package cliente
*/

try {
$conn = new PDO('mysql:host=localhost;dbname=db', 'root', '');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
    echo "ERROR: " . $e->getMessage();
}

$udate = $conn->query("SELECT * FROM clientes");
$rw = $udate->fetch();
echo $rw['code'];
?>

Everything works fine, but the problem is that the data is seen on the client's page and not on the desktop. I want to do something like WooCommerce, but simpler, much simpler.

    
asked by 25.05.2018 в 04:57
source

1 answer

1

You can add the information in the form of a widget on the desktop, as indicated by the documentation .

For example:

function cliente_add_dashboard_widgets() {

    wp_add_dashboard_widget(
                 'cliente_dashboard_widget',         // Widget slug.
                 'Estado de la Cuenta',              // Titulo.
                 'cliente_dashboard_widget_function' // Función que muestra el contenido.
        );  
}
add_action( 'wp_dashboard_setup', 'cliente_add_dashboard_widgets' );

/**
 * Esta es la función que muestra los datos.
 */
function cliente_dashboard_widget_function() {

    try {
    $conn = new PDO('mysql:host=localhost;dbname=db', 'root', '');
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
    catch(PDOException $e){
        echo "ERROR: " . $e->getMessage();
    }

    $udate = $conn->query("SELECT * FROM clientes");
    $rw = $udate->fetch();
    echo "Aquí puedes escribir más cosas si quieres: ".$rw['code'];

}
    
answered by 25.05.2018 / 12:17
source