Can't save theme options, following a tutorial from tutsplus - php

I know that the question has been asked before, why isn't my code saving, but this tutorial was recently recommended by a user here, and I have been following it from tuts plus, (obviously changing variables and options to fit my needs), but for some reason the little bar that says settings saved will come up, and the save button comes up, the form itself, it all looks right, but when I hit save, it is gone from the form. Keep in mind that I have only tried saving the settings for the first options, site logo url. Here is my code, it is properly included in the functions.php file.
PS: Sorry for it all being together, PHP and HTML, but that was the only way to get it all together in one post, plus, I like to put things in separate files after I finish.
<?php
if (!current_user_can('manage_options')) {
wp_die('You do not have permission to view this page, if you believe that this is a mistake, please contact your system administrator, or try closing the tab and come back.');
}
add_action("admin_menu", "setup_where_now_admin_menus");
function setup_where_now_admin_menus() {
add_menu_page('Front Door Theme Options', 'Front Door Theme Options', 'manage_options', 'where_now_elements', 'where_now_options') ;
}
?>
<?php
function where_now_options() { ?>
<div class="wrap">
<h2>Front Door Web Design Custom Theme Options</h2>
<form method="post" action="">
<h4>Site Logo URL</h4>
<p>Remember, this is the image used in places like your header, or anywhere else you want your logo to appear, and if you are having trouble remembering how to use this feature, you can always upload your new logo to the media section in Wordpress, get the URL from the specific images page, and then paste it here!</p>
<input type="text" name="site_logo" value="<?php echo $site_logo;?>" size="25">
<h4>Analytics Tracking Code</h4>
<p>Any code used for tracking purposes that is placed in the header goes here</p>
<input type="text" name="analytics_code">
<?php
$site_logo = get_option("where_now_site_logo");
if (isset($_POST["update_settings"])) {
$site_logo = esc_attr($_POST["site_logo"]);
update_option("where_now_site_logo", $site_logo);
?>
<div id="message" class="updated">Your Changes Have Been Saved</div>
<?php
}
?>
<input type="hidden" name="update_settings" value="Y" />
<input type="submit" value="Save settings" class="button-primary"/>
</form>
</div>
<?php
}
?>
Any ideas?

I recommend you to use this Plugin: Option Tree
It is very simple and doesn't need any coding.Just install it on your website that your theme is running,then you can manage your options easily.

Related

using get_post_meta() In wordpress plugin after form submit

I have a simple wordpress plugin that will take one or two inputs and display a chunk of HTML using a few pieces of meta data from custom posts in Wordpress (within the plugin admin menu).
I have it displaying the HTML output just fine on a new blank page, as well as displaying the input from $_POST when I tested it, although when I try and use get_post_meta() function using my $_post variables within that html output it draws a blank.
I'm using one PHP file, and the code is:
<?php
if (!isset($_POST['submit'])) {
?>
<h1>My Plugin</h1>
<form action="<?php echo plugin_dir_url( __FILE__ ).'myplugin.php'?>" method="post" >
Enter input:<input type="text" name="info" size="30">
<p><input type="submit" name="submit" value="Go">
</form>
<?php
}
else {
?>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<?php
$info = $_POST['info'];
?>
Information based on your input is:<?php echo get_post_meta($info, '_info', true); ?>
</body>
</html>
<?php } ?>
I'm a beginner at PHP and plugin development, so apologies for all the silly mistakes that are sprinkled in their most likely.
From my scouring on SO and other wordpress forums, I've got a hint that I might be taking the output out of the wordpress 'Sandbox' and therefore direct wordpress functions wouldn't work. So my question would be, what is the best way to generate my chunk of html with dynamic php on a separate blank page that still works with get_post_meta()?
I should mention that the code works correctly if I put it all on the first plugin page with no forms, and just force a few test variables to pull from the DB.

Wordpress tag filtered drop down form for wordpress pages

I'm working on a site for a client, who has specified he wants to replicate the functionality of the Rehab center database drop-down form on WordPress located at http://brainandspinalcord.org/ for a section on his own site.
I would like to modify the contents to be filtered by a tag assigned to a page, so that adding to the list is a simple matter of assigning that tag to a page; A plugin solution is preferred, but rather difficult to find, as the word drop-down is used generally for header menus that expand on hover to show sub-pages.
Instead, after researching, I found this code:
<li id="pages">
<h2><?php _e('pages:'); ?></h2>
<form action="<?php bloginfo('url'); ?>" method="get">
<?php wp_dropdown_pages(); ?>
<input type="submit" name="submit" value="view" />
</form>
</li>
How can I add a tag based filter to this?
Further research into the subject turned up Documentation on the function which I found an argument for child_of that will generate the desired functionality.

