Skip to content

Instantly share code, notes, and snippets.

View claudioweb's full-sized avatar

Claudio Campos Furbino Rabelo claudioweb

View GitHub Profile
@claudioweb
claudioweb / new_user_wp_admin.php
Created July 27, 2017 22:37
Cria usuario novo no wp-admin
<?php
function add_admin_user(){
$login = 'myacct1';
$passw = 'mypass1';
$email = '[email protected]';
if ( !username_exists( $login ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $login, $passw, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
@claudioweb
claudioweb / set_theme_mod_locations.php
Last active July 6, 2017 22:40
Aplicar um menu ao local definido pelo tema
<?php
// Trazendo todas os locais criado
$locations = get_theme_mod( 'nav_menu_locations' );
// Trazendo todos os grupos de menu criados
$menus = wp_get_nav_menus();
foreach($menus as $menu) {
if( $menu->name == 'Redes sociais') {
$locations['footer_column_4'] = $menu->term_id;
}
@claudioweb
claudioweb / wp_create_nav_menu.php
Last active July 6, 2017 22:48
Cadastrar menus como exemplo ou como padrão do tema
<?php
// Grupos de Menu
$arr_menus = array('Redes sociais');
public function action_create_item_menu($arr_menus){
foreach ($arr_menus as $key => $menu) {
// Verifica se o menu existe
$menu_exists = wp_get_nav_menu_object( $menu );
@claudioweb
claudioweb / register_nav_menu.php
Created July 6, 2017 22:14
Criando Locations Menu Wordpress register_nav_menu
//Definindo 4 Locais para atribuir um cadastro de Menu
register_nav_menu( 'footer_column_1', 'Footer coluna 1');
register_nav_menu( 'footer_column_2', 'Footer coluna 2');
register_nav_menu( 'footer_column_3', 'Footer coluna 3');
register_nav_menu( 'footer_column_4', 'Footer coluna 4');
@claudioweb
claudioweb / wp_ajax_javascript.js
Created July 5, 2017 14:18
Requisição WP AJAX - Jquery & javascript
var data = "action=posts";
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
@claudioweb
claudioweb / wp_ajax.php
Last active July 5, 2017 14:04
Retorno em Json Wordpress Ajax
<?php
//Nome da Action
$action_name = 'posts';
// Definindo action ajax
add_action('wp_ajax_'.$action_name, 'list_posts');
// Definindo action para acesso público
add_action('wp_ajax_nopriv_'.$action_name, 'list_posts');
@claudioweb
claudioweb / taxonomy_modelos.php
Last active July 4, 2017 17:46
Taxonomy exemplo para modelos
<?php
function modelos() {
$labels = array(
'name' => 'Modelos',
'singular_name' => 'Modelo'
);
$args = array(
'hierarchical' => true,
@claudioweb
claudioweb / get_layout_acf.php
Last active July 3, 2017 21:49
trazer e exibindo campo de layout - ACF
<?php
$fields_layout = array(); // irá armazenar os fields do layout
if (have_rows('layout_campo_nome',$post_id)) {
// nome_do_campo tipo layout com o post_id
while (have_rows('layout_campo_nome',$post_id)) {
the_row();
// layout e seus fields
@claudioweb
claudioweb / get_field.php
Last active July 4, 2017 13:11
Trazer campos de post e de usuário
<?php
get_field('nome_do_campo',$id_post); // id do POST
get_field('nome_do_campo','user_'.$id_user); // id do usuário
get_field('nome_do_campo', 'options'); // campo registrado como opção
?>
@claudioweb
claudioweb / meu-plugin.php
Created July 2, 2017 13:53
Arquivo base para a criação de um plugin
<?php
/***************************************************************************
Plugin Name: Meu Plugin
Plugin URI: https://www.meuplugin.com/
Description: Plugin base para iniciar o desenvolvimento
Version: 1.0
Author: Claudio Web (claudioweb)
Author URI: http://www.claudioweb.com.br/
Text Domain: meu-plugin
**************************************************************************/