| Server IP : 145.239.37.162 / Your IP : 216.73.217.46 Web Server : Apache System : Linux webm003.cluster130.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : verseaa ( 38250) PHP Version : 7.4.33 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/verseaa/www2024/wp-content/plugins/pop-up-aeb/ |
Upload File : |
<?php
/*
Plugin Name: pop-up Julien
Plugin URI: alencrebleue
Description: affiche une pop-up au chargement de la page
Version: 1.0
Author: alencrebleue
Author URI: alencrebleue.com
*/
// to include ACF functions witin the pugin : https://www.advancedcustomfields.com/resources/including-acf-within-a-plugin-or-theme/
// BEFORE : build ACF fields and make it ok
add_action('save_post', 'mon_plugin_remplir_champs_acf');
function mon_plugin_remplir_champs_acf($post_id)
{
// Vérifier s'il s'agit d'un type de contenu spécifique (article, page, etc.)
if (get_post_type($post_id) === 'post') {
// Récupérer et stocker les données dont vous avez besoin
$mon_champ_personnalise = 'Valeur personnalisée';
// Utiliser la fonction update_field() pour remplir le champ ACF avec la valeur
update_field('nom_du_champ_acf', $mon_champ_personnalise, $post_id);
}
}
// creation table BDD gestion des images
function create_plugin_database_table()
{
global $wpdb;
$table_name = $wpdb->prefix . 'popupaeb';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
name tinytext NOT NULL,
text text NOT NULL,
url varchar(55) DEFAULT '' NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
register_activation_hook(__FILE__, 'create_plugin_database_table');
function delete_plugin_database_table()
{
global $wpdb;
$table_name = $wpdb->prefix . 'popupaeb';
$sql = "DROP TABLE IF EXISTS $table_name";
$wpdb->query($sql);
}
register_deactivation_hook(__FILE__, 'delete_plugin_database_table');
if (is_admin()) {
require_once(plugin_dir_path(__FILE__) . 'admin/class-pop-up-admin.php');
}
// add to menu
function pop_up_plugin_menu()
{
add_menu_page('Pop-up', 'Pop-up', 'manage_options', 'pop-up-plugin', 'pop_up_content', 'dashicons-info-outline');
}
add_action('admin_menu', 'pop_up_plugin_menu');
// content display
function pop_up_content()
{
require_once(plugin_dir_path(__FILE__) . 'public/class-pop-up-public.php');
require_once(plugin_dir_path(__FILE__) . 'admin/class-pop-up-admin.php');
// POURQUOI JE DOIS AJOUTER ICI LE REQUIRE AU LIEU DE LE METTRE PLUS HAUT COMME POUR LA PARTIE ADMIN ??
$popup_cookie_name = 'popup_displayed';
$popup_displayed = isset($_COOKIE[$popup_cookie_name]);
if (is_admin()) {
Pop_up_admin::display();
} else {
// } elseif (is_page('test-popup')) {
Pop_up_public::display();
if (!$popup_displayed) {
setcookie($popup_cookie_name, 'displayed', time() + (365 * 24 * 60 * 60), '/');
}
}
}
add_action('wp_footer', 'pop_up_content');
function pop_up_styles()
{
if(is_admin()) {
wp_enqueue_style('pop-up-styles-admin', plugin_dir_url(__FILE__) . 'admin/admin-view.css');
} else {
wp_enqueue_style('pop-up-styles-public', plugin_dir_url(__FILE__) . '/public/public-view.css');
}
}
add_action('template_redirect', 'pop_up_styles');
add_action('admin_enqueue_scripts', 'pop_up_styles');
function pop_up_scripts()
{
wp_deregister_script('jquery');
wp_register_script('jquery', get_template_directory_uri() . '/assets/js/jquery-3.6.0.min.js', array());
wp_enqueue_script('jquery');
if(is_admin()) {
wp_register_script('popup_scripts-admin', plugin_dir_url(__FILE__) . 'admin/admin-view.js', array('jquery'));
wp_enqueue_script('popup_scripts-admin');
} else {
wp_register_script('popup_scripts-public', plugin_dir_url(__FILE__) . 'public/public-view.js', array('jquery'));
wp_enqueue_script('popup_scripts-public');
}
}
add_action('wp_footer', 'pop_up_scripts');
add_action('wp_enqueue_scripts', 'pop_up_scripts');
add_action('admin_enqueue_scripts', 'pop_up_scripts');
function load_media_files()
{
wp_enqueue_media();
}
add_action('admin_enqueue_scripts', 'load_media_files');
// allow <style> tag in wp editor
add_filter('tiny_mce_before_init', 'custom_allow_style_tags');
function custom_allow_style_tags($init)
{
if (isset($init['extended_valid_elements'])) {
$init['extended_valid_elements'] .= ', style';
} else {
$init['extended_valid_elements'] = 'style';
}
return $init;
}
function custom_acf_rule_type($choices)
{
$choices['Règle custom'] = array(
'my_custom_rule' => 'plugin', // Utilisez la même clé que celle définie dans custom_acf_rule_values()
);
return $choices;
}
add_filter('acf/location/rule_types', 'custom_acf_rule_type');
function custom_acf_rule_values($choices)
{
$choices['my_custom_rule_value'] = 'popup Julien';
// Ajoutez d'autres valeurs si nécessaire
return $choices;
}
add_filter('acf/location/rule_values/my_custom_rule', 'custom_acf_rule_values');
function custom_acf_rule_match($match, $rule, $options)
{
// Vérifier si la règle de localisation est celle de notre règle personnalisée
if ($rule['param'] === 'popup_julien') {
// Récupérer la valeur de l'option du plugin
$custom_rule_value = get_option('my_custom_rule_value');
// Vérifier si la règle est remplie (la valeur de l'option correspond à la valeur définie dans la règle)
if ($rule['operator'] === '==') {
$match = ($custom_rule_value == $rule['value']);
} elseif ($rule['operator'] === '!=') {
$match = ($custom_rule_value != $rule['value']);
}
}
return $match;
}
add_filter('acf/location/rule_match/my_custom_rule', 'custom_acf_rule_match', 10, 3);
function my_plugin_activation()
{
add_option('my_custom_rule_value', 'popup Julien');
}
register_activation_hook(__FILE__, 'my_plugin_activation');
add_action( 'acf/include_fields', function() {
if ( ! function_exists( 'acf_add_local_field_group' ) ) {
return;
}
acf_add_local_field_group( array(
'key' => 'group_64ba5141eafee',
'title' => 'Popup2.0',
'fields' => array(
array(
'key' => 'field_64ba51423c7d4',
'label' => 'Contenu du popup221',
'name' => 'input_group',
'aria-label' => '',
'type' => 'flexible_content',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '100',
'class' => '',
'id' => '',
),
'layouts' => array(
'layout_64bfec106f517' => array(
'key' => 'layout_64bfec106f517',
'name' => 'titre',
'label' => 'Titre',
'display' => 'table',
'sub_fields' => array(
array(
'key' => 'field_64c0d457e0836',
'label' => 'Type de titre',
'name' => 'type_de_titre',
'aria-label' => '',
'type' => 'select',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
'Titre2' => 'Titre2',
'Titre3' => 'Titre3',
),
'default_value' => 'Titre2',
'return_format' => 'value',
'multiple' => 0,
'allow_null' => 0,
'ui' => 0,
'ajax' => 0,
'placeholder' => '',
),
array(
'key' => 'field_64ba6b551d792',
'label' => 'Titre 2',
'name' => 'titre2',
'aria-label' => '',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_64c0d457e0836',
'operator' => '==',
'value' => 'Titre2',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'maxlength' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
),
array(
'key' => 'field_64c0d5ace0837',
'label' => 'Titre 3',
'name' => 'titre3',
'aria-label' => '',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_64c0d457e0836',
'operator' => '==',
'value' => 'Titre3',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'maxlength' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
),
),
'min' => '',
'max' => '',
),
'layout_64c0d290e0831' => array(
'key' => 'layout_64c0d290e0831',
'name' => 'text_line',
'label' => 'Ligne de texte',
'display' => 'row',
'sub_fields' => array(
array(
'key' => 'field_64c0d2c9e0833',
'label' => 'Ligne de texte',
'name' => 'text_line',
'aria-label' => '',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'maxlength' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
),
),
'min' => '',
'max' => '',
),
'layout_64c0d3d0e0834' => array(
'key' => 'layout_64c0d3d0e0834',
'name' => 'textarea',
'label' => 'Zone de texte',
'display' => 'row',
'sub_fields' => array(
array(
'key' => 'field_64c0d7228b95b',
'label' => 'Zone de texte',
'name' => 'textarea',
'aria-label' => '',
'type' => 'textarea',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'maxlength' => '',
'rows' => '',
'placeholder' => '',
'new_lines' => '',
),
),
'min' => '',
'max' => '',
),
'layout_64c0dc16222f8' => array(
'key' => 'layout_64c0dc16222f8',
'name' => 'wysiwyg',
'label' => 'Éditeur WYSIWYG',
'display' => 'row',
'sub_fields' => array(
array(
'key' => 'field_64c0dcd1222fa',
'label' => 'Éditeur WYSIWYG',
'name' => 'wysiwyg',
'aria-label' => '',
'type' => 'wysiwyg',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'tabs' => 'all',
'toolbar' => 'full',
'media_upload' => 1,
'delay' => 0,
),
),
'min' => '',
'max' => '',
),
'layout_64c0d7a08b95c' => array(
'key' => 'layout_64c0d7a08b95c',
'name' => 'button',
'label' => 'Bouton',
'display' => 'row',
'sub_fields' => array(
array(
'key' => 'field_64c0d7bf8b95e',
'label' => 'Lien',
'name' => 'link',
'aria-label' => '',
'type' => 'link',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'return_format' => 'url',
),
array(
'key' => 'field_64c0d9e5b1a52',
'label' => 'Texte lien',
'name' => 'link_text',
'aria-label' => '',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => 'CLIQUEZ ICI',
'maxlength' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
),
),
'min' => '',
'max' => '',
),
'layout_64c0dd02222fb' => array(
'key' => 'layout_64c0dd02222fb',
'name' => 'image',
'label' => 'Image',
'display' => 'row',
'sub_fields' => array(
array(
'key' => 'field_64c0dd29222fd',
'label' => 'Image',
'name' => 'image',
'aria-label' => '',
'type' => 'image',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'return_format' => 'array',
'library' => 'all',
'min_width' => '',
'min_height' => '',
'min_size' => '',
'max_width' => '',
'max_height' => '',
'max_size' => '',
'mime_types' => '',
'preview_size' => 'medium',
),
),
'min' => '',
'max' => '',
),
),
'min' => '',
'max' => '',
'button_label' => 'Ajouter un élément',
),
),
'location' => array(
array(
array(
'param' => 'my_custom_rule',
'operator' => '==',
'value' => 'my_custom_rule_value',
),
),
),
'menu_order' => 0,
'position' => 'side',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => array(
0 => 'the_content',
),
'active' => true,
'description' => '',
'show_in_rest' => 1,
) );
} );