• Resolved Mikko

    (@sainionmikko)


    Hi guys, thanks for a really nice plugin!
    I’m about to build a theme of my own and would like to include this plugin pre-installed. I don’t want to install the usual way and show it in the plugins list, just do the magic behind the curtain. The way I’ve approached this is to move the plugin files in a different folder and in my functions.php, include_once the main file happy-scss-compiler.php. This brings the settings page where it belongs, but the css and js seem to be lacking. Also I’m not sure if it compiles, without hitting the save settings button. At least it’s slower than when installed in the usual way.
    This works for some other plugins, what am I missing here?
    My include code is simply:

    if(!function_exists('run_hm_wp_scss')){
    	include_once( get_template_directory() . '/lib/plugins/happy-scss-compiler/happy-scss-compiler.php' );
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Happy Monkey

    (@happymonkeyagency)

    Hi Mikko,
    Thank you for your message!
    Do you have any PHP error message, or some errors in the browser console?
    If not, I will check this out on my own to understand what is missing.
    Thanks!
    Alex

    Thread Starter Mikko

    (@sainionmikko)

    Hi Alex,
    Thanks for your response! Yes, I have error messages! Both in the server log and in the console. It seems the GET method isn’t finding the following files:
    /happy-scss-compiler/includes/highlight/styles/ir-black.min.css
    /happy-scss-compiler/admin/css/hm-wp-scss-admin.css
    /happy-scss-compiler/includes/highlight/highlight.min.js
    /happy-scss-compiler/admin/js/hm-wp-scss-admin.js
    The path used is definitely wrong. It starts with /wp-content/plugins/ and continues with a full absolute path to my changed plugin directory, something like C:/Users/…/wp-content/themes/my-theme/lib/plugins/happy-scss-compiler/… where the last part is the correct path to where I save and include the plugin in my functions.php. As I wrote earlier, I have moved the plugin away from /wp-content/plugins/ in a subfolder in my theme.
    Is there a way to redefine the paths to these asset files for the plugin in some way prior to including the main plugin file?

    Thread Starter Mikko

    (@sainionmikko)

    Hi Alex,
    Meanwhile, I tried to tinker this and hardcoded the style and script enqueue path in the class-hm-wp-scss-admin.php file, lines 88-89 and 112-113. I got rid of the console errors, but the following error persists in the server log and styles&scripts are not loaded:
    CreateFile() "C:/Users/me/Local Sites/mysite/app/public/wp-content/plugins/C:/Users/me/Local Sites/mysite/app/public/wp-content/themes/my-theme/lib/plugins/happy-scss-compiler/admin/js/hm-wp-scss-admin.js" failed (123: The filename, directory name, or volume label syntax is incorrect), client: 127.0.0.1, server: , request: "GET /wp-content/plugins/C:/Users/me/Local%20Sites/mysite/app/public/wp-content/themes/my-theme/lib/plugins/happy-scss-compiler/admin/js/hm-wp-scss-admin.js?ver=1.3.10 HTTP/1.0"
    Obviously, the path is still wrong somewhere. I’d be grateful if you could point me to the right direction!

    Plugin Author Happy Monkey

    (@happymonkeyagency)

    Hi there,
    Sorry for the delay, it is difficult to find some time these days… I will try to be more reactive.
    What you changed in class-hm-wp-scss-admin.php is exactly what you had to do.
    Now, I think this error shows that WordPress doesn’t understand that the path you specified has to be relative, not absolute.
    Can you show me what you put in place of the previous path?
    Thanks!
    Alex

    Thread Starter Mikko

    (@sainionmikko)

    Hi Alex,
    I got this working now! I had replaced the original plugin_dir_url(__FILE__) with get_template_directory() + my path to dir. This didn’t work as it produced an absolute path. I then just wrote the whole relative path to my dir starting from /wp-content/ with no preceding functions. This will be my parent theme path and remain the same so it’s OK to hardcode. So it’s solved, thanks for your help!

    Plugin Author Happy Monkey

    (@happymonkeyagency)

    Hi Mikko,

    I am glad it works now! Thanks for sharing me this point, I will take it into account for the future updates.

    Have a good day!
    Alex

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Correct way to pre-install the plugin in a theme?’ is closed to new replies.