| 1 |
<?php |
| 2 |
/** |
| 3 |
* The admin-specific functionality of the plugin. |
| 4 |
* |
| 5 |
* @link https://wpsmartpost.com/ |
| 6 |
* @since 2.2.0 |
| 7 |
* |
| 8 |
* @package Smart_Post_Show |
| 9 |
* @subpackage Smart_Post_Show/admin |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly. |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* The admin-specific functionality of the plugin. |
| 18 |
* |
| 19 |
* Defines the plugin name, version, and two examples hooks for how to |
| 20 |
* enqueue the admin-specific stylesheet and JavaScript. |
| 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 |
* Plugin plugin name |
| 35 |
* |
| 36 |
* @access protected |
| 37 |
* @var string |
| 38 |
*/ |
| 39 |
protected $plugin_name; |
| 40 |
|
| 41 |
/** |
| 42 |
* Plugin version |
| 43 |
* |
| 44 |
* @access protected |
| 45 |
* @var string |
| 46 |
*/ |
| 47 |
protected $version; |
| 48 |
|
| 49 |
/** |
| 50 |
* Initialize the class and set its properties. |
| 51 |
* |
| 52 |
* @since 2.2.0 |
| 53 |
* @param string $plugin_name The name of this plugin. |
| 54 |
* @param string $version The version of this plugin. |
| 55 |
*/ |
| 56 |
public function __construct( $plugin_name, $version ) { |
| 57 |
|
| 58 |
$this->suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'WP_DEBUG' ) && WP_DEBUG ? '' : '.min'; |
| 59 |
$this->plugin_name = $plugin_name; |
| 60 |
$this->version = $version; |
| 61 |
|
| 62 |
// Autoload system. |
| 63 |
spl_autoload_register( array( $this, 'autoload' ) ); |
| 64 |
|
| 65 |
// Register options. |
| 66 |
add_action( 'after_setup_theme', array( $this, 'register_options' ) ); |
| 67 |
|
| 68 |
// Plugin action link Button. |
| 69 |
add_filter( 'plugin_action_links', array( $this, 'add_plugin_action_links' ), 10, 2 ); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Registers various options and settings for the post carousel plugin. |
| 74 |
* |
| 75 |
* This function sets up metaboxes for preview, layout, options, and shortcodes. |
| 76 |
* It also initializes settings, layout replacement, and tools for the plugin. |
| 77 |
* |
| 78 |
* @since 2.2.0 |
| 79 |
*/ |
| 80 |
public function register_options() { |
| 81 |
SPS_Metaboxes::preview_metabox( 'sp_pcp_display' ); |
| 82 |
SPS_Metaboxes::layout_metabox( 'sp_pcp_layouts' ); |
| 83 |
SPS_Metaboxes::option_metabox( 'sp_pcp_view_options' ); |
| 84 |
SPS_Metaboxes::shortcode_metabox( 'sp_pcp_display_shortcode' ); |
| 85 |
SPS_Metaboxes::page_builders_metabox( 'sp_pcp_page_builder_notice' ); |
| 86 |
SPS_Metaboxes::promotional_metabox( 'sp_pcp_promotional_notice' ); |
| 87 |
SPS_Settings::settings( 'sp_post_carousel_settings' ); |
| 88 |
SPS_ReplaceLayout::Replace_Layout( 'sp_post_carousel_rpl' ); |
| 89 |
SPS_Tools::tools( 'sp_post_carousel_tools' ); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Add plugin action menu |
| 94 |
* |
| 95 |
* @param array $links The action link. |
| 96 |
* @param array $file The file link. |
| 97 |
* |
| 98 |
* @return array |
| 99 |
*/ |
| 100 |
public function add_plugin_action_links( $links, $file ) { |
| 101 |
if ( SMART_POST_SHOW_BASENAME === $file ) { |
| 102 |
$new_links = array( |
| 103 |
sprintf( '<a href="%s">%s</a>', admin_url( 'post-new.php?post_type=page&spblock_inserter=true' ), __( 'Explore Blocks', 'post-carousel' ) ), |
| 104 |
); |
| 105 |
$links['go_pro'] = sprintf( '<a href="%s" target="_blank" style="%s">%s</a>', 'https://wpsmartpost.com/', 'color:#1dab87;font-weight:bold', __( 'Go Pro!', 'post-carousel' ) ); |
| 106 |
return array_merge( $new_links, $links ); |
| 107 |
} |
| 108 |
return $links; |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Add plugin row meta link |
| 113 |
* |
| 114 |
* @param [array] $plugin_meta Add plugin row meta link. |
| 115 |
* @param [url] $file plugin row meta link. |
| 116 |
* @return array |
| 117 |
*/ |
| 118 |
public function after_pcp_row_meta( $plugin_meta, $file ) { |
| 119 |
if ( SMART_POST_SHOW_BASENAME == $file ) { |
| 120 |
$plugin_meta[] = '<a href="https://wpsmartpost.com/blocks/" target="_blank">' . __( 'Live Demo', 'post-carousel' ) . '</a>'; |
| 121 |
$plugin_meta[] = '<a href="https://docs.shapedplugin.com/docs/post-carousel/overview/" target="_blank">' . __( 'Documentation', 'post-carousel' ) . '</a>'; |
| 122 |
$plugin_meta[] = '<a href="https://shapedplugin.com/support/?user=lite" target="_blank">' . __( 'Support', 'post-carousel' ) . '</a>'; |
| 123 |
} |
| 124 |
return $plugin_meta; |
| 125 |
} |
| 126 |
/** |
| 127 |
* Autoload class files on demand |
| 128 |
* |
| 129 |
* @param string $class requested class name. |
| 130 |
* @since 2.2.0 |
| 131 |
*/ |
| 132 |
private function autoload( $class ) { |
| 133 |
$name = explode( '_', $class ); |
| 134 |
if ( isset( $name[1] ) ) { |
| 135 |
$class_name = strtolower( $name[1] ); |
| 136 |
$pcp_config_paths = array( 'views/', 'views/configs/settings/', 'views/configs/generator/', 'help-page/' ); |
| 137 |
foreach ( $pcp_config_paths as $sp_ppc_path ) { |
| 138 |
$filename = plugin_dir_path( __FILE__ ) . '/' . $sp_ppc_path . 'class-sps-' . $class_name . '.php'; |
| 139 |
if ( file_exists( $filename ) ) { |
| 140 |
require_once $filename; |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Register the stylesheets for the admin area. |
| 148 |
* |
| 149 |
* @since 2.2.0 |
| 150 |
*/ |
| 151 |
public function enqueue_styles() { |
| 152 |
$current_screen = get_current_screen(); |
| 153 |
$the_current_post_type = $current_screen->post_type; |
| 154 |
$pcp_page_base = 'sp_post_carousel_page_pcp_settings' === $current_screen->base || 'sp_post_carousel_page_pcp_tools' === $current_screen->base || 'sp_post_carousel_page_pcp_replace_layout' === $current_screen->base || 'sp_post_carousel_page_pcp_help' === $current_screen->base; |
| 155 |
|
| 156 |
if ( 'sp_post_carousel' === $the_current_post_type || $pcp_page_base ) { |
| 157 |
wp_enqueue_style( 'font-awesome' ); |
| 158 |
wp_enqueue_style( 'pcp_swiper' ); |
| 159 |
wp_enqueue_style( 'pcp_fonttello_icon' ); |
| 160 |
wp_enqueue_style( 'pcp-style' ); |
| 161 |
} |
| 162 |
wp_enqueue_style( 'sp-' . SP_PC_PLUGIN_NAME, SP_PC_URL . 'admin/assets/css/post-carousel-admin.min.css', array(), SP_PC_VERSION, 'all' ); |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Register the JavaScript for the admin area. |
| 167 |
* |
| 168 |
* @since 2.2.0 |
| 169 |
*/ |
| 170 |
public function enqueue_scripts() { |
| 171 |
|
| 172 |
/** |
| 173 |
* This function is provided for demonstration purposes only. |
| 174 |
* |
| 175 |
* An instance of this class should be passed to the run() function |
| 176 |
* defined in Smart_Post_Show_Loader as all of the hooks are defined |
| 177 |
* in that particular class. |
| 178 |
* |
| 179 |
* The Smart_Post_Show_Loader will then create the relationship |
| 180 |
* between the defined hooks and the functions defined in this |
| 181 |
* class. |
| 182 |
*/ |
| 183 |
$current_screen = get_current_screen(); |
| 184 |
$the_current_post_type = $current_screen->post_type; |
| 185 |
if ( 'sp_post_carousel' === $the_current_post_type ) { |
| 186 |
wp_enqueue_script( SP_PC_PLUGIN_NAME, SP_PC_URL . 'admin/assets/js/post-carousel-admin.min.js', array( 'jquery' ), SP_PC_VERSION, true ); |
| 187 |
wp_enqueue_script( 'pcp_swiper' ); |
| 188 |
wp_enqueue_script( 'pcp_script' ); |
| 189 |
|
| 190 |
// Fix the plugin ui interaction conflict along with EasyTimeTable plugin. |
| 191 |
wp_dequeue_script( 'jQuery-ui' ); |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Add carousel admin columns. |
| 197 |
* |
| 198 |
* @since 2.2.0 |
| 199 |
* @return statement |
| 200 |
*/ |
| 201 |
public function filter_carousel_admin_column() { |
| 202 |
$admin_columns['cb'] = '<input type="checkbox" />'; |
| 203 |
$admin_columns['title'] = __( 'Title', 'post-carousel' ); |
| 204 |
$admin_columns['shortcode'] = __( 'Shortcode', 'post-carousel' ); |
| 205 |
$admin_columns['pcp_layout'] = __( 'Layout', 'post-carousel' ); |
| 206 |
$admin_columns['date'] = __( 'Date', 'post-carousel' ); |
| 207 |
|
| 208 |
return $admin_columns; |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* Display admin columns for the carousels. |
| 213 |
* |
| 214 |
* @param mix $column The columns. |
| 215 |
* @param string $post_id The post ID. |
| 216 |
* @return void |
| 217 |
*/ |
| 218 |
public function display_carousel_admin_fields( $column, $post_id ) { |
| 219 |
$pcp_layouts = get_post_meta( $post_id, 'sp_pcp_layouts', true ); |
| 220 |
$carousels_types = isset( $pcp_layouts['pcp_layout_preset'] ) ? $pcp_layouts['pcp_layout_preset'] : ''; |
| 221 |
switch ( $column ) { |
| 222 |
case 'shortcode': |
| 223 |
?> |
| 224 |
<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="<?php echo esc_attr( $post_id ); ?>"]"/> <div class="pcp-after-copy-text"><i class="fa fa-check-circle"></i> <?php esc_html_e( 'Shortcode Copied to Clipboard!', 'post-carousel' ); ?></div> |
| 225 |
<?php |
| 226 |
break; |
| 227 |
case 'pcp_layout': |
| 228 |
$layout = ucwords( str_replace( '_layout', ' ', $carousels_types ) ); |
| 229 |
echo esc_html( $layout ); |
| 230 |
} // end switch. |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Sp_post_carousel post type Save and update alert in Admin Dashboard created by Post carousel Pro |
| 235 |
* |
| 236 |
* @param array $messages alert messages. |
| 237 |
*/ |
| 238 |
public function sppcp_update( $messages ) { |
| 239 |
global $post, $post_ID; |
| 240 |
$messages['sp_post_carousel'][1] = __( 'Shortcode Updated', 'post-carousel' ); |
| 241 |
$messages['sp_post_carousel'][6] = __( 'Shortcode Published', 'post-carousel' ); |
| 242 |
return $messages; |
| 243 |
} |
| 244 |
|
| 245 |
/** |
| 246 |
* Redirect after active |
| 247 |
* |
| 248 |
* @param string $plugin The plugin help page. |
| 249 |
*/ |
| 250 |
public function redirect_help_page( $plugin ) { |
| 251 |
if ( SMART_POST_SHOW_BASENAME === $plugin && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) && ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) ) { |
| 252 |
|
| 253 |
$is_visited_setup_wizard = get_option( 'sp_smart_post_setup_wizard_visited', false ); |
| 254 |
|
| 255 |
if ( ! $is_visited_setup_wizard ) { |
| 256 |
wp_redirect( admin_url( 'edit.php?post_type=sp_post_carousel&page=pcp_help#setupwizard' ) ); |
| 257 |
} elseif ( $is_visited_setup_wizard ) { |
| 258 |
wp_redirect( admin_url( 'edit.php?post_type=sp_post_carousel&page=pcp_help' ) ); |
| 259 |
} |
| 260 |
exit(); |
| 261 |
} |
| 262 |
} |
| 263 |
/** |
| 264 |
* If it is the plugins page. |
| 265 |
* |
| 266 |
* @since 2.2.0 |
| 267 |
* @access private |
| 268 |
*/ |
| 269 |
private function is_plugins_screen() { |
| 270 |
return in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true ); |
| 271 |
} |
| 272 |
|
| 273 |
/** |
| 274 |
* Bottom review notice. |
| 275 |
* |
| 276 |
* @param string $text The review notice. |
| 277 |
* @return string |
| 278 |
*/ |
| 279 |
public function sp_spc_footer_text( $text ) { |
| 280 |
$screen = get_current_screen(); |
| 281 |
if ( 'sp_post_carousel_page_pcp_help' === $screen->id || 'sp_post_carousel' === $screen->post_type ) { |
| 282 |
$url = 'https://wordpress.org/support/plugin/post-carousel/reviews/'; |
| 283 |
$text = sprintf( wp_kses_post( 'Enjoying <strong>Smart Post?</strong> Please rate us <span class="spspc-footer-text-star">� |
| 284 |
� |
| 285 |
� |
| 286 |
� |
| 287 |
� |
| 288 |
</span> <a href="%s" target="_blank">WordPress.org.</a> Your positive feedback will help us grow more. Thank you! 😊', 'post-carousel' ), $url ); |
| 289 |
} |
| 290 |
return $text; |
| 291 |
} |
| 292 |
|
| 293 |
/** |
| 294 |
* Bottom version notice. |
| 295 |
* |
| 296 |
* @param string $text The version notice. |
| 297 |
* @return string |
| 298 |
*/ |
| 299 |
public function sp_spc_version_text( $text ) { |
| 300 |
$screen = get_current_screen(); |
| 301 |
if ( 'sp_post_carousel' === $screen->post_type ) { |
| 302 |
$text = 'Smart Post ' . SP_PC_VERSION; |
| 303 |
} |
| 304 |
return $text; |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
/** |
| 309 |
* Smart Post Show dashboard capability. |
| 310 |
* |
| 311 |
* @return string |
| 312 |
*/ |
| 313 |
function sp_pc_dashboard_capability() { |
| 314 |
return apply_filters( 'sp_pc_dashboard_capability', 'manage_options' ); |
| 315 |
} |
| 316 |
|