diff --git a/plugins/fipfcard_plugin/fipfcard_plugin.php b/plugins/fipfcard_plugin/fipfcard_plugin.php index 29de2cf..72762c7 100644 --- a/plugins/fipfcard_plugin/fipfcard_plugin.php +++ b/plugins/fipfcard_plugin/fipfcard_plugin.php @@ -50,7 +50,8 @@ include_once(FIPFCARD_PLUGIN_DIR . '/php/menu/example_menu.php'); * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * plugin shortcode */ -function fipfcard_main_shortcode() { +function fipfcard_main_shortcode() +{ $fipfcard_tools = new PLGNTLS_class(); @@ -61,16 +62,29 @@ function fipfcard_main_shortcode() { $names = ["hugo", "camille"]; $ages = ["13", "34", "56"]; - $getPostMeta = get_post_meta( get_the_ID() ); - $getMetaData = get_metadata( 'post', get_the_ID() ); - $post_meta = $getPostMeta; +$data = wp_get_current_user(); +$data = $data->data; +$data = $data->user_email; +//error_log("data->data"); +//error_log($data); +delete_post_meta(get_the_ID(), "_data_user_email"); +delete_post_meta(get_the_ID(), "_data"); +add_post_meta(get_the_ID(), "data_user_email", $data); - $getUserMeta = get_metadata( 'user', get_current_user_id() ); - $user_meta = $getUserMeta; + $post_metadata = get_metadata( 'post', get_the_ID() ); + $post_meta = get_post_meta( get_the_ID() ); + + $user_metadata = get_metadata( 'user', get_current_user_id() ); + $user_meta = get_user_meta( get_current_user_id() ); + $acf_get_fields = get_fields( get_the_ID() ); + $user_data = get_userdata( get_current_user_id() ); + $current_user = wp_get_current_user(); - return $fipfcard_tools->add_to_front( - array( + return $fipfcard_tools->add_to_front + ( + array + ( "css/example_style.css", "js/example_init.js", "js/example_script2.js", @@ -78,11 +92,18 @@ function fipfcard_main_shortcode() { "html/example_index.html", "html/example_index2.html", ), - compact( + compact + ( "myvar_1", "myvar_2", + "post_metadata", "post_meta", + "user_metadata", "user_meta", + "acf_get_fields", + "user_data", + "current_user", + "acf_get_email", "names", "ages", ) @@ -92,14 +113,198 @@ function fipfcard_main_shortcode() { add_shortcode('fipfcard_plugin', 'fipfcard_main_shortcode'); +/* +add_action('init', 'custom_action_handler'); +function custom_action_handler() { + error_log("inside init :)"); + if ( isset( $_GET['custom_action'] ) && $_GET['custom_action'] === 'do_something' ) { + error_log("GET :)"); + } + if ( isset( $_POST['custom_action'] ) && $_POST['custom_action'] === 'do_something' ) { + error_log("POST :)"); + } + + if ($_SERVER['REQUEST_METHOD'] === 'GET') { + error_log("REQUEST_METHOD === GET"); + error_log("_GET"); + error_log(json_encode($_GET)); + } + if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['submit'])) { + error_log("REQUEST_METHOD === GET && GET[SUBMIT]"); + } + if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['QUERY_STRING'] === 'custom_action=do_something' ) { + error_log("_POST['de_fb_ville']"); + error_log(json_encode($_POST['de_fb_ville'])); + } +*/ + // custom-form-handler.php +/* + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit'])) { + error_log("REQUEST_METHOD === POST && POST[SUBMIT]"); + error_log("_POST"); + error_log(json_encode($_POST)); + // Form submitted, handle the submission + $name = sanitize_text_field($_POST['name']); + $email = sanitize_email($_POST['email']); + + // Perform validation + $errors = array(); + + if (empty($name)) { + $errors['name'] = 'Name is required'; + } + + if (!is_email($email)) { + $errors['email'] = 'Invalid email address'; + } + + if (empty($errors)) { + // Form data is valid, process the submission + // For example, save data to the database or send an email + // Redirect the user or display a success message + } else { + // Form data is not valid, display errors + // You might re-render the form with error messages here + } + } +} +*/ + +/* +[17-Feb-2024 17:54:21 UTC] +{ + "SERVER_SOFTWARE":"nginx\/1.20.2", + "REQUEST_URI":"\/?custom_action=do_something", + "USER":"www-data", + "HOME":"\/home\/www-data", + "HTTP_SEC_GPC":"1", + "HTTP_SEC_FETCH_USER":"?1", + "HTTP_SEC_FETCH_SITE":"same-origin", + "HTTP_SEC_FETCH_MODE":"navigate", + "HTTP_SEC_FETCH_DEST":"document", + "HTTP_UPGRADE_INSECURE_REQUESTS":"1", + "HTTP_COOKIE":"wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_f31a945e73c53ab9af191e34eb33fa88=hugo%7C1708332197%7CbJvy7kRZ3UWJ2C0ZOaSuhpLCz11vHL8CA68sQv9U1ne%7C927c46e3b46a2716df0fcce98d7ccda0e158be0aad0593b2dc233de4ccad9e27; wp-settings-time-11=1708187741; mjx.menu=renderer%3ANativeMML%26%3Bsemantics%3Atrue%26%3Bcontext%3ABrowser%26%3Bzoom%3ANone", + "HTTP_REFERER":"https:\/\/local_fipfcard_plugin.com\/modif_profile\/", + "HTTP_CONNECTION":"keep-alive", + "HTTP_DNT":"1", + "HTTP_ORIGIN":"https:\/\/local_fipfcard_plugin.com", + "HTTP_CONTENT_LENGTH":"2310", + "HTTP_CONTENT_TYPE":"multipart\/form-data; boundary=---------------------------92033335430820533424009149678", + "HTTP_ACCEPT_ENCODING":"gzip, deflate, br", + "HTTP_ACCEPT_LANGUAGE":"en-US,en;q=0.5", + "HTTP_ACCEPT":"text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/avif,image\/webp,*\/*;q=0.8", + "HTTP_USER_AGENT":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko\/20100101 Firefox\/122.0", + "HTTP_HOST":"local_fipfcard_plugin.com", + "REDIRECT_STATUS":"200", + "SERVER_NAME":"local_fipfcard_plugin.com", + "SERVER_PORT":"443", + "SERVER_ADDR":"172.18.0.4", + "REMOTE_PORT":"47220", + "REMOTE_ADDR":"172.18.0.1", + "GATEWAY_INTERFACE":"CGI\/1.1", + "HTTPS":"on", + "REQUEST_SCHEME":"https", + "SERVER_PROTOCOL":"HTTP\/1.1", + "DOCUMENT_ROOT":"\/var\/www\/html", + "DOCUMENT_URI":"\/index.php", + "SCRIPT_NAME":"\/index.php", + "CONTENT_LENGTH":"2310", + "CONTENT_TYPE":"multipart\/form-data; boundary=---------------------------92033335430820533424009149678", + "REQUEST_METHOD":"POST", + "QUERY_STRING":"custom_action=do_something", + "SCRIPT_FILENAME":"\/var\/www\/html\/index.php", + "FCGI_ROLE":"RESPONDER", + "PHP_SELF":"\/index.php", + "REQUEST_TIME_FLOAT":1708192460.934234, + "REQUEST_TIME":1708192460 +} +$_POST +{ + "field_title":["ville_title","nom","pedagogie"], + "field_name":["de_fb_ville","de_fb_nom","de_fb_pedagogie"], + "field_id":["de_fb_ville_id","de_fb_nom","de_fb_pedagogie"], + "de_fb_ville":"gut", + "de_fb_nom":"gut", + "de_fb_pedagogie":"gut", + "form_key":"33420-0", + "unique_id":"d2564b14-290e-4865-b740-7932ae770d43", + "form_type":"custom", + "divi-form-submit":"yes", + "form_id":"modif_profile", + "form_type_confirm":"" +} +*/ +add_action('parse_request', 'my_custom_url_handler'); +function my_custom_url_handler($query) +{ + if ($_SERVER['REQUEST_METHOD'] !== 'POST' ) + return ; + if ($_SERVER['QUERY_STRING'] !== 'update_profile_acf' ) + return ; + // ! add verification that user can do this edit ! + + foreach($_POST['field_name'] as $field) + { + error_log("_POST[$field]"); + error_log($_POST[$field]); + } +} + +// 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) +{ + error_log("in acf/save_post"); +/* + if ($_SERVER['REQUEST_METHOD'] === 'POST' ) + { + error_log("_SERVER['REQUEST_URI']"); + error_log(json_encode($_SERVER['REQUEST_URI'])); + error_log("_SERVER['QUERY_STRING']"); + error_log(json_encode($_SERVER['QUERY_STRING'])); + error_log("_POST['de_fb_ville']"); + error_log(json_encode($_POST['de_fb_ville'])); + } + // Check if the request is coming from the specific URL + if ($_SERVER['QUERY_STRING'] !== '/') { + return; // Exit if the request is not from the specific URL + } + + // Check if this is an autosave + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { + return; + } + + // Check if this is a revision + if (wp_is_post_revision($post_id)) { + return; + } + + // Check if the current user has permission to edit the post + if (!current_user_can('edit_post', $post_id)) { + return; + } + + // Your ACF form submission handling logic goes here + // For example, you can retrieve form data using $_POST and update ACF fields accordingly + if (isset($_POST['your_acf_field_name'])) { + $field_value = sanitize_text_field($_POST['your_acf_field_name']); + update_field('your_acf_field_name', $field_value, $post_id); + } +*/ +} + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * menu plugin */ -function fipfcard_plugin_menu() { - add_menu_page( +function fipfcard_plugin_menu() +{ + add_menu_page + ( 'fipf_card', // webpage title 'fipf_card', // menu title 'manage_options', // capability @@ -122,8 +327,12 @@ ajax - to access the content of the data object properties of the ajax call : use $_POST['property_name'] */ -function fipfcard_ajax_handler() { - wp_send_json_success( array( +function fipfcard_ajax_handler() +{ + wp_send_json_success + ( + array + ( 'It works', "data_received" => $_POST['data'], ), diff --git a/plugins/fipfcard_plugin/html/example_index.html b/plugins/fipfcard_plugin/html/example_index.html index 8ac055b..7b36ba5 100644 --- a/plugins/fipfcard_plugin/html/example_index.html +++ b/plugins/fipfcard_plugin/html/example_index.html @@ -1,6 +1,14 @@
    -

    list of post meta :

    +

    list get_metadata('post') :

    + $meta_value) { + include($plgn_dir."html/templates/print_meta.html"); + } + ?> +
+
    +

    list get_post_meta() :

    $meta_value) { include($plgn_dir."html/templates/print_meta.html"); @@ -8,13 +16,61 @@ ?>
    -

    list of user meta :

    +

    list get_metadata('user') :

    + $meta_value) { + include($plgn_dir."html/templates/print_meta.html"); + } + ?> +
+
    +

    list get_user_meta() :

    $meta_value) { include($plgn_dir."html/templates/print_meta.html"); } ?>
+
    +

    list get_fields() :

    + $meta_value) { + include($plgn_dir."html/templates/print_meta.html"); + } + ?> +
+
    +

    list get_userdata() :

    + $meta_value) { + include($plgn_dir."html/templates/print_meta.html"); + } + ?> +
+
    +

    list wp_get_current_user() :

    + $meta_value) { + include($plgn_dir."html/templates/print_meta.html"); + } + ?> +
+
    +

    list wp_get_current_user()->data :

    + data as $meta_key => $meta_value) { + include($plgn_dir."html/templates/print_meta.html"); + } + ?> +
+
    +

    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/html/templates/print_meta.html b/plugins/fipfcard_plugin/html/templates/print_meta.html index 1f34017..67f95ae 100644 --- a/plugins/fipfcard_plugin/html/templates/print_meta.html +++ b/plugins/fipfcard_plugin/html/templates/print_meta.html @@ -1,4 +1,4 @@
  • "" : - +
  • diff --git a/private b/private index 3a33975..1c1acb2 160000 --- a/private +++ b/private @@ -1 +1 @@ -Subproject commit 3a33975c3ff0d095211ad9d89cb19e6f412a110b +Subproject commit 1c1acb272885908402e2e54304025f5c225771c4