-
Notifications
You must be signed in to change notification settings - Fork 0
/
banner-notice-for-wordpress.php
157 lines (136 loc) · 4.52 KB
/
banner-notice-for-wordpress.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
<?php
/**
*
*
* @link http://eduardogonzalez.me/
* @since 1.0.0
* @package Banner_Notice_For_Wordpress
*
* @wordpress-plugin
* Plugin Name: Banner Notice for Wordpress
* Plugin URI: http://eduardogonzalez.me/
* Description: Allows you to set single banner for a notice on the WooCommerce shop
* Version: 1.0.0
* Author: Efrain Gonzalez
* Author URI: http://eduardogonzalez.me/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: banner-notice-for-wordpress
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* 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( 'BANNER_NOTICE_FOR_WORDPRESS_VERSION', '1.0.0' );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-banner-notice-for-wordpress-activator.php
*/
function activate_banner_notice_for_wordpress() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-banner-notice-for-wordpress-activator.php';
Banner_Notice_For_Wordpress_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-banner-notice-for-wordpress-deactivator.php
*/
function deactivate_banner_notice_for_wordpress() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-banner-notice-for-wordpress-deactivator.php';
Banner_Notice_For_Wordpress_Deactivator::deactivate();
}
register_activation_hook( __FILE__, 'activate_banner_notice_for_wordpress' );
register_deactivation_hook( __FILE__, 'deactivate_banner_notice_for_wordpress' );
/**
* 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-banner-notice-for-wordpress.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_banner_notice_for_wordpress() {
$plugin = new Banner_Notice_For_Wordpress();
$plugin->run();
}
run_banner_notice_for_wordpress();
add_action('acf/init', 'my_acf_op_init');
if ( function_exists( 'acf_add_options_page' ) ) {
// Add a top menu page
acf_add_options_page(
array(
'page_title' => 'Banner para su sitio',
'menu_title' => 'Banners de envio',
'menu_slug' => 'banner-notice',
'redirect' => false,
'capability' => 'administrator',
'position' => 5.4
)
);
require_once plugin_dir_path( __FILE__ ) . 'includes/class-acf.php';
add_action('wp_head', 'add_header_banner_notice_for_wordpress');
function add_header_banner_notice_for_wordpress(){
$post_id = "option";
$select = get_field('tipo_de_banner', $post_id);
$imagenes = get_field('imagenes', $post_id);
$mobile = $imagenes['imagen_mobile'];
$desktop = $imagenes['imagen_escritorio'];
$texto = get_field('texto', $post_id);
if (!is_page('carrito') && !is_page('finalizar-compra')) { ?>
<style>
header{padding-top:0px !important;}
.responsive-img{
width: 100%;
margin: 0 auto;
max-width:100%;
}
.text-responsive{
align-items: center;
padding: 5px 20px;
}
.desktopimg{
display: block;
padding: 0px 0px;
width: 100%;
background: white;
}
.mobileimg{
display: none;
padding: 0px 0px;
width: 100%;
background: white;
}
@media (max-width: 998px) {
.desktopimg{display: none !important;}
.mobileimg{display: block !important;}
}
</style>
<?php if ($select== 1) { ?>
<div class="desktopimg">
<img src="<?php echo $desktop ?>" class="responsive-img desktopimg" />
</div>
<div class="mobileimg">
<img src="<?php echo $mobile ?>" class="responsive-img mobileimg" />
</div>
<?php } elseif ($select== 2) { ?>
<div style="width: 100%;background: white;" class="responsive-img">
<div class="text-responsive">
<?php echo $texto;?>
</div>
</div>
<?php } else { /* Deactivated */
}
}
};
}