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

Redux Guidelines? #22

Closed
dodzki opened this issue Sep 12, 2013 · 28 comments
Closed

Redux Guidelines? #22

dodzki opened this issue Sep 12, 2013 · 28 comments
Labels

Comments

@dodzki
Copy link

dodzki commented Sep 12, 2013

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.

@dovy
Copy link
Member

dovy commented Sep 12, 2013

@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... ;)

@dovy
Copy link
Member

dovy commented Sep 12, 2013

@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.

@teamcrisis
Copy link

@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!

@dovy
Copy link
Member

dovy commented Sep 12, 2013

No downside only benefit. ;)

@dodzki
Copy link
Author

dodzki commented Sep 13, 2013

@dovy , thanks for the reply. Hoping for the more advance tip of your documentation, soon. thank you very much!

@corradomatt
Copy link
Contributor

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...

  1. Am I making extra work for myself and my code (performance wise especially)
  2. 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.

@dovy
Copy link
Member

dovy commented Sep 17, 2013

@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. ;)

@dovy dovy mentioned this issue Sep 17, 2013
@evertiro
Copy link
Contributor

@dovy I've been considering removing get() as well, go for it.

@dovy
Copy link
Member

dovy commented Sep 17, 2013

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.

@dovy
Copy link
Member

dovy commented Sep 17, 2013

@corradomatt You'll want to look at that bit of code above. ;)

@dodzki
Copy link
Author

dodzki commented Sep 18, 2013

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.

media

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.

@dovy
Copy link
Member

dovy commented Sep 18, 2013

@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.

@dovy dovy closed this as completed Sep 18, 2013
@corradomatt
Copy link
Contributor

thanks @dovy - exactly what I was looking for!

@dodzki
Copy link
Author

dodzki commented Sep 19, 2013

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');

@corradomatt
Copy link
Contributor

Try echo dodzki_option('logo', 'url');

If you need to output the urge of the media file.

@dodzki
Copy link
Author

dodzki commented Sep 19, 2013

@corradomatt it's not working. :(

@dodzki
Copy link
Author

dodzki commented Sep 19, 2013

@dovy , @ghost1227 Whew. I made it work!!! thanks!

and now, what's left is to output the text title if media is empty.

@dariodev dariodev mentioned this issue Oct 7, 2013
@dovy
Copy link
Member

dovy commented Oct 31, 2013

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.

@dovy
Copy link
Member

dovy commented Oct 31, 2013

Check the new docs on it: http://reduxframework.com/docs/getting-started/

@teamcrisis
Copy link

@dovy that change doesn't affect embed option, does it? BTW, great work with continuing to make Redux even better!

@dovy
Copy link
Member

dovy commented Oct 31, 2013

@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/

@kprovance
Copy link
Member

@dodzki - NO CURLY BRACKETS??? AGGGGHHH! MY EYES!!!! ;-)

@dovy
Copy link
Member

dovy commented Nov 15, 2013

Did I miss something? lol.

@nasirawan
Copy link

Most of the reference links are dead now... Anyways worth reading

@corradomatt
Copy link
Contributor

Checkout the wiki - https://github.com/ReduxFramework/ReduxFramework/wiki

I believe that all the docs are moving to the wiki instead.

@nasirawan
Copy link

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

@ghost
Copy link

ghost commented Aug 27, 2015

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

@dovy
Copy link
Member

dovy commented Aug 27, 2015

@tusarnill Don't piggyback OLD tickets, make new ones.

Find where $opt_name is defined in the sample-config and update it. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants