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

Auto Import Theme Options #122

Closed
imangm opened this issue Jun 28, 2013 · 18 comments
Closed

Auto Import Theme Options #122

imangm opened this issue Jun 28, 2013 · 18 comments
Milestone

Comments

@imangm
Copy link
Contributor

imangm commented Jun 28, 2013

Hi,

First thanks for your great plugin (again).

I have a question. Is it possible to automatically import theme options and layouts after theme installation in theme mode?

There is a function named "compat_ot_import_from_files" in ot-functions.compact.php which I think will do what I want to do but I don't know how to use it. I have put theme-options.txt and layouts.txt files into option-tree folder but nothing happened and my theme is loaded without any saved options...

Any suggestions please?

Thanks

@imangm
Copy link
Contributor Author

imangm commented Jun 28, 2013

Some Updates:

I think there are some problems with "compat_ot_import_from_files" function.

The function at first loads the options and layouts files with get_stylesheet_directory() and get_template_directory() functions but finally it uses wp_remote_get() to read the file content which returns error as the files are addressed locally and this function is using http to access the files.

I've change this code:

 $get_data = wp_remote_get( $data_file );
 if ( is_wp_error( $get_data ) )
    return false;
$rawdata = isset( $get_data['body'] ) ? $get_data['body'] : '';

with this one:

 $fh = fopen($data_file, 'r');
 $rawdata = fread($fh, filesize($data_file));

And it works perfectly. Of course we should do this for layouts auto import too.
Is this a good solution?

Is there anyway to fix this issue without modifying plugin files directly?

Thanks

@valendesigns
Copy link
Owner

Wouldn't using get_stylesheet_directory_uri() and get_template_directory_uri() solve this issue. I'm trying to not use fopen as it's not allowed in theme mode by the theme check plugin. Can you try those functions out and if they work I'll update the core?

@valendesigns
Copy link
Owner

Once it's sorted you probably shouldn't rely on the deprecated 1.x branch compat_ot_import_from_files() function. The best way to handle that would be to create a couple functions in your theme that run when it's installed. First check for a flag that says it's not been imported yet, so it only runs once, then set the flag to installed when it's done its thing. At some point those functions will be removed entirely and moving away from them now is going to save you a headache later.

However, I still want to solve the issue at hand, so definitely check the alternative functions to see if they work. Cheers!

@valendesigns
Copy link
Owner

@imangm could you do me a favor and please verify that using get_stylesheet_directory_uri() or get_template_directory_uri() and not fopen() would work? I'm trying to clear out the tickets and get a new version out ASAP, and I want to start planing for 2.2 while I'm at it. Cheers!

@valendesigns
Copy link
Owner

@imangm I chose to bump this up to 2.1 and I've gone ahead and changed the paths to be wp_remote_get() compatible. The function should be working again. It used fopen() previously, but I changed it to be more theme check compatible.

Anyhow, version 2.1 is going live either later tonight or more likely tomorrow, because there is one more feature that needs testing; WPML. Anyhow, if you could please confirm that it's working correctly I would really greatly appreciate it.

Cheers!

@imangm
Copy link
Contributor Author

imangm commented Aug 12, 2013

Hi Derek,

I'm really sorry as I didn't answer you on time. I was on a vacation. If you still have time, I would answer it in a few hours.

@valendesigns
Copy link
Owner

No worries, looking forward to your reply.

@imangm
Copy link
Contributor Author

imangm commented Aug 12, 2013

Hi Derek.

I'm so sad as I disappointed you. I'm using your great plugin but I didn't help when I could...

I've upgraded OT to the latest version (2.1.2) putting theme-options.txt and layouts.txt on OT root directory and then installed the theme and after installing, I'm getting several errors on Theme Options page which I think are related to this new importer:

Notice: Undefined index: active_layout in D:\xampp\htdocs\wp2\wp-content\themes\ot_ultraflex\option-tree\includes\ot-functions-admin.php on line 3683

Notice: Array to string conversion in D:\xampp\htdocs\wp2\wp-content\themes\ot_ultraflex\option-tree\includes\ot-functions-admin.php on line 3708

Notice: Array to string conversion in D:\xampp\htdocs\wp2\wp-content\themes\ot_ultraflex\option-tree\includes\ot-functions-admin.php on line 3708

Notice: Array to string conversion in D:\xampp\htdocs\wp2\wp-content\themes\ot_ultraflex\option-tree\includes\ot-functions-admin.php on line 3708

It seems that most of the theme options are load currently but the page is full of these errors. I will work on it.

Maybe it's because that I've exported theme-options in the old version.

Here is the screenshot: http://cdn.themique.com/tf/screenshot.png

@valendesigns
Copy link
Owner

Shit! Okay that sucks, could you please send me your files so I can test it exactly the way you have it running? derek[at]valendesigns.com

@imangm
Copy link
Contributor Author

imangm commented Aug 12, 2013

Hi,

I think I've found the problem. When I go to OptionTree -> Settings -> Layouts, It lists all of my theme options as layouts. For example, I have blue, dark, light layouts, but now there are more than 200 layouts which names are similar to my theme options: tmq_layoutmode, tmq_favicon and ...

@imangm
Copy link
Contributor Author

imangm commented Aug 12, 2013

You mean the theme or just my OT folder?

@valendesigns
Copy link
Owner

The theme please. If you can.

@imangm
Copy link
Contributor Author

imangm commented Aug 12, 2013

Sent. Please let me know if I can help too

@valendesigns
Copy link
Owner

I figured it out!!!! Try the the hotfix-2.1.3 branch.

@valendesigns
Copy link
Owner

I tested the hotfix on the theme you sent and everything seems to be working on my end, other than your radio images not displaying correctly.

Edit: you can use PHP in your path for the radio images since you're setting it up via an array and not the UI builder.

@valendesigns
Copy link
Owner

Could you please confirm. I want to roll out the hotfix before I go to sleep.

@imangm
Copy link
Contributor Author

imangm commented Aug 12, 2013

in 5 minutes

@imangm
Copy link
Contributor Author

imangm commented Aug 12, 2013

Hi Derek.

Yes it works fine this time except radio images that I should fix them as you said on the previous comment.

Thank you very much :)

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

No branches or pull requests

2 participants