| 1 |
<?php |
| 2 |
|
| 3 |
function powerup_custom_css( $settings ) { |
| 4 |
|
| 5 |
paf_options ( array( |
| 6 |
'eoi_powerup_custom_css' => array( |
| 7 |
'type' => 'checkbox', |
| 8 |
'options' => array( |
| 9 |
'on' => __( 'Enabled' ), |
| 10 |
), |
| 11 |
'page' => 'eoi_powerups', |
| 12 |
'title' => __( 'Custom CSS' ), |
| 13 |
'description' => sprintf( '<p class="description eoi_powerup_description">%s</p>', __( 'Adds a setting that lets you add custom CSS to your opt-in box to the Easy Opt-ins editor.' ) ), |
| 14 |
) |
| 15 |
) ); |
| 16 |
|
| 17 |
if( ! paf( 'eoi_powerup_custom_css' ) ) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
new EoiCustomCssBox( $settings ); |
| 22 |
} |
| 23 |
|
| 24 |
class EoiCustomCssBox { |
| 25 |
|
| 26 |
var $settings; |
| 27 |
|
| 28 |
public function __construct( $settings ) { |
| 29 |
|
| 30 |
$this->settings = $settings; |
| 31 |
|
| 32 |
add_action( 'fca_eoi_powerups', array( $this, 'show_custom_css_field' ) ); |
| 33 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); |
| 34 |
add_action( 'admin_print_footer_scripts', array( $this, 'enqueue_admin_footer_js' ) ); |
| 35 |
add_filter( 'fca_eoi_alter_form', array( $this, 'append_css_to_form' ) , 10 , 2 ); |
| 36 |
} |
| 37 |
|
| 38 |
public function init() { |
| 39 |
} |
| 40 |
|
| 41 |
public function append_css_to_form( $content , $fca_eoi_meta ) { |
| 42 |
|
| 43 |
if( $css = K::get_var( 'custom_css', $fca_eoi_meta ) ) { |
| 44 |
$content .= "<style>$css</style>"; |
| 45 |
} |
| 46 |
|
| 47 |
return $content; |
| 48 |
} |
| 49 |
|
| 50 |
/* |
| 51 |
* Add fieldset custom css box |
| 52 |
*/ |
| 53 |
public function show_custom_css_field( $fca_eoi_meta ) { |
| 54 |
echo '<div class="eoi-custom-css-form" style="width:40.5em;">'; |
| 55 |
K::textarea( 'fca_eoi[custom_css]' |
| 56 |
, array( |
| 57 |
'class' => 'fca_eoi_custom_css_textbox', |
| 58 |
'placeholder' => __( 'Enter your custom CSS here...' ), |
| 59 |
) |
| 60 |
, array( |
| 61 |
'value' => K::get_var( 'custom_css', $fca_eoi_meta, '' ), |
| 62 |
'format' => '<label> Custom CSS</label><br />:textarea', |
| 63 |
) |
| 64 |
); |
| 65 |
echo '</div>'; |
| 66 |
} |
| 67 |
|
| 68 |
public function enqueue_admin_scripts() { |
| 69 |
wp_enqueue_style( 'powerups-css', $this->settings['plugin_url'] . '/assets/powerups/fca_eoi_powerups.css' ); |
| 70 |
|
| 71 |
$protocol = is_ssl() ? 'https' : 'http'; |
| 72 |
$screen = get_current_screen(); |
| 73 |
|
| 74 |
// Exit function if not in one of our plugin pages |
| 75 |
if( 'easy-opt-ins' !== $screen->id ){ |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
// Enqueue CodeMirror JS and CSS |
| 80 |
$codemirror_prefix = "$protocol://cdnjs.cloudflare.com/ajax/libs/codemirror/4.7.0/"; |
| 81 |
$codemirror_js = array( |
| 82 |
'codemirror' => 'codemirror.min.js', |
| 83 |
'codemirror-css' => 'mode/css/css.min.js', |
| 84 |
'codemirror-placeholder' => 'addon/display/placeholder.min.js', |
| 85 |
); |
| 86 |
foreach ( $codemirror_js as $handle => $path) { |
| 87 |
wp_enqueue_script( $handle, $codemirror_prefix . $path ); |
| 88 |
} |
| 89 |
wp_enqueue_style('codemirror', $codemirror_prefix . 'codemirror.min.css' ); |
| 90 |
} |
| 91 |
|
| 92 |
public function enqueue_admin_footer_js() { |
| 93 |
?><script type="text/javascript"> |
| 94 |
|
| 95 |
jQuery( document ).ready( function( $ ) { |
| 96 |
|
| 97 |
// Add CodeMirrors |
| 98 |
$( '.fca_eoi_custom_css_textbox' ).each( function( i, el ) { |
| 99 |
var editor = CodeMirror.fromTextArea( el, { |
| 100 |
mode: "text/css", |
| 101 |
matchBrackets: true, |
| 102 |
lineNumbers: true, |
| 103 |
lineWrapping: true, |
| 104 |
foldGutter: true, |
| 105 |
gutters: [ "CodeMirror-linenumbers", "CodeMirror-foldgutter" ] |
| 106 |
} ); |
| 107 |
} ); |
| 108 |
} ); |
| 109 |
</script><?php |
| 110 |
} |
| 111 |
} |
| 112 |
|