-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInit.php
103 lines (85 loc) · 2.46 KB
/
Init.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* Plugin Name: Magento API Shortcode
* Plugin URI: http://www.sitecritic.net
* Description: Use short-tags within wordpress to get product information via api calls.
* Version: 1.0
* Requires at least: 3.0
* Author: Bernard Peh
* Author URI: http://www.sitepoint.com/
*License: GPL
*/
class Init {
/**
* constructor
*/
public function __construct() {
// spl autoload
self::auto_include();
// init shortcode
add_action('init', array(__CLASS__, 'initShortcode'));
// init admin
add_action('admin_init', array(__CLASS__, 'initAdmin'));
// init admin menu
add_action('admin_menu', array(__CLASS__, 'createMenu'));
}
/**
* init shortcode
*
*/
public function initShortcode() {
add_shortcode('mage', array('Magento', 'processShortcode'));
}
/**
* init admin
*/
public static function initAdmin() {
// Register vars to be saved from the settings form later
register_setting('magento-api', 'magento-api-url');
register_setting('magento-api', 'magento-caching-time');
register_setting('magento-api', 'magento-cdn');
register_setting('magento-api', 'magento-api-username');
register_setting('magento-api', 'magento-api-passwd');
// add shortcode button to wysiwyg
add_action('media_buttons_context', array('Magento', 'addWysiwygButton'));
// add jquery for shortcode button
if(in_array(basename($_SERVER['PHP_SELF']), array('post.php', 'page.php', 'page-new.php', 'post-new.php'))) {
add_action('admin_footer', array('Magento', 'addWysiwygForm'));
}
}
/**
* create admin menu
*/
public static function createMenu()
{
// add submenu under settings menu
add_submenu_page (
'options-general.php',
'Magento API',
'Magento API',
'manage_options' ,
'magento-api-shortcode-settings' ,
function () {require_once('View/adminhtml/settings.phtml');}
);
}
/**
* use php5 autoload for classes in model dir
*/
public static function auto_include()
{
if(function_exists('spl_autoload_register')) {
function magento_autoload($name)
{
$name = str_replace('\\', DIRECTORY_SEPARATOR, $name);
$file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR . $name . '.php';
if(is_file($file)) {
require_once $file;
}
}
spl_autoload_register('magento_autoload');
}
}
}
// Init this plugin
new Init;
?>