Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger wp scss to compile based on URL trigger (webhook) #48

Open
philcook opened this issue Nov 4, 2015 · 10 comments
Open

Trigger wp scss to compile based on URL trigger (webhook) #48

philcook opened this issue Nov 4, 2015 · 10 comments
Assignees

Comments

@philcook
Copy link

philcook commented Nov 4, 2015

Hi,

I have a quick question, we have a deployment system that updates the scss files on our server. We have noticed that doing this sometimes the CSS is not generated therefore want to be able to trigger this plugin to run post deployment.

The easiest thing I can see to do is for our deployment system to hit a URL that then triggers the plugin but I am unsure how to achieve this. Any guidance you could give would be ace!

Thanks.

@tomandersen
Copy link

Agreed - it would be nice to be able to do this. I wonder if changing the 'Compiling mode' will do it.

@ReessKennedy
Copy link

+1 on this. I am going to try to code a solution like this tonight ... I want to keep the plugin inactive at all times and then just be able to manually click on a link or button to recompile the CSS after an update to the SCSS is made.

@ReessKennedy
Copy link

ReessKennedy commented Jan 7, 2017

Okay. What I decided to do is just wrap all the code in "wp-scss.php" in a URL activated conditional.

Specifically, if ($_GET['compress'] == 'scss') { all code here }

This way you can just leave the plugin activated on your live site all the time but it won't load any of the SCSS plugin code unnecessarily for all your visitors. Then when you make some changes and want to view them you can just visit your homepage and append mysite.com/?compress=scss and it will activate the code and compile it.

It's a hack. And I did have to modify the plugin but it works and solved my issue.

@brrn
Copy link
Collaborator

brrn commented Jan 9, 2017

Hey @ReessKennedy, thanks for the feedback. I like the idea of creating a URL that can trigger the compile, like a webhook. That would especially come in handy if we added an option to only compile scss manually (along with adding a compile button to the dashboard).

Would anyone else be interested in this?

@benhuson
Copy link

benhuson commented Jan 9, 2017

@brrn Yep, it would be handy so it could be triggered like a webhook. Some deploy tools allow you to trigger a URL after deploying code if your hosting only supports FTP (not SSH) so being able to recompile the SCSS after a deploy would be useful.

@dmbostan
Copy link

@brrn hell, yeah! Any ETA on this ?

@dmbostan
Copy link

@ReessKennedy can you share the code if possible? I don't quite get it.

@ReessKennedy
Copy link

ReessKennedy commented Feb 2, 2017

@dmbostan Sorry for the delay man. If you haven't figured it out, you can just open up the wp-scss.php file and then just wrap all the code with this

`if ($_GET['compress'] == 'scss') {

Plugin code goes here ... .

}`

Then whenever you want to update the .CSS you can just visit any page on site and add ?compress=scss. (Or you can change the trigger to any variable / keyword combo, for security.)

You'll no longer be able to see the plugin options page with this so you have to set those settings first.

You probably don't have to wrap the entire page with brackets but I didn't want to waste any time looking at what to hone in on and knew this would work just as good.

@dmbostan
Copy link

dmbostan commented Feb 2, 2017

@ReessKennedy thanks! Will give it a try.

@brrn brrn self-assigned this Jun 21, 2017
@primathon
Copy link

primathon commented Dec 8, 2017

@ReessKennedy @dmbostan Here's how I got this working. Wanted to regenerate the stylesheets whenever I saved an SCSS file within the AceIDE editor. Took quite a bit of debugging to find the correct hooks, but it's actually incredibly simple in the end:

// functions.php - Integration between AceIDE save event and regenerating WP-SCSS files
function mx_compile_wpscss_on_aceide_save()
{
  if ( (class_exists('AceIDE\Editor\IDE')) && (class_exists('Wp_Scss')) )
  {
	add_action('shutdown', 'wp_scss_needs_compiling');
  }
}
add_action('wp_ajax_aceide_save_file', 'mx_compile_wpscss_on_aceide_save');

Really, all you need to do is pick a place to add the wp_scss_needs_compiling function to the shutdown hook, and it'll take care of the rest.

@shadoath shadoath changed the title How to trigger wp scss Trigger wp scss to compile based on URL trigger (webhook) Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants