380 lines
12 KiB
PHP
380 lines
12 KiB
PHP
<?php
|
|
/*
|
|
Plugin Name: fipfcard_plugin
|
|
Plugin URI:
|
|
Description:
|
|
Author: hugogogo
|
|
Version: 1.1.0
|
|
Author URI:
|
|
*/
|
|
|
|
/**
|
|
* it means someone outside wp is accessing the file, in this case kill it.
|
|
*/
|
|
if (!defined('ABSPATH')) {
|
|
die('You can not access this file!');
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* plugin dir root
|
|
*/
|
|
include_once( plugin_dir_path(__FILE__) . '/utils/plugin_tools.php');
|
|
PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
|
|
|
|
/**
|
|
* general inclusions
|
|
*/
|
|
include_once(PLGNTLS_class::get_path() . '/php/utils/globals.php');
|
|
include_once(PLGNTLS_class::get_path() . '/php/utils/console_log.php');
|
|
|
|
//include_once(PLGNTLS_class::get_path() . '/php/images/image_edit_shortcode.php');
|
|
//include_once(PLGNTLS_class::get_path() . '/php/images/image-edit.php');
|
|
|
|
//include_once(PLGNTLS_class::get_path() . '/php/test_cache.php');
|
|
|
|
|
|
|
|
|
|
/**
|
|
* test the class PLGNTLS
|
|
*/
|
|
add_shortcode('fipfcard_plugin', 'fipfcard_test_class_tools');
|
|
|
|
|
|
|
|
|
|
/**
|
|
*
|
|
*/
|
|
function custom_frontend_posting_form() {
|
|
$my_image = the_field('image_ratio');
|
|
error_log("my_image");
|
|
error_log(json_encode($my_image));
|
|
return $my_image;
|
|
}
|
|
add_shortcode('custom_frontend_posting_form', 'custom_frontend_posting_form');
|
|
|
|
// function author_shortode_test($field) {
|
|
// // global $authordata;
|
|
// // $user_id = $authordata->ID;
|
|
//
|
|
// $author_username = get_query_var('author_name');
|
|
// $author = get_user_by('slug', $author_username);
|
|
// $user_id = $author->ID;
|
|
//
|
|
// $acf_field = $field['field'];
|
|
// $acf_post_id = "user_{$user_id}";
|
|
//
|
|
// $acf_shortcode = "[acf field='" . $acf_field . "' post_id='" . $acf_post_id . "']";
|
|
//
|
|
// error_log("---");
|
|
// error_log("acf_shortcode:");
|
|
// error_log($acf_shortcode);
|
|
// // error_log("get_userdata:");
|
|
// // error_log(json_encode(get_userdata($user_id)->data->user_email));
|
|
// error_log("get_fields($acf_post_id):");
|
|
// error_log(json_encode(get_fields($acf_post_id)));
|
|
// error_log("get_field($acf_field, $acf_post_id):");
|
|
// error_log(json_encode(get_field($acf_field, $acf_post_id)));
|
|
//
|
|
// //$shortcode = "[acf field=" . $field['field'] . "]";
|
|
// wp_reset_query();
|
|
// $acf_return = do_shortcode($acf_shortcode);
|
|
// // error_log("acf_return:");
|
|
// // error_log(json_encode($acf_return));
|
|
// return $acf_return;
|
|
// // regarder option repeter de diviengine
|
|
// // peutetre plugin gratuit ?
|
|
// // plugin menu avec conditions
|
|
// }
|
|
// add_shortcode('fipf_acf', 'author_shortode_test', 10, 1);
|
|
|
|
|
|
|
|
|
|
/**
|
|
* call to paypal_shortcode_content()
|
|
*/
|
|
include_once(PLGNTLS_class::get_path() . '/php/paypal/paypal.php');
|
|
add_shortcode('fipf_paypal_shortcode', 'paypal_shortcode_content');
|
|
|
|
|
|
|
|
//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]);
|
|
// }
|
|
//}
|
|
|
|
|
|
/*
|
|
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/
|
|
*/
|
|
// 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);
|
|
// }
|
|
// add_action ('df_before_process', 'PLGNTLS_my_custom_df_form_handler', 10, 3);
|
|
|
|
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
include_once(PLGNTLS_class::get_path() . '/php/menu/example_menu.php');
|
|
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' );
|
|
|
|
?>
|