-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-swift-plugins_.php
216 lines (177 loc) · 6.04 KB
/
wp-swift-plugins_.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
# #Plugin Name__WP Swift: Plugins
# #Description__Description
# #Plugin URI__http://#
# #Author__Gary Swift
# #Author URI__https://github.com/wp-swift-wordpress-plugins
# #Version__1.0
# #License__GPL2
# #Text Domain__Text Domain
# #Domain Path__Domain Path
/*
Copyright (C) Year Author Email
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, 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
*/
/**
* Generated by the WordPress Option Page generator
* at http://jeremyhixon.com/wp-tools/option-page/
*/
class WPSwiftPlugins {
private $wp_swift_plugins_options;
public function __construct() {
add_action( 'admin_menu', array( $this, 'wp_swift_plugins_add_plugin_page' ) );
add_action( 'admin_init', array( $this, 'wp_swift_plugins_page_init' ) );
}
public function wp_swift_plugins_add_plugin_page() {
add_menu_page(
'WP Swift Plugins', // page_title
'WP Swift Plugins', // menu_title
'manage_options', // capability
'wp-swift-plugins', // menu_slug
array( $this, 'wp_swift_plugins_create_admin_page' ), // function
'dashicons-admin-generic', // icon_url
3 // position
);
}
public function wp_swift_plugins_page_init() {
register_setting(
'wp_swift_plugins_option_group', // option_group
'wp_swift_plugins_option_name', // option_name
array( $this, 'wp_swift_plugins_sanitize' ) // sanitize_callback
);
add_settings_section(
'wp_swift_plugins_setting_section', // id
'Settings', // title
array( $this, 'wp_swift_plugins_section_info' ), // callback
'wp-swift-plugins-admin' // page
);
add_settings_field(
'input_0', // id
'Input', // title
array( $this, 'input_0_callback' ), // callback
'wp-swift-plugins-admin', // page
'wp_swift_plugins_setting_section' // section
);
}
public function wp_swift_plugins_sanitize($input) {
$sanitary_values = array();
if ( isset( $input['input_0'] ) ) {
$sanitary_values['input_0'] = sanitize_text_field( $input['input_0'] );
}
return $sanitary_values;
}
public function wp_swift_plugins_section_info() {
}
public function input_0_callback() {
printf(
'<input class="regular-text" type="text" name="wp_swift_plugins_option_name[input_0]" id="input_0" value="%s">',
isset( $this->wp_swift_plugins_options['input_0'] ) ? esc_attr( $this->wp_swift_plugins_options['input_0']) : ''
);
}
private function download_plugin() {
// Filenames
$plugin_location = plugin_dir_path(dirname(__FILE__));
$url = 'http://github.com/wp-swift-wordpress-plugins/wp-swift-acf-starter-widget/zipball/master/';
$dir = "wp-swift-acf-starter-widget";
$zip_dir_filename = $plugin_location.$dir.".zip";
// Download file
file_put_contents($zip_dir_filename, file_get_contents($url));
// Create a zip object
$zip = new ZipArchive();
$res = $zip->open($zip_dir_filename);
// Handle zip
if ($res === TRUE) {
// Get name of directort inside zip
$temp_dir_name = $zip->getNameIndex(0);
// Extract zip
$zip->extractTo($plugin_location);
$zip->close();
// Rename directory
rename($plugin_location.$temp_dir_name, $plugin_location.$dir);
// Delete zip
unlink($zip_dir_filename);
$plugin_path = $plugin_location.'wp-swift-acf-starter-widget/'.'_wp-swift-widget.php';
// activate_plugin( );
$result = activate_plugin( $plugin_path );
if ( is_wp_error( $result ) ) {
echo "<pre>"; var_dump($result); echo "</pre>";
}
else {
echo "<pre>activate_plugin</pre>";
}
} else {
echo 'Oops, that didn\'t work...';
}
}
public function get_content_from_github($url) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
public function wp_swift_plugins_create_admin_page() {
$this->wp_swift_plugins_options = get_option( 'wp_swift_plugins_option_name' );
?>
<div class="wrap">
<h2>WP Swift Plugins</h2>
<p>WP Swift Plugins</p>
<?php //settings_errors(); ?>
<?php
$ch = curl_init();
$source = 'https://api.github.com/wp-swift-wordpress-plugins';
// curl_setopt($ch,CURLOPT_URL,$source);
// curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
// curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1);
// $content = curl_exec($ch);
// echo "<pre>"; var_dump($content); echo "</pre>";
$res = file_get_contents($source );
$res = json_decode($res);
print_r($res);
// curl_setopt($ch, CURLOPT_URL, $source);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $data = curl_exec ($ch);
// echo "<pre>"; var_dump($ch); echo "</pre>";
// echo "<pre>"; var_dump($data); echo "</pre>";
curl_close ($ch);
// $ch = curl_init();
// curl_setopt($ch,CURLOPT_URL,$url);
// curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
// curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1);
// $content = curl_exec($ch);
// curl_close($ch);
// $plugin = 'Overlay';
// $cache_path = $_SERVER['DOCUMENT_ROOT'].'/plugin-cache/';
// $cache_file = $plugin.'-github.txt';
// $github_json = get_repo_json($cache_path.$cache_file,$plugin);
/*
<form method="post" action="options.php">
<?php
settings_fields( 'wp_swift_plugins_option_group' );
do_settings_sections( 'wp-swift-plugins-admin' );
submit_button();
?>
</form>
*/
?>
</div>
<?php }
}
if ( is_admin() )
$wp_swift_plugins = new WPSwiftPlugins();
/*
* Retrieve this value with:
* $wp_swift_plugins_options = get_option( 'wp_swift_plugins_option_name' ); // Array of All Options
* $input_0 = $wp_swift_plugins_options['input_0']; // Input
*/