Hi there,
I'm working on a project, but I'm a bit stuck. It's a logical question. I'll explain: We have a list of articles - Table: articles - saved in the database. However, we have collapse-able elements (let's call them accordeons now), which are based on the enabled languages (Table: languages). Now I'm tasked with saving every input for every "Accordeon" in the database, where content for the accordeons is stored in "article_language".
The accordeon
(It's contained in a WHILE-loop)
<div class="accord">
<div class="accordeon-head" data-id="<?php echo $language['shortname']; ?>"><?php echo $language['fullname']; ?><div class="accordeon-right"><i class='fa fa-chevron-down'></i></div></div>
<div class="accordeon-body" data-id="<?php echo $language['shortname']; ?>">
<div class="form-container bottom">
<div class="form-float full-width">
<label class="input-label" for="agg_e_txt"><?php echo $lang['ARTS_INPL_TXT']; ?></label>
<textarea type="text" id="agg_e_txt" name="agg_e_txt"><?php echo $text['article_text']; ?></textarea>
</div>
<div class="clear toplabel"></div>
<div class="form-float middle">
<label class="input-label" for="agg_e_rec"><?php echo $lang['ARTS_INPL_RECUSE']; ?></label>
<textarea type="text" id="agg_e_rec" name="agg_e_rec"><?php echo $text['article_recuse']; ?></textarea>
</div>
<div class="space"></div>
<div class="form-float middle" style="float:right;">
<label class="input-label" for="agg_e_spec"><?php echo $lang['ARTS_INPL_SPEC']; ?></label>
<textarea type="text" id="agg_e_spec" name="agg_e_spec"><?php echo $text['article_spec']; ?></textarea>
</div>
</div>
<div class="clear"></div>
</div>
</div>
I'd like to do this with an AJAX post. What is the best way to store everything for an accordeon in the article_language table with the correct language prefix?
My thoughts were a WHILE loop in the AJAX call, or a each in the jQuery. But, I'm not sure.
What is the best way to achieve this?
I am creating a WP theme. My search function does not work well.
When I hit the Search button nothing happens, it doen't even refresh the page. But when I type in the URL www.example.com/?s=Lorem I get the results. I don't understand why my search button does not work. Can anyone tell me how can I fix this problem? Below you will see my search.php and searchform.php
search.php
<?php get_header(); ?>
<main role="main">
<!-- section -->
<section>
<h1><?php echo sprintf( __( '%s search-form Search Results for ', 'mytheme' ), $wp_query->found_posts ); echo get_search_query(); ?></h1>
<?php get_template_part('loop'); ?>
</section>
<!-- /section -->
</main>
<?php get_footer(); ?>
searchform.php
<div id="search">
<button type="button" class="close" style="background:transparent;border-radius: 0px;">x</button>
<form method="get" id="searchform" action="<?php echo esc_url(home_url('/')); ?>">
<input type="search" value="" name="s" placeholder="<?php if (!empty($theme_options['search_placeholder'])) { echo $theme_options['search_placeholder']; } ?>" />
<button type="submit" class="btn btn-primary"><?php _e( 'Search', 'mytheme' ); ?></button>
</form>
</div>
May be you miss something. Replace input tag code with following code
<input type="search"
value="<?php the_search_query(); ?>"
name="s"
placeholder="<?php if(!empty($theme_options['search_placeholder'])) {
echo $theme_options['search_placeholder'];
} ?>"
/>
Thank you for your answers.
My initial code above was working fine after I removed
wp_register_script('slick.min', get_template_directory_uri() . '/js/slick.min.js', array('jquery'), '1.0.0', true);
//wp_enqueue_script('slick.min'); // Enqueue it!
from my functions.php
newsletter subscription not working in all pages. no newsletter confirmation mail send to customers
<div class="custom-subscribe">
<div class="title">
<span><?php echo $this->__('Newsletter') ?></span>
</div>
<form action="<?php echo $this->getFormActionUrl() ?>" method="post" id="newsletter-validate-detail">
<div class="form-subscribe-header">
<label for="newsletter"><?php echo $this->__('Sign Up for Our Newsletter:') ?></label>
</div>
<div class="input-box">
<input type="text" name="email" id="newsletter" title="<?php echo $this->__('Sign up for our newsletter') ?>" class="input-text required-entry validate-email form-control" />
</div>
<div class="actions">
<button type="submit" title="<?php echo $this->__('Subscribe') ?>" class="button"><span><span><?php echo $this->__('Subscribe') ?></span></span></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
var newsletterSubscriberFormDetail = new VarienForm('newsletter-validate-detail');
//]]>
</script>
Please check below solutions:
In the Magento backend "System > Permissions > Variables" and "System > Permissions > Blocks"
Add newsletter/subscribe and refreshed cache.
More info:
There is a new check on the template directive, see Mage_Core_Model_Email_Template_Filter::blockDirective() line 176
if ($this->_permissionBlock->isTypeAllowed($blockParameters['type'])) {
$type = $blockParameters['type'];
$block = $layout->createBlock($type, null, $blockParameters);
}
Also check in system configuration as below:
System--->Advanced--->Advanced
I have almost done a successful first time plugin, but unfortunately I cannot submit my updated values to the array I've created upon my register_activation_hook.
I need some insights in how Wordpress can handle all the dirty work - or will a $_POST be a better way to do it?
Below you'll see my admin.php which handles all admin related stuff.
<?php
// Meaning of abbreviations:
// clsc = Custom login shortcode
// Runs when plugin is activated
register_activation_hook( PLUGIN_MAIN_FILE, 'clsc_install');
// Create new database fields
function clsc_install() {
$clsc_options = array(
'Login_link' => '/log-in/',
'Login_string' => __('Log in', 'clsc'),
'Login_class' => '', // Default is empty to inherit theme styles
'Logout_link' => wp_logout_url( home_url()),
'Logout_string' => __('Log out', 'clsc'),
'Logout_class' => '', // Default is empty to inherit theme styles
'Account_link' => '/my-account/',
'Account_string' => __('My Account', 'clsc'),
'Account_class' => '' // Default is empty to inherit theme styles
);
add_option('clsc_options_array', $clsc_options, '', 'yes');
}
// Create admin option page
function add_clsc_option_page() {
add_options_page(
'Custom Login', // The text to be displayed in the title tag
'Custom Login', // The text to be used for the menu
'administrator', // The capability required to display this menu
'custom-login-shortcodes', // The unique slug name to refer to this menu
'clsc_html_page'); // The function to output the page content
}
/* Call the html code */
add_action('admin_menu', 'add_clsc_option_page');
// Enqueue admin styles and scripts
function clsc_enqueue_scripts() {
global $wpdb;
$screen = get_current_screen();
if ( $screen->id != 'settings_page_custom-login-shortcodes' ) {
return; // exit if incorrect screen id
}
wp_enqueue_style( 'brokenfruit-shortcodes-styles', plugins_url( 'admin/css/admin_styles.css', dirname(__FILE__) ) );
wp_enqueue_style( 'bootstrap', plugins_url('admin/css/bootstrap.css', dirname(__FILE__) ) );
wp_enqueue_script('admin_js_bootstrap_hack', plugins_url('admin/scripts/bootstrap-hack.js', dirname(__FILE__) ) );
}
add_action('admin_enqueue_scripts', 'clsc_enqueue_scripts' );
// Build admin interface
function clsc_html_page(){
$options = get_option('clsc_options_array');
?>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options'); ?>
<div class="bootstrap-wrapper">
<div class="row">
<div class="col-md-12">
<h1><?php _e('Custom Login Shortcode','clsc'); ?></h1>
<p><?php _e('To use for shortcode:','clsc'); ?><br/><span class="shortcode-preview">[custom_login]</span></p>
</div>
</div>
<div class="row" id="login-content">
<div class="col-md-4">
<h5><?php _e('Log in link:','clsc'); ?></h5>
<input placeholder="<?php _e('Example: /log-in/', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Login_link']; ?>" />
</div>
<div class="col-md-4">
<h5><?php _e('Log in string:','clsc'); ?></h5>
<input placeholder="<?php _e('Example: Log in', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Login_string']; ?>" />
</div>
<div class="col-md-4">
<h5><?php _e('Log in class:','clsc'); ?></h5>
<input placeholder="<?php _e('Example: login_style', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Login_class']; ?>" />
</div>
</div>
<div class="row top-buffer" id="logout-content">
<div class="col-md-4">
<h5><?php _e('Log out link:','clsc'); ?></h5>
<input placeholder="<?php _e('Example: /log-out/', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Logout_link']; ?>" />
</div>
<div class="col-md-4">
<h5><?php _e('Log out string:','clsc'); ?></h5>
<input placeholder="<?php _e('Example: Log out', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Logout_string']; ?>" />
</div>
<div class="col-md-4">
<h5><?php _e('Log out class:','clsc'); ?></h5>
<input placeholder="<?php _e('Example: logout_style', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Logout_class']; ?>" />
</div>
</div>
<div class="row top-buffer" id="account-content">
<div class="col-md-4">
<h5><?php _e('Account link:','clsc'); ?></h5>
<input placeholder="<?php _e('Example: /my-account/', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Account_link']; ?>" />
</div>
<div class="col-md-4">
<h5><?php _e('Account string:','clsc'); ?></h5>
<input placeholder="<?php _e('Example: My Account', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Account_string']; ?>" />
</div>
<div class="col-md-4">
<h5><?php _e('Account class:','clsc'); ?></h5>
<input placeholder="<?php _e('Example: account_style', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Account_class']; ?>" />
</div>
</div>
<div class="row top-buffer">
<div class="col-md-12">
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="clsc_options_array" />
<input class="btn btn-primary top-buffer" type="submit" value="<?php _e('Save Changes') ?>" />
</div>
</div>
</div>
</form>
<?php
}
?>
Feedback for alternative approaches are more than welcome!
I thank you all in advance and have a great day! :)
I have update function clsc_html_page() and added action 'admin_init' to save register your setting fields.
/**
Plugin Name: clsc
Plugin URI: http://google.com/
Description: this is description
Version: 1.0
Author: authourname
Author URI: http://authoururri.com/
License: GPLv2 or later
Text Domain: text domain
*/
// Runs when plugin is activated
register_activation_hook( PLUGIN_MAIN_FILE, 'clsc_install');
// Create new database fields
function clsc_install() {
$clsc_options = array(
'Login_link' => '/log-in/',
'Login_string' => __('Log in', 'clsc'),
'Login_class' => '', // Default is empty to inherit theme styles
'Logout_link' => wp_logout_url( home_url()),
'Logout_string' => __('Log out', 'clsc'),
'Logout_class' => '', // Default is empty to inherit theme styles
'Account_link' => '/my-account/',
'Account_string' => __('My Account', 'clsc'),
'Account_class' => '' // Default is empty to inherit theme styles
);
add_option('clsc_options_array', $clsc_options, '', 'yes');
}
add_action('admin_init','admin_init_register_setting');
function admin_init_register_setting()
{
// register your plugins settings
/*register_setting('wp_plugin_template-group', 'Account_class');
register_setting('wp_plugin_template-group', 'Account_string');
register_setting('wp_plugin_template-group', 'Account_link');
register_setting('wp_plugin_template-group', 'Logout_class');
register_setting('wp_plugin_template-group', 'Logout_string');
register_setting('wp_plugin_template-group', 'Logout_link');
register_setting('wp_plugin_template-group', 'Login_class');
register_setting('wp_plugin_template-group', 'Login_string');
register_setting('wp_plugin_template-group', 'Login_link'); */
register_setting('wp_plugin_template-group', 'clsc_options_array');
}
// Create admin option page
function add_clsc_option_page() {
add_options_page(
'Custom Login', // The text to be displayed in the title tag
'Custom Login', // The text to be used for the menu
'administrator', // The capability required to display this menu
'custom-login-shortcodes', // The unique slug name to refer to this menu
'clsc_html_page'); // The function to output the page content
}
/* Call the html code */
add_action('admin_menu', 'add_clsc_option_page');
// Enqueue admin styles and scripts
function clsc_enqueue_scripts() {
global $wpdb;
$screen = get_current_screen();
if ( $screen->id != 'settings_page_custom-login-shortcodes' ) {
return; // exit if incorrect screen id
}
wp_enqueue_style( 'brokenfruit-shortcodes-styles', plugins_url( 'admin/css/admin_styles.css', dirname(__FILE__) ) );
wp_enqueue_style( 'bootstrap', plugins_url('admin/css/bootstrap.css', dirname(__FILE__) ) );
wp_enqueue_script('admin_js_bootstrap_hack', plugins_url('admin/scripts/bootstrap-hack.js', dirname(__FILE__) ) );
}
add_action('admin_enqueue_scripts', 'clsc_enqueue_scripts' );
function clsc_html_page()
{
if(!current_user_can('manage_options'))
{
wp_die(__('You do not have sufficient permissions to access this page.'));
}
?>
<div class="wrap">
<form method="post" action="options.php">
<?php
$options = get_option('clsc_options_array');
#settings_fields('wp_plugin_template-group'); ?>
<?php #do_settings_fields('wp_plugin_template-group'); ?>
<div class="bootstrap-wrapper">
<div class="row">
<div class="col-md-12">
<h1><?php _e('Custom Login Shortcode','clsc'); ?></h1>
<p><?php _e('To use for shortcode:','clsc'); ?><br/><span class="shortcode-preview">[custom_login]</span></p>
</div>
</div>
<div class="row" id="login-content">
<div class="col-md-4">
<h5><?php _e('Log in link:','clsc'); ?></h5>
<input name="clsc_options_array[Login_link]" placeholder="<?php _e('Example: /log-in/', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Login_link']; ?>" />
</div>
<div class="col-md-4">
<h5><?php _e('Log in string:','clsc'); ?></h5>
<input name="clsc_options_array[Login_string]" placeholder="<?php _e('Example: Log in', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Login_string']; ?>" />
</div>
<div class="col-md-4">
<h5><?php _e('Log in class:','clsc'); ?></h5>
<input name="clsc_options_array[Login_class]" placeholder="<?php _e('Example: login_style', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Login_class']; ?>" />
</div>
</div>
<div class="row top-buffer" id="logout-content">
<div class="col-md-4">
<h5><?php _e('Log out link:','clsc'); ?></h5>
<input name="clsc_options_array[Logout_link]" placeholder="<?php _e('Example: /log-out/', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Logout_link']; ?>" />
</div>
<div class="col-md-4">
<h5><?php _e('Log out string:','clsc'); ?></h5>
<input name="clsc_options_array[Logout_string]" placeholder="<?php _e('Example: Log out', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Logout_string']; ?>" />
</div>
<div class="col-md-4">
<h5><?php _e('Log out class:','clsc'); ?></h5>
<input name="clsc_options_array[Logout_class]" placeholder="<?php _e('Example: logout_style', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Logout_class']; ?>" />
</div>
</div>
<div class="row top-buffer" id="account-content">
<div class="col-md-4">
<h5><?php _e('Account link:','clsc'); ?></h5>
<input name="clsc_options_array[Account_link]" placeholder="<?php _e('Example: /my-account/', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Account_link']; ?>" />
</div>
<div class="col-md-4">
<h5><?php _e('Account string:','clsc'); ?></h5>
<input name="clsc_options_array[Account_string]" placeholder="<?php _e('Example: My Account', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Account_string']; ?>" />
</div>
<div class="col-md-4">
<h5><?php _e('Account class:','clsc'); ?></h5>
<input name="clsc_options_array[Account_class]" placeholder="<?php _e('Example: account_style', 'clsc') ?>" class="form-control" type="text" value="<?php echo $options['Account_class']; ?>" />
</div>
</div>
</div>
<?php #submit_button(); ?>
</form>
</div>
<?php
}
You can go ahead with POST Method as you used a form so upon submission use update_option to update your option values.
Reference URL :
https://codex.wordpress.org/Function_Reference/update_option
How to use update_option :
function my_option_function() {
update_option('option_value','none');
}
add_action('update_option', 'my_option_function'); ?>
For more guidance,Take a look at :
WordPress functions.php: how to apply update_option()?
I'm using a template for Wordpress that has membership functions built-in, including membership plans.
What I'm trying to do is duplicate the Registration page and have everyone who create an account using the signup form on this page get automatically subscribed to a paid membership plan for free.
So I created a new signup page by duplicating the original one. I asked the developer of the template and he said I need to use this function somewhere on the page to subscribe the users to the paid plan. Here's the function:
ThemexCourse::subscribeUser(5244, $user, true);
5244 is the ID of the paid plan on the site.
Any idea how to configure the signup form using this function so that everyone who signs up gets subscribed to the paid plan?
Here's the sign up form code:
<?php
/*
Template Name: Custom Registration
*/
?>
<?php get_header(); ?>
<?php if(get_option('users_can_register')) { ?>
<h1><?php _e('Register Your Account','academy'); ?></h1>
<form class="ajax-form formatted-form" action="<?php echo AJAX_URL; ?>" method="POST">
<div class="message"></div>
<div class="sixcol column">
<div class="field-wrapper">
<input type="text" name="user_login" placeholder="<?php _e('Username','academy'); ?>" />
</div>
</div>
<div class="sixcol column last">
<div class="field-wrapper">
<input type="text" name="user_email" placeholder="<?php _e('Email','academy'); ?>" />
</div>
</div>
<div class="clear"></div>
<div class="sixcol column">
<div class="field-wrapper">
<input type="password" name="user_password" placeholder="<?php _e('Password','academy'); ?>" />
</div>
</div>
<div class="sixcol column last">
<div class="field-wrapper">
<input type="password" name="user_password_repeat" placeholder="<?php _e('Repeat Password','academy'); ?>" />
</div>
</div>
<div class="clear"></div>
<?php if(ThemexCore::checkOption('user_captcha')) { ?>
<div class="form-captcha">
<img src="<?php echo THEMEX_URI; ?>assets/images/captcha/captcha.php" alt="" />
<input type="text" name="captcha" id="captcha" size="6" value="" />
</div>
<div class="clear"></div>
<?php } ?>
<span class="button-icon register"></span><?php _e('Register','academy'); ?>
<div class="form-loader"></div>
<input type="hidden" name="user_action" value="register_user" />
<input type="hidden" name="user_redirect" value="<?php echo themex_value($_POST, 'user_redirect'); ?>" />
<input type="hidden" name="nonce" class="nonce" value="<?php echo wp_create_nonce(THEMEX_PREFIX.'nonce'); ?>" />
<input type="hidden" name="action" class="action" value="<?php echo THEMEX_PREFIX; ?>update_user" />
</form>
<?php } ?>
<div class="clear"></div>
<?php
$query=new WP_Query(array(
'post_type' => 'page',
'meta_key' => '_wp_page_template',
'meta_value' => 'template-register.php'
));
if($query->have_posts()) {
$query->the_post();
echo '<br />';
the_content();
}
?>
<?php get_footer(); ?>
Such customization belong to the Plugins, not themes indeed. As mention in Customizing registration form codex page you may hook to one of the action hooks, to both customize the registration form and do some action after the form posts. The 3 action hooks are register_form, register_post, user_register.
For your particular question the action hook user_register must be hooked with your function preferably in a plugin.
add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
function myplugin_registration_save( $user_id ) {
....
ThemexCourse::subscribeUser(5244, $user, true);
....
}