Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #6

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions hellotext.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
}
}

// Function on Events/AppInstalled.php
register_activation_hook( __FILE__, 'hellotext_activate' );

// Function on Events/AppRemoved.php
register_deactivation_hook( __FILE__, 'hellotext_deactivate' );

Expand Down Expand Up @@ -88,3 +85,20 @@ function hellotext_load_textdomain() {
load_plugin_textdomain( 'hellotext', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'hellotext_load_textdomain' );

function uninstall() {
global $wpdb;

delete_option('hellotext_business_id');
delete_option('hellotext_webchat_id');
delete_option('hellotext_webchat_placement');
delete_option('hellotext_webchat_behaviour');
delete_option('hellotext_access_token');

$api_keys_table = $wpdb->prefix . 'woocommerce_api_keys';
if ($wpdb->get_var("SHOW TABLES LIKE '$api_keys_table'") === $api_keys_table) {
$wpdb->delete($api_keys_table, ['description' => 'Hellotext']);
}
}

register_uninstall_hook(__FILE__, 'uninstall');
Binary file modified languages/hellotext-en_US.mo
Binary file not shown.
3 changes: 3 additions & 0 deletions languages/hellotext-en_US.po
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ msgstr "Top Left"
msgid "settings.webchat_behaviour"
msgstr "Webchat Behaviour"

msgid "settings.submit"
msgstr "Save changes"

msgid "description.paragraphs.one"
msgstr "You can find your Business ID on the <a href=\"https://www.hellotext.com/businesses\" target=\"_blank\" style=\"color: #FF4C00;\">Hellotext business settings</a>."

Expand Down
Binary file modified languages/hellotext-es_ES.mo
Binary file not shown.
3 changes: 3 additions & 0 deletions languages/hellotext-es_ES.po
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ msgstr "Arriba a la izquierda"
msgid "settings.webchat_behaviour"
msgstr "Comportamiento del Webchat"

msgid "settings.submit"
msgstr "Guardar cambios"

msgid "description.paragraphs.one"
msgstr "Puedes encontrar tu ID de negocio en la <a href=\"https://www.hellotext.com/businesses\" target=\"_blank\" style=\"color: #FF4C00;\">configuración de negocios de Hellotext</a>."

Expand Down
3 changes: 3 additions & 0 deletions languages/hellotext.pot
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ msgstr ""
msgid "settings.webchat_placement_top-left"
msgstr ""

msgid "settings.submit"
msgstr ""

msgid "settings.webchat_behaviour"
msgstr ""

Expand Down
44 changes: 30 additions & 14 deletions src/Events/AppInstalled.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,14 @@ function hellotext_activate () {
return;
}

do_action('hellotext_create_profile');
do_action('hellotext_create_integration', $hellotext_business_id);

// Disbaled for now
// $store_image_id = get_option('woocommerce_email_header_image_id');
// $store_image_url = wp_get_attachment_image_url($store_image_id, 'full');

// (new Event())->track('app.installed', array(
// 'app_parameters' => array(
// 'type' => 'app',
// 'name' => get_bloginfo('name'),
// 'image_url' => $store_image_url,
// )
// ));
}

add_action('hellotext_create_integration', function ($business_id) {
if(!$business_id) {
$business_id = get_option('hellotext_business_id');
}

global $wpdb;
$api_keys_table = $wpdb->prefix . 'woocommerce_api_keys';
$api_keys = $wpdb->get_row("SELECT * FROM $api_keys_table WHERE description = 'Hellotext'");
Expand All @@ -52,7 +43,6 @@ function hellotext_activate () {
Client::with_sufix()
->post('/integrations/woo', [
'shop' => [
'business_id' => $business_id,
'name' => get_bloginfo('name'),
'url' => get_bloginfo('url'),
'email' => get_bloginfo('admin_email'),
Expand All @@ -62,3 +52,29 @@ function hellotext_activate () {
]);
});

function after_business_id_save($old_value, $new_value) {
if ($old_value !== $new_value) {
maybe_trigger_integration($new_value);
}
}

function after_business_id_set($value) {
maybe_trigger_integration($value);
}

function maybe_trigger_integration($business_id) {
$hellotext_access_token = get_option('hellotext_access_token');
if ($hellotext_access_token && $business_id) {
do_action('hellotext_create_integration');
} else {
add_action('shutdown', function () {
$hellotext_access_token = get_option('hellotext_access_token');
if ($hellotext_access_token) {
do_action('hellotext_create_integration');
}
});
}
}

add_action('update_option_hellotext_business_id', 'after_business_id_save', 10, 2);
add_action('add_option_hellotext_business_id', 'after_business_id_set', 10, 1);
27 changes: 9 additions & 18 deletions src/Events/AppRemoved.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@
use Hellotext\Api\Client;
use Hellotext\Api\Event;

function hellotext_deactivate () {
$hellotext_business_id = get_option('hellotext_business_id');
if (!$hellotext_business_id) {
return;
}
function hellotext_deactivate ($hellotext_business_id = null) {
if (!$hellotext_business_id) {
$hellotext_business_id = get_option('hellotext_business_id');
}

do_action('hellotext_remove_integration', $hellotext_business_id);
if (!$hellotext_business_id) {
return;
}

// Disbaled for now
// $store_image_id = get_option('woocommerce_email_header_image_id');
// $store_image_url = wp_get_attachment_image_url($store_image_id, 'full');

// (new Event())->track('app.removed', array(
// 'app_parameters' => array(
// 'type' => 'app',
// 'name' => get_bloginfo('name'),
// 'image_url' => $store_image_url,
// )
// ));
}
do_action('hellotext_remove_integration', $hellotext_business_id);
}

add_action('hellotext_remove_integration', function ($business_id) {
Client::with_sufix()
Expand Down
12 changes: 9 additions & 3 deletions src/Misc/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ function hellotext_description_section_callback() {
$business_id = get_option('hellotext_business_id', null);
$access_token = get_option('hellotext_access_token', null);

if ($business_id) {
if (!$business_id) {
echo '<p>' . wp_kses( __( 'description.paragraphs.one', 'hellotext' ), array( 'a' => array( 'href' => array(), 'target' => array(), 'style' => array() ) ) ) . '</p>';
}

if ($access_token) {
if (!$access_token) {
echo '<p>' . wp_kses( __( 'description.paragraphs.two', 'hellotext' ), array( 'a' => array( 'href' => array(), 'target' => array(), 'style' => array() ) ) ) . '</p>';
}
}
Expand Down Expand Up @@ -183,7 +183,13 @@ function hellotext_submenu_page_callback () {
<?php
settings_fields( 'hellotext-form' );
do_settings_sections( 'hellotext-form' );
submit_button('Save Changes', null, null, false, array('style' => 'background-color: #FF4C00; color: #FFFFFF; border: none;'));
submit_button(
__('settings.submit', 'hellotext'),
null,
null,
false,
array('style' => 'background-color: #FF4C00; color: #FFFFFF; border: none;')
);
?>
</form>
</div>
Expand Down
Loading