Skip to content

Instantly share code, notes, and snippets.

View pedroelsner's full-sized avatar

Pedro R. Elsner Begosso pedroelsner

View GitHub Profile
@pedroelsner
pedroelsner / gist:2778345
Created May 23, 2012 22:54
#6 - Plugin WordPress - Hello Word
<?php
function hello_world_content_filter( $content ) {
global $post;
// Verifica a opção no banco de dados para este post ou página
if ( get_post_meta( $post->ID, 'hello_world_opt_mostrar_mensagem', true ) == '1' ) {
$content .= '<strong>Hello World!</strong>';
}
return $content;
}
?>
@pedroelsner
pedroelsner / gist:2778351
Created May 23, 2012 22:55
#7 - Plugin WordPress - Hello Word
<?php
function hello_world_meta_box() {
global $post;
echo '<input id="hello_world_nonce" name="hello_world_nonce" type="hidden" value="' . wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
echo '<input id="hello_world_opt_mostrar_mensagem" name="hello_world_opt_mostrar_mensagem" type="checkbox" ';
if ( get_post_meta( $post->ID, 'hello_world_opt_mostrar_mensagem', true ) == '1' )
echo ' checked="checked" ';
<?php
//Configure::write('Routing.prefixes', array('admin'));
?>
<?php
Router::connect(
'/admin',
array(
'controller' => 'pages',
'action' => 'index',
'admin' => true
)
);
?>
@pedroelsner
pedroelsner / gist:2779087
Created May 24, 2012 02:29
(SQL) Tabela Users - CakePHP 1.3 + AuthComponent
CREATE TABLE users (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(200) NOT NULL,
username VARCHAR(20) NOT NULL,
password VARCHAR(100) NOT NULL,
created DATETIME NULL,
modified DATETIME NULL,
active TINYINT(1) NOT NULL DEFAULT 1,
PRIMARY KEY(id),
UNIQUE(username)
cake bake model user
cake bake controller user admin
cake bake view user
@pedroelsner
pedroelsner / app_controller.php
Created May 24, 2012 02:32
#1 App_Controller - CakePHP 1.3 + AuthComponent
<?php
/**
* App Controller
*
* @use Controller
* @link http://book.cakephp.org/pt/view/957/A-classe-AppController
*/
class AppController extends Controller
{
@pedroelsner
pedroelsner / user.php
Created May 24, 2012 02:33
#2 User.php - CakePHP 1.3 + AuthComponent
<?php
/**
* Login
*
* @access public
*/
function login()
{
// Aqui é tudo automagic.
// O Auth Component se encarrega de fazer tudo sozinho.
@pedroelsner
pedroelsner / gist:2779108
Created May 24, 2012 02:34
#3 View Login - CakePHP 1.3 + AuthComponent
<h2>Login</h2>
<?php
echo $this->Form->create(
'User',
array(
'url' => array(
'controller' => 'users',
'action' => 'login'
)
)
<?php echo $this->Session->flash('auth'); ?>