Advertisement
Guest User

Untitled

a guest
Jun 29th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. Plugin Name: AB Test
  5. Description: Display different theme
  6. Author: RSmol
  7. */
  8.  
  9. add_filter('template', 'change_theme');
  10. add_filter('option_template', 'change_theme');
  11. add_filter('option_stylesheet', 'change_theme');
  12. function change_theme($theme) {
  13.  
  14. if ($_GET['ab_test'] == 'ab_test') {
  15. $theme = 'tolstovka_new';
  16. }
  17.  
  18. if (!get_option( 'ab_test_name' )) {
  19. return $theme;
  20. }
  21.  
  22. if (strpos($_SERVER['REQUEST_URI'], 'tekstil/futbolki/') !== false) {
  23.  
  24. require_once __DIR__ . '/ABTest.php';
  25. if (ABTest::instance()->getTestValue('print_capital_new_template_t-shirt') === 'new') {
  26. $theme = 'tolstovka_new';
  27. }
  28. }
  29.  
  30. return $theme;
  31. }
  32.  
  33. add_action( 'admin_init', 'ab_tests_api_init' );
  34. function ab_tests_api_init() {
  35. add_settings_section(
  36. 'ab_test_section', // секция
  37. 'Настройки AB тестирования',
  38. 'ab_test_section_callback_function',
  39. 'reading' // страница
  40. );
  41.  
  42. add_settings_field(
  43. 'ab_test_name',
  44. 'Включить AB тестирование',
  45. 'ab_test_callback_function', // можно указать ''
  46. 'reading', // страница
  47. 'ab_test_section' // секция
  48. );
  49.  
  50. register_setting( 'reading', 'ab_test_name' );
  51. }
  52.  
  53. function ab_test_section_callback_function() {
  54. }
  55.  
  56. function ab_test_callback_function() {
  57. echo '<input
  58. name="ab_test_name"
  59. type="checkbox"
  60. ' . checked( 1, get_option( 'ab_test_name' ), false ) . '
  61. value="1"
  62. class="code"
  63. />';
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement