Error adding codesample plugin to TinyMCE in WordPress - wordpress

I'm using WordPress version 5.2.1.
I've downloaded the codesample plugin, because it's not included in WordPress by default.
I've uploaded it to the /wp-includes/js/tinymce/plugins folder
I've added a reference to prism.css and prism.js to my theme, as mentioned here.
I've activated the 'Advanced TinyMCE Configuration' and updated the 'Plugins' option to include 'codesample'.
When I load a page with a TinyMCE WYSIWYG editor, it no longer renders and my console reports:
"Uncaught TypeError: Cannot read property 'registry' of undefined" in the codesample plugin.min.js file.
I've noticed that the WordPress version of TinyMCE is an old version - 4.8.0 (2018-06-27). Do I need to manually update it? Is this good practise?
I just wondered if I'm missing part of the process?
Thanks.
UPDATE
I've added the plugin via Functions.php as advised:
wp_enqueue_style( 'style', get_stylesheet_directory_uri().'/tinymce/plugins/codesample/prism.css' );
wp_enqueue_script( 'script', get_stylesheet_directory_uri().'/tinymce/plugins/codesample/prism.js' );
function my_custom_plugins( $plugins ) {
$plugins['codesample'] = get_stylesheet_directory_uri().'/tinymce/plugins/codesample/plugin.min.js';
return $plugins;
}
add_filter( 'mce_external_plugins', 'my_custom_plugins' );
But how do I go about upgrading the TinyMCE editor to v5?

Related

How to activate WpMediaElement in WordPress

I would like to use the plug-in WPMediaElement for styling audio player in Word Press. As I understand it should be default installed in WordPress (I am using version 5.2.15) and it is also placed in the folder wp-includes/js/mediaelement. But it is not included when the website are showing in a browser :-|
What do I have to do for activating it?
Thanks in advance !
Make sure that medialement is loaded on all the pages.
Insert this in your child-theme functions.php:
add_action('wp_enqueue_scripts', function () {
wp_enqueue_style( 'wp-mediaelement' );
}, 100);

How to Create custom woocommerce dashboard Template

I am trying to create custom woocommerce dashboard for my custom wordpress theme, but i found a error message when i am trying to create custom woocommerce dashboard template.
Deprecated: Your theme version of my-account.php template is deprecated since version 2.6! Use the latest version, which supports multiple account pages and navigation, from WC 2.6.0 instead.
I have followed the woocommerce template pattern (yourtheme/woocommerce/myaccount/my-account.php.) but nothing help . Please see the attached image. problem will gone if i edit wp-config.php with define( 'WP_DEBUG_DISPLAY', false );
Thanks
I found a solution for this.
I have to use this two function in my-account.php file.
Then the error message gone.
do_action( 'woocommerce_account_navigation' );
do_action( 'woocommerce_account_content' );

Wordpress media library not working - mediaelementplayer is not a function

Uncaught TypeError: b(...).not(...).filter(...).mediaelementplayer is not a function
I am getting this issue after wordpress latest update 4.9. I am using this library in my plugin to allow users to upload images using the wp media upload. It was working fine, but after the latest update it is returning the error as I mentioned above.
By adding the following code in functions.php file, error should be resolved.
add_action('wp_enqueue_scripts', 'my_register_javascript', 100);
function my_register_javascript() {
wp_register_script('mediaelement', plugins_url('wp-mediaelement.min.js', __FILE__), array('jquery'), '4.8.2', true);
wp_enqueue_script('mediaelement');
}
Does it appear on post/page edit?
'Add Media' button is not working?
If you answer 'yes' on both questions take a look if jQuery is not loaded twice, if so, load one only or implement JQuery.noConflict().

Wordpress custom hook to fetch plugin version (latest) after update it

im trying to get plugin name and plugin versions of plugins that has been recently updated and save it to a txt file.
Example in this txt file:
Jetpack had version 3.9.2 now its 3.9.4
Is there a way to make a custom hook that find the update process and retrieve the update number?
Maybe you can try it with upgrader_process_complete.
add_action( 'upgrader_process_complete', function( $upgrader_object, $options ) {
// inspect $options
}, 10, 2 );

How to use wp-post editor in plugin

I want to use the post editor of wordpress in one of the plugins I'm developing. How am I supposed to add the editor to the plugin.
Atlast I figured out a way to add the tiny-mce editor on my plugin.
You have to add a few script(s) and the post editor of wordpress will be available for you.
This is the code to use:
wp_enqueue_script( 'common' );
wp_enqueue_script( 'jquery-color' );
wp_enqueue_script('utils');
if (function_exists('add_thickbox')) add_thickbox();
wp_print_scripts('media-upload');
if (function_exists('wp_tiny_mce')) wp_tiny_mce();
wp_admin_css();
wp_print_scripts('editor');
do_action("admin_print_styles-post-php");
do_action('admin_print_styles');
It's enough to add the tiny mce editor on your plugin.
Now the following line is necessary to display the editor:

Resources