Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
update_recently_edited example
$settings
= array
(
'codeEditor' =>
wp_enqueue_code_editor
(
array
(
'file' =>
$real_file
)
)
,
)
;
wp_enqueue_script
(
'wp-theme-plugin-editor'
)
;
wp_add_inline_script
(
'wp-theme-plugin-editor',
sprintf
(
'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )',
wp_json_encode
(
$settings
)
)
)
;
wp_add_inline_script
(
'wp-theme-plugin-editor',
sprintf
(
'wp.themePluginEditor.themeOrPlugin = "plugin";'
)
)
;
require_once
ABSPATH . 'wp-admin/admin-header.php';
update_recently_edited
(
WP_PLUGIN_DIR . '/' .
$file
)
;
if
(
!
empty
(
$posted_content
)
)
{
$content
=
$posted_content
;
}
else
{
$content
=
file_get_contents
(
$real_file
)
;
}
if
(
str_ends_with
(
$real_file
, '.php'
)
)
{
$functions
=
wp_doc_link_parse
(
$content
)
;
if
(
!
empty
(
$functions
)
)
{
$settings
= array
(
'codeEditor' =>
wp_enqueue_code_editor
(
compact
(
'file'
)
)
,
)
;
wp_enqueue_script
(
'wp-theme-plugin-editor'
)
;
wp_add_inline_script
(
'wp-theme-plugin-editor',
sprintf
(
'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )',
wp_json_encode
(
$settings
)
)
)
;
wp_add_inline_script
(
'wp-theme-plugin-editor', 'wp.themePluginEditor.themeOrPlugin = "theme";'
)
;
require_once
ABSPATH . 'wp-admin/admin-header.php';
update_recently_edited
(
$file
)
;
if
(
!
is_file
(
$file
)
)
{
$error
= true;
}
$content
= '';
if
(
!
empty
(
$posted_content
)
)
{
$content
=
$posted_content
;
}
elseif
(
!
$error
&&
filesize
(
$file
)
> 0
)
{
$f
=
fopen
(
$file
, 'r'
)
;
$content
=
fread
(
$f
,
filesize
(
$file
)
)
;