Skip to main content
show full function in use
Source Link
Nadal
  • 89
  • 6

This is a concept of my goal

concept image

I want to

be able to create files in the current opened directory by entering the complete file name and and extension in a text field, click create and use the AJAX process to run the file_put_contents() method.

I haven't tried any coding methods as I do not even have a starting point. After 18 hours of research, I have only found methods using add_theme_page() to add a page where all the custom coding can be done. While that's a solid option, I'd like to keep it all in the core file editor. It's just an overkill to create an entire file editor which does all the same tasks as the core, with the only diff being a text field.

Update

In an act of desperation, I have used the admin_notices action to insert the input field and button, and attached a function to show only on the specified theme, and run the file creation process. It's not the solution I desire so I don't think it's appropriate to post as an answer.

if(public issetstatic function makeFile($_GET['file']$file, $data=null)
{
 && strstr  if($_GET['file'], 'styles'!is_null(mb::getPost('makecss')) ) {
        file_put_contents(DEF_THEMEPATH.'/styles/'.$file.'.css', $data);
        
add_action        wp_redirect('admin_notices', functionadd_query_arg(['file'=>'styles/'.$file.'.css','theme'=>'thor'],admin_url('theme-editor.php')) {);
  $newfileform      exit;
    }
    
    $newfile = '
    <div class="newfile-form">
    <form action=""method="post" method="post">action="">
        <p>Create New CSS File</p>
      File  <span>File name: <input type="text" name="newfile" id="newfile" value="" /><button></span>
        <span><button type="submit" name="makefilenow"name="makecss" class="button button-primary">Create File</button>button></span>
    </form>
    </div>
    ';
    return $newfile;
}

action

if( strstr(mb::urlVar('theme'), 'thor') ) {
 add_action('admin_notices', function() {
    echo $newfileform;mb::makeFile(mb::getPost('newfile'));
 });
 
}

Result

result of method used

The function query's the URL string forNote: $_GET['makefilenow'] on submission and runsmb represents the process to createname of my php class

Note: Though the .css file.css extension is shown in the assigned folderimage, I have since made it the default and only extension possible. A javascript method replaces any period and following string with null

This is a concept of my goal

concept image

I want to

be able to create files in the current opened directory by entering the complete file name and and extension in a text field, click create and use the AJAX process to run the file_put_contents() method.

I haven't tried any coding methods as I do not even have a starting point. After 18 hours of research, I have only found methods using add_theme_page() to add a page where all the custom coding can be done. While that's a solid option, I'd like to keep it all in the core file editor. It's just an overkill to create an entire file editor which does all the same tasks as the core, with the only diff being a text field.

Update

In an act of desperation, I have used the admin_notices action to insert the input field and button, and attached a function to show only on the specified theme, and run the file creation process. It's not the solution I desire so I don't think it's appropriate to post as an answer.

if( isset($_GET['file']) && strstr($_GET['file'], 'styles') ) { 

add_action('admin_notices', function() {
  $newfileform = '
    <div class="newfile-form">
    <form action="" method="post">
      <p>Create New CSS File</p>
      File name: <input type="text" name="newfile" id="newfile" value="" /><button type="submit" name="makefilenow" class="button button-primary">Create File</button>
    </form>
    </div>
  ';
  
  echo $newfileform;
});
 
}

Result

result of method used

The function query's the URL string for $_GET['makefilenow'] on submission and runs the process to create the .css file in the assigned folder.

This is a concept of my goal

concept image

I want to

be able to create files in the current opened directory by entering the complete file name and and extension in a text field, click create and use the AJAX process to run the file_put_contents() method.

I haven't tried any coding methods as I do not even have a starting point. After 18 hours of research, I have only found methods using add_theme_page() to add a page where all the custom coding can be done. While that's a solid option, I'd like to keep it all in the core file editor. It's just an overkill to create an entire file editor which does all the same tasks as the core, with the only diff being a text field.

Update

In an act of desperation, I have used the admin_notices action to insert the input field and button, and attached a function to show only on the specified theme, and run the file creation process. It's not the solution I desire so I don't think it's appropriate to post as an answer.

public static function makeFile($file, $data=null)
{
    if( !is_null(mb::getPost('makecss')) ) {
        file_put_contents(DEF_THEMEPATH.'/styles/'.$file.'.css', $data);
        
        wp_redirect( add_query_arg(['file'=>'styles/'.$file.'.css','theme'=>'thor'],admin_url('theme-editor.php')) );
        exit;
    }
    
    $newfile = '
    <div class="newfile-form">
    <form method="post" action="">
        <p>Create New CSS File</p>
        <span>File name: <input type="text" name="newfile" id="newfile" value="" /></span>
        <span><button type="submit" name="makecss" class="button button-primary">Create File</button></span>
    </form>
    </div>
    ';
    return $newfile;
}

action

if( strstr(mb::urlVar('theme'), 'thor') ) {
 add_action('admin_notices', function() {
    echo mb::makeFile(mb::getPost('newfile'));
 });
}

Result

result of method used

Note: mb represents the name of my php class

Note: Though the .css extension is shown in the image, I have since made it the default and only extension possible. A javascript method replaces any period and following string with null

updated to show possible solution
Source Link
Nadal
  • 89
  • 6

This is a concept of my goal

concept image

I want to

be able to create files in the current opened directory by entering the complete file name and and extension in a text field, click create and use the AJAX process to run the file_put_contents() method.

I haven't tried any coding methods as I do not even have a starting point. After 18 hours of research, I have only found methods using add_theme_page() to add a page where all the custom coding can be done. While that's a solid option, I'd like to keep it all in the core file editor. It's just an overkill to create an entire file editor which does all the same tasks as the core, with the only diff being a text field.

Update

In an act of desperation, I have used the admin_notices action to insert the input field and button, and attached a function to show only on the specified theme, and run the file creation process. It's not the solution I desire so I don't think it's appropriate to post as an answer.

if( isset($_GET['file']) && strstr($_GET['file'], 'styles') ) { 

add_action('admin_notices', function() {
  $newfileform = '
    <div class="newfile-form">
    <form action="" method="post">
      <p>Create New CSS File</p>
      File name: <input type="text" name="newfile" id="newfile" value="" /><button type="submit" name="makefilenow" class="button button-primary">Create File</button>
    </form>
    </div>
  ';
  
  echo $newfileform;
});

}

Result

result of method used

The function query's the URL string for $_GET['makefilenow'] on submission and runs the process to create the .css file in the assigned folder.

This is a concept of my goal

concept image

I want to

be able to create files in the current opened directory by entering the complete file name and and extension in a text field, click create and use the AJAX process to run the file_put_contents() method.

I haven't tried any coding methods as I do not even have a starting point. After 18 hours of research, I have only found methods using add_theme_page() to add a page where all the custom coding can be done. While that's a solid option, I'd like to keep it all in the core file editor. It's just an overkill to create an entire file editor which does all the same tasks as the core, with the only diff being a text field.

This is a concept of my goal

concept image

I want to

be able to create files in the current opened directory by entering the complete file name and and extension in a text field, click create and use the AJAX process to run the file_put_contents() method.

I haven't tried any coding methods as I do not even have a starting point. After 18 hours of research, I have only found methods using add_theme_page() to add a page where all the custom coding can be done. While that's a solid option, I'd like to keep it all in the core file editor. It's just an overkill to create an entire file editor which does all the same tasks as the core, with the only diff being a text field.

Update

In an act of desperation, I have used the admin_notices action to insert the input field and button, and attached a function to show only on the specified theme, and run the file creation process. It's not the solution I desire so I don't think it's appropriate to post as an answer.

if( isset($_GET['file']) && strstr($_GET['file'], 'styles') ) { 

add_action('admin_notices', function() {
  $newfileform = '
    <div class="newfile-form">
    <form action="" method="post">
      <p>Create New CSS File</p>
      File name: <input type="text" name="newfile" id="newfile" value="" /><button type="submit" name="makefilenow" class="button button-primary">Create File</button>
    </form>
    </div>
  ';
  
  echo $newfileform;
});

}

Result

result of method used

The function query's the URL string for $_GET['makefilenow'] on submission and runs the process to create the .css file in the assigned folder.

Source Link
Nadal
  • 89
  • 6

How can I add a method to create files when in theme-editor.php

This is a concept of my goal

concept image

I want to

be able to create files in the current opened directory by entering the complete file name and and extension in a text field, click create and use the AJAX process to run the file_put_contents() method.

I haven't tried any coding methods as I do not even have a starting point. After 18 hours of research, I have only found methods using add_theme_page() to add a page where all the custom coding can be done. While that's a solid option, I'd like to keep it all in the core file editor. It's just an overkill to create an entire file editor which does all the same tasks as the core, with the only diff being a text field.