PluginProbe ʕ •ᴥ•ʔ
DearFlip – PDF Flipbook, 3D Flipbook, PDF embed, PDF viewer / 2.2.41
DearFlip – PDF Flipbook, 3D Flipbook, PDF embed, PDF viewer v2.2.41
2.4.30 trunk 1.7.16 1.7.35 2.0.86 2.2.32 2.2.39 2.2.41 2.2.47 2.2.54 2.2.55 2.2.56 2.3.24 2.3.32 2.3.52 2.3.53 2.3.54 2.3.55 2.3.57 2.3.74 2.3.75 2.4.20 2.4.27
3d-flipbook-dflip-lite / inc / post-type.php
3d-flipbook-dflip-lite / inc Last commit date
index.php 2 years ago metaboxes.php 2 years ago post-type.php 2 years ago settings.php 2 years ago shortcode.php 2 years ago
post-type.php
262 lines
1 <?php
2
3 /**
4 * dFlip CUSTOM POST
5 *
6 * Initializes and Registers the required custom post for dFlip
7 *
8 * @since 1.0.0
9 *
10 * @package dFlip
11 * @author Deepak Ghimire
12 */
13 class DFlip_Post_Type {
14
15 /**
16 * Holds the singleton class object.
17 *
18 * @since 1.0.0
19 *
20 * @var object
21 */
22 public static $instance;
23
24 /**
25 * Holds the base DFlip class object.
26 *
27 * @since 1.0.0
28 *
29 * @var object
30 */
31 public $base;
32
33 /**
34 * Primary class constructor.
35 *
36 * @since 1.0.0
37 */
38 public function __construct() {
39
40 // Load the base class object.
41 $this->base = DFlip::get_instance();
42
43 $labels = array(
44 'name' => __( 'dFlip Book', '3d-flipbook-dflip-lite' ),
45 'singular_name' => __( 'dFlip Book', '3d-flipbook-dflip-lite' ),
46 'menu_name' => __( 'dFlip Books', '3d-flipbook-dflip-lite' ),
47 'name_admin_bar' => __( 'dFlip Book', '3d-flipbook-dflip-lite' ),
48 'add_new' => __( 'Add New Book', '3d-flipbook-dflip-lite' ),
49 'add_new_item' => __( 'Add New Book', '3d-flipbook-dflip-lite' ),
50 'new_item' => __( 'New dFlip Book', '3d-flipbook-dflip-lite' ),
51 'edit_item' => __( 'Edit dFlip Book', '3d-flipbook-dflip-lite' ),
52 'view_item' => __( 'View dFlip Book', '3d-flipbook-dflip-lite' ),
53 'all_items' => __( 'All Books', '3d-flipbook-dflip-lite' ),
54 'search_items' => __( 'Search dFlip Books', '3d-flipbook-dflip-lite' ),
55 'parent_item_colon' => __( 'Parent dFlip Books:', '3d-flipbook-dflip-lite' ),
56 'not_found' => __( 'No dFlip-Books found.', '3d-flipbook-dflip-lite' ),
57 'not_found_in_trash' => __( 'No dFlip Books found in Trash.', '3d-flipbook-dflip-lite' )
58 );
59
60 $args = array(
61 'labels' => $labels,
62 'description' => __( 'Description.', '3d-flipbook-dflip-lite' ),
63 'public' => false, //this removes the permalink option
64 'publicly_queryable' => false,
65 'show_ui' => true,
66 'show_in_menu' => true,
67 'query_var' => true,
68 'rewrite' => false, //array('slug' => $this->base->slug),
69 'capability_type' => 'post',
70 'has_archive' => true,
71 'hierarchical' => false,
72 'menu_position' => null,
73 'menu_icon' => 'dashicons-book',
74 'supports' => array( 'title', 'editor', 'revisions' )
75 );
76
77 register_post_type( 'dflip', $args );
78
79 register_taxonomy( 'dflip_category', 'dflip', array(
80 'hierarchical' => true,
81 'public' => true,
82 'show_ui' => true,
83 'show_admin_column' => true,
84 'show_in_nav_menus' => true,
85 'rewrite' => array( 'slug' => 'dflip_category' ),
86 ) );
87
88 if ( is_admin() ) {
89 $this->init_admin();
90 }
91
92 add_filter( 'the_content', array( $this, 'filter_the_pdf_attachment_content' ) );
93 }
94
95 /**
96 * Loads all admin related files into scope.
97 *
98 * @since 1.0.0
99 */
100 public function init_admin() {
101
102 // Remove quick editing from the dFlip post type row actions.
103 add_filter( 'post_row_actions', array( $this, 'remove_quick_edit' ), 10, 1 );
104
105 // Manage post type columns.
106 add_filter( 'manage_dflip_posts_columns', array( $this, 'dflip_columns' ) );
107 add_action( 'manage_dflip_posts_custom_column', array( $this, 'dflip_columns_content' ), 10, 2 );
108
109 add_filter( 'manage_edit-dflip_category_columns', array( $this, 'dflip_cat_columns' ) );
110 add_filter( 'manage_dflip_category_custom_column', array( $this, 'dflip_cat_columns_content' ), 10, 3 );
111
112 //Optimize the icons for retina display
113 add_action( 'admin_head', array( $this, 'menu_icon' ) );
114
115 }
116
117
118 /**
119 * Filter out unnecessary row actions dFlip post table.
120 *
121 * @param array $actions Default row actions.
122 *
123 * @return array $actions Amended row actions.
124 * @since 1.0.0
125 *
126 */
127 public function remove_quick_edit( $actions ) {
128 if ( isset( get_current_screen()->post_type ) && 'dflip' == get_current_screen()->post_type ) {
129 unset( $actions['inline hide-if-no-js'] );
130 }
131
132 return $actions;
133 }
134
135 /**
136 * Customize the post columns for the dFlip post type.
137 *
138 * @return array $columns New Updated columns.
139 * @since 1.0.0
140 *
141 */
142 public function dflip_columns( $columns ) {
143
144 $columns['shortcode'] = __( 'Shortcode', '3d-flipbook-dflip-lite' );
145 $columns['modified'] = __( 'Last Modified', '3d-flipbook-dflip-lite' );
146
147 return $columns;
148 }
149
150 /**
151 * Customize the post columns for the dFlip post type category page
152 *
153 * @param array $defaults columns.
154 *
155 * @return array $defaults default columns.
156 * @since 1.2.9
157 *
158 */
159 public function dflip_cat_columns( $defaults ) {
160 $defaults['shortcode'] = 'Shortcode';
161
162 return $defaults;
163 }
164
165 /**
166 * Add data to the custom columns added to the dFlip post type.
167 *
168 * @param string $column_name Name of the custom column.
169 * @param int $post_id Current post ID.
170 *
171 * @since 1.0.0
172 *
173 */
174 public function dflip_columns_content( $column_name, $post_id ) {
175 $post_id = absint( $post_id );
176
177 switch ( $column_name ) {
178 case 'shortcode':
179 echo '<code>[dflip id="' . esc_attr( $post_id ) . '"][/dflip]</code>';
180 break;
181
182 case 'modified' :
183 the_modified_date();
184 break;
185 }
186 }
187
188 /**
189 * Add data to the custom columns added to the dFlip post type category page.
190 *
191 * @param $c
192 * @param string $column_name Name of the custom column.
193 * @param $term_id
194 *
195 * @return string
196 * @since 1.2.9
197 *
198 */
199 public function dflip_cat_columns_content( $c, $column_name, $term_id = "" ) {
200
201 return '<code>[dflip books="' . get_term( $term_id, 'dflip_category' )->slug . '" limit="-1"][/dflip]</code>';
202
203 }
204
205
206 /**
207 * Forces the dFlip menu icon width/height for Retina devices.
208 *
209 * @since 1.0.0
210 */
211 public function menu_icon() {
212
213 ?>
214 <style type="text/css">#menu-posts-dflip .wp-menu-image img { width: 16px; height: 16px; }</style>
215 <?php
216
217 }
218
219 public function filter_the_pdf_attachment_content( $content ) {
220 global $post;
221
222
223 // Check if we're inside the main loop in a single post page.
224 if ( is_single() && in_the_loop() && is_main_query() && $post->post_mime_type == "application/pdf" ) {
225 $html = "";
226 $lightbox = $this->base->get_config( 'attachment_lightbox' );
227
228 if ( $lightbox == 'true' ) {
229 $html = do_shortcode( '[dflip attachment_pdf_flipbook_lightbox="true" type="link" source="' . wp_get_attachment_url( $post->ID ) . '"]Open ' . get_the_title( $post ) . '[/dflip]' );
230 } else {
231 $html = do_shortcode( '[dflip source="' . wp_get_attachment_url( $post->ID ) . '"][/dflip]' );
232 }
233
234 return $html;
235 }
236
237 return $content;
238 }
239
240
241 /**
242 * Returns the singleton instance of the class.
243 *
244 * @return object DFlip_Post_Type object.
245 * @since 1.0.0
246 *
247 */
248 public static function get_instance() {
249
250 if ( !isset( self::$instance ) && !( self::$instance instanceof DFlip_Post_Type ) ) {
251 self::$instance = new DFlip_Post_Type();
252 }
253
254 return self::$instance;
255
256 }
257 }
258
259 // Load the post-type class.
260 $dflip_post_type = DFlip_Post_Type::get_instance();
261
262