PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.2
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.2
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.2, at admin/class-smart-post-show-admin.php

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