| 1 |
<?php |
| 2 |
/** |
| 3 |
* Structured Data Product |
| 4 |
* |
| 5 |
* @package Welcart |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Structured Data Product |
| 10 |
*/ |
| 11 |
class USCES_STRUCTURED_DATA_PRODUCT { |
| 12 |
|
| 13 |
/** |
| 14 |
* Option value |
| 15 |
* |
| 16 |
* @var array |
| 17 |
*/ |
| 18 |
public static $opts; |
| 19 |
|
| 20 |
/** |
| 21 |
* Defailt option value |
| 22 |
* |
| 23 |
* @var array |
| 24 |
*/ |
| 25 |
public static $default_option; |
| 26 |
|
| 27 |
/** |
| 28 |
* Labels value |
| 29 |
* |
| 30 |
* @var array |
| 31 |
*/ |
| 32 |
public static $labels = array(); |
| 33 |
|
| 34 |
/** |
| 35 |
* Class Constructor |
| 36 |
*/ |
| 37 |
public function __construct() { |
| 38 |
self::initialize_data(); |
| 39 |
if ( is_admin() ) { |
| 40 |
add_action( 'usces_action_admin_system_extentions', array( $this, 'setting_form' ) ); |
| 41 |
add_action( 'init', array( $this, 'save_data' ) ); |
| 42 |
} |
| 43 |
self::$labels = array( |
| 44 |
'first' => 'First SKU selling price', |
| 45 |
'minimum' => 'Lowest SKU selling price', |
| 46 |
'maximum' => 'Highest SKU selling price', |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* 構造化データの設定の初期化. |
| 52 |
*/ |
| 53 |
public function initialize_data() { |
| 54 |
global $usces; |
| 55 |
$options = get_option( 'usces_ex', array() ); |
| 56 |
|
| 57 |
$options['system']['structured_data_product']['status'] = ( ! isset( $options['system']['structured_data_product']['status'] ) ) ? 0 : (int) $options['system']['structured_data_product']['status']; |
| 58 |
$options['system']['structured_data_product']['default_price'] = ( ! isset( $options['system']['structured_data_product']['default_price'] ) ) ? 'first' : $options['system']['structured_data_product']['default_price']; |
| 59 |
update_option( 'usces_ex', $options ); |
| 60 |
self::$opts = $options['system']['structured_data_product']; |
| 61 |
|
| 62 |
self::$default_option = array( |
| 63 |
'status' => array( 0, 1 ), |
| 64 |
'default_price' => array( 'first', 'minimum', 'maximum' ), |
| 65 |
); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* 構造化データの設定保存. |
| 70 |
*/ |
| 71 |
public function save_data() { |
| 72 |
global $usces; |
| 73 |
|
| 74 |
if ( isset( $_POST['usces_structured_data_product_option_update'] ) ) { |
| 75 |
|
| 76 |
check_admin_referer( 'admin_system', 'wc_nonce' ); |
| 77 |
if ( ! current_user_can( 'wel_manage_setting' ) ) { |
| 78 |
wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); |
| 79 |
} |
| 80 |
|
| 81 |
self::$opts['default_price'] = ( isset( $_POST['default_price'] ) ) ? $_POST['default_price'] : 'first'; |
| 82 |
self::$opts['status'] = ( isset( $_POST['structured_data_product_status'] ) ) ? (int) $_POST['structured_data_product_status'] : 0; |
| 83 |
$options = get_option( 'usces_ex', array() ); |
| 84 |
$options['system']['structured_data_product'] = self::$opts; |
| 85 |
if ( isset( $options['system']['structured_data_product']['error_message'] ) ) { |
| 86 |
unset( $options['system']['structured_data_product']['error_message'] ); |
| 87 |
} |
| 88 |
update_option( 'usces_ex', $options ); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* システム設定 > 拡張機能のフォーム作成. |
| 94 |
*/ |
| 95 |
public function setting_form() { |
| 96 |
$status = ( self::$opts['status'] || self::$opts['status'] ) ? '<span class="running">' . __( 'Running', 'usces' ) . '</span>' : '<span class="stopped">' . __( 'Stopped', 'usces' ) . '</span>'; |
| 97 |
$colspan = count( self::$default_option['default_price'] ); |
| 98 |
?> |
| 99 |
<form action="" method="post" name="option_form" id="structured_data_product_form"> |
| 100 |
<div class="postbox"> |
| 101 |
<div class="postbox-header"> |
| 102 |
<h2><span><?php esc_html_e( 'Structured data measures', 'usces' ); ?></span><?php wel_esc_script_e( $status ); ?></h2> |
| 103 |
<div class="handle-actions"> |
| 104 |
<button type="button" class="handlediv" id="structured_data_product"> |
| 105 |
<span class="screen-reader-text"><?php echo esc_html( sprintf( __( 'Toggle panel: %s' ), __( 'Structured data measures', 'usces' ) ) ); ?></span> |
| 106 |
<span class="toggle-indicator"></span> |
| 107 |
</button> |
| 108 |
</div> |
| 109 |
</div> |
| 110 |
<div class="inside"> |
| 111 |
<?php if ( isset( self::$opts['error_message'] ) ) { ?> |
| 112 |
<span class="stopped"><?php _e( self::$opts['error_message'], 'usces' ); ?></span> |
| 113 |
<?php } ?> |
| 114 |
<table class="form_table"> |
| 115 |
<tr height="35"> |
| 116 |
<th class="system_th"> |
| 117 |
<a style="cursor:pointer;" |
| 118 |
onclick="toggleVisibility('ex_structured_data_product_status');"><?php esc_html_e( 'Structured data measures', 'usces' ); ?></a> |
| 119 |
</th> |
| 120 |
<td> |
| 121 |
<input name="structured_data_product_status" type="radio" |
| 122 |
id="structured_data_product_status_0" |
| 123 |
value="0"<?php checked( self::$opts['status'], 0 ); ?> /> |
| 124 |
</td> |
| 125 |
<td> |
| 126 |
<label for="structured_data_product_status_0"><?php esc_html_e( 'disable', 'usces' ); ?></label> |
| 127 |
</td> |
| 128 |
<td> |
| 129 |
<input name="structured_data_product_status" type="radio" |
| 130 |
id="structured_data_product_status_1" |
| 131 |
value="1"<?php checked( self::$opts['status'], 1 ); ?> /> |
| 132 |
</td> |
| 133 |
<td colspan="<?php echo esc_attr( $colspan ); ?>"> |
| 134 |
<label for="structured_data_product_status_1"><?php esc_html_e( 'enable', 'usces' ); ?></label> |
| 135 |
</td> |
| 136 |
<td> |
| 137 |
<div id="ex_structured_data_product_status" class="explanation"> |
| 138 |
<?php esc_html_e( 'Enable Structured data measures.', 'usces' ); ?> |
| 139 |
</div> |
| 140 |
</td> |
| 141 |
</tr> |
| 142 |
<tr height="35"> |
| 143 |
<th class="system_th"> |
| 144 |
<a style="cursor:pointer;" |
| 145 |
onclick="toggleVisibility('ex_default_price');"><?php esc_html_e( 'Default price', 'usces' ); ?> |
| 146 |
</a> |
| 147 |
</th> |
| 148 |
<?php foreach ( self::$default_option['default_price'] as $value ) { ?> |
| 149 |
<td> |
| 150 |
<input name="default_price" type="radio" |
| 151 |
id="structured_data_product_default_price_<?php echo esc_attr( $value ); ?>" |
| 152 |
value="<?php echo esc_attr( $value ); ?>"<?php checked( self::$opts['default_price'], $value ); ?> /> |
| 153 |
</td> |
| 154 |
<td> |
| 155 |
<label for="structured_data_product_default_price_<?php echo esc_attr( $value ); ?>"><?php _e( USCES_STRUCTURED_DATA_PRODUCT::$labels[ $value ], 'usces' ); ?></label> |
| 156 |
</td> |
| 157 |
<?php } ?> |
| 158 |
<td> |
| 159 |
<div id="ex_default_price" |
| 160 |
class="explanation"><?php esc_html_e( 'Which SKU do you want to use?', 'usces' ); ?></div> |
| 161 |
</td> |
| 162 |
</tr> |
| 163 |
</table> |
| 164 |
<hr/> |
| 165 |
<input name="usces_structured_data_product_option_update" type="submit" |
| 166 |
class="button button-primary" |
| 167 |
value="<?php esc_attr_e( 'change decision', 'usces' ); ?>"/> |
| 168 |
</div> |
| 169 |
</div><!--postbox--> |
| 170 |
<?php wp_nonce_field( 'admin_system', 'wc_nonce' ); ?> |
| 171 |
</form> |
| 172 |
<?php |
| 173 |
} |
| 174 |
} |
| 175 |
|