PluginProbe
Assistant – Every Day Productivity Apps / 1.5.1
Assistant – Every Day Productivity Apps v1.5.1
1.5.5 trunk 0.1.0 0.2.0 0.2.1 0.2.2 0.3.0 0.3.1 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.6.0 0.7.0 0.7.0.2 0.7.0.3 0.7.0.4 0.7.0.5 0.7.0.6 0.7.0.7 0.7.0.8 0.7.0.9 0.7.1 1.0 All 71 releases
assistant / backend / src / Hooks / PostPreview.php

PostPreview.php in Assistant – Every Day Productivity Apps 1.5.1, at backend/src/Hooks/PostPreview.php

107 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FL\Assistant\Hooks;
4
5 class PostPreview {
6
7 protected $post_id;
8
9 public function __construct() {
10 if ( isset( $_GET['fl_asst_post_preview'] ) ) {
11 if ( isset( $_GET['p'] ) ) {
12 $this->post_id = absint( $_GET['p'] );
13 } elseif ( isset( $_GET['page_id'] ) ) {
14 $this->post_id = absint( $_GET['page_id'] );
15 }
16
17 if ( $this->post_id ) {
18 add_action( 'parse_query', [ $this, 'parse_query' ], PHP_INT_MAX );
19 add_filter( 'redirect_canonical', '__return_false', PHP_INT_MAX );
20 }
21 }
22
23 if ( isset( $_GET['fl_asst_screenshot'] ) ) {
24 add_filter( 'body_class', [ $this, 'body_class' ] );
25 show_admin_bar( false );
26
27 if ( $this->post_id ) {
28 add_action( 'wp', [ $this, 'disable_known_theme_parts' ], PHP_INT_MAX );
29 }
30 }
31 }
32
33 public function parse_query( $query ) {
34 if ( $query->is_main_query() ) {
35 if ( current_user_can( 'edit_others_posts' ) ) {
36 add_filter( 'posts_results', [ $this, 'override_posts_results' ], PHP_INT_MAX );
37 }
38 }
39 }
40
41 public function override_posts_results( $posts ) {
42 remove_filter( 'posts_results', [ $this, 'override_posts_results' ], PHP_INT_MAX );
43
44 $preview = get_post( $this->post_id );
45 $preview->post_status = 'publish';
46
47 return [ $preview ];
48 }
49
50 public function disable_known_theme_parts() {
51 $this->disable_bb_theme();
52 $this->disable_bb_themer();
53 $this->disable_generate_press();
54 $this->disable_genesis();
55 }
56
57 public function body_class( $classes ) {
58 $classes[] = 'fl-asst-screenshot';
59 return $classes;
60 }
61
62 protected function disable_bb_theme() {
63 add_filter( 'fl_topbar_enabled', '__return_false' );
64 add_filter( 'fl_fixed_header_enabled', '__return_false' );
65 add_filter( 'fl_header_enabled', '__return_false' );
66 add_filter( 'fl_footer_enabled', '__return_false' );
67 }
68
69 protected function disable_bb_themer() {
70 if ( ! defined( 'FL_THEME_BUILDER_VERSION' ) ) {
71 return;
72 }
73
74 $is_header = \FLThemeBuilderLayoutData::current_post_is( 'header' );
75 $is_footer = \FLThemeBuilderLayoutData::current_post_is( 'footer' );
76 $is_part = \FLThemeBuilderLayoutData::current_post_is( 'part' );
77
78 if ( ! $is_header ) {
79 remove_all_actions( 'fl_before_header' );
80 }
81 if ( ! $is_footer ) {
82 remove_all_actions( 'fl_after_content' );
83 }
84 if ( $is_header || $is_footer || $is_part ) {
85 add_action( 'wp_print_scripts', function() {
86 echo '<style>.fl-asst-screenshot .fl-theme-builder-content-placeholder { display: none; }</style>';
87 } );
88 }
89 }
90
91 protected function disable_generate_press() {
92 remove_action( 'generate_header', 'generate_construct_header' );
93 remove_action( 'generate_after_header', 'generate_add_navigation_after_header', 5 );
94 remove_action( 'generate_footer', 'generate_construct_footer_widgets', 5 );
95 remove_action( 'generate_footer', 'generate_construct_footer' );
96 }
97
98 protected function disable_genesis() {
99 remove_action( 'genesis_header', 'genesis_header_markup_open', 5 );
100 remove_action( 'genesis_header', 'genesis_do_header' );
101 remove_action( 'genesis_header', 'genesis_header_markup_close', 15 );
102 remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 );
103 remove_action( 'genesis_footer', 'genesis_do_footer' );
104 remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 );
105 }
106 }
107