-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpagos-offline-venezuela.php
197 lines (165 loc) · 6.83 KB
/
pagos-offline-venezuela.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
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link https://netkiub.com
* @since 1.0.0
* @package PagosOfflineVenezuela
*
* @wordpress-plugin
* Plugin Name: Pagos Offline Venezuela
* Plugin URI: https://netkiub.com
* Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area.
* Version: 3.0.1
* Author: Guillermo
* Author URI: https://netkiub.com
* GitHub Plugin URI: https://github.com/guillermoscript/pagos-offline-venezuela
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: pagos-offline-venezuela
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) return;
if ( file_exists( dirname( __FILE__ ) . '/vendor/autoload.php' ) ) {
require_once dirname( __FILE__ ) . '/vendor/autoload.php';
}
define('PLUGIN_BASE_PATH', plugin_dir_path( __FILE__ ));
define('BANK_URL', 'http://www.bcv.org.ve/');
define('REST_API_NAMESPACE', 'pagos-offline-venezuela');
define('REST_API_V1', 'v1');
// use Admin\Init;
use Includes\PagosOfflineVenezuelaActivator;
use Includes\PagosOfflineVenezuelaDeactivator;
use Includes\PagosOfflineVenezuela;
// use Puc_v4_Factory;
/**
* Currently plugin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'PAGOS_OFFLINE_VENEZUELA_VERSION', '1.0.0' );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-pagos-offline-venezuela-activator.php
*/
function activate_pagos_offline_venezuela() {
// require_once plugin_dir_path( __FILE__ ) . 'includes/class-pagos-offline-venezuela-activator.php';
PagosOfflineVenezuelaActivator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-pagos-offline-venezuela-deactivator.php
*/
function deactivate_pagos_offline_venezuela() {
// require_once plugin_dir_path( __FILE__ ) . 'includes/class-pagos-offline-venezuela-deactivator.php';
PagosOfflineVenezuelaDeactivator::deactivate();
}
register_activation_hook( __FILE__, 'activate_pagos_offline_venezuela' );
register_deactivation_hook( __FILE__, 'deactivate_pagos_offline_venezuela' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
// require plugin_dir_path( __FILE__ ) . 'includes/class-pagos-offline-venezuela.php';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
*/
function run_pagos_offline_venezuela() {
$plugin = new PagosOfflineVenezuela();
$plugin->run();
}
run_pagos_offline_venezuela();
add_action( 'wp_ajax_nopriv_get_image_from_checkout', 'get_image_from_checkout');
add_action( 'wp_ajax_get_image_from_checkout', 'get_image_from_checkout');
add_action( 'wp_ajax_nopriv_get_image_from_pay_order', 'get_image_from_pay_order');
add_action( 'wp_ajax_get_image_from_pay_order', 'get_image_from_pay_order');
function get_image_from_checkout() {
// comprobando el nonce
$nonce = sanitize_text_field( $_POST['nonce'] );
if ( ! wp_verify_nonce( $nonce, 'my-ajaxxx-nonce' ) ) {
die ( 'Busted!!!');
}
get_image();
}
function get_image_from_pay_order() {
// comprobando el nonce
$nonce = sanitize_text_field( $_POST['nonce'] );
if ( ! wp_verify_nonce( $nonce, 'my-ajaxxx-nonce2' ) ) {
die ( 'Busted!!!');
}
get_image();
}
function get_image() {
# code...
// estas cosas se requieren,lo vi en internet
if ( ! function_exists( 'wp_handle_upload' ) ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
}
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
foreach ( $_FILES as $image ) {
// $image = $_FILES['file'];
// if a files was upload
if ( $image['size'] < 3000000 ) {
// if it is an image
if ( preg_match('/(jpg|jpeg|png|gif|pdf)$/', $image['type']) ) {
$override = array('test_form' => false);
// save the file, and store an array, containing its location in $file
// guardamos la imagne en la carpeta uploads
$file = wp_handle_upload( $image, $override );
$wp_upload_dir = wp_upload_dir();
if ( $file && ! isset( $file['error'] ) ) {
// aqui es cuando hacemos la imagne un post para que este en la pagina de medios
$file_title_for_media_library = $title;
$attachment = array(
"guid" => $file['url'],
"post_mime_type" => $file['type'],
"post_title" => addslashes( $file_title_for_media_library ),
"post_content" => "",
"post_status" => "draft",
"post_author" => 1
);
$id = wp_insert_attachment( $attachment, $file['file'],0);
$attach_data = wp_generate_attachment_metadata( $id, $file['file'] );
wp_update_attachment_metadata( $id, $attach_data );
// add_option( 'capture', $order_id );
// $i++;
echo json_encode(['succes' => 'yey' , 'id' => $id]);
wp_die();
return ;
} else {
echo json_encode(['error' => 'error al guardar la imagen', 'type' => $file['error']]);
return ;
}
} else {
echo json_encode(['error' => 'Error, tipo no aceptado']);
return ;
}
} else {
echo json_encode(['error' => 'Error, tamano mas grande del permitido']);
return ;
}
}
}
require dirname( __FILE__ ) . '/plugin-update-checker/plugin-update-checker.php';
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://github.com/guillermoscript/pagos-offline-venezuela',
__FILE__, //Full path to the main plugin file or functions.php.
'pagos-offline-venezuela'
);
$myUpdateChecker->setBranch('main');