_notices = WOODMART_Registry()->notices; $this->_options = woodmart_get_config( 'wpbcss-parts' ); } private function _get_options_from_section( $section ) { return array_filter( $this->_options, function( $el ) use ( $section ) { return $el['section'] == $section; } ); } private function _checked( $opt ) { $checked = $opt['checked']; if ( isset( $_POST['generate-css'] ) ) { $checked = isset( $_POST[ $opt['id'] ] ) && $_POST[ $opt['id'] ]; } $css_data = $this->_get_data(); if ( ! empty( $css_data ) && is_array( $css_data ) ) { $checked = isset( $css_data[ $opt['id'] ] ) && $css_data[ $opt['id'] ]; } checked( $checked ); } private function _render_option( $opt ) { ?>
_checked( $opt ); ?> value="true"> _render_children( $opt['id'] ); ?>
_get_children( $id ); if ( empty( $children ) ) { return; } echo '
'; foreach ( $children as $id => $option ) { $this->_render_option( $option ); } echo '
'; } private function _get_children( $id ) { return array_filter( $this->_options, function( $el ) use ( $id ) { return isset( $el['parent'] ) && $el['parent'] == $id; } ); } private function _render_section( $name ) { foreach ( $this->_get_options_from_section( $name ) as $id => $option ) { if ( ! isset( $option['parent'] ) ) { $this->_render_option( $option ); } } } public function form() { $this->process_form(); $file = get_option( 'woodmart-generated-wpbcss-file' ); $theme = wp_get_theme( get_template() ); ?>

_notices->show_msgs(); ?>

Basic elements

_render_section( 'Basic elements' ); ?>

Galleries

_render_section( 'Galleries' ); ?>

Extras

_render_section( 'Extras' ); ?>
'Version' ) ) : array(); $version = isset( $data['Version'] ) ? $data['Version'] : 'unknown'; ?>

Custom CSS file is generated

File:
CSS Version:
Actual version:
_notices->add_warning( 'Wrong data sent. Try to resend the form.' ); return; } if ( ! $css_data = json_decode( $json, true ) ) { $this->_notices->add_warning( 'Wrong JSON data format. Try to resend the form.' ); return; } /* you can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ $creds = request_filesystem_credentials( false, '', false, false, array_keys( $_POST ) ); if ( ! $creds ) { return; } /* initialize the API */ if ( ! WP_Filesystem( $creds ) ) { /* any problems and we exit */ $this->_notices->add_warning( 'Can\'t access your file system. The FTP access is wrong.' ); return false; } global $wp_filesystem; $wpb_url = ''; if ( defined( 'WPB_PLUGIN_FILE' ) ) { $wpb_url = plugins_url( 'assets', WPB_PLUGIN_FILE ); } $response = wp_remote_get( $this->_generator_url . '?generate_css=' . $data . '&wpbakery=1&wpb_url=' . urlencode( $wpb_url ) . '/', array( 'timeout' => 30 ) ); // ar( $response ); // return; if ( ! is_array( $response ) ) { $this->_notices->add_warning( 'Can\'t call xtemos server to generate the file.' ); return false; } $header = $response['headers']; // array of http header lines $css = $response['body']; // use the content $t = time(); $file_name = $uploads['subdir'] . '/' . 'js_composer-' . $t . '.css'; $file_path = $uploads['basedir'] . '/' . $file_name; $res = $wp_filesystem->put_contents( $file_path, $css ); if ( $res ) { $upload = array( 'name' => $file_name, ); $file = get_option( 'woodmart-generated-wpbcss-file' ); if ( isset( $file['name'] ) && $file['name'] ) { $file_path = $uploads['basedir'] . '/' . $file['name']; $wp_filesystem->delete( $file_path ); } update_option( 'woodmart-generated-wpbcss-file', $upload ); update_option( 'woodmart-wpbcss-data', $css_data ); $this->_notices->add_success( 'New CSS file is generated and saved.' ); } else { $this->_notices->add_warning( 'Can\'t move file to uploads folder with wp_filesystem class.' ); return false; } } private function _get_data() { $css_data = get_option( 'woodmart-wpbcss-data', array() ); return $css_data; } }