first commit without licensingg
This commit is contained in:
60
inc/gutenberg/assets.php
Normal file
60
inc/gutenberg/assets.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Assets
|
||||
*
|
||||
* All enqueues of scripts and styles.
|
||||
*
|
||||
* @package Revision
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'csco_editor_style' ) ) {
|
||||
/**
|
||||
* Add callback for custom editor stylesheets.
|
||||
*/
|
||||
function csco_editor_style() {
|
||||
// Add support for editor styles.
|
||||
add_theme_support( 'editor-styles' );
|
||||
}
|
||||
}
|
||||
add_action( 'current_screen', 'csco_editor_style' );
|
||||
|
||||
if ( ! function_exists( 'csco_enqueue_block_editor_assets' ) ) {
|
||||
/**
|
||||
* Enqueue block editor specific scripts.
|
||||
*/
|
||||
function csco_enqueue_block_editor_assets() {
|
||||
if ( ! ( is_admin() && ! is_customize_preview() ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$version = csco_get_theme_data( 'Version' );
|
||||
|
||||
// Register theme scripts.
|
||||
wp_register_script( 'cs-scripts', get_template_directory_uri() . '/assets/js/scripts.js', array( 'jquery', 'imagesloaded' ), $version, true );
|
||||
|
||||
// Localization array.
|
||||
$localize = array(
|
||||
'siteSchemeMode' => 'light',
|
||||
'siteSchemeToogle' => false,
|
||||
);
|
||||
|
||||
// Localize the main theme scripts.
|
||||
wp_localize_script( 'cs-scripts', 'csLocalize', $localize );
|
||||
|
||||
// Enqueue theme scripts.
|
||||
wp_enqueue_script( 'cs-scripts' );
|
||||
|
||||
// Register theme styles.
|
||||
wp_register_style( 'cs-editor', csco_style( get_template_directory_uri() . '/assets/css/editor-style.css' ), false, $version );
|
||||
|
||||
// Enqueue typography styles.
|
||||
csco_enqueue_typography_styles( 'cs-editor' );
|
||||
|
||||
// Add RTL support.
|
||||
wp_style_add_data( 'cs-editor', 'rtl', 'replace' );
|
||||
|
||||
// Enqueue theme styles.
|
||||
wp_enqueue_style( 'cs-editor' );
|
||||
}
|
||||
add_action( 'enqueue_block_assets', 'csco_enqueue_block_editor_assets' );
|
||||
}
|
||||
188
inc/gutenberg/editor.php
Normal file
188
inc/gutenberg/editor.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
/**
|
||||
* Editor Settings.
|
||||
*
|
||||
* @package Revision
|
||||
*/
|
||||
|
||||
/**
|
||||
* Enqueue editor scripts
|
||||
*/
|
||||
function csco_block_editor_scripts() {
|
||||
wp_enqueue_script(
|
||||
'cs-editor-scripts',
|
||||
get_template_directory_uri() . '/assets/jsx/editor-scripts.js',
|
||||
array(
|
||||
'wp-editor',
|
||||
'wp-element',
|
||||
'wp-compose',
|
||||
'wp-data',
|
||||
'wp-plugins',
|
||||
),
|
||||
csco_get_theme_data( 'Version' ),
|
||||
true
|
||||
);
|
||||
}
|
||||
add_action( 'enqueue_block_editor_assets', 'csco_block_editor_scripts' );
|
||||
|
||||
/**
|
||||
* Adds classes to <div class="editor-styles-wrapper"> tag
|
||||
*/
|
||||
function csco_block_editor_wrapper() {
|
||||
$script_handle = 'cs-editor-wrapper';
|
||||
$script_file = 'editor-wrapper.js';
|
||||
|
||||
if ( 'enqueue_block_assets' === current_filter() ) {
|
||||
if ( ! ( is_admin() && ! is_customize_preview() ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$script_handle = 'cs-editor-iframe';
|
||||
$script_file = 'editor-iframe.js';
|
||||
}
|
||||
|
||||
$post_id = get_the_ID();
|
||||
|
||||
if ( ! $post_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set post type.
|
||||
$post_type = sprintf( 'post-type-%s', get_post_type( $post_id ) );
|
||||
|
||||
// Set page layout.
|
||||
$default_layout = csco_get_page_sidebar( $post_id, 'default' );
|
||||
$page_layout = csco_get_page_sidebar( $post_id, false );
|
||||
|
||||
if ( 'disabled' === $default_layout ) {
|
||||
$default_layout = 'cs-sidebar-disabled';
|
||||
} else {
|
||||
$default_layout = 'cs-sidebar-enabled';
|
||||
}
|
||||
|
||||
if ( 'disabled' === $page_layout ) {
|
||||
$page_layout = 'cs-sidebar-disabled';
|
||||
} else {
|
||||
$page_layout = 'cs-sidebar-enabled';
|
||||
}
|
||||
|
||||
// Set breakpoints.
|
||||
$breakpoints = array(
|
||||
'cs-breakpoint-up-576px' => 576,
|
||||
'cs-breakpoint-up-768px' => 768,
|
||||
'cs-breakpoint-up-992px' => 992,
|
||||
'cs-breakpoint-up-1200px' => 1200,
|
||||
'cs-breakpoint-up-1336px' => 1336,
|
||||
'cs-breakpoint-up-1920px' => 1920,
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
$script_handle,
|
||||
get_template_directory_uri() . '/assets/jsx/' . $script_file,
|
||||
array(
|
||||
'wp-editor',
|
||||
'wp-element',
|
||||
'wp-compose',
|
||||
'wp-data',
|
||||
'wp-plugins',
|
||||
),
|
||||
csco_get_theme_data( 'Version' ),
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
$script_handle,
|
||||
'cscoGWrapper',
|
||||
array(
|
||||
'post_type' => $post_type,
|
||||
'default_layout' => $default_layout,
|
||||
'page_layout' => $page_layout,
|
||||
'breakpoints' => $breakpoints,
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'enqueue_block_editor_assets', 'csco_block_editor_wrapper' );
|
||||
add_action( 'enqueue_block_assets', 'csco_block_editor_wrapper' );
|
||||
|
||||
/**
|
||||
* Change editor color palette.
|
||||
*/
|
||||
function csco_change_editor_color_palette() {
|
||||
// Editor Color Palette.
|
||||
add_theme_support(
|
||||
'editor-color-palette',
|
||||
array(
|
||||
array(
|
||||
'name' => esc_html__( 'Primary', 'revision' ),
|
||||
'slug' => 'primary',
|
||||
'color' => get_theme_mod( 'color_primary', '#29294B' ),
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'Secondary', 'revision' ),
|
||||
'slug' => 'secondary',
|
||||
'color' => get_theme_mod( 'color_secondary', '#696981' ),
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'Layout', 'revision' ),
|
||||
'slug' => 'layout',
|
||||
'color' => get_theme_mod( 'color_layout_background', '#F1F1F1' ),
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'Accent', 'revision' ),
|
||||
'slug' => 'accent',
|
||||
'color' => get_theme_mod( 'color_accent', '#5955D1' ),
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'Border', 'revision' ),
|
||||
'slug' => 'border',
|
||||
'color' => get_theme_mod( 'color_border', '#E1E1E8' ),
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'Blue', 'revision' ),
|
||||
'slug' => 'blue',
|
||||
'color' => '#59BACC',
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'Green', 'revision' ),
|
||||
'slug' => 'green',
|
||||
'color' => '#58AD69',
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'Orange', 'revision' ),
|
||||
'slug' => 'orange',
|
||||
'color' => '#FFBC49',
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'Red', 'revision' ),
|
||||
'slug' => 'red',
|
||||
'color' => '#e32c26',
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'Pale Pink', 'revision' ),
|
||||
'slug' => 'pale-pink',
|
||||
'color' => '#f78da7',
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'White', 'revision' ),
|
||||
'slug' => 'white',
|
||||
'color' => '#FFFFFF',
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'Gray 50', 'revision' ),
|
||||
'slug' => 'gray-50',
|
||||
'color' => '#f8f9fa',
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'Gray 100', 'revision' ),
|
||||
'slug' => 'gray-100',
|
||||
'color' => '#f8f9fa',
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'Gray 200', 'revision' ),
|
||||
'slug' => 'gray-200',
|
||||
'color' => '#E1E1E8',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'after_setup_theme', 'csco_change_editor_color_palette' );
|
||||
14
inc/gutenberg/filters.php
Normal file
14
inc/gutenberg/filters.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Filters.
|
||||
*
|
||||
* @package Revision
|
||||
*/
|
||||
|
||||
/**
|
||||
* Disable wp_check_widget_editor_deps.
|
||||
*/
|
||||
function csco_disable_wp_check_widget_editor_deps() {
|
||||
call_user_func( 'remove_filter', 'admin_head', 'wp_check_widget_editor_deps' );
|
||||
}
|
||||
add_filter( 'init', 'csco_disable_wp_check_widget_editor_deps' );
|
||||
210
inc/gutenberg/panels.php
Normal file
210
inc/gutenberg/panels.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
/**
|
||||
* Adding New Panels.
|
||||
*
|
||||
* @package Revision
|
||||
*/
|
||||
|
||||
/**
|
||||
* Register meta fields for gutenberg panels
|
||||
*/
|
||||
function csco_gutenberg_panels_register_meta() {
|
||||
|
||||
$post_types = array( 'post', 'page' );
|
||||
|
||||
// Loop Post Types.
|
||||
foreach ( $post_types as $post_type ) {
|
||||
|
||||
/**
|
||||
* ==================================
|
||||
* Layout Options
|
||||
* ==================================
|
||||
*/
|
||||
|
||||
register_post_meta(
|
||||
$post_type,
|
||||
'csco_singular_sidebar',
|
||||
array(
|
||||
'show_in_rest' => true,
|
||||
'type' => 'string',
|
||||
'single' => true,
|
||||
'auth_callback' => function () {
|
||||
return current_user_can( 'edit_posts' );
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
register_post_meta(
|
||||
$post_type,
|
||||
'csco_page_header_type',
|
||||
array(
|
||||
'show_in_rest' => true,
|
||||
'type' => 'string',
|
||||
'single' => true,
|
||||
'auth_callback' => function () {
|
||||
return current_user_can( 'edit_posts' );
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
register_post_meta(
|
||||
$post_type,
|
||||
'csco_page_load_nextpost',
|
||||
array(
|
||||
'show_in_rest' => true,
|
||||
'type' => 'string',
|
||||
'single' => true,
|
||||
'auth_callback' => function () {
|
||||
return current_user_can( 'edit_posts' );
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'init', 'csco_gutenberg_panels_register_meta' );
|
||||
|
||||
/**
|
||||
* Filters whether a meta key is considered protected.
|
||||
*
|
||||
* @param bool $protected Whether the key is considered protected.
|
||||
* @param string $meta_key Metadata key.
|
||||
* @param string $meta_type Type of object metadata is for.
|
||||
*/
|
||||
function csco_is_protected_meta( $protected, $meta_key, $meta_type ) {
|
||||
$hide_meta_keys = array(
|
||||
'csco_singular_sidebar',
|
||||
'csco_page_header_type',
|
||||
'csco_page_load_nextpost',
|
||||
);
|
||||
|
||||
if ( in_array( $meta_key, $hide_meta_keys, true ) ) {
|
||||
$protected = true;
|
||||
}
|
||||
|
||||
return $protected;
|
||||
}
|
||||
add_filter( 'is_protected_meta', 'csco_is_protected_meta', 10, 3 );
|
||||
|
||||
/**
|
||||
* Enqueue assets for gutenberg panels
|
||||
*/
|
||||
function csco_gutenberg_panels_assets() {
|
||||
|
||||
$post_id = get_the_ID();
|
||||
|
||||
if ( ! $post_id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post = get_post( $post_id );
|
||||
|
||||
$page_static = array();
|
||||
|
||||
// Add pages static.
|
||||
$page_static[] = get_option( 'page_on_front' );
|
||||
$page_static[] = get_option( 'page_for_posts' );
|
||||
|
||||
// Set options.
|
||||
$singular_sidebar = array(
|
||||
array(
|
||||
'value' => 'default',
|
||||
'label' => esc_html__( 'Default', 'revision' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'right',
|
||||
'label' => esc_html__( 'Right Sidebar', 'revision' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'left',
|
||||
'label' => esc_html__( 'Left Sidebar', 'revision' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'disabled',
|
||||
'label' => esc_html__( 'No Sidebar', 'revision' ),
|
||||
),
|
||||
);
|
||||
|
||||
$page_header_type = array();
|
||||
$page_load_nextpost = array();
|
||||
|
||||
if ( 'post' === $post->post_type || 'page' === $post->post_type ) {
|
||||
$page_header_type = array(
|
||||
array(
|
||||
'value' => 'default',
|
||||
'label' => esc_html__( 'Default', 'revision' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'standard',
|
||||
'label' => esc_html__( 'Standard', 'revision' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'split',
|
||||
'label' => esc_html__( 'Split', 'revision' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'overlay',
|
||||
'label' => esc_html__( 'Overlay', 'revision' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'title',
|
||||
'label' => esc_html__( 'Page Title Only', 'revision' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'none',
|
||||
'label' => esc_html__( 'None', 'revision' ),
|
||||
),
|
||||
);
|
||||
|
||||
if ( 'post' === $post->post_type ) {
|
||||
$page_load_nextpost = array(
|
||||
array(
|
||||
'value' => 'default',
|
||||
'label' => esc_html__( 'Default', 'revision' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'enabled',
|
||||
'label' => esc_html__( 'Enabled', 'revision' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'disabled',
|
||||
'label' => esc_html__( 'Disabled', 'revision' ),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$panels_data = array(
|
||||
'postType' => $post->post_type,
|
||||
'singularSidebar' => $singular_sidebar,
|
||||
'pageHeaderType' => $page_header_type,
|
||||
'pageLoadNextpost' => apply_filters( 'csco_editor_page_load_nextpost', $page_load_nextpost ),
|
||||
);
|
||||
|
||||
// Enqueue scripts.
|
||||
wp_enqueue_script(
|
||||
'csco-editor-panels',
|
||||
get_template_directory_uri() . '/assets/jsx/panels.js',
|
||||
array(
|
||||
'wp-i18n',
|
||||
'wp-blocks',
|
||||
'wp-edit-post',
|
||||
'wp-element',
|
||||
'wp-editor',
|
||||
'wp-components',
|
||||
'wp-data',
|
||||
'wp-plugins',
|
||||
'wp-edit-post',
|
||||
'wp-hooks',
|
||||
),
|
||||
csco_get_theme_data( 'Version' ),
|
||||
true
|
||||
);
|
||||
|
||||
// Localize scripts.
|
||||
wp_localize_script(
|
||||
'csco-editor-panels',
|
||||
'csPanelsData',
|
||||
apply_filters( 'csco_panels_data', $panels_data, $post )
|
||||
);
|
||||
}
|
||||
add_action( 'enqueue_block_editor_assets', 'csco_gutenberg_panels_assets' );
|
||||
Reference in New Issue
Block a user