admin-bar
1 year ago
client-migration
7 months ago
compatibility
1 year ago
customizer
1 day ago
freemius
9 months ago
menu-icons
1 year ago
metabox
1 year ago
onboarding
1 month ago
panel
10 months ago
post-settings
3 months ago
preloader
1 year ago
shortcodes
1 year ago
themepanel
1 year ago
widgets
1 day ago
wizard
3 years ago
adobe-font.php
1 year ago
custom-code.php
9 months ago
dashboard.php
1 year ago
image-resizer.php
1 year ago
jshrink.php
3 years ago
mautic.php
3 months ago
ocean-extra-strings.php
3 years ago
plugins-tab.php
1 year ago
update-message.php
1 year ago
utils.php
1 year ago
walker.php
4 years ago
custom-code.php
104 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Custom Code Customizer Options |
| 4 | * |
| 5 | * @package OceanWP WordPress theme |
| 6 | */ |
| 7 | |
| 8 | // Exit if accessed directly. |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | if ( ! class_exists( 'OceanWP_Custom_Code_Customizer' ) ) : |
| 14 | |
| 15 | /** |
| 16 | * Custom CSS / JS Customizer Class |
| 17 | */ |
| 18 | class OceanWP_Custom_Code_Customizer { |
| 19 | |
| 20 | /** |
| 21 | * Setup class. |
| 22 | * |
| 23 | * @since 1.0 |
| 24 | */ |
| 25 | public function __construct() { |
| 26 | |
| 27 | add_action( 'customize_register', array( $this, 'customizer_options' ) ); |
| 28 | add_action( 'wp_enqueue_scripts', array( $this, 'output_custom_js' ), 9999 ); |
| 29 | |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Customizer options |
| 34 | * |
| 35 | * @since 1.0.0 |
| 36 | * |
| 37 | * @param WP_Customize_Manager $wp_customize Theme Customizer object. |
| 38 | */ |
| 39 | public function customizer_options( $wp_customize ) { |
| 40 | |
| 41 | $section = 'ocean_custom_code_panel'; |
| 42 | $wp_customize->add_section( |
| 43 | $section, |
| 44 | array( |
| 45 | 'title' => esc_html__( 'Custom CSS/JS', 'ocean-extra' ), |
| 46 | 'priority' => 18, |
| 47 | ) |
| 48 | ); |
| 49 | |
| 50 | /** |
| 51 | * Custom JS |
| 52 | */ |
| 53 | $wp_customize->add_setting( |
| 54 | 'ocean_custom_js', |
| 55 | array( |
| 56 | 'transport' => 'postMessage', |
| 57 | 'sanitize_callback' => false, |
| 58 | ) |
| 59 | ); |
| 60 | |
| 61 | $wp_customize->add_control( |
| 62 | new WP_Customize_Code_Editor_Control( |
| 63 | $wp_customize, |
| 64 | 'ocean_custom_js', |
| 65 | array( |
| 66 | 'label' => esc_html__( 'Custom JS', 'ocean-extra' ), |
| 67 | 'description' => esc_html__( 'You need to reload to see the changes. No need to add the <script> tags.', 'ocean-extra' ), |
| 68 | 'code_type' => 'text/javascript', |
| 69 | 'input_attrs' => array( |
| 70 | 'aria-describedby' => 'editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4', |
| 71 | ), |
| 72 | 'section' => $section, |
| 73 | 'settings' => 'ocean_custom_js', |
| 74 | 'priority' => 10, |
| 75 | ) |
| 76 | ) |
| 77 | ); |
| 78 | |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Outputs the custom JS |
| 83 | * |
| 84 | * @since 1.0.0 |
| 85 | * |
| 86 | * @param string $output Custom JS output. |
| 87 | */ |
| 88 | public function output_custom_js() { |
| 89 | |
| 90 | $js = get_theme_mod( 'ocean_custom_js', false ); |
| 91 | if ( $js ) { |
| 92 | // $output .= $js; |
| 93 | wp_add_inline_script( 'oceanwp-main', $js ); |
| 94 | } |
| 95 | // return $output; |
| 96 | |
| 97 | } |
| 98 | |
| 99 | } |
| 100 | |
| 101 | endif; |
| 102 | |
| 103 | return new OceanWP_Custom_Code_Customizer(); |
| 104 |