Related
I have a nice demo importer which is working fine but with a category post count issue so there is plugin which is fixing this and I'm trying to integrate into my demo importer library.
This plugin here is fixing the issue after demo import but requires to go into the plugin page selecting post types in order to click on submit button.
Well this is the plugin admin page:
<?php
if($_POST) {
if(!check_admin_referer('select_post_types_'.get_current_user_id() )){
echo 'That is not allowed'; exit;
}
$fixes = $_POST['fix'];
foreach($fixes AS $fix_id){
$fix = new Fix_Category_Count();
$fix->post_type = $fix_id;
if($fix->process()){
$updated = TRUE;
}
}
}
?>
<div>
<?php echo "<h2>" . __( 'Fix Category Count Settings', 'fix_category_count' ) . "</h2>"; ?>
<h3>Select Post Types to Fix</h3>
<form name="site_data_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
<div class="sa_block">
<?php
$post_types = get_post_types(array('public'=>TRUE));
foreach($post_types AS $post_type){
?>
<input type="checkbox" class="post_type" name="fix[]" id="fix_<?=$post_type; ?>" value="<?=$post_type; ?>" /> <label for="fix_<?=$post_type; ?>"><?=ucwords(preg_replace("/_/"," ",$post_type)); ?> (<?=$post_type;?>)</label><br />
<?php
}
?>
<br><br>
Select All |
Deselect All
</div>
</div>
<?php wp_nonce_field('select_post_types_'.get_current_user_id()); ?>
<div class="submit">
<input type="submit" name="Submit" value="<?php _e('Fix Categories Now', '' ) ?>" />
</div>
<?php if($updated){ ?>
<div class="updated"><p><strong><?php _e('Categories Updated.' ); ?></strong></p></div>
<? } ?>
</form>
</div>
<script type="text/javascript">
if(jQuery){
jQuery(document).ready(function($){
$('.select_boxes').click(function(e){
e.preventDefault();
if($(this).attr('rel')=='all'){
$('.post_type').each(function() {
this.checked = true;
});
}
else{
$('.post_type').each(function() {
this.checked = false;
});
}
});
});
}
</script>
So the CLASS of the plugin is here
I want to use only the class without the admin page with something like this:
ob_start();
if ( 'complete' == $response['process'] ) {
// Set imported menus to registered theme locations
$locations = get_theme_mod( 'nav_menu_locations' ); // registered menu locations in theme
$menus = wp_get_nav_menus(); // registered menus
if ( $menus ) {
foreach( $menus as $menu ) { // assign menus to theme locations
if( 'Main Menu' == $menu->name ) {
$locations['primary'] = $menu->term_id;
break;
}
}
}
set_theme_mod( 'nav_menu_locations', $locations ); // set menus to locations
global $wp_rewrite;
$wp_rewrite->set_permalink_structure('/%postname%/');
$wp_rewrite->flush_rules();
// I want to add the plugin functionality as a last process here!
}
ob_end_clean();
I'm not a php developer yet but I would like to get this working without fixing the category count using the plugin page options but directly on the function above and with the php class provided by plugin.
Thank you.
Hi expert wp plugin developers, I need help. I have apply bellow code but not working default value and not showing updated notification after clicking save button. When I put all value in option page from dashboard everything is ok. But not showing all updated notification. Please help me.
<?php
function hkhk_options() {
add_menu_page('Scrol Line Admin Settings', 'hk Settings','manage_options',
'hk_settings', 'hk_admin_options');
}
add_action('admin_menu', 'hkhk_options');
function hk_defaults()
{
$hk_options = array(
'back_color' => '#ccc',
);
}
if ( is_admin() ) :
function hk_register_settings () {
register_setting('hkhk_options', 'hk_options', 'hk_validate_options');
}
add_action('admin_init', 'hk_register_settings');
function hk_admin_options() {
global $hk_options;
if ( ! isset( $_REQUEST['updated'] ) )
$_REQUEST['updated'] = false;
?>
<div class="wrap">
<h2>Select Scrol Line Option</h2>
<?php if ( false !== $_REQUEST['updated'] ) : ?>
<div class="update fade"><p><strong><?php _e( 'Options saved' ); ?></strong></p></div>
<?php endif; // If the form has just been submitted, this shows the notification ?>
<form method="post" action="options.php">
<?php $settings=get_option ( 'hk_options', $hk_options ); ?>
<?php settings_fields('hkhk_options'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="back_color"> Back Color </label></th>
<td>
<input id="back_color" type="text" name="hk_options[back_color]" value="<?php esc_attr_e($settings['back_color']); ?>" class="wp-picker-container" /><p class="description"> Choose any color from here for background color. </p>
</td>
</tr>
</table>
<p class="submit"><input type="submit" class="button-primary" value="Save Options" /> </p>
</form>
</div>
<?php
}
function hk_validate_options( $input ){
global $hk_options;
$settings = get_option( 'hk_options', $hk_options );
$input['back_color'] = wp_filter_post_kses( $input['back_color'] );
return $input;
}
endif;
function scrol_line_active() {?>
<?php global $hk_options; $hk_settings = get_option ( 'hk_options', $hk_options ); ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery("body") .hk({
backColor: "<?php echo $hk_settings['back_color']; ?>",
});
});
</script>
<?php
}
add_action ('wp_head', 'scrol_line_active');
?>
You are checking wrong REQUEST parameter. You need to check $_REQUEST['settings-updated'].
When option page is submitted new URL is similar to /wp-admin/admin.php?page=hk_settings&settings-updated=true.
Hope this helps.
I'm two or three weeks old to Wordpress, I'm writing a tiny custom system as a plugin for a wordpress-based site. This systems reads a set of json encoded files and shows them as a table list.
Together with some basic settings that I'm already saving, I want to include a simple text editor for these json files, and I was wondering if there's a way to 'attach' a custom action for the options.php script that processes form submission, in order to send to it the file path and content.
I'm currently thinking in writing some ajax, but I prefer to ask here before, maybe there is a simple way to achieve this.
myplugin.php
function myplugins_menu(){
add_options_page('myplugin configuration','myplugin','manage_options', _
'myplugin_menu','myplugin_options');
//call register settings function
add_action( 'admin_init', 'register_mysettings' );
}
add_action('admin_menu','myplugin_menu');
function myplugin_options(){
include('admin/myplugin-admin.php');
}
function register_mysettings() {
//register our settings
$setting_list=array('mail_title','mail_from','mail_to','recipient');
foreach ($setting_list as $setting){
register_setting( 'myplugin-settings-group', $setting );
}
}
myplugin-admin.php
<div class="wrap">
<h2>My plugin</h2>
<h3>My plugin Options</h3>
<form method="post" action="options.php">
<?php settings_fields( 'myplugin-settings-group' ); ?>
<?php do_settings_sections( 'myplugin-settings-group' ); ?>
<table class="form-table">
<?php
print_option('Mail Subject','mail_title');
print_option('Sender address','mail_from');
print_option('Recipient address','mail_to');
print_option('Recipient name','recipient');
?>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
echo "<select name=\"filename\" size=\"1\">";
$dir = plugin_dir_path( __FILE__ );
$files = glob($dir."../services/*.json");
foreach ($files as $filename){
echo "<option value=\"".basename($filename)."\">".basename($filename)."</option>";
}
echo "</select>";
$dir = plugin_dir_path( __FILE__ );
$file = file(WP_PLUGIN_DIR."/myplugin/services/010.Luftansa.json");
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
In the snippet above,
I put _SERVER['PHP_SELF'] as the action for the form, but this turns into /wp/wp-admin/options-general.php;.
If I put a path to my admin file I can't return to the admin interface except by an http-refresh or something like that.
Thanks for reading :)
myplugin-admin.php
<?php
/**
* #package my_plugin
* #version 1.6
*/
/*
Plugin Name: my plugin
Plugin URI:
Description:
Author:
Version:
Author URI:
*/
include_once(WP_PLUGIN_DIR."/my_plugin/model.php");
function my_plugin_admin_scripts(){
?>
<script type='text/javascript'>
jQuery('select')
.change(function() {
var filename = '';
jQuery('select option:selected').each(function() {
filename += jQuery( this ).text() + ' ';
});
jQuery.ajax({
type: 'GET',
url: '<?php echo WP_PLUGIN_URL;?>/my_plugin/action.php',
data: 'action=' + 'getJsonFile'+'&file='+filename,
success: function(data) {
jQuery('#services_file').val(data);
},
error: function(data) {
jQuery('#services_file').val('Something went wrong while loading '+filename+' file content');
}
});
})
.trigger('change');
</script>
<?php
}
add_action( 'admin_footer', 'my_plugin_admin_scripts' );
function print_option($label,$opt_name){
$str = "
<tr valign=\"top\">
<th scope=\"row\">{$label}</th>
<td><input type=\"text\" name=\"{$opt_name}\" value=\"".get_option($opt_name)."\" /></td>
</tr>";
echo $str;
}
function my_plugin_admin_tabs( $current = 'general' ) {
$tabs = array( 'general' => 'General', 'services' => 'Services');
echo "<h3>My plugin Options</h3>";
echo '<div id="icon-themes" class="icon32"><br></div>';
echo '<h2 class="nav-tab-wrapper">';
foreach( $tabs as $tab => $name ){
$class = ( $tab == $current ) ? ' nav-tab-active' : '';
echo "<a class='nav-tab$class' href='?page=my_plugin_menu&tab=$tab'>$name</a>";
}
echo '</h2>';
}
function tab_content_general() {
?>
<form method="post" action="options.php">
<?php settings_fields( 'my_plugin-settings-group' ); ?>
<?php do_settings_sections( 'my_plugin-settings-group' ); ?>
<table class="form-table">
<?php
print_option('Mail Subject','mail_title');
print_option('Sender address','mail_from');
print_option('Recipient address','mail_to');
print_option('Recipient name','recipient');
?>
</table>
<?php submit_button(); ?>
</form>
<?php
}
function tab_content_services(){
$files = glob(WP_PLUGIN_DIR."/my_plugin/services/*.json");
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=my_plugin_menu&tab=services">
<table class="form-table">
<tr><td><select name="filename" size="1" style="width: 180px">
<?php
foreach ($files as $filename){
echo "<option value=\"".basename($filename)."\">".basename($filename)."</option>";
}
?>
</select>
<input name="Submit" type="submit" value="Update" />
</td></tr>
<tr><td><textarea id="services_file" name="update" cols="80" rows="18" style="font-family: monospace">
</textarea></td></tr>
</table>
</form>
<?php
}
$tab = ( isset ( $_GET['tab'] ) )?$_GET['tab']:"general";
my_plugin_admin_tabs($tab);
?>
<div class="wrap">
<?php
switch ($tab) {
case "general":
tab_content_general();
break;
case "services":
tab_content_services();
break;
default:
break;
}
?>
</div>
<?php
if($_POST['Submit']){
save_json_file($_POST['filename'],$_POST['update']);
}
?>
action.php
<?php
define( 'WP_USE_THEMES', false );
require_once( '../../../wp-load.php' );
require_once('model.php');
//main
if (isset($_GET['action'])){
$action = $_GET['action'];
}
if (isset($_POST['action'])){
$action = $_POST['action'];
}
if (isset($action)) {
switch ($action){
case 'getJsonFile':
getJsonFile($_GET['file']);
break;
default:
echo "action unknown";
break;
}
}
?>
model.php
<?php
function isJson($string) {
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
}
function read_plain_json($file){
$file = file(WP_PLUGIN_DIR."/my_plugin/services/".$file);
return implode("",$file);
}
function getJsonFile($file){
echo read_plain_json($file);
die();
}
function save_json_file($file,$content){
$open = fopen(WP_PLUGIN_DIR."/my_plugin/services/".$file,"w+");
fwrite($open, stripslashes($content));
fclose($open);
}
?>
my_plugin/services/010.Luftansa.json
[
{
"subcat": "Natural Nail Care",
"column": ["service","Mani","Pedi","Mani & Pedi","info","book"],
"service": [
["Deluxe","40.00","55.00","90.00","Service Information","Book Deluxe"],
["Express","30.00","45.00","71.00","","BookExpress"],
["Fully Loaded","55","70","119.00","ServiceInformation","Book Fully Loaded"],
["French","45","60","100.00","","Book French"],
["Pure and Natural","50","60","105.00","Service Information","Book Pure And Natural"],
["Deluxe Series of 6","216","297","487.00","","Book Deluxe Series Of 6"],
["Re-varnish and Tidy-up Hands","18","20","35","","Book Re-Varnish And Tidy-Up Hands"],
["Course of 6","","","","","Book Course Of 6"]
]
}
the server gave me this error but i can't understand why!
The error is
"Parse error: syntax error, unexpected end of file in /homepages/43/d514350324/htdocs/wp-content/plugins/NetClass/nw_NetClass_init_CustomBoxes.php on line 227"
Line 227 is the last line of the file.
That's the code. Help me please!
<?php
/* Define the custom box */
add_action( 'add_meta_boxes', 'aggiungiMetaBox' );
add_action( 'save_post', 'salvaMetaBox', 10, 2 );
add_action( 'wp_ajax_nc_savePortable_lezioni_action', 'nc_savePortable_lezioni' );
add_action( 'admin_footer', 'nc_savePortable_lezioni_js' );
function parseInt($str){
return (int) $str;
}
function aggiungiMetaBox(){
add_meta_box( "nw_Netclass_Box_AggiungiaCorso", "Aggiungi la lezione al corso", "aggiungiMetaBox_AggiungiLezione", "corso");
add_meta_box("nw_NetClass_Box_DatiFattura", "Dati della fattura", "aggiungiMetaBox_DatiFattura", "fattura");
add_meta_box("nw_NetClass_Box_Corsi_Associati", "Corsi associati", "aggiungiMetaBox_Corsi_Associati", "lezione");
}
function aggiungiMetaBox_Corsi_Associati($post){
?>
<p><?php echo get_post_meta($post->ID, 'corsi_associati',true); ?></p>
<?php
}
function is_in_array($array_lezioni_del_corso, $object){
if(!is_array($array_lezioni_del_corso)){
if($array_lezioni_del_corso == $object){
return true;
}else{
return false;
}
}
else{
return in_array($object, $array_lezioni_del_corso);
}
}
function aggiungiMetaBox_DatiFattura($post){
$post_id = $post->ID;
$user_info = get_userdata(get_post_meta($post_id, "intestatarioFattura" , true));
$user_meta = array(
'tipo_utente' => get_user_meta(get_post_meta($post_id, "intestatarioFattura" , true), 'tipo_utente',true),
'p_iva' => get_user_meta(get_post_meta($post_id, "intestatarioFattura" , true), 'p_iva',true),
'indirizzo_fatturazione' => get_user_meta(get_post_meta($post_id, "intestatarioFattura" , true), 'indirizzo_fatturazione',true)
);
?>
Intestatario della fattura : <?php echo $user_info->display_name; ?> <br>
Tipo di utente : <?php echo $user_meta['tipo_utente']; ?> <br>
Indirizzo di fatturazione : <?php echo $user_meta['indirizzo_fatturazione']; ?> <br>
P.IVA : <?php echo $user_meta['p_iva']; ?> <br>
Inponibile della fattura : <?php echo get_post_meta( $post_id, "inponibileFattura" , true); ?> <br>
Totale della fattura : <?php echo get_post_meta( $post_id, "totaleFattura" , true); ?> <br>
Articoli acquistati:
<ul>
<?php
foreach(get_post_meta( $post_id, "articoliFattura" , true) as $prodotto){
?>
<li><?php echo get_the_title($prodotto); ?></li>
<?php
}
?>
</ul>
<?php
}
//save the meta box
function salvaMetaBox($post_id)
{
//Salvo i dati del Box lezioni nel post corso //
global $wpdb;
$database_name = $wpdb->prefix.'Netclass_friends';
if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || ( defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit']) ) { return $post_id; }
//Salvo i dati delle fatture
}
function aggiungiMetaBox_AggiungiLezione($post){
global $wpdb;
$post_id = $post->ID;
$query = "SELECT post_title,ID FROM ".$wpdb->prefix."posts WHERE post_type='lezione' AND post_status='publish'";
$array_lezioni_del_corso = get_post_meta($post_id, 'array_lezioni_del_corso');
$lezioni = $wpdb->get_results($query);
foreach ($lezioni as $lezione) { ?>
<input id="<?php echo $lezione->ID; ?>" data-title="<?php echo $lezione->post_title; ?>" class="nc_lezione_pubblicata" type="checkbox" name="checkfield[]" value="<?php echo $lezione->ID; ?>" <?php if ( is_in_array($array_lezioni_del_corso[0], $lezione->ID)) { ?> checked <?php } ?>/>
<label for="<?php echo $lezione->ID; ?>"><?php echo $lezione->post_title; ?></label> <br>
<?php } ?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function($)
{
$( '.sortable' ).sortable({
opacity: 0.6,
revert: true,
cursor: 'move',
handle: '.hndle',
placeholder: {
element: function(currentItem) {
return $("<li style='background:#E7E8AD'> </li>")[0];
},
update: function(container, p) {
return;
}
},
update: function( event, ui ) {
console.log($(".sortable").sortable("toArray", {attribute: 'data-id'}));
saveSortable($(".sortable").sortable("toArray", {attribute: 'data-id'}));
}
});
$( '.sortable' ).disableSelection();
$(".nc_lezione_pubblicata").change(function() {
if( $(this).is(':checked') ){
$( '<li class="nc_lezione_del_corso" data-id="'+$(this).attr('id')+'" id="lezione_del_corso_'+$(this).attr('id')+'"><code class="hndle"> -[]- </code>'+$(this).data('title')+'</p>' ).appendTo( ".sortable" );
}else{
$("#lezione_del_corso_"+$(this).attr('id')).remove();
console.log("elimino");
}
saveSortable($(".sortable").sortable("toArray", {attribute: 'data-id'}));
});
});
</script>
<ul class="sortable ui-sortable">
<?php foreach ($array_lezioni_del_corso[0] as $lezione_del_corso) { ?>
<li class="nc_lezione_del_corso" id="lezione_del_corso_<?php echo $lezione_del_corso; ?>"
data-id="<?php echo $lezione_del_corso; ?>">
<code class='hndle'> -[]- </code>
<?php echo get_the_title($lezione_del_corso); ?>
</li>
} ?>
</ul>
<p>
<script type="text/javascript">
$(function(){
console.log($(".sortable").sortable("toArray"));
});</script>
</p>
<?php }
function nc_savePortable_lezioni(){
global $wpdb;
$post_id = $_POST['post_id'];
$array_lezioni_del_corso = $_POST['array_lezioni_del_corso'];
update_post_meta($post_id, 'array_lezioni_del_corso', $array_lezioni_del_corso);
foreach ($array_lezioni_del_corso as $lezione_del_corso) {
$corsi_associati = get_post_meta($lezione_del_corso, 'corsi_associati', true);
$corsi_associati = $corsi_associati.','.$post_id;
update_post_meta(parseInt($lezione_del_corso), 'corsi_associati', $corsi_associati);
}
echo 'al server arrriva '.$array_lezioni_del_corso;
}
function nc_savePortable_lezioni_js(){
?>
<script type="text/javascript">
function saveSortable(sortableArraystringData){
var data = {
action: 'nc_savePortable_lezioni_action',
array_lezioni_del_corso : sortableArraystringData,
post_id : <? echo get_the_ID(); ?>
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
$.post(ajaxurl, data, function(response) {
alert('This was passed ' + sortableArraystringData);
});
}
</script>
<?php
}
You're missing a curly brace somewhere.
Im using wordpress 3.8, woocommerce 2.0.20. And im using this Zoom Image Plugin(http://wordpress.org/plugins/zoom-image/)
Everything is looking fine, but when I have a product with color variation, it does not change the color of the image, but when you put your mouse to zoom, it appears the previous image.
Zoom Image Plugin code:
class TccZoom {
var $pluginPath;
var $pluginUrl;
public function __construct()
{
// Set Plugin Path
$this->pluginPath = dirname(__FILE__);
// Set Plugin URL
$this->pluginUrl = WP_PLUGIN_URL . '/zoom-image';
add_filter('woocommerce_product_thumbnails', array( &$this, 'apply_zoom') );
add_action('woocommerce_product_thumbnails', array( &$this, 'add_scripts') );
if(is_admin()){
add_action('admin_menu', array(&$this, 'add_zoom_image_plugin_page'));
add_action('admin_init', array(&$this, 'zoom_image_init'));
add_action( 'admin_enqueue_scripts', array(&$this, 'wp_enqueue_color_picker') );
}
}
static function install() {
add_option('zoom_image_options', array('zoom_thumbnails'=>'1'));
}
function wp_enqueue_color_picker( ) {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker-script', plugins_url('/js/colorPicker.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
}
public function add_zoom_image_plugin_page(){
// This page will be under "Settings"
add_options_page('Zoom Image Settings', 'Zoom Image', 'manage_options', 'zoom-image', array($this, 'create_zoom_image_page'));
}
public function create_zoom_image_page(){
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2>Zoom Image Settings</h2>
<form method="post" action="options.php">
<?php
// This prints out all hidden setting fields
settings_fields('zoom_image_group');
do_settings_sections('zoom_image_settings');
?>
<?php submit_button(); ?>
</form>
</div>
<?php
}
public function zoom_image_init(){
register_setting('zoom_image_group', 'zoom_image_options', array($this, 'check_zoom_image_options'));
add_settings_section(
'general_zoom_settings',
'Zoom image options',
array($this, 'print_section_info'),
'zoom_image_settings'
);
add_settings_field(
'zoom_thumbnails',
'Zoom over thumbnails ?',
array($this, 'create_zoom_thumbnails_field'),
'zoom_image_settings',
'general_zoom_settings'
);
/*
add_settings_field(
'zoom_level',
'Zoom level',
array($this, 'create_zoom_level_field'),
'zoom_image_settings',
'general_zoom_settings'
);
*/
add_settings_field(
'zoom_type',
'Zoom type',
array($this, 'create_zoom_inner_field'),
'zoom_image_settings',
'general_zoom_settings'
);
/*
add_settings_field(
'zoom_background_color',
'Background color',
array($this, 'create_zoom_color_field'),
'zoom_image_settings',
'general_zoom_settings'
);
*/
}
public function check_zoom_image_options($input){
if(!in_array($input['zoom_thumbnails'],array(0,1)))
{
$input['zoom_thumbnails'] = '';
}
if(!in_array($input['zoom_level'],array(0.5,1,2)))
{
$input['zoom_level'] = '';
}
if(!in_array($input['zoom_type'],array('window','inner','lens')))
{
$input['zoom_type'] = '';
}
return $input;
}
public function print_section_info(){
//print 'Enter your setting below:';
}
public function create_zoom_thumbnails_field(){
$options = get_option('zoom_image_options');
?>
<input type="checkbox" id="zoom_over_thumbnails" name="zoom_image_options[zoom_thumbnails]" value="1" <?php if($options['zoom_thumbnails']==1) { ?> checked="checked" <?php } ?> />
<?php
}
public function create_zoom_inner_field(){
$options = get_option('zoom_image_options');
?>
<select name="zoom_image_options[zoom_type]">
<option value="window" <?php if($options['zoom_type']=='window') { ?> selected="selected" <?php } ?>>Window</option>
<option value="lens" <?php if($options['zoom_type']=='lens') { ?> selected="selected" <?php } ?>>Lens</option>
<option value="inner" <?php if($options['zoom_type']=='inner') { ?> selected="selected" <?php } ?>>Inner</option>
</select>
<?php
}
public function create_zoom_level_field()
{
$options = get_option('zoom_image_options');
?>
<select name="zoom_image_options[zoom_level]">
<option value="1" <?php if($options['zoom_level']==1) { ?> selected="selected" <?php } ?>>Normal zoom</option>
<?php /*
<option value="0.5" <?php if($options['zoom_level']==0.5) { ?> selected="selected" <?php } ?>>Twice as big</option>
*/ ?>
<option value="2" <?php if($options['zoom_level']==2) { ?> selected="selected" <?php } ?>>Twice as small</option>
</select>
<?php
}
public function create_zoom_color_field()
{
$options = get_option('zoom_image_options');
?>
<input type="text" id="zoom_background" class="wp-color-picker-field" name="zoom_image_options[zoom_background_color]" value="<?php echo esc_attr($options['zoom_background_color']); ?>" />
<br />
<span>Available only for Zoom type: window</span>
<?php
}
function apply_zoom()
{
global $post;
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full', false, '' );
$options = get_option('zoom_image_options');
ob_start();
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$('.woocommerce-main-image img').attr('data-zoom-image','<?php echo $src[0]; ?>');
$('.woocommerce-main-image img').elevateZoom({
<?php if($options['zoom_level']) { ?>
zoomLevel : <?php echo strip_tags(trim($options['zoom_level'])); ?>,
<?php }else { ?>
zoomLevel : 1,
<?php } ?>
<?php
switch ($options['zoom_type'])
{
case "window":
?>
zoomType : "window",
lensShape : "square",
<?php
break;
case "lens":
?>
zoomType : "lens",
lensShape : "round",
<?php
break;
case "inner":
?>
zoomType : "inner",
cursor : "crosshair",
<?php
break;
default:
?>
zoomType : "window",
lensShape : "square",
<?php
break;
}
if(strlen(trim($options['zoom_background_color']))>1 && $options['zoom_type']=='window' ) {
?>
tint:true,
tintColour:'<?php echo esc_attr($options['zoom_background_color']); ?>',
tintOpacity:0.5
<?php
}
?>
});
<?php if($options['zoom_thumbnails']==1) { ?>
$('.thumbnails .zoom img').each(function(){
$(this).attr('data-zoom-image',$(this).parent().attr('href'));
});
$('.thumbnails .zoom img').elevateZoom({
zoomType : "window",
lensShape : "square",
lensSize : 20,
zoomWindowPosition: 16,
zoomWindowOffetx: 10,
<?php if($options['zoom_level']) { ?>
zoomLevel : <?php echo strip_tags(trim($options['zoom_level'])); ?>,
<?php }else { ?>
zoomLevel : 1,
<?php } ?>
<?php
if(strlen(trim($options['zoom_background_color']))>1) {
?>
tint:true,
tintColour:'<?php echo esc_attr($options['zoom_background_color']); ?>',
tintOpacity:0.5
<?php
}
?>
});
<?php } ?>
})
</script>
<?php
echo ob_get_clean();
}
function add_scripts() {
wp_enqueue_script( 'tcc-magnifier-js', $this->pluginUrl.'/js/jquery.elevateZoom-2.5.5.min.js', 'jquery' );
}
}
$tcczoom = new TccZoom;
register_activation_hook( __FILE__, array('TccZoom', 'install') );
We use something very similar, CloudZoom for WooCommerce, which has the same problem as well. If you are interested in switching plugins, you can solve the same problem for that plugin by adding this line of jQuery to a script in your header:
jQuery('form.variations_form').on( 'found_variation', function( event, variation ) {
addCloudZoom($productImages);
} );
Again, just to be clear, this solution won't work for the plugin you are using, but it solves the same problem for a plugin that provides identical functionality. If you can't find a solution for the plugin you're using, you might try switching and using this solution.