Skip to content

Instantly share code, notes, and snippets.

@miya0001
Last active May 21, 2019 05:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miya0001/9461593 to your computer and use it in GitHub Desktop.
Save miya0001/9461593 to your computer and use it in GitHub Desktop.
汎用的な管理画面付きのWordPressプラグインのテンプレート
<?php
/**
* Plugin Name: Hatamoto
* Plugin URI: https://wpist.me/
* Description: This is a awesome cool plugin.
* Version: 0.1.0
* Author: Takayuki Miyauchi
* Author URI: https://wpist.me/
* License: GPLv2
* Text Domain: hatamoto
* Domain Path: /languages
*/
/**
* Copyright (c) 2014 Takayuki Miyauchi (https://wpist.me/)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 or, at
* your discretion, any later version, as published by the Free
* Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
define('HATAMOTO_URL', plugins_url('', __FILE__));
define('HATAMOTO_PATH', dirname(__FILE__));
$hatamoto = new Hatamoto();
$hatamoto->register();
class Hatamoto {
private $version = '';
private $langs = '';
function __construct()
{
$data = get_file_data(
__FILE__,
array('ver' => 'Version', 'langs' => 'Domain Path')
);
$this->version = $data['ver'];
$this->langs = $data['langs'];
}
public function register()
{
add_action('plugins_loaded', array($this, 'plugins_loaded'));
}
public function plugins_loaded()
{
load_plugin_textdomain(
'hatamoto',
false,
dirname(plugin_basename(__FILE__)).$this->langs
);
add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'));
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('admin_menu', array($this, 'admin_menu'));
add_action('admin_init', array($this, 'admin_init'));
}
public function admin_menu()
{
add_options_page(
__('Hatamoto', 'hatamoto'),
__('Hatamoto', 'hatamoto'),
'manage_options', // http://codex.wordpress.org/Roles_and_Capabilities
'hatamoto',
array($this, 'options_page')
);
}
public function admin_init()
{
if (isset($_POST['_wpnonce']) && $_POST['_wpnonce']){
if (check_admin_referer('hatamoto', '_wpnonce')){
// save something
wp_redirect('options-general.php?page=hatamoto');
}
}
}
public function options_page()
{
?>
<div id="hatamoto" class="wrap">
<h2><?php _e('Hatamoto', 'hatamoto'); ?></h2>
<form method="post" action="<?php echo esc_attr($_SERVER['REQUEST_URI']); ?>">
<?php wp_nonce_field('hatamoto', '_wpnonce'); ?>
Admin Panel Here!
<p style="margin-top: 3em;">
<input type="submit" name="submit" id="submit" class="button button-primary"
value="<?php _e("Save Changes", "hatamoto"); ?>"></p>
</form>
</div><!-- #hatamoto -->
<?php
}
public function admin_enqueue_scripts()
{
if (isset($_GET['page']) && $_GET['page'] === 'hatamoto') {
wp_enqueue_style(
'admin-hatamoto-style',
plugins_url('css/admin-hatamoto.min.css', __FILE__),
array(),
$this->version,
'all'
);
wp_enqueue_script(
'admin-hatamoto-script',
plugins_url('js/admin-hatamoto.min.js', __FILE__),
array('jquery'),
$this->version,
true
);
}
}
} // end class Hatamoto
// EOF
@miya0001
Copy link
Author

Generated by hatamoto.
https://github.com/megumiteam/hatamoto

hatamotoを使うとsassもセットアップ済みです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment