422 posts Keep Walking
  • Has been part of the Envato Community for over 3 years
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
UXbarn says

Thanks guys! It’s very clear now for css application. :)

What would you suggest about applying options from PHP to javascript codes? Does it use the same way of css? To echo extra <script> that includes all var for options to the header too?

This may be a silly question but I’m just not familiar with manipulating works between them.

493 posts
  • Has referred 1000+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+8 more
pixelentity says

What would you suggest about applying options from PHP to javascript codes?
http://ottopress.com/2010/passing-parameters-from-php-to-javascripts-in-plugins/
3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says


What would you suggest about applying options from PHP to javascript codes?
http://ottopress.com/2010/passing-parameters-from-php-to-javascripts-in-plugins/

And now i have a question for you :) i generate the file with php and it seems that there is a better way. How do you pass the variables exactly? ../script.js?param1=hello&param2=world ? And how do you get them inside the script?

493 posts
  • Has referred 1000+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+8 more
pixelentity says

And now i have a question for you :) i generate the file with php and it seems that there is a better way. How do you pass the variables exactly?

here’s an example: we have a js script registered under the id “pe_theme_video”, after that, we call
wp_localize_script("pe_theme_video",'peFallBackPlayer',array("url"=>$url)));


WordPress creates the “peFallBackPlayer” variable (object) right before the related script (pe_theme_video) gets loaded:
<script type='text/javascript'>
/* <![CDATA[ */
var peFallBackPlayer = {"url":"http%3A%2F%2Flocal.lan%3A85%2Fwp%2Fneo%2Fwp-content%2Fthemes%2Fneo%2Fframework%2Fjs%2Fvideo%2Fjarisplayer.swf"};
/* ]]> */
</script>
<script type='text/javascript' src='http://local.lan:85/wp/neo/wp-content/themes/neo/framework/js/pe/jquery.pixelentity.video.js?ver=1346147951'></script>


Then, in the js file, you can fetch the value:

var fbp = decodeURIComponent(window.peFallBackPlayer.url);

BF

38 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has collected 10+ items on Envato Market
+5 more
Lion says


For custom CSS styling I generate + minify css file and save it on server only when user clicks on ‘Save Changes’ button in theme options, so there are no additional WP queries made on each page view.
How many customers had issues with this? I can bet that many did not have the permission set for the file/folder and windows servers will bust the writing process + get_files_content restriction in effect, those are a few problems that i can say for sure that you have with this.

Actually so far no one had issue with this method. Another good way will be to store generated CSS in database and output it with single echo. I dont see any reason to call so many queries on DB to generate CSS .

:)

422 posts Keep Walking
  • Has been part of the Envato Community for over 3 years
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
UXbarn says


What would you suggest about applying options from PHP to javascript codes?
http://ottopress.com/2010/passing-parameters-from-php-to-javascripts-in-plugins/

Thank you so much @pixelentity. You just saved my life! :smitten:

3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says

Thanks BitFade

3243 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

for css.. http://codex.wordpress.org/Function_Reference/wp_add_inline_style

<?php
function my_styles_method() {
    wp_enqueue_script(
        'custom-style',
        get_template_directory_uri() . '/css/custom_script.css'
    );
        $color = get_option('my_custom_color'); 
        $custom_css = " 
                .mycolor{
                        background: {$color};
                }";
        wp_add_inline_style('custom-style',$custom_css);
}
add_action('wp_enqueue_scripts', 'my_styles_method');
?>

for js…. http://codex.wordpress.org/Function_Reference/wp_localize_script

http://pippinsplugins.com/use-wp_localize_script-it-is-awesome/
438 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Located in Europe
+1 more
Pixelous says

OrganicBeeMedia, thanks for the info, so, what do u think, it’s the best way to use wp_add_inline_style?

3243 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

OrganicBeeMedia, thanks for the info, so, what do u think, it’s the best way to use wp_add_inline_style?

Im not sure I’d say its the best way but its the most secure…

it also relies on a stylesheet so if some one want to de-register it from a child theme it will remove the options etc… and they can apply there own

now if your theme just needs to change a few colors/fonts etc then yes its viable but if your themes are adding 4339428434832843248 options to do everything then not so much(which I dont recommend in the first place bloat)

if youre messing with the headers to create a style.php file then just make sure you’re passing the data in a secure manor so it doesn’t leave all your customers sites wide open to get hacked(XSS)

by
by
by
by
by
by