Initialize settings classes

This commit is contained in:
Brian Miyaji
2014-03-27 03:10:04 +11:00
parent 690ba1463f
commit d3b27c8c73
33 changed files with 6294 additions and 89 deletions

View File

@@ -1,58 +1,4 @@
/* SportsPress admin styles */
@font-face {
font-family: 'sportspress';
src:url('../fonts/sportspress.eot?ofuus8');
src:url('../fonts/sportspress.eot?#iefixofuus8') format('embedded-opentype'),
url('../fonts/sportspress.woff?ofuus8') format('woff'),
url('../fonts/sportspress.ttf?ofuus8') format('truetype'),
url('../fonts/sportspress.svg?ofuus8#sportspress') format('svg');
font-weight: normal;
font-style: normal;
}
[class^="sp-icon-"], [class*=" sp-icon-"] {
font-family: 'sportspress';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.sp-icon-calendar:before {
content: "\f145";
}
.sp-icon-shield:before {
content: "\f334";
}
.sp-icon-clock:before {
content: "\f469";
}
.sp-icon-tshirt:before {
content: "\f307";
}
.sp-icon-megaphone:before {
content: "\f322";
}
.sp-icon-crown:before {
content: "\f313";
}
.sp-icon-trophy:before {
content: "\f325";
}
.sp-icon-list:before {
content: "\f163"
}
.sp-icon-smile:before {
content: "\f328";
}
.post-state-format.post-format-calendar:before, .post-format-icon.post-format-calendar:before, a.post-state-format.format-calendar:before {
content: "\f145";
}
@@ -118,6 +64,15 @@
color: #888;
}
/* Settings */
.sportspress table.form-table, .sportspress table.form-table .forminp-radio ul {
margin: 0;
}
.sportspress table.sp-admin-config-table .edit {
text-align: right;
}
/* Messages */
.sportspress-message {
border-left-color: #6bc2a5 !important;
}

View File

@@ -1,4 +1,56 @@
/* SportsPress menu styles */
@font-face {
font-family: 'sportspress';
src:url('../fonts/sportspress.eot?ofuus8');
src:url('../fonts/sportspress.eot?#iefixofuus8') format('embedded-opentype'),
url('../fonts/sportspress.woff?ofuus8') format('woff'),
url('../fonts/sportspress.ttf?ofuus8') format('truetype'),
url('../fonts/sportspress.svg?ofuus8#sportspress') format('svg');
font-weight: normal;
font-style: normal;
}
[class^="sp-icon-"], [class*=" sp-icon-"] {
font-family: 'sportspress';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.sp-icon-calendar:before {
content: "\f145";
}
.sp-icon-shield:before {
content: "\f334";
}
.sp-icon-clock:before {
content: "\f469";
}
.sp-icon-tshirt:before {
content: "\f307";
}
.sp-icon-megaphone:before {
content: "\f322";
}
.sp-icon-crown:before {
content: "\f313";
}
.sp-icon-trophy:before {
content: "\f325";
}
.sp-icon-list:before {
content: "\f163"
}
.sp-icon-smile:before {
content: "\f328";
}
#adminmenu #toplevel_page_sportspress .menu-icon-generic div.wp-menu-image:before,
#adminmenu #menu-posts-sp_event .menu-icon-sp_event div.wp-menu-image:before,

Binary file not shown.

View File

@@ -7,6 +7,7 @@
<font-face units-per-em="512" ascent="480" descent="-32" />
<missing-glyph horiz-adv-x="512" />
<glyph unicode="&#x20;" d="" horiz-adv-x="256" />
<glyph unicode="&#xe600;" d="M256 177.177c61.184 0 112.409 20.787 115.507 47.949-9.088 25.523-19.021 53.35-28.774 80.717-6.759-19.507-44.16-33.28-86.733-33.28s-79.949 13.747-86.758 33.255c-9.754-27.366-19.635-55.168-28.749-80.717 3.097-27.136 54.298-47.923 115.507-47.923zM256 348.826c28.749 0 55.475 8.909 63.309 22.733-10.777 30.285-20.045 56.243-25.907 72.627-3.865 10.931-21.504 16.615-37.401 16.615s-33.536-5.683-37.401-16.589c-5.863-16.384-15.104-42.368-25.907-72.627 7.833-13.849 34.56-22.758 63.309-22.758zM480.768 151.91l-96.128 38.733 11.085-30.899c-0.563-32.717-64.128-58.829-139.725-58.829s-139.161 26.112-139.699 58.829l11.059 30.899-96.128-38.733c-26.957-10.88-28.083-30.976-2.535-44.672l180.787-96.947c25.575-13.696 67.43-13.696 93.005 0l180.787 96.947c25.6 13.696 24.448 33.792-2.509 44.672z" />
<glyph unicode="&#xf145;" d="M384 435.2h-51.2v-51.2h51.2v51.2zM435.2 435.2h-25.6v-76.8h-102.4v76.8h-102.4v-76.8h-102.4v76.8h-25.6c-14.16 0-25.6-11.44-25.6-25.6v-358.4c0-14.16 11.44-25.6 25.6-25.6h358.4c14.16 0 25.6 11.44 25.6 25.6v358.4c0 14.16-11.44 25.6-25.6 25.6zM409.6 76.8h-307.2v230.4h307.2v-230.4zM179.2 435.2h-51.2v-51.2h51.2v51.2zM281.6 256h-51.2v-51.2h51.2v51.2zM358.4 256h-51.2v-51.2h51.2v51.2zM204.8 179.2h-51.2v-51.2h51.2v51.2zM204.8 256h-51.2v-51.2h51.2v51.2zM281.6 179.2h-51.2v-51.2h51.2v51.2zM358.4 179.2h-51.2v-51.2h51.2v51.2z" />
<glyph unicode="&#xf163;" d="M153.6 332.8h51.2v-51.2h-51.2v51.2zM153.6 256h51.2v-51.2h-51.2v51.2zM153.6 179.2h51.2v-51.2h-51.2v51.2zM256 179.2h102.4v-51.2h-102.4v51.2zM435.2 435.2h-358.4c-14.16 0-25.6-11.44-25.6-25.6v-358.4c0-14.16 11.44-25.6 25.6-25.6h358.4c14.16 0 25.6 11.44 25.6 25.6v358.4c0 14.16-11.44 25.6-25.6 25.6zM409.6 76.8h-307.2v307.2h307.2v-307.2zM256 256h102.4v-51.2h-102.4v51.2zM256 332.8h102.4v-51.2h-102.4v51.2z" />
<glyph unicode="&#xf307;" d="M384 102.4h-256v179.2h-76.8v102.4l130.4 25.6c8.56-33.12 38.56-57.6 74.4-57.6s65.84 24.48 74.4 57.6l130.4-25.6v-102.4h-76.8v-179.2zM384 76.8v-51.2h-256v51.2h256z" />
@@ -14,6 +15,6 @@
<glyph unicode="&#xf322;" d="M430.8 56.56l-116.8 97.2h-160.4v-76.8c0-7.2-2.56-13.28-7.6-18.24s-11.040-7.36-18-7.36h-25.6c-7.2 0-13.28 2.48-18.24 7.36s-7.36 11.040-7.36 18.24v76.8c-7.2 0-13.28 2.48-18.24 7.36s-7.36 11.040-7.36 18.24v128c0 7.2 2.48 13.28 7.36 18.24s11.040 7.36 18.24 7.36h237.2l116.8 97.2c2.96 3.2 6.88 4.88 11.84 4.96s9.2-0.88 12.8-3.040 5.44-4.8 5.44-8v-362c0-3.2-1.76-5.84-5.44-8s-7.84-3.040-12.8-2.8c-4.96 0.4-8.88 2.080-11.84 5.28zM243.2 332.96h-51.2c3.44 0 6.48-1.28 8.96-3.84s3.84-5.52 3.84-8.96v-153.6c0-3.44-1.28-6.48-3.84-8.96s-5.52-3.84-8.96-3.84h51.2c-3.76 0-6.8 1.28-9.2 3.84s-3.6 5.52-3.6 8.96v153.6c0 3.44 1.2 6.48 3.6 8.96s5.44 3.84 9.2 3.84z" />
<glyph unicode="&#xf325;" d="M381.28 261.12c-8.56-52.4-48.16-94.16-99.68-104.8v-54c0-28.32 22.96-51.28 51.28-51.28h25.6v-25.6h-204.96v25.6h25.6c28.32 0 51.28 22.96 51.28 51.28v54c-51.44 10.64-91.12 52.4-99.68 104.8-60.48 15.84-105.36 70.4-105.36 135.84 0 4.4 0.88 8.56 1.28 12.8h101.2v51.2h256.24v-51.28h101.2c0.4-4.32 1.28-8.4 1.28-12.8 0-65.44-44.8-119.92-105.28-135.76zM127.92 384.080h-75.6c4.96-44.4 34.96-81.040 75.6-95.6v95.6zM384.080 384.080v-95.6c40.64 14.56 70.56 51.2 75.6 95.6h-75.6z" />
<glyph unicode="&#xf328;" d="M324 170.571q-10.572-34.572-39.428-55.714t-65.143-21.143-65.143 21.143-39.428 55.714q-2.285 7.143 1.143 13.857t10.857 9q7.143 2.286 13.857-1.143t9-10.857q7.143-22.857 26.428-37t43.286-14.143 43.286 14.143 26.428 37q2.286 7.428 9.143 10.857t14 1.143 10.572-9 1.143-13.857zM182.857 294.857q0-15.143-10.714-25.857t-25.857-10.714-25.857 10.714-10.715 25.857 10.715 25.857 25.857 10.714 25.857-10.714 10.714-25.857zM329.143 294.857q0-15.143-10.714-25.857t-25.857-10.714-25.857 10.714-10.714 25.857 10.714 25.857 25.857 10.714 25.857-10.714 10.714-25.857zM402.286 221.714q0 37.143-14.572 71t-39 58.286-58.286 39-71 14.572-71-14.572-58.285-39-39-58.286-14.572-71 14.572-71 39-58.286 58.285-39 71-14.572 71 14.572 58.286 39 39 58.286 14.572 71zM438.857 221.714q0-59.714-29.428-110.143t-79.857-79.857-110.143-29.428-110.143 29.428-79.857 79.857-29.428 110.143 29.428 110.143 79.857 79.857 110.143 29.428 110.143-29.428 79.857-79.857 29.428-110.143z" horiz-adv-x="439" />
<glyph unicode="&#xf334;" d="M425.76 151.28c-6.16-15.76-14-29.84-23.2-42s-20.24-24.080-33.040-35.68c-12.8-11.52-24.56-21.2-35.36-28.88-10.88-7.6-22.080-14.88-33.84-21.68-11.84-6.8-20.16-11.44-25.12-13.92-4.96-2.4-8.96-4.24-11.92-5.52-2.24-1.2-4.64-1.68-7.28-1.68s-5.040 0.64-7.28 1.68c-3.040 1.28-6.88 3.12-11.92 5.52-5.040 2.4-13.36 7.040-25.12 13.92-11.76 6.8-23.040 14-33.84 21.68-10.88 7.68-22.56 17.28-35.36 28.88-12.8 11.52-23.84 23.36-33.040 35.68s-16.96 26.24-23.2 42c-6.32 15.76-9.44 31.76-9.44 47.76v215.040c0 4.8 1.68 9.12 5.28 12.64 3.6 3.52 7.76 5.28 12.64 5.28h322.56c4.8 0 9.12-1.68 12.64-5.28s5.28-7.76 5.28-12.64v-215.040c0-16-3.2-32-9.44-47.76zM384 380.8h-256v-181.92c0-33.36 22.4-67.52 67.12-102.32 17.92-14 38.24-27.040 60.88-38.96v0 0 0 0c22.64 11.92 42.96 24.96 60.88 38.96 44.72 34.88 67.12 68.96 67.12 102.32v181.92zM304.72 119.6c-14.32-11.6-30.56-22.4-48.72-32.24v0 0 267.68h102.4v-150.72c0-27.6-17.92-55.84-53.68-84.72z" />
<glyph unicode="&#xf469;" d="M256 465.92c-130.073 0-235.52-105.472-235.52-235.52 0-130.073 105.447-235.52 235.52-235.52s235.52 105.447 235.52 235.52c0 130.074-105.447 235.52-235.52 235.52zM256 46.080c-101.811 0-184.32 82.534-184.32 184.32s82.509 184.32 184.32 184.32 184.32-82.534 184.32-184.32-82.509-184.32-184.32-184.32zM273.92 363.52h-35.84v-140.544l87.168-87.168 25.344 25.344-76.672 76.672z" />
<glyph unicode="&#xf334;" d="M425.76 154.48c-6.16-15.76-14-29.84-23.2-42s-20.24-24.080-33.040-35.68c-12.8-11.52-24.56-21.2-35.36-28.88-10.88-7.6-22.080-14.88-33.84-21.68-11.84-6.8-20.16-11.44-25.12-13.92-4.96-2.4-8.96-4.24-11.92-5.52-2.24-1.2-4.64-1.68-7.28-1.68s-5.040 0.64-7.28 1.68c-3.040 1.28-6.88 3.12-11.92 5.52-5.040 2.4-13.36 7.040-25.12 13.92-11.76 6.8-23.040 14-33.84 21.68-10.88 7.68-22.56 17.28-35.36 28.88-12.8 11.52-23.84 23.36-33.040 35.68s-16.96 26.24-23.2 42c-6.32 15.76-9.44 31.76-9.44 47.76v215.040c0 4.8 1.68 9.12 5.28 12.64s7.76 5.28 12.64 5.28h322.56c4.8 0 9.12-1.68 12.64-5.28s5.28-7.76 5.28-12.64v-215.040c0-16-3.2-32-9.44-47.76zM384 384h-256v-181.92c0-33.36 22.4-67.52 67.12-102.32 17.92-14 38.24-27.040 60.88-38.96v0 0 0 0c22.64 11.92 42.96 24.96 60.88 38.96 44.72 34.88 67.12 68.96 67.12 102.32v181.92zM304.72 122.8c-14.32-11.6-30.56-22.4-48.72-32.24v0 0 267.68h102.4v-150.72c0-27.6-17.92-55.84-53.68-84.72z" />
<glyph unicode="&#xf469;" d="M256 462.72c-130.073 0-235.52-105.472-235.52-235.52 0-130.073 105.447-235.52 235.52-235.52s235.52 105.447 235.52 235.52c0 130.073-105.447 235.52-235.52 235.52zM256 42.88c-101.811 0-184.32 82.534-184.32 184.32s82.509 184.32 184.32 184.32 184.32-82.534 184.32-184.32-82.509-184.32-184.32-184.32zM273.92 360.32h-35.84v-140.544l87.168-87.168 25.344 25.344-76.672 76.672z" />
</font></defs></svg>

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,12 +0,0 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>Generated by IcoMoon</metadata>
<defs>
<font id="themeboy" horiz-adv-x="1024">
<font-face units-per-em="1024" ascent="960" descent="-64" />
<missing-glyph horiz-adv-x="1024" />
<glyph unicode="&#x20;" d="" horiz-adv-x="512" />
<glyph unicode="&#xe600;" d="M970.3 532l-22.1 12.8h23.1v-12.8h-1zM903.9 570.3h67.4v-12.8h-45.3l-22.1 12.8zM859.7 595.8h111.6v-12.8h-89.5l-22.1 12.8zM815.4 621.4h155.9v-12.8h-133.7l-22.2 12.8zM771.2 646.9h200.1c0-0.5 0.1-0.9 0.1-1.4v-11.4h-178l-22.2 12.8zM726.6 672.6h240.6c1.2-4.3 2.2-8.5 2.9-12.8h-221.4l-22.1 12.8zM682.3 698.2h274.3c2.2-4.2 4.2-8.4 6-12.8h-258.2l-22.1 12.8zM638.1 723.7h301.2c3.5-4 6.7-8.3 9.8-12.8h-288.9l-22.1 12.8zM593.8 749.2h313.6l6-3.4c4.5-2.6 8.8-5.8 13.1-9.3h-310.6l-22.1 12.7zM549.6 774.8h313.6l22.1-12.8h-313.6l-22.1 12.8zM510.5 797.3l-16.9-9.8h-313.6l22.1 12.8h616.8l22.1-12.8h-313.5l-17 9.8zM246.4 825.8h528.2l22.1-12.8h-572.4l22.1 12.8zM290.7 851.3h439.7l22.1-12.8h-484l22.2 12.8zM334.9 876.9h351.2l22.1-12.8h-395.4l22.1 12.8zM379.2 902.4h262.7l22.1-12.8h-307l22.2 12.8zM423.4 927.9h174.2l22.1-12.8h-218.4l22.1 12.8zM452.6 944.8c6.3 3.6 13.4 6.5 21 8.7h73.9c7.6-2.2 14.7-5.1 21-8.7l7-4.1h-129.9l7 4.1zM449.3 762h-313.6l22.1 12.8h313.6l-22.1-12.8zM405.1 736.5h-310.5c4.2 3.6 8.6 6.7 13.1 9.3l6 3.4h313.6l-22.2-12.7zM360.8 710.9h-288.8c3 4.5 6.3 8.8 9.7 12.8h301.2l-22.1-12.8zM358.5 709.6l152-87.7-155.7-89.9h-305v12.8h308.8v12.8h-308.9v12.8h308.8v12.8h-308.8v12.8h308.8v12.8h-308.8v12.8h308.8v12.8h-308.8v11.4c0 0.4 0.1 0.9 0.1 1.4h308.7v13h-307.6c0.7 4.2 1.7 8.5 2.9 12.8h304.6v12.8h-300c1.8 4.3 3.8 8.6 6 12.8h294.2v11zM310.5 506.5h-260.8v12.8h282.9l-22.1-12.8zM266.3 480.9h-216.6v12.8h238.7l-22.1-12.8zM222 455.4h-172.3v12.8h194.4l-22.1-12.8zM177.8 429.9h-128.1v12.8h150.2l-22.1-12.8zM133.5 404.3h-83.8v12.8h106l-22.2-12.8zM89.3 378.8h-39.6v12.8h61.7l-22.1-12.8zM49.7 356v10h17.5l-17.5-10zM662.5 534.2l156.7-90.4 152 87.7v-178.2h-4.7l-22.1-12.8h26.9v-12.8h-49l-22.2-12.7h71.2v-12.8h-93.3l-22.5-13h115.8v-12.8h-138l-14.1-8.1-14.1 8.1h-285.2l-22.1-12.8h473.5v-12.8h-495.6l-22.1-12.8h517.2c-0.5-4.2-1.2-8.5-2.2-12.8h-537.2l-22.1-12.8h555.4c-1.6-4.3-3.4-8.6-5.4-12.8h-572.1l-22.2-12.5h587.2c-2.7-4.4-5.7-8.7-8.8-12.8h-600.5l-22.1-12.8h611.3c-5.1-4.9-10.5-9.2-16.1-12.8h-617.3l-22.2-12.7h617.6l-22.1-12.7h-617.6l-22.1-12.8h617.6l-22.1-12.8h-617.6l-8.4-4.9-94.1 54.3c-31.9 18.4-57.9 63.5-57.9 100.2v108.7l152-87.7 460.7 265.9zM672 353.3h-19l-22.1-12.8h63.3l-22.2 12.8zM716.3 327.7h-107.5l-22.2-12.7h151.7l-22 12.7zM783 289.2l-22.5 13h-196l-22.5-13h241zM783.5 72.2h-546l-22.1 12.8h590.2l-22.1-12.8zM739.2 46.7h-457.4l-22.1 12.8h501.7l-22.2-12.8zM695 21.1h-368.9l-22.1 12.8h413.1l-22.1-12.8zM650.7-4.4h-280.4l-22.1 12.8h324.6l-22.1-12.8zM606.4-29.9h-191.8l-22.1 12.8h236.1l-22.2-12.8zM568.4-51.8c-2.3-1.3-4.7-2.5-7.1-3.6h-101.6c-2.5 1.1-4.8 2.3-7.1 3.6l-15.9 9.2h147.6l-15.9-9.2z" />
<glyph unicode="&#xe601;" d="M971.3 544.8v-12.8h-1l0.9-0.5-152-87.7-156.7 90.4-460.8-266-152 87.8v10h17.5l22.1 12.8h-39.6v12.8h61.7l22.1 12.8h-83.8v12.8h106l22.1 12.8h-128.1v12.8h150.2l22.1 12.8h-172.3v12.8h194.4l22.1 12.8h-216.5v12.8h238.7l22.1 12.8h-260.8v12.8h282.9l22.1 12.8h-305v12.8h308.8v-10.6l152 87.7-152 87.7 2.3 1.3h-288.8c3 4.5 6.3 8.8 9.7 12.8h301.2l22.1 12.8h-310.4c4.2 3.6 8.6 6.7 13.1 9.3l6 3.4h313.6l22.1 12.8h-313.7l22.1 12.8h313.6l22.1 12.8h-313.5l22.1 12.8h616.8l22.1-12.8h-313.5l22.1-12.8h313.6l22.1-12.8h-313.6l22.1-12.8h313.6l6-3.4c4.5-2.6 8.8-5.8 13.1-9.3h-310.6l22.1-12.8h301.2c3.5-4 6.7-8.3 9.8-12.8h-288.8l22.1-12.8h274.3c2.2-4.2 4.2-8.4 6-12.8h-258.2l22.1-12.8h240.6c1.2-4.3 2.2-8.5 2.9-12.8h-221.3l22.5-13h200.1c0-0.5 0.1-0.9 0.1-1.4v-11.4h-178l22.1-12.8h155.9v-12.8h-133.8l22.1-12.8h111.6v-12.8h-89.5l22.1-12.8h67.4v-12.8h-45.3l22.1-12.8h23.2zM246.4 825.8h528.2l22.1-12.8h-572.4l22.1 12.8zM290.7 851.3h439.7l22.1-12.8h-484l22.2 12.8zM334.9 876.9h351.2l22.1-12.8h-395.4l22.1 12.8zM379.2 902.4h262.7l22.1-12.8h-307l22.2 12.8zM423.4 927.9h174.2l22.1-12.8h-218.4l22.1 12.8zM452.6 944.8c6.3 3.6 13.4 6.5 21 8.7h73.9c7.6-2.2 14.7-5.1 21-8.7l7-4.1h-129.9l7 4.1zM358.5 685.4h-300.1c1.8 4.3 3.8 8.6 6 12.8h294.2v-12.8zM358.5 659.9h-307.6c0.7 4.2 1.7 8.5 2.9 12.8h304.6v-12.8zM358.5 634.1h-308.8v11.4c0 0.4 0.1 0.9 0.1 1.4h308.7v-12.8zM358.5 608.6h-308.8v12.8h308.8v-12.8zM358.5 583.1h-308.8v12.8h308.8v-12.8zM358.5 557.5h-308.8v12.8h308.8v-12.8zM849.9 110.5l-22.1-12.8h-617.6l22.1 12.8h617.6zM783.5 72.2h-546l-22.1 12.8h590.2l-22.1-12.8zM739.2 46.7h-457.4l-22.1 12.8h501.7l-22.2-12.8zM695 21.1h-368.9l-22.1 12.8h413.1l-22.1-12.8zM650.7-4.4h-280.4l-22.1 12.8h324.6l-22.1-12.8zM606.4-29.9h-191.8l-22.1 12.8h236.1l-22.2-12.8zM568.4-51.8c-2.3-1.3-4.7-2.5-7.1-3.6h-101.6c-2.5 1.1-4.8 2.3-7.1 3.6l-15.9 9.2h147.6l-15.9-9.2zM276.5 136h617.6l-22.1-12.7h-617.6l22.1 12.7zM320.8 161.6h611.3c-5.1-4.9-10.5-9.2-16.1-12.8h-617.3l22.1 12.8zM365 187.1h587.2c-2.7-4.4-5.7-8.7-8.8-12.8h-600.5l22.1 12.8zM409.3 212.6h555.4c-1.6-4.3-3.4-8.6-5.4-12.8h-572.1l22.1 12.8zM453.5 238.2h517.2c-0.5-4.2-1.2-8.5-2.2-12.8h-537.1l22.1 12.8zM805.1 276.5h-285.2l22.1 12.8h241l22.1-12.8zM760.5 302.2h-196l22.1 12.8h151.7l22.2-12.8zM672 353.3h-19l9.5 5.5 9.5-5.5zM716.3 327.7h-107.5l22.1 12.8h63.3l22.1-12.8zM971.3 250.9h-495.6l22.1 12.8h473.5v-12.8zM971.3 276.5h-138l22.1 12.8h115.8l0.1-12.8zM971.3 302.2h-93.3l22.1 12.8h71.2v-12.8zM971.2 353.3h-4.7l4.7 2.7v-2.7zM971.3 327.7h-49l22.1 12.8h26.9v-12.8z" />
</font></defs></svg>

Before

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,129 @@
<?php
/**
* Setup menus in WP admin.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Admin_Menus' ) ) :
/**
* SP_Admin_Menus Class
*/
class SP_Admin_Menus {
/**
* Hook in tabs.
*/
public function __construct() {
add_filter( 'admin_menu', array( $this, 'menu_clean' ) );
add_action( 'admin_menu', array( $this, 'settings_menu' ), 50 );
add_action( 'admin_head', array( $this, 'menu_highlight' ) );
}
/**
* Add menu item
*/
public function settings_menu() {
$settings_page = add_options_page( __( 'SportsPress', 'sportspress' ), __( 'SportsPress', 'sportspress' ), 'manage_options', 'sportspress', array( $this, 'settings_page' ) );
}
/**
* Highlights the correct top level admin menu item for post type add screens.
*
* @access public
* @return void
*/
public function menu_highlight() {
global $typenow;
if ( in_array( $typenow, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_performance', 'sp_metric' ) ) )
sportspress_highlight_admin_menu();
elseif ( $typenow == 'sp_table' )
sportspress_highlight_admin_menu( 'edit.php?post_type=sp_team', 'edit.php?post_type=sp_table' );
elseif ( $typenow == 'sp_list' )
sportspress_highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_list' );
elseif ( $typenow == 'sp_staff' )
sportspress_highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_staff' );
elseif ( $typenow == 'sp_directory' )
sportspress_highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_directory' );
}
/**
* Clean the SP menu items in admin.
*/
public function menu_clean() {
global $menu, $submenu;
// Find where our separator is in the menu
foreach( $menu as $key => $data ):
if ( is_array( $data ) && array_key_exists( 2, $data ) && $data[2] == 'edit.php?post_type=sp_separator' )
$separator_position = $key;
endforeach;
// Swap our separator post type with a menu separator
if ( isset( $separator_position ) ):
$menu[ $separator_position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
endif;
// Remove "Venues" and "Positions" links from Media submenu
if ( isset( $submenu['upload.php'] ) ):
$submenu['upload.php'] = array_filter( $submenu['upload.php'], array( $this, 'remove_venues' ) );
$submenu['upload.php'] = array_filter( $submenu['upload.php'], array( $this, 'remove_positions' ) );
endif;
// Remove "Leagues" and "Seasons" links from Events submenu
if ( isset( $submenu['edit.php?post_type=sp_event'] ) ):
$submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], array( $this, 'remove_seasons' ) );
endif;
// Remove "Leagues" and "Seasons" links from Players submenu
if ( isset( $submenu['edit.php?post_type=sp_player'] ) ):
$submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], array( $this, 'remove_seasons' ) );
endif;
// Remove "Leagues" and "Seasons" links from Staff submenu
if ( isset( $submenu['edit.php?post_type=sp_staff'] ) ):
$submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_seasons' ) );
endif;
}
/**
* Init the settings page
*/
public function settings_page() {
include_once( 'class-sp-admin-settings.php' );
SP_Admin_Settings::output();
}
public function remove_add_new( $arr = array() ) {
return $arr[0] != __( 'Add New', 'sportspress' );
}
public function remove_leagues( $arr = array() ) {
return $arr[0] != __( 'Leagues', 'sportspress' );
}
public function remove_positions( $arr = array() ) {
return $arr[0] != __( 'Positions', 'sportspress' );
}
public function remove_seasons( $arr = array() ) {
return $arr[0] != __( 'Seasons', 'sportspress' );
}
public function remove_venues( $arr = array() ) {
return $arr[0] != __( 'Venues', 'sportspress' );
}
}
endif;
return new SP_Admin_Menus();

