*/
class Scrollsequence_Admin
{
/**
* The ID of this plugin.
*
* @since 0.7.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name ;
/**
* The version of this plugin.
*
* @since 0.7.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version ;
/**
* Initialize the class and set its properties.
*
* @since 0.7.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version )
{
$this->plugin_name = $plugin_name;
$this->version = $version;
add_shortcode( 'scrollsequence', array( $this, 'scrollsequence_shortcode' ) );
}
/**
* Register the stylesheets for the admin area.
*
* @since 0.7.0
*/
public function enqueue_styles()
{
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Scrollsequence_Loader as all of the hooks are defined
* in that particular class.
*
* The Scrollsequence_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
// Ak: I want to add an IF statement to enqueue scripts only to my CPT
global $post_type ;
if ( 'scrollsequence' == $post_type ) {
wp_enqueue_style(
$this->plugin_name,
plugin_dir_url( __FILE__ ) . 'css/scrollsequence-admin.css',
array(),
$this->version,
'all'
);
}
// Ak: end
}
/**
* Register the JavaScript for the admin area.
*
* @since 0.7.0
*/
public function enqueue_scripts()
{
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Scrollsequence_Loader as all of the hooks are defined
* in that particular class.
*
* The Scrollsequence_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
// Ak: I want to add an IF statement to enqueue scripts only to my CPT
global $post_type ;
global $pagenow ;
if ( 'scrollsequence' == $post_type && ('post-new.php' === $pagenow || 'post.php' === $pagenow) ) {
// Free
wp_enqueue_script(
$this->plugin_name,
plugin_dir_url( __FILE__ ) . 'js/scrollsequence-admin.js',
array( 'jquery' ),
$this->version,
true
);
}
// Ak: end
}
/**
* Register Scrollsequence CPT .
*
* @since 0.7.0
*/
public function scrollsequence_cpt()
{
require_once "create-cpt.php";
}
/**
* Register Scrollsequence CPT .
*
* @since 0.7.3
*/
public function scrollsequence_cpt_submenu()
{
add_submenu_page(
'edit.php?post_type=scrollsequence',
/*parent_slug*/
'Dashboard Scrollsequence',
/*page title*/
'Dashboard',
/*menu title*/
'edit_posts',
/*roles and capability needed*/
// Update 0.9.93
'scrollsequence-dashboard',
/*menu slug*/
'scrollsequence_cpt_dashboard_callback'
);
function scrollsequence_cpt_dashboard_callback()
{
require_once "partials/scrollsequence-admin-display.php";
}
}
public function scrollsequence_preview_media()
{
add_submenu_page(
'edit.php?post_type=scrollsequence',
'Preview Scrollsequence',
/*page title*/
'Preview ',
/*menu title*/
'edit_posts',
/*roles and capability needed*/
// Update 0.9.93
'scrollsequence-preview',
/*menu slug*/
'scrollsequence_preview_callback'
);
function scrollsequence_preview_callback()
{
require_once "partials/scrollsequence-admin-display-media-tools-preview.php";
}
// Enqueue script on this specific submenu page
add_action( 'admin_enqueue_scripts', array( $this, 'scrollsequence_preview_enqueue_scripts' ) );
}
function scrollsequence_preview_media_hide_submenu_page()
{
echo '' ;
}
public function scrollsequence_preview_enqueue_scripts( $hook )
{
// Check if we're on the 'scrollsequence-preview' page
if ( 'admin_page_scrollsequence-preview' !== $hook ) {
return;
}
}
/**
* Single file custom template for scrollsequence. I am following this:
* https://code.tutsplus.com/tutorials/a-guide-to-wordpress-custom-post-types-creation-display-and-meta-boxes--wp-27645
* ref "tutsplus" in class-scrollsequence add action thing
* @since 0.7.0
* @uses i dont know
* Step 1 https://blog.wplauncher.com/add-meta-box-wordpress-custom-post-type/
*/
public function scrollsequence_template( $template_path )
{
if ( get_post_type() == 'scrollsequence' ) {
if ( is_single() ) {
// checks if the file exists in the theme first,
// otherwise serve the file from the plugin
if ( $theme_file = locate_template( array( 'single-scrollsequence.php' ) ) ) {
$template_path = $theme_file;
} else {
$template_path = plugin_dir_path( __DIR__ ) . 'public/partials/single-scrollsequence.php';
}
}
}
return $template_path;
}
/**
* Carbon Fields Boot function. This function boots up carbon fields.
*
* @since 0.9.8
*/
public function scrollsequence_carbon_fields_load()
{
require_once __DIR__ . '/../includes/carbonfields/autoload.php';
\Carbon_Fields\Carbon_Fields::boot();
}
/**
* Carbon Fields Main Function (Scrollsequence CPT)
*
* @since 0.9.8
*/
public function scrollsequence_carbon_fields_cpt()
{
/* TRANSLATION IS MISSING FOR STRINGS BELOW */
$scrollsequence_advert_html = '
[scrollsequence margintop="-200px"] Animation will have a 200px overlap. Useful when you have a gap at the top where animation starts.
[scrollsequence marginbottom="-600px"] Animation will have a 600px overlap. Useful when you want to seamlessly join content after the animation ends.
*/
public function scrollsequence_classic_content_html()
{
// Ak: I want to add an IF statement to add admin notice only to scrollsequence post php
global $post_type ;
global $pagenow ;
if ( $pagenow == 'post.php' && 'scrollsequence' == $post_type || $pagenow == 'post-new.php' && 'scrollsequence' == $post_type ) {
// IF Condition Changed 1.0.076
echo __( '
Content Editor
Place shortcode [scrollsequence] anywhere in the classic content to control image sequence position. If not specified [scrollsequence] shortcode will be placed at the start of content automatically, rendering the image sequence at the begining of the page.
', 'scrollsequence' ) . '
' ;
}
// Ak: end
}
/**
* Function that makes the scrollsequence shortcode happen..
*
* Shortcode: [scrollsequence id="###"]
*
*
* @since 0.9.95
*/
public function scrollsequence_shortcode( $atts )
{
// Extract atts
extract( shortcode_atts( array(
'id' => get_the_id(),
'margintop' => 0,
'marginbottom' => 0,
'hide' => false,
), $atts ) );
// Get info from database
$ssqInputZeroObject = array(
'debug' => carbon_get_post_meta( $id, 'scrollsequence_debug_multi' ),
'show_footer' => carbon_get_post_meta( $id, 'scrollsequence_show_footer' ),
'show_sidebar' => carbon_get_post_meta( $id, 'scrollsequence_show_sidebar' ),
'preloadPercentage' => esc_attr( get_option( 'ssq_option_preload_percentage', 0.12 ) ),
'ssqFyiId' => $id,
'siteUrl' => get_option( 'siteurl' ),
);
$ssqInputObject = array(
'ssqId' => $id,
'bodyBgColor' => carbon_get_post_meta( $id, 'scrollsequence_bodybgcolor' ),
'imageOpacity' => carbon_get_post_meta( $id, 'scrollsequence_image_opacity' ),
'scrub' => (double) carbon_get_post_meta( $id, 'scrollsequence_scrub' ),
'forceFullWidth' => carbon_get_post_meta( $id, 'scrollsequence_image_full_width' ),
'zIndex' => carbon_get_post_meta( $id, 'scrollsequence_image_zindex' ),
'triggerStart' => carbon_get_post_meta( $id, 'scrollsequence_trigger_start' ),
'triggerEnd' => carbon_get_post_meta( $id, 'scrollsequence_trigger_end' ),
'canvasDPR' => esc_attr( get_option( 'ssq_option_canvas_dpr', 'quality' ) ),
);
// Rename info from database in JS format
$ssqInputObject['page'] = array();
$ssqPageFromUI = carbon_get_post_meta( $id, 'scrollsequence_page' );
foreach ( $ssqPageFromUI as $x => $val ) {
$ssqInputObject['page'][$x]['alignX']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_alignx_desktop'];
$ssqInputObject['page'][$x]['alignX']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_alignx_mobile'];
$ssqInputObject['page'][$x]['alignY']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_aligny_desktop'];
$ssqInputObject['page'][$x]['alignY']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_aligny_mobile'];
// $ssqInputObject['page'][$x]['pageDuration']= (float)$ssqPageFromUI[$x]['scrollsequence_p_duration'];
$ssqInputObject['page'][$x]['imgDur'] = (double) $ssqPageFromUI[$x]['scrollsequence_p_imgdur'];
$ssqInputObject['page'][$x]['scaleTo']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_scaleto_desktop'];
$ssqInputObject['page'][$x]['scaleTo']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_scaleto_mobile'];
// Loop Through Anim
$ssqInputObject['page'][$x]['animEl'] = array();
// in case of empty
foreach ( $ssqPageFromUI[$x]['ssqnce_anim'] as $z => $animvar ) {
$ssqInputObject['page'][$x]['animEl'][$z] = $ssqPageFromUI[$x]['ssqnce_anim'][$z];
}
}
// If there is "hide" parameter -> enqueue mobile detect script and act based on parameter values.
if ( $hide ) {
$showDetectNotice = in_array( "detectdebug", carbon_get_post_meta( $id, 'scrollsequence_debug_multi' ) );
//echo '';
require_once 'mobile_detect/mobile_detect.php';
$detect = new Mobile_Detect();
// var_dump($detect);
// Any mobile device (phones or tablets).
if ( $detect->isMobile() && str_contains( strtolower( $hide ), 'ismobile' ) ) {
return '
Scrollsequence Debug - MobileDetect: Hide because device isMobile
Scrollsequence Debug - MobileDetect: Hide because device isNotPhone
';
}
// Check for a specific platform with the help of the magic methods:
if ( $detect->isiOS() && str_contains( strtolower( $hide ), 'isios' ) ) {
return '
Scrollsequence Debug - MobileDetect: Hide because device isiOs
';
}
// end of else count other than zero
// end of free
}
// end of scrollsequence_shortcode function
/**
* Add Columns to Custom Post Type List
*
*
*/
function scrollsequence_admin_columns( $columns )
{
$columns = array(
'cb' => $columns['cb'],
'title' => __( 'Title', 'scrollsequence' ),
'ssq_shortcode' => __( 'Shortcode', 'scrollsequence' ),
'date' => __( 'Date', 'scrollsequence' ),
'author' => __( 'Author', 'scrollsequence' ),
);
return $columns;
}
function scrollsequence_admin_column_content( $column, $id )
{
if ( 'ssq_shortcode' == $column ) {
echo '[scrollsequence id="' . $id . '"]' ;
}
}
/**
* Admin Columns - FEATURED IMAGE
*
* Since 1.2.0
*
*
*/
function ssq_add_thumbnail_column( $columns )
{
$columns['ssq_post_thumb'] = __( 'Featured Image', 'scrollsequence' );
return $columns;
}
function ssq_display_thumbnail_column( $column_name, $post_id )
{
switch ( $column_name ) {
case 'ssq_post_thumb':
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
if ( $post_thumbnail_id ) {
$post_thumbnail_img = wp_get_attachment_image_src( $post_thumbnail_id, 'thumbnail' );
echo '' ;
} else {
// no thumbnail, try to use something else
$idOfFirstImage = carbon_get_post_meta( get_the_ID(), 'scrollsequence_page' );
//var_dump($idOfFirstImage);
// Check that is array check that images is array and finally check that count of images is bigger than one.
if ( is_array( $idOfFirstImage ) && count( $idOfFirstImage ) > 0 && is_array( $idOfFirstImage[0]['scrollsequence_p_images'] ) && count( $idOfFirstImage[0]['scrollsequence_p_images'] ) > 0 ) {
// first image in sequence exists
echo '' ;
} else {
// there are no images here
echo 'No Image' ;
}
}
break;
}
}
/**
* Register Settings Options in Scrollsequence Options Dashboard
*
* @since 1.1.1
*/
function scrollsequence_register_options_settings()
{
// whitelist options
register_setting( 'scrollsequence-settings-group', 'ssq_option_preload_percentage', array(
'default' => 0.12,
) );
register_setting( 'scrollsequence-settings-group', 'ssq_option_position_sticky', array(
'default' => 'sticky-js',
) );
// since 1.3.0
register_setting( 'scrollsequence-settings-group', 'ssq_option_canvas_dpr', array(
'default' => 'quality',
) );
// since 1.3.3
// TODO
// register_setting( 'scrollsequence-settings-group', 'ssq_option_scroller_proxy' ); // not implemented yet
// register_setting( 'scrollsequence-settings-group', 'ssq_option_elementor_widget' ); // not implemented yet
}
/**
* DUPLICATE SCROLLSEQUENCE
* @snippet Duplicate posts and pages without plugins
* @author Misha Rudrastyh
* @url https://rudrastyh.com/wordpress/duplicate-post.html
*
*/
// Add the duplicate link to action list for post_row_actions for "post" and custom post types
function ssq_duplicate_post_link( $actions, $post )
{
if ( !current_user_can( 'edit_posts' ) ) {
return $actions;
}
if ( $post->post_type !== 'scrollsequence' ) {
return $actions;
}
$url = wp_nonce_url( add_query_arg( array(
'action' => 'duplicate_scrollsequence_as_draft',
'post' => $post->ID,
), 'admin.php' ), basename( __FILE__ ), 'duplicate_ssq_nonce' );
$actions['duplicate_ssq'] = '' . __( 'Duplicate' ) . '';
return $actions;
}
/*
* Function creates post duplicate as a draft and redirects then to the edit post screen
*/
function duplicate_scrollsequence_as_draft()
{
// check if post ID has been provided and action
if ( empty($_GET['post']) ) {
wp_die( 'No post to duplicate has been provided!' );
}
// Nonce verification
if ( !isset( $_GET['duplicate_ssq_nonce'] ) || !wp_verify_nonce( $_GET['duplicate_ssq_nonce'], basename( __FILE__ ) ) ) {
return;
}
// Get the original post id
$post_id = absint( $_GET['post'] );
// And all the original post data then
$post = get_post( $post_id );
/*
* if you don't want current user to be the new post author,
* then change next couple of lines to this: $new_post_author = $post->post_author;
*/
$current_user = wp_get_current_user();
$new_post_author = $current_user->ID;
// if post data exists (I am sure it is, but just in a case), create the post duplicate
if ( $post ) {
// new post data array
$args = array(
'comment_status' => $post->comment_status,
'ping_status' => $post->ping_status,
'post_author' => $new_post_author,
'post_content' => $post->post_content,
'post_excerpt' => $post->post_excerpt,
'post_name' => $post->post_name,
'post_parent' => $post->post_parent,
'post_password' => $post->post_password,
'post_status' => 'draft',
'post_title' => $post->post_title . '_duplicate',
'post_type' => $post->post_type,
'to_ping' => $post->to_ping,
'menu_order' => $post->menu_order,
);
// insert the post by wp_insert_post() function
$new_post_id = wp_insert_post( $args );
/*
* get all current post terms ad set them to the new post draft
*/
$taxonomies = get_object_taxonomies( get_post_type( $post ) );
// returns array of taxonomy names for post type, ex array("category", "post_tag");
if ( $taxonomies ) {
foreach ( $taxonomies as $taxonomy ) {
$post_terms = wp_get_object_terms( $post_id, $taxonomy, array(
'fields' => 'slugs',
) );
wp_set_object_terms(
$new_post_id,
$post_terms,
$taxonomy,
false
);
}
}
// duplicate all post meta
$post_meta = get_post_meta( $post_id );
if ( $post_meta ) {
foreach ( $post_meta as $meta_key => $meta_values ) {
if ( '_wp_old_slug' == $meta_key ) {
// do nothing for this meta key
continue;
}
foreach ( $meta_values as $meta_value ) {
add_post_meta( $new_post_id, $meta_key, $meta_value );
}
}
}
// finally, redirect to the edit post screen for the new draft
// wp_safe_redirect(
// add_query_arg(
// array(
// 'action' => 'edit',
// 'post' => $new_post_id
// ),
// admin_url( 'post.php' )
// )
// );
// exit;
// or we can redirect to all posts with a message
wp_safe_redirect( add_query_arg( array(
'post_type' => ( 'post' !== get_post_type( $post ) ? get_post_type( $post ) : false ),
'saved' => 'post_duplication_created',
), admin_url( 'edit.php' ) ) );
exit;
} else {
wp_die( 'Post creation failed, could not find original post.' );
}
}
/*
* In case we decided to add admin notices
*/
function ssq_duplication_admin_notice()
{
// Get the current screen
$screen = get_current_screen();
if ( 'edit' !== $screen->base ) {
return;
}
//Checks if settings updated
if ( isset( $_GET['saved'] ) && 'post_duplication_created' == $_GET['saved'] ) {
echo '
' . __( 'Copy created.' ) . '
' ;
}
}
// end of duplicate
/**
* This function defines helpscout beacon
*
*
*/
public function ssq_add_helpscout_beacon()
{
global $post_type ;
//var_dump($post_type);
global $pagenow ;
//var_dump($pagenow);
if ( 'scrollsequence' == $post_type && ('post-new.php' === $pagenow || 'post.php' === $pagenow) || 'scrollsequence' == $post_type && 'edit.php' === $pagenow || 'admin.php' === $pagenow && isset( $_GET['page'] ) && $_GET['page'] === 'scrollsequence-dashboard' || 'admin.php' === $pagenow && isset( $_GET['page'] ) && $_GET['page'] === 'scrollsequence-account' || 'admin.php' === $pagenow && isset( $_GET['page'] ) && $_GET['page'] === 'scrollsequence-contact' ) {
// Inline Script on admin screen - not ready yet, too few articles in the thing.
?>