Comments (28)
@dodzki We're working on documentation over the next few days. Here's a start that you can look at:
http://reduxframework.com/docs/fields/
You're right. You're at the cutting edge over here! That's why it's beta... ;)
from redux-framework.
@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.
from redux-framework.
@dovy @dodzki just tested this change with a few options and seems to work just fine! It cleans up the code a bit too. @dovy Any downside to this over the other methods? Thanks again for all the work you're putting into this!
from redux-framework.
No downside only benefit. ;)
from redux-framework.
@dovy , thanks for the reply. Hoping for the more advance tip of your documentation, soon. thank you very much!
from redux-framework.
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...
- Am I making extra work for myself and my code (performance wise especially)
- Is my reasoning for the function a good one? the reason being to not include "global $MY_Options;" on every template file that I need to pull an option.
from redux-framework.
@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 $args['global_variable']
you set.
Let's say for example your opt_name is theme_ten
. Then if global_variable
isn't set, your variable is $theme_ten
. If you set your global_variable
arg to say iamcool
, your global variable is then $iamcool
.
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. ;)
from redux-framework.
@dovy I've been considering removing get() as well, go for it.
from redux-framework.
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.
from redux-framework.
@corradomatt You'll want to look at that bit of code above. ;)
from redux-framework.
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.
from redux-framework.
@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.
from redux-framework.
thanks @dovy - exactly what I was looking for!
from redux-framework.
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
my opt_name is
$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');
from redux-framework.
Try echo dodzki_option('logo', 'url');
If you need to output the urge of the media file.
from redux-framework.
@corradomatt it's not working. :(
from redux-framework.
@dovy , @ghost1227 Whew. I made it work!!! thanks!
and now, what's left is to output the text title if media is empty.
from redux-framework.
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.
from redux-framework.
Check the new docs on it: http://reduxframework.com/docs/getting-started/
from redux-framework.
@dovy that change doesn't affect embed option, does it? BTW, great work with continuing to make Redux even better!
from redux-framework.
@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. ;)
http://reduxframework.com/docs/advanced/embed/
from redux-framework.
@dodzki - NO CURLY BRACKETS??? AGGGGHHH! MY EYES!!!! ;-)
from redux-framework.
Did I miss something? lol.
from redux-framework.
Most of the reference links are dead now... Anyways worth reading
from redux-framework.
Checkout the wiki - https://github.com/ReduxFramework/ReduxFramework/wiki
I believe that all the docs are moving to the wiki instead.
from redux-framework.
Thanks @corradomatt
I did the install successfully. Was wondering if there's any front-end configured basic theme as well? That would help as a foundation.
Asking this because upon simple calling certain functions, did faced strange errors like Warning: Illegal string offsetxxxx. in xxx/theme.php line no 917
from redux-framework.
Please help, Before of Redux Framework
'opt_name' => 'demo' from here get the text into footer.php
But in update of Redux Framework
'opt_name' => $opt_name <---- how can i get the output text into my footer.php
from redux-framework.
@tusarnill Don't piggyback OLD tickets, make new ones.
Find where $opt_name is defined in the sample-config and update it. ;)
from redux-framework.
Related Issues (20)
- Push Metabox field dynamically HOT 2
- Multilingual social media profiles HOT 1
- Check for object before assigning
- cannot click on pages HOT 1
- Can't change the home screen logo and colours of the theme HOT 1
- Unable to add variable products from woocommerce to my cart
- v4.4.10 - Undefined Variable $return in class-redux-filesystem.php
- Thecappa Theme - Animations can't be turned off HOT 1
- 4.4.10 Redux Upgrade - Fatal error HOT 1
- How to set default values for typography field with Redux::set_option? HOT 1
- change redux default values on child theme HOT 4
- Warning count display Nan on left side for color menu HOT 1
- Attribute not working with text field HOT 4
- WordPress Backend is buggy HOT 6
- Backend is buggy- No Field ID is set HOT 8
- Project Icon Category Type Not Change HOT 1
- Bug on switch or button_set fields while in tab and zero/false value HOT 2
- Bug in Dimension Field HOT 3
- Repeater extension : create unique ID for each entry HOT 1
- Theme options resets and show default values after avg (1min) of editing in wp customizer HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-framework.