Skip to content

Instantly share code, notes, and snippets.

@bordoni
Last active December 22, 2015 08:39
Show Gist options
  • Select an option

  • Save bordoni/6446636 to your computer and use it in GitHub Desktop.

Select an option

Save bordoni/6446636 to your computer and use it in GitHub Desktop.
WP Aula Plugins - Parte 2
<?php
if (!class_exists("MeuPortifolio")){
class MeuPortifolio {
/**
* Uma variável estática contendo uma instância dinâmica da classe
* @var [object||null]
*/
public static $instance = null;
public function __construct() {
// Criando a instancia dinâmica da Classe em uma variável estática
null === self::$instance and self::$instance = &$this;
// Apenas para debugar e explicar um conceito, apagar!
$this->foo = true;
}
// Método apenas para desenvolvimento, será apagado depois!
public function _dev_foo(){
echo "<pre>" . print_r($this, true) . "</pre>";
self::$instance->foo = 'Teste se funciona!';
echo "<pre>" . print_r($this, true) . "</pre>";
}
}
new MeuPortifolio;
}
<?php
/*
Plugin Name: Meu Portifólio
Version: 0.1
Plugin URI: https://vimeo.com/bordoni
Description: Um plugin para gerenciar os meus trabalhos como freelancer
Author: Gustavo Bordoni
Author URI: http://bordoni.me
License: GPL v3
Plugin Meu Portifólio
Copyright (C) 2013, Gustavo Bordoni - [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
foreach ( glob( plugin_dir_path( __FILE__ )."inc/*.php" ) as $file )
if (file_exists($file))
require_once $file;
// Apagar, utilizado apenas para desenvolvimento
add_action('all_admin_notices', function() {
MeuPortifolio::$instance->_dev_foo();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment