PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
← All changes | includes/class-wpsc-functions.php +99 -2 3.4.8 → 3.5.4 View file →
@@ -72,8 +72,23 @@
72 72 $object = WPSC_Customer::get_anonymous_customer();
73 73 }
74 74 break;
75 75
76 + case 'wpsc_ticket':
77 + if ( $value && isset( self::$ref_classes[ $ref_class ] ) ) {
78 + $class = self::$ref_classes[ $ref_class ]['class'];
79 + $object = new $class( $value );
80 + // A ticket referenced from another record (a todo, a thread, a timer log, ...)
81 + // may have since been archived - archived tickets are moved out of the live
82 + // tickets table entirely, so the lookup above resolves to an empty object. Fall
83 + // back to the archived-ticket table rather than silently returning a blank
84 + // ticket (blank id, blank subject, blank link) to every caller.
85 + if ( ! $object->id ) {
86 + $object = new WPSC_Archive_Ticket( $value );
87 + }
88 + }
89 + break;
90 +
76 91 default:
77 92 $object = apply_filters( 'wpsc_fun_get_object', $value, $ref_class );
78 93 if ( ! is_object( $object ) && isset( self::$ref_classes[ $ref_class ] ) ) {
79 94 $class = self::$ref_classes[ $ref_class ]['class'];
@@ -1302,9 +1317,9 @@
1302 1317 ),
1303 1318 get_permalink( $support_page )
1304 1319 );
1305 1320
1306 - } elseif ( $ticket_url_page === 'open-ticket-page' && $open_page && ! empty( $ticket->auth_code ) ) {
1321 + } elseif ( $ticket_url_page === 'open-ticket-page' && $open_page && $ticket->auth_code ) {
1307 1322
1308 1323 $url = add_query_arg(
1309 1324 array(
1310 1325 'ticket-id' => $ticket_id,
@@ -1314,9 +1329,9 @@
1314 1329 );
1315 1330 }
1316 1331 }
1317 1332
1318 - if ( empty( $url ) ) {
1333 + if ( ! $url ) {
1319 1334 $url = $admin_url;
1320 1335 }
1321 1336
1322 1337 return apply_filters( 'wpsc_get_ticket_url_by_view', $url, $ticket_id, $view );
@@ -1417,8 +1432,90 @@
1417 1432
1418 1433 $is_paid_customer = ! empty( array_intersect( $addon_plugins, $active_plugins ) );
1419 1434 update_option( $cache_key, $is_paid_customer ? 1 : 0 );
1420 1435 return (bool) $is_paid_customer;
1436 + }
1437 +
1438 + /**
1439 + * Whether SupportCandy front-end scripts/styles should load on the current page,
1440 + * based on Settings -> General -> Page settings -> Load scripts.
1441 + *
1442 + * Translation aware: if the current page is a WPML or Polylang translation of a
1443 + * page selected in the 'Custom' list, scripts still load - the settings screen can
1444 + * only ever store the ID of the page in the language active while saving.
1445 + *
1446 + * @return bool
1447 + */
1448 + public static function is_load_scripts_page() {
1449 +
1450 + $page_settings = get_option( 'wpsc-gs-page-settings' );
1451 +
1452 + $load = true;
1453 +
1454 + if ( isset( $page_settings['load-scripts'] ) && $page_settings['load-scripts'] === 'custom' ) {
1455 +
1456 + $current_id = get_the_id();
1457 + $pages = isset( $page_settings['load-script-pages'] ) ? (array) $page_settings['load-script-pages'] : array();
1458 +
1459 + $load = $current_id && self::page_id_in_pages_or_translations( $current_id, $pages );
1460 + }
1461 +
1462 + return (bool) apply_filters( 'wpsc_load_frontend_scripts', $load, $page_settings );
1463 + }
1464 +
1465 + /**
1466 + * Check if given post id matches (directly or via translation) any of the given page ids.
1467 + *
1468 + * @param int $current_id current post id.
1469 + * @param array $page_ids selected page ids from settings.
1470 + * @return bool
1471 + */
1472 + private static function page_id_in_pages_or_translations( $current_id, $page_ids ) {
1473 +
1474 + if ( in_array( $current_id, $page_ids ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
1475 + return true;
1476 + }
1477 +
1478 + foreach ( $page_ids as $page_id ) {
1479 +
1480 + // WPML.
1481 + if ( has_filter( 'wpml_object_id' ) ) {
1482 + $translated_id = apply_filters( 'wpml_object_id', $page_id, 'page', false );
1483 + if ( $translated_id && (int) $translated_id === (int) $current_id ) {
1484 + return true;
1485 + }
1486 + }
1487 +
1488 + // Polylang.
1489 + if ( function_exists( 'pll_get_post_translations' ) ) {
1490 + $translations = pll_get_post_translations( $page_id );
1491 + if ( in_array( $current_id, $translations ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
1492 + return true;
1493 + }
1494 + }
1495 + }
1496 +
1497 + return false;
1498 + }
1499 +
1500 + /**
1501 + * Get current active language code, if a multilingual plugin is active.
1502 + *
1503 + * @return string|null
1504 + */
1505 + public static function get_current_language_code() {
1506 +
1507 + if ( has_filter( 'wpml_current_language' ) ) {
1508 + $lang = apply_filters( 'wpml_current_language', null );
1509 + return $lang ? $lang : null;
1510 + }
1511 +
1512 + if ( function_exists( 'pll_current_language' ) ) {
1513 + $lang = pll_current_language();
1514 + return $lang ? $lang : null;
1515 + }
1516 +
1517 + return null;
1421 1518 }
1422 1519 }
1423 1520 endif;
1424 1521