diff --git a/plugins/fipfcard_plugin/fipfcard_plugin.php b/plugins/fipfcard_plugin/fipfcard_plugin.php index 7396af8..a3e6441 100644 --- a/plugins/fipfcard_plugin/fipfcard_plugin.php +++ b/plugins/fipfcard_plugin/fipfcard_plugin.php @@ -1,6 +1,6 @@ add_to_front( array( + echo $cipfcard->add_to_front( array( array("js/menu/example_menu.js", 'type'=>'module'), "css/menu/menu.css", "PLGNTLS_menu_css" => array('css'=>$my_css), @@ -66,17 +66,17 @@ ajax - to access the content of the data object properties of the ajax call : use $_POST['property_name'] */ -function fipfcard_menu_fetch_handler() +function cipfcard_menu_fetch_handler() { return new WP_REST_Response('hello', 200); } -function fipfcard_menu_endpoint() +function cipfcard_menu_endpoint() { register_rest_route('plgntls', '/get_data', array( 'methods' => 'POST', - 'callback' => 'fipfcard_menu_fetch_handler', + 'callback' => 'cipfcard_menu_fetch_handler', )); }; -add_action('rest_api_init', 'fipfcard_menu_endpoint'); +add_action('rest_api_init', 'cipfcard_menu_endpoint'); ?> diff --git a/plugins/fipfcard_plugin/php/author_restriction.php b/plugins/fipfcard_plugin/php/author_restriction.php index df477d5..3dea627 100644 --- a/plugins/fipfcard_plugin/php/author_restriction.php +++ b/plugins/fipfcard_plugin/php/author_restriction.php @@ -29,7 +29,7 @@ function restrict_author_page_CIPF() { $current_user_id = get_current_user_id(); if ($current_user_id != $author_id) { - wp_redirect(home_url()); + wp_redirect(home_url(), 301); exit; } } diff --git a/plugins/fipfcard_plugin/php/form_builder_patch/multiple_modals.php b/plugins/fipfcard_plugin/php/form_builder_patch/multiple_modals.php index 7b717e3..41df4e3 100644 --- a/plugins/fipfcard_plugin/php/form_builder_patch/multiple_modals.php +++ b/plugins/fipfcard_plugin/php/form_builder_patch/multiple_modals.php @@ -10,8 +10,8 @@ if (!defined('ABSPATH')) { function test_modal_PLGNTLS() { - $fipf_modal = new PLGNTLS_class(); - $fipf_modal->add_to_front( + $cipf_modal = new PLGNTLS_class(); + $cipf_modal->add_to_front( array( 'js/form_builder_patch/multiple_modals.js', )); diff --git a/plugins/fipfcard_plugin/php/images/image_edit_shortcode.php b/plugins/fipfcard_plugin/php/images/image_edit_shortcode.php index 44a3d28..e95733f 100644 --- a/plugins/fipfcard_plugin/php/images/image_edit_shortcode.php +++ b/plugins/fipfcard_plugin/php/images/image_edit_shortcode.php @@ -8,13 +8,13 @@ if (!defined('ABSPATH')) { } /* -function fipfcard_image_editor() +function cipfcard_image_editor() { // ob_start(); // wp_image_editor('33545'); // return ob_get_clean(); - $fipfcard_image_editor = new PLGNTLS_class(); - return $fipfcard_image_editor->add_to_front( + $cipfcard_image_editor = new PLGNTLS_class(); + return $cipfcard_image_editor->add_to_front( array( "js/image_editor.js", "html/image_editor.html", @@ -24,7 +24,7 @@ function fipfcard_image_editor() // it returns error 400 } -add_shortcode('fipfcard_image_editor', 'fipfcard_image_editor'); +add_shortcode('cipfcard_image_editor', 'cipfcard_image_editor'); */ diff --git a/plugins/fipfcard_plugin/php/paypal/route_api_orders.php b/plugins/fipfcard_plugin/php/paypal/route_api_orders.php index b49e58f..4adbef3 100644 --- a/plugins/fipfcard_plugin/php/paypal/route_api_orders.php +++ b/plugins/fipfcard_plugin/php/paypal/route_api_orders.php @@ -12,7 +12,7 @@ if (!defined('ABSPATH')) { /** * @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend */ -function handle_orders_request_FIPF($request_data) { +function handle_orders_request_CIPF($request_data) { try { // Extract cart information from request body //$cart = $request_data['cart']; @@ -22,12 +22,12 @@ function handle_orders_request_FIPF($request_data) { throw new HttpErrorException($can_pay['message'], 403); // Process the order and get the response - //$order_response = create_order_FIPF($cart); - $order_response = create_order_FIPF(); + //$order_response = create_order_CIPF($cart); + $order_response = create_order_CIPF(); $json_response = $order_response['json_response']; $http_status_code = $order_response['http_status_code']; - update_user_payment_FIPF($json_response, 'start'); + update_user_payment_CIPF($json_response, 'start'); // Return response return new WP_REST_Response($json_response, $http_status_code); @@ -48,12 +48,12 @@ function handle_orders_request_FIPF($request_data) { * Create an order to start the transaction. * @see https://developer.paypal.com/docs/api/orders/v2/#orders_create */ -//function create_order_FIPF($cart) -function create_order_FIPF() +//function create_order_CIPF($cart) +function create_order_CIPF() { // use the cart information passed from the front-end to calculate the purchase unit details - $access_token = generate_access_token_FIPF(); + $access_token = generate_access_token_CIPF(); $user_id = get_current_user_id(); $acf_id = 'user_' . $user_id; @@ -100,7 +100,7 @@ function create_order_FIPF() curl_close($ch); // in utils - return handle_response_FIPF($response); + return handle_response_CIPF($response); }; diff --git a/plugins/fipfcard_plugin/php/paypal/route_api_orders_capture.php b/plugins/fipfcard_plugin/php/paypal/route_api_orders_capture.php index 1188f92..a190d8c 100644 --- a/plugins/fipfcard_plugin/php/paypal/route_api_orders_capture.php +++ b/plugins/fipfcard_plugin/php/paypal/route_api_orders_capture.php @@ -10,18 +10,18 @@ if (!defined('ABSPATH')) { -function handle_orders_capture_request_FIPF($request) { +function handle_orders_capture_request_CIPF($request) { $order_id = $request['orderID']; try { // Implement captureOrder function logic here // Make sure you implement captureOrder function similar to the Node.js code - $response_data = capture_order_FIPF($order_id); + $response_data = capture_order_CIPF($order_id); $http_status_code = $response_data['http_status_code']; $json_response = $response_data['json_response']; - update_user_payment_FIPF($json_response, 'end'); + update_user_payment_CIPF($json_response, 'end'); return new WP_REST_Response($json_response, $http_status_code); } @@ -35,8 +35,8 @@ function handle_orders_capture_request_FIPF($request) { * Capture payment for the created order to complete the transaction. * @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture */ -function capture_order_FIPF($orderID) { - $access_token = generate_access_token_FIPF(); +function capture_order_CIPF($orderID) { + $access_token = generate_access_token_CIPF(); $url = PAYPAL_API_BASE_URL . '/v2/checkout/orders/' . $orderID . '/capture'; $headers = array( @@ -65,7 +65,7 @@ function capture_order_FIPF($orderID) { curl_close($ch); // in utils - return handle_response_FIPF($response); + return handle_response_CIPF($response); }; diff --git a/plugins/fipfcard_plugin/php/paypal/route_api_utils.php b/plugins/fipfcard_plugin/php/paypal/route_api_utils.php index fd31d4b..8bcc2be 100644 --- a/plugins/fipfcard_plugin/php/paypal/route_api_utils.php +++ b/plugins/fipfcard_plugin/php/paypal/route_api_utils.php @@ -12,7 +12,7 @@ if (!defined('ABSPATH')) { /** * @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend */ -function handle_response_FIPF($response) { +function handle_response_CIPF($response) { try { // Decode JSON response @@ -54,7 +54,7 @@ async function handleResponse(response) { * @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend * @see https://developer.paypal.com/api/rest/authentication/ */ -function generate_access_token_FIPF() +function generate_access_token_CIPF() { try { diff --git a/plugins/fipfcard_plugin/php/paypal/routes.php b/plugins/fipfcard_plugin/php/paypal/routes.php index 4e23260..072cfe9 100644 --- a/plugins/fipfcard_plugin/php/paypal/routes.php +++ b/plugins/fipfcard_plugin/php/paypal/routes.php @@ -11,20 +11,19 @@ if (!defined('ABSPATH')) { // handling routes and endpoints // diff routes and endpoints : https://stackoverflow.com/q/56075017/9497573 -function routes_endpoints_FIPF() +function routes_endpoints_CIPF() { - $base_rest_route = "fipf_plugin/api/v1"; + $base_rest_route = "cipf_plugin/api/v1"; register_rest_route($base_rest_route, '/orders', array( 'methods' => 'POST', - 'callback' => 'handle_orders_request_FIPF', + 'callback' => 'handle_orders_request_CIPF', )); - // https://local_fipfcard_plugin.com/wp-json/fipf_plugin/api/v1/orders/21T129305J264761D/capture register_rest_route($base_rest_route, '/orders/(?P[a-zA-Z0-9]+)/capture', array( 'methods' => 'POST', - 'callback' => 'handle_orders_capture_request_FIPF', + 'callback' => 'handle_orders_capture_request_CIPF', )); }; -add_action('rest_api_init', 'routes_endpoints_FIPF'); +add_action('rest_api_init', 'routes_endpoints_CIPF'); diff --git a/plugins/fipfcard_plugin/php/paypal/shortcode.php b/plugins/fipfcard_plugin/php/paypal/shortcode.php index 610b6af..d598fd0 100644 --- a/plugins/fipfcard_plugin/php/paypal/shortcode.php +++ b/plugins/fipfcard_plugin/php/paypal/shortcode.php @@ -15,11 +15,11 @@ if (!defined('ABSPATH')) { /** * call to paypal_shortcode_content() */ -function paypal_shortcode_content_FIPF() +function paypal_shortcode_content_CIPF() { // if (!can_pay_now_CIPF()) // return no_payment_CIPF(); - $fipfcard_paypal = new PLGNTLS_class(); + $cipfcard_paypal = new PLGNTLS_class(); $pp_client_id = PAYPAL_CLIENT_ID; $pp_sdk_currency = "EUR"; @@ -31,7 +31,7 @@ function paypal_shortcode_content_FIPF() $paypal_message_success = PAYPAL_MESSAGE_SUCCESS; $paypal_message_failure = PAYPAL_MESSAGE_FAILURE; - $added_to_front = $fipfcard_paypal->add_to_front( + $added_to_front = $cipfcard_paypal->add_to_front( array( $pp_sdk_url, array("js/paypal/paypal.js", 'type'=>'module'), @@ -47,7 +47,7 @@ function paypal_shortcode_content_FIPF() return $added_to_front; } -add_shortcode('fipf_paypal_shortcode', 'paypal_shortcode_content_FIPF'); +add_shortcode('cipf_paypal_shortcode', 'paypal_shortcode_content_CIPF'); function no_payment_CIPF() { diff --git a/plugins/fipfcard_plugin/php/paypal/update_user_payment.php b/plugins/fipfcard_plugin/php/paypal/update_user_payment.php index 9d29485..45c5fd9 100644 --- a/plugins/fipfcard_plugin/php/paypal/update_user_payment.php +++ b/plugins/fipfcard_plugin/php/paypal/update_user_payment.php @@ -15,17 +15,17 @@ if (!defined('ABSPATH')) { * basically it check if the user who initiate the transaction * is the same that finish it * -* add_user_meta('user_id', 'fipf_order_id', 'aaaaaa'); +* add_user_meta('user_id', 'cipf_order_id', 'aaaaaa'); * ['aaaaaa'] -* add_user_meta('user_id', 'fipf_order_id', 'bbbbbb'); +* add_user_meta('user_id', 'cipf_order_id', 'bbbbbb'); * ['aaaaaa', 'bbbbbb'] -* add_user_meta('user_id', 'fipf_order_id', 'bbbbbb'); +* add_user_meta('user_id', 'cipf_order_id', 'bbbbbb'); * ['aaaaaa', 'bbbbbb', 'bbbbbb'] -* get_user_meta('user_id', 'fipf_order_id'); +* get_user_meta('user_id', 'cipf_order_id'); * ['aaaaaa', 'bbbbbb', 'bbbbbb'] -* $del_ret = delete_user_meta('user_id', 'fipf_order_id', 'bbbbbb'); +* $del_ret = delete_user_meta('user_id', 'cipf_order_id', 'bbbbbb'); * ['aaaaaa'] - $del_ret === true -* $del_ret = delete_user_meta('user_id', 'fipf_order_id', 'bbbbbb'); +* $del_ret = delete_user_meta('user_id', 'cipf_order_id', 'bbbbbb'); * ['aaaaaa'] - $del_ret === false * * order status : https://developer.paypal.com/docs/api/orders/v2/#orders_capture!c=201&path=status&t=response @@ -37,16 +37,16 @@ if (!defined('ABSPATH')) { * PAYER_ACTION_REQUIRED * */ -function update_user_payment_FIPF($message, $step) { +function update_user_payment_CIPF($message, $step) { $order_id = $message->id; $user_id = get_current_user_id(); $status = $message->status; - // addind order_id to fipf_order_id meta field + // addind order_id to cipf_order_id meta field // it can duplicate, it's not a problem : delete_user_meta will delete all - add_user_meta($user_id, 'fipf_order_id', $order_id); + add_user_meta($user_id, 'cipf_order_id', $order_id); // add a schedule event to delete this order_id - schedule_delete_orderid_FIPF($user_id, $order_id); + schedule_delete_orderid_CIPF($user_id, $order_id); /* * create a meta field to check states of payements on prof author page : @@ -55,17 +55,17 @@ function update_user_payment_FIPF($message, $step) { * - '' -> no message to output | on author page (after set to empty on author page) * */ - delete_user_meta($user_id, 'fipf_payement_status'); - add_user_meta($user_id, 'fipf_payement_status', 'started'); + delete_user_meta($user_id, 'cipf_payement_status'); + add_user_meta($user_id, 'cipf_payement_status', 'started'); // if transaction is COMPLETED, then delete order_id and update user if ($status === 'COMPLETED') { // find the user containing the order_id and delete this order_id - $user_id_to_update = delete_order_id_on_success_FIPF($user_id, $order_id); + $user_id_to_update = delete_order_id_on_success_CIPF($user_id, $order_id); // change payement status to success - update_user_meta($user_id_to_update, 'fipf_payement_status', 'success'); + update_user_meta($user_id_to_update, 'cipf_payement_status', 'success'); // proceed to validate payment for user - validate_payment_for_user_FIPF($user_id_to_update, $order_id); + validate_payment_for_user_CIPF($user_id_to_update, $order_id); } } @@ -89,7 +89,7 @@ function update_user_payment_FIPF($message, $step) { * -> https://www.advancedcustomfields.com/resources/date-time-picker/ * */ -function validate_payment_for_user_FIPF($user_id, $order_id) { +function validate_payment_for_user_CIPF($user_id, $order_id) { $acf_card_state = PLGNTLS_class::ACF_CARD_STATE; $acf_card_expiration = PLGNTLS_class::ACF_CARD_EXPIRATION; $card_duration = PLGNTLS_class::CARD_VALIDITY_TIME; @@ -169,21 +169,21 @@ function validate_payment_for_user_FIPF($user_id, $order_id) { * -> also strtotime : https://www.php.net/manual/en/function.strtotime.php * */ -function schedule_delete_orderid_FIPF($user_id, $order_id) +function schedule_delete_orderid_CIPF($user_id, $order_id) { $delay = time() + MINUTE_IN_SECONDS; - wp_schedule_single_event($delay, 'orderid_deletion_event_FIPF', array($user_id, $order_id)); + wp_schedule_single_event($delay, 'orderid_deletion_event_CIPF', array($user_id, $order_id)); } /* * action hook for the scheduled event * TODO: ne marche pas je ne sais pas pourquoi, pas urgent a resoudre * */ -function delete_order_id_later_FIPF($user_id, $order_id) +function delete_order_id_later_CIPF($user_id, $order_id) { - delete_user_meta($user_id, 'fipf_order_id', $order_id); + delete_user_meta($user_id, 'cipf_order_id', $order_id); } -add_action('orderid_deletion_event_FIPF', 'delete_order_id_later_FIPF', 5, 2); +add_action('orderid_deletion_event_CIPF', 'delete_order_id_later_CIPF', 5, 2); @@ -195,9 +195,9 @@ add_action('orderid_deletion_event_FIPF', 'delete_order_id_later_FIPF', 5, 2); * bool false - if no match found * */ -function delete_order_id_on_success_FIPF($current_user_id, $order_id) +function delete_order_id_on_success_CIPF($current_user_id, $order_id) { - $del_ret = delete_user_meta($current_user_id, 'fipf_order_id', $order_id); + $del_ret = delete_user_meta($current_user_id, 'cipf_order_id', $order_id); if ($del_ret === true) return $current_user_id; @@ -207,7 +207,7 @@ function delete_order_id_on_success_FIPF($current_user_id, $order_id) foreach ($users as $user) { $user_id = $user->ID; - $del_ret = delete_user_meta($user_id, 'fipf_order_id', $order_id); + $del_ret = delete_user_meta($user_id, 'cipf_order_id', $order_id); if ($del_ret === true) return $user_id; } diff --git a/plugins/fipfcard_plugin/php/prof_check_page.php b/plugins/fipfcard_plugin/php/prof_check_page.php index 75d496b..e727f35 100644 --- a/plugins/fipfcard_plugin/php/prof_check_page.php +++ b/plugins/fipfcard_plugin/php/prof_check_page.php @@ -45,13 +45,13 @@ function handle_prof_is_activ_CIPF($author_id) { */ $redirection_prof_inactiv = home_url() . '/' . $slug_wait_activation; - wp_redirect($redirection_prof_inactiv); + wp_redirect($redirection_prof_inactiv, 301); exit; } /* -* check meta field 'fipf_payement_status' +* check meta field 'cipf_payement_status' * if field value is 'success' * - hide block 'failure' * - and update field to '', so it will not show next time @@ -62,9 +62,9 @@ function handle_prof_is_activ_CIPF($author_id) { * if field value is '' * - hide both 'success' and 'failure' blocs * -* .fipf_prof_paiement_message -> on row, added display none in page css -* #fipf_prof_paiement_reussi -> on row -* #fipf_prof_paiement_echoue -> on row +* .cipf_prof_paiement_message -> on row, added display none in page css +* #cipf_prof_paiement_reussi -> on row +* #cipf_prof_paiement_echoue -> on row * */ function show_prof_paiement_messages_CIPF($user_id) { @@ -80,22 +80,22 @@ function show_prof_paiement_messages_CIPF($user_id) { if ($is_activ === 'Inactif') return; - $fipf_prof_payement = new PLGNTLS_class(); + $cipf_prof_payement = new PLGNTLS_class(); - $payement_status2 = get_user_meta($user_id, 'fipf_payement_status'); - $payement_status = get_user_meta($user_id, 'fipf_payement_status', true); + $payement_status2 = get_user_meta($user_id, 'cipf_payement_status'); + $payement_status = get_user_meta($user_id, 'cipf_payement_status', true); if ($payement_status === 'success') { - $fipf_prof_payement->add_to_front(array( - array( 'css' => '#fipf_prof_paiement_reussi {display: block;}' ) + $cipf_prof_payement->add_to_front(array( + array( 'css' => '#cipf_prof_paiement_reussi {display: block;}' ) )); } else if ($payement_status === 'started') { - $fipf_prof_payement->add_to_front(array( - array( 'css' => '#fipf_prof_paiement_echoue {display: block;}' ) + $cipf_prof_payement->add_to_front(array( + array( 'css' => '#cipf_prof_paiement_echoue {display: block;}' ) )); } - update_user_meta($user_id, 'fipf_payement_status', ''); + update_user_meta($user_id, 'cipf_payement_status', ''); } diff --git a/plugins/fipfcard_plugin/php/renew_card.php b/plugins/fipfcard_plugin/php/renew_card.php new file mode 100644 index 0000000..e1fac84 --- /dev/null +++ b/plugins/fipfcard_plugin/php/renew_card.php @@ -0,0 +1,78 @@ + 'post', + 'author' => $current_user_id, + 'posts_per_page' => 1, + ); + $posts = get_posts($args); + if (empty($posts)) + $redirect_url = $base_url; + else { + $query = reset($posts); + $post_id = $query->ID; + $redirect_url = get_permalink($query->ID); + } + wp_redirect($redirect_url, 301); + } + exit; + */ +} +add_action('template_redirect', 'renew_page_restrictions_CIPF'); + + + +function renew_page_filter_message_CIPF(){ + $slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD; + if (!is_page($slug_renew_card)) + return; + + $cipf_renew = new PLGNTLS_class(); + $cipf_prof_payement->add_to_front(array( + array( 'css' => '#cipf_prof_paiement_reussi {display: block;}' ) + )); +} +add_action('wp_enqueue_scripts', 'renew_page_filter_message_CIPF'); + + + + + + + + + +?> diff --git a/plugins/fipfcard_plugin/php/utils/globals.php b/plugins/fipfcard_plugin/php/utils/globals.php index b61718b..3dd4a04 100644 --- a/plugins/fipfcard_plugin/php/utils/globals.php +++ b/plugins/fipfcard_plugin/php/utils/globals.php @@ -15,7 +15,7 @@ if (!defined('ABSPATH')) { /* switch console_log const CONSOLE_OFF = true; */ -const FIPFCARD_CONSOLE_OFF = false; +const CIPF_CONSOLE_OFF = false; /* diff --git a/plugins/fipfcard_plugin/utils/console_log.php b/plugins/fipfcard_plugin/utils/console_log.php index c3d7729..8e6bb0b 100644 --- a/plugins/fipfcard_plugin/utils/console_log.php +++ b/plugins/fipfcard_plugin/utils/console_log.php @@ -12,7 +12,7 @@ if (!defined('ABSPATH')) { https://stackify.com/how-to-log-to-console-in-php/ */ function console_log(...$outputs) { - if (FIPFCARD_CONSOLE_OFF) + if (CIPF_CONSOLE_OFF) return; foreach($outputs as $output) { diff --git a/plugins/fipfcard_plugin/utils/plgntls_class.php b/plugins/fipfcard_plugin/utils/plgntls_class.php index 2d0f415..3b50a72 100644 --- a/plugins/fipfcard_plugin/utils/plgntls_class.php +++ b/plugins/fipfcard_plugin/utils/plgntls_class.php @@ -69,6 +69,7 @@ class PLGNTLS_class const CARD_VALIDITY_TIME = '1 year'; // string : time of validity of the card (ex: '1 month' or '1 year' or '60 days') CONST SLUG_PROF_INACTIV = 'validation-en-cours'; + CONST SLUG_RENEW_CARD = 'commande'; CONST USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)