<?php
/**
* This file contains a bunch of helper functions that handle add caching to core WordPress functions.
*
*/
defined( 'ABSPATH' ) || exit; // Exit if accessed directly
if( ! class_exists( 'TIELABS_WP_HELPER' ) ) {
class TIELABS_WP_HELPER {
/**
* Runs on class initialization. Adds filters and actions.
*/
function __construct() {
// Properly clear get_term_by() cache when a term is updated
add_action( 'edit_terms', array( $this, 'wp_flush_get_term_by_cache' ), 10, 2 );
// Properly clear get_term_by() cache when a term is updated
add_action( 'edit_terms', array( $this, 'wp_flush_get_term_by_cache' ), 10, 2 );
// Properly clear term_exists() cache when a term is updated
add_action( 'delete_term', array( $this, 'wp_flush_term_exists' ), 10, 4 );
// Flush the cache for published pages so we don't end up with stale data
add_action( 'transition_post_status', array( $this, 'flush_get_page_by_path_cache' ), 10, 3 );
add_action( 'transition_post_status', array( $this, 'flush_get_page_by_title_cache' ), 10, 3 );
}
/**
* Cached version of get_term_by.
*
* Many calls to get_term_by (with name or slug lookup) across on a single pageload can easily add up the query count.
* This function helps prevent that by adding a layer of caching.
*
* @param string $field Either 'slug', 'name', or 'id'
* @param string|int $value Search for this term value
* @param string $taxonomy Taxonomy Name
* @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
* @param string $filter Optional. Default is 'raw' or no WordPress defined filter will applied.
* @return mixed|null|bool Term Row from database in the type specified by $filter. Will return false if $taxonomy does not exist or $term was not found.
* @link http://vip.wordpress.com/documentation/uncached-functions/ Uncached Functions
*/
public static function get_term_by( $field, $value, $taxonomy, $output = OBJECT, $filter = 'raw' ){
// ID lookups are cached
if ( 'id' == $field ){
return get_term_by( $field, $value, $taxonomy, $output, $filter );
}
$cache_key = $field . '|' . $taxonomy . '|' . md5( $value );
$term_id = wp_cache_get( $cache_key, 'get_term_by' );
if ( false === $term_id ){
$term = get_term_by( $field, $value, $taxonomy );
if ( $term && ! is_wp_error( $term ) ){
wp_cache_set( $cache_key, $term->term_id, 'get_term_by' );
} else{
wp_cache_set( $cache_key, 0, 'get_term_by' ); // if we get an invalid value, let's cache it anyway
}
} else {
$term = get_term( $term_id, $taxonomy, $output, $filter );
}
if ( is_wp_error( $term ) ){
$term = false;
}
return $term;
}
/**
* Cached version of term_exists()
*
* Term exists calls can pile up on a single pageload.
* This function adds a layer of caching to prevent lots of queries.
*
* @param int|string $term The term to check can be id, slug or name.
* @param string $taxonomy The taxonomy name to use
* @param int $parent Optional. ID of parent term under which to confine the exists search.
* @return mixed Returns null if the term does not exist. Returns the term ID
* if no taxonomy is specified and the term ID exists. Returns
* an array of the term ID and the term taxonomy ID the taxonomy
* is specified and the pairing exists.
*/
public static function term_exists( $term, $taxonomy = '', $parent = null ){
//If $parent is not null, let's skip the cache.
if ( null !== $parent ){
return term_exists( $term, $taxonomy, $parent );
}
if ( ! empty( $taxonomy ) ){
$cache_key = $term . '|' . $taxonomy;
}else{
$cache_key = $term;
}
$cache_value = wp_cache_get( $cache_key, 'term_exists' );
//term_exists frequently returns null, but (happily) never false
if ( false === $cache_value ){
$term_exists = term_exists( $term, $taxonomy );
wp_cache_set( $cache_key, $term_exists, 'term_exists' );
}else{
$term_exists = $cache_value;
}
if ( is_wp_error( $term_exists ) )
$term_exists = null;
return $term_exists;
}
/**
* Optimized version of get_term_link that adds caching for slug-based lookups.
*
* Returns permalink for a taxonomy term archive, or a WP_Error object if the term does not exist.
*
* @param int|string|object $term The term object / term ID / term slug whose link will be retrieved.
* @param string $taxonomy The taxonomy slug. NOT required if you pass the term object in the first parameter
*
* @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist.
*/
public static function get_term_link( $term, $taxonomy = null ){
// ID- or object-based lookups already result in cached lookups, so we can ignore those.
if ( is_numeric( $term ) || is_object( $term ) ){
return get_term_link( $term, $taxonomy );
}
$term_object = self::get_term_by( 'slug', $term, $taxonomy );
return get_term_link( $term_object );
}
/**
* Cached version of count_user_posts, which is uncached but doesn't always need to hit the db
*
* count_user_posts is generally fast, but it can be easy to end up with many redundant queries
* if it's called several times per request. This allows bypassing the db queries in favor of
* the cache
*/
public static function count_user_posts( $user_id ){
if ( ! is_numeric( $user_id ) ){
return 0;
}
$cache_key = 'vip_' . (int) $user_id;
$cache_group = 'user_posts_count';
if ( false === ( $count = wp_cache_get( $cache_key, $cache_group ) ) ){
$count = count_user_posts( $user_id );
wp_cache_set( $cache_key, $count, $cache_group, 5 * MINUTE_IN_SECONDS );
}
return $count;
}
/**
* Properly clear get_term_by() cache when a term is updated
*/
function wp_flush_get_term_by_cache( $term_id, $taxonomy ){
$term = get_term_by( 'id', $term_id, $taxonomy );
if ( ! $term ){
return;
}
foreach( array( 'name', 'slug' ) as $field ){
$cache_key = $field . '|' . $taxonomy . '|' . md5( $term->$field );
$cache_group = 'get_term_by';
wp_cache_delete( $cache_key, $cache_group );
}
}
/**
* Flush the cache for published pages so we don't end up with stale data
*
* @param string $new_status The post's new status
* @param string $old_status The post's previous status
* @param WP_Post $post The post
* @link http://vip.wordpress.com/documentation/uncached-functions/ Uncached Functions
*/
function flush_get_page_by_title_cache( $new_status, $old_status, $post ){
if ( 'publish' == $new_status || 'publish' == $old_status )
wp_cache_delete( $post->post_type . '_' . sanitize_key( $post->post_title ), 'get_page_by_title' );
}
/**
* Flush the cache for published pages so we don't end up with stale data
*
* @param string $new_status The post's new status
* @param string $old_status The post's previous status
* @param WP_Post $post The post
*
* @link http://vip.wordpress.com/documentation/uncached-functions/ Uncached Functions
*/
function flush_get_page_by_path_cache( $new_status, $old_status, $post ){
if ( 'publish' === $new_status || 'publish' === $old_status ){
$page_path = get_page_uri( $post->ID );
wp_cache_delete( $post->post_type . '_' . sanitize_key( $page_path ), 'get_page_by_path' );
}
}
/**
* Properly clear term_exists() cache when a term is updated
*/
function wp_flush_term_exists( $term, $tt_id, $taxonomy, $deleted_term ){
foreach( array( 'term_id', 'name', 'slug' ) as $field ){
$cache_key = $deleted_term->$field . '|' . $taxonomy ;
$cache_group = 'term_exists';
wp_cache_delete( $cache_key, $cache_group );
}
}
}
// Single instance.
$TIELABS_WP_HELPER = new TIELABS_WP_HELPER();
}
تمثل الصحة النفسية أولوية في مجال الطب، ونظرتها لأهميتها وتأثيرها على الفرد والمجتمع، وتتنوع مدارس العلاج النفسي سواء كان العلاج الطبي أو العلاج السلوكي، ومع التطور التكنولوجي الذي يشهده العالم الآن، أصبح الناس يستخدمون الذكاء الاصطناعي كبديل للطبيب النفسي، لذلك يصرون الاعتماد على الذكاء الاصطناعي في هذا المجال حول فعاليته مقارنة بالعلاج التقليدي الذي يقدمه الأطباء النفسيون، فهل يمكن أن يحل الذكاء الاصطناعي محل الطبيب النفسي ؟ ، ام انه اداة مساعدة لتعزيز الرعاية النفسية ؟
صرح “د/ مايكل سليم” اخصائي نفسي، ان الذكاء الاصطناعي اصبح يشكل خطرا على المرضي النفسيين الذين يتعالجون من الاكتئاب واضطرابات القلق ، حيث اكد ان استخدامهم للتكنولوجيا بشكل خاطئ يشكل ضررا أكثر من المنفعة ، وقال ان استخدام المرضي ل ” chat gpt” اصبح هوسا لدرجة انهم يتخذونه كصديق لهم ، ليصل بهم الحال ان يتحدثوا معه طوال اليوم تقريبا ، مؤكدا علي ان الارتباط الزائد بالذكاء الاصطناعي قد يسبب للمرضي الشعور بالوحدة والميل الي العزلة وعدم التواصل بمن حولهم ، مما يزيد من الرهاب الاجتماعي لدي المريض وفقد السيطرة علي نفسه عندما يكون وسط مجموعة كبيرة من الأفراد ليصبح أكثر قلقا وتوترا .
واكد الطبيب ” حسني توفيق ” اخصائي طب نفسي وعلاج ادمان ، انه مهما وصلت التكنولوجيا من تطور ، لا يمكن التغافل عن أهمية الطبيب النفسي ، لان المريض يحتاج الي دعم نفسي من شخص مختص ، وبعيدا عن العلاج الطبي فان المريض يحتاج الي تحسين سلوكي ، ويحتاج ان يشرح مشاعره لشخص قادرا علي فهمه والشعور به وليس لخوارزميات مبرمجة لا تفهم .
وقالت “د/ سوزان حلوي ” اخصائية نفسية وعلاج مخ واعصاب ، ان الأشخاص أصبحت تميل الى الطريق الاسهل ، فأصبح المريض النفسي يعتمد اعتمادا كليا على ” chat GPT ” كوسيلة تواصل سهلة بدلا من اللجوء الى اشخاص ، اعتقادا من المريض انه يشغل وقت فراغه ويبوح بمشاعره بحرية وبدون تفكير ، لكنه ينسي خطورة هذا عليه كشخص ، وانه يصبح مع الوقت أكثر عدوانية مع من حوله واكثر عزلة وصمت.
وأضاف ” د/ محمد يسرى ” أخصائي نفسي، أن التكنولوجيا بلا شك لها أهمية كبيرة، وأنها ساعدت في شتى مجالات الطب، لكن حذر من استخدام التكنولوجيا بشكل خاطئ قائلاً ” التكنولوجيا سلاح ذو حدين يمكن أن تدمرك ويمكن أن تطورك وأنت المسئول عن الاختيار”
، ونصح المريض النفسي أنه من الضروري أن يتابع مع أخصائي نفسي أيضاً يستطيع أن يستخدم chat GPT في إطار كيفية وطرق لتحسين حياته، فمن الممكن أن يستخدم التكنولوجيا أو Chat GPT ” بالأخص في وضع نظام غذائي صحي له، أو اقتراح ” podcasts ” لتزويد الشخص بالمعرفة ، وأضاف أن “ChatGPT” يمكنك استخدامه لكن عدم أخذه كصديق أو بديل للأشخاص ، كما ختم حديثه مؤكدا ان ” Chat GPT ” لا يمكنه تشخيص الحالة النفسية للفرد.
وقال ” د/ سيفين جوزيف ” أن استخدام الذكاء الاصطناعي يمكن أن يكون له آثار سلبية على الصحة النفسية، فبينما يمكن أن توفر هذه الأدوات تفاعلات سطحية، فإنها لا تعالج الجذور العميقة للمشاكل النفسية، مثل القلق والاكتئاب.
كما أشار إلى أن الاعتماد على التواصل مع الذكاء الاصطناعي قد يؤدي إلى “تطوير تطبيقات أقل ضررًا، وقد يعوض الأشخاص عن مشاعرهم بالذهاب إلى هذه التطبيقات، مما يؤدي إلى تفاقم مشاعر العزلة والقلق.
بالإضافة إلى ذلك، حذر ان استخدام الذكاء الاصطناعي قد يقلل من الوعي بأهمية العلاج النفسي، عندما يشعر الأشخاص بأنهم غير قادرين على الحصول على الدعم من تطبيقات الذكاء الاصطناعي، فإنهم قد يتجاهلون الحاجة إلى البحث عن مساعدة من المتخصصين، مما يؤدي إلى تفاقم الاعراض .
كما أكد على أهمية التواصل البشري في العلاج النفسي، قائلا: “العلاقة بين المعالج والمريض تعتبر جزءا أساسيًا من العلاج” وقال ان التواصل الفعال والتعاطف لا يمكن تعويضهما بالتكنولوجيا.
و شدد على ضرورة توعية الناس حول حدود الذكاء الاصطناعي في مجال الصحة النفسية. يجب أن نستخدم هذه الأدوات بشكل مسؤول كوسيلة مساعدة، وليس كبديل للعلاج النفسي المتخصص وان الرعاية النفسية تتطلب فهماً عميقاً واهتماماً إنسانياً لا يمكن للتكنولوجيا توفيره.”
وقالت ” مارفي أيمن ” احدى مستخدمي ” Chat GPT” بشكل زائد عن الطبيعي ، أن استخدامها في بداية الأمر كان يقتصر على اتمام المهام التي لديها بواسطة التكنولوجيا ، لكن تطور الموضوع واصبحت تتحدث مع “Chat GPT ” بشكل غير طبيعي وانها مع الوقت شعرت أنها ليس لديها شغف ان تجيب على أصدقاءها عبر مواقع التواصل الاجتماعي او من خلال مقابلتهم ، وأضافت أن برغم استخدامها الكثير ل” chat GPT” الا انها دائما كانت تشعر بالوحدة وعدم الانسجام مع الآخرين ، واضافت أنها واجهت صعوبة لتستعيد حياتها الطبيعية وتعود تنسجم مع من حولها.
وبرغم أن التكنولوجيا توفر دعماً سهلاً وفورياً، إلا أنها تفتقر إلى التعاطف البشري والفهم العميق للسياقات النفسية المعقدة ، وأيضا يعتمد الذكاء الاصطناعي على البيانات والنماذج، مما يؤدى إلى تقديم ونصائح غير مناسبة وغير دقيقة ، ومن المهم أن ندرك ان الصحة النفسية تتطلب رعاية متخصصة وعملية ، حيث يستطيع الأطباء النفسيون تقديم العلاج الفعال والدعم العاطفي ، ويجب ان ينظر الي أدوات مثل ” Chat GPT” كوسيلة مساعدة يمكن استخدامها جنبا الى جنب مع العلاج التقليدي ، وليس كبديل له .