/** * Callback to render a hidden field to store a Theme Customizer setting. * * @since 1.0.0 * @todo Figure out if this will work for non-scalar values. * * @param array $args Setting field arguments. */ public function render_customizer_sync_field($args) { extract($args); $value = get_audiotheme_option($option_name, $key, $default); $value = maybe_serialize($value); printf('<input type="hidden" name="%s" id="%s" value="%s" class="audiotheme-settings-hidden-field">', esc_attr($field_name), esc_attr($field_id), esc_attr($value)); printf('<span class="description">%s.</span>', sprintf(__('Change this setting in the %s', 'audiotheme'), sprintf('<a href="%s">%s</a>', admin_url('customize.php'), __('theme customizer', 'audiotheme')))); }
/** * A custom callback to display the field for entering and activating a license key. * * @since 1.0.0 * * @param array $args Array of arguments to modify output. */ function audiotheme_dashboard_license_input($args) { extract($args); $value = get_audiotheme_option($option_name, $key, $default); $status = get_option('audiotheme_license_status'); $activated_response = ' <strong class="audiotheme-response is-valid">' . esc_js(__('Activated!', 'audiotheme')) . '</strong>'; printf('<input type="text" name="%s" id="%s" value="%s" class="audiotheme-settings-license-text audiotheme-settings-text regular-text">', esc_attr($field_name), esc_attr($field_id), esc_attr($value)); if (!isset($status->status) || 'ok' !== $status->status) { echo '<input type="button" value="' . __('Activate', 'audiotheme') . '" disabled="disabled" class="audiotheme-settings-license-button button button-primary">'; audiotheme_admin_spinner(array('class' => 'audiotheme-license-spinner')); echo '<br><span class="audiotheme-response"></span>'; } else { echo $activated_response; } ?> <script type="text/javascript"> jQuery(function($) { var $field = $('#audiotheme_license_key'), $button = $field.parent().find('.button'); $spinner = $field.parent().find('.spinner'); $field.on('keyup', function() { if ( '' != $field.val() ) { $button.attr('disabled', false); } else { $button.attr('disabled', true); } }).trigger('keyup'); $button.on('click', function(e) { e.preventDefault(); $spinner.addClass('is-visible'); $.ajax({ url: ajaxurl, type: 'POST', data: { action: 'audiotheme_ajax_activate_license', license: $field.val(), nonce: '<?php echo wp_create_nonce('audiotheme-activate-license'); ?> ' }, dataType: 'json', success: function( data ) { data = data || {}; if ( 'status' in data && 'ok' == data.status ) { $field.parent().find('.audiotheme-response').remove(); $button.hide().after( '<?php echo $activated_response; ?> ' ); } else { var $response = $field.parent().find('.audiotheme-response').addClass('is-error'), errors = []; // ok|empty|unknown|invalid|expired|limit_reached|failed errors['empty'] = '<?php echo esc_js(__('Empty license key.', 'audiotheme')); ?> '; errors['invalid'] = '<?php echo esc_js(__('Invalid license key.', 'audiotheme')); ?> '; errors['expired'] = '<?php echo esc_js(__('License key expired.', 'audiotheme')) . ' <a href="https://audiotheme.com/view/audiotheme/" target="_blank">' . esc_js(__('Renew now.', 'audiotheme')) . '</a>'; ?> '; errors['limit_reached'] = '<?php echo esc_js(__('Activation limit reached.', 'audiotheme')) . ' <a href="https://audiotheme.com/view/audiotheme/" target="_blank">' . esc_js(__('Upgrade your license.', 'audiotheme')) . '</a>'; ?> '; if ( 'status' in data && data.status in errors ) { $response.html( errors[ data.status ] ); } else { $response.html( '<?php echo esc_js(__('Oops, there was an error.', 'audiotheme')); ?> ' ); } } $spinner.removeClass('is-visible'); } }); }); }); </script> <?php }
/** * Returns a theme option value. * * Function called to get a theme option. The returned value defaults to false * unless a default is passed. * * Note that this function footprint is slightly different than get_audiotheme_option(). While working in themes, the $option_name shouldn't necessarily need to be known or required, so it should be slightly easier to use while in a theme. * * @since 1.0.0 * @uses get_audiotheme_option() * * @param string The option key * @param mixed Optional. Default value to return if option key doesn't exist. * @param string Optional. Retrieve a non-standard option. * @return mixed The option value or $default or false. */ function get_audiotheme_theme_option($key, $default = false, $option_name = '') { $option_name = empty($option_name) ? get_audiotheme_theme_options_name() : $option_name; return get_audiotheme_option($option_name, $key, $default); }