Advertisement
Guest User

Untitled

a guest
Nov 14th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 52.49 KB | None | 0 0
  1. <?php
  2.  
  3. $GLOBALS['EC_Settings'] = new EC_Settings();
  4.  
  5. /*
  6. * EC_settings
  7. *
  8. * Settings for eg email template editing
  9. * @since: 3.6
  10. * @created: 25/01/13
  11. */
  12.  
  13. class EC_Settings {
  14.  
  15. /**
  16. * Construct and initialize the main plugin class
  17. */
  18. public function __construct() {
  19.  
  20. /* Init Shortcodes */
  21. add_shortcode( 'ec_firstname', array( "EC_Settings", 'ec_firstname' ) );
  22. add_shortcode( 'ec_lastname', array( "EC_Settings", 'ec_lastname' ) );
  23.  
  24. add_shortcode( 'ec_order', array( "EC_Settings", 'ec_order' ) );
  25. add_shortcode( 'ec_order_link', array( "EC_Settings", 'ec_order' ) );
  26. add_shortcode( 'ec_user_order_link', array( "EC_Settings", 'ec_order' ) );
  27. add_shortcode( 'ec_pay_link', array( "EC_Settings", 'ec_pay_link' ) );
  28.  
  29. add_shortcode( 'ec_customer_note', array( "EC_Settings", 'ec_customer_note' ) );
  30.  
  31. add_shortcode( 'ec_user_login', array( "EC_Settings", 'ec_user_login' ) );
  32. add_shortcode( 'ec_account_link', array( "EC_Settings", 'ec_account_link' ) );
  33. add_shortcode( 'ec_user_password', array( "EC_Settings", 'ec_user_password' ) );
  34. add_shortcode( 'ec_reset_password_link', array( "EC_Settings", 'ec_reset_password_link' ) );
  35. add_shortcode( 'ec_login_link', array( "EC_Settings", 'ec_login_link' ) );
  36. add_shortcode( 'ec_site_link', array( "EC_Settings", 'ec_site_link' ) );
  37. add_shortcode( 'ec_site_name', array( "EC_Settings", 'ec_site_name' ) );
  38. }
  39.  
  40. /**
  41. * Output admin fields.
  42. *
  43. * Loops though the options array and outputs each field.
  44. *
  45. * @access public
  46. * @param array $options Options array to output
  47. */
  48. public static function output_fields( $options ) {
  49.  
  50. // Sections
  51. // -------------------------
  52.  
  53. // Get Sections array.
  54. $sections = ec_get_settings( false, array('type'=>'section') );
  55.  
  56. // Set the all section so the fields that aren't in a section are not left out.
  57. $sections['all'] = array(
  58. 'id' =>'all',
  59. 'name' =>'All'
  60. );
  61.  
  62. // Collect a new array of only the sections that have fields.
  63. $collect_sections = array();
  64. foreach ( $options as $value ) :
  65. if ( !isset( $value['section'] ) ) $value['section'] = 'all';
  66. $collect_sections[ $value['section'] ] = $sections[ $value['section'] ];
  67. endforeach;
  68.  
  69. // Set sections back the new array of only sections with fields in them.
  70. $sections = $collect_sections;
  71.  
  72. foreach ( $sections as $section_value_array ) :
  73. ?>
  74.  
  75. <div class="section">
  76. <h3><?php echo $section_value_array['name'] ?></h3>
  77.  
  78. <div class="section-inner">
  79. <?php
  80. foreach ( $options as $value ) :
  81.  
  82. if ( !isset( $value['type'] ) ) continue;
  83. if ( !isset( $value['id'] ) ) $value['id'] = '';
  84. if ( !isset( $value['title'] ) ) $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
  85. if ( !isset( $value['class'] ) ) $value['class'] = '';
  86. if ( !isset( $value['field_class'] ) ) $value['field_class'] = '';
  87. if ( !isset( $value['css'] ) ) $value['css'] = '';
  88. if ( !isset( $value['default'] ) ) $value['default'] = '';
  89. if ( !isset( $value['desc'] ) ) $value['desc'] = '';
  90. if ( !isset( $value['tip'] ) ) $value['tip'] = false;
  91. if ( !isset( $value['size'] ) ) $value['size'] = 'full';
  92. if ( !isset( $value['section'] ) ) $value['section'] = 'all';
  93.  
  94.  
  95. if ( $value['section'] == $section_value_array['id'] ) :
  96.  
  97.  
  98. // Custom attribute handling
  99. $custom_attributes = array();
  100.  
  101. if ( !empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) )
  102. foreach ( $value['custom_attributes'] as $attribute => $attribute_value )
  103. $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
  104.  
  105. // Description handling
  106. if ( $value['tip'] === true ) {
  107. $description = '';
  108. $tip = $value['desc'];
  109. }
  110. elseif ( !empty( $value['tip'] ) ) {
  111. $description = $value['desc'];
  112. $tip = $value['tip'];
  113. }
  114. elseif ( !empty( $value['desc'] ) ) {
  115. $description = $value['desc'];
  116. $tip = '';
  117. }
  118. else {
  119. $description = $tip = '';
  120. }
  121.  
  122. if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) {
  123. $description = '<p style="margin-top:0">' . wp_kses_post( $description ) . '</p>';
  124. }
  125. elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) {
  126. $description = wp_kses_post( $description );
  127. }
  128. elseif ( $description ) {
  129. $description = '<span class="description">' . wp_kses_post( $description ) . '</span>';
  130. }
  131.  
  132. if ( $tip && in_array( $value['type'], array( 'checkbox' ) ) ) {
  133. $tip = '<span class="help-icon help_tip_new" data-tip="' . esc_attr($tip) . '" >&nbsp;</span>';
  134. }
  135. elseif ( $tip ) {
  136. $tip = '<span class="help-icon help_tip_new" data-tip="' . esc_attr($tip) . '" >&nbsp;</span>';
  137. }
  138.  
  139.  
  140. // Switch based on type
  141. switch( $value['type'] ) {
  142.  
  143. // CX
  144.  
  145. case 'image_upload':
  146. $type = $value['type'];
  147. $class = '';
  148. $option_value = self::get_option( $value['id'], $value['default'] );
  149. ?>
  150.  
  151. <div class="main-controls-element forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo esc_attr( $value['class'] ); ?>">
  152. <label class="controls-label">
  153. <?php echo esc_html( $value['title'] ); ?>
  154. <?php echo $tip; ?>
  155. </label>
  156. <?php // echo $tip; ?>
  157.  
  158. <div class="controls-field">
  159. <div class="controls-inner-row">
  160.  
  161. <?php if ($value['default']): ?>
  162. <span class="reset-to-default help_tip_new" data-tip="<?php echo esc_attr( __("Reset to - ",'email-control') . ' ' . $value['default'] ); ?>" data-default="<?php echo esc_html( $value['default'] ); ?>">
  163. Reset to default <i class="fa fa-refresh"></i>
  164. </span>
  165. <?php endif ?>
  166.  
  167. <input
  168. name="<?php echo esc_attr( $value['id'] ); ?>"
  169. id="<?php echo esc_attr( $value['id'] ); ?>"
  170. type="text"
  171. style="<?php echo esc_attr( $value['css'] ); ?>"
  172. value="<?php echo esc_attr( $option_value ); ?>"
  173. placeholder="http://"
  174.  
  175. class="upload_image <?php echo esc_attr( $value['field_class'] ); ?>"
  176. autocomplete="off"
  177. <?php echo implode( ' ', $custom_attributes ); ?>
  178. />
  179. <input class="upload_image_button button" type="button" value="Upload" />
  180.  
  181. <?php // echo $description; ?>
  182. </div>
  183. </div>
  184. </div>
  185.  
  186. <?php
  187.  
  188. break;
  189.  
  190. // Standard text inputs and subtypes like 'number'
  191. case 'text':
  192. case 'email':
  193. case 'number':
  194. case 'color' :
  195. case 'password' :
  196.  
  197. $type = $value['type'];
  198. $class = '';
  199. $option_value = self::get_option( $value['id'], $value['default'] );
  200.  
  201. if ( $value['type'] == 'color' ) {
  202. $type = 'text';
  203. $value['field_class'] .= 'ec-colorpick';
  204. $description .= '<div id="colorPickerDiv_' . esc_attr( $value['id'] ) . '" class="colorpickdiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"></div>';
  205. }
  206. ?>
  207.  
  208. <div class="main-controls-element forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo esc_attr( $value['class'] ); ?>">
  209. <label class="controls-label">
  210. <?php echo esc_html( $value['title'] ); ?>
  211. <?php echo $tip; ?>
  212. </label>
  213.  
  214. <div class="controls-field">
  215. <div class="controls-inner-row">
  216.  
  217. <?php if ($value['default']): ?>
  218. <span class="reset-to-default help_tip_new" data-tip="<?php echo esc_attr( __("Reset to - ",'email-control') . ' ' . $value['default'] ); ?>" data-default="<?php echo esc_html( $value['default'] ); ?>">
  219. Reset to default <i class="fa fa-refresh"></i>
  220. </span>
  221. <?php endif ?>
  222.  
  223. <input
  224. name="<?php echo esc_attr( $value['id'] ); ?>"
  225. id="<?php echo esc_attr( $value['id'] ); ?>"
  226. type="<?php echo esc_attr( $type ); ?>"
  227. style="<?php echo esc_attr( $value['css'] ); ?>"
  228. value="<?php echo esc_attr( $option_value ); ?>"
  229. class="<?php echo esc_attr( $value['field_class'] ); ?>"
  230. autocomplete="off"
  231. <?php echo implode( ' ', $custom_attributes ); ?>
  232. />
  233. <?php // echo $description; ?>
  234. </div>
  235. </div>
  236. </div>
  237.  
  238. <?php
  239. break;
  240.  
  241. case 'heading':
  242.  
  243. $type = $value['type'];
  244. $class = '';
  245. ?>
  246.  
  247. <div class="main-controls-heading forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo esc_attr( $value['class'] ); ?>">
  248. <?php echo esc_html( $value['title'] ); ?>
  249. <?php echo $tip; ?>
  250. </div>
  251.  
  252. <?php
  253. break;
  254.  
  255. // Textarea
  256. case 'textarea':
  257.  
  258. $option_value = self::get_option( $value['id'], $value['default'] );
  259. ?>
  260.  
  261. <div class="main-controls-element forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo esc_attr( $value['class'] ); ?>">
  262. <label class="controls-label">
  263. <?php echo esc_html( $value['title'] ); ?>
  264. <?php echo $tip; ?>
  265. </label>
  266. <?php // echo $tip; ?>
  267. <?php // echo $description; ?>
  268.  
  269. <div class="controls-field">
  270. <div class="controls-inner-row">
  271.  
  272. <?php if ($value['default']): ?>
  273. <span class="reset-to-default help_tip_new" data-tip="<?php echo esc_attr( __("Reset to - ",'email-control') . ' ' . $value['default'] ); ?>" data-default="<?php echo esc_attr( $value['default'] ); ?>">
  274. Reset to default <i class="fa fa-refresh"></i>
  275. </span>
  276. <?php endif ?>
  277.  
  278. <textarea
  279. name="<?php echo esc_attr( $value['id'] ); ?>"
  280. id="<?php echo esc_attr( $value['id'] ); ?>"
  281. style="<?php echo esc_attr( $value['css'] ); ?>"
  282. class="<?php echo esc_attr( $value['field_class'] ); ?>"
  283. <?php echo implode( ' ', $custom_attributes ); ?>
  284. ><?php echo esc_textarea( $option_value ); ?></textarea>
  285.  
  286. </div>
  287. </div>
  288. </div>
  289.  
  290. <?php
  291.  
  292. break;
  293.  
  294.  
  295. // /CX
  296.  
  297. // Section Titles
  298. case 'title':
  299. if ( !empty( $value['title'] ) ) {
  300. echo '<h3>' . esc_html( $value['title'] ) . '</h3>';
  301. }
  302. if ( !empty( $value['desc'] ) ) {
  303. echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) );
  304. }
  305. echo '<table class="form-table">'. "\n\n";
  306. if ( !empty( $value['id'] ) ) {
  307. do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) );
  308. }
  309. break;
  310.  
  311. // Section Ends
  312. case 'sectionend':
  313. if ( !empty( $value['id'] ) ) {
  314. do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) . '_end' );
  315. }
  316. echo '</table>';
  317. if ( !empty( $value['id'] ) ) {
  318. do_action( 'woocommerce_settings_' . sanitize_title( $value['id'] ) . '_after' );
  319. }
  320. break;
  321.  
  322. // Select boxes
  323. case 'select' :
  324. case 'multiselect' :
  325.  
  326. $option_value = self::get_option( $value['id'], $value['default'] );
  327.  
  328. ?>
  329. <div class="main-controls-element forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo esc_attr( $value['class'] ); ?>">
  330. <label class="controls-label">
  331. <?php echo esc_html( $value['title'] ); ?>
  332. <?php echo $tip; ?>
  333. </label>
  334. <?php // echo $tip; ?>
  335. <?php // echo $description; ?>
  336.  
  337. <div class="controls-field">
  338. <div class="controls-inner-row">
  339.  
  340. <?php if ($value['default']): ?>
  341. <span class="reset-to-default help_tip_new" data-tip="<?php echo esc_attr( __("Reset to - ",'email-control') . ' ' . $value['default'] ); ?>" data-default="<?php echo esc_attr( $value['default'] ); ?>">
  342. Reset to default <i class="fa fa-refresh"></i>
  343. </span>
  344. <?php endif ?>
  345.  
  346. <select
  347. name="<?php echo esc_attr( $value['id'] ); ?><?php if ( $value['type'] == 'multiselect' ) echo '[]'; ?>"
  348. id="<?php echo esc_attr( $value['id'] ); ?>"
  349. style="<?php echo esc_attr( $value['css'] ); ?>"
  350. class="<?php echo esc_attr( $value['field_class'] ); ?>"
  351. <?php echo implode( ' ', $custom_attributes ); ?>
  352. <?php if ( $value['type'] == 'multiselect' ) echo 'multiple="multiple"'; ?>
  353. >
  354. <?php
  355. foreach ( $value['options'] as $key => $val ) {
  356. ?>
  357. <option value="<?php echo esc_attr( $key ); ?>" <?php
  358.  
  359. if ( is_array( $option_value ) )
  360. selected( in_array( $key, $option_value ), true );
  361. else
  362. selected( $option_value, $key );
  363.  
  364. ?>><?php echo $val ?></option>
  365. <?php
  366. }
  367. ?>
  368. </select>
  369.  
  370. </div>
  371. </div>
  372. </div>
  373. <?php
  374. break;
  375.  
  376. // Radio inputs
  377. case 'radio' :
  378.  
  379. $option_value = self::get_option( $value['id'], $value['default'] );
  380.  
  381. ?><tr valign="top">
  382. <th scope="row" class="titledesc">
  383. <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
  384. <?php echo $tip; ?>
  385. </th>
  386. <td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
  387. <fieldset>
  388. <?php echo $description; ?>
  389. <ul>
  390. <?php
  391. foreach ( $value['options'] as $key => $val ) {
  392. ?>
  393. <li>
  394. <label><input
  395. name="<?php echo esc_attr( $value['id'] ); ?>"
  396. value="<?php echo $key; ?>"
  397. type="radio"
  398. style="<?php echo esc_attr( $value['css'] ); ?>"
  399. class="<?php echo esc_attr( $value['field_class'] ); ?>"
  400. <?php echo implode( ' ', $custom_attributes ); ?>
  401. <?php checked( $key, $option_value ); ?>
  402. /> <?php echo $val ?></label>
  403. </li>
  404. <?php
  405. }
  406. ?>
  407. </ul>
  408. </fieldset>
  409. </td>
  410. </tr><?php
  411. break;
  412.  
  413. // Checkbox input
  414. case 'checkbox' :
  415. ?>
  416. <div class="main-controls-element forminp-<?php echo sanitize_title( $value['type'] ) ?> <?php echo esc_attr( $value['class'] ); ?>">
  417. <label class="controls-label">
  418. <?php echo esc_html( $value['title'] ); ?>
  419. <?php echo $tip; ?>
  420. </label>
  421.  
  422. <div class="controls-field">
  423. <div class="controls-inner-row">
  424.  
  425. <?php if ($value['default']): ?>
  426. <span class="reset-to-default help_tip_new" data-tip="<?php echo esc_attr( __("Reset to - ",'email-control') . ' ' . $value['default'] ); ?>" data-default="<?php echo esc_html( $value['default'] ); ?>">
  427. Reset to default <i class="fa fa-refresh"></i>
  428. </span>
  429. <?php endif ?>
  430. <input
  431. name="<?php echo esc_attr( $value['id'] ); ?>"
  432. id="<?php echo esc_attr( $value['id'] ); ?>"
  433. type="checkbox"
  434. style="<?php echo esc_attr( $value['css'] ); ?>"
  435. value="<?php echo esc_attr( $option_value ); ?>"
  436. class="<?php echo esc_attr( $value['field_class'] ); ?>"
  437. <?php echo implode( ' ', $custom_attributes ); ?>
  438. />
  439. <?php // echo $description; ?>
  440. </div>
  441. </div>
  442. </div>
  443. <?php
  444. break;
  445.  
  446. // Image width settings
  447. case 'image_width' :
  448.  
  449. $width = self::get_option( $value['id'] . '[width]', $value['default']['width'] );
  450. $height = self::get_option( $value['id'] . '[height]', $value['default']['height'] );
  451. $crop = checked( 1, self::get_option( $value['id'] . '[crop]', $value['default']['crop'] ), false );
  452.  
  453. ?><tr valign="top">
  454. <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?> <?php echo $tip; ?></th>
  455. <td class="forminp image_width_settings">
  456.  
  457. <input name="<?php echo esc_attr( $value['id'] ); ?>[width]" id="<?php echo esc_attr( $value['id'] ); ?>-width" type="text" size="3" value="<?php echo $width; ?>" autocomplete="off" /> &times; <input name="<?php echo esc_attr( $value['id'] ); ?>[height]" id="<?php echo esc_attr( $value['id'] ); ?>-height" type="text" size="3" value="<?php echo $height; ?>" autocomplete="off" />px
  458.  
  459. <label><input name="<?php echo esc_attr( $value['id'] ); ?>[crop]" id="<?php echo esc_attr( $value['id'] ); ?>-crop" type="checkbox" <?php echo $crop; ?> /> <?php _e( 'Hard Crop?', 'email-control' ); ?></label>
  460.  
  461. </td>
  462. </tr><?php
  463. break;
  464.  
  465. // Single page selects
  466. case 'single_select_page' :
  467.  
  468. $args = array( 'name' => $value['id'],
  469. 'id' => $value['id'],
  470. 'sort_column' => 'menu_order',
  471. 'sort_order' => 'ASC',
  472. 'show_option_none' => ' ',
  473. 'field_class' => $value['field_class'],
  474. 'echo' => false,
  475. 'selected' => absint( self::get_option( $value['id'] ) )
  476. );
  477.  
  478. if ( isset( $value['args'] ) )
  479. $args = wp_parse_args( $value['args'], $args );
  480.  
  481. ?><tr valign="top" class="single_select_page">
  482. <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?> <?php echo $tip; ?></th>
  483. <td class="forminp">
  484. <?php echo str_replace(' id=', " data-placeholder='" . __( 'Select a page&hellip;', 'email-control' ) . "' style='" . $value['css'] . "' class='" . $value['field_class'] . "' id=", wp_dropdown_pages( $args ) ); ?> <?php echo $description; ?>
  485. </td>
  486. </tr><?php
  487. break;
  488.  
  489. // Single country selects
  490. case 'single_select_country' :
  491. $country_setting = (string) self::get_option( $value['id'] );
  492.  
  493. if ( class_exists('WC') )
  494. $countries = WC()->countries->countries;
  495. else
  496. $countries = $woocommerce->countries->countries;
  497.  
  498. if ( strstr( $country_setting, ':' ) ) {
  499. $country_setting = explode( ':', $country_setting );
  500. $country = current( $country_setting );
  501. $state = end( $country_setting );
  502. }
  503. else {
  504. $country = $country_setting;
  505. $state = '*';
  506. }
  507. ?><tr valign="top">
  508. <th scope="row" class="titledesc">
  509. <label><?php echo esc_html( $value['title'] ); ?></label>
  510. <?php echo $tip; ?>
  511. </th>
  512. <td class="forminp"><select name="<?php echo esc_attr( $value['id'] ); ?>" style="<?php echo esc_attr( $value['css'] ); ?>" data-placeholder="<?php _e( 'Choose a country&hellip;', 'email-control' ); ?>" title="Country" class="chosen_select">
  513. <?php
  514. if ( class_exists('WC') )
  515. WC()->countries->country_dropdown_options( $country, $state );
  516. else
  517. $woocommerce->countries->country_dropdown_options( $country, $state );
  518. ?>
  519. </select> <?php echo $description; ?>
  520. </td>
  521. </tr><?php
  522. break;
  523.  
  524. // Country multiselects
  525. case 'multi_select_countries' :
  526.  
  527. $selections = (array) self::get_option( $value['id'] );
  528.  
  529. if ( !empty( $value['options'] ) )
  530. $countries = $value['options'];
  531. else
  532. $countries = WC()->countries->countries;
  533.  
  534. asort( $countries );
  535. ?><tr valign="top">
  536. <th scope="row" class="titledesc">
  537. <label><?php echo esc_html( $value['title'] ); ?></label>
  538. <?php echo $tip; ?>
  539. </th>
  540. <td class="forminp">
  541. <select multiple="multiple" name="<?php echo esc_attr( $value['id'] ); ?>[]" style="width:350px" data-placeholder="<?php _e( 'Choose countries&hellip;', 'email-control' ); ?>" title="Country" class="chosen_select">
  542. <?php
  543. if ( $countries )
  544. foreach ( $countries as $key => $val )
  545. echo '<option value="' . esc_attr( $key ) . '" ' . selected( in_array( $key, $selections ), true, false ).'>' . $val . '</option>';
  546. ?>
  547. </select> <?php if ( $description ) echo $description; ?> </br><a class="select_all button" href="#"><?php _e( 'Select all', 'email-control' ); ?></a> <a class="select_none button" href="#"><?php _e( 'Select none', 'email-control' ); ?></a>
  548. </td>
  549. </tr><?php
  550. break;
  551.  
  552. // Default: run an action
  553. default:
  554. do_action( 'woocommerce_admin_field_' . $value['type'], $value );
  555. break;
  556. }
  557.  
  558. endif;
  559.  
  560. endforeach;
  561. ?>
  562. </div>
  563. </div>
  564.  
  565. <?php
  566.  
  567. endforeach;
  568. }
  569.  
  570. /**
  571. * Get a setting from the settings API.
  572. *
  573. * @param mixed $option
  574. * @return string
  575. */
  576. public static function get_option( $option_name, $default = '' ) {
  577.  
  578. if ( strstr( $option_name, '[' ) ) {
  579.  
  580. // Array value
  581. parse_str( $option_name, $option_array );
  582.  
  583. // Option name is first key
  584. $option_name = current( array_keys( $option_array ) );
  585.  
  586. // Get value
  587. $option_values = get_option( $option_name, '' );
  588.  
  589. $key = key( $option_array[ $option_name ] );
  590.  
  591. if ( isset( $option_values[ $key ] ) )
  592. $option_value = $option_values[ $key ];
  593. else
  594. $option_value = null;
  595.  
  596. }
  597. else {
  598.  
  599. // Single value
  600. $option_value = get_option( $option_name, null );
  601. }
  602.  
  603. if ( is_array( $option_value ) )
  604. $option_value = array_map( 'stripslashes', $option_value );
  605. elseif ( !is_null( $option_value ) )
  606. $option_value = stripslashes( $option_value );
  607.  
  608. return $option_value === null ? $default : $option_value;
  609. }
  610.  
  611. /**
  612. * Save admin fields.
  613. *
  614. * Loops though the options array and save each field.
  615. *
  616. * @access public
  617. * @param array $options Opens array to output
  618. * @return bool
  619. */
  620. public static function save_fields( $options ) {
  621.  
  622. // if ( empty( $_POST ) )
  623. // return false;
  624.  
  625. // Options to update will be stored here
  626. $update_options = array();
  627.  
  628. // Loop options and get values to save
  629. foreach ( $options as $value ) {
  630.  
  631. if ( !isset( $value['id'] ) )
  632. continue;
  633.  
  634. $type = isset( $value['type'] ) ? sanitize_title( $value['type'] ) : '';
  635.  
  636. // Get the option name
  637. $option_value = null;
  638.  
  639. switch ( $type ) {
  640.  
  641. // CX
  642.  
  643. case 'textarea' :
  644.  
  645. if ( isset( $_POST[$value['id']] ) ) {
  646. $option_value = wp_kses_post( trim( stripslashes( $_POST[ $value['id'] ] ) ) );
  647. }
  648. else {
  649. $option_value = '';
  650. }
  651.  
  652. break;
  653.  
  654. case 'text' :
  655. case 'email':
  656. case 'number':
  657. case 'select' :
  658. case 'color' :
  659. case 'password' :
  660. case 'single_select_page' :
  661. case 'single_select_country' :
  662. case 'radio' :
  663. case 'image_upload' :
  664.  
  665. if ( $value['id'] == 'woocommerce_price_thousand_sep' || $value['id'] == 'woocommerce_price_decimal_sep' ) {
  666.  
  667. // price separators get a special treatment as they should allow a spaces (don't trim)
  668. if ( isset( $_POST[ $value['id'] ] ) ) {
  669. $option_value = wp_kses_post( stripslashes( $_POST[ $value['id'] ] ) );
  670. }
  671. else {
  672. $option_value = '';
  673. }
  674.  
  675. }
  676. elseif ( $value['id'] == 'woocommerce_price_num_decimals' ) {
  677.  
  678. // price separators get a special treatment as they should allow a spaces (don't trim)
  679. if ( isset( $_POST[ $value['id'] ] ) ) {
  680. $option_value = absint( $_POST[ $value['id'] ] );
  681. }
  682. else {
  683. $option_value = 2;
  684. }
  685.  
  686. }
  687. elseif ( $value['id'] == 'woocommerce_hold_stock_minutes' ) {
  688.  
  689. // Allow > 0 or set to ''
  690. if ( !empty( $_POST[ $value['id'] ] ) ) {
  691. $option_value = absint( $_POST[ $value['id'] ] );
  692. }
  693. else {
  694. $option_value = '';
  695. }
  696.  
  697. wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' );
  698.  
  699. if ( $option_value != '' )
  700. wp_schedule_single_event( time() + ( absint( $option_value ) * 60 ), 'woocommerce_cancel_unpaid_orders' );
  701.  
  702. }
  703. else {
  704.  
  705. if ( isset( $_POST[$value['id']] ) ) {
  706. $option_value = wc_clean( stripslashes( $_POST[ $value['id'] ] ) );
  707. }
  708. else {
  709. $option_value = '';
  710. }
  711.  
  712. }
  713.  
  714. break;
  715.  
  716. // /CX
  717.  
  718. // Standard types
  719. case 'checkbox' :
  720.  
  721. if ( isset( $_POST[ $value['id'] ] ) ) {
  722. $option_value = 'yes';
  723. }
  724. else {
  725. $option_value = 'no';
  726. }
  727.  
  728. break;
  729.  
  730. // Special types
  731. case 'multiselect' :
  732. case 'multi_select_countries' :
  733.  
  734. // Get countries array
  735. if ( isset( $_POST[ $value['id'] ] ) )
  736. $selected_countries = array_map( 'wc_clean', array_map( 'stripslashes', (array) $_POST[ $value['id'] ] ) );
  737. else
  738. $selected_countries = array();
  739.  
  740. $option_value = $selected_countries;
  741.  
  742. break;
  743.  
  744. case 'image_width' :
  745.  
  746. if ( isset( $_POST[$value['id'] ]['width'] ) ) {
  747.  
  748. $update_options[ $value['id'] ]['width'] = wc_clean( stripslashes( $_POST[ $value['id'] ]['width'] ) );
  749. $update_options[ $value['id'] ]['height'] = wc_clean( stripslashes( $_POST[ $value['id'] ]['height'] ) );
  750.  
  751. if ( isset( $_POST[ $value['id'] ]['crop'] ) )
  752. $update_options[ $value['id'] ]['crop'] = 1;
  753. else
  754. $update_options[ $value['id'] ]['crop'] = 0;
  755.  
  756. }
  757. else {
  758. $update_options[ $value['id'] ]['width'] = $value['default']['width'];
  759. $update_options[ $value['id'] ]['height'] = $value['default']['height'];
  760. $update_options[ $value['id'] ]['crop'] = $value['default']['crop'];
  761. }
  762.  
  763. break;
  764.  
  765. // Custom handling
  766. default :
  767.  
  768. do_action( 'woocommerce_update_option_' . $type, $value );
  769.  
  770. break;
  771.  
  772. }
  773.  
  774. if ( !is_null( $option_value ) ) {
  775. // Check if option is an array
  776. if ( strstr( $value['id'], '[' ) ) {
  777.  
  778. parse_str( $value['id'], $option_array );
  779.  
  780. // Option name is first key
  781. $option_name = current( array_keys( $option_array ) );
  782.  
  783. // Get old option value
  784. if ( !isset( $update_options[ $option_name ] ) )
  785. $update_options[ $option_name ] = get_option( $option_name, array() );
  786.  
  787. if ( !is_array( $update_options[ $option_name ] ) )
  788. $update_options[ $option_name ] = array();
  789.  
  790. // Set keys and value
  791. $key = key( $option_array[ $option_name ] );
  792.  
  793. $update_options[ $option_name ][ $key ] = $option_value;
  794.  
  795. // Single value
  796. }
  797. else {
  798. $update_options[ $value['id'] ] = $option_value;
  799. }
  800. }
  801.  
  802. // Custom handling
  803. do_action( 'woocommerce_update_option', $value );
  804. }
  805.  
  806. // Now save the options
  807. foreach( $update_options as $name => $value ) {
  808. if ( str_replace(PHP_EOL, "\n", $value) != str_replace(PHP_EOL, "\n", self::get_option_array($name, 'default')) ) {
  809. update_option( $name, $value );
  810. //update_option( $name, self::get_option_array($name, 'default') );
  811. }
  812. else{
  813. delete_option( $name );
  814. }
  815. }
  816.  
  817. return true;
  818. }
  819.  
  820. /**
  821. * Save Defaults
  822. *
  823. * @deprecated 2.0 Never used - rather use sane defaults
  824. *
  825. */
  826. function save_defaults( $id, $settings ) {
  827.  
  828. foreach ($settings as $setting_key => $setting_args) {
  829.  
  830. $template_id_part = $id . "_";
  831. $settings_group_part = $setting_args["group"] . "_";
  832.  
  833. $field_id = "ec_" . $template_id_part . $settings_group_part . $setting_args["id"];
  834.  
  835. if ( get_option($field_id)=='' && isset($setting_args["default"]) ) {
  836. update_option( $field_id, $setting_args["default"] );
  837. }
  838. }
  839.  
  840. }
  841.  
  842. /**
  843. * Get a setting from the settings API.
  844. *
  845. * @param mixed $option
  846. * @return string Value of the option.
  847. */
  848. public static function get_option_array( $option_name, $option_key = false ) {
  849.  
  850. global $ec_cache_options;
  851.  
  852. $return_value = false;
  853.  
  854. if (!isset($ec_cache_options)) {
  855. $ec_cache_options = ec_get_settings();
  856. }
  857.  
  858. if ( isset($ec_cache_options[$option_name]) ) {
  859. $return_value = $ec_cache_options[$option_name];
  860. }
  861.  
  862. // No option array found return false
  863. if ( !$return_value ) {
  864. return false;
  865. }
  866.  
  867. $defaults = array(
  868. 'type' => '',
  869. 'default' => '',
  870. );
  871.  
  872. $return_value = wp_parse_args( $return_value, $defaults );
  873.  
  874.  
  875. if ($option_key) {
  876. if ( isset($return_value[ $option_key ]) )
  877. $return_value = $return_value[ $option_key ];
  878. else
  879. $return_value = false;
  880. }
  881.  
  882. return $return_value;
  883. }
  884.  
  885. /**
  886. * Render Option
  887. *
  888. * @param mixed $option
  889. * @return string
  890. */
  891.  
  892. public static function ec_default_option( $default ) {
  893.  
  894. $option_name = str_replace( 'default_option_', '', current_filter() );
  895.  
  896. $option_value = self::get_option_array( $option_name, 'default' );
  897.  
  898. $option_value = EC_Settings::ec_render_option( $option_name, $option_value);
  899.  
  900. return $option_value;
  901. }
  902.  
  903. /**
  904. * Render Option
  905. *
  906. * @param mixed $option
  907. * @return string
  908. */
  909. public static function ec_render_option( $option_name, $option_value = '' ) {
  910.  
  911. if (!$option_value) {
  912. $option_value = self::get_option_array($option_name, 'default');
  913. }
  914.  
  915. if ( isset($_REQUEST[$option_name]) ) {
  916. $option_value = stripslashes( $_REQUEST[$option_name] );
  917. }
  918.  
  919. $option_value = __( $option_value, 'email-control' );
  920. $option_value = do_shortcode( $option_value );
  921.  
  922. // stylise certain content types, eg textarea
  923. if ( in_array(self::get_option_array($option_name, 'type'), array('textarea') ) ) {
  924. $option_value = wptexturize( $option_value );
  925. $option_value = wpautop( $option_value );
  926. }
  927.  
  928. return __( $option_value, 'email-control' );
  929. }
  930.  
  931. /**
  932. * Helper to check whether to show shortcode elements.
  933. */
  934. public static function check_display( $shortcode_args, $check ) {
  935.  
  936. //Set to arrays
  937. $shortcode_args['show'] = array_map('trim', explode(',', $shortcode_args['show'] ));
  938. $shortcode_args['hide'] = array_map('trim', explode(',', $shortcode_args['hide'] ));
  939.  
  940. //Remove any show's that have been set as hide's
  941. foreach ($shortcode_args['hide'] as $key => $value) {
  942. if ( in_array($value, $shortcode_args['show'] ) ) {
  943. unset( $shortcode_args['show'] [array_search( $value, $shortcode_args['show'] )] );
  944. }
  945. }
  946.  
  947. return in_array( $check, $shortcode_args['show'] );
  948. }
  949.  
  950. public static function ec_normalize_template_args() {
  951.  
  952. global $ec_template_args;
  953.  
  954. $defaults = array(
  955. 'user_id' => '' ,
  956. 'user_login' => ( isset( $_REQUEST["ec_render_email"] ) ) ? 'username' : '' ,
  957. 'user_nicename' => ( isset( $_REQUEST["ec_render_email"] ) ) ? 'Nicename' : '' ,
  958. 'email' => ( isset( $_REQUEST["ec_render_email"] ) ) ? 'email@email.com' : '' ,
  959. 'first_name' => ( isset( $_REQUEST["ec_render_email"] ) ) ? 'Firstname' : '' ,
  960. 'last_name' => ( isset( $_REQUEST["ec_render_email"] ) ) ? 'Lastname' : '' ,
  961. );
  962.  
  963. $ec_template_args = wp_parse_args( $ec_template_args, $defaults );
  964.  
  965.  
  966. if ( isset( $ec_template_args['order'] ) ) {
  967.  
  968. $order = $ec_template_args['order'];
  969.  
  970. if ( ( $user_id = get_post_meta( $order->id, '_customer_user', true ) ) ) {
  971.  
  972. $user = get_user_by( 'id', $user_id );
  973.  
  974. // All emails with Orders in them - with an existing user account
  975.  
  976. if ( isset( $user->user_login ) ) $ec_template_args['user_login'] = $user->user_login ; // brentvr
  977. if ( isset( $user->user_nicename ) ) $ec_template_args['user_nicename'] = $user->user_nicename ; // BrentVR
  978. if ( $billing_email = get_post_meta( $order->id, '_billing_email', true ) ) $ec_template_args['email'] = $billing_email ; // brentvr@gmail.com
  979. if ( $billing_first_name = get_post_meta( $order->id, '_billing_first_name', true ) ) $ec_template_args['first_name'] = $billing_first_name ; // Brent
  980. if ( $billing_last_name = get_post_meta( $order->id, '_billing_last_name', true ) ) $ec_template_args['last_name'] = $billing_last_name ; // VanRensburg
  981. }
  982. else{
  983.  
  984. // All emails with Orders in them - without a user account
  985.  
  986. $ec_template_args['user_login'] = ''; //$user->user_login; // brentvr
  987. $ec_template_args['user_nicename'] = ''; //$user->user_nicename; // BrentVR
  988. if ( $billing_email = get_post_meta( $order->id, '_billing_email', true ) ) $ec_template_args['email'] = get_post_meta( $order->id, '_billing_email', true ); // brentvr@gmail.com
  989. if ( $billing_first_name = get_post_meta( $order->id, '_billing_first_name', true ) ) $ec_template_args['first_name'] = get_post_meta( $order->id, '_billing_first_name', true ); // Brent
  990. if ( $billing_last_name = get_post_meta( $order->id, '_billing_last_name', true ) ) $ec_template_args['last_name'] = get_post_meta( $order->id, '_billing_last_name', true ); // VanRensburg
  991. }
  992. }
  993. elseif ( isset( $ec_template_args['user_login'] ) ) {
  994.  
  995. // New account email.
  996.  
  997. $user = get_user_by( 'login', $ec_template_args['user_login'] );
  998.  
  999. if ( isset( $user->ID ) ) $ec_template_args['user_id'] = $user->ID; // 2
  1000. if ( isset( $user->user_login ) ) $ec_template_args['user_login'] = $user->user_login; // brentvr@gmail.com
  1001. if ( isset( $user->user_nicename ) ) $ec_template_args['user_nicename'] = $user->user_nicename; // brentvr@gmail.com
  1002. if ( isset( $user->user_email ) ) $ec_template_args['email'] = $user->user_email; // brentvr@gmail.com
  1003.  
  1004. if ( ( $first_name = get_user_meta( $user->ID, 'first_name', true ) ) )
  1005. $ec_template_args['first_name'] = $first_name; // Brent
  1006. elseif ( isset( $_POST['billing_first_name'] ) )
  1007. $ec_template_args['first_name'] = $_POST['billing_first_name']; // Brent
  1008.  
  1009. if ( ( $last_name = get_user_meta( $user->ID, 'last_name', true ) ) )
  1010. $ec_template_args['last_name'] = $last_name; // Van Rensburg
  1011. elseif ( isset( $_POST['billing_last_name'] ) )
  1012. $ec_template_args['last_name'] = $_POST['billing_last_name']; // Van Rensburg
  1013. }
  1014. }
  1015.  
  1016. public static function ec_user_login( $shortcode_args ) {
  1017.  
  1018. // Shortcode args
  1019. // ---------------------------
  1020.  
  1021. //Set shortcode args defaults
  1022. $shortcode_args_defaults = array(
  1023. 'show' => 'container',
  1024. 'hide' => '',
  1025. );
  1026.  
  1027. // Merge shortcode args with defaults
  1028. $shortcode_args = wp_parse_args( $shortcode_args, $shortcode_args_defaults );
  1029.  
  1030. // Compile content
  1031. // ----------------------------
  1032. global $ec_template_args;
  1033. self::ec_normalize_template_args();
  1034.  
  1035. $content = esc_html( $ec_template_args['user_login'] );
  1036.  
  1037. //Add Container (optional).
  1038. if ( self::check_display( $shortcode_args, 'container' ) ) {
  1039. $content = '<span class="ec_shortcode ec_user_login">' . $content . '</span>';
  1040. }
  1041.  
  1042. return $content;
  1043. }
  1044.  
  1045. public static function ec_lastname( $shortcode_args ) {
  1046.  
  1047. // Shortcode args
  1048. // ---------------------------
  1049.  
  1050. //Set shortcode args defaults
  1051. $shortcode_args_defaults = array(
  1052. 'show' => 'container',
  1053. 'hide' => '',
  1054. );
  1055.  
  1056. // Merge shortcode args with defaults
  1057. $shortcode_args = wp_parse_args( $shortcode_args, $shortcode_args_defaults );
  1058.  
  1059. // Compile content
  1060. // ----------------------------
  1061. global $ec_template_args;
  1062. self::ec_normalize_template_args();
  1063.  
  1064. // Check if necessary template args exits
  1065. if ( !isset( $ec_template_args['last_name'] ) ) return;
  1066.  
  1067. $content = $ec_template_args['last_name'];
  1068.  
  1069. //Add Container (optional).
  1070. if ( self::check_display( $shortcode_args, 'container' ) ) {
  1071. $content = '<span class="ec_shortcode ec_lastname">' . trim( $content ) . '</span>';
  1072. }
  1073.  
  1074. return $content;
  1075. }
  1076.  
  1077. public static function ec_firstname( $shortcode_args ) {
  1078.  
  1079. // Shortcode args
  1080. // ---------------------------
  1081.  
  1082. //Set shortcode args defaults
  1083. $shortcode_args_defaults = array(
  1084. 'show' => 'container',
  1085. 'hide' => '',
  1086. );
  1087.  
  1088. // Merge shortcode args with defaults
  1089. $shortcode_args = wp_parse_args( $shortcode_args, $shortcode_args_defaults );
  1090.  
  1091. // Compile content
  1092. // ----------------------------
  1093. global $ec_template_args;
  1094. self::ec_normalize_template_args();
  1095.  
  1096. // Check if necessary template args exits
  1097. if ( !isset( $ec_template_args['first_name'] ) ) return;
  1098.  
  1099. $content = $ec_template_args['first_name'];
  1100.  
  1101. //Add Container (optional).
  1102. if ( self::check_display( $shortcode_args, 'container' ) ) {
  1103. $content = '<span class="ec_shortcode ec_firstname">' . trim( $content ) . '</span>';
  1104. }
  1105.  
  1106. return $content;
  1107. }
  1108.  
  1109. public static function ec_order( $shortcode_args ) {
  1110.  
  1111. // Shortcode args
  1112. // ---------------------------
  1113.  
  1114. //Set shortcode args defaults
  1115. $shortcode_args_defaults = array(
  1116. 'show' => '#, number, date, link, container',
  1117. 'hide' => '',
  1118. );
  1119.  
  1120. // Merge shortcode args with defaults
  1121. $shortcode_args = wp_parse_args( $shortcode_args, $shortcode_args_defaults );
  1122.  
  1123. // Compile content
  1124. // ----------------------------
  1125. global $ec_template_args;
  1126. self::ec_normalize_template_args();
  1127.  
  1128. // Check if this shortcode can be used here
  1129. if ( !isset( $ec_template_args['order'] ) ) {
  1130. if ( isset( $_REQUEST["ec_render_email"] ) ) return '<span class="shortcode-error">' . __( 'This shortcode cannot be used in this email', 'email-control' ) . '</span>';
  1131. else return;
  1132. }
  1133.  
  1134. // Check if necessary template args exits
  1135. if ( !isset( $ec_template_args['order'] ) ) {
  1136. if ( isset( $_REQUEST["ec_render_email"] ) ) return '<span class="shortcode-error">[' . __( 'Order shortcodes cannot be used in this email', 'email-control' ) . ']</span>';
  1137. else return;
  1138. }
  1139.  
  1140. if ( isset( $ec_template_args['sent_to_admin'] ) && $ec_template_args['sent_to_admin'] ) {
  1141.  
  1142. //Admin Order URL
  1143. $order_url = admin_url( 'post.php?post=' . $ec_template_args['order']->id . '&action=edit' );
  1144. } else {
  1145.  
  1146. //Front End Order URL
  1147. $order_url = $ec_template_args['order']->get_view_order_url();
  1148. }
  1149.  
  1150. //start the return output.
  1151. $content = '';
  1152.  
  1153. if ( self::check_display( $shortcode_args, '#' ) || self::check_display( $shortcode_args, 'number' ) ) {
  1154.  
  1155. if ( self::check_display( $shortcode_args, 'link' ) ) {
  1156. $content .= '<a href="' . $order_url . '">';
  1157. }
  1158.  
  1159. if ( self::check_display( $shortcode_args, '#' ) )
  1160. $content .= '#';
  1161. if ( self::check_display( $shortcode_args, 'number' ) )
  1162. $content .= ltrim( $ec_template_args['order']->get_order_number(), '#' );
  1163.  
  1164. if ( self::check_display( $shortcode_args, 'link' ) ) {
  1165. $content .= '</a>';
  1166. }
  1167.  
  1168. //Add space.
  1169. $content .= " ";
  1170. }
  1171.  
  1172. if ( self::check_display( $shortcode_args, 'date' ) ) {
  1173. $content .= '<span class="ec_datetime">(' . sprintf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $ec_template_args['order']->order_date ) ), date_i18n( wc_date_format(), strtotime( $ec_template_args['order']->order_date ) ) ) . ')</span>';
  1174.  
  1175. //Add space.
  1176. $content .= " ";
  1177. }
  1178.  
  1179. //Trim spaces beginning and end.
  1180. $content = trim($content);
  1181.  
  1182. //Add Container (optional).
  1183. if ( self::check_display( $shortcode_args, 'container' ) ) {
  1184. $content = '<span class="ec_shortcode ec_order">' . $content . '</span>';
  1185. }
  1186.  
  1187. return $content;
  1188. }
  1189.  
  1190. public static function ec_customer_note( $shortcode_args ) {
  1191.  
  1192. // Shortcode args
  1193. // ---------------------------
  1194.  
  1195. //Set shortcode args defaults
  1196. $shortcode_args_defaults = array(
  1197. 'show' => 'container',
  1198. 'hide' => '',
  1199. );
  1200.  
  1201. // Merge shortcode args with defaults
  1202. $shortcode_args = wp_parse_args( $shortcode_args, $shortcode_args_defaults );
  1203.  
  1204. // Compile content
  1205. // ----------------------------
  1206. global $ec_template_args;
  1207. self::ec_normalize_template_args();
  1208.  
  1209. // Check if this shortcode can be used here
  1210. if ( !isset( $ec_template_args['order'] ) ) {
  1211. if ( isset( $_REQUEST["ec_render_email"] ) ) return '<span class="shortcode-error">' . __( 'This shortcode cannot be used in this email', 'email-control' ) . '</span>';
  1212. else return;
  1213. }
  1214. if ( isset( $_REQUEST["ec_email_type"] ) && $_REQUEST["ec_email_type"] !== 'customer_note' ) {
  1215. if ( isset( $_REQUEST["ec_render_email"] ) ) return '<span class="shortcode-error">' . __( 'This shortcode cannot be used in this email', 'email-control' ) . '</span>';
  1216. else return;
  1217. }
  1218.  
  1219. $content = '';
  1220.  
  1221. // Check if necessary template args exits
  1222. if ( isset( $ec_template_args['customer_note'] ) ) {
  1223. $content = $ec_template_args['customer_note'];
  1224. }
  1225. elseif ( isset( $_REQUEST["ec_email_template"] ) ) {
  1226. $content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas a nisi in dui consectetur ultricies eu id tellus. Sed elementum, metus vitae volutpat hendrerit, mi est rutrum enim, eget sodales nulla risus sit amet justo. Mauris luctus eu arcu eget malesuada.';
  1227. }
  1228.  
  1229. if ( '' == $content ) {
  1230. return;
  1231. }
  1232.  
  1233. //Add Container (optional).
  1234. if ( self::check_display( $shortcode_args, 'container' ) ) {
  1235. $content = '<span class="ec_shortcode ec_customer_note">' . trim( $content ) . '</span>';
  1236. }
  1237.  
  1238. return $content;
  1239. }
  1240.  
  1241. public static function ec_account_link( $shortcode_args ) {
  1242.  
  1243. // Shortcode args
  1244. // ---------------------------
  1245.  
  1246. //Set shortcode args defaults
  1247. $shortcode_args_defaults = array(
  1248. 'show' => 'container',
  1249. 'hide' => '',
  1250. );
  1251.  
  1252. // Merge shortcode args with defaults
  1253. $shortcode_args = wp_parse_args( $shortcode_args, $shortcode_args_defaults );
  1254.  
  1255. // Compile content
  1256. // ----------------------------
  1257. global $ec_template_args;
  1258. self::ec_normalize_template_args();
  1259.  
  1260. $link = get_permalink( wc_get_page_id( 'myaccount' ) );
  1261.  
  1262. ob_start();
  1263. ?><a href="<?php echo $link; ?>"><?php echo $link; ?></a><?php
  1264. $content = ob_get_clean();
  1265.  
  1266. //Add Container (optional).
  1267. if ( self::check_display( $shortcode_args, 'container' ) ) {
  1268. $content = '<span class="ec_shortcode ec_account_link">' . $content . '</span>';
  1269. }
  1270.  
  1271. return $content;
  1272. }
  1273.  
  1274. public static function ec_reset_password_link( $shortcode_args ) {
  1275.  
  1276. // Shortcode args
  1277. // ---------------------------
  1278.  
  1279. //Set shortcode args defaults
  1280. $shortcode_args_defaults = array(
  1281. 'show' => 'container',
  1282. 'hide' => '',
  1283. );
  1284.  
  1285. // Merge shortcode args with defaults
  1286. $shortcode_args = wp_parse_args( $shortcode_args, $shortcode_args_defaults );
  1287.  
  1288. // Compile content
  1289. // ----------------------------
  1290. global $ec_template_args;
  1291. self::ec_normalize_template_args();
  1292.  
  1293. $query_args = array();
  1294.  
  1295. if ( isset( $ec_template_args['reset_key'] ) && isset( $ec_template_args['user_login'] ) ) {
  1296. $query_args = array(
  1297. 'key' => $ec_template_args['reset_key'],
  1298. 'login' => rawurlencode( $ec_template_args['user_login'] )
  1299. );
  1300. }
  1301.  
  1302. $link = esc_url_raw( add_query_arg(
  1303. $query_args,
  1304. wc_get_endpoint_url( 'lost-password', '', get_permalink( wc_get_page_id( 'myaccount' ) ) )
  1305. ) );
  1306.  
  1307. ob_start();
  1308. ?><a href="<?php echo $link; ?>"><?php _e( 'Click here to reset your password', 'email-control' ); ?></a><?php
  1309. $content = ob_get_clean();
  1310.  
  1311. //Add Container (optional).
  1312. if ( self::check_display( $shortcode_args, 'container' ) ) {
  1313. $content = '<span class="ec_shortcode ec_reset_password_link">' . $content . '</span>';
  1314. }
  1315.  
  1316. return $content;
  1317. }
  1318.  
  1319. public static function ec_user_password( $shortcode_args ) {
  1320.  
  1321. // Shortcode args
  1322. // ---------------------------
  1323.  
  1324. //Set shortcode args defaults
  1325. $shortcode_args_defaults = array(
  1326. 'show' => 'container',
  1327. 'hide' => '',
  1328. );
  1329.  
  1330. // Merge shortcode args with defaults
  1331. $shortcode_args = wp_parse_args( $shortcode_args, $shortcode_args_defaults );
  1332.  
  1333. // Compile content
  1334. // ----------------------------
  1335. global $ec_template_args;
  1336. self::ec_normalize_template_args();
  1337.  
  1338. // Check if this shortcode can be used here
  1339. if ( isset( $ec_template_args['order'] ) ) {
  1340. if ( isset( $_REQUEST["ec_render_email"] ) ) return '<span class="shortcode-error">' . __( 'This shortcode cannot be used in this email', 'email-control' ) . '</span>';
  1341. else return;
  1342. }
  1343.  
  1344. $content = '';
  1345.  
  1346. // Check if necessary template args exits
  1347. if ( isset( $ec_template_args['user_pass'] ) ) {
  1348. $content = esc_html( $ec_template_args['user_pass'] );
  1349. }
  1350. elseif ( isset( $_REQUEST["ec_email_template"] ) ) {
  1351. $content = '#%ZiZi$%#kL#';
  1352. }
  1353.  
  1354. if ( '' == $content ) {
  1355. return;
  1356. }
  1357.  
  1358. //Add Container (optional).
  1359. if ( self::check_display( $shortcode_args, 'container' ) ) {
  1360. $content = '<span class="ec_shortcode ec_user_password">' . trim( $content ) . '</span>';
  1361. }
  1362.  
  1363. return $content;
  1364. }
  1365.  
  1366. public static function ec_pay_link( $shortcode_args ) {
  1367.  
  1368. // Shortcode args
  1369. // ---------------------------
  1370.  
  1371. //Set shortcode args defaults
  1372. $shortcode_args_defaults = array(
  1373. 'show' => 'container',
  1374. 'hide' => '',
  1375. );
  1376.  
  1377. // Merge shortcode args with defaults
  1378. $shortcode_args = wp_parse_args( $shortcode_args, $shortcode_args_defaults );
  1379.  
  1380. // Compile content
  1381. // ----------------------------
  1382. global $ec_template_args;
  1383. self::ec_normalize_template_args();
  1384.  
  1385. // Check if this shortcode can be used here
  1386. if ( !isset( $ec_template_args['order'] ) ) {
  1387. if ( isset( $_REQUEST["ec_render_email"] ) ) return '<span class="shortcode-error">' . __( 'This shortcode cannot be used in this email', 'email-control' ) . '</span>';
  1388. else return;
  1389. }
  1390.  
  1391. // Check if necessary template args exits
  1392. $link = esc_url_raw( $ec_template_args['order']->get_checkout_payment_url() );
  1393. if ( !$link ) return;
  1394.  
  1395. ob_start();
  1396. ?><a href="<?php echo $link; ?>"><?php _e( 'Pay now', 'email-control' ) ?></a><?php
  1397. $content = ob_get_clean();
  1398.  
  1399. //Add Container (optional).
  1400. if ( self::check_display( $shortcode_args, 'container' ) ) {
  1401. $content = '<span class="ec_shortcode ec_pay_link">' . $content . '</span>';
  1402. }
  1403.  
  1404. return $content;
  1405. }
  1406.  
  1407. public static function ec_login_link( $shortcode_args ) {
  1408.  
  1409. // Shortcode args
  1410. // ---------------------------
  1411.  
  1412. //Set shortcode args defaults
  1413. $shortcode_args_defaults = array(
  1414. 'show' => 'container',
  1415. 'hide' => '',
  1416. );
  1417.  
  1418. // Merge shortcode args with defaults
  1419. $shortcode_args = wp_parse_args( $shortcode_args, $shortcode_args_defaults );
  1420.  
  1421. // Compile content
  1422. // ----------------------------
  1423. global $ec_template_args;
  1424. self::ec_normalize_template_args();
  1425.  
  1426. $link = get_permalink( wc_get_page_id( 'myaccount' ) );
  1427.  
  1428. ob_start();
  1429. ?><a href="<?php echo $link; ?>"><?php echo $link; ?></a><?php
  1430. $content = ob_get_clean();
  1431.  
  1432. //Add Container (optional).
  1433. if ( self::check_display( $shortcode_args, 'container' ) ) {
  1434. $content = '<span class="ec_shortcode ec_login_link">' . $content . '</span>';
  1435. }
  1436.  
  1437. return $content;
  1438. }
  1439.  
  1440. public static function ec_site_link( $shortcode_args ) {
  1441.  
  1442. // Shortcode args
  1443. // ---------------------------
  1444.  
  1445. //Set shortcode args defaults
  1446. $shortcode_args_defaults = array(
  1447. 'show' => 'container',
  1448. 'hide' => '',
  1449. );
  1450.  
  1451. // Merge shortcode args with defaults
  1452. $shortcode_args = wp_parse_args( $shortcode_args, $shortcode_args_defaults );
  1453.  
  1454. // Compile content
  1455. // ----------------------------
  1456. global $ec_template_args;
  1457. self::ec_normalize_template_args();
  1458.  
  1459. ob_start();
  1460. ?><a href="<?php echo esc_url_raw( get_site_url() ) ?>"><?php echo get_bloginfo( 'name' ); ?></a><?php
  1461. $content = ob_get_clean();
  1462.  
  1463. //Add Container (optional).
  1464. if ( self::check_display( $shortcode_args, 'container' ) ) {
  1465. $content = '<span class="ec_shortcode ec_site_link">' . $content . '</span>';
  1466. }
  1467.  
  1468. return $content;
  1469. }
  1470.  
  1471. public static function ec_site_name( $shortcode_args ) {
  1472.  
  1473. // Shortcode args
  1474. // ---------------------------
  1475.  
  1476. //Set shortcode args defaults
  1477. $shortcode_args_defaults = array(
  1478. 'show' => 'container',
  1479. 'hide' => '',
  1480. );
  1481.  
  1482. // Merge shortcode args with defaults
  1483. $shortcode_args = wp_parse_args( $shortcode_args, $shortcode_args_defaults );
  1484.  
  1485. // Compile content
  1486. // ----------------------------
  1487. global $ec_template_args;
  1488. self::ec_normalize_template_args();
  1489.  
  1490. $content = get_bloginfo( 'name' );
  1491.  
  1492. //Add Container (optional).
  1493. if ( self::check_display( $shortcode_args, 'container' ) ) {
  1494. $content = '<span class="ec_shortcode ec_site_name">' . $content . '</span>';
  1495. }
  1496.  
  1497. return $content;
  1498. }
  1499.  
  1500. }
  1501.  
  1502.  
  1503.  
  1504. /**
  1505. * Get Settings
  1506. *
  1507. * Gets modified array of uniqe-ified keys for optionally specific selected settings.
  1508. *
  1509. * @global array $ec_email_templates Registered templates
  1510. * @param string $template_id Optional. Template id of settings to get
  1511. * @param string $group Optional. Template type eg New Order
  1512. */
  1513. if ( !function_exists('ec_get_settings') ) {
  1514. function ec_get_settings( $template_id = false, $filter_args = array() ) {
  1515.  
  1516. global $ec_email_templates;
  1517.  
  1518. //Set default filtred array of templates, incase get_settings isn't specific about an id
  1519. $ec_email_templates_filtered = $ec_email_templates;
  1520.  
  1521.  
  1522. $settings_all = array();
  1523.  
  1524.  
  1525. if ( $template_id ) {
  1526. if ( isset($ec_email_templates[$template_id]) ) {
  1527. // assign just the settings that id is looking for
  1528. $ec_email_templates_filtered = array();
  1529. $ec_email_templates_filtered[$template_id] = $ec_email_templates[$template_id];
  1530. }
  1531. else{
  1532. //if nothing is found base on template_id then return nothing
  1533. return false;
  1534. }
  1535. }
  1536.  
  1537. foreach ($ec_email_templates_filtered as $ec_email_templates_filtered_key => $ec_email_templates_filtered_value ) {
  1538.  
  1539. // Only do anything if there are acutally settings been set by thte template
  1540. if ( isset( $ec_email_templates_filtered_value["settings"] ) && is_array($ec_email_templates_filtered_value["settings"]) ) {
  1541.  
  1542. $settings = $ec_email_templates_filtered_value["settings"];
  1543.  
  1544. // Filter out anything specified in the filter args array - eg Email Types - "new_order"
  1545. foreach ($filter_args as $filter_key => $filter_value ) {
  1546.  
  1547. $filtered_settings = array();
  1548.  
  1549. foreach ($settings as $setting_key => $setting_args ) {
  1550.  
  1551. if ( isset( $setting_args[$filter_key] ) && $setting_args[$filter_key] == $filter_value ) // || $setting_args["group"] == 'all'
  1552. $filtered_settings[] = $setting_args;
  1553. }
  1554.  
  1555. $settings = $filtered_settings;
  1556.  
  1557. }
  1558.  
  1559.  
  1560.  
  1561. // Rename ID's to make them more unique. eg heading becomes ec_deluxe_new_order_heading
  1562. $renamed_id_settings = array();
  1563. foreach ($settings as $setting_key => $setting_args) {
  1564.  
  1565. // Don't id change on sections
  1566. if ( $setting_args["type"] != "section" ) {
  1567.  
  1568. $template_id_part = $ec_email_templates_filtered_key . "_";
  1569. //$settings_group_part = ( $setting_args["group"] != 'all' ) ? $setting_args["group"] . "_" : "" ;
  1570. $settings_group_part = $setting_args["group"] . "_";
  1571.  
  1572. $setting_args["id"] = "ec_" . $template_id_part . $settings_group_part . $setting_args["id"];
  1573. }
  1574. $renamed_id_settings[ $setting_args["id"] ] = $setting_args;
  1575.  
  1576. }
  1577.  
  1578. $settings_all = array_merge( $settings_all, $renamed_id_settings );
  1579. }
  1580.  
  1581. }
  1582.  
  1583.  
  1584. if ( count($settings_all) )
  1585. return $settings_all;
  1586. else
  1587. return false;
  1588.  
  1589.  
  1590. }
  1591. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement