Froala v2

PHOTO EMBED

Thu Apr 06 2023 14:04:07 GMT+0000 (Coordinated Universal Time)

Saved by @FOrestNAtion #json

// There are 2 available hooks that work for the front-end part of the website.
// froala_before_public_init acts before the editor gets initialized and
// froala_after_public_init acts after the editor and all the plugins are loaded.
// Callback function for these hooks accepts 4 params
 
/** Callback function for public hooks"
 *
 * @param null $path        * File path on server.
 * @param null $type        * Can be js or css
 * @param string $prop      * Can be inline|file
 * @param null $mix         * If prop = file, mix will be the file name else if prop = inline mix will be the data.
 *
 * @return array|WP_Error
 *
 *
* To use a public hook, it needs to be registered right after the editor get is instantiated. The proper way
* would be to store it in a variable so you can have access to the debug log.
*
* This example includes a custom CSS file and load's it accordingly because it's used after public init the CSS file
* will be at the very bottom of your head tag.
 
* To understand better, the params are in this way:
* 1' st froala_after_public_init        => name of the hook.
* 2' nd $custom_css_path.'/test.css'    => path to the file.
* 3' rd 'css'                           => script type.
* 4' th 'file'                          => script property, can be file|inline.
* 5' th 'test'                          => the name of the file.
*/
$custom_css_path = plugins_url('wordpress-froala-wysiwyg-master/admin/css');
$custom_js_path = plugins_url('wordpress-froala-wysiwyg-master/admin/js');
 
$hook = apply_filters('froala_after_public_init', $custom_css_path.'/test.css', 'css', 'file','test');
 
if( is_wp_error( $hook ) ) {
    echo $hook->get_error_message();
}
 
// Same as the example above but it includes a javascript file and the action of the hook it's before Froala Editor's initialization.
$hook = apply_filters('froala_before_public_init', $custom_js_path.'/test.js', 'js', 'file','test');
 
if( is_wp_error( $hook ) ) {
  echo $hook->get_error_message();
}
// Example using inline script
 
$hook = apply_filters('froala_after_public_init', null, 'js', 'inline', 'console.log("test")');
 
if( is_wp_error( $hook ) ) {
  echo $hook->get_error_message();
}
 
// Example using inline css
$hook = apply_filters('froala_before_public_init', null, 'css', 'inline', 'h1 {background-color: #00ffff;}');
 
 
if( is_wp_error( $hook ) ) {
  echo $hook->get_error_message();
}
 
// Note!!
//The hooks must be registered right after instantiating the FroalaEditor class.
 
$Froala_Editor = new Froala_Editor();

$hook = apply_filters('froala_before_public_init', null, 'css', 'inline', 'h1 {background-color: #00ffff;}');

$Froala_Editor->activate('#comment',array('colorsBackground' => ['#61BD6D', '#1ABC9C', '#54ACD2', 'REMOVE'],
                                         'colorsText' => ['#61BD6D', '#1ABC9C', '#54ACD2', 'REMOVE']
                                        ));

content_copyCOPY