Created
January 27, 2016 11:38
-
-
Save pixelbart/3d1c73c2236c791d0ee3 to your computer and use it in GitHub Desktop.
WP-Blaupause
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
Name: Blaupause | |
Author: Kevin Pliester | |
License: MIT License | |
License URI: http://opensource.org/licenses/MIT | |
**/ | |
namespace Gameplane\Extensions\Blaupause; // Sorgt dafür, dass die Funktionen heißen können, wie sie wollen. | |
new Blaupause; // Startet die Extension | |
class Blaupause | |
{ | |
public $extension_name = 'Blaupause'; // Extension Name | |
public $extension_slug = 'gp-blaupause'; // Extension Slug | |
public $extension_dir = 'Gameplane/Extensions/Blaupause/'; // Verzeichnis der Extension | |
public $extension_file = 'Gameplane/Extensions/Blaupause/Blaupause.extension.php'; // Verzeichnis der Extension | |
public $textdomain = 'Gameplane'; // Extension Textdomain | |
// Wird für das Core-Plugin benötigt + Steuert die start()-Methode | |
public function __construct() | |
{ | |
add_action( 'admin_init', array( $this, 'settings' ) ); | |
if( get_option($this->extension_slug) == 1 ) $this->start(); | |
} | |
/** | |
* Startet die Extension | |
*/ | |
public function start() | |
{ | |
// Erlaubt die Verwendung von Scripten und CSS-Dateien | |
add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts' ) ); | |
} | |
public function settings() | |
{ | |
register_setting( | |
'gameplane-extensions-group', // Gruppe der gesamten Felder | |
$this->extension_slug // Name des einzelnen Feldes | |
); | |
add_settings_field( | |
$this->extension_slug, // ID | |
__($this->extensions_name, $this->textdomain), // Titel | |
array( $this, 'settings_template' ), // Callback | |
'gameplane-extensions', // Seite | |
'gameplane-extensions-section' // Abschnitt | |
); | |
} | |
/** | |
* Methode zur Ausgabe der Checkbox im Backend (Admin) | |
*/ | |
public function settings_template() | |
{ ?> | |
<input type="checkbox" name="<?php echo $this->extension_slug; ?>" value="1" <?php checked(1, get_option($this->extension_slug), true); ?> /> | |
<?php | |
} | |
/** | |
* Bindet die Scripts ein (CSS + JS) | |
*/ | |
public function add_scripts() | |
{ | |
// Aktiviert die CSS-Datei | |
wp_enqueue_style( $this->extension_slug.'-css', plugins_url( $this->extension_dir.'css/style.css', GAMEPLANE_FILE) ); | |
// Aktiviert die Javascript-Datei | |
wp_register_script( $this->extension_slug.'-js', plugins_url( $this->extension_dir.'js/script.js', GAMEPLANE_FILE), array('jquery')); | |
wp_enqueue_script( $this->extension_slug.'-js'); | |
} | |
} // !class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment