PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.17
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.17
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / admin / class-smart-post-show-admin.php

class-smart-post-show-admin.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 2.4.17, at admin/class-smart-post-show-admin.php

234 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The admin-specific functionality of the plugin.
4 *
5 * @link https://smartpostshow.com/
6 * @since 2.2.0
7 *
8 * @package Smart_Post_Show
9 * @subpackage Smart_Post_Show/admin
10 */
11
12 /**
13 * The admin-specific functionality of the plugin.
14 *
15 * Defines the plugin name, version, and two examples hooks for how to
16 * enqueue the admin-specific stylesheet and JavaScript.
17 */
18 class Smart_Post_Show_Admin {
19
20 /**
21 * Script and style suffix
22 *
23 * @since 2.2.0
24 * @access protected
25 * @var string
26 */
27 protected $suffix;
28
29 /**
30 * Initialize the class and set its properties.
31 *
32 * @since 2.2.0
33 * @param string $plugin_name The name of this plugin.
34 * @param string $version The version of this plugin.
35 */
36 public function __construct( $plugin_name, $version ) {
37
38 $this->suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'WP_DEBUG' ) && WP_DEBUG ? '' : '.min';
39 $this->plugin_name = $plugin_name;
40 $this->version = $version;
41
42 // Autoload system.
43 spl_autoload_register( array( $this, 'autoload' ) );
44 SPS_Metaboxes::preview_metabox( 'sp_pcp_display' );
45 SPS_Metaboxes::layout_metabox( 'sp_pcp_layouts' );
46
47 SPS_Metaboxes::option_metabox( 'sp_pcp_view_options' );
48 SPS_Metaboxes::shortcode_metabox( 'sp_pcp_display_shortcode' );
49 SPS_Settings::settings( 'sp_post_carousel_settings' );
50 SPS_ReplaceLayout::Replace_Layout( 'sp_post_carousel_rpl' );
51 SPS_Tools::tools( 'sp_post_carousel_tools' );
52 // Plugin action link Button.
53 add_filter( 'plugin_action_links', array( $this, 'add_plugin_action_links' ), 10, 2 );
54 }
55
56 /**
57 * Add plugin action menu
58 *
59 * @param array $links The action link.
60 * @param array $file The file link.
61 *
62 * @return array
63 */
64 public function add_plugin_action_links( $links, $file ) {
65 if ( SMART_POST_SHOW_BASENAME === $file ) {
66 $new_links = array(
67 sprintf( '<a href="%s">%s</a>', admin_url( 'edit.php?post_type=sp_post_carousel' ), __( 'Manage Shows', 'post-carousel' ) ),
68 );
69 $links['go_pro'] = sprintf( '<a href="%s" target="_blank" style="%s">%s</a>', 'https://smartpostshow.com/', 'color:#1dab87;font-weight:bold', __( 'Go Pro!', 'post-carousel' ) );
70 return array_merge( $new_links, $links );
71 }
72 return $links;
73 }
74
75 /**
76 * Add plugin row meta link
77 *
78 * @param [array] $plugin_meta Add plugin row meta link.
79 * @param [url] $file plugin row meta link.
80 * @return array
81 */
82 public function after_pcp_row_meta( $plugin_meta, $file ) {
83 if ( SMART_POST_SHOW_BASENAME == $file ) {
84 $plugin_meta[] = '<a href="https://smartpostshow.com/demo/" target="_blank">' . __( 'Live Demo', 'post-carousel' ) . '</a>';
85 $plugin_meta[] = '<a href="https://docs.shapedplugin.com/docs/post-carousel/overview/" target="_blank">' . __( 'Documentation', 'post-carousel' ) . '</a>';
86 $plugin_meta[] = '<a href="https://shapedplugin.com/support/?user=lite" target="_blank">' . __( 'Support', 'post-carousel' ) . '</a>';
87 }
88 return $plugin_meta;
89 }
90 /**
91 * Autoload class files on demand
92 *
93 * @param string $class requested class name.
94 * @since 2.2.0
95 */
96 private function autoload( $class ) {
97 $name = explode( '_', $class );
98 if ( isset( $name[1] ) ) {
99 $class_name = strtolower( $name[1] );
100 $pcp_config_paths = array( 'views/', 'views/configs/settings/', 'views/configs/generator/' );
101 foreach ( $pcp_config_paths as $sp_ppc_path ) {
102 $filename = plugin_dir_path( __FILE__ ) . '/' . $sp_ppc_path . 'class-sps-' . $class_name . '.php';
103 if ( file_exists( $filename ) ) {
104 require_once $filename;
105 }
106 }
107 }
108 }
109
110 /**
111 * Register the stylesheets for the admin area.
112 *
113 * @since 2.2.0
114 */
115 public function enqueue_styles() {
116 $current_screen = get_current_screen();
117 $the_current_post_type = $current_screen->post_type;
118 if ( 'sp_post_carousel' === $the_current_post_type ) {
119 wp_enqueue_style( 'pcp-font-awesome', SP_PC_URL . 'public/assets/css/font-awesome.min.css', array(), SP_PC_VERSION, 'all' );
120 wp_enqueue_style( 'pcp_swiper', SP_PC_URL . 'public/assets/css/swiper-bundle' . $this->suffix . '.css', array(), SP_PC_VERSION, 'all' );
121 wp_enqueue_style( 'pcp-style', SP_PC_URL . 'public/assets/css/style' . $this->suffix . '.css', array(), SP_PC_VERSION, 'all' );
122 }
123 wp_enqueue_style( 'sp-' . SP_PC_PLUGIN_NAME, SP_PC_URL . 'admin/assets/css/post-carousel-admin' . $this->suffix . '.css', array(), SP_PC_VERSION, 'all' );
124 }
125
126 /**
127 * Register the JavaScript for the admin area.
128 *
129 * @since 2.2.0
130 */
131 public function enqueue_scripts() {
132
133 /**
134 * This function is provided for demonstration purposes only.
135 *
136 * An instance of this class should be passed to the run() function
137 * defined in Smart_Post_Show_Loader as all of the hooks are defined
138 * in that particular class.
139 *
140 * The Smart_Post_Show_Loader will then create the relationship
141 * between the defined hooks and the functions defined in this
142 * class.
143 */
144 $current_screen = get_current_screen();
145 $the_current_post_type = $current_screen->post_type;
146 if ( 'sp_post_carousel' === $the_current_post_type ) {
147 wp_enqueue_script( SP_PC_PLUGIN_NAME, SP_PC_URL . 'admin/assets/js/post-carousel-admin' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true );
148 wp_enqueue_script( 'pcp_swiper', SP_PC_URL . 'public/assets/js/swiper-bundle' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true );
149 wp_enqueue_script( 'pcp_script', SP_PC_URL . 'public/assets/js/scripts' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true );
150 }
151
152 }
153
154 /**
155 * Add carousel admin columns.
156 *
157 * @since 2.2.0
158 * @return statement
159 */
160 public function filter_carousel_admin_column() {
161 $admin_columns['cb'] = '<input type="checkbox" />';
162 $admin_columns['title'] = __( 'Title', 'post-carousel' );
163 $admin_columns['shortcode'] = __( 'Shortcode', 'post-carousel' );
164 $admin_columns['pcp_layout'] = __( 'Layout', 'post-carousel' );
165 $admin_columns['date'] = __( 'Date', 'post-carousel' );
166
167 return $admin_columns;
168 }
169
170 /**
171 * Display admin columns for the carousels.
172 *
173 * @param mix $column The columns.
174 * @param string $post_id The post ID.
175 * @return void
176 */
177 public function display_carousel_admin_fields( $column, $post_id ) {
178 $pcp_layouts = get_post_meta( $post_id, 'sp_pcp_layouts', true );
179 $carousels_types = isset( $pcp_layouts['pcp_layout_preset'] ) ? $pcp_layouts['pcp_layout_preset'] : '';
180 switch ( $column ) {
181 case 'shortcode':
182 ?>
183 <input class="sp_pcp_input" style="width: 230px;padding: 4px 8px;cursor: pointer;" type="text" onClick="this.select();" readonly="readonly" value="[smart_post_show id=&quot;<?php echo esc_attr( $post_id ); ?>&quot;]"/> <div class="pcp-after-copy-text"><i class="fa fa-check-circle"></i> <?php esc_html_e( 'Shortcode Copied to Clipboard!', 'post-carousel' ); ?></div>
184 <?php
185 break;
186 case 'pcp_layout':
187 $layout = ucwords( str_replace( '_layout', ' ', $carousels_types ) );
188 esc_html_e( $layout, 'post-carousel' );
189 } // end switch.
190 }
191
192 /**
193 * Sp_post_carousel post type Save and update alert in Admin Dashboard created by Post carousel Pro
194 *
195 * @param array $messages alert messages.
196 */
197 public function sppcp_update( $messages ) {
198 global $post, $post_ID;
199 $messages['sp_post_carousel'][1] = __( 'Shortcode Updated', 'post-carousel' );
200 $messages['sp_post_carousel'][6] = __( 'Shortcode Published', 'post-carousel' );
201 return $messages;
202 }
203
204 /**
205 * Redirect after active
206 *
207 * @param string $plugin The plugin help page.
208 */
209 public function redirect_help_page( $plugin ) {
210 if ( SMART_POST_SHOW_BASENAME === $plugin ) {
211 wp_safe_redirect( admin_url( 'edit.php?post_type=sp_post_carousel&page=pcp_help' ) );
212 exit();
213 }
214 }
215 /**
216 * If it is the plugins page.
217 *
218 * @since 2.2.0
219 * @access private
220 */
221 private function is_plugins_screen() {
222 return in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true );
223 }
224 }
225
226 /**
227 * Smart Post Show dashboard capability.
228 *
229 * @return string
230 */
231 function sp_pc_dashboard_capability() {
232 return apply_filters( 'sp_pc_dashboard_capability', 'manage_options' );
233 }
234