PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.41
Post Grid Gutenberg Blocks – PostX v5.0.41
5.0.41 5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 All 238 releases
ultimate-post / addons / templates / Saved_Templates.php

Saved_Templates.php in Post Grid Gutenberg Blocks – PostX 5.0.41, at addons/templates/Saved_Templates.php

103 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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