PluginProbe
Cool Timeline (Horizontal & Vertical Timeline) / trunk
Cool Timeline (Horizontal & Vertical Timeline) vtrunk
3.4.0 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 2.2.3 2.3.3 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.6.1 2.7.1 2.8.3 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 All 79 releases
cool-timeline / admin / class.cool-timeline-posttype.php

class.cool-timeline-posttype.php in Cool Timeline (Horizontal & Vertical Timeline) trunk, at admin/class.cool-timeline-posttype.php

160 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly.
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6 class CoolTimelinePosttypeFree {
7
8 /**
9 * Registers our plugin with WordPress.
10 */
11 public static function register() {
12 $postTypeCls = new self();
13 // register hooks
14 add_action( 'init', array( $postTypeCls, 'cooltimeline_custom_post_type' ) );
15 add_filter( 'manage_edit-cool_timeline_columns', array( $postTypeCls, 'add_new_cool_timeline_columns' ) );
16 add_action( 'manage_cool_timeline_posts_custom_column', array( $postTypeCls, 'ctl_custom_columns' ), 10, 2 );
17 add_filter( 'display_post_states', array( $postTypeCls, 'ctl_generted_page_label' ) );
18 // custom message in publish metabox
19 add_action( 'post_submitbox_misc_actions', array( $postTypeCls, 'ctl_submitbox_metabox' ) );
20 }
21
22 // Register Cool Timeline Post Type
23 public function cooltimeline_custom_post_type() {
24 $labels = array(
25 'name' => _x( 'Timeline Stories', 'Post Type General Name', 'cool-timeline' ),
26 'singular_name' => _x( 'Timeline Stories', 'Post Type Singular Name', 'cool-timeline' ),
27 'menu_name' => __( 'Timeline Stories', 'cool-timeline' ),
28 'name_admin_bar' => __( 'Timeline Stories', 'cool-timeline' ),
29 'parent_item_colon' => __( 'Parent Item:', 'cool-timeline' ),
30 'all_items' => __( 'Cool Timeline Stories', 'cool-timeline' ),
31 'add_new_item' => __( 'Add New Story', 'cool-timeline' ),
32 'add_new' => __( 'Add New', 'cool-timeline' ),
33 'new_item' => __( 'New Story', 'cool-timeline' ),
34 'edit_item' => __( 'Edit Story', 'cool-timeline' ),
35 'update_item' => __( 'Update Story', 'cool-timeline' ),
36 'view_item' => __( 'View Story', 'cool-timeline' ),
37 'search_items' => __( 'Search Story', 'cool-timeline' ),
38 'not_found' => __( 'Not found', 'cool-timeline' ),
39 'not_found_in_trash' => __( 'Not found in Trash', 'cool-timeline' ),
40 );
41 $args = array(
42 'label' => __( 'cool_timeline', 'cool-timeline' ),
43 'description' => __( 'Timeline Post Type Description', 'cool-timeline' ),
44 'labels' => $labels,
45 'supports' => array( 'title', 'editor', 'thumbnail' ),
46 'taxonomies' => array(),
47 'hierarchical' => false,
48 'public' => true,
49 'show_ui' => true,
50 // Show as a submenu under the shared "Timeline Addons" top-level menu.
51 'show_in_menu' => 'cool-plugins-timeline-addon',
52 'menu_position' => 5,
53 'show_in_admin_bar' => true,
54 'show_in_nav_menus' => true,
55 'can_export' => true,
56 'has_archive' => true,
57 'exclude_from_search' => false,
58 // 'show_in_rest' => true,
59 'publicly_queryable' => true,
60 'capability_type' => 'page',
61 'menu_icon' => CTL_PLUGIN_URL . 'assets/images/timeline-icon-small.png',
62 );
63 register_post_type( 'cool_timeline', $args );
64 }
65
66 // custom columns for all stories
67 public function add_new_cool_timeline_columns( $columns ) {
68 unset( $columns );
69
70 $new_columns['cb'] = '<input type="checkbox" />';
71 $new_columns['title'] = _x( 'Story Title', 'column name', 'cool-timeline' );
72 $new_columns['story_year'] = __( 'Story Year', 'cool-timeline' );
73 $new_columns['story_date'] = __( 'Story Date', 'cool-timeline' );
74 $new_columns['icon'] = __( 'Story Icon', 'cool-timeline' );
75 $new_columns['date'] = _x( 'Published Date', 'column name', 'cool-timeline' );
76 return $new_columns;
77 }
78
79 // clt column handlers
80 public function ctl_custom_columns( $column, $post_id ) {
81 $ctl_story_type = get_post_meta( $post_id, 'story_type', true );
82 $ctl_story_date = ( is_array( $ctl_story_type ) && isset( $ctl_story_type['ctl_story_date'] ) )
83 ? sanitize_text_field( $ctl_story_type['ctl_story_date'] )
84 : '';
85 switch ( $column ) {
86 case 'story_year':
87 $story_timestamp = strtotime( $ctl_story_date );
88 if ( $story_timestamp !== false ) {
89 $story_year = gmdate( 'Y', $story_timestamp );
90 echo '<p><strong>' . esc_html( $story_year ) . '</strong></p>'; // Escape output
91 } else {
92 $ctl_story_date = trim( str_ireplace( array( 'am', 'pm' ), '', $ctl_story_date ) );
93 $dateobj = DateTime::createFromFormat( 'm/d/Y H:i', $ctl_story_date, wp_timezone() );
94 if ( $dateobj ) {
95 echo '<p><strong>' . wp_kses_post( $dateobj->format( __( 'Y', 'cool-timeline' ) ) ) . '</strong></p>';
96 }
97 }
98 break;
99 case 'story_date':
100 echo '<p><strong>' . esc_html( $ctl_story_date ) . '</strong></p>'; // Escape output
101 break;
102 case 'icon':
103 $icon = get_post_meta( $post_id, 'story_icon', true );
104 $icon = isset( $icon['fa_field_icon'] ) ? sanitize_text_field( $icon['fa_field_icon'] ) : ''; // Sanitize input
105 if ( $icon ) {
106 echo '<i style="font-size:32px;" class="' . esc_attr( $icon ) . '" aria-hidden="true"></i>'; // Escape output
107 } else {
108 echo '<i style="font-size:32px;" class="fa fa-clock-o" aria-hidden="true"></i>';
109 }
110 break;
111 default:
112 echo '<p>' . esc_html__( 'Not Matched', 'cool-timeline' ) . '</p>'; // Escape output and allow translation
113 }
114 }
115
116 public function ctl_generted_page_label( $states ) {
117 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
118 if ( isset( $_REQUEST['post_type'] ) && sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ) == 'cool_timeline' ) {
119 unset( $states['scheduled'] );
120 }
121 return $states;
122 }
123
124 public function ctl_submitbox_metabox() {
125
126 $is_cool_timeline = false;
127
128 // phpcs:disable WordPress.Security.NonceVerification.Recommended
129 if ( isset( $_GET['post'] ) ) {
130 $post_id = intval( wp_unslash( $_GET['post'] ) );
131
132 if ( 'cool_timeline' === get_post_type( $post_id ) ) {
133 $is_cool_timeline = true;
134 }
135 }
136
137 if ( isset( $_GET['post_type'] ) ) {
138 $post_type = sanitize_text_field( wp_unslash( $_GET['post_type'] ) );
139
140 if ( 'cool_timeline' === $post_type ) {
141 $is_cool_timeline = true;
142 }
143 }
144 // phpcs:enable WordPress.Security.NonceVerification.Recommended
145
146 if ( $is_cool_timeline ) {
147 ?>
148 <div class="misc-pub-section ctl-notice">
149 <span style="font-weight:bold;">
150 <?php esc_html_e( '*Please select story Date / Year from settings below the story content.', 'cool-timeline' ); ?>
151 <a href="#ctl_post_meta"><br/>- <?php esc_html_e( 'Timeline Story Settings (Date/Year)', 'cool-timeline' ); ?></a>
152 </span>
153 </div>
154 <?php
155 }
156 }
157
158 }
159 CoolTimelinePosttypeFree::register();
160