- wip trying to patch jquery url validator
- resolve conflict in addition of multiple vars and ajax function
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -31,14 +31,6 @@
|
||||
}
|
||||
?>
|
||||
</ol>
|
||||
<ol>
|
||||
<p>list get_fields() :</p>
|
||||
<?php
|
||||
foreach($acf_get_fields as $meta_key => $meta_value) {
|
||||
include($plgn_dir."html/templates/print_meta.html");
|
||||
}
|
||||
?>
|
||||
</ol>
|
||||
<ol>
|
||||
<p>list get_userdata() :</p>
|
||||
<?php
|
||||
@@ -63,14 +55,6 @@
|
||||
}
|
||||
?>
|
||||
</ol>
|
||||
<ol>
|
||||
<p>list get_field() :</p>
|
||||
<?php
|
||||
foreach($acf_get_email as $meta_key => $meta_value) {
|
||||
include($plgn_dir."html/templates/print_meta.html");
|
||||
}
|
||||
?>
|
||||
</ol>
|
||||
|
||||
<p>i am a new p</p>
|
||||
<p class="first_el_to_change">to change</p>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
console.log("-------------EXAMPLEEEEE----------------- :)");
|
||||
console.log("PLGNTLS_data:");
|
||||
console.log(PLGNTLS_data);
|
||||
|
||||
|
||||
20
plugins/fipfcard_plugin/js/jquery_validator_patch.js
vendored
Normal file
20
plugins/fipfcard_plugin/js/jquery_validator_patch.js
vendored
Normal file
@@ -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);
|
||||
@@ -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 <?php echo $this->_prefix ?>_ajax(ajax_data, action) {
|
||||
const _ajax_nonce = "<?php echo wp_create_nonce( 'wp-pageviews-nonce' ); ?>";
|
||||
const _ajax_url = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
|
||||
const data = new FormData();
|
||||
|
||||
2
private
2
private
Submodule private updated: 1c1acb2728...42644f633f
Reference in New Issue
Block a user