View File

@@ -0,0 +1,701 @@
<?php
/**
* SportsPress Admin Settings Class.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Admin_Settings' ) ) :
/**
* SP_Admin_Settings
*/
class SP_Admin_Settings {
private static $settings = array();
private static $errors = array();
private static $messages = array();
/**
* Include the settings page classes
*/
public static function get_settings_pages() {
if ( empty( self::$settings ) ) {
$settings = array();
include_once( 'settings/class-sp-settings-page.php' );
$settings[] = include( 'settings/class-sp-settings-general.php' );
$settings[] = include( 'settings/class-sp-settings-events.php' );
$settings[] = include( 'settings/class-sp-settings-teams.php' );
$settings[] = include( 'settings/class-sp-settings-players.php' );
$settings[] = include( 'settings/class-sp-settings-text.php' );
$settings[] = include( 'settings/class-sp-settings-config.php' );
self::$settings = apply_filters( 'sportspress_get_settings_pages', $settings );
}
return self::$settings;
}
/**
* Save the settings
*/
public static function save() {
global $current_section, $current_tab;
if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'sportspress-settings' ) )
die( __( 'Action failed. Please refresh the page and retry.', 'sportspress' ) );
// Trigger actions
do_action( 'sportspress_settings_save_' . $current_tab );
do_action( 'sportspress_update_options_' . $current_tab );
do_action( 'sportspress_update_options' );
self::add_message( __( 'Your settings have been saved.', 'sportspress' ) );
do_action( 'sportspress_settings_saved' );
}
/**
* Add a message
* @param string $text
*/
public static function add_message( $text ) {
self::$messages[] = $text;
}
/**
* Add an error
* @param string $text
*/
public static function add_error( $text ) {
self::$errors[] = $text;
}
/**
* Output messages + errors
*/
public static function show_messages() {
if ( sizeof( self::$errors ) > 0 ) {
foreach ( self::$errors as $error )
echo '<div id="message" class="error fade"><p><strong>' . esc_html( $error ) . '</strong></p></div>';
} elseif ( sizeof( self::$messages ) > 0 ) {
foreach ( self::$messages as $message )
echo '<div id="message" class="updated fade"><p><strong>' . esc_html( $message ) . '</strong></p></div>';
}
}
/**
* Settings page.
*
* Handles the display of the main sportspress settings page in admin.
*
* @access public
* @return void
*/
public static function output() {
global $current_section, $current_tab;
do_action( 'sportspress_settings_start' );
wp_enqueue_script( 'sportspress_settings', SP()->plugin_url() . '/assets/js/admin/settings.min.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'iris', 'chosen' ), SP()->version, true );
wp_localize_script( 'sportspress_settings', 'sportspress_settings_params', array(
'i18n_nav_warning' => __( 'The changes you made will be lost if you navigate away from this page.', 'sportspress' )
) );
// Include settings pages
self::get_settings_pages();
// Get current tab/section
$current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( $_GET['tab'] );
$current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( $_REQUEST['section'] );
// Save settings if data has been posted
if ( ! empty( $_POST ) )
self::save();
// Add any posted messages
if ( ! empty( $_GET['sp_error'] ) )
self::add_error( stripslashes( $_GET['sp_error'] ) );
if ( ! empty( $_GET['sp_message'] ) )
self::add_message( stripslashes( $_GET['sp_message'] ) );
self::show_messages();
// Get tabs for the settings page
$tabs = apply_filters( 'sportspress_settings_tabs_array', array() );
include 'views/html-admin-settings.php';
}
/**
* Get a setting from the settings API.
*
* @param mixed $option
* @return string
*/
public static function get_option( $option_name, $default = '' ) {
// Array value
if ( strstr( $option_name, '[' ) ) {
parse_str( $option_name, $option_array );
// Option name is first key
$option_name = current( array_keys( $option_array ) );
// Get value
$option_values = get_option( $option_name, '' );
$key = key( $option_array[ $option_name ] );
if ( isset( $option_values[ $key ] ) )
$option_value = $option_values[ $key ];
else
$option_value = null;
// Single value
} else {
$option_value = get_option( $option_name, null );
}
if ( is_array( $option_value ) )
$option_value = array_map( 'stripslashes', $option_value );
elseif ( ! is_null( $option_value ) )
$option_value = stripslashes( $option_value );
return $option_value === null ? $default : $option_value;
}
/**
* Output admin fields.
*
* Loops though the sportspress options array and outputs each field.
*
* @access public
* @param array $options Opens array to output
*/
public static function output_fields( $options ) {
foreach ( $options as $value ) {
if ( ! isset( $value['type'] ) ) continue;
if ( ! isset( $value['id'] ) ) $value['id'] = '';
if ( ! isset( $value['title'] ) ) $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
if ( ! isset( $value['class'] ) ) $value['class'] = '';
if ( ! isset( $value['css'] ) ) $value['css'] = '';
if ( ! isset( $value['default'] ) ) $value['default'] = '';
if ( ! isset( $value['desc'] ) ) $value['desc'] = '';
if ( ! isset( $value['desc_tip'] ) ) $value['desc_tip'] = false;
if ( ! isset( $value['placeholder'] ) ) $value['placeholder'] = '';
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) )
foreach ( $value['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
// Description handling
if ( $value['desc_tip'] === true ) {
$description = '';
$tip = $value['desc'];
} elseif ( ! empty( $value['desc_tip'] ) ) {
$description = $value['desc'];
$tip = $value['desc_tip'];
} elseif ( ! empty( $value['desc'] ) ) {
$description = $value['desc'];
$tip = '';
} else {
$description = $tip = '';
}
if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) {
$description = '<p style="margin-top:0">' . wp_kses_post( $description ) . '</p>';
} elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) {
$description = wp_kses_post( $description );
} elseif ( $description ) {
$description = '<span class="description">' . wp_kses_post( $description ) . '</span>';
}
if ( $tip && in_array( $value['type'], array( 'checkbox' ) ) ) {
$tip = '<p class="description">' . $tip . '</p>';
} elseif ( $tip ) {
$tip = '<img class="help_tip" data-tip="' . esc_attr( $tip ) . '" src="' . SP()->plugin_url() . '/assets/images/help.png" height="16" width="16" />';
}
// Switch based on type
switch( $value['type'] ) {
// Section Titles
case 'title':
if ( ! empty( $value['title'] ) ) {
echo '<h3>' . esc_html( $value['title'] ) . '</h3>';
}
if ( ! empty( $value['desc'] ) ) {
echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) );
}
echo '<table class="form-table">'. "\n\n";
if ( ! empty( $value['id'] ) ) {
do_action( 'sportspress_settings_' . sanitize_title( $value['id'] ) );
}
break;
// Section Ends
case 'sectionend':
if ( ! empty( $value['id'] ) ) {
do_action( 'sportspress_settings_' . sanitize_title( $value['id'] ) . '_end' );
}
echo '</table>';
if ( ! empty( $value['id'] ) ) {
do_action( 'sportspress_settings_' . sanitize_title( $value['id'] ) . '_after' );
}
break;
// Standard text inputs and subtypes like 'number'
case 'text':
case 'email':
case 'number':
case 'color' :
case 'password' :
$type = $value['type'];
$class = '';
$option_value = self::get_option( $value['id'], $value['default'] );
if ( $value['type'] == 'color' ) {
$type = 'text';
$value['class'] .= 'colorpick';
$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>';
}
?><tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
<?php echo $tip; ?>
</th>
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
<input
name="<?php echo esc_attr( $value['id'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
type="<?php echo esc_attr( $type ); ?>"
style="<?php echo esc_attr( $value['css'] ); ?>"
value="<?php echo esc_attr( $option_value ); ?>"
placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); ?>
/> <?php echo $description; ?>
</td>
</tr><?php
break;
// Textarea
case 'textarea':
$option_value = self::get_option( $value['id'], $value['default'] );
?><tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
<?php echo $tip; ?>
</th>
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
<?php echo $description; ?>
<textarea
name="<?php echo esc_attr( $value['id'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
style="<?php echo esc_attr( $value['css'] ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); ?>
><?php echo esc_textarea( $option_value ); ?></textarea>
</td>
</tr><?php
break;
// Select boxes
case 'select' :
case 'multiselect' :
$option_value = self::get_option( $value['id'], $value['default'] );
?><tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
<?php echo $tip; ?>
</th>
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
<select
name="<?php echo esc_attr( $value['id'] ); ?><?php if ( $value['type'] == 'multiselect' ) echo '[]'; ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
style="<?php echo esc_attr( $value['css'] ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); ?>
<?php if ( $value['type'] == 'multiselect' ) echo 'multiple="multiple"'; ?>
>
<?php
foreach ( $value['options'] as $key => $val ) {
?>
<option value="<?php echo esc_attr( $key ); ?>" <?php
if ( is_array( $option_value ) )
selected( in_array( $key, $option_value ), true );
else
selected( $option_value, $key );
?>><?php echo $val ?></option>
<?php
}
?>
</select> <?php echo $description; ?>
</td>
</tr><?php
break;
// Radio inputs
case 'radio' :
$option_value = self::get_option( $value['id'], $value['default'] );
?><tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
<?php echo $tip; ?>
</th>
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
<fieldset>
<?php echo $description; ?>
<ul>
<?php
foreach ( $value['options'] as $key => $val ) {
?>
<li>
<label><input
name="<?php echo esc_attr( $value['id'] ); ?>"
value="<?php echo $key; ?>"
type="radio"
style="<?php echo esc_attr( $value['css'] ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>"
<?php echo implode( ' ', $custom_attributes ); ?>
<?php checked( $key, $option_value ); ?>
/> <?php echo $val ?></label>
</li>
<?php
}
?>
</ul>
</fieldset>
</td>
</tr><?php
break;
// Checkbox input
case 'checkbox' :
$option_value = self::get_option( $value['id'], $value['default'] );
$visbility_class = array();
if ( ! isset( $value['hide_if_checked'] ) ) {
$value['hide_if_checked'] = false;
}
if ( ! isset( $value['show_if_checked'] ) ) {
$value['show_if_checked'] = false;
}
if ( $value['hide_if_checked'] == 'yes' || $value['show_if_checked'] == 'yes' ) {
$visbility_class[] = 'hidden_option';
}
if ( $value['hide_if_checked'] == 'option' ) {
$visbility_class[] = 'hide_options_if_checked';
}
if ( $value['show_if_checked'] == 'option' ) {
$visbility_class[] = 'show_options_if_checked';
}
if ( ! isset( $value['checkboxgroup'] ) || 'start' == $value['checkboxgroup'] ) {
?>
<tr valign="top" class="<?php echo esc_attr( implode( ' ', $visbility_class ) ); ?>">
<th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?></th>
<td class="forminp forminp-checkbox">
<fieldset>
<?php
} else {
?>
<fieldset class="<?php echo esc_attr( implode( ' ', $visbility_class ) ); ?>">
<?php
}
if ( ! empty( $value['title'] ) ) {
?>
<legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ) ?></span></legend>
<?php
}
?>
<label for="<?php echo $value['id'] ?>">
<input
name="<?php echo esc_attr( $value['id'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
type="checkbox"
value="1"
<?php checked( $option_value, 'yes'); ?>
<?php echo implode( ' ', $custom_attributes ); ?>
/> <?php echo $description ?>
</label> <?php echo $tip; ?>
<?php
if ( ! isset( $value['checkboxgroup'] ) || 'end' == $value['checkboxgroup'] ) {
?>
</fieldset>
</td>
</tr>
<?php
} else {
?>
</fieldset>
<?php
}
break;
// Image width settings
case 'image_width' :
$width = self::get_option( $value['id'] . '[width]', $value['default']['width'] );
$height = self::get_option( $value['id'] . '[height]', $value['default']['height'] );
$crop = checked( 1, self::get_option( $value['id'] . '[crop]', $value['default']['crop'] ), false );
?><tr valign="top">
<th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?> <?php echo $tip; ?></th>
<td class="forminp image_width_settings">
<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; ?>" /> &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; ?>" />px
<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?', 'sportspress' ); ?></label>
</td>
</tr><?php
break;
// Single page selects
case 'single_select_page' :
$args = array( 'name' => $value['id'],
'id' => $value['id'],
'sort_column' => 'menu_order',
'sort_order' => 'ASC',
'show_option_none' => ' ',
'class' => $value['class'],
'echo' => false,
'selected' => absint( self::get_option( $value['id'] ) )
);
if( isset( $value['args'] ) )
$args = wp_parse_args( $value['args'], $args );
?><tr valign="top" class="single_select_page">
<th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ) ?> <?php echo $tip; ?></th>
<td class="forminp">
<?php echo str_replace(' id=', " data-placeholder='" . __( 'Select a page&hellip;', 'sportspress' ) . "' style='" . $value['css'] . "' class='" . $value['class'] . "' id=", wp_dropdown_pages( $args ) ); ?> <?php echo $description; ?>
</td>
</tr><?php
break;
// Single country selects
case 'single_select_country' :
$country_setting = (string) self::get_option( $value['id'] );
$countries = SP()->countries->countries;
if ( strstr( $country_setting, ':' ) ) {
$country_setting = explode( ':', $country_setting );
$country = current( $country_setting );
$state = end( $country_setting );
} else {
$country = $country_setting;
$state = '*';
}
?><tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
<?php echo $tip; ?>
</th>
<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;', 'sportspress' ); ?>" title="Country" class="chosen_select">
<?php SP()->countries->country_dropdown_options( $country, $state ); ?>
</select> <?php echo $description; ?>
</td>
</tr><?php
break;
// Country multiselects
case 'multi_select_countries' :
$selections = (array) self::get_option( $value['id'] );
if ( ! empty( $value['options'] ) )
$countries = $value['options'];
else
$countries = SP()->countries->countries;
asort( $countries );
?><tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
<?php echo $tip; ?>
</th>
<td class="forminp">
<select multiple="multiple" name="<?php echo esc_attr( $value['id'] ); ?>[]" style="width:350px" data-placeholder="<?php _e( 'Choose countries&hellip;', 'sportspress' ); ?>" title="Country" class="chosen_select">
<?php
if ( $countries )
foreach ( $countries as $key => $val )
echo '<option value="' . esc_attr( $key ) . '" ' . selected( in_array( $key, $selections ), true, false ).'>' . $val . '</option>';
?>
</select> <?php if ( $description ) echo $description; ?> </br><a class="select_all button" href="#"><?php _e( 'Select all', 'sportspress' ); ?></a> <a class="select_none button" href="#"><?php _e( 'Select none', 'sportspress' ); ?></a>
</td>
</tr><?php
break;
// Default: run an action
default:
do_action( 'sportspress_admin_field_' . $value['type'], $value );
break;
}
}
}
/**
* Save admin fields.
*
* Loops though the sportspress options array and outputs each field.
*
* @access public
* @param array $options Opens array to output
* @return bool
*/
public static function save_fields( $options ) {
if ( empty( $_POST ) )
return false;
// Options to update will be stored here
$update_options = array();
// Loop options and get values to save
foreach ( $options as $value ) {
if ( ! isset( $value['id'] ) )
continue;
$type = isset( $value['type'] ) ? sanitize_title( $value['type'] ) : '';
// Get the option name
$option_value = null;
switch ( $type ) {
// Standard types
case "checkbox" :
if ( isset( $_POST[ $value['id'] ] ) ) {
$option_value = 'yes';
} else {
$option_value = 'no';
}
break;
case "textarea" :
if ( isset( $_POST[$value['id']] ) ) {
$option_value = wp_kses_post( trim( stripslashes( $_POST[ $value['id'] ] ) ) );
} else {
$option_value = '';
}
break;
case "text" :
case 'email':
case 'number':
case "select" :
case "color" :
case 'password' :
case "single_select_page" :
case "single_select_country" :
case 'radio' :
if ( isset( $_POST[$value['id']] ) ) {
$option_value = sanitize_text_field( stripslashes( $_POST[ $value['id'] ] ) );
} else {
$option_value = '';
}
break;
// Special types
case "multiselect" :
case "multi_select_countries" :
// Get countries array
if ( isset( $_POST[ $value['id'] ] ) )
$selected_countries = array_map( 'sanitize_text_field', array_map( 'stripslashes', (array) $_POST[ $value['id'] ] ) );
else
$selected_countries = array();
$option_value = $selected_countries;
break;
// Custom handling
default :
do_action( 'sportspress_update_option_' . $type, $value );
break;
}
if ( ! is_null( $option_value ) ) {
// Check if option is an array
if ( strstr( $value['id'], '[' ) ) {
parse_str( $value['id'], $option_array );
// Option name is first key
$option_name = current( array_keys( $option_array ) );
// Get old option value
if ( ! isset( $update_options[ $option_name ] ) )
$update_options[ $option_name ] = get_option( $option_name, array() );
if ( ! is_array( $update_options[ $option_name ] ) )
$update_options[ $option_name ] = array();
// Set keys and value
$key = key( $option_array[ $option_name ] );
$update_options[ $option_name ][ $key ] = $option_value;
// Single value
} else {
$update_options[ $value['id'] ] = $option_value;
}
}
// Custom handling
do_action( 'sportspress_update_option', $value );
}
// Now save the options
foreach( $update_options as $name => $value )
update_option( $name, $value );
return true;
}
}
endif;

View File

@@ -37,7 +37,7 @@ class SP_Admin {
// Classes we only need if the ajax is not-ajax
if ( ! is_ajax() ) {
// include( 'class-sp-admin-menus.php' );
include( 'class-sp-admin-menus.php' );
// include( 'class-sp-admin-welcome.php' );
// include( 'class-sp-admin-notices.php' );
include( 'class-sp-admin-assets.php' );

View File

@@ -0,0 +1,162 @@
<?php
/**
* SportsPress Account Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Accounts' ) ) :
/**
* SP_Settings_Accounts
*/
class SP_Settings_Accounts extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'account';
$this->label = __( 'Accounts', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
return apply_filters( 'sportspress_' . $this->id . '_settings', array(
array( 'title' => __( 'Account Pages', 'sportspress' ), 'type' => 'title', 'desc' => __( 'These pages need to be set so that SportsPress knows where to send users to access account related functionality.', 'sportspress' ), 'id' => 'account_page_options' ),
array(
'title' => __( 'My Account Page', 'sportspress' ),
'desc' => __( 'Page contents:', 'sportspress' ) . ' [' . apply_filters( 'sportspress_my_account_shortcode_tag', 'sportspress_my_account' ) . ']',
'id' => 'sportspress_myaccount_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'chosen_select_nostd',
'css' => 'min-width:300px;',
'desc_tip' => true,
),
array( 'type' => 'sectionend', 'id' => 'account_page_options' ),
array( 'title' => __( 'My Account Endpoints', 'sportspress' ), 'type' => 'title', 'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions on the accounts pages. They should be unique.', 'sportspress' ), 'id' => 'account_endpoint_options' ),
array(
'title' => __( 'View Order', 'sportspress' ),
'desc' => __( 'Endpoint for the My Account &rarr; View Order page', 'sportspress' ),
'id' => 'sportspress_myaccount_view_order_endpoint',
'type' => 'text',
'default' => 'view-order',
'desc_tip' => true,
),
array(
'title' => __( 'Edit Account', 'sportspress' ),
'desc' => __( 'Endpoint for the My Account &rarr; Edit Account page', 'sportspress' ),
'id' => 'sportspress_myaccount_edit_account_endpoint',
'type' => 'text',
'default' => 'edit-account',
'desc_tip' => true,
),
array(
'title' => __( 'Edit Address', 'sportspress' ),
'desc' => __( 'Endpoint for the My Account &rarr; Edit Address page', 'sportspress' ),
'id' => 'sportspress_myaccount_edit_address_endpoint',
'type' => 'text',
'default' => 'edit-address',
'desc_tip' => true,
),
array(
'title' => __( 'Lost Password', 'sportspress' ),
'desc' => __( 'Endpoint for the My Account &rarr; Lost Password page', 'sportspress' ),
'id' => 'sportspress_myaccount_lost_password_endpoint',
'type' => 'text',
'default' => 'lost-password',
'desc_tip' => true,
),
array(
'title' => __( 'Logout', 'sportspress' ),
'desc' => __( 'Endpoint for the triggering logout. You can add this to your menus via a custom link: yoursite.com/?customer-logout=true', 'sportspress' ),
'id' => 'sportspress_logout_endpoint',
'type' => 'text',
'default' => 'customer-logout',
'desc_tip' => true,
),
array( 'type' => 'sectionend', 'id' => 'account_endpoint_options' ),
array( 'title' => __( 'Registration Options', 'sportspress' ), 'type' => 'title', 'id' => 'account_registration_options' ),
array(
'title' => __( 'Enable Registration', 'sportspress' ),
'desc' => __( 'Enable registration on the "Checkout" page', 'sportspress' ),
'id' => 'sportspress_enable_signup_and_login_from_checkout',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'desc' => __( 'Enable registration on the "My Account" page', 'sportspress' ),
'id' => 'sportspress_enable_myaccount_registration',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false
),
array(
'desc' => __( 'Display returning customer login reminder on the "Checkout" page', 'sportspress' ),
'id' => 'sportspress_enable_checkout_login_reminder',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'title' => __( 'Account Creation', 'sportspress' ),
'desc' => __( 'Automatically generate username from customer email', 'sportspress' ),
'id' => 'sportspress_registration_generate_username',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'desc' => __( 'Automatically generate customer password', 'sportspress' ),
'id' => 'sportspress_registration_generate_password',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false
),
array( 'type' => 'sectionend', 'id' => 'account_registration_options'),
)); // End pages settings
}
}
endif;
return new SP_Settings_Accounts();

