diff --git a/plugins/fipfcard_plugin/fipfcard_plugin.php b/plugins/fipfcard_plugin/fipfcard_plugin.php index 72762c7..50d0328 100644 --- a/plugins/fipfcard_plugin/fipfcard_plugin.php +++ b/plugins/fipfcard_plugin/fipfcard_plugin.php @@ -103,7 +103,6 @@ add_post_meta(get_the_ID(), "data_user_email", $data); "acf_get_fields", "user_data", "current_user", - "acf_get_email", "names", "ages", ) @@ -250,6 +249,24 @@ function my_custom_url_handler($query) } } +/** + * in `wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php` + * line 1328 : wp_register_script( 'de_fb_validate', DE_FB_URL . '/js/jquery.validation/jquer + * line 1354 : wp_enqueue_script( 'de_fb_validate' ); + */ +function add_my_jquery_patch() +{ + $fipfcard_tools = new PLGNTLS_class(); + return $fipfcard_tools->add_to_front + ( + array + ( + 'de_fb_validate' => 'js/jquery_validator_patch.js', + ) + ); +} +add_action('wp_enqueue_scripts', 'add_my_jquery_patch'); + // Hook into the 'acf/save_post' action add_action('acf/save_post', 'handle_acf_form_submission', 5); // 20 is the priority, you can adjust it as needed function handle_acf_form_submission($post_id) diff --git a/plugins/fipfcard_plugin/html/example_index.html b/plugins/fipfcard_plugin/html/example_index.html index 7b36ba5..352708b 100644 --- a/plugins/fipfcard_plugin/html/example_index.html +++ b/plugins/fipfcard_plugin/html/example_index.html @@ -31,14 +31,6 @@ } ?> -
list get_fields() :
- $meta_value) { - include($plgn_dir."html/templates/print_meta.html"); - } - ?> -list get_userdata() :
list get_field() :
- $meta_value) { - include($plgn_dir."html/templates/print_meta.html"); - } - ?> -i am a new p
to change
diff --git a/plugins/fipfcard_plugin/js/example_init.js b/plugins/fipfcard_plugin/js/example_init.js index b003818..28c1c39 100644 --- a/plugins/fipfcard_plugin/js/example_init.js +++ b/plugins/fipfcard_plugin/js/example_init.js @@ -1,3 +1,4 @@ +console.log("-------------EXAMPLEEEEE----------------- :)"); console.log("PLGNTLS_data:"); console.log(PLGNTLS_data); diff --git a/plugins/fipfcard_plugin/js/jquery_validator_patch.js b/plugins/fipfcard_plugin/js/jquery_validator_patch.js new file mode 100644 index 0000000..4d3d9a9 --- /dev/null +++ b/plugins/fipfcard_plugin/js/jquery_validator_patch.js @@ -0,0 +1,20 @@ +console.log("-------------jquery----------------- :)"); +// https://stackoverflow.com/questions/24938890/wordpress-jquery-noconflict +// https://wordpress.stackexchange.com/questions/104510/how-to-add-jquery-script-to-an-individual-page +// https://developer.wordpress.org/reference/functions/wp_enqueue_script/#jQuery_noConflict_Wrappers +//(function($) { +jQuery( document ).ready( function( $ ) { + + $.validator.addMethod + ( + 'validUrl', + function(value, element) + { + var url = $.validator.methods.url.bind(this); + return url(value, element) || url('http://' + value, element); + }, + 'Please enter a valid URL' + ); + +} ); +//})(jQuery); diff --git a/plugins/fipfcard_plugin/php/utils/plugin_tools.php b/plugins/fipfcard_plugin/php/utils/plugin_tools.php index 854f93e..aeed203 100644 --- a/plugins/fipfcard_plugin/php/utils/plugin_tools.php +++ b/plugins/fipfcard_plugin/php/utils/plugin_tools.php @@ -11,23 +11,24 @@ class PLGNTLS_class { - private static $root_path; - private static $root_url; + private static $_root_path; + private static $_root_url; private static $_ajax_already_there; private $_first_script; - private $_object_data; + private $_prefix; + private $_js_dependencies; + private $_css_dependencies; /** - * init _ajax_already_there - * _first_script - * _object_data */ public function __construct() { if (! isset( self::$_ajax_already_there )) self::$_ajax_already_there = false; - $this->_object_data = "PLGNTLS_data"; + $this->_prefix = "PLGNTLS"; $this->_first_script = null; + $this->_js_dependencies = array(); + $this->_css_dependencies = array(); } /** @@ -35,25 +36,25 @@ class PLGNTLS_class * PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) ); */ public static function set_root_dir($path, $url) { - if (isset( self::$root_path )) + if (isset( self::$_root_path )) return ; - if (isset( self::$root_url )) + if (isset( self::$_root_url )) return ; - self::$root_path = $path; - self::$root_url = $url; + self::$_root_path = $path; + self::$_root_url = $url; } public function get_path() { - return(self::$root_path); + return(self::$_root_path); } public function get_url() { - return(self::$root_url); + return(self::$_root_url); } public function add_to_front($files_arr = null, $vars = null) { $files = array(); - foreach($files_arr as $file_name) { - $files[] = $this->init_file($file_name); + foreach($files_arr as $key => $file_name) { + $files[] = $this->init_file($key, $file_name); } if (!is_null($files_arr)) $this->add_files_to_front($files); @@ -136,23 +137,24 @@ class PLGNTLS_class * this name is the filename + "_" + extension : * init.js -> init_js */ - private function add_vars_to_front($vars_arr, $ajax = null) { + private function add_vars_to_front($vars_arr, $ajax = null) + { if (is_null($this->_first_script)) return ; if (is_null($vars_arr) && is_null($ajax)) return ; $handle = $this->_first_script; - $object_name = $this->_object_data; + $object_name = $this->_prefix . "_data"; - if (is_null($vars_arr)) - $obj = "let $object_name = {};"; - else { + $front = ""; + if (!is_null($vars_arr)) + { $vars_json = json_encode($vars_arr); - $obj = "let $object_name = $vars_json;"; + $front .= "let $object_name = $vars_json;"; } if (! is_null($ajax)) - $obj .= "$object_name.ajax = $ajax"; - wp_add_inline_script($handle, $obj, 'before'); + $front .= "$ajax"; + wp_add_inline_script($handle, $front, 'before'); } /** @@ -173,15 +175,47 @@ class PLGNTLS_class if ($file->ext === "js") { if (is_null($this->_first_script)) $this->_first_script = $file->handle; - wp_enqueue_script( $file->handle, $file->url, $previous_js_basename, $file->version, true); - $previous_js_basename = $file->basename; + $depends_on = $this->check_dependencies($file, $previous_js_basename); + if ($depends_on !== null) + wp_enqueue_script( $file->handle, $file->url, $depends_on, $file->version, true); + $previous_js_basename = $file->handle; } else if ($file->ext === "css") { - wp_enqueue_style( $file->handle, $file->url, $previous_css_basename, $file->version, ''); - $previous_css_basename = $file->basename; + $depends_on = $this->check_dependencies($file, $previous_css_basename); + if ($depends_on !== null) + wp_enqueue_style( $file->handle, $file->url, $depends_on, $file->version, ''); + $previous_css_basename = $file->handle; } } } + private function check_dependencies(&$file, $previous_basename) + { + if ($file->ext === "js") + { + global $wp_scripts; + $already_enqueued = array_search($file->handle, $wp_scripts->queue); + if ($already_enqueued !== false) + { + error_log("double !"); + return null; + } + } + else if ($file->ext === "css") + { + global $wp_styles; + $already_enqueued = array_search($file->handle, $wp_styles->queue); + if ($already_enqueued !== false) + return null; + } + + $depends_on = array(); + if (isset($file->depends) && $file->depends !== '') + $depends_on[] = $file->depends; + if (isset($previous_basename) && $previous_basename !== '') + $depends_on[] = $previous_basename; + + return $depends_on; + } /** * @param string : name of the file, with its path from its extension directory @@ -196,21 +230,28 @@ class PLGNTLS_class * - url : url to file in wordpress * - path : path to file in server * - version : used to avoid browser caching + * - depends : string if depends on a handle, or '' */ - private function init_file($file_name) { + private function init_file($key, $file_name) { $file = (object)[]; $file->ext = pathinfo($file_name, PATHINFO_EXTENSION); if (! in_array($file->ext, array("js", "css", "html"))) return null; - $file->basename = pathinfo($file_name, PATHINFO_FILENAME); - $file->handle = str_replace(".", "_", $file_name); + $file->basename = pathinfo($file_name, PATHINFO_BASENAME); + $file->handle = "PLGNTLS_" . str_replace(".", "_", $file->basename); + error_log("in init file->handle"); + error_log(json_encode($file->handle)); $file->url = $this->get_url().$file_name; $file->path = $this->get_path().$file_name; $file->version = date("ymd-Gis", filemtime($file->path)); + $file->depends = ''; + if (is_string($key)) + $file->depends = $key; + return $file; } @@ -239,7 +280,7 @@ class PLGNTLS_class ob_start(); ?> - function (ajax_data, action) { + function _prefix ?>_ajax(ajax_data, action) { const _ajax_nonce = ""; const _ajax_url = ""; const data = new FormData(); diff --git a/private b/private index 1c1acb2..42644f6 160000 --- a/private +++ b/private @@ -1 +1 @@ -Subproject commit 1c1acb272885908402e2e54304025f5c225771c4 +Subproject commit 42644f633ffb5dcec0cf4c341e113d82fe5b7daa