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); $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 ( "css/example_style.css", "js/example_init.js", "js/example_script2.js", "js/example_script3.js", "html/example_index.html", "html/example_index2.html", ), compact ( "myvar_1", "myvar_2", "post_metadata", "post_meta", "user_metadata", "user_meta", "acf_get_fields", "user_data", "current_user", "names", "ages", ) ); } add_shortcode('fipfcard_plugin', 'fipfcard_main_shortcode'); function fipfcard_image_editor() { // ob_start(); // wp_image_editor('33545'); // return ob_get_clean(); $test1 = "hello"; $test2 = "you"; $fipfcard_image_editor = new PLGNTLS_class(); return $fipfcard_image_editor->add_to_front( array( "js/image_editor.js", "html/image_editor.html", ), compact( "test1", "test2", ) ); /* if ( ! has_action( "wp_ajax_{$action}" ) ) { it returns error 400 */ } add_shortcode('fipfcard_image_editor', 'fipfcard_image_editor'); /** * Handles image editing via AJAX. * from wp-admin/includes/ajax-action.php */ function wp_ajax_image_editor_PLGNTLS() { $attachment_id = (int) $_POST['postid']; // $attachment_id = 33555; // if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) { // wp_die( -1 ); // } // check_ajax_referer( "image_editor-$attachment_id" ); // require_once ABSPATH . 'wp-admin/includes/image-edit.php'; $msg = false; switch ( $_POST['do'] ) { case 'save': $msg = wp_save_image( $attachment_id ); if ( ! empty( $msg->error ) ) { wp_send_json_error( $msg ); } wp_send_json_success( $msg ); break; case 'scale': $msg = wp_save_image( $attachment_id ); break; case 'restore': $msg = wp_restore_image( $attachment_id ); break; } ob_start(); wp_image_editor( $attachment_id, $msg ); $html = ob_get_clean(); if ( ! empty( $msg->error ) ) { wp_send_json_error( array( 'message' => $msg, 'html' => $html, ) ); } wp_send_json_success( array( 'message' => $msg, 'html' => $html, ) ); } add_action( 'wp_ajax_image_editor_PLGNTLS', 'wp_ajax_image_editor_PLGNTLS' ); /* 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]); } } */ /** * do_action( 'df_before_process', string $form_id, Array $post_array, String $form_type ) * Description: Fires after form is submitted and captcha checking is ok. * Parameters: * - $form_id: (String) Form ID from Form setting. * - $post_array: (Array) Submitted fields from the form. Keys are mapped field names or custom field names (in case of Field Mapping Type is Custom). * - $form_type : (String) Form Type * * wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/DiviFormBuilder.php|298 col 18-35| do_action( 'df_before_process', $form_id, $post_array, $form_type ); * wordpress_docker/volumes/wp_volume/wp-content/plugins/divi-form-builder/includes/ajaxcalls/post_ajax.php|254 col 16-33| do_action( 'df_before_process', $form_id, $post_array, $form_type ); * * check user rights : * - https://developer.wordpress.org/reference/functions/is_user_logged_in/ * - https://stackoverflow.com/questions/19802492/check-if-current-user-is-administrator-in-wordpress * - https://developer.wordpress.org/reference/functions/current_user_can/ */ add_action ('df_before_process', 'PLGNTLS_my_custom_df_form_handler', 10, 3); function PLGNTLS_my_custom_df_form_handler($form_id, $post_array, $form_type) { error_log("in my_custom_df_form_handler"); error_log("form_id"); error_log($form_id); error_log("post_array"); error_log(json_encode($post_array)); error_log("form_type"); error_log($form_type); } // 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 ( 'fipf_card', // webpage title 'fipf_card', // menu title 'manage_options', // capability 'fipfcard-plugin', // menu_slug 'fipfcard_plugin_content' // callback function to display page content ); } add_action('admin_menu', 'fipfcard_plugin_menu'); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ajax - https://stackoverflow.com/questions/43557755/how-to-call-ajax-in-wordpress - in `add_action( 'wp_ajax_get_data', 'my_ajax_handler' );` the 'wp_ajax_get_data' is a hooks formated as 'wp_ajax_{$action}' the `$action` param is passed in the data object of the ajax call - 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 ( 'It works', "data_received" => $_POST['postid'], ), 200 ); } add_action( 'wp_ajax_get_data', 'fipfcard_ajax_handler' ); ?>