View File

@@ -0,0 +1,322 @@
<?php
/**
* SportsPress Shipping Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Payment_Gateways' ) ) :
/**
* SP_Settings_Payment_Gateways
*/
class SP_Settings_Payment_Gateways extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'checkout';
$this->label = _x( 'Checkout', 'Settings tab label', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_sections_' . $this->id, array( $this, 'output_sections' ) );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_admin_field_payment_gateways', array( $this, 'payment_gateways_setting' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get sections
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Checkout Options', 'sportspress' )
);
// Load shipping methods so we can show any global options they may have
$payment_gateways = SP()->payment_gateways->payment_gateways();
foreach ( $payment_gateways as $gateway ) {
$title = empty( $gateway->method_title ) ? ucfirst( $gateway->id ) : $gateway->method_title;
$sections[ strtolower( get_class( $gateway ) ) ] = esc_html( $title );
}
return $sections;
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
return apply_filters( 'sportspress_payment_gateways_settings', array(
array( 'title' => __( 'Checkout Process', 'sportspress' ), 'type' => 'title', 'id' => 'checkout_process_options' ),
array(
'title' => __( 'Coupons', 'sportspress' ),
'desc' => __( 'Enable the use of coupons', 'sportspress' ),
'id' => 'sportspress_enable_coupons',
'default' => 'yes',
'type' => 'checkbox',
'desc_tip' => __( 'Coupons can be applied from the cart and checkout pages.', 'sportspress' ),
'autoload' => false
),
array(
'title' => _x( 'Checkout', 'Settings group label', 'sportspress' ),
'desc' => __( 'Enable guest checkout', 'sportspress' ),
'desc_tip' => __( 'Allows customers to checkout without creating an account.', 'sportspress' ),
'id' => 'sportspress_enable_guest_checkout',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'desc' => __( 'Force secure checkout', 'sportspress' ),
'id' => 'sportspress_force_ssl_checkout',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => '',
'show_if_checked' => 'option',
'desc_tip' => __( 'Force SSL (HTTPS) on the checkout pages (an SSL Certificate is required).', 'sportspress' ),
),
array(
'desc' => __( 'Un-force HTTPS when leaving the checkout', 'sportspress' ),
'id' => 'sportspress_unforce_ssl_checkout',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
),
array( 'type' => 'sectionend', 'id' => 'checkout_process_options'),
array( 'title' => __( 'Checkout Pages', 'sportspress' ), 'desc' => __( 'These pages need to be set so that SportsPress knows where to send users to checkout.', 'sportspress' ), 'type' => 'title', 'id' => 'checkout_page_options' ),
array(
'title' => __( 'Cart Page', 'sportspress' ),
'desc' => __( 'Page contents:', 'sportspress' ) . ' [' . apply_filters( 'sportspress_cart_shortcode_tag', 'sportspress_cart' ) . ']',
'id' => 'sportspress_cart_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'chosen_select_nostd',
'css' => 'min-width:300px;',
'desc_tip' => true,
),
array(
'title' => __( 'Checkout Page', 'sportspress' ),
'desc' => __( 'Page contents:', 'sportspress' ) . ' [' . apply_filters( 'sportspress_checkout_shortcode_tag', 'sportspress_checkout' ) . ']',
'id' => 'sportspress_checkout_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'chosen_select_nostd',
'css' => 'min-width:300px;',
'desc_tip' => true,
),
array(
'title' => __( 'Terms and Conditions', 'sportspress' ),
'desc' => __( 'If you define a "Terms" page the customer will be asked if they accept them when checking out.', 'sportspress' ),
'id' => 'sportspress_terms_page_id',
'default' => '',
'class' => 'chosen_select_nostd',
'css' => 'min-width:300px;',
'type' => 'single_select_page',
'desc_tip' => true,
'autoload' => false
),
array( 'type' => 'sectionend', 'id' => 'checkout_page_options' ),
array( 'title' => __( 'Checkout Endpoints', 'sportspress' ), 'type' => 'title', 'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions during the checkout process. They should be unique.', 'sportspress' ), 'id' => 'account_endpoint_options' ),
array(
'title' => __( 'Pay', 'sportspress' ),
'desc' => __( 'Endpoint for the Checkout &rarr; Pay page', 'sportspress' ),
'id' => 'sportspress_checkout_pay_endpoint',
'type' => 'text',
'default' => 'order-pay',
'desc_tip' => true,
),
array(
'title' => __( 'Order Received', 'sportspress' ),
'desc' => __( 'Endpoint for the Checkout &rarr; Pay page', 'sportspress' ),
'id' => 'sportspress_checkout_order_received_endpoint',
'type' => 'text',
'default' => 'order-received',
'desc_tip' => true,
),
array(
'title' => __( 'Add Payment Method', 'sportspress' ),
'desc' => __( 'Endpoint for the Checkout &rarr; Add Payment Method page', 'sportspress' ),
'id' => 'sportspress_myaccount_add_payment_method_endpoint',
'type' => 'text',
'default' => 'add-payment-method',
'desc_tip' => true,
),
array( 'type' => 'sectionend', 'id' => 'checkout_endpoint_options' ),
array( 'title' => __( 'Payment Gateways', 'sportspress' ), 'desc' => __( 'Installed gateways are listed below. Drag and drop gateways to control their display order on the frontend.', 'sportspress' ), 'type' => 'title', 'id' => 'payment_gateways_options' ),
array( 'type' => 'payment_gateways' ),
array( 'type' => 'sectionend', 'id' => 'payment_gateways_options' ),
)); // End payment_gateway settings
}
/**
* Output the settings
*/
public function output() {
global $current_section;
// Load shipping methods so we can show any global options they may have
$payment_gateways = SP()->payment_gateways->payment_gateways();
if ( $current_section ) {
foreach ( $payment_gateways as $gateway ) {
if ( strtolower( get_class( $gateway ) ) == strtolower( $current_section ) ) {
$gateway->admin_options();
break;
}
}
} else {
$settings = $this->get_settings();
SP_Admin_Settings::output_fields( $settings );
}
}
/**
* Output payment gateway settings.
*
* @access public
* @return void
*/
public function payment_gateways_setting() {
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Gateway Display', 'sportspress' ) ?></th>
<td class="forminp">
<table class="sp_gateways widefat" cellspacing="0">
<thead>
<tr>
<?php
$columns = apply_filters( 'sportspress_payment_gateways_setting_columns', array(
'default' => __( 'Default', 'sportspress' ),
'name' => __( 'Gateway', 'sportspress' ),
'id' => __( 'Gateway ID', 'sportspress' ),
'status' => __( 'Status', 'sportspress' ),
'settings' => ''
) );
foreach ( $columns as $key => $column ) {
echo '<th class="' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>';
}
?>
</tr>
</thead>
<tbody>
<?php
$default_gateway = get_option( 'sportspress_default_gateway' );
foreach ( SP()->payment_gateways->payment_gateways() as $gateway ) {
echo '<tr>';
foreach ( $columns as $key => $column ) {
switch ( $key ) {
case 'default' :
echo '<td width="1%" class="default">
<input type="radio" name="default_gateway" value="' . esc_attr( $gateway->id ) . '" ' . checked( $default_gateway, esc_attr( $gateway->id ), false ) . ' />
<input type="hidden" name="gateway_order[]" value="' . esc_attr( $gateway->id ) . '" />
</td>';
break;
case 'name' :
echo '<td class="name">
' . $gateway->get_title() . '
</td>';
break;
case 'id' :
echo '<td class="id">
' . esc_html( $gateway->id ) . '
</td>';
break;
case 'status' :
echo '<td class="status">';
if ( $gateway->enabled == 'yes' )
echo '<span class="status-enabled tips" data-tip="' . __ ( 'Enabled', 'sportspress' ) . '">' . __ ( 'Enabled', 'sportspress' ) . '</span>';
else
echo '-';
echo '</td>';
break;
case 'settings' :
echo '<td class="settings">
<a class="button" href="' . admin_url( 'admin.php?page=sp-settings&tab=checkout&section=' . strtolower( get_class( $gateway ) ) ) . '">' . __( 'Settings', 'sportspress' ) . '</a>
</td>';
break;
default :
do_action( 'sportspress_payment_gateways_setting_column_' . $key, $gateway );
break;
}
}
echo '</tr>';
}
?>
</tbody>
</table>
</td>
</tr>
<?php
}
/**
* Save settings
*/
public function save() {
global $current_section;
if ( ! $current_section ) {
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
SP()->payment_gateways->process_admin_options();
} elseif ( class_exists( $current_section ) ) {
$current_section_class = new $current_section();
do_action( 'sportspress_update_options_payment_gateways_' . $current_section_class->id );
SP()->payment_gateways()->init();
}
}
}
endif;
return new SP_Settings_Payment_Gateways();

View File

@@ -0,0 +1,378 @@
<?php
/**
* SportsPress Configure Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Config' ) ) :
/**
* SP_Settings_Configure
*/
class SP_Settings_Config extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'config';
$this->label = __( 'Configure', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_admin_field_results', array( $this, 'results_setting' ) );
add_action( 'sportspress_admin_field_outcomes', array( $this, 'outcomes_setting' ) );
add_action( 'sportspress_admin_field_columns', array( $this, 'columns_setting' ) );
add_action( 'sportspress_admin_field_metrics', array( $this, 'metrics_setting' ) );
add_action( 'sportspress_admin_field_performance', array( $this, 'performance_setting' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
return apply_filters('sportspress_event_settings', array(
array( 'title' => __( 'Configure SportsPress', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'config_options' ),
array(
'title' => __( 'Sport', 'sportspress' ),
'id' => 'sportspress_sport',
'default' => 'soccer',
'type' => 'select',
'options' => SP()->sports->options,
),
array( 'type' => 'results' ),
array( 'type' => 'outcomes' ),
array( 'type' => 'columns' ),
array( 'type' => 'metrics' ),
array( 'type' => 'performance' ),
array( 'type' => 'statistics' ),
array( 'type' => 'sectionend', 'id' => 'config_options' ),
)); // End event settings
}
/**
* Output the settings
*/
public function output() {
global $current_section;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
$this->output_tax_rates();
} else {
$settings = $this->get_settings();
SP_Admin_Settings::output_fields( $settings );
}
}
/**
* Save settings
*/
public function save() {
global $current_section, $wpdb;
if ( ! $current_section ) {
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
} else {
$this->save_tax_rates();
}
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_sp_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_sp_tax_rates_%')" );
}
/**
* Output results settings.
*
* @access public
* @return void
*/
public function results_setting() {
$main_result = get_option( 'sportspress_main_result', 0 );
$args = array(
'post_type' => 'sp_result',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Results', 'sportspress' ) ?></th>
<td class="forminp">
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th scope="col"><?php _e( 'Primary', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
</thead>
<tfoot>
<tr>
<th class="radio"><input type="radio" id="sportspress_main_result_0" name="main_result" value="0" <?php checked( $main_result, 0 ); ?>></th>
<th colspan="3"><label for="main_result_0">
<?php
if ( sizeof( $data ) > 0 ):
$default = end( $data );
reset( $data );
printf( __( 'Default (%s)', 'sportspress' ), $default->post_title );
else:
_e( 'Default', 'sportspress' );
endif;
?>
</label></th>
</tr>
</tfoot>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="radio"><input type="radio" id="main_result_<?php echo $row->post_name; ?>" name="main_result" value="<?php echo $row->post_name; ?>" <?php checked( $main_result, $row->post_name ); ?>></td>
<td class="row-title"><label for="sportspress_main_result_<?php echo $row->post_name; ?>"><?php echo $row->post_title; ?></label></td>
<td><?php echo $row->post_name; ?>for / <?php echo $row->post_name; ?>against</td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; ?>
</table>
<div class="tablenav bottom">
<div class="alignleft actions">
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_result' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
</div>
<br class="clear">
</div>
</td>
</tr>
<?php
}
/**
* Output outcomes settings.
*
* @access public
* @return void
*/
public function outcomes_setting() {
$args = array(
'post_type' => 'sp_outcome',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Outcomes', 'sportspress' ) ?></th>
<td class="forminp">
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
</thead>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="row-title"><?php echo $row->post_title; ?></td>
<td><?php echo $row->post_name; ?></td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; ?>
</table>
<div class="tablenav bottom">
<div class="alignleft actions">
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_outcome' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_outcome' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
</div>
<br class="clear">
</div>
</td>
</tr>
<?php
}
/**
* Output columns settings.
*
* @access public
* @return void
*/
public function columns_setting() {
$args = array(
'post_type' => 'sp_column',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Columns', 'sportspress' ) ?></th>
<td class="forminp">
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Equation', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Rounding', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Sort Order', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
</thead>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="row-title"><?php echo $row->post_title; ?></td>
<td><?php echo $row->post_name; ?></td>
<td><?php echo sportspress_get_post_equation( $row->ID, $row->post_name ); ?></td>
<td><?php echo sportspress_get_post_precision( $row->ID ); ?></td>
<td><?php echo sportspress_get_post_order( $row->ID ); ?></td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; ?>
</table>
<div class="tablenav bottom">
<div class="alignleft actions">
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_column' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_column' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
</div>
<br class="clear">
</div>
</fieldset>
</td>
</tr>
<?php
}
/**
* Output metrics settings.
*
* @access public
* @return void
*/
public function metrics_setting() {
$args = array(
'post_type' => 'sp_metric',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Metrics', 'sportspress' ) ?></th>
<td class="forminp">
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Positions', 'sportspress' ); ?></th>
<th scope="col">&nbsp;</th>
<th scope="col" class="edit"></th>
</tr>
</thead>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="row-title"><?php echo $row->post_title; ?></td>
<td><?php echo get_the_terms ( $row->ID, 'sp_position' ) ? the_terms( $row->ID, 'sp_position' ) : '&mdash;'; ?></td>
<td>&nbsp;</td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; ?>
</table>
<div class="tablenav bottom">
<div class="alignleft actions">
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_metric' ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></a>
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_metric' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
</div>
<br class="clear">
</div>
</td>
</tr>
<?php
}
/**
* Output performance settings.
*
* @access public
* @return void
*/
public function performance_setting() {
$args = array(
'post_type' => 'sp_performance',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Performance', 'sportspress' ) ?></th>
<td class="forminp">
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Positions', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Calculate', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
</thead>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="row-title"><?php echo $row->post_title; ?></td>
<td><?php echo get_the_terms ( $row->ID, 'sp_position' ) ? the_terms( $row->ID, 'sp_position' ) : '&mdash;'; ?></td>
<td><?php echo sportspress_get_post_calculate( $row->ID ); ?></td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; ?>
</table>
<div class="tablenav bottom">
<div class="alignleft actions">
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_performance' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_performance' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
</div>
<br class="clear">
</div>
</td>
</tr>
<?php
}
}
endif;
return new SP_Settings_Config();

View File

@@ -0,0 +1,213 @@
<?php
/**
* SportsPress Email Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Emails' ) ) :
/**
* SP_Settings_Emails
*/
class SP_Settings_Emails extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'email';
$this->label = __( 'Emails', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_sections_' . $this->id, array( $this, 'output_sections' ) );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get sections
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Email Options', 'sportspress' )
);
// Define emails that can be customised here
$mailer = SP()->mailer();
$email_templates = $mailer->get_emails();
foreach ( $email_templates as $email ) {
$title = empty( $email->title ) ? ucfirst( $email->id ) : ucfirst( $email->title );
$sections[ strtolower( get_class( $email ) ) ] = esc_html( $title );
}
return $sections;
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
return apply_filters('sportspress_email_settings', array(
array( 'type' => 'sectionend', 'id' => 'email_recipient_options' ),
array( 'title' => __( 'Email Sender Options', 'sportspress' ), 'type' => 'title', 'desc' => __( 'The following options affect the sender (email address and name) used in SportsPress emails.', 'sportspress' ), 'id' => 'email_options' ),
array(
'title' => __( '"From" Name', 'sportspress' ),
'desc' => '',
'id' => 'sportspress_email_from_name',
'type' => 'text',
'css' => 'min-width:300px;',
'default' => esc_attr(get_bloginfo('title')),
'autoload' => false
),
array(
'title' => __( '"From" Email Address', 'sportspress' ),
'desc' => '',
'id' => 'sportspress_email_from_address',
'type' => 'email',
'custom_attributes' => array(
'multiple' => 'multiple'
),
'css' => 'min-width:300px;',
'default' => get_option('admin_email'),
'autoload' => false
),
array( 'type' => 'sectionend', 'id' => 'email_options' ),
array( 'title' => __( 'Email Template', 'sportspress' ), 'type' => 'title', 'desc' => sprintf(__( 'This section lets you customise the SportsPress emails. <a href="%s" target="_blank">Click here to preview your email template</a>. For more advanced control copy <code>sportspress/templates/emails/</code> to <code>yourtheme/sportspress/emails/</code>.', 'sportspress' ), wp_nonce_url(admin_url('?preview_sportspress_mail=true'), 'preview-mail')), 'id' => 'email_template_options' ),
array(
'title' => __( 'Header Image', 'sportspress' ),
'desc' => sprintf(__( 'Enter a URL to an image you want to show in the email\'s header. Upload your image using the <a href="%s">media uploader</a>.', 'sportspress' ), admin_url('media-new.php')),
'id' => 'sportspress_email_header_image',
'type' => 'text',
'css' => 'min-width:300px;',
'default' => '',
'autoload' => false
),
array(
'title' => __( 'Email Footer Text', 'sportspress' ),
'desc' => __( 'The text to appear in the footer of SportsPress emails.', 'sportspress' ),
'id' => 'sportspress_email_footer_text',
'css' => 'width:100%; height: 75px;',
'type' => 'textarea',
'default' => get_bloginfo('title') . ' - ' . __( 'Powered by SportsPress', 'sportspress' ),
'autoload' => false
),
array(
'title' => __( 'Base Colour', 'sportspress' ),
'desc' => __( 'The base colour for SportsPress email templates. Default <code>#557da1</code>.', 'sportspress' ),
'id' => 'sportspress_email_base_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => '#557da1',
'autoload' => false
),
array(
'title' => __( 'Background Colour', 'sportspress' ),
'desc' => __( 'The background colour for SportsPress email templates. Default <code>#f5f5f5</code>.', 'sportspress' ),
'id' => 'sportspress_email_background_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => '#f5f5f5',
'autoload' => false
),
array(
'title' => __( 'Email Body Background Colour', 'sportspress' ),
'desc' => __( 'The main body background colour. Default <code>#fdfdfd</code>.', 'sportspress' ),
'id' => 'sportspress_email_body_background_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => '#fdfdfd',
'autoload' => false
),
array(
'title' => __( 'Email Body Text Colour', 'sportspress' ),
'desc' => __( 'The main body text colour. Default <code>#505050</code>.', 'sportspress' ),
'id' => 'sportspress_email_text_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => '#505050',
'autoload' => false
),
array( 'type' => 'sectionend', 'id' => 'email_template_options' ),
)); // End email settings
}
/**
* Output the settings
*/
public function output() {
global $current_section;
// Define emails that can be customised here
$mailer = SP()->mailer();
$email_templates = $mailer->get_emails();
if ( $current_section ) {
foreach ( $email_templates as $email ) {
if ( strtolower( get_class( $email ) ) == $current_section ) {
$email->admin_options();
break;
}
}
} else {
$settings = $this->get_settings();
SP_Admin_Settings::output_fields( $settings );
}
}
/**
* Save settings
*/
public function save() {
global $current_section;
if ( ! $current_section ) {
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
} else {
// Load mailer
$mailer = SP()->mailer();
if ( class_exists( $current_section ) ) {
$current_section_class = new $current_section();
do_action( 'sportspress_update_options_' . $this->id . '_' . $current_section_class->id );
SP()->mailer()->init();
} else {
do_action( 'sportspress_update_options_' . $this->id . '_' . $current_section );
}
}
}
}
endif;
return new SP_Settings_Emails();

View File

@@ -0,0 +1,708 @@
<?php
/**
* SportsPress Event Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Events' ) ) :
/**
* SP_Settings_Events
*/
class SP_Settings_Events extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'events';
$this->label = __( 'Events', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'sportspress_tax_classes' ) ) ) );
$classes_options = array();
if ( $tax_classes )
foreach ( $tax_classes as $class )
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
return apply_filters('sportspress_event_settings', array(
array( 'title' => __( 'Event Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'tax_options' ),
array(
'title' => __( 'Delimiter', 'sportspress' ),
'id' => 'sportspress_event_teams_delimiter',
'default' => 'vs',
'type' => 'radio',
'options' => array(
'vs' => sprintf( '%s vs %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ),
'v' => sprintf( '%s v %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ),
'&mdash;' => sprintf( '%s &mdash; %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ),
'/' => sprintf( '%s / %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) )
),
),
array(
'title' => __( 'Calculate Tax Based On:', 'sportspress' ),
'id' => 'sportspress_tax_based_on',
'desc_tip' => __( 'This option determines which address is used to calculate tax.', 'sportspress' ),
'default' => 'shipping',
'type' => 'select',
'options' => array(
'shipping' => __( 'Customer shipping address', 'sportspress' ),
'billing' => __( 'Customer billing address', 'sportspress' ),
'base' => __( 'Shop base address', 'sportspress' )
),
),
array(
'title' => __( 'Default Customer Address:', 'sportspress' ),
'id' => 'sportspress_default_customer_address',
'desc_tip' => __( 'This option determines the customers default address (before they input their own).', 'sportspress' ),
'default' => 'base',
'type' => 'select',
'options' => array(
'' => __( 'No address', 'sportspress' ),
'base' => __( 'Shop base address', 'sportspress' ),
),
),
array(
'title' => __( 'Shipping Tax Class:', 'sportspress' ),
'desc' => __( 'Optionally control which tax class shipping gets, or leave it so shipping tax is based on the cart items themselves.', 'sportspress' ),
'id' => 'sportspress_shipping_tax_class',
'css' => 'min-width:150px;',
'default' => 'title',
'type' => 'select',
'options' => array( '' => __( 'Shipping tax class based on cart items', 'sportspress' ), 'standard' => __( 'Standard', 'sportspress' ) ) + $classes_options,
'desc_tip' => true,
),
array(
'title' => __( 'Rounding', 'sportspress' ),
'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'sportspress' ),
'id' => 'sportspress_tax_round_at_subtotal',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Additional Tax Classes', 'sportspress' ),
'desc' => __( 'List additonal tax classes below (1 per line). This is in addition to the default <code>Standard Rate</code>. Tax classes can be assigned to products.', 'sportspress' ),
'id' => 'sportspress_tax_classes',
'css' => 'width:100%; height: 65px;',
'type' => 'textarea',
'default' => sprintf( __( 'Reduced Rate%sZero Rate', 'sportspress' ), PHP_EOL )
),
array(
'title' => __( 'Display prices in the shop:', 'sportspress' ),
'id' => 'sportspress_tax_display_shop',
'default' => 'excl',
'type' => 'select',
'options' => array(
'incl' => __( 'Including tax', 'sportspress' ),
'excl' => __( 'Excluding tax', 'sportspress' ),
)
),
array(
'title' => __( 'Price display suffix:', 'sportspress' ),
'id' => 'sportspress_price_display_suffix',
'default' => '',
'type' => 'text',
'desc' => __( 'Define text to show after your product prices. This could be, for example, "inc. Vat" to explain your pricing. You can also have prices substituted here using one of the following: <code>{price_including_tax}, {price_excluding_tax}</code>.', 'sportspress' ),
),
array(
'title' => __( 'Display prices during cart/checkout:', 'sportspress' ),
'id' => 'sportspress_tax_display_cart',
'default' => 'excl',
'type' => 'select',
'options' => array(
'incl' => __( 'Including tax', 'sportspress' ),
'excl' => __( 'Excluding tax', 'sportspress' ),
),
'autoload' => false
),
array(
'title' => __( 'Display tax totals:', 'sportspress' ),
'id' => 'sportspress_tax_total_display',
'default' => 'itemized',
'type' => 'select',
'options' => array(
'single' => __( 'As a single total', 'sportspress' ),
'itemized' => __( 'Itemized', 'sportspress' ),
),
'autoload' => false
),
array( 'type' => 'results' ),
array( 'type' => 'sectionend', 'id' => 'event_options' ),
)); // End event settings
}
/**
* Output the settings
*/
public function output() {
global $current_section;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
$this->output_tax_rates();
} else {
$settings = $this->get_settings();
SP_Admin_Settings::output_fields( $settings );
}
}
/**
* Save settings
*/
public function save() {
global $current_section, $wpdb;
if ( ! $current_section ) {
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
} else {
$this->save_tax_rates();
}
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_sp_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_sp_tax_rates_%')" );
}
/**
* Output tax rate tables
*/
public function output_tax_rates() {
global $sportspress, $current_section, $wpdb;
$page = ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1;
$limit = 100;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
$current_class = '';
foreach( $tax_classes as $class )
if ( sanitize_title( $class ) == $current_section )
$current_class = $class;
?>
<h3><?php printf( __( 'Tax Rates for the "%s" Class', 'sportspress' ), $current_class ? esc_html( $current_class ) : __( 'Standard', 'sportspress' ) ); ?></h3>
<p><?php printf( __( 'Define tax rates for countries and states below. <a href="%s">See here</a> for available alpha-2 country codes.', 'sportspress' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?></p>
<table class="sp_tax_rates sp_input_table sortable widefat">
<thead>
<tr>
<th class="sort">&nbsp;</th>
<th width="8%"><?php _e( 'Country&nbsp;Code', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('A 2 digit country code, e.g. US. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'State&nbsp;Code', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('A 2 digit state code, e.g. AL. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
<th><?php _e( 'ZIP/Postcode', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Postcode for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all areas. Wildcards (*) can be used. Ranges for numeric postcodes (e.g. 12345-12350) will be expanded into individual postcodes.', 'sportspress'); ?>">[?]</span></th>
<th><?php _e( 'City', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Cities for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all cities.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Rate&nbsp;%', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'Enter a tax rate (percentage) to 4 decimal places.', 'sportspress' ); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Tax&nbsp;Name', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Enter a name for this tax rate.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Priority', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Choose a priority for this tax rate. Only 1 matching rate per priority will be used. To define multiple tax rates for a single area you need to specify a different priority per rate.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Compound', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Choose whether or not this is a compound rate. Compound tax rates are applied on top of other tax rates.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Shipping', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Choose whether or not this tax rate also gets applied to shipping.', 'sportspress'); ?>">[?]</span></th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="10">
<a href="#" class="button plus insert"><?php _e( 'Insert row', 'sportspress' ); ?></a>
<a href="#" class="button minus remove_tax_rates"><?php _e( 'Remove selected row(s)', 'sportspress' ); ?></a>
<div class="pagination">
<?php
echo str_replace( 'page-numbers', 'page-numbers button', paginate_links( array(
'base' => add_query_arg( 'p', '%#%' ),
'type' => 'plain',
'prev_text' => '&laquo;',
'next_text' => '&raquo;',
'total' => ceil( absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(tax_rate_id) FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_class = %s;", sanitize_title( $current_class ) ) ) ) / $limit ),
'current' => $page
) ) );
?>
</div>
<a href="#" download="tax_rates.csv" class="button export"><?php _e( 'Export CSV', 'sportspress' ); ?></a>
<a href="<?php echo admin_url( 'admin.php?import=sportspress_tax_rate_csv' ); ?>" class="button import"><?php _e( 'Import CSV', 'sportspress' ); ?></a>
</th>
</tr>
</tfoot>
<tbody id="rates">
<?php
$rates = $wpdb->get_results( $wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}sportspress_tax_rates
WHERE tax_rate_class = %s
ORDER BY tax_rate_order
LIMIT %d, %d
" ,
sanitize_title( $current_class ),
( $page - 1 ) * $limit,
$limit
) );
foreach ( $rates as $rate ) {
?>
<tr>
<td class="sort"><input type="hidden" class="remove_tax_rate" name="remove_tax_rate[<?php echo $rate->tax_rate_id ?>]" value="0" /></td>
<td class="country" width="8%">
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_country ) ?>" placeholder="*" name="tax_rate_country[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="state" width="8%">
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_state ) ?>" placeholder="*" name="tax_rate_state[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="postcode">
<input type="text" value="<?php
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
echo esc_attr( implode( '; ', $locations ) );
?>" placeholder="*" data-name="tax_rate_postcode[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="city">
<input type="text" value="<?php
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
echo esc_attr( implode( '; ', $locations ) );
?>" placeholder="*" data-name="tax_rate_city[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="rate" width="8%">
<input type="number" step="any" min="0" value="<?php echo esc_attr( $rate->tax_rate ) ?>" placeholder="0" name="tax_rate[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="name" width="8%">
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_name ) ?>" name="tax_rate_name[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="priority" width="8%">
<input type="number" step="1" min="1" value="<?php echo esc_attr( $rate->tax_rate_priority ) ?>" name="tax_rate_priority[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="compound" width="8%">
<input type="checkbox" class="checkbox" name="tax_rate_compound[<?php echo $rate->tax_rate_id ?>]" <?php checked( $rate->tax_rate_compound, '1' ); ?> />
</td>
<td class="apply_to_shipping" width="8%">
<input type="checkbox" class="checkbox" name="tax_rate_shipping[<?php echo $rate->tax_rate_id ?>]" <?php checked($rate->tax_rate_shipping, '1' ); ?> />
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<script type="text/javascript">
jQuery( function() {
jQuery('.sp_tax_rates .remove_tax_rates').click(function() {
var $tbody = jQuery('.sp_tax_rates').find('tbody');
if ( $tbody.find('tr.current').size() > 0 ) {
$current = $tbody.find('tr.current');
$current.find('input').val('');
$current.find('input.remove_tax_rate').val('1');
$current.each(function(){
if ( jQuery(this).is('.new') )
jQuery(this).remove();
else
jQuery(this).hide();
});
} else {
alert('<?php echo esc_js( __( 'No row(s) selected', 'sportspress' ) ); ?>');
}
return false;
});
jQuery('.sp_tax_rates .export').click(function() {
var csv_data = "data:application/csv;charset=utf-8,<?php _e( 'Country Code', 'sportspress' ); ?>,<?php _e( 'State Code', 'sportspress' ); ?>,<?php _e( 'ZIP/Postcode', 'sportspress' ); ?>,<?php _e( 'City', 'sportspress' ); ?>,<?php _e( 'Rate %', 'sportspress' ); ?>,<?php _e( 'Tax Name', 'sportspress' ); ?>,<?php _e( 'Priority', 'sportspress' ); ?>,<?php _e( 'Compound', 'sportspress' ); ?>,<?php _e( 'Shipping', 'sportspress' ); ?>,<?php _e( 'Tax Class', 'sportspress' ); ?>\n";
jQuery('#rates tr:visible').each(function() {
var row = '';
jQuery(this).find('td:not(.sort) input').each(function() {
if ( jQuery(this).is('.checkbox') ) {
if ( jQuery(this).is(':checked') ) {
val = 1;
} else {
val = 0;
}
} else {
var val = jQuery(this).val();
if ( ! val )
val = jQuery(this).attr('placeholder');
}
row = row + val + ',';
});
row = row + '<?php echo $current_class; ?>';
//row.substring( 0, row.length - 1 );
csv_data = csv_data + row + "\n";
});
jQuery(this).attr( 'href', encodeURI( csv_data ) );
return true;
});
jQuery('.sp_tax_rates .insert').click(function() {
var $tbody = jQuery('.sp_tax_rates').find('tbody');
var size = $tbody.find('tr').size();
var code = '<tr class="new">\
<td class="sort">&nbsp;</td>\
<td class="country" width="8%">\
<input type="text" placeholder="*" name="tax_rate_country[new][' + size + ']" />\
</td>\
<td class="state" width="8%">\
<input type="text" placeholder="*" name="tax_rate_state[new][' + size + ']" />\
</td>\
<td class="postcode">\
<input type="text" placeholder="*" name="tax_rate_postcode[new][' + size + ']" />\
</td>\
<td class="city">\
<input type="text" placeholder="*" name="tax_rate_city[new][' + size + ']" />\
</td>\
<td class="rate" width="8%">\
<input type="number" step="any" min="0" placeholder="0" name="tax_rate[new][' + size + ']" />\
</td>\
<td class="name" width="8%">\
<input type="text" name="tax_rate_name[new][' + size + ']" />\
</td>\
<td class="priority" width="8%">\
<input type="number" step="1" min="1" value="1" name="tax_rate_priority[new][' + size + ']" />\
</td>\
<td class="compound" width="8%">\
<input type="checkbox" class="checkbox" name="tax_rate_compound[new][' + size + ']" />\
</td>\
<td class="apply_to_shipping" width="8%">\
<input type="checkbox" class="checkbox" name="tax_rate_shipping[new][' + size + ']" checked="checked" />\
</td>\
</tr>';
if ( $tbody.find('tr.current').size() > 0 ) {
$tbody.find('tr.current').after( code );
} else {
$tbody.append( code );
}
jQuery( "td.country input" ).autocomplete({
source: availableCountries,
minLength: 3
});
jQuery( "td.state input" ).autocomplete({
source: availableStates,
minLength: 3
});
return false;
});
jQuery('.sp_tax_rates td.postcode, .sp_tax_rates td.city').find('input').change(function() {
jQuery(this).attr( 'name', jQuery(this).attr( 'data-name' ) );
});
var availableCountries = [<?php
$countries = array();
foreach ( SP()->countries->get_allowed_countries() as $value => $label )
$countries[] = '{ label: "' . $label . '", value: "' . $value . '" }';
echo implode( ', ', $countries );
?>];
var availableStates = [<?php
$countries = array();
foreach ( SP()->countries->get_allowed_country_states() as $value => $label )
foreach ( $label as $code => $state )
$countries[] = '{ label: "' . $state . '", value: "' . $code . '" }';
echo implode( ', ', $countries );
?>];
jQuery( "td.country input" ).autocomplete({
source: availableCountries,
minLength: 3
});
jQuery( "td.state input" ).autocomplete({
source: availableStates,
minLength: 3
});
});
</script>
<?php
}
/**
* Save tax rates
*/
public function save_tax_rates() {
global $wpdb, $current_section;
// Get class
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
$current_class = '';
foreach( $tax_classes as $class )
if ( sanitize_title( $class ) == $current_section )
$current_class = $class;
// Get POST data
$tax_rate_country = isset( $_POST['tax_rate_country'] ) ? $_POST['tax_rate_country'] : array();
$tax_rate_state = isset( $_POST['tax_rate_state'] ) ? $_POST['tax_rate_state'] : array();
$tax_rate_postcode = isset( $_POST['tax_rate_postcode'] ) ? $_POST['tax_rate_postcode'] : array();
$tax_rate_city = isset( $_POST['tax_rate_city'] ) ? $_POST['tax_rate_city'] : array();
$tax_rate = isset( $_POST['tax_rate'] ) ? $_POST['tax_rate'] : array();
$tax_rate_name = isset( $_POST['tax_rate_name'] ) ? $_POST['tax_rate_name'] : array();
$tax_rate_priority = isset( $_POST['tax_rate_priority'] ) ? $_POST['tax_rate_priority'] : array();
$tax_rate_compound = isset( $_POST['tax_rate_compound'] ) ? $_POST['tax_rate_compound'] : array();
$tax_rate_shipping = isset( $_POST['tax_rate_shipping'] ) ? $_POST['tax_rate_shipping'] : array();
$i = 0;
// Loop posted fields
foreach ( $tax_rate_country as $key => $value ) {
// new keys are inserted...
if ( $key == 'new' ) {
foreach ( $value as $new_key => $new_value ) {
// Sanitize + format
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ][ $new_key ] ) );
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ][ $new_key ] ) );
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ][ $new_key ] );
$city = sanitize_text_field( $tax_rate_city[ $key ][ $new_key ] );
$rate = number_format( sanitize_text_field( $tax_rate[ $key ][ $new_key ] ), 4, '.', '' );
$name = sanitize_text_field( $tax_rate_name[ $key ][ $new_key ] );
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ][ $new_key ] ) );
$compound = isset( $tax_rate_compound[ $key ][ $new_key ] ) ? 1 : 0;
$shipping = isset( $tax_rate_shipping[ $key ][ $new_key ] ) ? 1 : 0;
if ( ! $name )
$name = __( 'Tax', 'sportspress' );
if ( $country == '*' )
$country = '';
if ( $state == '*' )
$state = '';
$wpdb->insert(
$wpdb->prefix . "sportspress_tax_rates",
array(
'tax_rate_country' => $country,
'tax_rate_state' => $state,
'tax_rate' => $rate,
'tax_rate_name' => $name,
'tax_rate_priority' => $priority,
'tax_rate_compound' => $compound,
'tax_rate_shipping' => $shipping,
'tax_rate_order' => $i,
'tax_rate_class' => sanitize_title( $current_class )
)
);
$tax_rate_id = $wpdb->insert_id;
if ( ! empty( $postcode ) ) {
$postcodes = explode( ';', $postcode );
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
$postcode_query = array();
foreach( $postcodes as $postcode )
if ( strstr( $postcode, '-' ) ) {
$postcode_parts = explode( '-', $postcode );
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
if ( ! $i )
continue;
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
}
}
} else {
if ( $postcode )
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
}
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
}
if ( ! empty( $city ) ) {
$cities = explode( ';', $city );
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
foreach( $cities as $city ) {
$wpdb->insert(
$wpdb->prefix . "sportspress_tax_rate_locations",
array(
'location_code' => $city,
'tax_rate_id' => $tax_rate_id,
'location_type' => 'city',
)
);
}
}
$i++;
}
// ...whereas the others are updated
} else {
$tax_rate_id = absint( $key );
if ( $_POST['remove_tax_rate'][ $key ] == 1 ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) );
continue;
}
// Sanitize + format
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ] ) );
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ] ) );
$rate = number_format( (double) sanitize_text_field( $tax_rate[ $key ] ), 4, '.', '' );
$name = sanitize_text_field( $tax_rate_name[ $key ] );
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ] ) );
$compound = isset( $tax_rate_compound[ $key ] ) ? 1 : 0;
$shipping = isset( $tax_rate_shipping[ $key ] ) ? 1 : 0;
if ( ! $name )
$name = __( 'Tax', 'sportspress' );
if ( $country == '*' )
$country = '';
if ( $state == '*' )
$state = '';
$wpdb->update(
$wpdb->prefix . "sportspress_tax_rates",
array(
'tax_rate_country' => $country,
'tax_rate_state' => $state,
'tax_rate' => $rate,
'tax_rate_name' => $name,
'tax_rate_priority' => $priority,
'tax_rate_compound' => $compound,
'tax_rate_shipping' => $shipping,
'tax_rate_order' => $i,
'tax_rate_class' => sanitize_title( $current_class )
),
array(
'tax_rate_id' => $tax_rate_id
)
);
if ( isset( $tax_rate_postcode[ $key ] ) ) {
// Delete old
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'postcode';", $tax_rate_id ) );
// Add changed
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ] );
$postcodes = explode( ';', $postcode );
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
$postcode_query = array();
foreach( $postcodes as $postcode )
if ( strstr( $postcode, '-' ) ) {
$postcode_parts = explode( '-', $postcode );
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
if ( ! $i )
continue;
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
}
}
} else {
if ( $postcode )
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
}
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
}
if ( isset( $tax_rate_city[ $key ] ) ) {
// Delete old
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'city';", $tax_rate_id ) );
// Add changed
$city = sanitize_text_field( $tax_rate_city[ $key ] );
$cities = explode( ';', $city );
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
foreach( $cities as $city ) {
if ( $city ) {
$wpdb->insert(
$wpdb->prefix . "sportspress_tax_rate_locations",
array(
'location_code' => $city,
'tax_rate_id' => $tax_rate_id,
'location_type' => 'city',
)
);
}
}
}
$i++;
}
}
}
}
endif;
return new SP_Settings_Events();

