admin_url( 'admin-ajax.php' ) ) );
}
endif;
add_action( 'admin_enqueue_scripts', "firsttool_enqueue_scripts" );
if ( ! function_exists( 'firsttool_product_sync' ) ):
/**
* Add Admin Menu Page for 1Tool API Configuration
*
* This page is used to configure API credentials that are being used for
* connecting to 1Tool APIs. It also has feature to sync products manually
* from 1Tool account.
*
* @since 1.0.0
*
*/
function firsttool_product_sync() {
add_menu_page(
__( '1Tool API Settings', '1tool-to-wc-integration' ),
__( '1Tool API Settings', '1tool-to-wc-integration' ),
'manage_options',
'firsttool_settings',
'firsttool_api_setting',
'dashicons-admin-generic',
);
}
endif;
add_action( 'admin_menu', 'firsttool_product_sync' );
if ( ! function_exists( 'firsttool_api_setting' ) ):
/**
* Manages settings form and process it's value to save them in db
*
* Prepare UI for setting page and save the submitted value in WP Options table
* to use them later for API call.
*
* @since 1.0.0
*
*/
function firsttool_api_setting() {
if ( isset($_POST['km_submit_btn']) ) {
$km_applicationSecret = sanitize_text_field( $_POST['km_applicationSecret'] );
update_option( 'km_applicationSecret', $km_applicationSecret );
$km_applicationId = sanitize_text_field( $_POST['km_applicationId'] );
update_option( 'km_applicationId', $km_applicationId );
$km_is_create_invoice = isset( $_POST['km_is_create_invoice'] ) ? sanitize_text_field( $_POST['km_is_create_invoice'] ) : "";
update_option( 'km_is_create_invoice', $km_is_create_invoice );
$km_api = new FIRSTTOOL_API\FirstTool_API;
/* get accessToken */
$km_res = $km_api->km_post_request( 'auth/application', array( 'applicationId' => $km_applicationId, 'applicationSecret' => $km_applicationSecret ) );
if ( isset( $km_res["accessToken"] ) ) {
update_option( 'km_accessToken', $km_res["accessToken"] );
}
}
$km_applicationId = get_option( 'km_applicationId' );
$km_applicationSecret = get_option( 'km_applicationSecret' );
$checked_cat_list = get_option( 'km_checked_category' );
$is_sync_value = get_option( 'km_is_sync' );
$km_is_create_invoice = get_option( 'km_is_create_invoice' );
$syn_frequency_choice = get_option( 'km_sync_frequency' );
?>