| 1 |
<?php |
| 2 |
|
| 3 |
namespace ULTP; |
| 4 |
|
| 5 |
use ULTP\Includes\Durbin\Xpo; |
| 6 |
|
| 7 |
defined( 'ABSPATH' ) || exit; |
| 8 |
|
| 9 |
class Saved_Templates { |
| 10 |
public function __construct() { |
| 11 |
$this->templates_post_type_callback(); |
| 12 |
add_action( 'admin_head', array( $this, 'custom_head_templates' ) ); |
| 13 |
add_action( 'load-post-new.php', array( $this, 'disable_new_post_templates' ) ); |
| 14 |
add_filter( 'manage_ultp_templates_posts_columns', array( $this, 'templates_table_head' ) ); |
| 15 |
add_action( 'manage_ultp_templates_posts_custom_column', array( $this, 'templates_table_content' ), 10, 2 ); |
| 16 |
} |
| 17 |
|
| 18 |
public function custom_head_templates() { |
| 19 |
if ( 'ultp_templates' == get_current_screen()->post_type && ( ! defined( 'ULTP_PRO_VER' ) ) ) { |
| 20 |
$post_count = wp_count_posts( 'ultp_templates' ); |
| 21 |
$post_count = $post_count->publish + $post_count->draft; |
| 22 |
if ( $post_count > 0 ) { ?> |
| 23 |
<span class="ultp-saved-templates-action" data-link=" |
| 24 |
<?php |
| 25 |
echo esc_url( |
| 26 |
Xpo::generate_utm_link( |
| 27 |
array( |
| 28 |
'utmKey' => 'post_type_page', |
| 29 |
) |
| 30 |
) |
| 31 |
); |
| 32 |
?> |
| 33 |
" data-text="Go Pro for Unlimited Templates" data-count="<?php echo esc_attr( $post_count ); ?>" style="display:none;"></span> |
| 34 |
<?php |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
public function disable_new_post_templates() { |
| 40 |
if ( get_current_screen()->post_type == 'ultp_templates' && ( ! defined( 'ULTP_PRO_VER' ) ) ) { |
| 41 |
$post_count = wp_count_posts( 'ultp_templates' ); |
| 42 |
$post_count = $post_count->publish + $post_count->draft; |
| 43 |
if ( $post_count > 0 ) { |
| 44 |
wp_die( |
| 45 |
'You cannot do that! Only one template can be created in the free version. Please <a target="_blank" href="' . esc_url( |
| 46 |
Xpo::generate_utm_link( |
| 47 |
array( |
| 48 |
'utmKey' => 'post_type_page', |
| 49 |
) |
| 50 |
) |
| 51 |
) . '">Upgrade Pro.</a>' |
| 52 |
); |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
// Template Heading Add |
| 58 |
public function templates_table_head( $defaults ) { |
| 59 |
$type_array = array( 'type' => __( 'Shortcode', 'ultimate-post' ) ); |
| 60 |
array_splice( $defaults, 2, 0, $type_array ); |
| 61 |
return $defaults; |
| 62 |
} |
| 63 |
|
| 64 |
// Column Content |
| 65 |
public function templates_table_content( $column_name, $post_id ) { |
| 66 |
echo '<code class="ultp-shortcode-copy">[postx_template id="' . esc_attr( $post_id ) . '"]</code>'; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
// Templates Post Type Register |
| 71 |
public function templates_post_type_callback() { |
| 72 |
$labels = array( |
| 73 |
'name' => _x( 'Saved Templates', 'Templates', 'ultimate-post' ), |
| 74 |
'singular_name' => _x( 'Saved Template', 'Templates', 'ultimate-post' ), |
| 75 |
'menu_name' => __( 'Saved Templates', 'ultimate-post' ), |
| 76 |
'parent_item_colon' => __( 'Parent Template', 'ultimate-post' ), |
| 77 |
'all_items' => __( 'Saved Templates', 'ultimate-post' ), |
| 78 |
'view_item' => __( 'View Template', 'ultimate-post' ), |
| 79 |
'add_new_item' => __( 'Add New Template', 'ultimate-post' ), |
| 80 |
'add_new' => __( 'Add New Template', 'ultimate-post' ), |
| 81 |
'edit_item' => __( 'Edit Template', 'ultimate-post' ), |
| 82 |
'update_item' => __( 'Update Template', 'ultimate-post' ), |
| 83 |
'search_items' => __( 'Search Template', 'ultimate-post' ), |
| 84 |
'not_found' => __( 'No Template Found', 'ultimate-post' ), |
| 85 |
'not_found_in_trash' => __( 'Not Template found in Trash', 'ultimate-post' ), |
| 86 |
); |
| 87 |
$args = array( |
| 88 |
'labels' => $labels, |
| 89 |
'show_in_rest' => true, |
| 90 |
'supports' => array( 'title', 'editor' ), |
| 91 |
'hierarchical' => false, |
| 92 |
'public' => false, |
| 93 |
'rewrite' => false, |
| 94 |
'show_ui' => true, |
| 95 |
'show_in_menu' => false, |
| 96 |
'show_in_nav_menus' => false, |
| 97 |
'exclude_from_search' => true, |
| 98 |
'capability_type' => 'page', |
| 99 |
); |
| 100 |
register_post_type( 'ultp_templates', $args ); |
| 101 |
} |
| 102 |
} |
| 103 |
|