/**
 * Adjust post links for embedded Views.
 *
 * Currently only CT edit links are supported. See icl_post_link filter for parameter description.
 *
 * @param $link
 * @param $post_type
 * @param $post_id
 * @param $link_purpose
 * @return array
 *
 * @since 1.10
 */
function wpv_embedded_post_link($link, $post_type, $post_id, $link_purpose)
{
    global $WP_Views;
    // Skip if we're in full Views
    if ($WP_Views->is_embedded()) {
        if (!is_array($link)) {
            $link = array();
        }
        switch ($post_type) {
            // Content Templates
            case WPV_Content_Template_Embedded::POST_TYPE:
                if ('edit' == $link_purpose) {
                    // Content Template edit page
                    // Check that CT exists and is not trashed.
                    $ct = WPV_Content_Template_Embedded::get_instance($post_id);
                    if (null == $ct || $ct->is_trashed) {
                        $link['is_disabled'] = true;
                    } else {
                        // Generate the URL to the read-only page.
                        $link['is_disabled'] = false;
                        $link['url'] = esc_url(add_query_arg(array('page' => 'view-templates-embedded', 'view_id' => $post_id), admin_url('admin.php')));
                    }
                }
                break;
        }
    }
    return $link;
}
 /**
  * Get a Content Template by it's name.
  *
  * See get_template_id_by_name() for details.
  *
  * @param string $post_name Content Template name.
  * @return null|WPV_Content_Template_Embedded Content Template or null if it wasn't found or couldn't be loaded.
  *
  * @since 1.9
  */
 static function get_template_by_name( $post_name ) {
     return WPV_Content_Template_Embedded::get_instance( WPV_Content_Template_Embedded::get_template_id_by_name( $post_name ) );
 }