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

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