Skip to content

Instantly share code, notes, and snippets.

View raphaelnikson's full-sized avatar

Raphael Nikson raphaelnikson

View GitHub Profile
@raphaelnikson
raphaelnikson / functions.php
Last active September 27, 2015 01:59
Painel - Action - Edit - New - List posts
add_action( 'admin_head-post.php', 'admin_head_post_editing' );
add_action( 'admin_head-post-new.php', 'admin_head_post_new' );
add_action( 'admin_head-edit.php', 'admin_head_post_listing' );
function admin_head_post_editing() {
echo ‘você está editando o post';
}
function admin_head_post_new() {
echo ‘você está criando um novo post';
@raphaelnikson
raphaelnikson / functions.php
Last active September 28, 2015 22:18
Mostrar no admin só posts do usuário logado
function posts_for_current_author($query) {
if (is_admin()) {
$userLog = wp_get_current_user();
$userLogID = $userLog->ID;
$query->set('author', $userLogID);
return $query;
# code...
}
}
add_filter('pre_get_posts', 'posts_for_current_author');
@raphaelnikson
raphaelnikson / functions.php
Created September 28, 2015 22:16
Remover tipos de usuário padrão do wordpress
function remove_wp_users_role() {
/* remove tipos de usuários padrão do wordpress */
remove_role( 'subscriber' );
remove_role( 'contributor' );
remove_role( 'editor' );
remove_role( 'author' );
remove_role( '' );
}
register_activation_hook( __FILE__, 'remove_wp_users_role' );
@raphaelnikson
raphaelnikson / functions.php
Last active September 28, 2015 22:23
Restaura os tipos de usuários do wordpress.
function wp_restaure_roles_users(){
/* adiciona tipos de usuários padrão */
add_role( 'subscriber', 'Assinante', 'level_0' );
add_role( 'contributor', 'Contribuidor', 'level_1' );
add_role( 'editor', 'Editor', 'level_7' );
add_role( 'author', 'Autor', 'level_2' );
}
register_activation_hook( __FILE__, 'wp_restaure_roles_users' );
@raphaelnikson
raphaelnikson / functions.php
Created September 28, 2015 22:25
Ativação do Plugin
function active_plugins() {
// código plugin
}
register_activation_hook( __FILE__, 'active_plugins' );
@raphaelnikson
raphaelnikson / functions.php
Created September 28, 2015 22:26
Desativação do plugin
function desactive_plugins() {
// código plugin
}
register_activation_hook( __FILE__, 'desactive_plugins' );
@raphaelnikson
raphaelnikson / functions.php
Created September 29, 2015 03:02
Adicionar meta box
function list_users() {
add_meta_box( 'list-users', 'usuários', 'users', 'imoveis');
}
add_action( 'add_meta_boxes', 'list_users' );
function users() {
$usuarios = get_users();
foreach ($usuarios as $usuario) {
echo "<br>" . $usuario->user_nicename;
@raphaelnikson
raphaelnikson / functions.php
Created September 29, 2015 18:15
Adiciona uma nova coluna na listagem de posts do painel
function cols_admin( $column ) {
$column['foto'] = 'Foto';
return $column;
}
add_filter( 'manage_imoveis_posts_columns', 'cols_admin' );
function colsfield( $column_name, $post_id ) {
$custom_fields = "foi";
if ($column_name == 'foto') {
<?php
// Add two new role.
// Full list of capabilities can be found at http://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table
add_role('writer', 'Writer', array(
'delete_posts' => true,
'delete_published_posts' => true,
'edit_posts' => true,
'edit_published_posts' => true,
'publish_posts' => true,
'read' => true,
@raphaelnikson
raphaelnikson / functions.php
Created October 9, 2015 03:54
Formulário de registro
function user_register() {
echo "
<form action='"; echo site_url('wp-login.php?action=register', 'login_post'); echo "' method='post'>
<input type='text' name='user_login' value='Username' id='user_login' />
<input type='text' name='user_email' value='Mail' id='user_email' />";
do_action('register_form');
echo "<input type='submit' value='Register' id='register' />";
}
add_shortcode( 'form_register', 'user_register' );