post_type ) ) { return; } $values = get_post_custom( $post->ID ); $selected = isset( $values['es_template_type'] ) ? esc_attr( $values['es_template_type'][0] ) : ''; $template_type = ES_Common::get_campaign_types( array( 'sequence' ) ); ?>
{{subscriber.first_name | fallback:'there'}}, {{subscriber.last_name}}, {{subscriber.name}}, {{subscriber.email}}, {{post.date}}, {{post.title}}, {{post.image}}, {{post.excerpt}}, {{post.description}}, {{post.author}}, {{post.author_avatar}}, {{post.author_avatar_url}}, {{post.link}}, {{post.link_with_title}}, {{post.link_only}}, {{post.full}}
';
$es_template_thumbnail = apply_filters( 'ig_es_template_thumbnail', $es_template_thumbnail );
$es_template_thumbnail = ( ! empty( $es_template_thumbnail ) ) ? $es_template_thumbnail : $default_template_thumbnail;
switch ( $column ) {
case 'es_template_type':
$type = get_post_meta( $post->ID, 'es_template_type', true );
$type = sanitize_text_field( strtolower( $type ) );
$type = ( 'newsletter' === $type ) ? __( 'Broadcast', 'email-subscribers' ) : $type;
$type = ucwords( str_replace( '_', ' ', $type ) );
echo esc_html( $type );
break;
case 'es_template_thumbnail':
echo wp_kses_post( $es_template_thumbnail );
break;
default:
break;
}
return $column;
}
public function add_template_action( $actions, $post ) {
if ( 'es_template' !== $post->post_type ) {
return $actions;
}
$nonce = wp_create_nonce( 'ig_es_duplicate_template_nonce' );
$actions['duplicate_template'] = '' . __( 'Duplicate', 'email-subscribers' ) . '';
return $actions;
}
public function duplicate_template() {
$action = ig_es_get_request_data( 'action' );
$template_id = ig_es_get_request_data( 'template_id' );
if ( ! empty( $template_id ) && 'duplicate-template' === $action ) {
check_admin_referer( 'ig_es_duplicate_template_nonce' );
// duplicate tempalte
$this->duplicate_in_db( $template_id );
// $location = admin_url( 'post.php?post='.$duplicate_template_id.'&action=edit');
$location = admin_url( 'edit.php?post_type=es_template' );
wp_safe_redirect( $location );
exit;
}
}
public function duplicate_in_db( $original_id ) {
// Get access to the database
global $wpdb;
// Get the post as an array
$duplicate = get_post( $original_id, 'ARRAY_A' );
// Modify some of the elements
$duplicate['post_title'] = $duplicate['post_title'] . ' ' . __( 'Copy', 'email-subscribers' );
$duplicate['post_status'] = 'draft';
// Set the post date
$timestamp = current_time( 'timestamp', 0 );
$duplicate['post_date'] = gmdate( 'Y-m-d H:i:s', $timestamp );
// Remove some of the keys
unset( $duplicate['ID'] );
unset( $duplicate['guid'] );
unset( $duplicate['comment_count'] );
$current_user_id = get_current_user_id();
if ( ! empty( $current_user_id ) ) {
// Set post author to current logged in author.
$duplicate['post_author'] = $current_user_id;
}
// Insert the post into the database
$duplicate_id = wp_insert_post( $duplicate );
// Duplicate all taxonomies/terms
$taxonomies = get_object_taxonomies( $duplicate['post_type'] );
foreach ( $taxonomies as $taxonomy ) {
$terms = wp_get_post_terms( $original_id, $taxonomy, array( 'fields' => 'names' ) );
wp_set_object_terms( $duplicate_id, $terms, $taxonomy );
}
// Duplicate all custom fields
$custom_fields = get_post_custom( $original_id );
foreach ( $custom_fields as $key => $value ) {
add_post_meta( $duplicate_id, $key, maybe_unserialize( $value[0] ) );
}
return $duplicate_id;
}
/**
* Exclude DND Templates from template list
*
* @since 4.5.3
*/
public static function exclude_dnd_templates( $wp_query ) {
global $pagenow;
if ( 'edit.php' !== $pagenow || empty( $wp_query->query_vars['post_type'] ) ||'es_template' !== $wp_query->query_vars['post_type'] ) {
return;
}
$wp_query->query_vars['meta_query'] = array(
'relation' => 'OR',
array(
'key' => 'es_editor_type',
'value' => IG_ES_CLASSIC_EDITOR,
'compare' => '=',
),
array(
'key' => 'es_editor_type',
'compare' => 'NOT EXISTS', // if key doesn't exists, then template is created using Classic editor
),
);
}
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
}