| 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=sp_post_template&spblock_inserter=true' ), __( 'Add Post Layout', '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/patterns/" target="_blank">' . __( 'Ready Patterns', 'post-carousel' ) . '</a>'; |
| 121 |
$plugin_meta[] = '<a href="https://wpsmartpost.com/docs/" target="_blank">' . __( 'Docs', 'post-carousel' ) . '</a>'; |
| 122 |
$plugin_meta[] = '<a href="https://www.youtube.com/watch?v=_WxI7oyxdPA&list=PLoUb-7uG-5jMKaIryd6B0d41Lafvx4UF5" target="_blank">' . __( 'Video Tutorials', '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 || 'toplevel_page_sp_post_carousel_settings' === $screen->id ) { |
| 282 |
$heart_icon = '<svg class="spspc-footer-heart" width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> |
| 283 |
<path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z" fill="#E25555"/> |
| 284 |
</svg>'; |
| 285 |
|
| 286 |
$social_icons = array( |
| 287 |
'linkedin' => array( |
| 288 |
'url' => 'https://www.linkedin.com/company/shapedplugin', |
| 289 |
'icon' => '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13 0c.563 0 1 .469 1 1v12c0 .563-.437 1-1 1H1c-.562 0-1-.437-1-1V1c0-.531.438-1 1-1zM4.219 12h.031V5.313H2.156V12zM3.187 2C2.532 2 2 2.531 2 3.219c0 .656.531 1.187 1.188 1.187s1.218-.531 1.218-1.187A1.22 1.22 0 0 0 3.188 2M12 12V8.344c0-1.813-.375-3.188-2.469-3.188-1.031 0-1.687.563-1.969 1.063h-.03v-.907h-2V12h2.093V8.688c0-.876.156-1.72 1.219-1.72 1.062 0 1.094 1 1.094 1.782V12z" fill="#757575"/></svg>', |
| 290 |
), |
| 291 |
'twitter' => array( |
| 292 |
'url' => 'https://www.x.com/shapedplugin/', |
| 293 |
'icon' => '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2 0h10c1.094 0 2 .906 2 2v10c0 1.094-.906 2-2 2H2c-1.094 0-2-.906-2-2V2C0 .906.906 0 2 0m9.281 2.625H9.812L7.345 5.438 5.25 2.625H2.188l3.656 4.781-3.469 3.969h1.469L6.53 8.313l2.344 3.062h2.969L8.03 6.344zM10.094 10.5H9.28L3.906 3.469h.875z" fill="#757575"/></svg>', |
| 294 |
), |
| 295 |
'wordpress' => array( |
| 296 |
'url' => 'https://profiles.wordpress.org/shapedplugin/#content-plugins', |
| 297 |
'icon' => '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.688 5.031a6.6 6.6 0 0 0-.594 2.719 6.62 6.62 0 0 0 3.75 5.969zM12.25 7.406c0 .594-.219 1.25-.5 2.157l-.687 2.218-2.376-7.156c.376 0 .75-.062.75-.062.344-.032.313-.563-.062-.532 0 0-1.062.063-1.75.063-.656 0-1.75-.063-1.75-.063-.375-.031-.406.532-.062.532 0 0 .343.062.718.062l1.032 2.844-1.47 4.375-2.405-7.219c.406 0 .75-.062.75-.062.343-.032.312-.563-.032-.532 0 0-1.093.063-1.781.063h-.437a6.65 6.65 0 0 1 5.562-3c1.719 0 3.313.656 4.5 1.75h-.094c-.656 0-1.125.562-1.125 1.187 0 .532.313 1 .656 1.563.25.437.563 1 .563 1.812m-4.375.938 2.031 5.594c.031.03.031.062.063.093a6.5 6.5 0 0 1-2.219.375 6.2 6.2 0 0 1-1.875-.281zm5.719-3.781c.5.937.812 2.03.812 3.187 0 2.469-1.344 4.594-3.312 5.75l2.031-5.875c.375-.937.5-1.719.5-2.375 0-.25 0-.469-.031-.687M0 7.75a7.75 7.75 0 0 0 7.75 7.75 7.75 7.75 0 0 0 7.75-7.75A7.75 7.75 0 0 0 7.75 0 7.75 7.75 0 0 0 0 7.75m15.156 0a7.4 7.4 0 0 1-7.406 7.406A7.4 7.4 0 0 1 .344 7.75 7.4 7.4 0 0 1 7.75.344a7.4 7.4 0 0 1 7.406 7.406" fill="#757575"/></svg>', |
| 298 |
), |
| 299 |
'facebook' => array( |
| 300 |
'url' => 'https://www.facebook.com/shapedplugin/', |
| 301 |
'icon' => '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2 0h10c1.094 0 2 .906 2 2v10c0 1.094-.906 2-2 2H7.969V9.438h2.156L10.594 7H7.969v-.875c0-1.281.5-1.781 1.812-1.781.406 0 .75 0 .938.031V2.156c-.375-.094-1.25-.187-1.75-.187-2.656 0-3.906 1.25-3.906 3.968V7H3.406v2.438h1.656V14H2c-1.094 0-2-.906-2-2V2C0 .906.906 0 2 0" fill="#757575"/></svg>', |
| 302 |
), |
| 303 |
'youtube' => array( |
| 304 |
'url' => 'https://www.youtube.com/@shapedplugin', |
| 305 |
'icon' => '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="m8.813 7-2.97 1.688V5.312zM12 0c1.094 0 2 .906 2 2v10c0 1.094-.906 2-2 2H2c-1.094 0-2-.906-2-2V2C0 .906.906 0 2 0zm.438 4.25c-.126-.5-.5-.875-1-1C10.562 3 7 3 7 3s-3.562 0-4.437.25c-.5.125-.876.5-1 1-.25.906-.25 2.75-.25 2.75s0 1.875.25 2.781c.125.469.5.844 1 .969C3.437 11 7 11 7 11s3.563 0 4.438-.25c.5-.125.874-.5 1-1 .25-.875.25-2.75.25-2.75s0-1.844-.25-2.75" fill="#757575"/></svg>', |
| 306 |
), |
| 307 |
); |
| 308 |
|
| 309 |
$social_html = ''; |
| 310 |
foreach ( $social_icons as $platform => $data ) { |
| 311 |
$social_html .= sprintf( |
| 312 |
'<a href="%s" target="_blank" rel="noopener noreferrer" class="spspc-footer-social-link" title="%s">%s</a>', |
| 313 |
esc_url( $data['url'] ), |
| 314 |
esc_attr( ucfirst( $platform ) ), |
| 315 |
$data['icon'] |
| 316 |
); |
| 317 |
} |
| 318 |
|
| 319 |
$text = sprintf( |
| 320 |
'<div class="spspc-footer-container"> |
| 321 |
<div class="spspc-footer-left"> |
| 322 |
<span class="spspc-footer-made-with">%s</span> |
| 323 |
%s |
| 324 |
<span class="spspc-footer-by">%s</span> |
| 325 |
<a href="https://shapedplugin.com/about-us/" target="_blank" rel="noopener noreferrer" class="spspc-footer-team-link">ShapedPlugin LLC Team</a> |
| 326 |
</div> |
| 327 |
<div class="spspc-footer-social">Get Connected with %s</div> |
| 328 |
</div>', |
| 329 |
esc_html__( 'Made with', 'post-carousel' ), |
| 330 |
$heart_icon, |
| 331 |
esc_html__( 'by the', 'post-carousel' ), |
| 332 |
$social_html |
| 333 |
); |
| 334 |
} |
| 335 |
return $text; |
| 336 |
} |
| 337 |
|
| 338 |
/** |
| 339 |
* Bottom version notice. |
| 340 |
* |
| 341 |
* @param string $text The version notice. |
| 342 |
* @return string |
| 343 |
*/ |
| 344 |
public function sp_spc_version_text( $text ) { |
| 345 |
$screen = get_current_screen(); |
| 346 |
if ( 'sp_post_carousel_page_pcp_help' === $screen->id || 'sp_post_carousel' === $screen->post_type || 'toplevel_page_sp_post_carousel_settings' === $screen->id ) { |
| 347 |
$text = sprintf( 'Enjoyed <b>Smart Post?</b> <a class="spspc-footer-text" href="https://wordpress.org/support/plugin/post-carousel/reviews/" target="_blank"> Rate us! � |
| 348 |
� |
| 349 |
� |
| 350 |
� |
| 351 |
� |
| 352 |
</a>' ); |
| 353 |
} |
| 354 |
return $text; |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
/** |
| 359 |
* Smart Post Show dashboard capability. |
| 360 |
* |
| 361 |
* @return string |
| 362 |
*/ |
| 363 |
function sp_pc_dashboard_capability() { |
| 364 |
return apply_filters( 'sp_pc_dashboard_capability', 'manage_options' ); |
| 365 |
} |
| 366 |
|