PluginProbe
Scrollsequence – Cinematic Scroll Image Animation Plugin / 1.5.5
Scrollsequence – Cinematic Scroll Image Animation Plugin v1.5.5
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.5.5, at admin/class-scrollsequence-admin.php

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