Skip to content

Commit

Permalink
Versão 1.0.0
Browse files Browse the repository at this point in the history
Primeiro commit
  • Loading branch information
filipecsweb committed Jul 21, 2015
1 parent 06e623a commit a7b38be
Show file tree
Hide file tree
Showing 10 changed files with 429 additions and 0 deletions.
168 changes: 168 additions & 0 deletions admin/class-wordpress-manutencao-settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?php
/**
* This file contains all code needed to build the options page of the plugin.
* It is being loaded in core class.
*
* @since 1.0.0
* @author Filipe Seabra <[email protected]>
*/
if(!defined('ABSPATH')){
exit;
}

class Wordpress_Manutencao_Settings{
/**
* @var string $option Option name
*/
public $option = 'fswpma_settings';

/**
* @var string $option Page options slug
*/
public $page = 'fswpma_manutencao';

public function __construct(){
/**
* Add options menu
*/
add_action('admin_menu', array($this, 'fswpa_admin_menu'));

/**
* Add plugin settings
*/
add_action('admin_init', array($this, 'fswpma_plugin_settings'));
}

/**
* Load menu under 'Settings'
*/
public function fswpa_admin_menu(){
add_options_page(
__('Site em manutenção', 'wp-manutencao'),
__('Manutenção', 'wp-manutencao'),
'edit_posts',
'fswpma_manutencao',
array($this, 'fswpma_manutencao_callback')
);
}

/**
* Callback function that outputs settings page content
*/
public function fswpma_manutencao_callback(){
include_once 'html-settings-page.php';
}

public function fswpma_plugin_settings(){
$option = $this->option; // Option name that keeps all saved options in an array
$page = $this->page; // Chosen slug

add_settings_section(
'basic_options_section', // id
__('Opções', 'wp-manutencao'), // title
array($this, 'basic_options_section_callback'), // callback
$page // page
);

add_settings_field(
'activate',
__('Ativar?', 'wp-manutencao'),
array($this, 'radio_element_callback'),
$page,
'basic_options_section',
array(
'option_name' => $option,
'id' => 'activate',
'type' => 'radio',
'desc' => __('Marque "Sim" para que o site seja visto apenas por administradores logados.')
)
);

add_settings_field(
'hmtl',
__('HTML', 'wp-manutencao'),
array($this, 'textarea_element_callback'),
$page,
'basic_options_section',
array(
'option_name' => $option,
'id' => 'html',
'label_for' => 'html',
'class' => 'large-text',
'desc' => 'Insira a estrutura do conteúdo HTML que deve aparecer enquanto o site estiver em manutenção.'
)
);

add_settings_field(
'css',
__('CSS', 'wp-manutencao'),
array($this, 'textarea_element_callback'),
$page,
'basic_options_section',
array(
'option_name' => $option,
'id' => 'css',
'label_for' => 'css',
'class' => 'large-text',
'desc' => 'Insira seu CSS personalizado para customizar seu conteúdo HTML.'
)
);

register_setting($option, $option, array($this, 'validate_fswpma_settings'));
}

/**
* Basic options section callback
*
* @return void
*/
public function basic_options_section_callback(){

}

/**
* Radio element callback
*
* @return input type radio
*/
public function radio_element_callback($args){
extract($args);

$options = get_option($option_name);

$options[$id] = isset($options[$id]) ? $options[$id] : '0';

echo "<input id='$id-0' type='$type' name='".$option_name."[$id]' value='0'".checked('0', $options[$id], false)." /> N&atilde;o";
echo "<br />";
echo "<input id='$id-1' type='$type' name='".$option_name."[$id]' value='1'".checked('1', $options[$id], false)." /> Sim";
echo $desc != '' ? "<br /><span class='description'>$desc</span>" : "";
}

/**
* Text area element callback
*
* @return textarea tag
*/
public function textarea_element_callback($args){
extract($args);

$options = get_option($option_name);

$options[$id] = isset($options[$id]) ? $options[$id] : '';

echo "<textarea id='$id' rows='15' class='$class' name='".$option_name."[$id]'>$options[$id]</textarea>";
echo $desc != '' ? "<br /><span class='description'>$desc</span>" : "";
}

/**
* Sanitize/validate options
*
* @return array Validated options
*/
public function validate_fswpma_settings($input){
foreach($input as $k => $v){
$newinput[$k] = trim($v);
}
return $newinput;
}
}
26 changes: 26 additions & 0 deletions admin/html-settings-page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* This file contains the HTML form for the plugin
*
* @since 1.0.0
* @author Filipe Seabra <[email protected]>
*/
if(!defined('ABSPATH')){
exit;
}
?>

<div class="wrap">
<h2><?php echo esc_html(get_admin_page_title()); ?></h2>

<?php settings_errors(); ?>

<form action="options.php" method="post">
<?php
settings_fields('fswpma_settings');
do_settings_sections('fswpma_manutencao');

submit_button();
?>
</form>
</div>
1 change: 1 addition & 0 deletions admin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // May the force of ninja be with you
12 changes: 12 additions & 0 deletions includes/class-wordpress-manutencao-activator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Fired during plugin activation
*
* @since 1.0.0
* @author Filipe Seabra <[email protected]>
*/
class Wordpress_Manutencao_Activator{
public static function activate(){

}
}
12 changes: 12 additions & 0 deletions includes/class-wordpress-manutencao-deactivator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Fired during plugin deactivation
*
* @since 1.0.0
* @author Filipe Seabra <[email protected]>
*/
class Wordpress_Manutencao_Deactivator{
public static function deactivate(){

}
}
1 change: 1 addition & 0 deletions includes/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // May the force of ninja be with you
42 changes: 42 additions & 0 deletions public/class-wordpress-manutencao-public.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* This file manages whether the maintenance page is going to be viwed or not
* @since 1.0.0
* @author Filipe Seabra
*/
if(!defined('ABSPATH')){
exit;
}

class Wordpress_Manutencao_Public{
/**
* Initialize the function that will turn front end visible just to logged in users
*/
public function __construct(){
$this->fswpma_maintenance_page();
}

/**
* Displays HTML of the maintenance page for not logged in users and
* prevents the maintenance page from appearing in the login page
*
* @return Void
*/
public function fswpma_maintenance_page(){
$screen = $_SERVER['REQUEST_URI'];

if(is_user_logged_in()){
return;
}
elseif(strpos($screen, 'wp-admin') || strpos($screen, 'wp-login.php')){
return;
}
else{
include_once 'html-maintenance-page.php';
}

return;
}
}

new Wordpress_Manutencao_Public();
40 changes: 40 additions & 0 deletions public/html-maintenance-page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* This file contains html for the maintenance page
*
* @since 1.0.0
* @author Filipe Seabra <[email protected]>
*/
if(!defined('ABSPATH')){
exit;
}

$settings = new Wordpress_Manutencao_Settings();

$options = get_option($settings->option);
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>

<head>
<meta charset="<?php bloginfo('charset'); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

<title><?php bloginfo('name'); ?></title>

<style>
<?php echo $options['css']; ?>
</style>
</head>

<body>
<?php echo $options['html']; ?>
</body>

</html>

<?php

exit;
1 change: 1 addition & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // May the force of ninja be with you
Loading

0 comments on commit a7b38be

Please sign in to comment.