PluginProbe
Gutenify – Visual Site Builder Blocks & Starter Templates / 1.1.1
Gutenify – Visual Site Builder Blocks & Starter Templates v1.1.1
1.9.0 1.8.0 1.7.0 1.6.6 1.6.5 1.6.4 trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 All 74 releases
gutenify / inc / class-actions.php

class-actions.php in Gutenify – Visual Site Builder Blocks & Starter Templates 1.1.1, at inc/class-actions.php

103 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Actions functions
4 *
5 * @package Gutenify
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Class Gutenify_Actions
14 */
15 class Gutenify_Actions {
16
17 /**
18 * Gutenify_Actions constructor.
19 */
20 public function __construct() {
21 add_action( 'use_block_editor_for_post_type', array( $this, 'disable_gutenberg' ), 10, 2 );
22 add_filter( 'gutenify_skip_gutenburg_post_type', array( $this, 'skip_gutenburg_post_type' ) );
23
24 add_action(
25 'save_post',
26 function( $post_id, $post ) {
27 // If this is just a revision, don't send the email.
28 if ( wp_is_post_revision( $post_id ) ) {
29 return;
30 }
31
32 $data = json_decode( file_get_contents( 'php://input' ), true );
33 // error_log( print_r( $data, true ) );
34 if ( ! empty( $data['meta']['gutenify_custom_css'] ) ) {
35 $name = 'post-' . $post_id;
36 if ( 'wp_template_parts' === $post->post_type ) {
37 $name = 'part-' . $post_id;
38 }
39 if ( $this->create_styles_folder() ) {
40 $this->create_styles_file( $name, gutenify_minimize_css_simple( $data['meta']['gutenify_custom_css'] ) );
41 }
42 }
43 },
44 10,
45 2
46 );
47 }
48
49 /**
50 * Disable gutenber on post type.
51 *
52 * @param boolean $is_enabled If editor is enabled.
53 * @param string $post_type Post type name.
54 * @return boolean
55 */
56 public function disable_gutenberg( $is_enabled, $post_type ) {
57 $skip_gutenburg = apply_filters( 'gutenify_skip_gutenburg_post_type', array() );
58 if ( ! in_array( $post_type, $skip_gutenburg, true ) ) {
59 $settings = gutenify_settings();
60 $active_post_types = ! empty( $settings['active_post_types'] ) ? $settings['active_post_types'] : array();
61 if ( ! in_array( $post_type, $active_post_types, true ) ) {
62 return false;
63 }
64 }
65 return $is_enabled;
66 }
67
68 /**
69 * Post types to skip the options.
70 *
71 * @param array $post_types Post types.
72 * @return array
73 */
74 public function skip_gutenburg_post_type( $post_types ) {
75 $post_types = array_merge( $post_types, array( 'attachment', 'wp_template', 'wp_block', 'gutenify_template' ) );
76 return $post_types;
77 }
78
79 public function create_styles_folder() {
80 $uploads_dir = trailingslashit( wp_upload_dir()['basedir'] ) . 'gutenify/styles';
81 if ( ! file_exists( $uploads_dir ) ) {
82 wp_mkdir_p( $uploads_dir );
83 }
84 return true;
85 // $fileLocation = $uploads_dir . '/myfile.txt';
86 // $file = fopen( $fileLocation, 'w' );
87 // $content = 'Your text here';
88 // fwrite( $file, $content );
89 // fclose( $file );
90 }
91
92 public function create_styles_file( $name, $content ) {
93 $uploads_dir = trailingslashit( wp_upload_dir()['basedir'] ) . 'gutenify/styles';
94 if ( file_exists( $uploads_dir ) ) {
95 $fileLocation = $uploads_dir . '/style-' . $name . '.css';
96 $file = fopen( $fileLocation, 'w' );
97 fwrite( $file, $content );
98 fclose( $file );
99 }
100 }
101 }
102 new Gutenify_Actions();
103