Hello,
You can use custom code to change the behaviour without changing the plugin code:
a)
/* Modify WP Telegram settings fields */
add_action( 'cmb2_init_before_hookup', function () {
$meta_box = cmb2_get_metabox( 'wptelegram_p2tg' );
if ( ! ( $meta_box instanceof CMB2 ) ) {
return;
}
$meta_box->update_field_property(
'post_types',
'options_cb',
'get_all_post_types_for_wptelegram'
);
} );
function get_all_post_types_for_wptelegram() {
$options = array();
$post_types = get_post_types( array(), 'objects' );
foreach ( $post_types as $post_type ) {
if ( 'attachment' !== $post_type->name ) {
$label = "{$post_type->labels->singular_name} ({$post_type->name})";
$options[ $post_type->name ] = $label;
}
}
return $options;
}
/* Modify WP Telegram settings fields */
b)
/* WP Telegram - modify post URL */
add_filter( 'wptelegram_p2tg_post_data_full_url_value', function ( $url, $post ) {
if ('wpsc_ticket_thread' === $post->post_type ) {
$post_ID = get_post_meta($post->ID,'ticket_id',true);
// Get the URL somehow.
$url = get_permalink( $post_ID );
}
return $url;
}, 10, 2 );
/* WP Telegram - modify post URL */
c)
/* WP Telegram - use custom image */
add_filter( 'wptelegram_p2tg_post_data_featured_image_url_value', function ( $url, $post ) {
if ('wpsc_ticket_thread' === $post->post_type ) {
// Get the URL somehow.
$url = get_term_meta( 'term_id_here', 'file_path', true );
}
return $url;
}, 10, 2 );
/* WP Telegram - use custom image */
Thread Starter
af3
(@af3)
Thank you so much!!!
a) This works okay — thanks.
b) This still give empty $post_ID, not sure why it is not returning the $post_ID
c) the image in the post is in the form of img src=http://myserver.com/?wpsc_img_attachment=923 – i tried this to get term_id = 923 — havent tested
/* WP Telegram - use custom image */
add_filter( 'wptelegram_p2tg_post_data_featured_image_url_value', function ( $url, $post ) {
if ('wpsc_ticket_thread' === $post->post_type ) {
// Get the term id from featured_img url
$url_components = parse_url($url);
parse_str($url_components['query'], $term_query);
$term_ID = $term_query['wpsc_img_attachment'];
// This will give the full file path and not url
$url_path = get_term_meta( $term_ID, 'file_path', true );
// Convert file path to url
$url = 'http://'.$_SERVER['HTTP_HOST'].str_replace($_SERVER['DOCUMENT_ROOT'], '', $url_path);
}
return $url;
}, 10, 2 );
/* WP Telegram - use custom image */
d) Also added this to get the ticket title — but i cant get the topic title.
/* WP Telegram - use custom topic */
add_filter( 'wptelegram_p2tg_post_data_post_title_value', function ( $post_title, $post ) {
if ('wpsc_ticket_thread' === $post->post_type ) {
global $wpdb;
$ticket_subject = $wpdb->get_var( "SELECT ticket_subject FROM ".$wpdb->prefix."wpsc_ticket WHERE historyId = " . $post->ID );
$post_title = $ticket_subject;
}
return $post_title;
}, 10, 2 );
/* WP Telegram - use custom topic */
The code I gave you is just a demonstration of how to do it without modifying the plugin, the actual working of the code still needs to be figured out by you or your developer.
Thread Starter
af3
(@af3)
For whatever reason, this seemingly straight fwd get_post_meta function keeps returning empty $post_ID , any ideas?
/* WP Telegram - modify post URL */
add_filter( 'wptelegram_p2tg_post_data_full_url_value', function ( $url, $post ) {
if ('wpsc_ticket_thread' === $post->post_type ) {
$post_ID = get_post_meta($post->ID,'ticket_id',true);
// Get the URL somehow.
$url = get_permalink( $post_ID );
}
return $url;
}, 10, 2 );
/* WP Telegram - modify post URL */
Thread Starter
af3
(@af3)
Just for those using SC, if you add delay in WP Telegram setting for 1 min, the above should now work ..