View File

@@ -0,0 +1,69 @@
<?php
/**
* SportsPress General Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_General' ) ) :
/**
* SP_Admin_Settings_General
*/
class SP_Settings_General extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'general';
$this->label = __( 'General', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
return apply_filters( 'sportspress_general_settings', array(
array( 'title' => __( 'General Options', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
array(
'title' => __( 'Tables', 'sportspress' ),
'desc' => __( 'Responsive', 'sportspress' ),
'id' => 'sportspress_tables_responsive',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'desc' => __( 'Sortable', 'sportspress' ),
'id' => 'sportspress_tables_sortable',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'option',
),
array( 'type' => 'sectionend', 'id' => 'general_options' ),
)); // End general settings
}
}
endif;
return new SP_Settings_General();

View File

@@ -0,0 +1,74 @@
<?php
/**
* SportsPress Integration Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Integrations' ) ) :
/**
* SP_Settings_Integrations
*/
class SP_Settings_Integrations extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'integration';
$this->label = __( 'Integration', 'sportspress' );
if ( isset( SP()->integrations ) && SP()->integrations->get_integrations() ) {
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_sections_' . $this->id, array( $this, 'output_sections' ) );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
}
/**
* Get sections
*
* @return array
*/
public function get_sections() {
global $current_section;
$sections = array();
$integrations = SP()->integrations->get_integrations();
if ( ! $current_section )
$current_section = current( $integrations )->id;
foreach ( $integrations as $integration ) {
$title = empty( $integration->method_title ) ? ucfirst( $integration->id ) : $integration->method_title;
$sections[ strtolower( $integration->id ) ] = esc_html( $title );
}
return $sections;
}
/**
* Output the settings
*/
public function output() {
global $current_section;
$integrations = SP()->integrations->get_integrations();
if ( isset( $integrations[ $current_section ] ) )
$integrations[ $current_section ]->admin_options();
}
}
endif;
return new SP_Settings_Integrations();

View File

@@ -0,0 +1,94 @@
<?php
/**
* SportsPress Settings Page/Tab
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Page' ) ) :
/**
* SP_Settings_Page
*/
class SP_Settings_Page {
protected $id = '';
protected $label = '';
/**
* Add this page to settings
*/
public function add_settings_page( $pages ) {
$pages[ $this->id ] = $this->label;
return $pages;
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
return array();
}
/**
* Get sections
*
* @return array
*/
public function get_sections() {
return array();
}
/**
* Output sections
*/
public function output_sections() {
global $current_section;
$sections = $this->get_sections();
if ( empty( $sections ) )
return;
echo '<ul class="subsubsub">';
$array_keys = array_keys( $sections );
foreach ( $sections as $id => $label )
echo '<li><a href="' . admin_url( 'admin.php?page=wc-settings&tab=' . $this->id . '&section=' . sanitize_title( $id ) ) . '" class="' . ( $current_section == $id ? 'current' : '' ) . '">' . $label . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>';
echo '</ul><br class="clear" />';
}
/**
* Output the settings
*/
public function output() {
$settings = $this->get_settings();
SP_Admin_Settings::output_fields( $settings );
}
/**
* Save settings
*/
public function save() {
global $current_section;
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
if ( $current_section )
do_action( 'sportspress_update_options_' . $this->id . '_' . $current_section );
}
}
endif;

View File

@@ -0,0 +1,783 @@
<?php
/**
* SportsPress Player Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Players' ) ) :
/**
* SP_Settings_Players
*/
class SP_Settings_Players extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'players';
$this->label = __( 'Players', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'sportspress_tax_classes' ) ) ) );
$classes_options = array();
if ( $tax_classes )
foreach ( $tax_classes as $class )
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
return apply_filters('sportspress_event_settings', array(
array( 'title' => __( 'Player Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'tax_options' ),
array(
'title' => __( 'Enable Players', 'sportspress' ),
'desc' => __( 'Enable taxes and tax calculations', 'sportspress' ),
'id' => 'sportspress_calc_taxes',
'default' => 'no',
'type' => 'checkbox'
),
array(
'title' => __( 'Prices Entered With Tax', 'sportspress' ),
'id' => 'sportspress_prices_include_tax',
'default' => 'no',
'type' => 'radio',
'options' => array(
'vs' => sprintf( '%s vs %s', __( 'Player', 'sportspress' ), __( 'Player', 'sportspress' ) ),
'v' => sprintf( '%s v %s', __( 'Player', 'sportspress' ), __( 'Player', 'sportspress' ) ),
'&mdash;' => sprintf( '%s &mdash; %s', __( 'Player', 'sportspress' ), __( 'Player', 'sportspress' ) ),
'/' => sprintf( '%s / %s', __( 'Player', 'sportspress' ), __( 'Player', 'sportspress' ) )
),
),
array(
'title' => __( 'Calculate Tax Based On:', 'sportspress' ),
'id' => 'sportspress_tax_based_on',
'desc_tip' => __( 'This option determines which address is used to calculate tax.', 'sportspress' ),
'default' => 'shipping',
'type' => 'select',
'options' => array(
'shipping' => __( 'Customer shipping address', 'sportspress' ),
'billing' => __( 'Customer billing address', 'sportspress' ),
'base' => __( 'Shop base address', 'sportspress' )
),
),
array(
'title' => __( 'Default Customer Address:', 'sportspress' ),
'id' => 'sportspress_default_customer_address',
'desc_tip' => __( 'This option determines the customers default address (before they input their own).', 'sportspress' ),
'default' => 'base',
'type' => 'select',
'options' => array(
'' => __( 'No address', 'sportspress' ),
'base' => __( 'Shop base address', 'sportspress' ),
),
),
array(
'title' => __( 'Shipping Tax Class:', 'sportspress' ),
'desc' => __( 'Optionally control which tax class shipping gets, or leave it so shipping tax is based on the cart items themselves.', 'sportspress' ),
'id' => 'sportspress_shipping_tax_class',
'css' => 'min-width:150px;',
'default' => 'title',
'type' => 'select',
'options' => array( '' => __( 'Shipping tax class based on cart items', 'sportspress' ), 'standard' => __( 'Standard', 'sportspress' ) ) + $classes_options,
'desc_tip' => true,
),
array(
'title' => __( 'Rounding', 'sportspress' ),
'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'sportspress' ),
'id' => 'sportspress_tax_round_at_subtotal',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Additional Tax Classes', 'sportspress' ),
'desc' => __( 'List additonal tax classes below (1 per line). This is in addition to the default <code>Standard Rate</code>. Tax classes can be assigned to products.', 'sportspress' ),
'id' => 'sportspress_tax_classes',
'css' => 'width:100%; height: 65px;',
'type' => 'textarea',
'default' => sprintf( __( 'Reduced Rate%sZero Rate', 'sportspress' ), PHP_EOL )
),
array(
'title' => __( 'Display prices in the shop:', 'sportspress' ),
'id' => 'sportspress_tax_display_shop',
'default' => 'excl',
'type' => 'select',
'options' => array(
'incl' => __( 'Including tax', 'sportspress' ),
'excl' => __( 'Excluding tax', 'sportspress' ),
)
),
array(
'title' => __( 'Price display suffix:', 'sportspress' ),
'id' => 'sportspress_price_display_suffix',
'default' => '',
'type' => 'text',
'desc' => __( 'Define text to show after your product prices. This could be, for example, "inc. Vat" to explain your pricing. You can also have prices substituted here using one of the following: <code>{price_including_tax}, {price_excluding_tax}</code>.', 'sportspress' ),
),
array(
'title' => __( 'Display prices during cart/checkout:', 'sportspress' ),
'id' => 'sportspress_tax_display_cart',
'default' => 'excl',
'type' => 'select',
'options' => array(
'incl' => __( 'Including tax', 'sportspress' ),
'excl' => __( 'Excluding tax', 'sportspress' ),
),
'autoload' => false
),
array(
'title' => __( 'Display tax totals:', 'sportspress' ),
'id' => 'sportspress_tax_total_display',
'default' => 'itemized',
'type' => 'select',
'options' => array(
'single' => __( 'As a single total', 'sportspress' ),
'itemized' => __( 'Itemized', 'sportspress' ),
),
'autoload' => false
),
array( 'type' => 'results' ),
array( 'type' => 'sectionend', 'id' => 'event_options' ),
)); // End event settings
}
/**
* Output the settings
*/
public function output() {
global $current_section;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
$this->output_tax_rates();
} else {
$settings = $this->get_settings();
SP_Admin_Settings::output_fields( $settings );
}
}
/**
* Save settings
*/
public function save() {
global $current_section, $wpdb;
if ( ! $current_section ) {
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
} else {
$this->save_tax_rates();
}
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_sp_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_sp_tax_rates_%')" );
}
/**
* Output tax rate tables
*/
public function output_tax_rates() {
global $sportspress, $current_section, $wpdb;
$page = ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1;
$limit = 100;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
$current_class = '';
foreach( $tax_classes as $class )
if ( sanitize_title( $class ) == $current_section )
$current_class = $class;
?>
<h3><?php printf( __( 'Tax Rates for the "%s" Class', 'sportspress' ), $current_class ? esc_html( $current_class ) : __( 'Standard', 'sportspress' ) ); ?></h3>
<p><?php printf( __( 'Define tax rates for countries and states below. <a href="%s">See here</a> for available alpha-2 country codes.', 'sportspress' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?></p>
<table class="sp_tax_rates sp_input_table sortable widefat">
<thead>
<tr>
<th class="sort">&nbsp;</th>
<th width="8%"><?php _e( 'Country&nbsp;Code', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('A 2 digit country code, e.g. US. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'State&nbsp;Code', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('A 2 digit state code, e.g. AL. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
<th><?php _e( 'ZIP/Postcode', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Postcode for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all areas. Wildcards (*) can be used. Ranges for numeric postcodes (e.g. 12345-12350) will be expanded into individual postcodes.', 'sportspress'); ?>">[?]</span></th>
<th><?php _e( 'City', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Cities for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all cities.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Rate&nbsp;%', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'Enter a tax rate (percentage) to 4 decimal places.', 'sportspress' ); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Tax&nbsp;Name', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Enter a name for this tax rate.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Priority', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Choose a priority for this tax rate. Only 1 matching rate per priority will be used. To define multiple tax rates for a single area you need to specify a different priority per rate.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Compound', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Choose whether or not this is a compound rate. Compound tax rates are applied on top of other tax rates.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Shipping', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Choose whether or not this tax rate also gets applied to shipping.', 'sportspress'); ?>">[?]</span></th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="10">
<a href="#" class="button plus insert"><?php _e( 'Insert row', 'sportspress' ); ?></a>
<a href="#" class="button minus remove_tax_rates"><?php _e( 'Remove selected row(s)', 'sportspress' ); ?></a>
<div class="pagination">
<?php
echo str_replace( 'page-numbers', 'page-numbers button', paginate_links( array(
'base' => add_query_arg( 'p', '%#%' ),
'type' => 'plain',
'prev_text' => '&laquo;',
'next_text' => '&raquo;',
'total' => ceil( absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(tax_rate_id) FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_class = %s;", sanitize_title( $current_class ) ) ) ) / $limit ),
'current' => $page
) ) );
?>
</div>
<a href="#" download="tax_rates.csv" class="button export"><?php _e( 'Export CSV', 'sportspress' ); ?></a>
<a href="<?php echo admin_url( 'admin.php?import=sportspress_tax_rate_csv' ); ?>" class="button import"><?php _e( 'Import CSV', 'sportspress' ); ?></a>
</th>
</tr>
</tfoot>
<tbody id="rates">
<?php
$rates = $wpdb->get_results( $wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}sportspress_tax_rates
WHERE tax_rate_class = %s
ORDER BY tax_rate_order
LIMIT %d, %d
" ,
sanitize_title( $current_class ),
( $page - 1 ) * $limit,
$limit
) );
foreach ( $rates as $rate ) {
?>
<tr>
<td class="sort"><input type="hidden" class="remove_tax_rate" name="remove_tax_rate[<?php echo $rate->tax_rate_id ?>]" value="0" /></td>
<td class="country" width="8%">
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_country ) ?>" placeholder="*" name="tax_rate_country[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="state" width="8%">
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_state ) ?>" placeholder="*" name="tax_rate_state[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="postcode">
<input type="text" value="<?php
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
echo esc_attr( implode( '; ', $locations ) );
?>" placeholder="*" data-name="tax_rate_postcode[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="city">
<input type="text" value="<?php
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
echo esc_attr( implode( '; ', $locations ) );
?>" placeholder="*" data-name="tax_rate_city[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="rate" width="8%">
<input type="number" step="any" min="0" value="<?php echo esc_attr( $rate->tax_rate ) ?>" placeholder="0" name="tax_rate[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="name" width="8%">
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_name ) ?>" name="tax_rate_name[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="priority" width="8%">
<input type="number" step="1" min="1" value="<?php echo esc_attr( $rate->tax_rate_priority ) ?>" name="tax_rate_priority[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="compound" width="8%">
<input type="checkbox" class="checkbox" name="tax_rate_compound[<?php echo $rate->tax_rate_id ?>]" <?php checked( $rate->tax_rate_compound, '1' ); ?> />
</td>
<td class="apply_to_shipping" width="8%">
<input type="checkbox" class="checkbox" name="tax_rate_shipping[<?php echo $rate->tax_rate_id ?>]" <?php checked($rate->tax_rate_shipping, '1' ); ?> />
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<script type="text/javascript">
jQuery( function() {
jQuery('.sp_tax_rates .remove_tax_rates').click(function() {
var $tbody = jQuery('.sp_tax_rates').find('tbody');
if ( $tbody.find('tr.current').size() > 0 ) {
$current = $tbody.find('tr.current');
$current.find('input').val('');
$current.find('input.remove_tax_rate').val('1');
$current.each(function(){
if ( jQuery(this).is('.new') )
jQuery(this).remove();
else
jQuery(this).hide();
});
} else {
alert('<?php echo esc_js( __( 'No row(s) selected', 'sportspress' ) ); ?>');
}
return false;
});
jQuery('.sp_tax_rates .export').click(function() {
var csv_data = "data:application/csv;charset=utf-8,<?php _e( 'Country Code', 'sportspress' ); ?>,<?php _e( 'State Code', 'sportspress' ); ?>,<?php _e( 'ZIP/Postcode', 'sportspress' ); ?>,<?php _e( 'City', 'sportspress' ); ?>,<?php _e( 'Rate %', 'sportspress' ); ?>,<?php _e( 'Tax Name', 'sportspress' ); ?>,<?php _e( 'Priority', 'sportspress' ); ?>,<?php _e( 'Compound', 'sportspress' ); ?>,<?php _e( 'Shipping', 'sportspress' ); ?>,<?php _e( 'Tax Class', 'sportspress' ); ?>\n";
jQuery('#rates tr:visible').each(function() {
var row = '';
jQuery(this).find('td:not(.sort) input').each(function() {
if ( jQuery(this).is('.checkbox') ) {
if ( jQuery(this).is(':checked') ) {
val = 1;
} else {
val = 0;
}
} else {
var val = jQuery(this).val();
if ( ! val )
val = jQuery(this).attr('placeholder');
}
row = row + val + ',';
});
row = row + '<?php echo $current_class; ?>';
//row.substring( 0, row.length - 1 );
csv_data = csv_data + row + "\n";
});
jQuery(this).attr( 'href', encodeURI( csv_data ) );
return true;
});
jQuery('.sp_tax_rates .insert').click(function() {
var $tbody = jQuery('.sp_tax_rates').find('tbody');
var size = $tbody.find('tr').size();
var code = '<tr class="new">\
<td class="sort">&nbsp;</td>\
<td class="country" width="8%">\
<input type="text" placeholder="*" name="tax_rate_country[new][' + size + ']" />\
</td>\
<td class="state" width="8%">\
<input type="text" placeholder="*" name="tax_rate_state[new][' + size + ']" />\
</td>\
<td class="postcode">\
<input type="text" placeholder="*" name="tax_rate_postcode[new][' + size + ']" />\
</td>\
<td class="city">\
<input type="text" placeholder="*" name="tax_rate_city[new][' + size + ']" />\
</td>\
<td class="rate" width="8%">\
<input type="number" step="any" min="0" placeholder="0" name="tax_rate[new][' + size + ']" />\
</td>\
<td class="name" width="8%">\
<input type="text" name="tax_rate_name[new][' + size + ']" />\
</td>\
<td class="priority" width="8%">\
<input type="number" step="1" min="1" value="1" name="tax_rate_priority[new][' + size + ']" />\
</td>\
<td class="compound" width="8%">\
<input type="checkbox" class="checkbox" name="tax_rate_compound[new][' + size + ']" />\
</td>\
<td class="apply_to_shipping" width="8%">\
<input type="checkbox" class="checkbox" name="tax_rate_shipping[new][' + size + ']" checked="checked" />\
</td>\
</tr>';
if ( $tbody.find('tr.current').size() > 0 ) {
$tbody.find('tr.current').after( code );
} else {
$tbody.append( code );
}
jQuery( "td.country input" ).autocomplete({
source: availableCountries,
minLength: 3
});
jQuery( "td.state input" ).autocomplete({
source: availableStates,
minLength: 3
});
return false;
});
jQuery('.sp_tax_rates td.postcode, .sp_tax_rates td.city').find('input').change(function() {
jQuery(this).attr( 'name', jQuery(this).attr( 'data-name' ) );
});
var availableCountries = [<?php
$countries = array();
foreach ( SP()->countries->get_allowed_countries() as $value => $label )
$countries[] = '{ label: "' . $label . '", value: "' . $value . '" }';
echo implode( ', ', $countries );
?>];
var availableStates = [<?php
$countries = array();
foreach ( SP()->countries->get_allowed_country_states() as $value => $label )
foreach ( $label as $code => $state )
$countries[] = '{ label: "' . $state . '", value: "' . $code . '" }';
echo implode( ', ', $countries );
?>];
jQuery( "td.country input" ).autocomplete({
source: availableCountries,
minLength: 3
});
jQuery( "td.state input" ).autocomplete({
source: availableStates,
minLength: 3
});
});
</script>
<?php
}
/**
* Save tax rates
*/
public function save_tax_rates() {
global $wpdb, $current_section;
// Get class
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
$current_class = '';
foreach( $tax_classes as $class )
if ( sanitize_title( $class ) == $current_section )
$current_class = $class;
// Get POST data
$tax_rate_country = isset( $_POST['tax_rate_country'] ) ? $_POST['tax_rate_country'] : array();
$tax_rate_state = isset( $_POST['tax_rate_state'] ) ? $_POST['tax_rate_state'] : array();
$tax_rate_postcode = isset( $_POST['tax_rate_postcode'] ) ? $_POST['tax_rate_postcode'] : array();
$tax_rate_city = isset( $_POST['tax_rate_city'] ) ? $_POST['tax_rate_city'] : array();
$tax_rate = isset( $_POST['tax_rate'] ) ? $_POST['tax_rate'] : array();
$tax_rate_name = isset( $_POST['tax_rate_name'] ) ? $_POST['tax_rate_name'] : array();
$tax_rate_priority = isset( $_POST['tax_rate_priority'] ) ? $_POST['tax_rate_priority'] : array();
$tax_rate_compound = isset( $_POST['tax_rate_compound'] ) ? $_POST['tax_rate_compound'] : array();
$tax_rate_shipping = isset( $_POST['tax_rate_shipping'] ) ? $_POST['tax_rate_shipping'] : array();
$i = 0;
// Loop posted fields
foreach ( $tax_rate_country as $key => $value ) {
// new keys are inserted...
if ( $key == 'new' ) {
foreach ( $value as $new_key => $new_value ) {
// Sanitize + format
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ][ $new_key ] ) );
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ][ $new_key ] ) );
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ][ $new_key ] );
$city = sanitize_text_field( $tax_rate_city[ $key ][ $new_key ] );
$rate = number_format( sanitize_text_field( $tax_rate[ $key ][ $new_key ] ), 4, '.', '' );
$name = sanitize_text_field( $tax_rate_name[ $key ][ $new_key ] );
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ][ $new_key ] ) );
$compound = isset( $tax_rate_compound[ $key ][ $new_key ] ) ? 1 : 0;
$shipping = isset( $tax_rate_shipping[ $key ][ $new_key ] ) ? 1 : 0;
if ( ! $name )
$name = __( 'Tax', 'sportspress' );
if ( $country == '*' )
$country = '';
if ( $state == '*' )
$state = '';
$wpdb->insert(
$wpdb->prefix . "sportspress_tax_rates",
array(
'tax_rate_country' => $country,
'tax_rate_state' => $state,
'tax_rate' => $rate,
'tax_rate_name' => $name,
'tax_rate_priority' => $priority,
'tax_rate_compound' => $compound,
'tax_rate_shipping' => $shipping,
'tax_rate_order' => $i,
'tax_rate_class' => sanitize_title( $current_class )
)
);
$tax_rate_id = $wpdb->insert_id;
if ( ! empty( $postcode ) ) {
$postcodes = explode( ';', $postcode );
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
$postcode_query = array();
foreach( $postcodes as $postcode )
if ( strstr( $postcode, '-' ) ) {
$postcode_parts = explode( '-', $postcode );
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
if ( ! $i )
continue;
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
}
}
} else {
if ( $postcode )
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
}
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
}
if ( ! empty( $city ) ) {
$cities = explode( ';', $city );
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
foreach( $cities as $city ) {
$wpdb->insert(
$wpdb->prefix . "sportspress_tax_rate_locations",
array(
'location_code' => $city,
'tax_rate_id' => $tax_rate_id,
'location_type' => 'city',
)
);
}
}
$i++;
}
// ...whereas the others are updated
} else {
$tax_rate_id = absint( $key );
if ( $_POST['remove_tax_rate'][ $key ] == 1 ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) );
continue;
}
// Sanitize + format
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ] ) );
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ] ) );
$rate = number_format( (double) sanitize_text_field( $tax_rate[ $key ] ), 4, '.', '' );
$name = sanitize_text_field( $tax_rate_name[ $key ] );
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ] ) );
$compound = isset( $tax_rate_compound[ $key ] ) ? 1 : 0;
$shipping = isset( $tax_rate_shipping[ $key ] ) ? 1 : 0;
if ( ! $name )
$name = __( 'Tax', 'sportspress' );
if ( $country == '*' )
$country = '';
if ( $state == '*' )
$state = '';
$wpdb->update(
$wpdb->prefix . "sportspress_tax_rates",
array(
'tax_rate_country' => $country,
'tax_rate_state' => $state,
'tax_rate' => $rate,
'tax_rate_name' => $name,
'tax_rate_priority' => $priority,
'tax_rate_compound' => $compound,
'tax_rate_shipping' => $shipping,
'tax_rate_order' => $i,
'tax_rate_class' => sanitize_title( $current_class )
),
array(
'tax_rate_id' => $tax_rate_id
)
);
if ( isset( $tax_rate_postcode[ $key ] ) ) {
// Delete old
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'postcode';", $tax_rate_id ) );
// Add changed
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ] );
$postcodes = explode( ';', $postcode );
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
$postcode_query = array();
foreach( $postcodes as $postcode )
if ( strstr( $postcode, '-' ) ) {
$postcode_parts = explode( '-', $postcode );
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
if ( ! $i )
continue;
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
}
}
} else {
if ( $postcode )
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
}
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
}
if ( isset( $tax_rate_city[ $key ] ) ) {
// Delete old
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'city';", $tax_rate_id ) );
// Add changed
$city = sanitize_text_field( $tax_rate_city[ $key ] );
$cities = explode( ';', $city );
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
foreach( $cities as $city ) {
if ( $city ) {
$wpdb->insert(
$wpdb->prefix . "sportspress_tax_rate_locations",
array(
'location_code' => $city,
'tax_rate_id' => $tax_rate_id,
'location_type' => 'city',
)
);
}
}
}
$i++;
}
}
}
/**
* Output results settings.
*
* @access public
* @return void
*/
public function results_setting() {
$main_result = get_option( 'sportspress_main_result', 0 );
$args = array(
'post_type' => 'sp_result',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Results', 'sportspress' ) ?></th>
<td class="forminp">
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th scope="col"><?php _e( 'Primary', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
<th class="edit"></th>
</tr>
</thead>
<tfoot>
<tr>
<th class="radio"><input type="radio" id="sportspress_main_result_0" name="main_result" value="0" <?php checked( $main_result, 0 ); ?>></th>
<th colspan="3"><label for="main_result_0">
<?php
if ( sizeof( $data ) > 0 ):
$default = end( $data );
reset( $data );
printf( __( 'Default (%s)', 'sportspress' ), $default->post_title );
else:
_e( 'Default', 'sportspress' );
endif;
?>
</label></th>
</tr>
</tfoot>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="radio"><input type="radio" id="main_result_<?php echo $row->post_name; ?>" name="main_result" value="<?php echo $row->post_name; ?>" <?php checked( $main_result, $row->post_name ); ?>></td>
<td class="row-title"><label for="sportspress_main_result_<?php echo $row->post_name; ?>"><?php echo $row->post_title; ?></label></td>
<td><?php echo $row->post_name; ?>for / <?php echo $row->post_name; ?>against</td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; ?>
</table>
<div class="tablenav bottom">
<div class="alignleft actions">
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_result' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
</div>
<br class="clear">
</div>
</td>
</tr>
<?php
}
}
endif;
return new SP_Settings_Players();

View File

@@ -0,0 +1,458 @@
<?php
/**
* SportsPress Product Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Products' ) ) :
/**
* SP_Settings_Products
*/
class SP_Settings_Products extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'products';
$this->label = __( 'Products', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
add_action( 'sportspress_sections_' . $this->id, array( $this, 'output_sections' ) );
}
/**
* Get sections
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Product Options', 'sportspress' ),
'inventory' => __( 'Inventory', 'sportspress' )
);
return $sections;
}
/**
* Output the settings
*/
public function output() {
global $current_section;
$settings = $this->get_settings( $current_section );
SP_Admin_Settings::output_fields( $settings );
}
/**
* Save settings
*/
public function save() {
global $current_section;
$settings = $this->get_settings( $current_section );
SP_Admin_Settings::save_fields( $settings );
}
/**
* Get settings array
*
* @return array
*/
public function get_settings( $current_section = '' ) {
if ( $current_section == 'inventory' ) {
return apply_filters('sportspress_inventory_settings', array(
array( 'title' => __( 'Inventory Options', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'inventory_options' ),
array(
'title' => __( 'Manage Stock', 'sportspress' ),
'desc' => __( 'Enable stock management', 'sportspress' ),
'id' => 'sportspress_manage_stock',
'default' => 'yes',
'type' => 'checkbox'
),
array(
'title' => __( 'Hold Stock (minutes)', 'sportspress' ),
'desc' => __( 'Hold stock (for unpaid orders) for x minutes. When this limit is reached, the pending order will be cancelled. Leave blank to disable.', 'sportspress' ),
'id' => 'sportspress_hold_stock_minutes',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1
),
'css' => 'width:50px;',
'default' => '60',
'autoload' => false
),
array(
'title' => __( 'Notifications', 'sportspress' ),
'desc' => __( 'Enable low stock notifications', 'sportspress' ),
'id' => 'sportspress_notify_low_stock',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'desc' => __( 'Enable out of stock notifications', 'sportspress' ),
'id' => 'sportspress_notify_no_stock',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false
),
array(
'title' => __( 'Notification Recipient', 'sportspress' ),
'desc' => '',
'id' => 'sportspress_stock_email_recipient',
'type' => 'email',
'default' => get_option( 'admin_email' ),
'autoload' => false
),
array(
'title' => __( 'Low Stock Threshold', 'sportspress' ),
'desc' => '',
'id' => 'sportspress_notify_low_stock_amount',
'css' => 'width:50px;',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1
),
'default' => '2',
'autoload' => false
),
array(
'title' => __( 'Out Of Stock Threshold', 'sportspress' ),
'desc' => '',
'id' => 'sportspress_notify_no_stock_amount',
'css' => 'width:50px;',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1
),
'default' => '0',
'autoload' => false
),
array(
'title' => __( 'Out Of Stock Visibility', 'sportspress' ),
'desc' => __( 'Hide out of stock items from the catalog', 'sportspress' ),
'id' => 'sportspress_hide_out_of_stock_items',
'default' => 'no',
'type' => 'checkbox'
),
array(
'title' => __( 'Stock Display Format', 'sportspress' ),
'desc' => __( 'This controls how stock is displayed on the frontend.', 'sportspress' ),
'id' => 'sportspress_stock_format',
'css' => 'min-width:150px;',
'default' => '',
'type' => 'select',
'options' => array(
'' => __( 'Always show stock e.g. "12 in stock"', 'sportspress' ),
'low_amount' => __( 'Only show stock when low e.g. "Only 2 left in stock" vs. "In Stock"', 'sportspress' ),
'no_amount' => __( 'Never show stock amount', 'sportspress' ),
),
'desc_tip' => true,
),
array( 'type' => 'sectionend', 'id' => 'inventory_options'),
));
} else {
// Get shop page
$shop_page_id = sp_get_page_id('shop');
$base_slug = ($shop_page_id > 0 && get_page( $shop_page_id )) ? get_page_uri( $shop_page_id ) : 'shop';
$sportspress_prepend_shop_page_to_products_warning = '';
if ( $shop_page_id > 0 && sizeof(get_pages("child_of=$shop_page_id")) > 0 )
$sportspress_prepend_shop_page_to_products_warning = ' <mark class="notice">' . __( 'Note: The shop page has children - child pages will not work if you enable this option.', 'sportspress' ) . '</mark>';
return apply_filters( 'sportspress_product_settings', array(
array( 'title' => __( 'Product Listings', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'catalog_options' ),
array(
'title' => __( 'Product Archive / Shop Page', 'sportspress' ),
'desc' => '<br/>' . sprintf( __( 'The base page can also be used in your <a href="%s">product permalinks</a>.', 'sportspress' ), admin_url( 'options-permalink.php' ) ),
'id' => 'sportspress_shop_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'chosen_select_nostd',
'css' => 'min-width:300px;',
'desc_tip' => __( 'This sets the base page of your shop - this is where your product archive will be.', 'sportspress' ),
),
array(
'title' => __( 'Shop Page Display', 'sportspress' ),
'desc' => __( 'This controls what is shown on the product archive.', 'sportspress' ),
'id' => 'sportspress_shop_page_display',
'class' => 'chosen_select',
'css' => 'min-width:300px;',
'default' => '',
'type' => 'select',
'options' => array(
'' => __( 'Show products', 'sportspress' ),
'subcategories' => __( 'Show subcategories', 'sportspress' ),
'both' => __( 'Show both', 'sportspress' ),
),
'desc_tip' => true,
),
array(
'title' => __( 'Default Category Display', 'sportspress' ),
'desc' => __( 'This controls what is shown on category archives.', 'sportspress' ),
'id' => 'sportspress_category_archive_display',
'class' => 'chosen_select',
'css' => 'min-width:300px;',
'default' => '',
'type' => 'select',
'options' => array(
'' => __( 'Show products', 'sportspress' ),
'subcategories' => __( 'Show subcategories', 'sportspress' ),
'both' => __( 'Show both', 'sportspress' ),
),
'desc_tip' => true,
),
array(
'title' => __( 'Default Product Sorting', 'sportspress' ),
'desc' => __( 'This controls the default sort order of the catalog.', 'sportspress' ),
'id' => 'sportspress_default_catalog_orderby',
'class' => 'chosen_select',
'css' => 'min-width:300px;',
'default' => 'title',
'type' => 'select',
'options' => apply_filters('sportspress_default_catalog_orderby_options', array(
'menu_order' => __( 'Default sorting (custom ordering + name)', 'sportspress' ),
'popularity' => __( 'Popularity (sales)', 'sportspress' ),
'rating' => __( 'Average Rating', 'sportspress' ),
'date' => __( 'Sort by most recent', 'sportspress' ),
'price' => __( 'Sort by price (asc)', 'sportspress' ),
'price-desc' => __( 'Sort by price (desc)', 'sportspress' ),
)),
'desc_tip' => true,
),
array(
'title' => __( 'Add to cart', 'sportspress' ),
'desc' => __( 'Redirect to the cart page after successful addition', 'sportspress' ),
'id' => 'sportspress_cart_redirect_after_add',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start'
),
array(
'desc' => __( 'Enable AJAX add to cart buttons on archives', 'sportspress' ),
'id' => 'sportspress_enable_ajax_add_to_cart',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end'
),
array( 'type' => 'sectionend', 'id' => 'catalog_options' ),
array( 'title' => __( 'Product Data', 'sportspress' ), 'type' => 'title', 'id' => 'product_data_options' ),
array(
'title' => __( 'Weight Unit', 'sportspress' ),
'desc' => __( 'This controls what unit you will define weights in.', 'sportspress' ),
'id' => 'sportspress_weight_unit',
'class' => 'chosen_select',
'css' => 'min-width:300px;',
'default' => 'kg',
'type' => 'select',
'options' => array(
'kg' => __( 'kg', 'sportspress' ),
'g' => __( 'g', 'sportspress' ),
'lbs' => __( 'lbs', 'sportspress' ),
'oz' => __( 'oz', 'sportspress' ),
),
'desc_tip' => true,
),
array(
'title' => __( 'Dimensions Unit', 'sportspress' ),
'desc' => __( 'This controls what unit you will define lengths in.', 'sportspress' ),
'id' => 'sportspress_dimension_unit',
'class' => 'chosen_select',
'css' => 'min-width:300px;',
'default' => 'cm',
'type' => 'select',
'options' => array(
'm' => __( 'm', 'sportspress' ),
'cm' => __( 'cm', 'sportspress' ),
'mm' => __( 'mm', 'sportspress' ),
'in' => __( 'in', 'sportspress' ),
'yd' => __( 'yd', 'sportspress' ),
),
'desc_tip' => true,
),
array(
'title' => __( 'Product Ratings', 'sportspress' ),
'desc' => __( 'Enable ratings on reviews', 'sportspress' ),
'id' => 'sportspress_enable_review_rating',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'show_if_checked' => 'option',
'autoload' => false
),
array(
'desc' => __( 'Ratings are required to leave a review', 'sportspress' ),
'id' => 'sportspress_review_rating_required',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
'show_if_checked' => 'yes',
'autoload' => false
),
array(
'desc' => __( 'Show "verified owner" label for customer reviews', 'sportspress' ),
'id' => 'sportspress_review_rating_verification_label',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
'show_if_checked' => 'yes',
'autoload' => false
),
array(
'desc' => __( 'Only allow reviews from "verified owners"', 'sportspress' ),
'id' => 'sportspress_review_rating_verification_required',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
'autoload' => false
),
array( 'type' => 'sectionend', 'id' => 'product_data_options' ),
array( 'title' => __( 'Product Image Sizes', 'sportspress' ), 'type' => 'title','desc' => sprintf(__( 'These settings affect the actual dimensions of images in your catalog - the display on the front-end will still be affected by CSS styles. After changing these settings you may need to <a href="%s">regenerate your thumbnails</a>.', 'sportspress' ), 'http://wordpress.org/extend/plugins/regenerate-thumbnails/'), 'id' => 'image_options' ),
array(
'title' => __( 'Catalog Images', 'sportspress' ),
'desc' => __( 'This size is usually used in product listings', 'sportspress' ),
'id' => 'shop_catalog_image_size',
'css' => '',
'type' => 'image_width',
'default' => array(
'width' => '150',
'height' => '150',
'crop' => true
),
'desc_tip' => true,
),
array(
'title' => __( 'Single Product Image', 'sportspress' ),
'desc' => __( 'This is the size used by the main image on the product page.', 'sportspress' ),
'id' => 'shop_single_image_size',
'css' => '',
'type' => 'image_width',
'default' => array(
'width' => '300',
'height' => '300',
'crop' => 1
),
'desc_tip' => true,
),
array(
'title' => __( 'Product Thumbnails', 'sportspress' ),
'desc' => __( 'This size is usually used for the gallery of images on the product page.', 'sportspress' ),
'id' => 'shop_thumbnail_image_size',
'css' => '',
'type' => 'image_width',
'default' => array(
'width' => '90',
'height' => '90',
'crop' => 1
),
'desc_tip' => true,
),
array( 'type' => 'sectionend', 'id' => 'image_options' ),
array( 'title' => __( 'Downloadable Products', 'sportspress' ), 'type' => 'title', 'id' => 'digital_download_options' ),
array(
'title' => __( 'File Download Method', 'sportspress' ),
'desc' => __( 'Forcing downloads will keep URLs hidden, but some servers may serve large files unreliably. If supported, <code>X-Accel-Redirect</code>/ <code>X-Sendfile</code> can be used to serve downloads instead (server requires <code>mod_xsendfile</code>).', 'sportspress' ),
'id' => 'sportspress_file_download_method',
'type' => 'select',
'class' => 'chosen_select',
'css' => 'min-width:300px;',
'default' => 'force',
'desc_tip' => true,
'options' => array(
'force' => __( 'Force Downloads', 'sportspress' ),
'xsendfile' => __( 'X-Accel-Redirect/X-Sendfile', 'sportspress' ),
'redirect' => __( 'Redirect only', 'sportspress' ),
),
'autoload' => false
),
array(
'title' => __( 'Access Restriction', 'sportspress' ),
'desc' => __( 'Downloads require login', 'sportspress' ),
'id' => 'sportspress_downloads_require_login',
'type' => 'checkbox',
'default' => 'no',
'desc_tip' => __( 'This setting does not apply to guest purchases.', 'sportspress' ),
'checkboxgroup' => 'start',
'autoload' => false
),
array(
'desc' => __( 'Grant access to downloadable products after payment', 'sportspress' ),
'id' => 'sportspress_downloads_grant_access_after_payment',
'type' => 'checkbox',
'default' => 'yes',
'desc_tip' => __( 'Enable this option to grant access to downloads when orders are "processing", rather than "completed".', 'sportspress' ),
'checkboxgroup' => 'end',
'autoload' => false
),
array( 'type' => 'sectionend', 'id' => 'digital_download_options' ),
));
}
}
}
endif;
return new SP_Settings_Products();

View File

@@ -0,0 +1,281 @@
<?php
/**
* SportsPress Shipping Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Shipping' ) ) :
/**
* SP_Settings_Shipping
*/
class SP_Settings_Shipping extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'shipping';
$this->label = __( 'Shipping', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_sections_' . $this->id, array( $this, 'output_sections' ) );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_admin_field_shipping_methods', array( $this, 'shipping_methods_setting' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get sections
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Shipping Options', 'sportspress' )
);
// Load shipping methods so we can show any global options they may have
$shipping_methods = SP()->shipping->load_shipping_methods();
foreach ( $shipping_methods as $method ) {
if ( ! $method->has_settings() ) continue;
$title = empty( $method->method_title ) ? ucfirst( $method->id ) : $method->method_title;
$sections[ strtolower( get_class( $method ) ) ] = esc_html( $title );
}
return $sections;
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
return apply_filters('sportspress_shipping_settings', array(
array( 'title' => __( 'Shipping Options', 'sportspress' ), 'type' => 'title', 'id' => 'shipping_options' ),
array(
'title' => __( 'Shipping Calculations', 'sportspress' ),
'desc' => __( 'Enable shipping', 'sportspress' ),
'id' => 'sportspress_calc_shipping',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start'
),
array(
'desc' => __( 'Enable the shipping calculator on the cart page', 'sportspress' ),
'id' => 'sportspress_enable_shipping_calc',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
'autoload' => false
),
array(
'desc' => __( 'Hide shipping costs until an address is entered', 'sportspress' ),
'id' => 'sportspress_shipping_cost_requires_address',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false
),
array(
'title' => __( 'Shipping Display Mode', 'sportspress' ),
'desc' => __( 'This controls how multiple shipping methods are displayed on the frontend.', 'sportspress' ),
'id' => 'sportspress_shipping_method_format',
'default' => '',
'type' => 'radio',
'options' => array(
'' => __( 'Display shipping methods with "radio" buttons', 'sportspress' ),
'select' => __( 'Display shipping methods in a dropdown', 'sportspress' ),
),
'desc_tip' => true,
'autoload' => false
),
array(
'title' => __( 'Shipping Destination', 'sportspress' ),
'desc' => __( 'Ship to billing address by default', 'sportspress' ),
'id' => 'sportspress_ship_to_billing',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
'show_if_checked' => 'option',
),
array(
'desc' => __( 'Only ship to the users billing address', 'sportspress' ),
'id' => 'sportspress_ship_to_billing_address_only',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false,
'show_if_checked' => 'yes',
),
array(
'title' => __( 'Restrict shipping to Location(s)', 'sportspress' ),
'desc' => sprintf( __( 'Choose which countries you want to ship to, or choose to ship to all <a href="%s">locations you sell to</a>.', 'sportspress' ), admin_url( 'admin.php?page=sp-settings&tab=general' ) ),
'id' => 'sportspress_ship_to_countries',
'default' => '',
'type' => 'select',
'class' => 'chosen_select',
'desc_tip' => false,
'options' => array(
'' => __( 'Ship to all countries you sell to', 'sportspress' ),
'all' => __( 'Ship to all countries', 'sportspress' ),
'specific' => __( 'Ship to specific countries only', 'sportspress' )
)
),
array(
'title' => __( 'Specific Countries', 'sportspress' ),
'desc' => '',
'id' => 'sportspress_specific_ship_to_countries',
'css' => '',
'default' => '',
'type' => 'multi_select_countries'
),
array(
'type' => 'shipping_methods',
),
array( 'type' => 'sectionend', 'id' => 'shipping_options' ),
)); // End shipping settings
}
/**
* Output the settings
*/
public function output() {
global $current_section;
// Load shipping methods so we can show any global options they may have
$shipping_methods = SP()->shipping->load_shipping_methods();
if ( $current_section ) {
foreach ( $shipping_methods as $method ) {
if ( strtolower( get_class( $method ) ) == strtolower( $current_section ) && $method->has_settings() ) {
$method->admin_options();
break;
}
}
} else {
$settings = $this->get_settings();
SP_Admin_Settings::output_fields( $settings );
}
}
/**
* Output shipping method settings.
*
* @access public
* @return void
*/
public function shipping_methods_setting() {
$default_shipping_method = esc_attr( get_option('sportspress_default_shipping_method') );
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Shipping Methods', 'sportspress' ) ?></th>
<td class="forminp">
<table class="sp_shipping widefat" cellspacing="0">
<thead>
<tr>
<th class="default"><?php _e( 'Default', 'sportspress' ); ?></th>
<th class="name"><?php _e( 'Name', 'sportspress' ); ?></th>
<th class="id"><?php _e( 'ID', 'sportspress' ); ?></th>
<th class="status"><?php _e( 'Status', 'sportspress' ); ?></th>
<th class="settings">&nbsp;</th>
</tr>
</thead>
<tfoot>
<tr>
<th width="1%" class="default">
<input type="radio" name="default_shipping_method" value="" <?php checked( $default_shipping_method, '' ); ?> />
</th>
<th><?php _e( 'No default', 'sportspress' ); ?></th>
<th colspan="3"><span class="description"><?php _e( 'Drag and drop the above shipping methods to control their display order.', 'sportspress' ); ?></span></th>
</tr>
</tfoot>
<tbody>
<?php
foreach ( SP()->shipping->load_shipping_methods() as $key => $method ) {
echo '<tr>
<td width="1%" class="default">
<input type="radio" name="default_shipping_method" value="' . esc_attr( $method->id ) . '" ' . checked( $default_shipping_method, $method->id, false ) . ' />
<input type="hidden" name="method_order[]" value="' . esc_attr( $method->id ) . '" />
</td>
<td class="name">
' . $method->get_title() . '
</td>
<td class="id">
' . $method->id . '
</td>
<td class="status">';
if ( $method->enabled == 'yes' )
echo '<span class="status-enabled tips" data-tip="' . __ ( 'Enabled', 'sportspress' ) . '">' . __ ( 'Enabled', 'sportspress' ) . '</span>';
else
echo '-';
echo '</td>
<td class="settings">';
if ( $method->has_settings ) {
echo '<a class="button" href="' . admin_url( 'admin.php?page=sp-settings&tab=shipping&section=' . strtolower( get_class( $method ) ) ) . '">' . __( 'Settings', 'sportspress' ) . '</a>';
}
echo '</td>
</tr>';
}
?>
</tbody>
</table>
</td>
</tr>
<?php
}
/**
* Save settings
*/
public function save() {
global $current_section;
if ( ! $current_section ) {
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
SP()->shipping->process_admin_options();
} elseif ( class_exists( $current_section ) ) {
$current_section_class = new $current_section();
do_action( 'sportspress_update_options_' . $this->id . '_' . $current_section_class->id );
}
}
}
endif;
return new SP_Settings_Shipping();

View File

@@ -0,0 +1,735 @@
<?php
/**
* SportsPress Tax Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Tax' ) ) :
/**
* SP_Settings_Tax
*/
class SP_Settings_Tax extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'tax';
$this->label = __( 'Tax', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_sections_' . $this->id, array( $this, 'output_sections' ) );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get sections
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Tax Options', 'sportspress' ),
'standard' => __( 'Standard Rates', 'sportspress' )
);
// Get tax classes and display as links
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
if ( $tax_classes )
foreach ( $tax_classes as $class )
$sections[ sanitize_title( $class ) ] = sprintf( __( '%s Rates', 'sportspress' ), $class );
return $sections;
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'sportspress_tax_classes' ) ) ) );
$classes_options = array();
if ( $tax_classes )
foreach ( $tax_classes as $class )
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
return apply_filters('sportspress_tax_settings', array(
array( 'title' => __( 'Tax Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'tax_options' ),
array(
'title' => __( 'Enable Taxes', 'sportspress' ),
'desc' => __( 'Enable taxes and tax calculations', 'sportspress' ),
'id' => 'sportspress_calc_taxes',
'default' => 'no',
'type' => 'checkbox'
),
array(
'title' => __( 'Prices Entered With Tax', 'sportspress' ),
'id' => 'sportspress_prices_include_tax',
'default' => 'no',
'type' => 'radio',
'desc_tip' => __( 'This option is important as it will affect how you input prices. Changing it will not update existing products.', 'sportspress' ),
'options' => array(
'yes' => __( 'Yes, I will enter prices inclusive of tax', 'sportspress' ),
'no' => __( 'No, I will enter prices exclusive of tax', 'sportspress' )
),
),
array(
'title' => __( 'Calculate Tax Based On:', 'sportspress' ),
'id' => 'sportspress_tax_based_on',
'desc_tip' => __( 'This option determines which address is used to calculate tax.', 'sportspress' ),
'default' => 'shipping',
'type' => 'select',
'options' => array(
'shipping' => __( 'Customer shipping address', 'sportspress' ),
'billing' => __( 'Customer billing address', 'sportspress' ),
'base' => __( 'Shop base address', 'sportspress' )
),
),
array(
'title' => __( 'Default Customer Address:', 'sportspress' ),
'id' => 'sportspress_default_customer_address',
'desc_tip' => __( 'This option determines the customers default address (before they input their own).', 'sportspress' ),
'default' => 'base',
'type' => 'select',
'options' => array(
'' => __( 'No address', 'sportspress' ),
'base' => __( 'Shop base address', 'sportspress' ),
),
),
array(
'title' => __( 'Shipping Tax Class:', 'sportspress' ),
'desc' => __( 'Optionally control which tax class shipping gets, or leave it so shipping tax is based on the cart items themselves.', 'sportspress' ),
'id' => 'sportspress_shipping_tax_class',
'css' => 'min-width:150px;',
'default' => 'title',
'type' => 'select',
'options' => array( '' => __( 'Shipping tax class based on cart items', 'sportspress' ), 'standard' => __( 'Standard', 'sportspress' ) ) + $classes_options,
'desc_tip' => true,
),
array(
'title' => __( 'Rounding', 'sportspress' ),
'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'sportspress' ),
'id' => 'sportspress_tax_round_at_subtotal',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Additional Tax Classes', 'sportspress' ),
'desc' => __( 'List additonal tax classes below (1 per line). This is in addition to the default <code>Standard Rate</code>. Tax classes can be assigned to products.', 'sportspress' ),
'id' => 'sportspress_tax_classes',
'css' => 'width:100%; height: 65px;',
'type' => 'textarea',
'default' => sprintf( __( 'Reduced Rate%sZero Rate', 'sportspress' ), PHP_EOL )
),
array(
'title' => __( 'Display prices in the shop:', 'sportspress' ),
'id' => 'sportspress_tax_display_shop',
'default' => 'excl',
'type' => 'select',
'options' => array(
'incl' => __( 'Including tax', 'sportspress' ),
'excl' => __( 'Excluding tax', 'sportspress' ),
)
),
array(
'title' => __( 'Price display suffix:', 'sportspress' ),
'id' => 'sportspress_price_display_suffix',
'default' => '',
'type' => 'text',
'desc' => __( 'Define text to show after your product prices. This could be, for example, "inc. Vat" to explain your pricing. You can also have prices substituted here using one of the following: <code>{price_including_tax}, {price_excluding_tax}</code>.', 'sportspress' ),
),
array(
'title' => __( 'Display prices during cart/checkout:', 'sportspress' ),
'id' => 'sportspress_tax_display_cart',
'default' => 'excl',
'type' => 'select',
'options' => array(
'incl' => __( 'Including tax', 'sportspress' ),
'excl' => __( 'Excluding tax', 'sportspress' ),
),
'autoload' => false
),
array(
'title' => __( 'Display tax totals:', 'sportspress' ),
'id' => 'sportspress_tax_total_display',
'default' => 'itemized',
'type' => 'select',
'options' => array(
'single' => __( 'As a single total', 'sportspress' ),
'itemized' => __( 'Itemized', 'sportspress' ),
),
'autoload' => false
),
array( 'type' => 'sectionend', 'id' => 'tax_options' ),
)); // End tax settings
}
/**
* Output the settings
*/
public function output() {
global $current_section;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
$this->output_tax_rates();
} else {
$settings = $this->get_settings();
SP_Admin_Settings::output_fields( $settings );
}
}
/**
* Save settings
*/
public function save() {
global $current_section, $wpdb;
if ( ! $current_section ) {
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
} else {
$this->save_tax_rates();
}
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_sp_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_sp_tax_rates_%')" );
}
/**
* Output tax rate tables
*/
public function output_tax_rates() {
global $sportspress, $current_section, $wpdb;
$page = ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1;
$limit = 100;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
$current_class = '';
foreach( $tax_classes as $class )
if ( sanitize_title( $class ) == $current_section )
$current_class = $class;
?>
<h3><?php printf( __( 'Tax Rates for the "%s" Class', 'sportspress' ), $current_class ? esc_html( $current_class ) : __( 'Standard', 'sportspress' ) ); ?></h3>
<p><?php printf( __( 'Define tax rates for countries and states below. <a href="%s">See here</a> for available alpha-2 country codes.', 'sportspress' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?></p>
<table class="sp_tax_rates sp_input_table sortable widefat">
<thead>
<tr>
<th class="sort">&nbsp;</th>
<th width="8%"><?php _e( 'Country&nbsp;Code', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('A 2 digit country code, e.g. US. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'State&nbsp;Code', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('A 2 digit state code, e.g. AL. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
<th><?php _e( 'ZIP/Postcode', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Postcode for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all areas. Wildcards (*) can be used. Ranges for numeric postcodes (e.g. 12345-12350) will be expanded into individual postcodes.', 'sportspress'); ?>">[?]</span></th>
<th><?php _e( 'City', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Cities for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all cities.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Rate&nbsp;%', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'Enter a tax rate (percentage) to 4 decimal places.', 'sportspress' ); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Tax&nbsp;Name', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Enter a name for this tax rate.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Priority', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Choose a priority for this tax rate. Only 1 matching rate per priority will be used. To define multiple tax rates for a single area you need to specify a different priority per rate.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Compound', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Choose whether or not this is a compound rate. Compound tax rates are applied on top of other tax rates.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Shipping', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Choose whether or not this tax rate also gets applied to shipping.', 'sportspress'); ?>">[?]</span></th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="10">
<a href="#" class="button plus insert"><?php _e( 'Insert row', 'sportspress' ); ?></a>
<a href="#" class="button minus remove_tax_rates"><?php _e( 'Remove selected row(s)', 'sportspress' ); ?></a>
<div class="pagination">
<?php
echo str_replace( 'page-numbers', 'page-numbers button', paginate_links( array(
'base' => add_query_arg( 'p', '%#%' ),
'type' => 'plain',
'prev_text' => '&laquo;',
'next_text' => '&raquo;',
'total' => ceil( absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(tax_rate_id) FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_class = %s;", sanitize_title( $current_class ) ) ) ) / $limit ),
'current' => $page
) ) );
?>
</div>
<a href="#" download="tax_rates.csv" class="button export"><?php _e( 'Export CSV', 'sportspress' ); ?></a>
<a href="<?php echo admin_url( 'admin.php?import=sportspress_tax_rate_csv' ); ?>" class="button import"><?php _e( 'Import CSV', 'sportspress' ); ?></a>
</th>
</tr>
</tfoot>
<tbody id="rates">
<?php
$rates = $wpdb->get_results( $wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}sportspress_tax_rates
WHERE tax_rate_class = %s
ORDER BY tax_rate_order
LIMIT %d, %d
" ,
sanitize_title( $current_class ),
( $page - 1 ) * $limit,
$limit
) );
foreach ( $rates as $rate ) {
?>
<tr>
<td class="sort"><input type="hidden" class="remove_tax_rate" name="remove_tax_rate[<?php echo $rate->tax_rate_id ?>]" value="0" /></td>
<td class="country" width="8%">
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_country ) ?>" placeholder="*" name="tax_rate_country[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="state" width="8%">
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_state ) ?>" placeholder="*" name="tax_rate_state[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="postcode">
<input type="text" value="<?php
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
echo esc_attr( implode( '; ', $locations ) );
?>" placeholder="*" data-name="tax_rate_postcode[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="city">
<input type="text" value="<?php
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
echo esc_attr( implode( '; ', $locations ) );
?>" placeholder="*" data-name="tax_rate_city[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="rate" width="8%">
<input type="number" step="any" min="0" value="<?php echo esc_attr( $rate->tax_rate ) ?>" placeholder="0" name="tax_rate[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="name" width="8%">
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_name ) ?>" name="tax_rate_name[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="priority" width="8%">
<input type="number" step="1" min="1" value="<?php echo esc_attr( $rate->tax_rate_priority ) ?>" name="tax_rate_priority[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="compound" width="8%">
<input type="checkbox" class="checkbox" name="tax_rate_compound[<?php echo $rate->tax_rate_id ?>]" <?php checked( $rate->tax_rate_compound, '1' ); ?> />
</td>
<td class="apply_to_shipping" width="8%">
<input type="checkbox" class="checkbox" name="tax_rate_shipping[<?php echo $rate->tax_rate_id ?>]" <?php checked($rate->tax_rate_shipping, '1' ); ?> />
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<script type="text/javascript">
jQuery( function() {
jQuery('.sp_tax_rates .remove_tax_rates').click(function() {
var $tbody = jQuery('.sp_tax_rates').find('tbody');
if ( $tbody.find('tr.current').size() > 0 ) {
$current = $tbody.find('tr.current');
$current.find('input').val('');
$current.find('input.remove_tax_rate').val('1');
$current.each(function(){
if ( jQuery(this).is('.new') )
jQuery(this).remove();
else
jQuery(this).hide();
});
} else {
alert('<?php echo esc_js( __( 'No row(s) selected', 'sportspress' ) ); ?>');
}
return false;
});
jQuery('.sp_tax_rates .export').click(function() {
var csv_data = "data:application/csv;charset=utf-8,<?php _e( 'Country Code', 'sportspress' ); ?>,<?php _e( 'State Code', 'sportspress' ); ?>,<?php _e( 'ZIP/Postcode', 'sportspress' ); ?>,<?php _e( 'City', 'sportspress' ); ?>,<?php _e( 'Rate %', 'sportspress' ); ?>,<?php _e( 'Tax Name', 'sportspress' ); ?>,<?php _e( 'Priority', 'sportspress' ); ?>,<?php _e( 'Compound', 'sportspress' ); ?>,<?php _e( 'Shipping', 'sportspress' ); ?>,<?php _e( 'Tax Class', 'sportspress' ); ?>\n";
jQuery('#rates tr:visible').each(function() {
var row = '';
jQuery(this).find('td:not(.sort) input').each(function() {
if ( jQuery(this).is('.checkbox') ) {
if ( jQuery(this).is(':checked') ) {
val = 1;
} else {
val = 0;
}
} else {
var val = jQuery(this).val();
if ( ! val )
val = jQuery(this).attr('placeholder');
}
row = row + val + ',';
});
row = row + '<?php echo $current_class; ?>';
//row.substring( 0, row.length - 1 );
csv_data = csv_data + row + "\n";
});
jQuery(this).attr( 'href', encodeURI( csv_data ) );
return true;
});
jQuery('.sp_tax_rates .insert').click(function() {
var $tbody = jQuery('.sp_tax_rates').find('tbody');
var size = $tbody.find('tr').size();
var code = '<tr class="new">\
<td class="sort">&nbsp;</td>\
<td class="country" width="8%">\
<input type="text" placeholder="*" name="tax_rate_country[new][' + size + ']" />\
</td>\
<td class="state" width="8%">\
<input type="text" placeholder="*" name="tax_rate_state[new][' + size + ']" />\
</td>\
<td class="postcode">\
<input type="text" placeholder="*" name="tax_rate_postcode[new][' + size + ']" />\
</td>\
<td class="city">\
<input type="text" placeholder="*" name="tax_rate_city[new][' + size + ']" />\
</td>\
<td class="rate" width="8%">\
<input type="number" step="any" min="0" placeholder="0" name="tax_rate[new][' + size + ']" />\
</td>\
<td class="name" width="8%">\
<input type="text" name="tax_rate_name[new][' + size + ']" />\
</td>\
<td class="priority" width="8%">\
<input type="number" step="1" min="1" value="1" name="tax_rate_priority[new][' + size + ']" />\
</td>\
<td class="compound" width="8%">\
<input type="checkbox" class="checkbox" name="tax_rate_compound[new][' + size + ']" />\
</td>\
<td class="apply_to_shipping" width="8%">\
<input type="checkbox" class="checkbox" name="tax_rate_shipping[new][' + size + ']" checked="checked" />\
</td>\
</tr>';
if ( $tbody.find('tr.current').size() > 0 ) {
$tbody.find('tr.current').after( code );
} else {
$tbody.append( code );
}
jQuery( "td.country input" ).autocomplete({
source: availableCountries,
minLength: 3
});
jQuery( "td.state input" ).autocomplete({
source: availableStates,
minLength: 3
});
return false;
});
jQuery('.sp_tax_rates td.postcode, .sp_tax_rates td.city').find('input').change(function() {
jQuery(this).attr( 'name', jQuery(this).attr( 'data-name' ) );
});
var availableCountries = [<?php
$countries = array();
foreach ( SP()->countries->get_allowed_countries() as $value => $label )
$countries[] = '{ label: "' . $label . '", value: "' . $value . '" }';
echo implode( ', ', $countries );
?>];
var availableStates = [<?php
$countries = array();
foreach ( SP()->countries->get_allowed_country_states() as $value => $label )
foreach ( $label as $code => $state )
$countries[] = '{ label: "' . $state . '", value: "' . $code . '" }';
echo implode( ', ', $countries );
?>];
jQuery( "td.country input" ).autocomplete({
source: availableCountries,
minLength: 3
});
jQuery( "td.state input" ).autocomplete({
source: availableStates,
minLength: 3
});
});
</script>
<?php
}
/**
* Save tax rates
*/
public function save_tax_rates() {
global $wpdb, $current_section;
// Get class
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
$current_class = '';
foreach( $tax_classes as $class )
if ( sanitize_title( $class ) == $current_section )
$current_class = $class;
// Get POST data
$tax_rate_country = isset( $_POST['tax_rate_country'] ) ? $_POST['tax_rate_country'] : array();
$tax_rate_state = isset( $_POST['tax_rate_state'] ) ? $_POST['tax_rate_state'] : array();
$tax_rate_postcode = isset( $_POST['tax_rate_postcode'] ) ? $_POST['tax_rate_postcode'] : array();
$tax_rate_city = isset( $_POST['tax_rate_city'] ) ? $_POST['tax_rate_city'] : array();
$tax_rate = isset( $_POST['tax_rate'] ) ? $_POST['tax_rate'] : array();
$tax_rate_name = isset( $_POST['tax_rate_name'] ) ? $_POST['tax_rate_name'] : array();
$tax_rate_priority = isset( $_POST['tax_rate_priority'] ) ? $_POST['tax_rate_priority'] : array();
$tax_rate_compound = isset( $_POST['tax_rate_compound'] ) ? $_POST['tax_rate_compound'] : array();
$tax_rate_shipping = isset( $_POST['tax_rate_shipping'] ) ? $_POST['tax_rate_shipping'] : array();
$i = 0;
// Loop posted fields
foreach ( $tax_rate_country as $key => $value ) {
// new keys are inserted...
if ( $key == 'new' ) {
foreach ( $value as $new_key => $new_value ) {
// Sanitize + format
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ][ $new_key ] ) );
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ][ $new_key ] ) );
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ][ $new_key ] );
$city = sanitize_text_field( $tax_rate_city[ $key ][ $new_key ] );
$rate = number_format( sanitize_text_field( $tax_rate[ $key ][ $new_key ] ), 4, '.', '' );
$name = sanitize_text_field( $tax_rate_name[ $key ][ $new_key ] );
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ][ $new_key ] ) );
$compound = isset( $tax_rate_compound[ $key ][ $new_key ] ) ? 1 : 0;
$shipping = isset( $tax_rate_shipping[ $key ][ $new_key ] ) ? 1 : 0;
if ( ! $name )
$name = __( 'Tax', 'sportspress' );
if ( $country == '*' )
$country = '';
if ( $state == '*' )
$state = '';
$wpdb->insert(
$wpdb->prefix . "sportspress_tax_rates",
array(
'tax_rate_country' => $country,
'tax_rate_state' => $state,
'tax_rate' => $rate,
'tax_rate_name' => $name,
'tax_rate_priority' => $priority,
'tax_rate_compound' => $compound,
'tax_rate_shipping' => $shipping,
'tax_rate_order' => $i,
'tax_rate_class' => sanitize_title( $current_class )
)
);
$tax_rate_id = $wpdb->insert_id;
if ( ! empty( $postcode ) ) {
$postcodes = explode( ';', $postcode );
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
$postcode_query = array();
foreach( $postcodes as $postcode )
if ( strstr( $postcode, '-' ) ) {
$postcode_parts = explode( '-', $postcode );
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
if ( ! $i )
continue;
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
}
}
} else {
if ( $postcode )
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
}
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
}
if ( ! empty( $city ) ) {
$cities = explode( ';', $city );
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
foreach( $cities as $city ) {
$wpdb->insert(
$wpdb->prefix . "sportspress_tax_rate_locations",
array(
'location_code' => $city,
'tax_rate_id' => $tax_rate_id,
'location_type' => 'city',
)
);
}
}
$i++;
}
// ...whereas the others are updated
} else {
$tax_rate_id = absint( $key );
if ( $_POST['remove_tax_rate'][ $key ] == 1 ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) );
continue;
}
// Sanitize + format
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ] ) );
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ] ) );
$rate = number_format( (double) sanitize_text_field( $tax_rate[ $key ] ), 4, '.', '' );
$name = sanitize_text_field( $tax_rate_name[ $key ] );
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ] ) );
$compound = isset( $tax_rate_compound[ $key ] ) ? 1 : 0;
$shipping = isset( $tax_rate_shipping[ $key ] ) ? 1 : 0;
if ( ! $name )
$name = __( 'Tax', 'sportspress' );
if ( $country == '*' )
$country = '';
if ( $state == '*' )
$state = '';
$wpdb->update(
$wpdb->prefix . "sportspress_tax_rates",
array(
'tax_rate_country' => $country,
'tax_rate_state' => $state,
'tax_rate' => $rate,
'tax_rate_name' => $name,
'tax_rate_priority' => $priority,
'tax_rate_compound' => $compound,
'tax_rate_shipping' => $shipping,
'tax_rate_order' => $i,
'tax_rate_class' => sanitize_title( $current_class )
),
array(
'tax_rate_id' => $tax_rate_id
)
);
if ( isset( $tax_rate_postcode[ $key ] ) ) {
// Delete old
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'postcode';", $tax_rate_id ) );
// Add changed
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ] );
$postcodes = explode( ';', $postcode );
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
$postcode_query = array();
foreach( $postcodes as $postcode )
if ( strstr( $postcode, '-' ) ) {
$postcode_parts = explode( '-', $postcode );
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
if ( ! $i )
continue;
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
}
}
} else {
if ( $postcode )
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
}
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
}
if ( isset( $tax_rate_city[ $key ] ) ) {
// Delete old
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'city';", $tax_rate_id ) );
// Add changed
$city = sanitize_text_field( $tax_rate_city[ $key ] );
$cities = explode( ';', $city );
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
foreach( $cities as $city ) {
if ( $city ) {
$wpdb->insert(
$wpdb->prefix . "sportspress_tax_rate_locations",
array(
'location_code' => $city,
'tax_rate_id' => $tax_rate_id,
'location_type' => 'city',
)
);
}
}
}
$i++;
}
}
}
}
endif;
return new SP_Settings_Tax();

