Skip to content

Instantly share code, notes, and snippets.

@PabloWestphalen
Created May 30, 2016 23:40
Show Gist options
  • Save PabloWestphalen/691d0bc0fb49b98dc3ad0bf0d51a4279 to your computer and use it in GitHub Desktop.
Save PabloWestphalen/691d0bc0fb49b98dc3ad0bf0d51a4279 to your computer and use it in GitHub Desktop.
Stub for a PHP script that can use Wordpress' functions to manipulate the database
<?php
//Força report de erros
error_reporting(E_ALL|E_STRICT);
//Inicializa o wordpress, trazendo todas as funções e contexto dele pra dentro desse script
require_once("../wp-config.php");
$wp->init(); $wp->parse_request(); $wp->query_posts();
$wp->register_globals(); $wp->send_headers();
//Inicializa a referência à interface de query do WP (ver https://codex.wordpress.org/Class_Reference/wpdb)
global $wpdb;
//Inicializa a referência à sessão do usuário logado, se houver
global $current_user;
$current_user = wp_get_current_user();
// A partir daqui você pode usar todas as funções do WP, consultando o banco de dados com o $wpdb e inserindo conteúdo com funções como wp_insert_post() e wp_insert_attachment()
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment