PluginProbe
Scrollsequence – Cinematic Scroll Image Animation Plugin / 1.4.6
Scrollsequence – Cinematic Scroll Image Animation Plugin v1.4.6
1.4.3 1.4.4 1.4.5 1.4.6 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 trunk 0.9.92 0.9.93 0.9.94 0.9.96 1.0.072 1.0.073 All 61 releases
scrollsequence / admin / class-scrollsequence-admin.php

class-scrollsequence-admin.php in Scrollsequence – Cinematic Scroll Image Animation Plugin 1.4.6, at admin/class-scrollsequence-admin.php

978 lines 51.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Carbon_Fields\Container ;
4 use Carbon_Fields\Field ;
5 //use Carbon_Fields\Block; //not at the moment
6 /**
7 * The admin-specific functionality of the plugin.
8 *
9 * @link www.scrollsequence.com
10 * @since 0.7.0
11 *
12 * @package Scrollsequence
13 * @subpackage Scrollsequence/admin
14 */
15 /**
16 * The admin-specific functionality of the plugin.
17 *
18 * Defines the plugin name, version, and two examples hooks for how to
19 * enqueue the admin-specific stylesheet and JavaScript.
20 *
21 * @package Scrollsequence
22 * @subpackage Scrollsequence/admin
23 * @author Scrollsequence <info@scrollsequence.com>
24 */
25 class Scrollsequence_Admin
26 {
27 /**
28 * The ID of this plugin.
29 *
30 * @since 0.7.0
31 * @access private
32 * @var string $plugin_name The ID of this plugin.
33 */
34 private $plugin_name ;
35 /**
36 * The version of this plugin.
37 *
38 * @since 0.7.0
39 * @access private
40 * @var string $version The current version of this plugin.
41 */
42 private $version ;
43 /**
44 * Initialize the class and set its properties.
45 *
46 * @since 0.7.0
47 * @param string $plugin_name The name of this plugin.
48 * @param string $version The version of this plugin.
49 */
50 public function __construct( $plugin_name, $version )
51 {
52 $this->plugin_name = $plugin_name;
53 $this->version = $version;
54 add_shortcode( 'scrollsequence', array( $this, 'scrollsequence_shortcode' ) );
55 }
56
57 /**
58 * Register the stylesheets for the admin area.
59 *
60 * @since 0.7.0
61 */
62 public function enqueue_styles()
63 {
64 /**
65 * This function is provided for demonstration purposes only.
66 *
67 * An instance of this class should be passed to the run() function
68 * defined in Scrollsequence_Loader as all of the hooks are defined
69 * in that particular class.
70 *
71 * The Scrollsequence_Loader will then create the relationship
72 * between the defined hooks and the functions defined in this
73 * class.
74 */
75 // Ak: I want to add an IF statement to enqueue scripts only to my CPT
76 global $post_type ;
77 if ( 'scrollsequence' == $post_type ) {
78 wp_enqueue_style(
79 $this->plugin_name,
80 plugin_dir_url( __FILE__ ) . 'css/scrollsequence-admin.css',
81 array(),
82 $this->version,
83 'all'
84 );
85 }
86 // Ak: end
87 }
88
89 /**
90 * Register the JavaScript for the admin area.
91 *
92 * @since 0.7.0
93 */
94 public function enqueue_scripts()
95 {
96 /**
97 * This function is provided for demonstration purposes only.
98 *
99 * An instance of this class should be passed to the run() function
100 * defined in Scrollsequence_Loader as all of the hooks are defined
101 * in that particular class.
102 *
103 * The Scrollsequence_Loader will then create the relationship
104 * between the defined hooks and the functions defined in this
105 * class.
106 */
107 // Ak: I want to add an IF statement to enqueue scripts only to my CPT
108 global $post_type ;
109 global $pagenow ;
110 if ( 'scrollsequence' == $post_type && ('post-new.php' === $pagenow || 'post.php' === $pagenow) ) {
111 // Free
112 wp_enqueue_script(
113 $this->plugin_name,
114 plugin_dir_url( __FILE__ ) . 'js/scrollsequence-admin.js',
115 array( 'jquery' ),
116 $this->version,
117 true
118 );
119 }
120 // Ak: end
121 }
122
123 /**
124 * Register Scrollsequence CPT .
125 *
126 * @since 0.7.0
127 */
128 public function scrollsequence_cpt()
129 {
130 require_once "create-cpt.php";
131 }
132
133 /**
134 * Register Scrollsequence CPT .
135 *
136 * @since 0.7.3
137 */
138 public function scrollsequence_cpt_submenu()
139 {
140 add_submenu_page(
141 'edit.php?post_type=scrollsequence',
142 /*parent_slug*/
143 'Dashboard Scrollsequence',
144 /*page title*/
145 'Dashboard',
146 /*menu title*/
147 'edit_posts',
148 /*roles and capability needed*/
149 // Update 0.9.93
150 'scrollsequence-dashboard',
151 /*menu slug*/
152 'scrollsequence_cpt_dashboard_callback'
153 );
154 function scrollsequence_cpt_dashboard_callback()
155 {
156 require_once "partials/scrollsequence-admin-display.php";
157 }
158
159 }
160
161 /**
162 * Single file custom template for scrollsequence. I am following this:
163 * https://code.tutsplus.com/tutorials/a-guide-to-wordpress-custom-post-types-creation-display-and-meta-boxes--wp-27645
164 * ref "tutsplus" in class-scrollsequence add action thing
165 * @since 0.7.0
166 * @uses i dont know
167 * Step 1 https://blog.wplauncher.com/add-meta-box-wordpress-custom-post-type/
168 */
169 public function scrollsequence_template( $template_path )
170 {
171 if ( get_post_type() == 'scrollsequence' ) {
172 if ( is_single() ) {
173 // checks if the file exists in the theme first,
174 // otherwise serve the file from the plugin
175
176 if ( $theme_file = locate_template( array( 'single-scrollsequence.php' ) ) ) {
177 $template_path = $theme_file;
178 } else {
179 $template_path = plugin_dir_path( __DIR__ ) . 'public/partials/single-scrollsequence.php';
180 }
181
182 }
183 }
184 return $template_path;
185 }
186
187 /**
188 * Carbon Fields Boot function. This function boots up carbon fields.
189 *
190 * @since 0.9.8
191 */
192 public function scrollsequence_carbon_fields_load()
193 {
194 require_once __DIR__ . '/../includes/carbonfields/autoload.php';
195 \Carbon_Fields\Carbon_Fields::boot();
196 }
197
198 /**
199 * Carbon Fields Main Function (Scrollsequence CPT)
200 *
201 * @since 0.9.8
202 */
203 public function scrollsequence_carbon_fields_cpt()
204 {
205 /* TRANSLATION IS MISSING FOR STRINGS BELOW */
206 $scrollsequence_advert_html = '<h4>Full animation settings are available in <a href=' . admin_url( "admin.php?page=scrollsequence-pricing" ) . '>Scrollsequence PRO</a>.</h4><strong>NEW: </strong>We offer <a href=' . admin_url( "admin.php?page=scrollsequence-pricing&trial=true" ) . '>14 days FREE trial</a> - no card required, no risk. ';
207 $scrollsequence_left_center_right = '
208 <div style="float: left">' . __( 'Left', 'scrollsequence' ) . '</div>
209 <div style="float: right">' . __( 'Right', 'scrollsequence' ) . '</div>
210 <div style="margin: 0 auto; width: 100px;"></div>
211 ';
212 $scrollsequence_bottom_center_top = '
213 <div style="float: left">' . __( 'Top', 'scrollsequence' ) . '</div>
214 <div style="float: right">' . __( 'Bottom', 'scrollsequence' ) . '</div>
215 <div style="margin: 0 auto; width: 100px;"></div>
216 ';
217 $scrollsequence_trigger_start = '
218 <div style="float: left">' . __( 'Start Sooner', 'scrollsequence' ) . '</div>
219 <div style="float: right">' . __( 'Default', 'scrollsequence' ) . '</div>
220 <div style="margin: 0 auto; width: 100px;"></div>
221 ';
222 $scrollsequence_trigger_end = '
223 <div style="float: left">' . __( 'Default', 'scrollsequence' ) . '</div>
224 <div style="float: right">' . __( 'End Later', 'scrollsequence' ) . '</div>
225 <div style="margin: 0 auto; width: 100px;"></div>
226 ';
227 /* TRANSLATION IS MISSING FOR STRINGS BELOW */
228 $scrollsequence_aglignmentadv = '<p>More Scale and Alignment settings are available in <a href=' . admin_url( "admin.php?page=scrollsequence-pricing" ) . '>Scrollsequence PRO</a>. </p><p><strong>NEW: </strong>We offer <a href=' . admin_url( "admin.php?page=scrollsequence-pricing&trial=true" ) . '>14 days FREE trial</a> - no card required, no risk.</p>';
229 $scrollsequence_condition_need_images = array(
230 'relation' => 'AND',
231 array(
232 'field' => 'scrollsequence_p_images',
233 'value' => '',
234 'compare' => '!=',
235 ),
236 );
237 // FREE VERSION
238 Container::make( 'post_meta', 'Scrollsequence' )->where( 'post_type', '=', 'scrollsequence' )->set_context( 'carbon_fields_after_title' )->add_fields( array( Field::make( 'complex', 'scrollsequence_page', __( 'Scene', 'scrollsequence' ) )->setup_labels( array(
239 'plural_name' => __( 'Scenes', 'scrollsequence' ),
240 'singular_name' => __( 'Scene', 'scrollsequence' ),
241 ) )->set_layout( 'tabbed-horizontal' )->set_required( true )->set_max( 3 )->add_fields( array(
242 Field::make( 'rich_text', 'scrollsequence_p_wysiwyg', __( 'Fixed Content', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_default_value( '<div class="ssq-center-center"><h1 id="on-earth">' . __( 'Another day on Earth', 'scrollsequence' ) . '</h1></div>' ),
243 Field::make( 'media_gallery', 'scrollsequence_p_images', __( 'Image Sequence', 'scrollsequence' ) )->set_type( array( 'image' ) )->set_required( true )->set_duplicates_allowed( true )->set_classes( 'scrollsequence-custom-class' ),
244 Field::make( 'complex', 'ssqnce_anim', __( 'Fixed Content Animation', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_layout( 'tabbed-vertical' )->setup_labels( array(
245 'plural_name' => __( 'Animations', 'scrollsequence' ),
246 'singular_name' => __( 'Animation', 'scrollsequence' ),
247 ) )->add_fields( 'ssqnce_anim_io', 'Animate From/To', array(
248 Field::make( 'text', 'ssqnce_anim_io_id', __( 'Selector', 'scrollsequence' ) )->set_width( 20 )->set_required( true )->set_help_text( __( 'Enter #id or .class selector', 'scrollsequence' ) ),
249 Field::make( 'text', 'ssqnce_anim_io_start', __( 'Start', 'scrollsequence' ) )->set_width( 20 )->set_required( true )->set_help_text( __( 'Enter image number where element becomes visible', 'scrollsequence' ) )->set_attribute( 'type', 'number' )->set_attribute( 'min', '0' )->set_attribute( 'step', '1' ),
250 Field::make( 'text', 'ssqnce_anim_io_end', __( 'End', 'scrollsequence' ) )->set_width( 20 )->set_required( true )->set_help_text( __( 'Enter image number where element is hidden', 'scrollsequence' ) )->set_attribute( 'type', 'number' )->set_attribute( 'min', '0' )->set_attribute( 'step', '1' ),
251 // Free advert
252 Field::make( 'separator', 'scrollsequence_advert', __( 'Animation Settings Not Available in Free Version', 'scrollsequence' ) )->set_help_text( $scrollsequence_advert_html ),
253 ) )->set_header_template( __( 'Animation', 'scrollsequence' ) . '
254 <% if (ssqnce_anim_io_id) { %>
255 - <%- ssqnce_anim_io_id %>
256 <% } %>
257 ' ),
258 // PRO ONLY END1
259 // Field::make( 'text', 'scrollsequence_p_duration', __( 'Page Height (vh)' ) )
260 // ->set_conditional_logic($scrollsequence_condition_need_images)
261 // ->set_attribute( 'type', 'number' )
262 // ->set_required( true )
263 // ->set_default_value('200')
264 // ->set_attribute( 'min', '20' )
265 // ->set_attribute( 'max', '2000' )
266 // ->set_attribute( 'step', '1' )
267 // ->help_text('This sets the amount of scroll needed to get past this page.'),
268 Field::make( 'text', 'scrollsequence_p_imgdur', __( 'Image Duration (px)', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_attribute( 'type', 'number' )->set_required( true )->set_default_value( '25' )->set_attribute( 'min', '5' )->set_attribute( 'max', '500' )->set_attribute( 'step', '1' )->help_text( __( 'This sets how far the images are apart.', 'scrollsequence' ) ),
269 // PANORAMA (MOBILE)
270 Field::make( 'html', 'scrollsequence_info_html_panorama' )->set_conditional_logic( $scrollsequence_condition_need_images )->set_html( '<h3>' . __( 'Image Scale and Alignment', 'scrollsequence' ) . '</h3>' ),
271 Field::make( 'select', 'scrollsequence_p_scaleto_mobile', __( 'Portrait (Mobile)', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_width( 30 )->set_default_value( 'fill' )->set_options( array(
272 'fill' => __( 'Scale to fill', 'scrollsequence' ),
273 'fit' => __( 'Scale to fit', 'scrollsequence' ) . ' 100%',
274 '0.5' => __( 'Scale to fit', 'scrollsequence' ) . ' 50%',
275 ) ),
276 Field::make( 'text', 'scrollsequence_p_alignx_mobile', __( 'Horizontal Align', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_help_text( $scrollsequence_left_center_right )->set_width( 35 )->set_attribute( 'type', 'range' )->set_classes( 'ssq-range-slider' )->set_default_value( '0.5' )->set_attribute( 'min', '0' )->set_attribute( 'max', '1' )->set_attribute( 'step', '0.5' ),
277 // ROADM
278 Field::make( 'text', 'scrollsequence_p_aligny_mobile', __( 'Vertical Align', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_help_text( $scrollsequence_bottom_center_top )->set_width( 35 )->set_attribute( 'type', 'range' )->set_classes( 'ssq-range-slider' )->set_default_value( '0.5' )->set_attribute( 'min', '0' )->set_attribute( 'max', '1' )->set_attribute( 'step', '0.5' ),
279 // ROADM
280 // LANDSCAPE (DESKTOP)
281 Field::make( 'select', 'scrollsequence_p_scaleto_desktop', __( 'Landscape (Desktop)', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_width( 30 )->set_default_value( 'fill' )->set_options( array(
282 'fill' => __( 'Scale to fill', 'scrollsequence' ),
283 'fit' => __( 'Scale to fit', 'scrollsequence' ) . ' 100%',
284 '0.5' => __( 'Scale to fit', 'scrollsequence' ) . ' 50%',
285 ) ),
286 Field::make( 'text', 'scrollsequence_p_alignx_desktop', __( 'Horizontal Align', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_help_text( $scrollsequence_left_center_right )->set_width( 35 )->set_attribute( 'type', 'range' )->set_classes( 'ssq-range-slider' )->set_default_value( '0.5' )->set_attribute( 'min', '0' )->set_attribute( 'max', '1' )->set_attribute( 'step', '0.5' ),
287 // ROADM
288 Field::make( 'text', 'scrollsequence_p_aligny_desktop', __( 'Vertical Align', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_help_text( $scrollsequence_bottom_center_top )->set_width( 35 )->set_attribute( 'type', 'range' )->set_classes( 'ssq-range-slider' )->set_default_value( '0.5' )->set_attribute( 'min', '0' )->set_attribute( 'max', '1' )->set_attribute( 'step', '0.5' ),
289 // ROADM
290 Field::make( 'html', 'scrollsequence_info_html_freealignadv' )->set_conditional_logic( $scrollsequence_condition_need_images )->set_html( $scrollsequence_aglignmentadv ),
291 ) )->set_header_template( __( 'Scene', 'scrollsequence' ) . ' <%- $_index %>' ) ) );
292 // FREE
293 $scrub_field = Field::make( 'html', 'scrollsequence_hidden', '' )->set_html( '
294 <style>
295 .nevim{
296 line-height: 1.4;
297 font-size: 13px;
298 cursor: pointer;
299 vertical-align: middle;
300 display: block;
301 padding-bottom: 5px;
302 font-weight: 600;
303 color: #23282d;
304 }
305
306
307 </style>
308 <div class="nevim">' . __( 'Scroll Delay', 'scrollsequence' ) . '</div>
309 <select disabled>
310 <option value="0">0s (instant)</option>
311 </select>
312 <p>' . __( 'Scroll Delay Settings available only in', 'scrollsequence' ) . ' <a href=' . admin_url( "admin.php?page=scrollsequence-pricing" ) . '>Scrollsequence PRO</a>.</p>' );
313 $debug_multi_options_array = array(
314 'debug' => __( 'General Debug', 'scrollsequence' ),
315 'preloaddebug' => __( 'Image Preload Debug', 'scrollsequence' ),
316 'detectdebug' => __( 'Device Detect Debug', 'scrollsequence' ),
317 );
318 $scrollsequence_trigger_start_field = Field::make( 'hidden', 'scrollsequence_trigger_start_hidden', '' )->set_classes( 'schovej-to-policko' );
319 $scrollsequence_trigger_end_field = Field::make( 'hidden', 'scrollsequence_trigger_end_hidden', '' )->set_classes( 'schovej-to-policko' );
320 // END OF FREE __(,'scrollsequence')
321 Container::make( 'post_meta', 'Scrollsequence Settings' )->where( 'post_type', '=', 'scrollsequence' )->set_context( 'side' )->set_priority( 'low' )->add_fields( array(
322 $scrollsequence_trigger_start_field,
323 $scrollsequence_trigger_end_field,
324 Field::make( 'select', 'scrollsequence_position', __( 'Position', 'scrollsequence' ) )->help_text( __( 'Sticky position fixes animation to the viewport. Static makes it flow with the rest of the page. Sticky behavior can be controlled via options. See more in documentation. ', 'scrollsequence' ) )->add_options( array(
325 'sticky' => __( 'Sticky (default)', 'scrollsequence' ),
326 'absolute' => __( 'Absolute', 'scrollsequence' ),
327 'static' => __( 'Static', 'scrollsequence' ),
328 ) ),
329 $scrub_field,
330 Field::make( 'select', 'scrollsequence_image_full_width', __( 'Image Width', 'scrollsequence' ) )->add_options( array(
331 false => __( 'Content Width (default)', 'scrollsequence' ),
332 true => __( 'Force Full Width', 'scrollsequence' ),
333 ) )->help_text( __( 'Select "Force Full Width" to overrride your templates default width. If the setting does not work, use full width template included in your Theme.', 'scrollsequence' ) ),
334 Field::make( 'text', 'scrollsequence_image_opacity', __( 'Image Opacity', 'scrollsequence' ) )->set_attribute( 'type', 'number' )->set_required( true )->set_default_value( '1' )->set_attribute( 'min', '0' )->set_attribute( 'max', '1' )->set_attribute( 'step', '0.01' ),
335 // THIS IS QUITE COMPLEX - ACTIVATE LATER ???
336 // Field::make( 'text', 'scrollsequence_image_zindex', __( 'Image z-index (optional)' ) )
337 // //->set_help_text( '' )
338 // ->set_attribute( 'type', 'number' )
339 // ->set_attribute( 'min', '-9999' )
340 // ->set_attribute( 'max', '9999' )
341 // ->set_attribute( 'step', '1' ),
342 // Field::make( 'select', 'scrollsequence_content_spacer', 'Classic Content Position' ) // LEGACY
343 // ->add_options( array( // LEGACY
344 // 'after100' => 'End of Document (default)', // LEGACY
345 // 'after' => 'End of Document (with overlap) ', // LEGACY
346 // 'during' => 'Start of Document',
347 // ) ),
348 Field::make( 'textarea', 'scrollsequence_custom_css', __( 'Custom CSS', 'scrollsequence' ) )->set_default_value( '.ssq-center-center{
349 position: absolute;
350 left: 50%;
351 top: 50%;
352 transform: translate(-50%, -50%);
353 text-shadow: 0 0 8px white;
354 text-align: center;
355 }
356 ' )->help_text( __( 'Enter custom CSS here.', 'scrollsequence' ) ),
357 Field::make( "multiselect", "scrollsequence_debug_multi", __( "Show Development Information", 'scrollsequence' ) )->add_options( $debug_multi_options_array ),
358 ) );
359 /*
360 * SIDE CONTEXT - ADVANCED SETTINGS
361 */
362 Container::make( 'post_meta', 'Custom Post Settings' )->where( 'post_type', '=', 'scrollsequence' )->set_context( 'side' )->set_priority( 'low' )->add_fields( array(
363 Field::make( 'color', 'scrollsequence_bodybgcolor', __( 'Body Background Color', 'scrollsequence' ) )->help_text( __( 'Set CSS attribute <i><strong>background-color</strong></i> of <i><strong>body.single-scrollsequence</strong></i> class.', 'scrollsequence' ) ),
364 // Field::make( 'color', 'scrollsequence_classic_content_after_bgcolor', __( 'Background Color - After Scrollsequence' ) )
365 // ->help_text('Use in case you want to have different background color after the scrollsequence is finished. Only active when there is content after the image sequence. ')
366 // ,
367 Field::make( 'checkbox', 'scrollsequence_show_sidebar', __( 'Show Sidebar', 'scrollsequence' ) )->set_option_value( 'yes' )->help_text( __( 'Experimental, take care', 'scrollsequence' ) ),
368 Field::make( 'checkbox', 'scrollsequence_show_footer', __( 'Show Footer', 'scrollsequence' ) )->set_option_value( 'yes' )->help_text( __( 'Experimental, take care. <br>(This setting displays footer element and changes z-index to 9999)', 'scrollsequence' ) ),
369 ) );
370 }
371
372 // END OF CARBON FIELD MAIN FUNCTION (CPT)
373 /**
374 * ROADM Alert Too Many Pages and Images
375 *
376 * @since 0.7.4
377 */
378 public function scrollsequence_admin_notice()
379 {
380 // Ak: I want to add an IF statement to add admin notice only to scrollsequence post php
381 global $post_type ;
382 global $pagenow ;
383
384 if ( $pagenow == 'post.php' && 'scrollsequence' == $post_type || $pagenow == 'post-new.php' && 'scrollsequence' == $post_type ) {
385 echo '<div class="notice notice-warning" id="scrollsequence_notice_toomanyimg" style="display:none" ><p>' . __( 'Warning: Image limit reached. For performance reasons, free version allows maximum of 100 images on a single page. Images marked with "X" will not be displayed.', 'scrollsequence' ) . ' <a href="' . admin_url( 'admin.php?page=scrollsequence-pricing' ) . '">' . __( 'Upgrade to display unlimited images in your Scrollsequence', 'scrollsequence' ) . '</a>.</p></div>' ;
386 echo '<div class="notice notice-warning" id="scrollsequence_notice_toomanypages" style="display:none" ><p>' . __( 'Warning: Scene limit reached. For performance reasons, free version allows maximum of 3 scenes.', 'scrollsequence' ) . ' <a href="' . admin_url( 'admin.php?page=scrollsequence-pricing' ) . '">' . __( 'Upgrade to display unlimited scenes in your Scrollsequence', 'scrollsequence' ) . ' </a>.</p></div>' ;
387 }
388
389 // Ak: end
390 }
391
392 /**
393 * Classic Content Editor Heading
394 *
395 * @since 0.9.94
396 */
397 /* OBSOLETE
398 <h2><strong> Shortcode options:</strong> </h2>
399 <p><i>[scrollsequence margintop="-200px"]</i> Animation will have a 200px overlap. Useful when you have a gap at the top where animation starts.</p>
400 <p><i>[scrollsequence marginbottom="-600px"]</i> Animation will have a 600px overlap. Useful when you want to seamlessly join content after the animation ends.</p>
401 */
402 public function scrollsequence_classic_content_html()
403 {
404 // Ak: I want to add an IF statement to add admin notice only to scrollsequence post php
405 global $post_type ;
406 global $pagenow ;
407 if ( $pagenow == 'post.php' && 'scrollsequence' == $post_type || $pagenow == 'post-new.php' && 'scrollsequence' == $post_type ) {
408 // IF Condition Changed 1.0.076
409 echo __( '<h1>Content Editor </h1>
410 <p><strong>Place shortcode <i>[scrollsequence]</i> anywhere in the classic content to control image sequence position.<br> If not specified <i>[scrollsequence]</i> shortcode will be placed at the start of content automatically, rendering the image sequence at the begining of the page. </strong></p>', 'scrollsequence' ) . '
411
412 ' ;
413 }
414 // Ak: end
415 }
416
417 /**
418 * Function that makes the scrollsequence shortcode happen..
419 *
420 * Shortcode: [scrollsequence id="###"]
421 *
422 *
423 * @since 0.9.95
424 */
425 public function scrollsequence_shortcode( $atts )
426 {
427 // Extract atts
428 extract( shortcode_atts( array(
429 'id' => get_the_id(),
430 'margintop' => 0,
431 'marginbottom' => 0,
432 'hide' => false,
433 ), $atts ) );
434 // Get info from database
435 $ssqInputZeroObject = array(
436 'debug' => carbon_get_post_meta( $id, 'scrollsequence_debug_multi' ),
437 'show_footer' => carbon_get_post_meta( $id, 'scrollsequence_show_footer' ),
438 'show_sidebar' => carbon_get_post_meta( $id, 'scrollsequence_show_sidebar' ),
439 'preloadPercentage' => esc_attr( get_option( 'ssq_option_preload_percentage', 0.12 ) ),
440 'ssqFyiId' => $id,
441 'siteUrl' => get_option( 'siteurl' ),
442 );
443 $ssqInputObject = array(
444 'ssqId' => $id,
445 'bodyBgColor' => carbon_get_post_meta( $id, 'scrollsequence_bodybgcolor' ),
446 'imageOpacity' => carbon_get_post_meta( $id, 'scrollsequence_image_opacity' ),
447 'scrub' => (double) carbon_get_post_meta( $id, 'scrollsequence_scrub' ),
448 'forceFullWidth' => carbon_get_post_meta( $id, 'scrollsequence_image_full_width' ),
449 'zIndex' => carbon_get_post_meta( $id, 'scrollsequence_image_zindex' ),
450 'triggerStart' => carbon_get_post_meta( $id, 'scrollsequence_trigger_start' ),
451 'triggerEnd' => carbon_get_post_meta( $id, 'scrollsequence_trigger_end' ),
452 'canvasDPR' => esc_attr( get_option( 'ssq_option_canvas_dpr', 'quality' ) ),
453 );
454 // Rename info from database in JS format
455 $ssqInputObject['page'] = array();
456 $ssqPageFromUI = carbon_get_post_meta( $id, 'scrollsequence_page' );
457 foreach ( $ssqPageFromUI as $x => $val ) {
458 $ssqInputObject['page'][$x]['alignX']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_alignx_desktop'];
459 $ssqInputObject['page'][$x]['alignX']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_alignx_mobile'];
460 $ssqInputObject['page'][$x]['alignY']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_aligny_desktop'];
461 $ssqInputObject['page'][$x]['alignY']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_aligny_mobile'];
462 // $ssqInputObject['page'][$x]['pageDuration']= (float)$ssqPageFromUI[$x]['scrollsequence_p_duration'];
463 $ssqInputObject['page'][$x]['imgDur'] = (double) $ssqPageFromUI[$x]['scrollsequence_p_imgdur'];
464 $ssqInputObject['page'][$x]['scaleTo']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_scaleto_desktop'];
465 $ssqInputObject['page'][$x]['scaleTo']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_scaleto_mobile'];
466 // Loop Through Anim
467 $ssqInputObject['page'][$x]['animEl'] = array();
468 // in case of empty
469 foreach ( $ssqPageFromUI[$x]['ssqnce_anim'] as $z => $animvar ) {
470 $ssqInputObject['page'][$x]['animEl'][$z] = $ssqPageFromUI[$x]['ssqnce_anim'][$z];
471 }
472 }
473 // If there is "hide" parameter -> enqueue mobile detect script and act based on parameter values.
474
475 if ( $hide ) {
476 $showDetectNotice = in_array( "detectdebug", carbon_get_post_meta( $id, 'scrollsequence_debug_multi' ) );
477 //echo '<!--Scrollsequence - Hide Parameter Exists: -->';
478 require_once 'mobile_detect/mobile_detect.php';
479 $detect = new Mobile_Detect();
480 // var_dump($detect);
481 // Any mobile device (phones or tablets).
482 if ( $detect->isMobile() && str_contains( strtolower( $hide ), 'ismobile' ) ) {
483 return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isMobile </div>';
484 }
485 if ( !$detect->isMobile() && str_contains( strtolower( $hide ), 'isnotmobile' ) ) {
486 return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isNotMobile </div>';
487 }
488 // Any tablet device.
489 if ( $detect->isTablet() && str_contains( strtolower( $hide ), 'istablet' ) ) {
490 return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isTablet </div>';
491 }
492 if ( !$detect->isTablet() && str_contains( strtolower( $hide ), 'isnottablet' ) ) {
493 return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isNotTablet </div>';
494 }
495 // Exclude tablets.
496 if ( $detect->isMobile() && !$detect->isTablet() && str_contains( strtolower( $hide ), 'isphone' ) ) {
497 return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isPhone </div>';
498 }
499 if ( !($detect->isMobile() && !$detect->isTablet()) && str_contains( strtolower( $hide ), 'isnotphone' ) ) {
500 return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isNotPhone </div>';
501 }
502 // Check for a specific platform with the help of the magic methods:
503 if ( $detect->isiOS() && str_contains( strtolower( $hide ), 'isios' ) ) {
504 return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isiOs </div>';
505 }
506 if ( !$detect->isiOS() && str_contains( strtolower( $hide ), 'isnotios' ) ) {
507 return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isNotiOs </div>';
508 }
509 if ( $detect->isAndroidOS() && str_contains( strtolower( $hide ), 'isandroidos' ) ) {
510 return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isAndroidOs </div>';
511 }
512 if ( !$detect->isAndroidOS() && str_contains( strtolower( $hide ), 'isnotandroidos' ) ) {
513 return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isNotAndroidOs </div>';
514 }
515 }
516
517 // FREE
518 foreach ( $ssqPageFromUI as $x => $val ) {
519 // Loop Through IMAGES
520 $ssqInputObject['page'][$x]['imagesFull'] = array( plugin_dir_url( __DIR__ ) . 'public/img/noimg.jpg' );
521 //if empty
522
523 if ( function_exists( 'get_rocket_cdn_url' ) ) {
524 foreach ( $ssqPageFromUI[$x]['scrollsequence_p_images'] as $y => $imgvar ) {
525 $ssqInputObject['page'][$x]['imagesFull'][$y] = get_rocket_cdn_url( wp_get_attachment_image_src( $ssqPageFromUI[$x]['scrollsequence_p_images'][$y], 'full' )[0] );
526 }
527 } else {
528 foreach ( $ssqPageFromUI[$x]['scrollsequence_p_images'] as $y => $imgvar ) {
529 $ssqInputObject['page'][$x]['imagesFull'][$y] = wp_get_attachment_image_src( $ssqPageFromUI[$x]['scrollsequence_p_images'][$y], 'full' )[0];
530 }
531 }
532
533 $ssqInputObject['page'][$x]['imagesFull'] = array_splice( $ssqInputObject['page'][$x]['imagesFull'], 0, 100 );
534 }
535 // Calculate lengths, spacers and absSpacers (SC is calculated in JS)
536 $ssqInputObject['pageLength'] = count( $ssqInputObject['page'] );
537 $ssqInputObject['scSpacer'] = 0;
538 $pageAbsSpacerTotal = 0;
539 foreach ( $ssqPageFromUI as $x => $val ) {
540 $ssqInputObject['page'][$x]['imagesLength'] = count( $ssqInputObject['page'][$x]['imagesFull'] );
541 $ssqInputObject['page'][$x]['animElLength'] = count( $ssqInputObject['page'][$x]['animEl'] );
542 $ssqInputObject['page'][$x]['pageSpacer'] = $ssqInputObject['page'][$x]['imagesLength'] * $ssqInputObject['page'][$x]['imgDur'];
543 $ssqInputObject['scSpacer'] = $ssqInputObject['scSpacer'] + $ssqInputObject['page'][$x]['pageSpacer'];
544 $ssqInputObject['page'][$x]['pageAbsBegin'] = $pageAbsSpacerTotal;
545 $pageAbsSpacerTotal = $pageAbsSpacerTotal + $ssqInputObject['page'][$x]['pageSpacer'];
546 $ssqInputObject['page'][$x]['pageAbsEnd'] = $pageAbsSpacerTotal;
547 }
548 // Sticky JS/CSS or Static - Deal with all here early on. - Since 1.3.0
549 $stickyOptionFromSettings = get_option( 'ssq_option_position_sticky', 'sticky-js' );
550 // second argument must be the same as default value, it needs to be here to cover if null
551
552 if ( carbon_get_post_meta( $id, 'scrollsequence_position' ) == 'sticky' && $stickyOptionFromSettings == 'sticky-js' ) {
553 // sticky js
554 $ssqInputObject['position'] = 'sticky-js';
555 $stickyStyle = 'position:relative;box-sizing: border-box;';
556 $ssqDomSpacer = $ssqInputObject['scSpacer'];
557 $ssqWrapStylePosition = '';
558 $absoluteScrollsequenceStyle = '';
559 } else {
560
561 if ( carbon_get_post_meta( $id, 'scrollsequence_position' ) == 'sticky' && $stickyOptionFromSettings == 'sticky-css' ) {
562 // sticky css
563 $ssqInputObject['position'] = 'sticky-css';
564 $stickyStyle = 'position: -webkit-sticky;position:sticky;top:0;box-sizing: border-box;';
565 $ssqDomSpacer = $ssqInputObject['scSpacer'];
566 $ssqWrapStylePosition = '';
567 $absoluteScrollsequenceStyle = '';
568 } else {
569
570 if ( carbon_get_post_meta( $id, 'scrollsequence_position' ) == 'absolute' && $stickyOptionFromSettings == 'sticky-js' ) {
571 // sticky js
572 $ssqInputObject['position'] = 'sticky-js';
573 $stickyStyle = 'position:relative;box-sizing: border-box;';
574 $ssqDomSpacer = $ssqInputObject['scSpacer'];
575 $ssqWrapStylePosition = 'position:absolute;';
576 $absoluteScrollsequenceStyle = 'style="display:block;position:relative;"';
577 } else {
578
579 if ( carbon_get_post_meta( $id, 'scrollsequence_position' ) == 'absolute' && $stickyOptionFromSettings == 'sticky-css' ) {
580 // sticky css
581 $ssqInputObject['position'] = 'sticky-css';
582 $stickyStyle = 'position: -webkit-sticky;position:sticky;top:0;box-sizing: border-box;';
583 $ssqDomSpacer = $ssqInputObject['scSpacer'];
584 $ssqWrapStylePosition = 'position:absolute;';
585 $absoluteScrollsequenceStyle = 'style="display:block;position:relative;"';
586 } else {
587 // static
588 //$ssqInputObject['carbongetpostmetascrollsequenceposition'] = carbon_get_post_meta( $id, 'scrollsequence_position');
589 //$ssqInputObject['get_optionssqoptionpositionsticky'] =$stickyOptionFromSettings;
590 $ssqInputObject['position'] = 'static';
591 $stickyStyle = 'position:relative;box-sizing: border-box; ';
592 $ssqDomSpacer = 0;
593 $ssqWrapStylePosition = '';
594 $absoluteScrollsequenceStyle = 'style="display:block;position:relative;"';
595 }
596
597 }
598
599 }
600
601 }
602
603 // Localize/Inline Script
604 static $ssqScCount = 0 ;
605
606 if ( !$ssqScCount ) {
607 // First run we need to declare variable and input
608 $inlineData = 'var ssqInput={};
609 ssqInput=' . json_encode( $ssqInputZeroObject ) . ';
610 ssqInput.sc=[];
611 ssqInput.sc[' . $ssqScCount . ']=' . json_encode( $ssqInputObject ) . ';';
612 } else {
613 // All other runs just input
614 $inlineData = 'ssqInput.sc[' . $ssqScCount . ']=' . json_encode( $ssqInputObject ) . ';';
615 }
616
617 wp_enqueue_script( 'scrollsequence-lib' );
618 // Prepare for returning onlyonece HTML
619
620 if ( !$ssqScCount ) {
621 // First run
622 $onlyonceHtml = '
623
624 <style>
625 .scrollsequence-pages-wrap {height:100vh}
626 .scrollsequence-page {position:absolute;display:none}
627
628 .gsap-marker-scroller-start {z-index:999999!important;}
629 </style>
630 <noscript>
631 <style>
632 .scrollsequence-wrap {height:initial!important;}
633 .scrollsequence-pages-wrap {height:initial}
634 .scrollsequence-page {position:relative;opacity:initial;display:block ;visibility:initial}
635 </style>
636 </noscript>
637
638 <div style="position: fixed;z-index:99999;bottom:50px;left: 100px;background:#383131b0;color:white; padding: 0.5rem; display:none" class="ssq-alert-container" id="ssqalert" >
639 </div>
640
641 ';
642 } else {
643 $onlyonceHtml = '';
644 }
645
646 //all other runs
647 // Style for each SC
648 $customCssVar = '';
649 if ( !empty(carbon_get_post_meta( $id, 'scrollsequence_custom_css' )) ) {
650 $customCssVar = '
651 <style>
652 ' . carbon_get_post_meta( $id, 'scrollsequence_custom_css' ) . '
653 </style>
654 ';
655 }
656 // end of if not empty
657 // Prepare for returning pages html
658 $pagesHtml = array();
659 foreach ( $ssqPageFromUI as $p => $pagevar ) {
660 /**
661 * Filter Stuff
662 * Since 1.1.2.
663 * Inspired from: https://wordpress.stackexchange.com/questions/134582/apply-filtersthe-content-content-alternative
664 * List of standard filters for the_content
665 * source: https://core.trac.wordpress.org/browser/tags/5.7.2/src/wp-includes/default-filters.php#L131
666 * search for "the_content" to find what things are applied as standard
667 */
668 $filterSsqPageContent = do_blocks( $ssqPageFromUI[$p]['scrollsequence_p_wysiwyg'] );
669 // priority 9 // Introduced 5.0
670 $filterSsqPageContent = wptexturize( $filterSsqPageContent );
671 // Introduced 0.71
672 $filterSsqPageContent = wpautop( $filterSsqPageContent );
673 // Introduced 0.71
674 $filterSsqPageContent = do_shortcode( $filterSsqPageContent );
675 // Introduced 2.5
676 $filterSsqPageContent = shortcode_unautop( $filterSsqPageContent );
677 // Introduced in 2.9
678 $filterSsqPageContent = prepend_attachment( $filterSsqPageContent );
679 // Introduced in 2.0
680 // $filterSsqPageContent = wp_filter_content_tags($filterSsqPageContent); // Introducted in 5.5 - cannot use (yet)
681 // $filterSsqPageContent = wp_replace_insecure_home_url($filterSsqPageContent); // Introducted WP 5.7 - cannot use (yet)
682 $filterSsqPageContent = convert_smilies( $filterSsqPageContent );
683 // priority 20? // Introduced longtimeago
684 // Page HTML
685 $pagesHtml[$p] = '
686 <div class="scrollsequence-page" id="ssq-page-' . $ssqScCount . '-' . $p . '" style="box-sizing: border-box;height:100vh;width:100%;overflow:hidden!important;">
687 ' . $filterSsqPageContent . '
688 </div>
689 ';
690 }
691 // return
692 $returnvar = '
693
694 <!-- Scrollsequence WP Plugin -->
695 <scrollsequence ' . $absoluteScrollsequenceStyle . '>
696 ' . $onlyonceHtml . $customCssVar . '
697 <section class="scrollsequence-wrap ssq-wrap-' . $ssqScCount . ' " id="ssq-uid-' . get_the_id() . '-' . $ssqScCount . '-' . $id . '" style="' . $ssqWrapStylePosition . ';height: calc(100vh + ' . $ssqDomSpacer . 'px);padding:0;margin:0; margin-top:' . $margintop . ';margin-bottom:' . $marginbottom . '; width:100%; max-width:initial;box-sizing: border-box;border:-1px dashed blue;">
698 <div class="scrollsequence-sticky" style="' . $stickyStyle . '">
699 <canvas class="scrollsequence-canvas" style="position:absolute;"></canvas>
700 <div class="scrollsequence-pages-wrap" style="position:relative; margin:0; padding:0; box-sizing: border-box;">
701 ' . implode( " ", $pagesHtml ) . '
702 </div>
703 </div><!-- .scrollsequence-sticky -->
704
705
706 </section><!-- .scrollsequence-wrap -->
707 ' . '<script class="scrollsequence-input-script">
708 ' . $inlineData . '
709 </script>
710 </scrollsequence>
711 ';
712 // Free
713 $ssqScCount++;
714
715 if ( $ssqScCount <= 1 ) {
716 return $returnvar;
717 } else {
718 return '<section><h5 style="border:2px solid; padding:20px">' . __( 'For performance reasons only one shortcode is allowed in Scrollsequence FREE.', 'scrollsequence' ) . '<br><br> <a href="' . admin_url( 'admin.php?page=scrollsequence-pricing' ) . '">' . __( 'Upgrade to PRO version for unlimited shortcodes.', 'scrollsequence' ) . '</a> </h5></section>';
719 }
720
721 // end of else count other than zero
722 // end of free
723 }
724
725 // end of scrollsequence_shortcode function
726 /**
727 * Add Columns to Custom Post Type List
728 *
729 *
730 */
731 function scrollsequence_admin_columns( $columns )
732 {
733 $columns = array(
734 'cb' => $columns['cb'],
735 'title' => __( 'Title', 'scrollsequence' ),
736 'ssq_shortcode' => __( 'Shortcode', 'scrollsequence' ),
737 'date' => __( 'Date', 'scrollsequence' ),
738 'author' => __( 'Author', 'scrollsequence' ),
739 );
740 return $columns;
741 }
742
743 function scrollsequence_admin_column_content( $column, $id )
744 {
745 if ( 'ssq_shortcode' == $column ) {
746 echo '[scrollsequence id="' . $id . '"]' ;
747 }
748 }
749
750 /**
751 * Admin Columns - FEATURED IMAGE
752 *
753 * Since 1.2.0
754 *
755 *
756 */
757 function ssq_add_thumbnail_column( $columns )
758 {
759 $columns['ssq_post_thumb'] = __( 'Featured Image', 'scrollsequence' );
760 return $columns;
761 }
762
763 function ssq_display_thumbnail_column( $column_name, $post_id )
764 {
765 switch ( $column_name ) {
766 case 'ssq_post_thumb':
767 $post_thumbnail_id = get_post_thumbnail_id( $post_id );
768
769 if ( $post_thumbnail_id ) {
770 $post_thumbnail_img = wp_get_attachment_image_src( $post_thumbnail_id, 'thumbnail' );
771 echo '<img width="64" src="' . $post_thumbnail_img[0] . '" />' ;
772 } else {
773 // no thumbnail, try to use something else
774 $idOfFirstImage = carbon_get_post_meta( get_the_ID(), 'scrollsequence_page' );
775 //var_dump($idOfFirstImage);
776 // Check that is array check that images is array and finally check that count of images is bigger than one.
777
778 if ( is_array( $idOfFirstImage ) && count( $idOfFirstImage ) > 0 && is_array( $idOfFirstImage[0]['scrollsequence_p_images'] ) && count( $idOfFirstImage[0]['scrollsequence_p_images'] ) > 0 ) {
779 // first image in sequence exists
780 echo '<img width="64" src="' . wp_get_attachment_image_src( $idOfFirstImage[0]['scrollsequence_p_images'][0], 'thumbnail' )[0] . '" />' ;
781 } else {
782 // there are no images here
783 echo 'No Image' ;
784 }
785
786 }
787
788 break;
789 }
790 }
791
792 /**
793 * Register Settings Options in Scrollsequence Options Dashboard
794 *
795 * @since 1.1.1
796 */
797 function scrollsequence_register_options_settings()
798 {
799 // whitelist options
800 register_setting( 'scrollsequence-settings-group', 'ssq_option_preload_percentage', array(
801 'default' => 0.12,
802 ) );
803 register_setting( 'scrollsequence-settings-group', 'ssq_option_position_sticky', array(
804 'default' => 'sticky-js',
805 ) );
806 // since 1.3.0
807 register_setting( 'scrollsequence-settings-group', 'ssq_option_canvas_dpr', array(
808 'default' => 'quality',
809 ) );
810 // since 1.3.3
811 // TODO
812 // register_setting( 'scrollsequence-settings-group', 'ssq_option_scroller_proxy' ); // not implemented yet
813 // register_setting( 'scrollsequence-settings-group', 'ssq_option_elementor_widget' ); // not implemented yet
814 }
815
816 /**
817 * DUPLICATE SCROLLSEQUENCE
818 * @snippet Duplicate posts and pages without plugins
819 * @author Misha Rudrastyh
820 * @url https://rudrastyh.com/wordpress/duplicate-post.html
821 *
822 */
823 // Add the duplicate link to action list for post_row_actions for "post" and custom post types
824 function ssq_duplicate_post_link( $actions, $post )
825 {
826 if ( !current_user_can( 'edit_posts' ) ) {
827 return $actions;
828 }
829 if ( $post->post_type !== 'scrollsequence' ) {
830 return $actions;
831 }
832 $url = wp_nonce_url( add_query_arg( array(
833 'action' => 'duplicate_scrollsequence_as_draft',
834 'post' => $post->ID,
835 ), 'admin.php' ), basename( __FILE__ ), 'duplicate_ssq_nonce' );
836 $actions['duplicate_ssq'] = '<a href="' . $url . '" title="' . __( 'Duplicate Scrollsequence' ) . '" rel="permalink">' . __( 'Duplicate' ) . '</a>';
837 return $actions;
838 }
839
840 /*
841 * Function creates post duplicate as a draft and redirects then to the edit post screen
842 */
843 function duplicate_scrollsequence_as_draft()
844 {
845 // check if post ID has been provided and action
846 if ( empty($_GET['post']) ) {
847 wp_die( 'No post to duplicate has been provided!' );
848 }
849 // Nonce verification
850 if ( !isset( $_GET['duplicate_ssq_nonce'] ) || !wp_verify_nonce( $_GET['duplicate_ssq_nonce'], basename( __FILE__ ) ) ) {
851 return;
852 }
853 // Get the original post id
854 $post_id = absint( $_GET['post'] );
855 // And all the original post data then
856 $post = get_post( $post_id );
857 /*
858 * if you don't want current user to be the new post author,
859 * then change next couple of lines to this: $new_post_author = $post->post_author;
860 */
861 $current_user = wp_get_current_user();
862 $new_post_author = $current_user->ID;
863 // if post data exists (I am sure it is, but just in a case), create the post duplicate
864
865 if ( $post ) {
866 // new post data array
867 $args = array(
868 'comment_status' => $post->comment_status,
869 'ping_status' => $post->ping_status,
870 'post_author' => $new_post_author,
871 'post_content' => $post->post_content,
872 'post_excerpt' => $post->post_excerpt,
873 'post_name' => $post->post_name,
874 'post_parent' => $post->post_parent,
875 'post_password' => $post->post_password,
876 'post_status' => 'draft',
877 'post_title' => $post->post_title . '_duplicate',
878 'post_type' => $post->post_type,
879 'to_ping' => $post->to_ping,
880 'menu_order' => $post->menu_order,
881 );
882 // insert the post by wp_insert_post() function
883 $new_post_id = wp_insert_post( $args );
884 /*
885 * get all current post terms ad set them to the new post draft
886 */
887 $taxonomies = get_object_taxonomies( get_post_type( $post ) );
888 // returns array of taxonomy names for post type, ex array("category", "post_tag");
889 if ( $taxonomies ) {
890 foreach ( $taxonomies as $taxonomy ) {
891 $post_terms = wp_get_object_terms( $post_id, $taxonomy, array(
892 'fields' => 'slugs',
893 ) );
894 wp_set_object_terms(
895 $new_post_id,
896 $post_terms,
897 $taxonomy,
898 false
899 );
900 }
901 }
902 // duplicate all post meta
903 $post_meta = get_post_meta( $post_id );
904 if ( $post_meta ) {
905 foreach ( $post_meta as $meta_key => $meta_values ) {
906 if ( '_wp_old_slug' == $meta_key ) {
907 // do nothing for this meta key
908 continue;
909 }
910 foreach ( $meta_values as $meta_value ) {
911 add_post_meta( $new_post_id, $meta_key, $meta_value );
912 }
913 }
914 }
915 // finally, redirect to the edit post screen for the new draft
916 // wp_safe_redirect(
917 // add_query_arg(
918 // array(
919 // 'action' => 'edit',
920 // 'post' => $new_post_id
921 // ),
922 // admin_url( 'post.php' )
923 // )
924 // );
925 // exit;
926 // or we can redirect to all posts with a message
927 wp_safe_redirect( add_query_arg( array(
928 'post_type' => ( 'post' !== get_post_type( $post ) ? get_post_type( $post ) : false ),
929 'saved' => 'post_duplication_created',
930 ), admin_url( 'edit.php' ) ) );
931 exit;
932 } else {
933 wp_die( 'Post creation failed, could not find original post.' );
934 }
935
936 }
937
938 /*
939 * In case we decided to add admin notices
940 */
941 function ssq_duplication_admin_notice()
942 {
943 // Get the current screen
944 $screen = get_current_screen();
945 if ( 'edit' !== $screen->base ) {
946 return;
947 }
948 //Checks if settings updated
949 if ( isset( $_GET['saved'] ) && 'post_duplication_created' == $_GET['saved'] ) {
950 echo '<div class="notice notice-success is-dismissible"><p>' . __( 'Copy created.' ) . '</p></div>' ;
951 }
952 }
953
954 // end of duplicate
955 /**
956 * This function defines helpscout beacon
957 *
958 *
959 */
960 public function ssq_add_helpscout_beacon()
961 {
962 global $post_type ;
963 //var_dump($post_type);
964 global $pagenow ;
965 //var_dump($pagenow);
966
967 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' ) {
968 // Inline Script on admin screen - not ready yet, too few articles in the thing.
969 ?>
970 <script type="text/javascript">!function(e,t,n){function a(){var e=t.getElementsByTagName("script")[0],n=t.createElement("script");n.type="text/javascript",n.async=!0,n.src="https://beacon-v2.helpscout.net",e.parentNode.insertBefore(n,e)}if(e.Beacon=n=function(t,n,a){e.Beacon.readyQueue.push({method:t,options:n,data:a})},n.readyQueue=[],"complete"===t.readyState)return a();e.attachEvent?e.attachEvent("onload",a):e.addEventListener("load",a,!1)}(window,document,window.Beacon||function(){});</script>
971 <script type="text/javascript">window.Beacon('init', '751bcab8-88ed-4f04-9255-788822978f93')</script>
972 <?php
973 }
974
975 }
976
977 }
978 // end of class Scrollsequence_Admin