View File

@@ -0,0 +1,783 @@
<?php
/**
* SportsPress Team Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Teams' ) ) :
/**
* SP_Settings_Teams
*/
class SP_Settings_Teams extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'teams';
$this->label = __( 'Teams', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'sportspress_tax_classes' ) ) ) );
$classes_options = array();
if ( $tax_classes )
foreach ( $tax_classes as $class )
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
return apply_filters('sportspress_event_settings', array(
array( 'title' => __( 'Team Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'tax_options' ),
array(
'title' => __( 'Enable Teams', 'sportspress' ),
'desc' => __( 'Enable taxes and tax calculations', 'sportspress' ),
'id' => 'sportspress_calc_taxes',
'default' => 'no',
'type' => 'checkbox'
),
array(
'title' => __( 'Prices Entered With Tax', 'sportspress' ),
'id' => 'sportspress_prices_include_tax',
'default' => 'no',
'type' => 'radio',
'options' => array(
'vs' => sprintf( '%s vs %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ),
'v' => sprintf( '%s v %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ),
'&mdash;' => sprintf( '%s &mdash; %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) ),
'/' => sprintf( '%s / %s', __( 'Team', 'sportspress' ), __( 'Team', 'sportspress' ) )
),
),
array(
'title' => __( 'Calculate Tax Based On:', 'sportspress' ),
'id' => 'sportspress_tax_based_on',
'desc_tip' => __( 'This option determines which address is used to calculate tax.', 'sportspress' ),
'default' => 'shipping',
'type' => 'select',
'options' => array(
'shipping' => __( 'Customer shipping address', 'sportspress' ),
'billing' => __( 'Customer billing address', 'sportspress' ),
'base' => __( 'Shop base address', 'sportspress' )
),
),
array(
'title' => __( 'Default Customer Address:', 'sportspress' ),
'id' => 'sportspress_default_customer_address',
'desc_tip' => __( 'This option determines the customers default address (before they input their own).', 'sportspress' ),
'default' => 'base',
'type' => 'select',
'options' => array(
'' => __( 'No address', 'sportspress' ),
'base' => __( 'Shop base address', 'sportspress' ),
),
),
array(
'title' => __( 'Shipping Tax Class:', 'sportspress' ),
'desc' => __( 'Optionally control which tax class shipping gets, or leave it so shipping tax is based on the cart items themselves.', 'sportspress' ),
'id' => 'sportspress_shipping_tax_class',
'css' => 'min-width:150px;',
'default' => 'title',
'type' => 'select',
'options' => array( '' => __( 'Shipping tax class based on cart items', 'sportspress' ), 'standard' => __( 'Standard', 'sportspress' ) ) + $classes_options,
'desc_tip' => true,
),
array(
'title' => __( 'Rounding', 'sportspress' ),
'desc' => __( 'Round tax at subtotal level, instead of rounding per line', 'sportspress' ),
'id' => 'sportspress_tax_round_at_subtotal',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Additional Tax Classes', 'sportspress' ),
'desc' => __( 'List additonal tax classes below (1 per line). This is in addition to the default <code>Standard Rate</code>. Tax classes can be assigned to products.', 'sportspress' ),
'id' => 'sportspress_tax_classes',
'css' => 'width:100%; height: 65px;',
'type' => 'textarea',
'default' => sprintf( __( 'Reduced Rate%sZero Rate', 'sportspress' ), PHP_EOL )
),
array(
'title' => __( 'Display prices in the shop:', 'sportspress' ),
'id' => 'sportspress_tax_display_shop',
'default' => 'excl',
'type' => 'select',
'options' => array(
'incl' => __( 'Including tax', 'sportspress' ),
'excl' => __( 'Excluding tax', 'sportspress' ),
)
),
array(
'title' => __( 'Price display suffix:', 'sportspress' ),
'id' => 'sportspress_price_display_suffix',
'default' => '',
'type' => 'text',
'desc' => __( 'Define text to show after your product prices. This could be, for example, "inc. Vat" to explain your pricing. You can also have prices substituted here using one of the following: <code>{price_including_tax}, {price_excluding_tax}</code>.', 'sportspress' ),
),
array(
'title' => __( 'Display prices during cart/checkout:', 'sportspress' ),
'id' => 'sportspress_tax_display_cart',
'default' => 'excl',
'type' => 'select',
'options' => array(
'incl' => __( 'Including tax', 'sportspress' ),
'excl' => __( 'Excluding tax', 'sportspress' ),
),
'autoload' => false
),
array(
'title' => __( 'Display tax totals:', 'sportspress' ),
'id' => 'sportspress_tax_total_display',
'default' => 'itemized',
'type' => 'select',
'options' => array(
'single' => __( 'As a single total', 'sportspress' ),
'itemized' => __( 'Itemized', 'sportspress' ),
),
'autoload' => false
),
array( 'type' => 'results' ),
array( 'type' => 'sectionend', 'id' => 'event_options' ),
)); // End event settings
}
/**
* Output the settings
*/
public function output() {
global $current_section;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
$this->output_tax_rates();
} else {
$settings = $this->get_settings();
SP_Admin_Settings::output_fields( $settings );
}
}
/**
* Save settings
*/
public function save() {
global $current_section, $wpdb;
if ( ! $current_section ) {
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
} else {
$this->save_tax_rates();
}
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_sp_tax_rates_%') OR `option_name` LIKE ('_transient_timeout_sp_tax_rates_%')" );
}
/**
* Output tax rate tables
*/
public function output_tax_rates() {
global $sportspress, $current_section, $wpdb;
$page = ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1;
$limit = 100;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
$current_class = '';
foreach( $tax_classes as $class )
if ( sanitize_title( $class ) == $current_section )
$current_class = $class;
?>
<h3><?php printf( __( 'Tax Rates for the "%s" Class', 'sportspress' ), $current_class ? esc_html( $current_class ) : __( 'Standard', 'sportspress' ) ); ?></h3>
<p><?php printf( __( 'Define tax rates for countries and states below. <a href="%s">See here</a> for available alpha-2 country codes.', 'sportspress' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?></p>
<table class="sp_tax_rates sp_input_table sortable widefat">
<thead>
<tr>
<th class="sort">&nbsp;</th>
<th width="8%"><?php _e( 'Country&nbsp;Code', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('A 2 digit country code, e.g. US. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'State&nbsp;Code', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('A 2 digit state code, e.g. AL. Leave blank to apply to all.', 'sportspress'); ?>">[?]</span></th>
<th><?php _e( 'ZIP/Postcode', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Postcode for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all areas. Wildcards (*) can be used. Ranges for numeric postcodes (e.g. 12345-12350) will be expanded into individual postcodes.', 'sportspress'); ?>">[?]</span></th>
<th><?php _e( 'City', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Cities for this rule. Semi-colon (;) separate multiple values. Leave blank to apply to all cities.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Rate&nbsp;%', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e( 'Enter a tax rate (percentage) to 4 decimal places.', 'sportspress' ); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Tax&nbsp;Name', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Enter a name for this tax rate.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Priority', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Choose a priority for this tax rate. Only 1 matching rate per priority will be used. To define multiple tax rates for a single area you need to specify a different priority per rate.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Compound', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Choose whether or not this is a compound rate. Compound tax rates are applied on top of other tax rates.', 'sportspress'); ?>">[?]</span></th>
<th width="8%"><?php _e( 'Shipping', 'sportspress' ); ?>&nbsp;<span class="tips" data-tip="<?php _e('Choose whether or not this tax rate also gets applied to shipping.', 'sportspress'); ?>">[?]</span></th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan="10">
<a href="#" class="button plus insert"><?php _e( 'Insert row', 'sportspress' ); ?></a>
<a href="#" class="button minus remove_tax_rates"><?php _e( 'Remove selected row(s)', 'sportspress' ); ?></a>
<div class="pagination">
<?php
echo str_replace( 'page-numbers', 'page-numbers button', paginate_links( array(
'base' => add_query_arg( 'p', '%#%' ),
'type' => 'plain',
'prev_text' => '&laquo;',
'next_text' => '&raquo;',
'total' => ceil( absint( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(tax_rate_id) FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_class = %s;", sanitize_title( $current_class ) ) ) ) / $limit ),
'current' => $page
) ) );
?>
</div>
<a href="#" download="tax_rates.csv" class="button export"><?php _e( 'Export CSV', 'sportspress' ); ?></a>
<a href="<?php echo admin_url( 'admin.php?import=sportspress_tax_rate_csv' ); ?>" class="button import"><?php _e( 'Import CSV', 'sportspress' ); ?></a>
</th>
</tr>
</tfoot>
<tbody id="rates">
<?php
$rates = $wpdb->get_results( $wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}sportspress_tax_rates
WHERE tax_rate_class = %s
ORDER BY tax_rate_order
LIMIT %d, %d
" ,
sanitize_title( $current_class ),
( $page - 1 ) * $limit,
$limit
) );
foreach ( $rates as $rate ) {
?>
<tr>
<td class="sort"><input type="hidden" class="remove_tax_rate" name="remove_tax_rate[<?php echo $rate->tax_rate_id ?>]" value="0" /></td>
<td class="country" width="8%">
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_country ) ?>" placeholder="*" name="tax_rate_country[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="state" width="8%">
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_state ) ?>" placeholder="*" name="tax_rate_state[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="postcode">
<input type="text" value="<?php
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='postcode' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
echo esc_attr( implode( '; ', $locations ) );
?>" placeholder="*" data-name="tax_rate_postcode[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="city">
<input type="text" value="<?php
$locations = $wpdb->get_col( $wpdb->prepare( "SELECT location_code FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE location_type='city' AND tax_rate_id = %d ORDER BY location_code", $rate->tax_rate_id ) );
echo esc_attr( implode( '; ', $locations ) );
?>" placeholder="*" data-name="tax_rate_city[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="rate" width="8%">
<input type="number" step="any" min="0" value="<?php echo esc_attr( $rate->tax_rate ) ?>" placeholder="0" name="tax_rate[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="name" width="8%">
<input type="text" value="<?php echo esc_attr( $rate->tax_rate_name ) ?>" name="tax_rate_name[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="priority" width="8%">
<input type="number" step="1" min="1" value="<?php echo esc_attr( $rate->tax_rate_priority ) ?>" name="tax_rate_priority[<?php echo $rate->tax_rate_id ?>]" />
</td>
<td class="compound" width="8%">
<input type="checkbox" class="checkbox" name="tax_rate_compound[<?php echo $rate->tax_rate_id ?>]" <?php checked( $rate->tax_rate_compound, '1' ); ?> />
</td>
<td class="apply_to_shipping" width="8%">
<input type="checkbox" class="checkbox" name="tax_rate_shipping[<?php echo $rate->tax_rate_id ?>]" <?php checked($rate->tax_rate_shipping, '1' ); ?> />
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<script type="text/javascript">
jQuery( function() {
jQuery('.sp_tax_rates .remove_tax_rates').click(function() {
var $tbody = jQuery('.sp_tax_rates').find('tbody');
if ( $tbody.find('tr.current').size() > 0 ) {
$current = $tbody.find('tr.current');
$current.find('input').val('');
$current.find('input.remove_tax_rate').val('1');
$current.each(function(){
if ( jQuery(this).is('.new') )
jQuery(this).remove();
else
jQuery(this).hide();
});
} else {
alert('<?php echo esc_js( __( 'No row(s) selected', 'sportspress' ) ); ?>');
}
return false;
});
jQuery('.sp_tax_rates .export').click(function() {
var csv_data = "data:application/csv;charset=utf-8,<?php _e( 'Country Code', 'sportspress' ); ?>,<?php _e( 'State Code', 'sportspress' ); ?>,<?php _e( 'ZIP/Postcode', 'sportspress' ); ?>,<?php _e( 'City', 'sportspress' ); ?>,<?php _e( 'Rate %', 'sportspress' ); ?>,<?php _e( 'Tax Name', 'sportspress' ); ?>,<?php _e( 'Priority', 'sportspress' ); ?>,<?php _e( 'Compound', 'sportspress' ); ?>,<?php _e( 'Shipping', 'sportspress' ); ?>,<?php _e( 'Tax Class', 'sportspress' ); ?>\n";
jQuery('#rates tr:visible').each(function() {
var row = '';
jQuery(this).find('td:not(.sort) input').each(function() {
if ( jQuery(this).is('.checkbox') ) {
if ( jQuery(this).is(':checked') ) {
val = 1;
} else {
val = 0;
}
} else {
var val = jQuery(this).val();
if ( ! val )
val = jQuery(this).attr('placeholder');
}
row = row + val + ',';
});
row = row + '<?php echo $current_class; ?>';
//row.substring( 0, row.length - 1 );
csv_data = csv_data + row + "\n";
});
jQuery(this).attr( 'href', encodeURI( csv_data ) );
return true;
});
jQuery('.sp_tax_rates .insert').click(function() {
var $tbody = jQuery('.sp_tax_rates').find('tbody');
var size = $tbody.find('tr').size();
var code = '<tr class="new">\
<td class="sort">&nbsp;</td>\
<td class="country" width="8%">\
<input type="text" placeholder="*" name="tax_rate_country[new][' + size + ']" />\
</td>\
<td class="state" width="8%">\
<input type="text" placeholder="*" name="tax_rate_state[new][' + size + ']" />\
</td>\
<td class="postcode">\
<input type="text" placeholder="*" name="tax_rate_postcode[new][' + size + ']" />\
</td>\
<td class="city">\
<input type="text" placeholder="*" name="tax_rate_city[new][' + size + ']" />\
</td>\
<td class="rate" width="8%">\
<input type="number" step="any" min="0" placeholder="0" name="tax_rate[new][' + size + ']" />\
</td>\
<td class="name" width="8%">\
<input type="text" name="tax_rate_name[new][' + size + ']" />\
</td>\
<td class="priority" width="8%">\
<input type="number" step="1" min="1" value="1" name="tax_rate_priority[new][' + size + ']" />\
</td>\
<td class="compound" width="8%">\
<input type="checkbox" class="checkbox" name="tax_rate_compound[new][' + size + ']" />\
</td>\
<td class="apply_to_shipping" width="8%">\
<input type="checkbox" class="checkbox" name="tax_rate_shipping[new][' + size + ']" checked="checked" />\
</td>\
</tr>';
if ( $tbody.find('tr.current').size() > 0 ) {
$tbody.find('tr.current').after( code );
} else {
$tbody.append( code );
}
jQuery( "td.country input" ).autocomplete({
source: availableCountries,
minLength: 3
});
jQuery( "td.state input" ).autocomplete({
source: availableStates,
minLength: 3
});
return false;
});
jQuery('.sp_tax_rates td.postcode, .sp_tax_rates td.city').find('input').change(function() {
jQuery(this).attr( 'name', jQuery(this).attr( 'data-name' ) );
});
var availableCountries = [<?php
$countries = array();
foreach ( SP()->countries->get_allowed_countries() as $value => $label )
$countries[] = '{ label: "' . $label . '", value: "' . $value . '" }';
echo implode( ', ', $countries );
?>];
var availableStates = [<?php
$countries = array();
foreach ( SP()->countries->get_allowed_country_states() as $value => $label )
foreach ( $label as $code => $state )
$countries[] = '{ label: "' . $state . '", value: "' . $code . '" }';
echo implode( ', ', $countries );
?>];
jQuery( "td.country input" ).autocomplete({
source: availableCountries,
minLength: 3
});
jQuery( "td.state input" ).autocomplete({
source: availableStates,
minLength: 3
});
});
</script>
<?php
}
/**
* Save tax rates
*/
public function save_tax_rates() {
global $wpdb, $current_section;
// Get class
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
$current_class = '';
foreach( $tax_classes as $class )
if ( sanitize_title( $class ) == $current_section )
$current_class = $class;
// Get POST data
$tax_rate_country = isset( $_POST['tax_rate_country'] ) ? $_POST['tax_rate_country'] : array();
$tax_rate_state = isset( $_POST['tax_rate_state'] ) ? $_POST['tax_rate_state'] : array();
$tax_rate_postcode = isset( $_POST['tax_rate_postcode'] ) ? $_POST['tax_rate_postcode'] : array();
$tax_rate_city = isset( $_POST['tax_rate_city'] ) ? $_POST['tax_rate_city'] : array();
$tax_rate = isset( $_POST['tax_rate'] ) ? $_POST['tax_rate'] : array();
$tax_rate_name = isset( $_POST['tax_rate_name'] ) ? $_POST['tax_rate_name'] : array();
$tax_rate_priority = isset( $_POST['tax_rate_priority'] ) ? $_POST['tax_rate_priority'] : array();
$tax_rate_compound = isset( $_POST['tax_rate_compound'] ) ? $_POST['tax_rate_compound'] : array();
$tax_rate_shipping = isset( $_POST['tax_rate_shipping'] ) ? $_POST['tax_rate_shipping'] : array();
$i = 0;
// Loop posted fields
foreach ( $tax_rate_country as $key => $value ) {
// new keys are inserted...
if ( $key == 'new' ) {
foreach ( $value as $new_key => $new_value ) {
// Sanitize + format
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ][ $new_key ] ) );
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ][ $new_key ] ) );
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ][ $new_key ] );
$city = sanitize_text_field( $tax_rate_city[ $key ][ $new_key ] );
$rate = number_format( sanitize_text_field( $tax_rate[ $key ][ $new_key ] ), 4, '.', '' );
$name = sanitize_text_field( $tax_rate_name[ $key ][ $new_key ] );
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ][ $new_key ] ) );
$compound = isset( $tax_rate_compound[ $key ][ $new_key ] ) ? 1 : 0;
$shipping = isset( $tax_rate_shipping[ $key ][ $new_key ] ) ? 1 : 0;
if ( ! $name )
$name = __( 'Tax', 'sportspress' );
if ( $country == '*' )
$country = '';
if ( $state == '*' )
$state = '';
$wpdb->insert(
$wpdb->prefix . "sportspress_tax_rates",
array(
'tax_rate_country' => $country,
'tax_rate_state' => $state,
'tax_rate' => $rate,
'tax_rate_name' => $name,
'tax_rate_priority' => $priority,
'tax_rate_compound' => $compound,
'tax_rate_shipping' => $shipping,
'tax_rate_order' => $i,
'tax_rate_class' => sanitize_title( $current_class )
)
);
$tax_rate_id = $wpdb->insert_id;
if ( ! empty( $postcode ) ) {
$postcodes = explode( ';', $postcode );
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
$postcode_query = array();
foreach( $postcodes as $postcode )
if ( strstr( $postcode, '-' ) ) {
$postcode_parts = explode( '-', $postcode );
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
if ( ! $i )
continue;
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
}
}
} else {
if ( $postcode )
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
}
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
}
if ( ! empty( $city ) ) {
$cities = explode( ';', $city );
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
foreach( $cities as $city ) {
$wpdb->insert(
$wpdb->prefix . "sportspress_tax_rate_locations",
array(
'location_code' => $city,
'tax_rate_id' => $tax_rate_id,
'location_type' => 'city',
)
);
}
}
$i++;
}
// ...whereas the others are updated
} else {
$tax_rate_id = absint( $key );
if ( $_POST['remove_tax_rate'][ $key ] == 1 ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d;", $tax_rate_id ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rates WHERE tax_rate_id = %d;", $tax_rate_id ) );
continue;
}
// Sanitize + format
$country = strtoupper( sanitize_text_field( $tax_rate_country[ $key ] ) );
$state = strtoupper( sanitize_text_field( $tax_rate_state[ $key ] ) );
$rate = number_format( (double) sanitize_text_field( $tax_rate[ $key ] ), 4, '.', '' );
$name = sanitize_text_field( $tax_rate_name[ $key ] );
$priority = absint( sanitize_text_field( $tax_rate_priority[ $key ] ) );
$compound = isset( $tax_rate_compound[ $key ] ) ? 1 : 0;
$shipping = isset( $tax_rate_shipping[ $key ] ) ? 1 : 0;
if ( ! $name )
$name = __( 'Tax', 'sportspress' );
if ( $country == '*' )
$country = '';
if ( $state == '*' )
$state = '';
$wpdb->update(
$wpdb->prefix . "sportspress_tax_rates",
array(
'tax_rate_country' => $country,
'tax_rate_state' => $state,
'tax_rate' => $rate,
'tax_rate_name' => $name,
'tax_rate_priority' => $priority,
'tax_rate_compound' => $compound,
'tax_rate_shipping' => $shipping,
'tax_rate_order' => $i,
'tax_rate_class' => sanitize_title( $current_class )
),
array(
'tax_rate_id' => $tax_rate_id
)
);
if ( isset( $tax_rate_postcode[ $key ] ) ) {
// Delete old
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'postcode';", $tax_rate_id ) );
// Add changed
$postcode = sanitize_text_field( $tax_rate_postcode[ $key ] );
$postcodes = explode( ';', $postcode );
$postcodes = array_map( 'strtoupper', array_map( 'sanitize_text_field', $postcodes ) );
$postcode_query = array();
foreach( $postcodes as $postcode )
if ( strstr( $postcode, '-' ) ) {
$postcode_parts = explode( '-', $postcode );
if ( is_numeric( $postcode_parts[0] ) && is_numeric( $postcode_parts[1] ) && $postcode_parts[1] > $postcode_parts[0] ) {
for ( $i = $postcode_parts[0]; $i <= $postcode_parts[1]; $i ++ ) {
if ( ! $i )
continue;
if ( strlen( $i ) < strlen( $postcode_parts[0] ) )
$i = str_pad( $i, strlen( $postcode_parts[0] ), "0", STR_PAD_LEFT );
$postcode_query[] = "( '" . esc_sql( $i ) . "', $tax_rate_id, 'postcode' )";
}
}
} else {
if ( $postcode )
$postcode_query[] = "( '" . esc_sql( $postcode ) . "', $tax_rate_id, 'postcode' )";
}
$wpdb->query( "INSERT INTO {$wpdb->prefix}sportspress_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES " . implode( ',', $postcode_query ) );
}
if ( isset( $tax_rate_city[ $key ] ) ) {
// Delete old
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}sportspress_tax_rate_locations WHERE tax_rate_id = %d AND location_type = 'city';", $tax_rate_id ) );
// Add changed
$city = sanitize_text_field( $tax_rate_city[ $key ] );
$cities = explode( ';', $city );
$cities = array_map( 'strtoupper', array_map( 'sanitize_text_field', $cities ) );
foreach( $cities as $city ) {
if ( $city ) {
$wpdb->insert(
$wpdb->prefix . "sportspress_tax_rate_locations",
array(
'location_code' => $city,
'tax_rate_id' => $tax_rate_id,
'location_type' => 'city',
)
);
}
}
}
$i++;
}
}
}
/**
* Output results settings.
*
* @access public
* @return void
*/
public function results_setting() {
$main_result = get_option( 'sportspress_main_result', 0 );
$args = array(
'post_type' => 'sp_result',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Results', 'sportspress' ) ?></th>
<td class="forminp">
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th scope="col"><?php _e( 'Primary', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
<th class="edit"></th>
</tr>
</thead>
<tfoot>
<tr>
<th class="radio"><input type="radio" id="sportspress_main_result_0" name="main_result" value="0" <?php checked( $main_result, 0 ); ?>></th>
<th colspan="3"><label for="main_result_0">
<?php
if ( sizeof( $data ) > 0 ):
$default = end( $data );
reset( $data );
printf( __( 'Default (%s)', 'sportspress' ), $default->post_title );
else:
_e( 'Default', 'sportspress' );
endif;
?>
</label></th>
</tr>
</tfoot>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="radio"><input type="radio" id="main_result_<?php echo $row->post_name; ?>" name="main_result" value="<?php echo $row->post_name; ?>" <?php checked( $main_result, $row->post_name ); ?>></td>
<td class="row-title"><label for="sportspress_main_result_<?php echo $row->post_name; ?>"><?php echo $row->post_title; ?></label></td>
<td><?php echo $row->post_name; ?>for / <?php echo $row->post_name; ?>against</td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; ?>
</table>
<div class="tablenav bottom">
<div class="alignleft actions">
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_result' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
</div>
<br class="clear">
</div>
</td>
</tr>
<?php
}
}
endif;
return new SP_Settings_Teams();

View File

@@ -0,0 +1,83 @@
<?php
/**
* SportsPress Text Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Settings_Text' ) ) :
/**
* SP_Settings_Text
*/
class SP_Settings_Text extends SP_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'text';
$this->label = __( 'Text', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option( 'sportspress_tax_classes' ) ) ) );
$classes_options = array();
if ( $tax_classes )
foreach ( $tax_classes as $class )
$classes_options[ sanitize_title( $class ) ] = esc_html( $class );
$settings = array( array( 'title' => __( 'Text Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'text_options' ) );
$this->strings =& SP()->text->strings;
foreach ( $this->strings as $string ):
$settings[] = array(
'title' => $string,
'id' => 'sportspress_text_' . sanitize_title( $string ),
'default' => '',
'placeholder' => $string,
'type' => 'text',
);
endforeach;
$settings[] = array( 'type' => 'sectionend', 'id' => 'text_options' );
return apply_filters( 'sportspress_event_settings', $settings ); // End text settings
}
/**
* Output the settings
*/
public function output() {
global $current_section;
$tax_classes = array_filter( array_map( 'trim', explode( "\n", get_option('sportspress_tax_classes' ) ) ) );
if ( $current_section == 'standard' || in_array( $current_section, array_map( 'sanitize_title', $tax_classes ) ) ) {
$this->output_tax_rates();
} else {
$settings = $this->get_settings();
SP_Admin_Settings::output_fields( $settings );
}
}
}
endif;
return new SP_Settings_Text();

View File

@@ -162,12 +162,5 @@ function sportspress_options_validate( $input ) {
}
function sportspress_add_menu_page() {
add_options_page(
__( 'SportsPress', 'sportspress' ),
__( 'SportsPress', 'sportspress' ),
'manage_options',
'sportspress',
'sportspress_options'
);
}
add_action( 'admin_menu', 'sportspress_add_menu_page' );

View File

@@ -0,0 +1,26 @@
<div class="wrap sportspress">
<form method="post" id="mainform" action="" enctype="multipart/form-data">
<div class="icon32 icon32-sportspress-settings" id="icon-sportspress"><br /></div><h2 class="nav-tab-wrapper sp-nav-tab-wrapper">
<?php
foreach ( $tabs as $name => $label )
echo '<a href="' . admin_url( 'options-general.php?page=sportspress&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>';
do_action( 'sportspress_settings_tabs' );
?>
</h2>
<?php
do_action( 'sportspress_sections_' . $current_tab );
do_action( 'sportspress_settings_' . $current_tab );
do_action( 'sportspress_settings_tabs_' . $current_tab ); // @deprecated hook
?>
<p class="submit">
<?php if ( ! isset( $GLOBALS['hide_save_button'] ) ) : ?>
<input name="save" class="button-primary" type="submit" value="<?php _e( 'Save changes', 'sportspress' ); ?>" />
<?php endif; ?>
<input type="hidden" name="subtab" id="last_tab" />
<?php wp_nonce_field( 'sportspress-settings' ); ?>
</p>
</form>
</div>

View File

@@ -0,0 +1,219 @@
<?php
/**
* Handle frontend forms
*
* @class SP_Frontend_Scripts
* @version 2.1.0
* @package SportsPress/Classes/
* @category Class
* @author ThemeBoy
*/
class SP_Frontend_Scripts {
/**
* Constructor
*/
public function __construct () {
add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts' ) );
add_action( 'wp_print_scripts', array( $this, 'check_jquery' ), 25 );
add_filter( 'sportspress_enqueue_styles', array( $this, 'backwards_compat' ) );
}
/**
* Get styles for the frontend
* @return array
*/
public static function get_styles() {
return apply_filters( 'sportspress_enqueue_styles', array(
'sportspress-layout' => array(
'src' => str_replace( array( 'http:', 'https:' ), '', SP()->plugin_url() ) . '/assets/css/sportspress-layout.css',
'deps' => '',
'version' => SP_VERSION,
'media' => 'all'
),
'sportspress-smallscreen' => array(
'src' => str_replace( array( 'http:', 'https:' ), '', SP()->plugin_url() ) . '/assets/css/sportspress-smallscreen.css',
'deps' => 'sportspress-layout',
'version' => SP_VERSION,
'media' => 'only screen and (max-width: ' . apply_filters( 'sportspress_style_smallscreen_breakpoint', $breakpoint = '768px' ) . ')'
),
'sportspress-general' => array(
'src' => str_replace( array( 'http:', 'https:' ), '', SP()->plugin_url() ) . '/assets/css/sportspress.css',
'deps' => '',
'version' => SP_VERSION,
'media' => 'all'
),
) );
}
/**
* Register/queue frontend scripts.
*
* @access public
* @return void
*/
public function load_scripts() {
global $post, $wp;
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$lightbox_en = get_option( 'sportspress_enable_lightbox' ) == 'yes' ? true : false;
$ajax_cart_en = get_option( 'sportspress_enable_ajax_add_to_cart' ) == 'yes' ? true : false;
$assets_path = str_replace( array( 'http:', 'https:' ), '', SP()->plugin_url() ) . '/assets/';
$frontend_script_path = $assets_path . 'js/frontend/';
// Register any scripts for later use, or used as dependencies
wp_register_script( 'chosen', $assets_path . 'js/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.0.0', true );
wp_register_script( 'jquery-blockui', $assets_path . 'js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.60', true );
wp_register_script( 'jquery-payment', $assets_path . 'js/jquery-payment/jquery.payment' . $suffix . '.js', array( 'jquery' ), '1.0.2', true );
wp_register_script( 'sp-credit-card-form', $assets_path . 'js/frontend/credit-card-form' . $suffix . '.js', array( 'jquery', 'jquery-payment' ), SP_VERSION, true );
wp_register_script( 'sp-add-to-cart-variation', $frontend_script_path . 'add-to-cart-variation' . $suffix . '.js', array( 'jquery' ), SP_VERSION, true );
wp_register_script( 'sp-single-product', $frontend_script_path . 'single-product' . $suffix . '.js', array( 'jquery' ), SP_VERSION, true );
wp_register_script( 'sp-country-select', $frontend_script_path . 'country-select' . $suffix . '.js', array( 'jquery' ), SP_VERSION, true );
wp_register_script( 'sp-address-i18n', $frontend_script_path . 'address-i18n' . $suffix . '.js', array( 'jquery' ), SP_VERSION, true );
wp_register_script( 'jquery-cookie', $assets_path . 'js/jquery-cookie/jquery.cookie' . $suffix . '.js', array( 'jquery' ), '1.3.1', true );
// Queue frontend scripts conditionally
if ( $ajax_cart_en )
wp_enqueue_script( 'sp-add-to-cart', $frontend_script_path . 'add-to-cart' . $suffix . '.js', array( 'jquery' ), SP_VERSION, true );
if ( is_cart() )
wp_enqueue_script( 'sp-cart', $frontend_script_path . 'cart' . $suffix . '.js', array( 'jquery', 'sp-country-select' ), SP_VERSION, true );
if ( is_checkout() ) {
if ( get_option( 'sportspress_enable_chosen' ) == 'yes' ) {
wp_enqueue_script( 'sp-chosen', $frontend_script_path . 'chosen-frontend' . $suffix . '.js', array( 'chosen' ), SP_VERSION, true );
wp_enqueue_style( 'sportspress_chosen_styles', $assets_path . 'css/chosen.css' );
}
wp_enqueue_script( 'sp-checkout', $frontend_script_path . 'checkout' . $suffix . '.js', array( 'jquery', 'sportspress', 'sp-country-select', 'sp-address-i18n' ), SP_VERSION, true );
}
if ( is_page( get_option( 'sportspress_myaccount_page_id' ) ) ) {
if ( get_option( 'sportspress_enable_chosen' ) == 'yes' ) {
wp_enqueue_script( 'sp-chosen', $frontend_script_path . 'chosen-frontend' . $suffix . '.js', array( 'chosen' ), SP_VERSION, true );
wp_enqueue_style( 'sportspress_chosen_styles', $assets_path . 'css/chosen.css' );
}
}
if ( is_add_payment_method_page() )
wp_enqueue_script( 'sp-add-payment-method', $frontend_script_path . 'add-payment-method' . $suffix . '.js', array( 'jquery', 'sportspress' ), SP_VERSION, true );
if ( $lightbox_en && ( is_product() || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) ) {
wp_enqueue_script( 'prettyPhoto', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js', array( 'jquery' ), '3.1.5', true );
wp_enqueue_script( 'prettyPhoto-init', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js', array( 'jquery' ), SP_VERSION, true );
wp_enqueue_style( 'sportspress_prettyPhoto_css', $assets_path . 'css/prettyPhoto.css' );
}
if ( is_product() )
wp_enqueue_script( 'sp-single-product' );
// Global frontend scripts
wp_enqueue_script( 'sportspress', $frontend_script_path . 'sportspress' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ), SP_VERSION, true );
wp_enqueue_script( 'sp-cart-fragments', $frontend_script_path . 'cart-fragments' . $suffix . '.js', array( 'jquery', 'jquery-cookie' ), SP_VERSION, true );
// Variables for JS scripts
wp_localize_script( 'sportspress', 'sportspress_params', apply_filters( 'sportspress_params', array(
'ajax_url' => SP()->ajax_url(),
'ajax_loader_url' => apply_filters( 'sportspress_ajax_loader_url', $assets_path . 'images/ajax-loader@2x.gif' ),
) ) );
wp_localize_script( 'sp-single-product', 'sp_single_product_params', apply_filters( 'sp_single_product_params', array(
'i18n_required_rating_text' => esc_attr__( 'Please select a rating', 'sportspress' ),
'review_rating_required' => get_option( 'sportspress_review_rating_required' ),
) ) );
wp_localize_script( 'sp-checkout', 'sp_checkout_params', apply_filters( 'sp_checkout_params', array(
'ajax_url' => SP()->ajax_url(),
'ajax_loader_url' => apply_filters( 'sportspress_ajax_loader_url', $assets_path . 'images/ajax-loader@2x.gif' ),
'update_order_review_nonce' => wp_create_nonce( "update-order-review" ),
'apply_coupon_nonce' => wp_create_nonce( "apply-coupon" ),
'option_guest_checkout' => get_option( 'sportspress_enable_guest_checkout' ),
'checkout_url' => add_query_arg( 'action', 'sportspress_checkout', SP()->ajax_url() ),
'is_checkout' => is_page( sp_get_page_id( 'checkout' ) ) && empty( $wp->query_vars['order-pay'] ) && ! isset( $wp->query_vars['order-received'] ) ? 1 : 0
) ) );
wp_localize_script( 'sp-address-i18n', 'sp_address_i18n_params', apply_filters( 'sp_address_i18n_params', array(
'locale' => json_encode( SP()->countries->get_country_locale() ),
'locale_fields' => json_encode( SP()->countries->get_country_locale_field_selectors() ),
'i18n_required_text' => esc_attr__( 'required', 'sportspress' ),
) ) );
wp_localize_script( 'sp-cart', 'sp_cart_params', apply_filters( 'sp_cart_params', array(
'ajax_url' => SP()->ajax_url(),
'ajax_loader_url' => apply_filters( 'sportspress_ajax_loader_url', $assets_path . 'images/ajax-loader@2x.gif' ),
'update_shipping_method_nonce' => wp_create_nonce( "update-shipping-method" ),
) ) );
wp_localize_script( 'sp-cart-fragments', 'sp_cart_fragments_params', apply_filters( 'sp_cart_fragments_params', array(
'ajax_url' => SP()->ajax_url(),
'fragment_name' => apply_filters( 'sportspress_cart_fragment_name', 'sp_fragments' )
) ) );
wp_localize_script( 'sp-add-to-cart', 'sp_add_to_cart_params', apply_filters( 'sp_add_to_cart_params', array(
'ajax_url' => SP()->ajax_url(),
'ajax_loader_url' => apply_filters( 'sportspress_ajax_loader_url', $assets_path . 'images/ajax-loader@2x.gif' ),
'i18n_view_cart' => esc_attr__( 'View Cart', 'sportspress' ),
'cart_url' => get_permalink( sp_get_page_id( 'cart' ) ),
'is_cart' => is_cart(),
'cart_redirect_after_add' => get_option( 'sportspress_cart_redirect_after_add' )
) ) );
wp_localize_script( 'sp-add-to-cart-variation', 'sp_add_to_cart_variation_params', apply_filters( 'sp_add_to_cart_variation_params', array(
'i18n_no_matching_variations_text' => esc_attr__( 'Sorry, no products matched your selection. Please choose a different combination.', 'sportspress' ),
'i18n_unavailable_text' => esc_attr__( 'Sorry, this product is unavailable. Please choose a different combination.', 'sportspress' ),
) ) );
wp_localize_script( 'sp-country-select', 'sp_country_select_params', apply_filters( 'sp_country_select_params', array(
'countries' => json_encode( array_merge( SP()->countries->get_allowed_country_states(), SP()->countries->get_shipping_country_states() ) ),
'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'sportspress' ),
) ) );
// CSS Styles
$enqueue_styles = $this->get_styles();
if ( $enqueue_styles )
foreach ( $enqueue_styles as $handle => $args )
wp_enqueue_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'] );
}
/**
* SP requires jQuery 1.8 since it uses functions like .on() for events and .parseHTML.
* If, by the time wp_print_scrips is called, jQuery is outdated (i.e not
* using the version in core) we need to deregister it and register the
* core version of the file.
*
* @access public
* @return void
*/
public function check_jquery() {
global $wp_scripts;
// Enforce minimum version of jQuery
if ( ! empty( $wp_scripts->registered['jquery']->ver ) && ! empty( $wp_scripts->registered['jquery']->src ) && 0 >= version_compare( $wp_scripts->registered['jquery']->ver, '1.8' ) ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', '/wp-includes/js/jquery/jquery.js', array(), '1.8' );
wp_enqueue_script( 'jquery' );
}
}
/**
* Provide backwards compat for old constant
* @param array $styles
* @return array
*/
public function backwards_compat( $styles ) {
if ( defined( 'WOOCOMMERCE_USE_CSS' ) ) {
_deprecated_function( 'WOOCOMMERCE_USE_CSS', '2.1', 'Styles should be removed using wp_deregister_style or the sportspress_enqueue_styles filter rather than the WOOCOMMERCE_USE_CSS constant.' );
if ( ! WOOCOMMERCE_USE_CSS )
return false;
}
return $styles;
}
}
new SP_Frontend_Scripts();

View File

@@ -353,9 +353,8 @@ class SP_Post_types {
apply_filters( 'sportspress_register_post_type_event',
array(
'labels' => array(
'name' => __( 'Schedule', 'sportspress' ),
'name' => __( 'Events', 'sportspress' ),
'singular_name' => __( 'Event', 'sportspress' ),
'all_items' => __( 'Events', 'sportspress' ),
'add_new_item' => __( 'Add New Event', 'sportspress' ),
'edit_item' => __( 'Edit Event', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
@@ -386,7 +385,6 @@ class SP_Post_types {
'labels' => array(
'name' => __( 'Calendars', 'sportspress' ),
'singular_name' => __( 'Calendar', 'sportspress' ),
'all_items' => __( 'Calendars', 'sportspress' ),
'add_new_item' => __( 'Add New Calendar', 'sportspress' ),
'edit_item' => __( 'Edit Calendar', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
@@ -417,7 +415,6 @@ class SP_Post_types {
'labels' => array(
'name' => __( 'Teams', 'sportspress' ),
'singular_name' => __( 'Team', 'sportspress' ),
'all_items' => __( 'Teams', 'sportspress' ),
'add_new_item' => __( 'Add New Team', 'sportspress' ),
'edit_item' => __( 'Edit Team', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
@@ -448,7 +445,6 @@ class SP_Post_types {
'labels' => array(
'name' => __( 'League Tables', 'sportspress' ),
'singular_name' => __( 'League Table', 'sportspress' ),
'all_items' => __( 'League Tables', 'sportspress' ),
'add_new_item' => __( 'Add New League Table', 'sportspress' ),
'edit_item' => __( 'Edit League Table', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
@@ -477,9 +473,8 @@ class SP_Post_types {
apply_filters( 'sportspress_register_post_type_player',
array(
'labels' => array(
'name' => __( 'Roster', 'sportspress' ),
'name' => __( 'Players', 'sportspress' ),
'singular_name' => __( 'Player', 'sportspress' ),
'all_items' => __( 'Players', 'sportspress' ),
'add_new_item' => __( 'Add New Player', 'sportspress' ),
'edit_item' => __( 'Edit Player', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
@@ -510,7 +505,6 @@ class SP_Post_types {
'labels' => array(
'name' => __( 'Player Lists', 'sportspress' ),
'singular_name' => __( 'Player List', 'sportspress' ),
'all_items' => __( 'Player Lists', 'sportspress' ),
'add_new_item' => __( 'Add New Player List', 'sportspress' ),
'edit_item' => __( 'Edit Player List', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
@@ -541,7 +535,6 @@ class SP_Post_types {
'labels' => array(
'name' => __( 'Staff', 'sportspress' ),
'singular_name' => __( 'Staff', 'sportspress' ),
'all_items' => __( 'Staff', 'sportspress' ),
'add_new_item' => __( 'Add New Staff', 'sportspress' ),
'edit_item' => __( 'Edit Staff', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
@@ -561,7 +554,7 @@ class SP_Post_types {
'supports' => array( 'title', 'author', 'thumbnail' ),
'has_archive' => true,
'show_in_nav_menus' => true,
'show_in_menu' => 'edit.php?post_type=sp_player',
'menu_icon' => 'dashicons-businessman',
)
)
);

View File

@@ -2264,8 +2264,13 @@ class SP_Sports {
}
public function __get( $key ) {
if ( 'options' == $key )
return $this->data;
if ( 'options' == $key ):
$option = array();
foreach ( $this->data as $slug => $data ):
$options[ $slug ] = $data['name'];
endforeach;
return $options;
endif;
return ( array_key_exists( $key, $this->data ) ? $this->data[ $key ] : null );
}

View File

@@ -241,7 +241,7 @@ final class SportsPress {
// Admin request actions (deprecating)
include_once( 'admin/hooks/admin-init.php' );
include_once( 'admin/hooks/admin-menu.php' );
//include_once( 'admin/hooks/admin-menu.php' );
//include_once( 'admin/hooks/admin-enqueue-scripts.php' );
include_once( 'admin/hooks/admin-print-styles.php' );
include_once( 'admin/hooks/admin-head.php' );