I am new with Wordpress.
I have created a simple plugin to save setting for theme.
In this its working fine for saving data in database.
But am having problem when i am exporting my project Databse and import to new database.
That time all settings are gone ,i have to update theme setting every time when i am importing database to new database.
Any suggestion.
What am i doing wrong.
// admin page
function my_custom_settings_form()
{
include('include/settings.php');
}
// admin menu
function my_custom_settings_menu()
{
add_options_page('CustomSetting', ' Theme Settings', 'manage_options', 'theme-settings', 'my_custom_settings_form');
}
add_action('admin_menu', 'my_custom_settings_menu');
// register setting
function my_custom_settings_settings()
{
register_setting('wp_sp_settings_group', 'pageSettings');
}
add_action('admin_init', 'my_custom_settings_settings');
function do_css()
{
wp_enqueue_style('thickbox');
wp_enqueue_style('thickbox');
}
function do_jslibs()
{
wp_enqueue_script('editor');
wp_enqueue_script('thickbox');
add_action( 'admin_head', 'wp_tiny_mce' );
}
add_action('admin_print_scripts', 'do_jslibs' );
add_action('admin_print_styles', 'do_css' );
function wp_gear_manager_admin_scripts() {
wp_enqueue_media();
}
function wp_gear_manager_admin_styles() {
wp_enqueue_style('thickbox');
}
add_action('admin_print_scripts', 'wp_gear_manager_admin_scripts');
add_action('admin_print_styles', 'wp_gear_manager_admin_styles');
?>
include/settings.php
$pageSettings = get_option('pageSettings');
?>
<div class="wrap">
<h2>Theme Settings</h2>
<hr/>
<?php settings_errors('', true, true); ?>
<div class="postbox-container" id="poststuff">
<form action="options.php" method="POST">
<?php settings_fields('wp_sp_settings_group'); ?>
<div class="postbox">
<div class="handlediv" title="Click to toggle">
<br>
</div>
<h3>
<span>Header Logo</span>
</h3>
<div class="inside">
<table class="form-table ">
<tbody>
<tr>
<td>
<div class="uploader">
<input type="text" name="pageSettings[site-logo]" id="site-logo" value="<?php echo $pageSettings['site-logo'] ; ?>" />
<input class="button" type="button" name="site-logo-button" id="site-logo-button" value="Upload" />
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p class="submit">
<input type="submit" value="Save Changes" class="button button-primary" id="submit"
name="submit">
</p>
</form>
</div>
</div>
The Best way to Make a exact copy of database without losing any info is by going to the database itself and export everything. Then import the data into the new website setup your WP config. Once done, go into the database and change your wp-setting data table for values
related to WEBSITE URL
There should be two places you need to change.
Jay has the right answer, but I think off the top of my head the table is wp_options rather than settings. The things you need to change are "siteurl" and "home"
Related
need help with drupal 7. I'm newbie with drupal.
I have code below for validation and validation errors, and it works fine. But errors always appear in wrong place.
I think the problem in $element, but i'm note sure.
some example html
<form id="webform_client_form_226">
<div class="catalogue__form-input-inner">
<div class="catalogue__form-input">
<div class="form-item">
// i need it here
<label for="edit-submitted-vashe-imya--3">Your name</label>
<input name="submitted[vashe_imya]" value="" size="60" maxlength="128" class="form-text error">
</div>
</div>
<div class="catalogue__form-input">
<div class="form-item webform-component webform-component-textfield webform-component--nomer-telefona webform-container-inline">
// and here
<label>Phone number</label>
<input name="submitted[nomer_telefona]">
</div>
</div>
<div class="catalogue__form-button">
// always appears here right now
<div class="form-actions">
<input name="op" value="send"></div>
</div>
</div>
</div>
and template.php
function pkpro_uikit_form_alter(&$form, &$form_state, $form_id) {
// Check the form id
if($form_id == 'webform_client_form_226') {
$form['#validate'][] = 'form_validate';
}
}
function form_validate(&$form, &$form_state) {
$message = "Field required";
if(isset($form_state['values']['submitted']['vashe_imya'])) {
$name = $form_state['values']['submitted']['vashe_imya'];
if( condition ) {
form_error($form['submitted']['vashe_imya'], $message);
}
}
if(isset($form_state['values']['submitted']['nomer_telefona'])) {
$name = $form_state['values']['submitted']['nomer_telefona'];
if( condition ) {
form_error($form['submitted']["nomer_telefona"], $message);
}
}
// get all validation errors.
$form_errors = form_get_errors();
if (!empty($form_errors)) {
foreach ($form_errors as $element => $error) {
$form[$element]['#suffix'] = '<div>'.$error.'</div>';
}
}
// clear default error messages.
drupal_get_messages('error');
}
Help, pls)
You need to modify your template. Look for page.tpl.php. It should have a $message variable on it. Move it to the correct location. If you only want it for one content type or page, copy the page.tpl.php so it only targets what you want.
The business link (Place) is not mandatory when inserting a new event. How to make this mandatory. Every event should be connected with a place !
Visuals
Add class "required_field" and * in the respective Business Link row by replacing this at plugins\geodir_event_manager\gdevents_template_functions.php line 1035
<div id="geodir_link_business_row" class="geodir_form_row clearfix">
<label>
<?php _e( 'Link Business', 'geodirevents' );?>
</label>
with
<div id="geodir_link_business_row" class="required_field geodir_form_row clearfix">
<label>
<?php _e( 'Link Business', 'geodirevents' );?>
<span>*</span>
</label>
in the same function replace also
<input type="button" id="geodir_link_business_autofill" class="geodir_button button-primary" value="<?php echo EVENT_FILL_IN_BUSINESS_DETAILS; style="float:none;margin-left:30%;" ?>"
</div>
with this
<input type="button" id="geodir_link_business_autofill" class="geodir_button button-primary" value="<?php echo EVENT_FILL_IN_BUSINESS_DETAILS; ?>" style="float:none;margin-left:30%;" />
<span class="geodir_message_note"><?php _e('Basic HTML tags are allowed', 'geodirevents');?></span>
<span class="geodir_message_error"> <?php _e("This field is required","gdevents") ?> </span>
</div>
Functional: prevent form from submit
a. deactivate listing_validation.min.js and enable listing_validation.js in
\plugins\geodirectory\geodirectory_template_tags.php line 198
i.e. change this
wp_enqueue_script('geodirectory-listing-validation-script', geodir_plugin_url() . '/geodirectory-assets/js/listing_validation.min.js#asyncload');
to this
wp_enqueue_script('geodirectory-listing-validation-script', geodir_plugin_url() . '/geodirectory-assets/js/listing_validation.js#asyncload');
b. add the check in plugins\geodirectory\geodirectory-assets\js\listing_validation.jsline 159 (validate_form())
if (jQuery('#geodir_link_business')[0].selectedIndex == 0) {
jQuery('#geodir_link_business').closest('.required_field').find('.geodir_message_error')[0].style.display = "inline";
is_validate = false;
} else {
jQuery('#geodir_link_business').closest('.required_field').find('.geodir_message_error')[0].style.display = "";
}
I'm trying to filter out some results in an Algolia faceted search within Wordpress. I want to show only certain results to a user logged in with a specific WP user role. Here is what I have in my results now and it's not returning any result, but the pagination for the search does show up, so I know the script is running without errors. I also do not have any console errors.
This is my current script from instantsearch.php:
<script type="text/html" id="tmpl-instantsearch-hit">
<article itemtype="http://schema.org/Article">
<?php
// Get data
$post_title = '{{{ data._highlightResult.post_title.value }}}';
$aim_of_work = '{{{ data._snippetResult.aim_of_organisations_work.value }}}';
$organisation_region = '{{{ data._highlightResult.organisation_region.value }}}';
?>
<?php
// If user is limited to Americas and the Carribbean
if( in_array('americas', $user_info->roles) ) {
if($organisation_region == 'Americas and the Caribbean') { ?>
<!-- Print Americas Results -->
<div class="ais-hits--content">
<h3 itemprop="name headline"><?php echo $post_title; ?></h3>
<div class="ais-hits--tags">
<# for (var index in data.taxonomies.post_tag) { #>
<span class="ais-hits--tag">{{{ data._highlightResult.taxonomies.post_tag[index].value }}}</span>
<# } #>
</div>
<div class="excerpt">
<p>
<?php echo $aim_of_work; ?>...
</p>
<p class="text-small">Region: <?php echo $organisation_region; ?></p>
</div>
</div>
<div class="ais-clearfix"></div>
<?php } //END if
} else { ?>
<!-- Print All Results -->
<div class="ais-hits--content">
<h3 itemprop="name headline"><?php echo $post_title; ?></h3>
<div class="ais-hits--tags">
<# for (var index in data.taxonomies.post_tag) { #>
<span class="ais-hits--tag">{{{ data._highlightResult.taxonomies.post_tag[index].value }}}</span>
<# } #>
</div>
<div class="excerpt">
<p>
<?php echo $aim_of_work; ?>...
</p>
<p class="text-small">Region: <?php echo $organisation_region; ?></p>
</div>
</div>
<div class="ais-clearfix"></div>
<?php } // END if ?>
</article>
</script>
My concern is that my conditional is not working: if($organisation_region == 'Americas and the Caribbean')
I feel like there is a better way to do this, but I would take any way that works right now.
/**-- UPDATE --*/
Here is my facet widget:
/* Region refinement widget */
search.addWidget(
instantsearch.widgets.menu({
container: '#facet-org-region',
attributeName: 'organisation_region',
sortBy: ['isRefined:desc', 'count:desc', 'name:asc'],
limit: 10,
templates: {
header: '<h3 class="widgettitle">Region</h3>'
}
})
);
Your solution seems to mix JavaScript code with PHP.
PHP code gets parsed and executed on the server side and JavaScript on the client side in the browser.
In your example, $organisation_region will always equal the string '{{{ data._highlightResult.organisation_region.value }}}'.
You probably want to add organisation_region as a facet and then refine on that.
To achieve that, you can take a look how other facets are implemented here https://community.algolia.com/wordpress/customize-search-page.html
Also, here is how to register your custom facet: https://community.algolia.com/wordpress/indexing-settings.html#register-custom-facet
The plugin generated 2 characters of unexpected output during activation. If you notice “headers already sent” messages, my code is below
<?php
/*
Plugin Name: configuration
Description: example plugin to demonstrate wordpress capatabilities
Author: kailash
License: Public Domain
*/
// run the install scripts upon plugin activation
function test_init() {
if(isset($_POST['save'])) {
$setting=$_POST['setting'];
global $wpdb;
$table_name ="setting";
$wpdb->query("UPDATE $table_name SET setting='$setting' WHERE id=1");
//echo"Setting Saved";
}
?>
<form name="form" id="myform" method="POST">
<input type="radio" name="setting" value="2" <?php if($setting==2){echo 'checked="checked"';}?> id="term"/>newconfiguration<br>
<input type="radio" name="setting" value="1" <?php if($setting==1){echo 'checked="checked"';}?> id="term"/>oldconfiguration<br>
<input type="submit" name="save" value="save">
<?php
}
add_action('admin_menu', 'config_plugin_setup_menu');
function config_plugin_setup_menu(){
add_menu_page( 'Test Plugin Page', 'configuration', 'manage_options', 'config-plugin', 'test_init' );
}
Headers already sent
It is usually because there are spaces, new lines, or other garbage before an opening <?php tag or after a closing ?>
check and remove all unnecessary space. example check before
<form> tag. means after ?> tag there is extra space in your code. so check other too and remove all space..!
Check that the very first characters are
<?php
Check that the very last characters are
?>
for details check this
https://codex.wordpress.org/Answers-Troubleshooting
I'm working on this test site, which is a WordPress website (using version 5.5) and using the Canvas WooTheme. The front page of it is supposed to display today's calendar events, which are provided by the WordPress plugin, Events Manager.
What I would like for them to do is display, such as this events page (and the screenshot below - seen in this screenshot), does. Instead, the code below somehow has the rest of the template (including the sidebar) sucked into the table, continuing to duplicate table rows and columns into itself (as seen from this screenshot).
The code it shoots out into Firebug is the following:
<table cellspacing="0" cellpadding="0" id="current-events"><tbody><tr><td class="startdate_cost_td">
<span class="start_time"><table cellspacing="0" cellpadding="0" id="current-events"><tbody><tr>
<td class="startdate_cost_td">
<span class="start_time">12:00 AM</span><br>
<span class="cost">Free</span>
</td>
<td class="event_image"> <img src="../../../wp-includes/images/default_img.jpg"></td>
<td class="event_title">Sex Addicts Anonymous meeting<br>
<i><span class="location_name"># No location listed</span></i>
<div id="read_more_wrapper">
<img src="../../../wp-includes/images/little_pink_arrow.jpg"><a class="pink_link" href="http://testbuzz.illinimedia.com/events/sex-addicts-anonymous-meeting-90">READ MORE</a></div></td></tr>
<!--12:00 AM</span><br/><span class='cost'>Free</span></td><td class='event_image'><img src='../../../wp-includes/images/default_img.jpg' /></td><td class='event_title'>Sex Addicts Anonymous meeting<br/><i><span class='location_name'>#No location listed</span></i><br />Mind, body, & spirit<div id='read_more_wrapper'><img src='../../../wp-includes/images/little_pink_arrow.jpg' /><a href='http://testbuzz.illinimedia.com/events/sex-addicts-anonymous-meeting-90' class='pink_link'>READ MORE</a></td></tr></div><tr><td class='startdate_cost_td'>
<span class='start_time'>-->
<tr>
<td class="startdate_cost_td">
<span class="start_time">8:30 AM</span><br>
<span class="cost">Free</span>
</td>
<td class="event_image"><img alt=""Inside India" with Larry Kanfer" src="http://testbuzz.illinimedia.com/wp-content/uploads/locations-pics/event-35214.jpg"> </td>
<td class="event_title">“Inside India” with Larry Kanfer<br>
<i><span class="location_name"># Alice Campbell Alumni Center</span></i>
<div id="read_more_wrapper">
<img src="../../../wp-includes/images/little_pink_arrow.jpg"><a class="pink_link" href="http://testbuzz.illinimedia.com/events/inside-india-with-larry-kanfer-31">READ MORE</a></div></td></tr>
......more events similar to this......
<div class="fix"></div>
<div class="nav-entries">
<span class="nav-prev icon fl">Older posts</span> <div class="fix"></div>
</div>
<!-- /#main -->
<div id="sidebar">
<div class="widget widget_woo_search" id="woo_search-3"><div class="search_main">
<form action="http://testbuzz.illinimedia.com/" class="searchform" method="get">
<input type="text" onblur="if (this.value == '') {this.value = 'Search...';}" onfocus="if (this.value == 'Search...') {this.value = '';}" value="Search..." name="s" class="field s">
<input type="image" name="submit" class="submit" alt="Search" src="http://testbuzz.illinimedia.com/wp-content/themes/canvas/images/ico-search.png">
</form>
<div class="fix"></div>
</div>
.... the rest of the content stuck .....
</span></td></tr></tbody></table>
Below is the code I stuck into our magazine template within our child theme, template-magazine.php, which is causing the problem:
<?php
$page = ( !empty($_REQUEST['page']) && is_numeric($_REQUEST['page']) )? $_REQUEST['page'] : 1;
$args = array(
'limit' => 10,
'scope' => 'today',
'pagination' => 1
);
if (isset($_REQUEST['c'])) {
$args['category'] = $_REQUEST['c'];
$args['scope'] = 'future';
}
$args['offset'] = $args['limit'] * ($page-1);
$events = em_get_events_array($args);
$size = sizeof($events)-1;
echo "<h2 id='headding'class='title'>Today's Events</h2>";
echo "<table cellpadding='0' cellspacing='0' id='current-events' >";
for ($i=0;$i<$size;$i++) {
echo "<tr><td class='startdate_cost_td'>
<span class='start_time'>" . $events[$i][0] .
"</span><br/><span class='cost'>" . $events[$i][7] .
"</span></td><td class='event_image'>";
if ($events[$i][8] == '') {
echo "<img src='../../../wp-includes/images/default_img.jpg' />";
}
else {
echo $events[$i][9];
}
echo "</td><td class='event_title'>" . $events[$i][10] .
"<br/><i><span class='location_name'>#". $events[$i][11] .
"</span></i><br />" .$events[$i][12] .
"<div id='read_more_wrapper'>" .
"<img src='../../../wp-includes/images/little_pink_arrow.jpg' /><a href='" . $events[$i][13] . "' class='pink_link'>READ MORE</a></td></tr>" .
"</div>";
}
echo "</table>";
$last_index = count($events) - 1;
echo $events[$last_index][0];
?>
I made sure the PHP code above was the cause of the main problems, by removing the code itself. That seems to do the trick! When I tried placing this code in different parts of the template-magazine.php file, it repeated the same results. When I also moved this to the functions.php file in our child theme, it simply made everything else go further down and expand to the whole width of the browser. How do I get rid of the looping in the code, having all of the side content being sucked into the table being created?
UPDATE: I commented out the above PHP code using HTML tags, duplicating the events and commenting out the table elements, which we would like to have show on the page. Below is the screenshot of what it looks like: https://docs.google.com/open?id=0B2UC67NQiW2yalhMSGxra0FFWGM and the code that's showing up in the picture below (I didn't want to paste in the code because it would've been very long:
It ended up being that it seemed to be reading in the Event Preview settings, which I created within the plugin. All I needed to do was simply create a for loop, reading in each of the events for that specific page, blocking out the rest of the PHP code above. The following is the code used to read in the events:
for ($i=0;$i<$size;$i++) {
echo $events[$i][0];
}
Hopefully this helps someone using the Events Manager plugin.