How would I go about creating a simple file builder? - wordpress

Forgive me if this doesn't make sense but I'll do my best to explain.
I am looking into creating a piece of software/web app which will generate a package file for website themes including only the options the user would need for their project.
The best example I can think of is the underscores WordPress theme generator. But I would also like to be able to include other files. Like for example a check box that simply says "include x.js library" where if the box is checked it will include that js file or files in the folder. As well as generate the theme name, author name, theme description version number etc.
In other words I need something like underscores, that also has the option to include extra files for the development team to quickly get bespoke WordPress themes up and running whilst also including all the optional assets that we use at the firm.

You can hold the basic logic, opening, reading, editing, closing of files in a php script that's triggered when the user submits a form.
One route to manipulate files on the server with php is to use fopen.
First enable fopen in the directory in which your files you want available for download are stored. Do this by including the following in a .htaccess file in this directory:
php_value allow_url_fopen On
In whatever script you would like triggered on form submit, you can change say the author name with something like the following (you'll obviously want to target where you're writing to, I imagine with FSeek):
$downloadable_theme_index = 'index.php';
$handle = fopen($downloadable_theme_index, 'w') or die('Cannot open file: '.$downloadable_theme_index);
$new_author_name = 'Abe Lincoln';
fwrite($handle, $new_author_name);
The logic for what files are available to download could basically be form logic that provides links to download based on user input.
Additionally, there are download manager plugins available in wordpress.

Related

WordPress: Deleted Media Files Don't Go Away

I'm building a web site with WordPress, and frequently need to replace a media file--specifically, a Java project exported from Eclipse to an archive, but the same happens with images. To retain the original file name, I "delete the file permanently" from the media library, then upload the revision.
Unfortunately, when I download the file via a link, I get the "deleted" version instead of the new one.
I have disabled the "Organize my uploads into month- and year-based folders" option, so I know the file name is consistent over time.
How is it the "permanently deleted" files don't disappear? And why do they supersede their replacements?
Right now, my choice is to upload the revision without deleting the original; WordPress assigns a sequence number to the revision. I need to change links to match, and the downloaded file will contain the sequence number when used (which isn't very tidy).
This is WordPress 6.1.1.
I've had the same problem quite a few times. What I do now is just use the plugin called Enable Media Replace: https://wordpress.org/plugins/enable-media-replace/ and I don't really have to think about that issue anymore. Maybe this could be an option for you?
Otherwise I think you will have to go in to the database and manually remove the images unfortunately.

Unable to delete uploaded XML file on Drupal 8.5

I have created a media type that accepts XML files and saves them to a custom publicly accessible location on the server.
Ideally I would like the file to be overwritten when the exact same file is uploaded. This does not happen, instead it creates a new file and adds a number on the end. I have "Create new Revision" turned off.
To get around this issue I thought I could just delete the file via the CMS. The uploaded file has status of "Permanent" and is used 0 places. I know the cron job cleans up files for you, but when I run the cron the file in question is still there. I figure it's because the file is set to permanent, but I don't see a way to flip this to temporary.
Any help is much appeciated.
There is a setting nested away in the file system settings, which lets you configure it to remove (or not removed) orphaned files. If drush isn't removing them despite having no usages recorded, I'd check this option isn't ticked.
The temporary and permanent status are used for storing temporary files during the upload/save process, so I wouldn't tinker with those too much.
If you fancy making the form yourself using the form API, then you can save the file programmatically using the FILE_EXISTS_REPLACE parameter.
https://api.drupal.org/api/drupal/core%21modules%21file%21file.module/function/file_save_data/8.5.x

Debugging WordPress with PhpStorm and a local deploy setup

I like to keep my project files clean.
E.g. I keep all the files I manipulate in my project folder, and deploy them on to my local developer server on save.
e.g. if I write a theme for WordPress I create:
wp-content
wp-content/themes/
wp-content/themes/mytheme
I certainly don't keep all the files of the whole WordPress installation in my project.
I include those over the include path, then it shows as external libraries
those include all files of WordPress including mine.
Now here comes trouble
When I now press F3 on one of my functions I get "Choose declaration"
well I don't want code on my local deployment never! I always want to code in my project source files, that is, not in "external libraries"
so basically
when I add the include path, I want to have the ability to say
"excluded sub-directory of that include path"
so I can exclude my deployed files from the library. Do you understand what I mean?
is that possible?
"well just remove the include path"
no! without include path I cannot debug. Without include path I don't get auto-complete
I figured it out
the trick was in the end to not use "include path" but the project structure editor and add a different content root folder.
FIle - project structure
or
CTRL + ALT + SHIT + S
looks like this:
click on your module, click on add content root folder, click on the target deploy folder of your deployment scripts, and then exclude the stuff you don't like
it will create a new folder in the project explorer but i don't care about that really.
Remove it from the include that i mentioned in my post earlier, i mean from settings - php - external libraries. YOu don't need that any longer
hope it helps

Wordpress File Upload Hook

I am trying to hook into the Wordpress file uploader and would like some suggestions. I would like to be able to grab the path of the source file (not WP path; i.e. K:\docs\file.pdf) so I can download another file of the same name (different extension) & path automatically (i.e. K:\docs\file.txt).
Wordpress provides hooks for after the file is uploaded but all path information at that point is internal to wordpress.
Thanks in advance!!
the path information can be obtained from normal php functions like pathinfo() and realpath() for example .
Bit too late to the party but I think what you are asking for is to find the source of the document in the clients system and based on that you want similar files there to be picked up by the browser and then sent to the user.
I think it will be a fairly complex thing to do, firstly you have to get the source of the document being added to the browser (I am not sure it can be done, but if it can be done then it will be via javascript) and then upload all the files one by one to the server hosting wordpress and you can do this by creating a custom page which will add the files uploaded to it as a wordpress attachment and then using something like jquery file uploader to upload files to that location.
But honestly, I think it would be a very complex thing, unless the client and the server are on the same machine.

Drupal flushing "Page requisites" cache also deletes javascript files

When I delete "Page requisites" cache, my 2 Javascript files that I use for my home page image rotator get deleted.
Here is how I'm adding the javascript for those 2 files into a WYSIWYG editor with PHP code enabled:
<?
drupal_add_js('sites/default/files/js/jquery.jcarousellite.js');
drupal_add_js('sites/default/files/js/cycle.js');
?>
Some html here for the rotator......
Then I also have some JS code added to the home page only using the js Injector .
Any ideas why this is happening?
thanks
You shouldn't have permanent js files located in your files folder. Either they should be in your theme or a module that uses them. The files folder is meant for uploaded files and other files that Drupal creates on the fly.
The reason to your problem is probably that Drupal has write access to the folder where you have placed the files, and it cleans out in it, since it's only used for compressions. You should think twice about which files you let drupal write to. Letting Drupal have write access to a script file you use, is an added security risk.
Generally, you don't want to let Drupal write to js or php files. This is because if a cracker would be able to get Drupal to write to those files, he would be able to more or less gain control over your entire site. This is also why the compressed js files that drupal uses has a long and random name.
So try moving those files into your theme and see if that doesn't fix it. If you want to link to them you can do
drupal_add_js(drupal_get_path('theme', 'name_of_your_theme') . 'path/to/file.js');

Resources