Made Wordpress Plugin - Shows up at top of entire site

*EXAM AT HIVOLDA, IN CASE EXTERNAL EXAMINER SEES THIS*
I have just made some Wordpress Plugin for school.
My PHP-files works just fine, but when I upload and activates them as plugin, they only shows up at top of the page.
As you understand, I am kinda noob...
Screenshot: s27.postimg.org/53w3bmyw3/131128oav_plugin.jpg
Here is the shortest code:
<html>
<head>
<meta charset="utf-8">
<title>Registrering av åpne bakker</title>
</head>
<body>
<?PHP
/**
* Plugin Name: Haugsdalen Skisenter Bakkeregistrering
* Description: Registrering av åpne/stengte bakker for Haugsdalen Skisenter.
*/
function visSkjema(){
echo('
<form id="bakkerreg" name="bakkerreg" method="post" action="bakkerreg.php">
<label for="hoved">Er hovedbakken åpen?</label><br/>
<input type="radio" name="hoved" value="Åpen">Ja
<input type="radio" name="hoved" value="Stengt">Nei<br/>
<label for="skog1">Er skogsløypen vest åpen?</label><br/>
<input type="radio" name="skog1" value="Åpen">Ja
<input type="radio" name="skog1" value="Stengt">Nei<br/>
<label for="skog2">Er skogsløypen øst åpen?</label><br/>
<input type="radio" name="skog2" value="Åpen">Ja
<input type="radio" name="skog2" value="Stengt">Nei<br/>
<input type="submit" name="lagre" id="lagre" value="Send inn">
</form>');
}
if( isset($_POST['lagre'])) {
if( $_POST['hoved']!="" &&
$_POST['skog1']!="" AND
$_POST['skog2']!="" ){
/* Her lagrer den til databasen*/
$db = mysql_connect('localhost','USERNAME','PASSWORD');
/* Velge database */
mysql_select_db('USERNAME',$db);
/* Definer spørringen */
$sql = "INSERT INTO bakker(hoved,skog1,skog2)
VALUES('".$_POST['hoved']."',
'".$_POST['skog1']."',
'".$_POST['skog2']."') ";
/* Kjør spørring */
$resultat = mysql_query($sql);
if($resultat) {
echo ("<p>Grattis, du har nå registrert informasjonen!</p>");
}else {
echo ("<p>Du failet!</p>");
echo ("<p>".mysql_error()."</p>");
}
}else{ // Manglande obligatoriske felt
visSkjema();
}
}else {
/*Vis skjema, ingen har trykt på lagre knappen (enda) */
visSkjema();
}
?>
</body>
</html>
Suggestions? :)
The intention is to easy update information on the frontpage. It will be a admin-poll-system, where the company can update the information by pressing checkboxes. I have made 3 plugins that has this function. This one has the function that the company can update which of the ski hills are open. I have also made a plugin which has a registration form, and sends to database. And a file that recieve information from the database, and admin can delete any rows.
*EXAM AT HIVOLDA, IN CASE EXTERNAL EXAMINER SEES THIS*
It sounds like you're a bit confused on how WordPress functions. Plugins are all included into Wordpress at the very beginning of the page load, right after WordPress gets all its files loaded, but before it actually does anything. This allows plugins to modify any functionality from that point further, but means you can't actually write out any code yet, because then it'd end up at the top of the page.
Wordpress combats this issue by what is called the hook system. Hooks (or action hooks) are setup throughout WordPress and are called at certain times, and you can register your functions with them, so they are called when that hook is run. I know that's a bit abstract, so here is an example:
add_action( 'get_footer', 'customplugin_footer_hook' );
function customplugin_footer_hook ($name)
{
echo 'Some code here.';
echo 'This will show up right before the footer, because it's registered to the get_footer action hook';
}
There are actions and filters, filters are designed to modify data passed to them, and return it, actions (or hooks) are designed to be given data and print something to the screen (but that isn't always what they're used for).
All this being said, it doesn't look like it'd help much with what you're actually trying to do, as processing post data in WordPress can be a bit confusing, and I can't tell if that is suppose to be a poll, or admin settings, or something else; I don't speak Norwegian :)
Give us a bit more information on what you're trying to achieve and we may be able to give you a bit more detailed information on how to do it.
Some helpful links in the meantime:
Wordpress action hooks
Wordpress filter hooks
Decent guide over hooks

custom wordpress comment form html

I would like to modify the actual HTML of the comment forms in WordPress. I know of the comment_form() function that WordPress provides, but it doesn't actually let me modify the html of the form. What I'm specifically trying to do is make a bootstrap responsive form, which is not possible with the options provided with the comment_form() function. I've tried looking all over the internet for a way, but to no avail. Can anyone point me in the right direction?
Let me clarify this:
I am looking to modify the actual FORM and containing DIV elements of the comment form, not just the fields.
The uncustomizable parts of the function comment_form() should (idealistically) be limited purely to code that is essential for security and proper form handling by the WordPress core. However, that is not the case. To explore the issue, I used filters (could have used arguments) to completely remove all the code that is customizable. I set all available variables to empty strings—that is, all the stuff mentioned on the codex page for comment_form().
Here is the left-over, non-customisable code from comment_form():
<div id="respond" class="comment-respond">
<h3 id="reply-title" class="comment-reply-title"> <small><a rel="nofollow" id="cancel-comment-reply-link" href="/1#respond" style="display:none;">Click here to cancel reply.</a></small></h3>
<form action="http://www.[yourdomain].com/wp-comments-post.php" method="post" id="" class="comment-form">
<p class="form-submit">
<input name="submit" type="submit" id="" value="" />
<input type='hidden' name='comment_post_ID' value='1' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</p>
</form>
</div><!-- #respond -->
Where does all this come from? At the bottom of the codex page for comment_form() it says…
Source Code
comment_form() is located in wp-includes/comment-template.php.
comment-template.php is linked and you can view the full code in the browser. comment_form() starts on line 1960. In fact, it’s the last function in that file. There are no arguments or filters that let you modify the residual code above. These lines of code are all moreorless “hard-coded”.
The text Click here to cancel reply. is the only text that survived my filter genocide. Strangely, comment_form() has back-up text for cancel_reply_link hard-coded into the function, in case it is passed to the function as an empty string. None of the other filterable items have hard-coded back-ups.
It is easy to see which bits of code are essential and which bits are non-essential for a HTML form. A little more difficult to judge is which bits are essential for a WordPress form. Some of the bits above were dynamically output (note that this is the first comment on a development blog with no other replies, no parent/child comments).
From the comment_form() function in comment-template.php you can draw out the code needed to produce the dynamic parts of the WordPress form. Then, with default arguments taken from the codex page for comment_form(), you could piece together a barebones form, hard-coding the desired fields, labels and wrapping HTML. I’m doing that now and putting my custom form function in my theme’s comments.php template file, which I call using comments_template() only in single.php (for this particular theme).
The result would be a full and proper, lean and mean WordPress comment form. But… it would be a form that could not be customized anymore using comment_form() arguments or related filters unless you went ahead and included the filter code in your own comment form function. Since you’re customizing the heck out it already, that’s probably not a problem. Similarly, all the WordPress actions would also be unavailable to you or any other plugins unless you also triggered those action functions in your own comment form function. Again, probably not an issue for you at this point.
But most importantly, the resulting form might break your theme if future WordPress updates change the way the core handles forms.
If you’re aware of those risks, you can probably rebuild a hand-coded comment form just from copying code on the codex page for comment_form() and in wp-includes/comment-template.php. I don’t have the finished code, otherwise I’d post it. But I will post when/if I succeed.
Right, that’s all from me for now. Bear in mind (all readers) that despite appearances, I am an amateur WordPress theme developer and my proficiency with PHP and WordPress is very rudimentary. Just writing up this post I learned a lot.
I’m also worried that a full and proper solution is already out there somewhere but I haven’t found it in my searches.
Just Create a New PHP file with the name of comment_form.php then paste all of your code. And your comment form is ready.
you shouldn't edit the wp-includes/comment-template.php file.
Keep this for your ref for more styling your existing comment form
http://codex.wordpress.org/Template_Tags/comment_form
Or this one
http://wordpress.org/support/topic/where-to-find-the-comment_form-function-in-wp3
Form code and action
<div class="comment-form">
<h2 class="comments-wrapper-heading"> Leave a comment </h2>
<form id="commentform" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<div class="commentform-element">
<label class="hide" for="author">Full Name</label>
<input class="input-fields" id="author" name="author" type="text" placeholder="Full Name" value=""/>
</div>
<div class="commentform-element">
<label class="hide" for="author">Email</label>
<input class="input-fields" id="email" name="email" type="text" placeholder="Email" value=""/>
</div>
<div class="commentform-element">
<label class="hide" for="comment">Message</label>
<textarea id="comment" class="input-fields" placeholder="Message" name="comment" cols="40" rows="200"></textarea>
</div>
<input name="submit" class="form-submit-button" type="submit" id="submit-comment" value="Post comment">
<input type="hidden" name="comment_post_ID" value="22" id="comment_post_ID">
<input type="hidden" name="comment_parent" id="comment_parent" value="0">
</form>
</div>
WP does not offer a way to create and use a comment form template. i.e.: as of 4.1.1, there's still no way to control all of the HTML markup that makes up the form. There are only ways to edit parts of it and that's by supplying arguments to comment_form().
So, if you would like to edit the whole layout (e.g.: place some of the content side to side instead of on top of one another; replace some of the <p>with <div>), you're out of luck.
What can we do?
An option would be to borrow the whole comment_form() function from the WordPress codebase (like this guy did): make a copy of the function in your theme, rename it, customize it and then call it in place of the vanilla function. That will work but there's a chance it might break on a future WordPress update if some of the inner workings of WP change.
Did you look for the comment_form() function in Wordpress code to see if you can edit it ?
You'll also find some informations here :
http://wordpress.org/support/topic/editing-the-comment-form
This function uses the default form. You need to make a comment-template.php file in your theme and in that file you can make your form.
Now when you will call comments_template() you will get your made form instead of default form.
I don't think you can change the containing div (<div id="respond" class="comment-respond">). Have a look at the comment-template.php
The only thing you can change is the form ID. 'id_form' => 'commentform'
You can make a responsive form without changing these elements.
I've recently answered something similiar on WPSE. You can go and check it out here

Dynamically generated Wordpress Wysiwyg Editor ( wp_editor ) not displaying properly

I have 2 html wysiwyg editors on a wordpress admin page. Both use WP_EDITOR() function. The first one is hard coded into the page:
<form name="form1" id="form1" method="post" action="" style="display:block;">
<p>
<!-- editor here -->
<?php
wp_editor( 'CONTENT WILL APPEAR HERE!', 'addsometxt', array('textarea_name'=>'create_txt','textarea_rows'=>10,'wpautop'=>false));
?>
</p>
<p>
<input name="save" type="submit" class="button-primary" id="save" style="margin:5px;" value="Save Input" /></p>
</form>
The second one is generated dynamically with a PHP function using an AJAX call (wp_ajax_ and $.post). I've test the ajax call and know it works; so, for brevity, here's the php function:
<?php
function display_editor2() {
// grab data from database (data_from_db) and display in editor
wp_editor( $row->data_from_db, 'editsometxt', array('textarea_name'=>'edit_txt','textarea_rows'=>10,'wpautop'=>false));
}
?>
The problem is that even though the 2nd editor is displaying; it's missing all the tool bar buttons. See image below for illustration. Anyone know who to fix this?
I had the same problem.
When I add the code <?php wp_footer(); ?> in my footer.php, it works.
I had the exact same issue and solved it this way (WP 4.7):
First create an hidden editor in your template so WP load all the necessary files for TinyMCE (the ID doesn't matter):
<div style="display:none"><?php wp_editor('', 'hidden_editor'); ?></div>
Then after you appended the new editor to the DOM, use the following functions:
quicktags({id :'your_new_editor_id'});
tinymce.execCommand('mceAddEditor', true, 'your_new_editor_id');
Using tinymce.init didn't worked for me, as the new editor ID wasn't recognized. Those two lines reinstantiate the quicktags and add the new editor.
Probably you need to add media_buttons and tinymce parameter on your AJAX call.
Something like this:
<?php
function display_editor2() {
// grab data from database (data_from_db) and display in editor
wp_editor( $row->data_from_db, 'editsometxt', array('textarea_name'=>'edit_txt','media_buttons'=>true,'tinymce'=>true,'textarea_rows'=>10,'wpautop'=>false));
}
?>
I recommend you check wp_editor() Function Reference page at Wordpress Codex.
Hey I too had the same problem!
I just deactivated all the plug-ins which are installed by me and refreshed the page, and then I tried to edit the post/pages in the visual area also. Check once it will work for you. :)
I hade the same problem, using this:
<?php wp_editor(get_the_content()); ?>
By passing a ID (second parameter to wp_editor) I got the buttons.
Like this:
<?php wp_editor(get_the_content(), "with_a_ID_its_buttons_are_showing"); ?>

Categories