-
Notifications
You must be signed in to change notification settings - Fork 584
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
Redux Guidelines? #22
Comments
@dodzki We're working on documentation over the next few days. Here's a start that you can look at: You're right. You're at the cutting edge over here! That's why it's beta... ;) |
@dodzki So you know, I just added a little tidbit to the code. Whenever you define an opt_name, a global variable with that name is created for you. That global variable houses all of your field values. It's already set to be global. So you just have to define it in a field. Let me show you how I use this in a project that was previously using SMOF: <?
// Gets the current values from SMOF, and if not there, grabs the defaults
function shoestrap_getVariable( $key ) {
global $redux;
if ( !empty( $redux[$key] ) ) {
return $redux[$key];
}
return false;
} This single function is what I used everywhere to grab the value. With SMOF I used to have to pull from the DB if initialised properly, etc. It was so complex it needed its own function. Not with Redux 3.0.0! If you're in a template file it's even easier! You don't have to declare global $YOUROPT_NAME. It's already there. Hopefully that will get you off and running. It's in the newest commit. @teamcrisis, this may be useful to you. |
No downside only benefit. ;) |
@dovy , thanks for the reply. Hoping for the more advance tip of your documentation, soon. thank you very much! |
For using the options on the front end of a site I'm building I wanted an easy way to call them so I wrote a function similar to the one @dovy used above. Part of my reasoning for this is so that I don't have to call the global options variable on every template page. I ran into a bit of trouble when pulling options from media fields however. The reason being that media elements are stored in an array which didn't play nicely with my function. So instead I got this function to work... function my_option_array( $name, $key = false, $default = false ) {
global $MY_Options;
$the_option = $MY_Options->get( $name, $default );
if ( !empty( $key ) ) {
return $the_option[$key];
}
return $the_option;
} The above function works and I can return just the url of a media field from the theme options like so... <?php echo my_option_array( 'media_field', 'url',) My questions...
|
@corradomatt Actually, I want to use that in my own code! Fantastic suggestion. I used the function myself so I don't have to do global, but to access an array value I always had to set an array. This simplifies the issue! Now, one change I'd suggest. DO NOT use ->get(). There's no need. I've made things easier. I've created a global variable of set values you can use at any time. Let's go over how this works. So I'd change your function like thus: SEE UPDATED FUNCTION BELOW THIS POST<?
function get_value( $name, $key = false ) {
global $MY_OPT_NAME;
$the_option = $MY_OPT_NAME[$name];
if ( !empty( $key ) ) {
return $the_option[$key];
}
return $the_option;
} Now a word about this global set variable. It is equal to the opt_name you set for your theme OR the name of the Let's say for example your opt_name is This is a shift from the old way of doing Redux and removes the need for you to define values. You can still, if you prefer, make your ReduxFramework value global, but it's not needed as it was before. I'd advise to just declare it once and not make it global, just use the globally defined variable that houses the results of your panel. Also ->get() does still work, but I'm thinking of removing it completely. It had some speed issues that greatly affected things in the DB. I think I lost some 75 queries to the panel on each load by bypassing that function. ;) |
@dovy I've been considering removing get() as well, go for it. |
Scratch that. He's a full function that handles all cases. This will work if you place it anywhere in your code. <?
function redux_get_variables( $name, $key = false ) {
global $MY_VAR_NAME;
$options = $MY_VAR_NAME;
$var = ""; // Set this to your preferred default value
if ( empty( $name ) && !empty( $options ) ) {
$var = $options;
} else {
if ( !empty( $options[$name] ) ) {
if ( !empty( $key ) && !empty( $options[$name][$key] ) ) {
$var = $options[$name][$key];
} else {
$var = $options[$name];
}
}
}
return $var;
} To use this, you'd call anywhere you want redux_get_variables(). You can specify the name of the option by id, and a key within it to return. |
@corradomatt You'll want to look at that bit of code above. ;) |
Hi @dovy Doesn't work on my 'type' => 'media' my functions.php function webbysolve_option($selected_option) { global $options; $options = get_option('webbysolve'); return $options[$selected_option]; } and for the header.php to display image. From the old stable version; my code is working just fine. After I migrate to version 3. It's no longer working. I'm not sure why and I can't even get the right code of your sample functions. and also, most of my codes are working fine. I'm only having bad issue with media. |
@corradomatt We just removed get() and show() from the core FYI. @dodzki From your other post you should have the answer you are seeking. @ghost1227 helped out and we have better documentation now. Please open a new ticket if you have continued issues. |
thanks @dovy - exactly what I was looking for! |
Hi @dovy , can you take a look of my code. I still can't output the image. and I'm still confuse. :( sorry, I'm just too dumb when it comes to programming. functions.php $args['opt_name'] = 'webbysolve'; function dodzki_option( $webbysolve, $key = false ) { global $webbysolve; $options = $webbysolve; $var = ""; // Set this to your preferred default value if ( empty( $webbysolve ) && !empty( $options ) ) { $var = $options; } else { if ( !empty( $options[$webbysolve] ) ) { if ( !empty( $key ) && !empty( $options[$webbysolve][$key] ) ) { $var = $options[$webbysolve][$key]; } else { $var = $options[$webbysolve]; } } } return $var; } did I get it right for the functions? my ID for media is 'logo' in the options.php array to output for image url and still not working. echo dodzki_option('logo'); |
Try echo dodzki_option('logo', 'url'); If you need to output the urge of the media file. |
@corradomatt it's not working. :( |
@dovy , @ghost1227 Whew. I made it work!!! thanks! and now, what's left is to output the text title if media is empty. |
Everyone, just fixed Redux. You can use the global variable anywhere without any extra features. It loads properly on the front and backend. The only exception is within template files you need to put global $OPT_NAME in the header.php as those functions run within another function. How's that for simplicity? See the updated sample-config.php to see how to do this. Basically you remove the init function for the redux init. It's not needed now. |
Check the new docs on it: http://reduxframework.com/docs/getting-started/ |
@dovy that change doesn't affect embed option, does it? BTW, great work with continuing to make Redux even better! |
@teamcrisis It made it easier for the embedded. You don't have to use an init hook to get your variable. Also, here are the new embedded docs I am writing as we type. ;) |
@dodzki - NO CURLY BRACKETS??? AGGGGHHH! MY EYES!!!! ;-) |
Did I miss something? lol. |
Most of the reference links are dead now... Anyways worth reading |
Checkout the wiki - https://github.com/ReduxFramework/ReduxFramework/wiki I believe that all the docs are moving to the wiki instead. |
Thanks @corradomatt Asking this because upon simple calling certain functions, did faced strange errors like Warning: Illegal string offsetxxxx. in xxx/theme.php line no 917 |
Please help, Before of Redux Framework |
@tusarnill Don't piggyback OLD tickets, make new ones. Find where $opt_name is defined in the sample-config and update it. ;) |
The framework is nice. Been checking the functionality in the admin side and it looks great same as HNP Framework that I'm using. The problem with this, there's no guide on how to use in front-end. Guidelines on how to use it in front-end should be implemented. Like, how to use the radio option, multi-check, upload, fonts and especially with if else state.
What's nice if there's an if else statement guide; is to display the field entry if there is an entry, and if it's empy, it should not display or else, display another content as default.
Not all front-end developer is good in PHP like me. Hope this will be implemented like what Advanced Custom Fields doing. Lots of sample guidelines for front-end development. Thanks for the framework. Good job.
The text was updated successfully, but these errors were encountered: