Clean up spaces, tabs, indentation, and bracket formatting

This commit is contained in:
Brian Miyaji
2021-11-10 15:41:40 +09:00
parent e58beb1201
commit 3dff686a00
285 changed files with 29638 additions and 24147 deletions

View File

@@ -60,18 +60,18 @@ p.sportspress-actions a.button-primary:focus {
.sportspress-steps:before, .sportspress-steps:before,
.sportspress-steps:after { .sportspress-steps:after {
content: " "; content: " ";
display: table; display: table;
} }
.sportspress-steps:after { .sportspress-steps:after {
clear: both; clear: both;
} }
.sportspress-steps { .sportspress-steps {
*zoom: 1; *zoom: 1;
} }
.sportspress-steps .welcome-icon i:before { .sportspress-steps .welcome-icon i:before {
color: #888; color: #888;
} }

View File

@@ -318,8 +318,8 @@ table.widefat.sp-data-table input[type="text"],
table.widefat.sp-data-table input[type="number"] { table.widefat.sp-data-table input[type="number"] {
min-width: 1.25em; min-width: 1.25em;
width: 100%; width: 100%;
margin: 1px; margin: 1px;
padding: 3px 5px; padding: 3px 5px;
} }
table.widefat.sp-data-table input[type="text"]::placeholder, table.widefat.sp-data-table input[type="text"]::placeholder,
@@ -681,28 +681,28 @@ table.widefat.sp-sortable-table tbody tr .icon {
.sp-toggle-switch + label:before, .sp-toggle-switch + label:before,
.sp-toggle-switch + label:after { .sp-toggle-switch + label:after {
display: block; display: block;
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
bottom: 0; bottom: 0;
content: ""; content: "";
} }
.sp-toggle-switch + label:before { .sp-toggle-switch + label:before {
right: 1px; right: 1px;
background-color: #e4e4e4; background-color: #e4e4e4;
border-radius: 16px; border-radius: 16px;
transition: background 0.4s; transition: background 0.4s;
} }
.sp-toggle-switch + label:after { .sp-toggle-switch + label:after {
width: 16px; width: 16px;
background-color: #fff; background-color: #fff;
border-radius: 100%; border-radius: 100%;
-webkit-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); -webkit-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
transition: margin 0.4s; transition: margin 0.4s;
} }
.sp-toggle-switch:checked + label:before { .sp-toggle-switch:checked + label:before {
@@ -735,7 +735,7 @@ table.widefat.sp-sortable-table tbody tr .icon {
clear: both; clear: both;
max-width: 382px; max-width: 382px;
width: 100%; width: 100%;
box-sizing: border-box; box-sizing: border-box;
} }
.sp-sortable-list .sp-item-float + .sp-item-float { .sp-sortable-list .sp-item-float + .sp-item-float {
@@ -743,49 +743,49 @@ table.widefat.sp-sortable-table tbody tr .icon {
} }
.sp-item-bar { .sp-item-bar {
clear: both; clear: both;
line-height: 1.5em; line-height: 1.5em;
position: relative; position: relative;
margin: 9px 0 0; margin: 9px 0 0;
} }
.sp-item-bar .sp-item-handle { .sp-item-bar .sp-item-handle {
background: #fafafa; background: #fafafa;
color: #23282d; color: #23282d;
border: 1px solid #dfdfdf; border: 1px solid #dfdfdf;
position: relative; position: relative;
padding: 10px 15px; padding: 10px 15px;
height: auto; height: auto;
min-height: 20px; min-height: 20px;
line-height: 30px; line-height: 30px;
overflow: hidden; overflow: hidden;
word-wrap: break-word; word-wrap: break-word;
} }
.sp-item-bar .sp-item-handle:hover { .sp-item-bar .sp-item-handle:hover {
border-color: #999; border-color: #999;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.1); -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.1);
box-shadow: 0 1px 2px rgba(0,0,0,.1); box-shadow: 0 1px 2px rgba(0,0,0,.1);
} }
.sp-item-bar .sp-item-title { .sp-item-bar .sp-item-title {
font-size: 13px; font-size: 13px;
font-weight: 600; font-weight: 600;
line-height: 20px; line-height: 20px;
display: block; display: block;
margin-right: 13em; margin-right: 13em;
} }
.sp-item-settings { .sp-item-settings {
display: block; display: block;
padding: 10px 0 10px 15px; padding: 10px 0 10px 15px;
position: relative; position: relative;
z-index: 10; z-index: 10;
background: #fff; background: #fff;
border: 1px solid #e5e5e5; border: 1px solid #e5e5e5;
border-top: none; border-top: none;
-webkit-box-shadow: 0 1px 1px rgba(0,0,0,.04); -webkit-box-shadow: 0 1px 1px rgba(0,0,0,.04);
box-shadow: 0 1px 1px rgba(0,0,0,.04); box-shadow: 0 1px 1px rgba(0,0,0,.04);
} }
.js .sp-item-handle { .js .sp-item-handle {
@@ -793,9 +793,9 @@ table.widefat.sp-sortable-table tbody tr .icon {
} }
.sp-sortable-list .sp-item-placeholder { .sp-sortable-list .sp-item-placeholder {
border: 1px dashed #b4b9be; border: 1px dashed #b4b9be;
margin: 9px auto 6px; margin: 9px auto 6px;
height: 42px; height: 42px;
} }
/* Logo */ /* Logo */
@@ -1225,7 +1225,7 @@ table.sp-status-table td mark.yes {
float: none; float: none;
margin-left: 0; margin-left: 0;
} }
.wp-list-table tr:not(.inline-edit-row):not(.no-items) td.column-sp_format, .wp-list-table tr:not(.inline-edit-row):not(.no-items) td.column-sp_format,
.wp-list-table tr:not(.inline-edit-row):not(.no-items) td.column-sp_icon, .wp-list-table tr:not(.inline-edit-row):not(.no-items) td.column-sp_icon,
.wp-list-table tr:not(.inline-edit-row):not(.no-items) td.column-sp_number { .wp-list-table tr:not(.inline-edit-row):not(.no-items) td.column-sp_number {
@@ -1241,7 +1241,7 @@ table.sp-status-table td mark.yes {
margin-right: 0; margin-right: 0;
padding-right: 0; padding-right: 0;
} }
.about-sportspress-wrap .sp-badge { .about-sportspress-wrap .sp-badge {
float: none; float: none;
margin: 20px auto 10px; margin: 20px auto 10px;

View File

@@ -427,9 +427,9 @@ This file is generated by `grunt build`, do not edit it by hand.
.chosen-container-multi .chosen-choices .search-choice .search-choice-close, .chosen-container-multi .chosen-choices .search-choice .search-choice-close,
.chosen-container .chosen-results-scroll-down span, .chosen-container .chosen-results-scroll-down span,
.chosen-container .chosen-results-scroll-up span { .chosen-container .chosen-results-scroll-up span {
background-image: url('../images/chosen/chosen-sprite@2x.png') !important; background-image: url('../images/chosen/chosen-sprite@2x.png') !important;
background-size: 52px 37px !important; background-size: 52px 37px !important;
background-repeat: no-repeat !important; background-repeat: no-repeat !important;
} }
} }
/* @end */ /* @end */

View File

@@ -17,4 +17,4 @@
} }
#available-widgets [class*=sp_countdown] .widget-title:before { #available-widgets [class*=sp_countdown] .widget-title:before {
content: "\f469"; content: "\f469";
} }

View File

@@ -73,4 +73,4 @@
.sp-equation-formula .button .remove:hover { .sp-equation-formula .button .remove:hover {
color: #d00; color: #d00;
} }

View File

@@ -22,7 +22,7 @@
.leaflet-marker-shadow { .leaflet-marker-shadow {
-webkit-user-select: none; -webkit-user-select: none;
-moz-user-select: none; -moz-user-select: none;
user-select: none; user-select: none;
-webkit-user-drag: none; -webkit-user-drag: none;
} }
/* Prevents IE11 from highlighting tiles in blue */ /* Prevents IE11 from highlighting tiles in blue */
@@ -86,7 +86,7 @@
width: 0; width: 0;
height: 0; height: 0;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
z-index: 800; z-index: 800;
} }
/* workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=888319 */ /* workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=888319 */
@@ -173,15 +173,15 @@
opacity: 0; opacity: 0;
-webkit-transition: opacity 0.2s linear; -webkit-transition: opacity 0.2s linear;
-moz-transition: opacity 0.2s linear; -moz-transition: opacity 0.2s linear;
transition: opacity 0.2s linear; transition: opacity 0.2s linear;
} }
.leaflet-fade-anim .leaflet-map-pane .leaflet-popup { .leaflet-fade-anim .leaflet-map-pane .leaflet-popup {
opacity: 1; opacity: 1;
} }
.leaflet-zoom-animated { .leaflet-zoom-animated {
-webkit-transform-origin: 0 0; -webkit-transform-origin: 0 0;
-ms-transform-origin: 0 0; -ms-transform-origin: 0 0;
transform-origin: 0 0; transform-origin: 0 0;
} }
.leaflet-zoom-anim .leaflet-zoom-animated { .leaflet-zoom-anim .leaflet-zoom-animated {
will-change: transform; will-change: transform;
@@ -189,13 +189,13 @@
.leaflet-zoom-anim .leaflet-zoom-animated { .leaflet-zoom-anim .leaflet-zoom-animated {
-webkit-transition: -webkit-transform 0.25s cubic-bezier(0,0,0.25,1); -webkit-transition: -webkit-transform 0.25s cubic-bezier(0,0,0.25,1);
-moz-transition: -moz-transform 0.25s cubic-bezier(0,0,0.25,1); -moz-transition: -moz-transform 0.25s cubic-bezier(0,0,0.25,1);
transition: transform 0.25s cubic-bezier(0,0,0.25,1); transition: transform 0.25s cubic-bezier(0,0,0.25,1);
} }
.leaflet-zoom-anim .leaflet-tile, .leaflet-zoom-anim .leaflet-tile,
.leaflet-pan-anim .leaflet-tile { .leaflet-pan-anim .leaflet-tile {
-webkit-transition: none; -webkit-transition: none;
-moz-transition: none; -moz-transition: none;
transition: none; transition: none;
} }
.leaflet-zoom-anim .leaflet-zoom-hide { .leaflet-zoom-anim .leaflet-zoom-hide {
@@ -435,7 +435,7 @@ svg.leaflet-image-layer.leaflet-interactive path {
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
background: #fff; background: #fff;
background: rgba(255, 255, 255, 0.5); background: rgba(255, 255, 255, 0.5);
@@ -498,8 +498,8 @@ svg.leaflet-image-layer.leaflet-interactive path {
-webkit-transform: rotate(45deg); -webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg); -moz-transform: rotate(45deg);
-ms-transform: rotate(45deg); -ms-transform: rotate(45deg);
transform: rotate(45deg); transform: rotate(45deg);
} }
.leaflet-popup-content-wrapper, .leaflet-popup-content-wrapper,
.leaflet-popup-tip { .leaflet-popup-tip {

View File

@@ -371,4 +371,4 @@ i.mce-i-sp_shortcodes_button:before, span.mce_sp_shortcodes_button:before {
text-align: center; text-align: center;
content: "\f111"; content: "\f111";
font-size: 20px; font-size: 20px;
} }

View File

@@ -1,421 +1,421 @@
.sp-setup-content p, .sp-setup-content p,
.sp-setup-content table { .sp-setup-content table {
font-size: 1em; font-size: 1em;
line-height: 1.75em; line-height: 1.75em;
color: #666; color: #666;
} }
body { body {
margin: 100px auto 24px; margin: 100px auto 24px;
box-shadow: none; box-shadow: none;
background: #f1f1f1; background: #f1f1f1;
padding: 0; padding: 0;
} }
#sp-logo { #sp-logo {
border: 0; border: 0;
margin: 24px 0; margin: 24px 0;
padding: 0; padding: 0;
text-align: center; text-align: center;
} }
#sp-logo img { #sp-logo img {
width: auto; width: auto;
height: auto; height: auto;
max-width: 100%; max-width: 100%;
max-height: 50px; max-height: 50px;
} }
.sp-setup-content { .sp-setup-content {
box-shadow: 0 1px 3px rgba(0, 0, 0, .13); box-shadow: 0 1px 3px rgba(0, 0, 0, .13);
padding: 24px 24px 0; padding: 24px 24px 0;
background: #fff; background: #fff;
zoom: 1; zoom: 1;
} }
.sp-setup-content:after { .sp-setup-content:after {
content: ""; content: "";
display: table; display: table;
clear: both; clear: both;
} }
.sp-setup-content h1, .sp-setup-content h1,
.sp-setup-content h2, .sp-setup-content h2,
.sp-setup-content h3, .sp-setup-content h3,
.sp-setup-content table { .sp-setup-content table {
margin: 0 0 24px; margin: 0 0 24px;
border: 0; border: 0;
padding: 0; padding: 0;
color: #666; color: #666;
clear: none; clear: none;
} }
.sp-setup-content p { .sp-setup-content p {
margin: 0 0 24px; margin: 0 0 24px;
} }
.sp-setup-content a { .sp-setup-content a {
color: #00a69c; color: #00a69c;
} }
.sp-setup-content a:focus, .sp-setup-content a:focus,
.sp-setup-content a:hover { .sp-setup-content a:hover {
color: #111; color: #111;
} }
.sp-setup-content .form-table { .sp-setup-content .form-table {
width: 100%; width: 100%;
border-top: 1px solid #eee; border-top: 1px solid #eee;
} }
.sp-setup-content .form-table th { .sp-setup-content .form-table th {
width: 30%; width: 30%;
vertical-align: top; vertical-align: top;
font-weight: 700; font-weight: 700;
} }
.sp-setup-content .form-table td { .sp-setup-content .form-table td {
vertical-align: top; vertical-align: top;
} }
.sp-setup-content .form-table td input, .sp-setup-content .form-table td input,
.sp-setup-content .form-table td select { .sp-setup-content .form-table td select {
width: 100%; width: 100%;
box-sizing: border-box; box-sizing: border-box;
} }
.sp-setup-content .form-table td input[size] { .sp-setup-content .form-table td input[size] {
width: auto; width: auto;
} }
.sp-setup-content .form-table td ol, .sp-setup-content .form-table td ol,
.sp-setup-content .form-table td ul { .sp-setup-content .form-table td ul {
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
.sp-setup-content .form-table td ul { .sp-setup-content .form-table td ul {
list-style: none; list-style: none;
} }
.sp-setup-content .form-table td li { .sp-setup-content .form-table td li {
margin-bottom: 10px; margin-bottom: 10px;
} }
.sp-setup-content .form-table td li:last-child { .sp-setup-content .form-table td li:last-child {
margin-bottom: 0; margin-bottom: 0;
} }
.sp-setup-content .form-table td .description { .sp-setup-content .form-table td .description {
line-height: 1.5em; line-height: 1.5em;
display: block; display: block;
margin: .25em 0 0; margin: .25em 0 0;
color: #999; color: #999;
font-style: italic; font-style: italic;
} }
.sp-setup-content .form-table td .input-checkbox, .sp-setup-content .form-table td .input-checkbox,
.sp-setup-content .form-table td .input-radio { .sp-setup-content .form-table td .input-radio {
width: auto; width: auto;
box-sizing: inherit; box-sizing: inherit;
padding: inherit; padding: inherit;
margin: 0 .5em 0 0; margin: 0 .5em 0 0;
box-shadow: none; box-shadow: none;
} }
.sp-setup-content .form-table .section_title td { .sp-setup-content .form-table .section_title td {
padding: 0; padding: 0;
} }
.sp-setup-content .form-table .section_title td h2, .sp-setup-content .form-table .section_title td h2,
.sp-setup-content .form-table .section_title td p { .sp-setup-content .form-table .section_title td p {
margin: 12px 0 0; margin: 12px 0 0;
} }
.sp-setup-content .form-table td, .sp-setup-content .form-table td,
.sp-setup-content .form-table th { .sp-setup-content .form-table th {
padding: 14px 0; padding: 14px 0;
margin: 0; margin: 0;
border: 0; border: 0;
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
} }
.sp-setup-content .form-table td:first-child, .sp-setup-content .form-table td:first-child,
.sp-setup-content .form-table th:first-child { .sp-setup-content .form-table th:first-child {
padding-right: 9px; padding-right: 9px;
} }
.sp-setup-content .form-table th .sp-desc-tip { .sp-setup-content .form-table th .sp-desc-tip {
line-height: 1.4; line-height: 1.4;
} }
.sp-setup-content .form-table .sp-chosen-container { .sp-setup-content .form-table .sp-chosen-container {
display: block; display: block;
} }
.sp-setup-content .form-table .sp-location-picker { .sp-setup-content .form-table .sp-location-picker {
width: 100%; width: 100%;
height: 320px; height: 320px;
margin: 0.5em 0 0; margin: 0.5em 0 0;
} }
.sp-setup-content .twitter-share-button { .sp-setup-content .twitter-share-button {
float: right; float: right;
} }
.sp-setup-content .sp-banner { .sp-setup-content .sp-banner {
margin: 0 -24px 24px; margin: 0 -24px 24px;
} }
.sp-setup-content .sp-banner img { .sp-setup-content .sp-banner img {
display: block; display: block;
width: auto; width: auto;
height: auto; height: auto;
max-width: 100%; max-width: 100%;
} }
.sp-setup-content .sp-setup-next-steps { .sp-setup-content .sp-setup-next-steps {
overflow: hidden; overflow: hidden;
margin: 0 0 24px; margin: 0 0 24px;
} }
.sp-setup-content .sp-setup-next-steps h2 { .sp-setup-content .sp-setup-next-steps h2 {
margin-bottom: 12px; margin-bottom: 12px;
} }
.sp-setup-content .sp-setup-next-steps .sp-setup-next-steps-first { .sp-setup-content .sp-setup-next-steps .sp-setup-next-steps-first {
float: left; float: left;
width: 50%; width: 50%;
box-sizing: border-box; box-sizing: border-box;
} }
.sp-setup-content .sp-setup-next-steps .sp-setup-next-steps-last { .sp-setup-content .sp-setup-next-steps .sp-setup-next-steps-last {
float: right; float: right;
width: 50%; width: 50%;
box-sizing: border-box; box-sizing: border-box;
} }
.sp-setup-content .sp-setup-next-steps ul { .sp-setup-content .sp-setup-next-steps ul {
padding: 0 2em 0 0; padding: 0 2em 0 0;
list-style: none; list-style: none;
margin: 0; margin: 0;
} }
.sp-setup-content .sp-setup-next-steps ul li .button { .sp-setup-content .sp-setup-next-steps ul li .button {
display: block; display: block;
padding: 0 0 .75em; padding: 0 0 .75em;
} }
.sp-setup-content .sp-setup-next-steps ul li .button-first-event { .sp-setup-content .sp-setup-next-steps ul li .button-first-event {
background-color: #3bbab3; background-color: #3bbab3;
border-color: #15a29a; border-color: #15a29a;
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a;
text-shadow: 0 -1px 1px #15a29a, 1px 0 1px #15a29a, 0 1px 1px #15a29a, -1px 0 1px #15a29a; text-shadow: 0 -1px 1px #15a29a, 1px 0 1px #15a29a, 0 1px 1px #15a29a, -1px 0 1px #15a29a;
font-size: 1em; font-size: 1em;
height: auto; height: auto;
line-height: 1.75em; line-height: 1.75em;
margin: 0 0 .75em; margin: 0 0 .75em;
opacity: 1; opacity: 1;
padding: 1em; padding: 1em;
text-align: center; text-align: center;
} }
.sp-setup-content .sp-setup-next-steps ul li .button-first-event:active, .sp-setup-content .sp-setup-next-steps ul li .button-first-event:active,
.sp-setup-content .sp-setup-next-steps ul li .button-first-event:focus, .sp-setup-content .sp-setup-next-steps ul li .button-first-event:focus,
.sp-setup-content .sp-setup-next-steps ul li .button-first-event:hover { .sp-setup-content .sp-setup-next-steps ul li .button-first-event:hover {
background: #15a29a; background: #15a29a;
border-color: #15a29a; border-color: #15a29a;
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a;
} }
.sp-setup-content .sp-setup-next-steps ul li a:before { .sp-setup-content .sp-setup-next-steps ul li a:before {
color: #82878c; color: #82878c;
font: 400 20px/1 dashicons; font: 400 20px/1 dashicons;
speak: none; speak: none;
display: inline-block; display: inline-block;
padding: 0 10px 0 0; padding: 0 10px 0 0;
top: 1px; top: 1px;
position: relative; position: relative;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
text-decoration: none!important; text-decoration: none!important;
vertical-align: top; vertical-align: top;
} }
.sp-setup-content .sp-setup-next-steps ul .learn-more a:before { .sp-setup-content .sp-setup-next-steps ul .learn-more a:before {
content: "\f105"; content: "\f105";
} }
.sp-setup-content .sp-setup-next-steps ul .video-walkthrough a:before { .sp-setup-content .sp-setup-next-steps ul .video-walkthrough a:before {
content: "\f126"; content: "\f126";
} }
.sp-setup-content .sp-setup-next-steps ul .newsletter a:before { .sp-setup-content .sp-setup-next-steps ul .newsletter a:before {
content: "\f465"; content: "\f465";
} }
.sp-setup-content .updated { .sp-setup-content .updated {
padding: 24px 24px 0; padding: 24px 24px 0;
margin: 0 0 24px; margin: 0 0 24px;
overflow: hidden; overflow: hidden;
background: #f5f5f5; background: #f5f5f5;
} }
.sp-setup-content .updated p { .sp-setup-content .updated p {
padding: 0; padding: 0;
margin: 0 0 12px; margin: 0 0 12px;
} }
.sp-setup-content .updated p:last-child { .sp-setup-content .updated p:last-child {
margin: 0 0 24px; margin: 0 0 24px;
} }
.sp-setup-steps { .sp-setup-steps {
padding: 0 0 24px; padding: 0 0 24px;
margin: 0; margin: 0;
list-style: none; list-style: none;
overflow: hidden; overflow: hidden;
color: #ccc; color: #ccc;
width: 100%; width: 100%;
display: -webkit-inline-flex; display: -webkit-inline-flex;
display: -ms-inline-flexbox; display: -ms-inline-flexbox;
display: inline-flex; display: inline-flex;
} }
.sp-setup-steps li { .sp-setup-steps li {
width: 20%; width: 20%;
float: left; float: left;
padding: 0 0 .8em; padding: 0 0 .8em;
margin: 0; margin: 0;
text-align: center; text-align: center;
position: relative; position: relative;
border-bottom: 4px solid #ccc; border-bottom: 4px solid #ccc;
line-height: 1.4em; line-height: 1.4em;
} }
.sp-setup-steps li:before { .sp-setup-steps li:before {
content: ""; content: "";
border: 4px solid #ccc; border: 4px solid #ccc;
border-radius: 100%; border-radius: 100%;
width: 4px; width: 4px;
height: 4px; height: 4px;
position: absolute; position: absolute;
bottom: 0; bottom: 0;
left: 50%; left: 50%;
margin-left: -6px; margin-left: -6px;
margin-bottom: -8px; margin-bottom: -8px;
background: #fff; background: #fff;
} }
.sp-setup-steps li.active { .sp-setup-steps li.active {
border-color: #00a69c; border-color: #00a69c;
color: #00a69c; color: #00a69c;
} }
.sp-setup-steps li.active:before { .sp-setup-steps li.active:before {
border-color: #00a69c; border-color: #00a69c;
} }
.sp-setup-steps li.done { .sp-setup-steps li.done {
border-color: #00a69c; border-color: #00a69c;
color: #00a69c; color: #00a69c;
} }
.sp-setup-steps li.done:before { .sp-setup-steps li.done:before {
border-color: #00a69c; border-color: #00a69c;
background: #00a69c; background: #00a69c;
} }
.sp-setup .sp-setup-actions:after { .sp-setup .sp-setup-actions:after {
content: ""; content: "";
display: table; display: table;
clear: both; clear: both;
} }
.sp-setup .sp-setup-actions .button { .sp-setup .sp-setup-actions .button {
float: right; float: right;
font-size: 1.25em; font-size: 1.25em;
padding: .5em 1em; padding: .5em 1em;
line-height: 1em; line-height: 1em;
margin-right: .5em; margin-right: .5em;
margin-bottom: 2px; margin-bottom: 2px;
height: auto; height: auto;
border-radius: 4px; border-radius: 4px;
} }
.sp-setup .sp-setup-actions .button-primary { .sp-setup .sp-setup-actions .button-primary {
background-color: #3bbab3; background-color: #3bbab3;
border-color: #15a29a; border-color: #15a29a;
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a;
text-shadow: 0 -1px 1px #15a29a, 1px 0 1px #15a29a, 0 1px 1px #15a29a, -1px 0 1px #15a29a; text-shadow: 0 -1px 1px #15a29a, 1px 0 1px #15a29a, 0 1px 1px #15a29a, -1px 0 1px #15a29a;
float: right; float: right;
margin: 0 0 0 1em; margin: 0 0 0 1em;
opacity: 1; opacity: 1;
} }
.sp-setup .sp-setup-actions .button-primary:active, .sp-setup .sp-setup-actions .button-primary:active,
.sp-setup .sp-setup-actions .button-primary:focus, .sp-setup .sp-setup-actions .button-primary:focus,
.sp-setup .sp-setup-actions .button-primary:hover { .sp-setup .sp-setup-actions .button-primary:hover {
background: #15a29a; background: #15a29a;
border-color: #15a29a; border-color: #15a29a;
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #15a29a;
} }
.sp-setup .sp-setup-actions .button-muted { .sp-setup .sp-setup-actions .button-muted {
border: none; border: none;
background: transparent; background: transparent;
-webkit-box-shadow: none; -webkit-box-shadow: none;
box-shadow: none; box-shadow: none;
padding: 0; padding: 0;
margin: .55em 0.05em 0.65em; margin: .55em 0.05em 0.65em;
color: #ccc; color: #ccc;
} }
.sp-setup .sp-setup-actions .button-muted:hover { .sp-setup .sp-setup-actions .button-muted:hover {
color: #999; color: #999;
} }
.sp-return-to-dashboard { .sp-return-to-dashboard {
font-size: .85em; font-size: .85em;
margin: 1.18em 0; margin: 1.18em 0;
display: block; display: block;
text-align: center; text-align: center;
} }
.sp-return-to-dashboard a { .sp-return-to-dashboard a {
color: #b5b5b5; color: #b5b5b5;
} }
.sp-return-to-dashboard a:hover { .sp-return-to-dashboard a:hover {
color: #888; color: #888;
} }
/* Media Queries */ /* Media Queries */
@media screen and (max-width: 782px) { @media screen and (max-width: 782px) {
.sp-setup-content .form-table tbody th { .sp-setup-content .form-table tbody th {
width: auto width: auto
}; };
} }
@media screen and (min-width: 783px) { @media screen and (min-width: 783px) {
.sp-setup-content .form-table td li input { .sp-setup-content .form-table td li input {
width: 40%; width: 40%;
} }
.sp-setup-content .form-table td .player input { .sp-setup-content .form-table td .player input {
width: 40%; width: 40%;
} }
.sp-setup-content .form-table td .player .player-number { .sp-setup-content .form-table td .player .player-number {
width: 11%; width: 11%;
} }
.sp-setup-content .form-table td .staff .staff-name { .sp-setup-content .form-table td .staff .staff-name {
width: 52%; width: 52%;
} }
} }

View File

@@ -240,4 +240,4 @@ table, .sp-sitemap caption, .sp-sitemap tbody, .sp-sitemap tfoot, .sp-sitemap th
.sp-sitemap .sp-utility { .sp-sitemap .sp-utility {
max-width: none; max-width: none;
} }
} }

View File

@@ -6,28 +6,28 @@
*/ */
.sp-tournament-bracket .sp-team .sp-team-name:before { .sp-tournament-bracket .sp-team .sp-team-name:before {
border-left-color: #e5e5e5 !important; border-left-color: #e5e5e5 !important;
border-right-color: #e5e5e5 !important; border-right-color: #e5e5e5 !important;
left: -10px !important; left: -10px !important;
} }
.sp-tournament-bracket .sp-team-flip .sp-team-name:before { .sp-tournament-bracket .sp-team-flip .sp-team-name:before {
left: auto !important; left: auto !important;
right: -10px !important; right: -10px !important;
} }
.sp-tournament-bracket .sp-team.sp-first-round .sp-team-name { .sp-tournament-bracket .sp-team.sp-first-round .sp-team-name {
margin-left: -1px !important; margin-left: -1px !important;
} }
.sp-tournament-bracket .sp-team.sp-last-round .sp-team-name { .sp-tournament-bracket .sp-team.sp-last-round .sp-team-name {
margin-right: -1px !important; margin-right: -1px !important;
} }
.sp-template-event-performance-icons .sp-performance-icons { .sp-template-event-performance-icons .sp-performance-icons {
text-align: right !important; text-align: right !important;
} }
.sp-data-table .data-name { .sp-data-table .data-name {
text-align: left !important; text-align: left !important;
} }

View File

@@ -6,28 +6,28 @@
*/ */
.sp-tournament-bracket .sp-team .sp-team-name:before { .sp-tournament-bracket .sp-team .sp-team-name:before {
border-right-color: #e5e5e5 !important; border-right-color: #e5e5e5 !important;
border-left-color: #e5e5e5 !important; border-left-color: #e5e5e5 !important;
right: -10px !important; right: -10px !important;
} }
.sp-tournament-bracket .sp-team-flip .sp-team-name:before { .sp-tournament-bracket .sp-team-flip .sp-team-name:before {
right: auto !important; right: auto !important;
left: -10px !important; left: -10px !important;
} }
.sp-tournament-bracket .sp-team.sp-first-round .sp-team-name { .sp-tournament-bracket .sp-team.sp-first-round .sp-team-name {
margin-right: -1px !important; margin-right: -1px !important;
} }
.sp-tournament-bracket .sp-team.sp-last-round .sp-team-name { .sp-tournament-bracket .sp-team.sp-last-round .sp-team-name {
margin-left: -1px !important; margin-left: -1px !important;
} }
.sp-template-event-performance-icons .sp-performance-icons { .sp-template-event-performance-icons .sp-performance-icons {
text-align: left !important; text-align: left !important;
} }
.sp-data-table .data-name { .sp-data-table .data-name {
text-align: right !important; text-align: right !important;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -61,10 +61,10 @@
margin: 0 10px; margin: 0 10px;
color: inherit; color: inherit;
opacity: 0.5; opacity: 0.5;
transition: all .3s; transition: all .3s;
} }
.sp-tab-menu-item a:focus { .sp-tab-menu-item a:focus {
outline: none; outline: none;
} }
.sp-tab-menu-item-active a, .sp-tab-menu-item-active a,
.sp-tab-menu-item a:hover { .sp-tab-menu-item a:hover {
@@ -90,7 +90,7 @@
.sp-data-table { .sp-data-table {
width: 100%; width: 100%;
table-layout: auto; table-layout: auto;
border-spacing: 0; border-spacing: 0;
} }
.sp-paginated-table { .sp-paginated-table {
margin-bottom: 0; margin-bottom: 0;
@@ -310,12 +310,12 @@
color: #f4d014; color: #f4d014;
} }
.sp-event-performance .sp-event-star-number { .sp-event-performance .sp-event-star-number {
margin-left: -20px; margin-left: -20px;
width: 20px; width: 20px;
text-align: center; text-align: center;
display: inline-block; display: inline-block;
font-size: smaller; font-size: smaller;
line-height: 20px; line-height: 20px;
} }
/* Event Performance (Icons) */ /* Event Performance (Icons) */
@@ -335,12 +335,12 @@
} }
.sp-template-event-performance-icons .sp-player-position { .sp-template-event-performance-icons .sp-player-position {
display: block; display: block;
} }
/* Event Calendar */ /* Event Calendar */
.sp-event-calendar { .sp-event-calendar {
border-spacing: 0; border-spacing: 0;
} }
.sp-event-calendar a { .sp-event-calendar a {
text-decoration: none; text-decoration: none;
@@ -635,11 +635,11 @@ span.sp_event_spec_label {
display: inline-block; display: inline-block;
margin: 0 0.25em; margin: 0 0.25em;
} }
.sp-template-logo + .sp-post-content { .sp-template-logo + .sp-post-content {
clear: left; clear: left;
} }
.sp-template-photo + .sp-post-content { .sp-template-photo + .sp-post-content {
clear: none; clear: none;
} }
@@ -664,15 +664,15 @@ span.sp_event_spec_label {
text-align: right; text-align: right;
float: right; float: right;
} }
.sp-template-event-logos-block .logo-odd img { .sp-template-event-logos-block .logo-odd img {
margin-right: 10px; margin-right: 10px;
} }
.sp-template-event-logos-block .logo-even img { .sp-template-event-logos-block .logo-even img {
margin-left: 10px; margin-left: 10px;
} }
.sp-template-event-logos-block .sp-team-name { .sp-template-event-logos-block .sp-team-name {
display: inline; display: inline;
clear: none; clear: none;

View File

@@ -6,4 +6,4 @@
.sportspress-page .entry-content h4:first-child { .sportspress-page .entry-content h4:first-child {
margin-top: 36px; margin-top: 36px;
} }

View File

@@ -1,26 +1,38 @@
jQuery(document).ready(function($){ jQuery( document ).ready(
function($){
// Color picker // Color picker
$('.colorpick').iris( { $( '.colorpick' ).iris(
change: function(event, ui){ {
$(this).css( { backgroundColor: ui.color.toString() } ); change: function(event, ui){
}, $( this ).css( { backgroundColor: ui.color.toString() } );
hide: true, },
border: true hide: true,
} ).each( function() { border: true
$(this).css( { backgroundColor: $(this).val() } ); }
}) ).each(
.click(function(){ function() {
$('.iris-picker').hide(); $( this ).css( { backgroundColor: $( this ).val() } );
$(this).closest('.sp-color-box, td').find('.iris-picker').show(); }
}); )
.click(
function(){
$( '.iris-picker' ).hide();
$( this ).closest( '.sp-color-box, td' ).find( '.iris-picker' ).show();
}
);
$('body').click(function() { $( 'body' ).click(
$('.iris-picker').hide(); function() {
}); $( '.iris-picker' ).hide();
}
);
$('.sp-color-box, .colorpick').click(function(event){ $( '.sp-color-box, .colorpick' ).click(
event.stopPropagation(); function(event){
}); event.stopPropagation();
}
);
}); }
);

View File

@@ -1,11 +1,18 @@
jQuery(document).ready(function($){ jQuery( document ).ready(
function($){
// Dashboard countdown // Dashboard countdown
$("#sportspress_dashboard_status .sp_status_list li.countdown").each(function() { $( "#sportspress_dashboard_status .sp_status_list li.countdown" ).each(
var $this = $(this), finalDate = $(this).data('countdown'); function() {
$this.countdown(finalDate, function(event) { var $this = $( this ), finalDate = $( this ).data( 'countdown' );
$this.find('strong').html(event.strftime("%D "+localized_strings.days+" %H:%M:%S")); $this.countdown(
}); finalDate,
}); function(event) {
$this.find( 'strong' ).html( event.strftime( "%D " + localized_strings.days + " %H:%M:%S" ) );
}
);
}
);
}); }
);

View File

@@ -3,51 +3,63 @@
$shortcodes = ''; $shortcodes = '';
$options = array( $options = array(
'event' => array( 'event' => array(
'details', 'results', 'performance', 'venue', 'officials', 'teams', 'full', 'details',
), 'results',
'team' => array(), 'performance',
'player' => array( 'venue',
'details', 'statistics' 'officials',
), 'teams',
'full',
),
'team' => array(),
'player' => array(
'details',
'statistics',
),
); );
$options = apply_filters( 'sportspress_shortcodes', $options ); $options = apply_filters( 'sportspress_shortcodes', $options );
foreach ( $options as $name => $group ) { foreach ( $options as $name => $group ) {
if ( empty( $group ) ) continue; if ( empty( $group ) ) {
$shortcodes .= $name . '[' . implode( '|', $group ) . ']'; continue;
}
$shortcodes .= $name . '[' . implode( '|', $group ) . ']';
} }
$raw = apply_filters( 'sportspress_tinymce_strings', array( $raw = apply_filters(
'shortcodes' => $shortcodes, 'sportspress_tinymce_strings',
'insert' => __( 'SportsPress Shortcodes', 'sportspress' ), array(
'auto' => __( 'Auto', 'sportspress' ), 'shortcodes' => $shortcodes,
'manual' => __( 'Manual', 'sportspress' ), 'insert' => __( 'SportsPress Shortcodes', 'sportspress' ),
'select' => __( 'Select...', 'sportspress' ), 'auto' => __( 'Auto', 'sportspress' ),
'event' => __( 'Event', 'sportspress' ), 'manual' => __( 'Manual', 'sportspress' ),
'details' => __( 'Details', 'sportspress' ), 'select' => __( 'Select...', 'sportspress' ),
'results' => __( 'Results', 'sportspress' ), 'event' => __( 'Event', 'sportspress' ),
'countdown' => __( 'Countdown', 'sportspress' ), 'details' => __( 'Details', 'sportspress' ),
'performance' => __( 'Box Score', 'sportspress' ), 'results' => __( 'Results', 'sportspress' ),
'venue' => __( 'Venue', 'sportspress' ), 'countdown' => __( 'Countdown', 'sportspress' ),
'officials' => __( 'Officials', 'sportspress' ), 'performance' => __( 'Box Score', 'sportspress' ),
'teams' => __( 'Teams', 'sportspress' ), 'venue' => __( 'Venue', 'sportspress' ),
'full' => __( 'Full Info', 'sportspress' ), 'officials' => __( 'Officials', 'sportspress' ),
'calendar' => __( 'Calendar', 'sportspress' ), 'teams' => __( 'Teams', 'sportspress' ),
'statistics' => __( 'Statistics', 'sportspress' ), 'full' => __( 'Full Info', 'sportspress' ),
'team' => __( 'Team', 'sportspress' ), 'calendar' => __( 'Calendar', 'sportspress' ),
'standings' => __( 'League Table', 'sportspress' ), 'statistics' => __( 'Statistics', 'sportspress' ),
'player' => __( 'Player', 'sportspress' ), 'team' => __( 'Team', 'sportspress' ),
'list' => __( 'List', 'sportspress' ), 'standings' => __( 'League Table', 'sportspress' ),
'blocks' => __( 'Blocks', 'sportspress' ), 'player' => __( 'Player', 'sportspress' ),
'gallery' => __( 'Gallery', 'sportspress' ), 'list' => __( 'List', 'sportspress' ),
)); 'blocks' => __( 'Blocks', 'sportspress' ),
'gallery' => __( 'Gallery', 'sportspress' ),
)
);
$formatted = array(); $formatted = array();
foreach ( $raw as $key => $value ) { foreach ( $raw as $key => $value ) {
$formatted[] = $key . ': "' . esc_js( $value ) . '"'; $formatted[] = $key . ': "' . esc_js( $value ) . '"';
} }
$strings = 'tinyMCE.addI18n({' . _WP_Editors::$mce_locale . ':{ $strings = 'tinyMCE.addI18n({' . _WP_Editors::$mce_locale . ':{

View File

@@ -1,42 +1,58 @@
/* global tinymce */ /* global tinymce */
( function () { ( function () {
tinymce.PluginManager.add( 'sp_shortcodes_button', function( editor, url ) { tinymce.PluginManager.add(
var ed = tinymce.activeEditor; 'sp_shortcodes_button',
function( editor, url ) {
var ed = tinymce.activeEditor;
var groups = ed.getLang( 'sportspress.shortcodes' ).split("]"); var groups = ed.getLang( 'sportspress.shortcodes' ).split( "]" );
var menu = new Array(); var menu = new Array();
groups.forEach(function(g) { groups.forEach(
if ( "" == g ) return; function(g) {
var p = g.split("["); if ( "" == g ) {
var label = p.shift(); return;
var variations = p.shift();
var shortcodes = typeof variations!== 'undefined' ? variations.split("|") : [];
var submenu = new Array();
shortcodes.forEach(function(s) {
submenu.push({
text: ed.getLang( 'sportspress.' + s ),
onclick: function() {
// triggers the thickbox
var width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.' + label ) + ' - ' + ed.getLang( 'sportspress.' + s ), 'admin-ajax.php?action=sportspress_' + label + '_' + s + '_shortcode&width=' + W + '&height=' + H );
} }
}); var p = g.split( "[" );
}); var label = p.shift();
menu.push({ var variations = p.shift();
text: ed.getLang( 'sportspress.' + label ), var shortcodes = typeof variations !== 'undefined' ? variations.split( "|" ) : [];
menu: submenu var submenu = new Array();
}); shortcodes.forEach(
}); function(s) {
submenu.push(
{
text: ed.getLang( 'sportspress.' + s ),
onclick: function() {
// triggers the thickbox
var width = jQuery( window ).width(), H = jQuery( window ).height(), W = ( 720 < width ) ? 720 : width;
W = W - 80;
H = H - 84;
tb_show( ed.getLang( 'sportspress.' + label ) + ' - ' + ed.getLang( 'sportspress.' + s ), 'admin-ajax.php?action=sportspress_' + label + '_' + s + '_shortcode&width=' + W + '&height=' + H );
}
}
);
}
);
menu.push(
{
text: ed.getLang( 'sportspress.' + label ),
menu: submenu
}
);
}
);
editor.addButton( 'sp_shortcodes_button', { editor.addButton(
title: ed.getLang('sportspress.insert'), 'sp_shortcodes_button',
text: false, {
icon: false, title: ed.getLang( 'sportspress.insert' ),
type: 'menubutton', text: false,
menu: menu icon: false,
}); type: 'menubutton',
}); menu: menu
}
);
}
);
})(); })();

View File

@@ -1,37 +1,55 @@
jQuery(document).ready(function($){ jQuery( document ).ready(
$("#title").keyup(function() { function($){
val = $(this).val(); $( "#title" ).keyup(
if ( val == '' ) val = 'f(x)'; function() {
$(".sp-equation-variable").text( val + ' =' ); val = $( this ).val();
}); if ( val == '' ) {
val = 'f(x)';
}
$( ".sp-equation-variable" ).text( val + ' =' );
}
);
$(".sp-equation-parts .button").draggable({ $( ".sp-equation-parts .button" ).draggable(
appendTo: "body", {
helper: "clone", appendTo: "body",
cursor: "move", helper: "clone",
distance: 10, cursor: "move",
containment: "#sp_equationdiv", distance: 10,
}).click(function() { containment: "#sp_equationdiv",
$("<label class='button'></label>").text( $(this).text() ).append("<span class='remove'>&times;</span><input name='sp_equation[]' type='hidden' value='" + $(this).data("variable") + "'>").appendTo( $(".sp-equation-formula") ); }
}); ).click(
function() {
$( "<label class='button'></label>" ).text( $( this ).text() ).append( "<span class='remove'>&times;</span><input name='sp_equation[]' type='hidden' value='" + $( this ).data( "variable" ) + "'>" ).appendTo( $( ".sp-equation-formula" ) );
}
);
$(".sp-equation").droppable({ $( ".sp-equation" ).droppable(
activeClass: "ui-state-active", {
hoverClass: "ui-state-hover", activeClass: "ui-state-active",
accept: ".button:not(.ui-sortable-helper)", hoverClass: "ui-state-hover",
drop: function( event, ui ) { accept: ".button:not(.ui-sortable-helper)",
$("<label class='button'></label>").text( ui.draggable.text() ).append("<span class='remove'>&times;</span><input name='sp_equation[]' type='hidden' value='" + ui.draggable.data("variable") + "'>").appendTo( $(".sp-equation-formula") ); drop: function( event, ui ) {
} $( "<label class='button'></label>" ).text( ui.draggable.text() ).append( "<span class='remove'>&times;</span><input name='sp_equation[]' type='hidden' value='" + ui.draggable.data( "variable" ) + "'>" ).appendTo( $( ".sp-equation-formula" ) );
}).sortable({ }
items: ".button", }
tolerance: "pointer", ).sortable(
containment: "#sp_equationdiv", {
sort: function() { items: ".button",
$( this ).removeClass( "ui-state-active" ); tolerance: "pointer",
} containment: "#sp_equationdiv",
}); sort: function() {
$( this ).removeClass( "ui-state-active" );
}
}
);
$(".sp-equation-formula").on("click", ".button .remove", function() { $( ".sp-equation-formula" ).on(
$(this).closest(".button").remove(); "click",
}); ".button .remove",
}); function() {
$( this ).closest( ".button" ).remove();
}
);
}
);

View File

@@ -1,37 +1,52 @@
jQuery(document).ready(function($){ jQuery( document ).ready(
function($){
// Icon picker // Icon picker
$('.sp-icons input').on('change', function() { $( '.sp-icons input' ).on(
if ('' == $(this).val()) { 'change',
$('.sp-custom-colors').hide(); function() {
$('.sp-custom-thumbnail').show(); if ('' == $( this ).val()) {
} else { $( '.sp-custom-colors' ).hide();
$('.sp-custom-thumbnail').hide(); $( '.sp-custom-thumbnail' ).show();
$('.sp-custom-colors').show(); } else {
} $( '.sp-custom-thumbnail' ).hide();
}); $( '.sp-custom-colors' ).show();
}
}
);
// Color picker // Color picker
$('.colorpick').iris( { $( '.colorpick' ).iris(
change: function(event, ui){ {
$(this).css( { backgroundColor: ui.color.toString() } ); change: function(event, ui){
}, $( this ).css( { backgroundColor: ui.color.toString() } );
hide: true, },
border: true hide: true,
} ).each( function() { border: true
$(this).css( { backgroundColor: $(this).val() } ); }
}) ).each(
.click(function(){ function() {
$('.iris-picker').hide(); $( this ).css( { backgroundColor: $( this ).val() } );
$(this).closest('.sp-color-box-for-icon, td').find('.iris-picker').show(); }
}); )
.click(
function(){
$( '.iris-picker' ).hide();
$( this ).closest( '.sp-color-box-for-icon, td' ).find( '.iris-picker' ).show();
}
);
$('body').click(function() { $( 'body' ).click(
$('.iris-picker').hide(); function() {
}); $( '.iris-picker' ).hide();
}
);
$('.sp-color-box-for-icon, .colorpick').click(function(event){ $( '.sp-color-box-for-icon, .colorpick' ).click(
event.stopPropagation(); function(event){
}); event.stopPropagation();
}
);
}); }
);

View File

@@ -24,56 +24,72 @@
var $post_row = $( '#post-' + $post_id ); var $post_row = $( '#post-' + $post_id );
// get the data // get the data
var $number = $( '.column-sp_number', $post_row ).text(); var $number = $( '.column-sp_number', $post_row ).text();
var $current_teams = String( $( '.column-sp_team', $post_row ).find( '.sp-player-teams' ).data( 'current-teams' ) ).split(','); var $current_teams = String( $( '.column-sp_team', $post_row ).find( '.sp-player-teams' ).data( 'current-teams' ) ).split( ',' );
var $past_teams = String( $( '.column-sp_team', $post_row ).find( '.sp-player-teams' ).data( 'past-teams' ) ).split(','); var $past_teams = String( $( '.column-sp_team', $post_row ).find( '.sp-player-teams' ).data( 'past-teams' ) ).split( ',' );
// populate the data // populate the data
$( ':input[name="sp_number"]', $edit_row ).val( $number ); $( ':input[name="sp_number"]', $edit_row ).val( $number );
$( ':input[name="sp_current_team[]"]', $edit_row ).each(function() { $( ':input[name="sp_current_team[]"]', $edit_row ).each(
$(this).prop("checked", ($.inArray($(this).val(), $current_teams ) != -1)); function() {
}); $( this ).prop( "checked", ($.inArray( $( this ).val(), $current_teams ) != -1) );
$( ':input[name="sp_past_team[]"]', $edit_row ).each(function() { }
$(this).prop("checked", ($.inArray($(this).val(), $past_teams ) != -1)); );
}); $( ':input[name="sp_past_team[]"]', $edit_row ).each(
function() {
$( this ).prop( "checked", ($.inArray( $( this ).val(), $past_teams ) != -1) );
}
);
} }
}; };
$( document ).on( 'click', '#bulk_edit', function() { $( document ).on(
// define the bulk edit row 'click',
var $bulk_row = $( '#bulk-edit' ); '#bulk_edit',
function() {
// define the bulk edit row
var $bulk_row = $( '#bulk-edit' );
// get the selected post ids that are being edited // get the selected post ids that are being edited
var $post_ids = new Array(); var $post_ids = new Array();
$bulk_row.find( '#bulk-titles' ).children().each( function() { $bulk_row.find( '#bulk-titles' ).children().each(
$post_ids.push( $( this ).attr( 'id' ).replace( /^(ttle)/i, '' ) ); function() {
}); $post_ids.push( $( this ).attr( 'id' ).replace( /^(ttle)/i, '' ) );
}
);
// get the data // get the data
var $current_teams = []; var $current_teams = [];
$bulk_row.find( 'input[name="sp_current_team[]"]:checked' ).each(function() { $bulk_row.find( 'input[name="sp_current_team[]"]:checked' ).each(
$current_teams.push( $(this).val() ); function() {
}); $current_teams.push( $( this ).val() );
}
);
var $past_teams = []; var $past_teams = [];
$bulk_row.find( 'input[name="sp_past_team[]"]:checked' ).each(function() { $bulk_row.find( 'input[name="sp_past_team[]"]:checked' ).each(
$past_teams.push( $(this).val() ); function() {
}); $past_teams.push( $( this ).val() );
}
);
// save the data // save the data
$.ajax({ $.ajax(
url: ajaxurl, // this is a variable that WordPress has already defined for us {
type: 'POST', url: ajaxurl, // this is a variable that WordPress has already defined for us
async: false, type: 'POST',
cache: false, async: false,
data: { cache: false,
action: 'save_bulk_edit_sp_player', data: {
post_ids: $post_ids, action: 'save_bulk_edit_sp_player',
current_teams: $current_teams, post_ids: $post_ids,
past_teams: $past_teams, current_teams: $current_teams,
nonce: $("#sp_player_edit_nonce").val() past_teams: $past_teams,
} nonce: $( "#sp_player_edit_nonce" ).val()
}); }
}); }
);
}
);
})(jQuery); })( jQuery );

View File

@@ -1,64 +1,92 @@
jQuery(document).ready(function($){ jQuery( document ).ready(
function($){
// Display custom sport name field as needed // Display custom sport name field as needed
$("body.toplevel_page_sportspress #sportspress_sport").change(function() { $( "body.toplevel_page_sportspress #sportspress_sport" ).change(
$target = $("#sportspress_custom_sport_name"); function() {
if ( $(this).val() == "custom" ) $target = $( "#sportspress_custom_sport_name" );
$target.show(); if ( $( this ).val() == "custom" ) {
else $target.show();
$target.hide(); } else {
}); $target.hide();
}
}
);
// Color picker // Color picker
$('.colorpick').iris( { $( '.colorpick' ).iris(
change: function(event, ui){ {
$(this).css( { backgroundColor: ui.color.toString() } ); change: function(event, ui){
}, $( this ).css( { backgroundColor: ui.color.toString() } );
hide: true, },
border: true hide: true,
} ).each( function() { border: true
$(this).css( { backgroundColor: $(this).val() } ); }
}) ).each(
.click(function(){ function() {
$('.iris-picker').hide(); $( this ).css( { backgroundColor: $( this ).val() } );
$(this).closest('.sp-color-box, td').find('.iris-picker').show(); }
}); )
.click(
function(){
$( '.iris-picker' ).hide();
$( this ).closest( '.sp-color-box, td' ).find( '.iris-picker' ).show();
}
);
$('body').click(function() { $( 'body' ).click(
$('.iris-picker').hide(); function() {
}); $( '.iris-picker' ).hide();
}
);
$('.sp-color-box, .colorpick').click(function(event){ $( '.sp-color-box, .colorpick' ).click(
event.stopPropagation(); function(event){
}); event.stopPropagation();
}
);
// Chosen select // Chosen select
$(".chosen-select").chosen({ $( ".chosen-select" ).chosen(
allow_single_deselect: true, {
single_backstroke_delete: false, allow_single_deselect: true,
placeholder_text_multiple: localized_strings.none single_backstroke_delete: false,
}); placeholder_text_multiple: localized_strings.none
}
);
// Preset field modifier // Preset field modifier
$(".sp-custom-input-wrapper .preset").click(function() { $( ".sp-custom-input-wrapper .preset" ).click(
val = $(this).val(); function() {
if(val == "\\c\\u\\s\\t\\o\\m") return true; val = $( this ).val();
example = $(this).attr("data-example"); if (val == "\\c\\u\\s\\t\\o\\m") {
$(this).closest(".sp-custom-input-wrapper").find(".value").val(val).siblings(".example").html(example); return true;
}); }
example = $( this ).attr( "data-example" );
$( this ).closest( ".sp-custom-input-wrapper" ).find( ".value" ).val( val ).siblings( ".example" ).html( example );
}
);
// Select custom preset when field is brought to focus // Select custom preset when field is brought to focus
$(".sp-custom-input-wrapper .value").focus(function() { $( ".sp-custom-input-wrapper .value" ).focus(
$(this).siblings("label").find(".preset").prop("checked", true); function() {
}); $( this ).siblings( "label" ).find( ".preset" ).prop( "checked", true );
}
);
// Adjust example field when custom preset is entered // Adjust example field when custom preset is entered
$(".sp-custom-input-wrapper .value").on("keyup", function() { $( ".sp-custom-input-wrapper .value" ).on(
val = $(this).val(); "keyup",
if ( val === undefined ) return true; function() {
format = $(this).attr("data-example-format"); val = $( this ).val();
example = format.replace(/__val__/g, val); if ( val === undefined ) {
$(this).siblings(".example").html(example); return true;
}); }
format = $( this ).attr( "data-example-format" );
example = format.replace( /__val__/g, val );
$( this ).siblings( ".example" ).html( example );
}
);
}); }
);

View File

@@ -1,54 +1,76 @@
//Get variables form input values // Get variables form input values
latitude = document.getElementById('term_meta[sp_latitude]').value; latitude = document.getElementById( 'term_meta[sp_latitude]' ).value;
longitude = document.getElementById('term_meta[sp_longitude]').value; longitude = document.getElementById( 'term_meta[sp_longitude]' ).value;
//Initialize the map and add the Search control box // Initialize the map and add the Search control box
var map = L.map('sp-location-picker').setView([latitude, longitude], 15), var map = L.map( 'sp-location-picker' ).setView( [latitude, longitude], 15 ),
geocoder = L.Control.Geocoder.nominatim(), geocoder = L.Control.Geocoder.nominatim(),
control = L.Control.geocoder({ control = L.Control.geocoder(
geocoder: geocoder, {
collapsed: false, geocoder: geocoder,
defaultMarkGeocode: false collapsed: false,
}).addTo(map), defaultMarkGeocode: false
//Add a marker to use from the begining
marker = L.marker([latitude, longitude],{draggable: true, autoPan: true}).addTo(map);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
//Pass the values to the fields after dragging
marker.on('dragend', function (e) {
document.getElementById('term_meta[sp_latitude]').value = marker.getLatLng().lat;
document.getElementById('term_meta[sp_longitude]').value = marker.getLatLng().lng;
geocoder.reverse(marker.getLatLng(), map.options.crs.scale(map.getZoom()), function(results) {
var r = results[0];
if (r) {
document.getElementById('term_meta[sp_address]').value = r.name;
} }
}) ).addTo( map ),
}); // Add a marker to use from the begining
marker = L.marker( [latitude, longitude],{draggable: true, autoPan: true} ).addTo( map );
//After searching L.tileLayer(
control.on('markgeocode', function(e) { 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
var center = e.geocode.center; {
var address = e.geocode.name; attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
map.setView([center.lat, center.lng], 15); //Center map to the new place }
map.removeLayer(marker); //Remove previous marker ).addTo( map );
marker = L.marker([center.lat, center.lng],{draggable: true, autoPan: true}).addTo(map); //Add new marker to use
//Pass the values to the fields after searching // Pass the values to the fields after dragging
document.getElementById('term_meta[sp_latitude]').value = center.lat; marker.on(
document.getElementById('term_meta[sp_longitude]').value = center.lng; 'dragend',
document.getElementById('term_meta[sp_address]').value = address; function (e) {
//Pass the values to the fields after dragging document.getElementById( 'term_meta[sp_latitude]' ).value = marker.getLatLng().lat;
marker.on('dragend', function (e) { document.getElementById( 'term_meta[sp_longitude]' ).value = marker.getLatLng().lng;
document.getElementById('term_meta[sp_latitude]').value = marker.getLatLng().lat; geocoder.reverse(
document.getElementById('term_meta[sp_longitude]').value = marker.getLatLng().lng; marker.getLatLng(),
geocoder.reverse(marker.getLatLng(), map.options.crs.scale(map.getZoom()), function(results) { map.options.crs.scale( map.getZoom() ),
var r = results[0]; function(results) {
if (r) { var r = results[0];
document.getElementById('term_meta[sp_address]').value = r.name; if (r) {
document.getElementById( 'term_meta[sp_address]' ).value = r.name;
}
} }
}) )
}); }
}).addTo(map); );
// After searching
control.on(
'markgeocode',
function(e) {
var center = e.geocode.center;
var address = e.geocode.name;
map.setView( [center.lat, center.lng], 15 ); // Center map to the new place
map.removeLayer( marker ); // Remove previous marker
marker = L.marker( [center.lat, center.lng],{draggable: true, autoPan: true} ).addTo( map ); // Add new marker to use
// Pass the values to the fields after searching
document.getElementById( 'term_meta[sp_latitude]' ).value = center.lat;
document.getElementById( 'term_meta[sp_longitude]' ).value = center.lng;
document.getElementById( 'term_meta[sp_address]' ).value = address;
// Pass the values to the fields after dragging
marker.on(
'dragend',
function (e) {
document.getElementById( 'term_meta[sp_latitude]' ).value = marker.getLatLng().lat;
document.getElementById( 'term_meta[sp_longitude]' ).value = marker.getLatLng().lng;
geocoder.reverse(
marker.getLatLng(),
map.options.crs.scale( map.getZoom() ),
function(results) {
var r = results[0];
if (r) {
document.getElementById( 'term_meta[sp_address]' ).value = r.name;
}
}
)
}
);
}
).addTo( map );

View File

@@ -1,54 +1,76 @@
//Get variables form input values // Get variables form input values
latitude = document.getElementById('sp_latitude').value; latitude = document.getElementById( 'sp_latitude' ).value;
longitude = document.getElementById('sp_longitude').value; longitude = document.getElementById( 'sp_longitude' ).value;
//Initialize the map and add the Search control box // Initialize the map and add the Search control box
var map = L.map('sp-location-picker').setView([latitude, longitude], 15), var map = L.map( 'sp-location-picker' ).setView( [latitude, longitude], 15 ),
geocoder = L.Control.Geocoder.nominatim(), geocoder = L.Control.Geocoder.nominatim(),
control = L.Control.geocoder({ control = L.Control.geocoder(
geocoder: geocoder, {
collapsed: false, geocoder: geocoder,
defaultMarkGeocode: false collapsed: false,
}).addTo(map), defaultMarkGeocode: false
//Add a marker to use from the begining
marker = L.marker([latitude, longitude],{draggable: true, autoPan: true}).addTo(map);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
//Pass the values to the fields after dragging
marker.on('dragend', function (e) {
document.getElementById('sp_latitude').value = marker.getLatLng().lat;
document.getElementById('sp_longitude').value = marker.getLatLng().lng;
geocoder.reverse(marker.getLatLng(), map.options.crs.scale(map.getZoom()), function(results) {
var r = results[0];
if (r) {
document.getElementById('sp_address').value = r.name;
} }
}) ).addTo( map ),
}); // Add a marker to use from the begining
marker = L.marker( [latitude, longitude],{draggable: true, autoPan: true} ).addTo( map );
//After searching L.tileLayer(
control.on('markgeocode', function(e) { 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
var center = e.geocode.center; {
var address = e.geocode.name; attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
map.setView([center.lat, center.lng], 15); //Center map to the new place }
map.removeLayer(marker); //Remove previous marker ).addTo( map );
marker = L.marker([center.lat, center.lng],{draggable: true, autoPan: true}).addTo(map); //Add new marker to use
//Pass the values to the fields after searching // Pass the values to the fields after dragging
document.getElementById('sp_latitude').value = center.lat; marker.on(
document.getElementById('sp_longitude').value = center.lng; 'dragend',
document.getElementById('sp_address').value = address; function (e) {
//Pass the values to the fields after dragging document.getElementById( 'sp_latitude' ).value = marker.getLatLng().lat;
marker.on('dragend', function (e) { document.getElementById( 'sp_longitude' ).value = marker.getLatLng().lng;
document.getElementById('sp_latitude').value = marker.getLatLng().lat; geocoder.reverse(
document.getElementById('sp_longitude').value = marker.getLatLng().lng; marker.getLatLng(),
geocoder.reverse(marker.getLatLng(), map.options.crs.scale(map.getZoom()), function(results) { map.options.crs.scale( map.getZoom() ),
var r = results[0]; function(results) {
if (r) { var r = results[0];
document.getElementById('sp_address').value = r.name; if (r) {
document.getElementById( 'sp_address' ).value = r.name;
}
} }
}) )
}); }
}).addTo(map); );
// After searching
control.on(
'markgeocode',
function(e) {
var center = e.geocode.center;
var address = e.geocode.name;
map.setView( [center.lat, center.lng], 15 ); // Center map to the new place
map.removeLayer( marker ); // Remove previous marker
marker = L.marker( [center.lat, center.lng],{draggable: true, autoPan: true} ).addTo( map ); // Add new marker to use
// Pass the values to the fields after searching
document.getElementById( 'sp_latitude' ).value = center.lat;
document.getElementById( 'sp_longitude' ).value = center.lng;
document.getElementById( 'sp_address' ).value = address;
// Pass the values to the fields after dragging
marker.on(
'dragend',
function (e) {
document.getElementById( 'sp_latitude' ).value = marker.getLatLng().lat;
document.getElementById( 'sp_longitude' ).value = marker.getLatLng().lng;
geocoder.reverse(
marker.getLatLng(),
map.options.crs.scale( map.getZoom() ),
function(results) {
var r = results[0];
if (r) {
document.getElementById( 'sp_address' ).value = r.name;
}
}
)
}
);
}
).addTo( map );

File diff suppressed because it is too large Load Diff

View File

@@ -1,24 +1,32 @@
jQuery(document).ready(function($){ jQuery( document ).ready(
function($){
// Tiptip // Tiptip
$(".sp-tip").tipTip({ $( ".sp-tip" ).tipTip(
delay: 200, {
fadeIn: 100, delay: 200,
fadeOut: 100 fadeIn: 100,
}); fadeOut: 100
$(".sp-desc-tip").tipTip({ }
delay: 200, );
fadeIn: 100, $( ".sp-desc-tip" ).tipTip(
fadeOut: 100, {
defaultPosition: 'right' delay: 200,
}); fadeIn: 100,
fadeOut: 100,
defaultPosition: 'right'
}
);
// Chosen select // Chosen select
$(".chosen-select, #poststuff #post_author_override").chosen({ $( ".chosen-select, #poststuff #post_author_override" ).chosen(
allow_single_deselect: true, {
search_contains: true, allow_single_deselect: true,
single_backstroke_delete: false, search_contains: true,
disable_search_threshold: 10, single_backstroke_delete: false,
placeholder_text_multiple: localized_strings.none disable_search_threshold: 10,
}); placeholder_text_multiple: localized_strings.none
}); }
);
}
);

View File

@@ -1,41 +1,60 @@
jQuery(document).ready(function($){ jQuery( document ).ready(
function($){
// Orderby affects order select in widget options // Orderby affects order select in widget options
$("body").on("change", ".sp-select-orderby", function() { $( "body" ).on(
$(this).closest(".widget-content").find(".sp-select-order").prop("disabled", $(this).val() == "default"); "change",
}); ".sp-select-orderby",
function() {
$( this ).closest( ".widget-content" ).find( ".sp-select-order" ).prop( "disabled", $( this ).val() == "default" );
}
);
// Calendar affects view all link checkbox in widget options // Calendar affects view all link checkbox in widget options
$("body").on("change", ".sp-event-calendar-select", function() { $( "body" ).on(
$el = $(this).closest(".widget-content").find(".sp-event-calendar-show-all-toggle"); "change",
if($(this).val() == 0) ".sp-event-calendar-select",
$el.hide(); function() {
else $el = $( this ).closest( ".widget-content" ).find( ".sp-event-calendar-show-all-toggle" );
$el.show(); if ($( this ).val() == 0) {
}); $el.hide();
} else {
$el.show();
}
}
);
// Show or hide datepicker // Show or hide datepicker
$("body").on("change", ".sp-date-selector select", function() { $( "body" ).on(
if ( $(this).val() == "range" ) { "change",
$(this).closest(".sp-date-selector").find(".sp-date-range").show(); ".sp-date-selector select",
} else { function() {
$(this).closest(".sp-date-selector").find(".sp-date-range").hide(); if ( $( this ).val() == "range" ) {
} $( this ).closest( ".sp-date-selector" ).find( ".sp-date-range" ).show();
}); } else {
$(".sp-date-selector select").trigger("change"); $( this ).closest( ".sp-date-selector" ).find( ".sp-date-range" ).hide();
}
}
);
$( ".sp-date-selector select" ).trigger( "change" );
// Toggle date range selectors // Toggle date range selectors
$("body").on("change", ".sp-date-relative input", function() { $( "body" ).on(
$relative = $(this).closest(".sp-date-relative").siblings(".sp-date-range-relative").toggle(0, $(this).attr("checked")); "change",
$absolute = $(this).closest(".sp-date-relative").siblings(".sp-date-range-absolute").toggle(0, $(this).attr("checked")); ".sp-date-relative input",
function() {
$relative = $( this ).closest( ".sp-date-relative" ).siblings( ".sp-date-range-relative" ).toggle( 0, $( this ).attr( "checked" ) );
$absolute = $( this ).closest( ".sp-date-relative" ).siblings( ".sp-date-range-absolute" ).toggle( 0, $( this ).attr( "checked" ) );
if ($(this).attr("checked")) { if ($( this ).attr( "checked" )) {
$relative.show(); $relative.show();
$absolute.hide(); $absolute.hide();
} else { } else {
$absolute.show(); $absolute.show();
$relative.hide(); $relative.hide();
} }
}); }
$(".sp-date-selector input").trigger("change"); );
}); $( ".sp-date-selector input" ).trigger( "change" );
}
);

View File

@@ -1,81 +1,88 @@
import apiFetch from '@wordpress/api-fetch'; import apiFetch from '@wordpress/api-fetch';
console.log(wp.api.collections.Posts()); console.log( wp.api.collections.Posts() );
wp.blocks.registerBlockType('sportspress/event-calendar', { wp.blocks.registerBlockType(
title: strings.event_calendar, 'sportspress/event-calendar',
icon: 'calendar', {
category: 'sportspress', title: strings.event_calendar,
attributes: { icon: 'calendar',
title: { category: 'sportspress',
type: 'string' attributes: {
}, title: {
id: { type: 'string'
type: 'number' },
}, id: {
status: { type: 'number'
type: 'string' },
}, status: {
date: { type: 'string'
type: 'string' },
}, date: {
date_from: { type: 'string'
type: 'string' },
}, date_from: {
date_to: { type: 'string'
type: 'string' },
}, date_to: {
date_past: { type: 'string'
type: 'number' },
}, date_past: {
date_future: { type: 'number'
type: 'number' },
}, date_future: {
date_relative: { type: 'number'
type: 'number' },
}, date_relative: {
day: { type: 'number'
type: 'string' },
}, day: {
show_all_events_link: { type: 'string'
type: 'number' },
}, show_all_events_link: {
type: 'number'
},
content: {type: 'string'}, content: {type: 'string'},
color: {type: 'string'} color: {type: 'string'}
}, },
edit: function(props) {
function updateContent(event) {
props.setAttributes({content: event.target.value})
}
function updateColor(value) {
props.setAttributes({color: value.hex})
}
return React.createElement(
wp.components.Panel,
{header: strings.event_calendar},
React.createElement(
wp.components.PanelBody,
{title: strings.properties},
React.createElement(
wp.components.TextControl,
{label: strings.title, type: "text", value: props.attributes.title}
),
React.createElement(
wp.components.SelectControl,
{label: strings.select_calendar, options: [{label: strings.all, value: 0}].concat(posts.events.map(post => {
return {label: post.post_title, value: post.ID}
}))}
)
)
);
},
save: function(props) { edit: function(props) {
return wp.element.createElement( function updateContent(event) {
"h3", props.setAttributes( {content: event.target.value} )
{ style: { border: "3px solid " + props.attributes.color } }, }
props.attributes.content function updateColor(value) {
); props.setAttributes( {color: value.hex} )
} }
}) return React.createElement(
wp.components.Panel,
{header: strings.event_calendar},
React.createElement(
wp.components.PanelBody,
{title: strings.properties},
React.createElement(
wp.components.TextControl,
{label: strings.title, type: "text", value: props.attributes.title}
),
React.createElement(
wp.components.SelectControl,
{label: strings.select_calendar, options: [{label: strings.all, value: 0}].concat(
posts.events.map(
post => {
return {label: post.post_title, value: post.ID}
}
)
)}
)
)
);
},
save: function(props) {
return wp.element.createElement(
"h3",
{ style: { border: "3px solid " + props.attributes.color } },
props.attributes.content
);
}
}
)

View File

@@ -11,73 +11,77 @@
(function( $ ){ (function( $ ){
'use strict'; 'use strict';
$.fn.fitVids = function( options ) { $.fn.fitVids = function( options ) {
var settings = { var settings = {
customSelector: null, customSelector: null,
ignore: null ignore: null
}; };
if(!document.getElementById('fit-vids-style')) { if ( ! document.getElementById( 'fit-vids-style' )) {
// appendStyles: https://github.com/toddmotto/fluidvids/blob/master/dist/fluidvids.js // appendStyles: https://github.com/toddmotto/fluidvids/blob/master/dist/fluidvids.js
var head = document.head || document.getElementsByTagName('head')[0]; var head = document.head || document.getElementsByTagName( 'head' )[0];
var css = '.fluid-width-video-wrapper{width:100%;position:relative;padding:0;}.fluid-width-video-wrapper iframe,.fluid-width-video-wrapper object,.fluid-width-video-wrapper embed {position:absolute;top:0;left:0;width:100%;height:100%;}'; var css = '.fluid-width-video-wrapper{width:100%;position:relative;padding:0;}.fluid-width-video-wrapper iframe,.fluid-width-video-wrapper object,.fluid-width-video-wrapper embed {position:absolute;top:0;left:0;width:100%;height:100%;}';
var div = document.createElement("div"); var div = document.createElement( "div" );
div.innerHTML = '<p>x</p><style id="fit-vids-style">' + css + '</style>'; div.innerHTML = '<p>x</p><style id="fit-vids-style">' + css + '</style>';
head.appendChild(div.childNodes[1]); head.appendChild( div.childNodes[1] );
} }
if ( options ) { if ( options ) {
$.extend( settings, options ); $.extend( settings, options );
} }
return this.each(function(){ return this.each(
var selectors = [ function(){
'iframe[src*="player.vimeo.com"]', var selectors = [
'iframe[src*="youtube.com"]', 'iframe[src*="player.vimeo.com"]',
'iframe[src*="youtube-nocookie.com"]', 'iframe[src*="youtube.com"]',
'iframe[src*="kickstarter.com"][src*="video.html"]', 'iframe[src*="youtube-nocookie.com"]',
'object', 'iframe[src*="kickstarter.com"][src*="video.html"]',
'embed' 'object',
]; 'embed'
];
if (settings.customSelector) { if (settings.customSelector) {
selectors.push(settings.customSelector); selectors.push( settings.customSelector );
} }
var ignoreList = '.fitvidsignore'; var ignoreList = '.fitvidsignore';
if(settings.ignore) { if (settings.ignore) {
ignoreList = ignoreList + ', ' + settings.ignore; ignoreList = ignoreList + ', ' + settings.ignore;
} }
var $allVideos = $(this).find(selectors.join(',')); var $allVideos = $( this ).find( selectors.join( ',' ) );
$allVideos = $allVideos.not('object object'); // SwfObj conflict patch $allVideos = $allVideos.not( 'object object' ); // SwfObj conflict patch
$allVideos = $allVideos.not(ignoreList); // Disable FitVids on this video. $allVideos = $allVideos.not( ignoreList ); // Disable FitVids on this video.
$allVideos.each(function(){ $allVideos.each(
var $this = $(this); function(){
if($this.parents(ignoreList).length > 0) { var $this = $( this );
return; // Disable FitVids on this video. if ($this.parents( ignoreList ).length > 0) {
} return; // Disable FitVids on this video.
if (this.tagName.toLowerCase() === 'embed' && $this.parent('object').length || $this.parent('.fluid-width-video-wrapper').length) { return; } }
if ((!$this.css('height') && !$this.css('width')) && (isNaN($this.attr('height')) || isNaN($this.attr('width')))) if (this.tagName.toLowerCase() === 'embed' && $this.parent( 'object' ).length || $this.parent( '.fluid-width-video-wrapper' ).length) {
{ return; }
$this.attr('height', 9); if (( ! $this.css( 'height' ) && ! $this.css( 'width' )) && (isNaN( $this.attr( 'height' ) ) || isNaN( $this.attr( 'width' ) ))) {
$this.attr('width', 16); $this.attr( 'height', 9 );
} $this.attr( 'width', 16 );
var height = ( this.tagName.toLowerCase() === 'object' || ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10))) ) ? parseInt($this.attr('height'), 10) : $this.height(), }
width = !isNaN(parseInt($this.attr('width'), 10)) ? parseInt($this.attr('width'), 10) : $this.width(), var height = ( this.tagName.toLowerCase() === 'object' || ($this.attr( 'height' ) && ! isNaN( parseInt( $this.attr( 'height' ), 10 ) )) ) ? parseInt( $this.attr( 'height' ), 10 ) : $this.height(),
aspectRatio = height / width; width = ! isNaN( parseInt( $this.attr( 'width' ), 10 ) ) ? parseInt( $this.attr( 'width' ), 10 ) : $this.width(),
if(!$this.attr('id')){ aspectRatio = height / width;
var videoID = 'fitvid' + Math.floor(Math.random()*999999); if ( ! $this.attr( 'id' )) {
$this.attr('id', videoID); var videoID = 'fitvid' + Math.floor( Math.random() * 999999 );
} $this.attr( 'id', videoID );
$this.wrap('<div class="fluid-width-video-wrapper"></div>').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+'%'); }
$this.removeAttr('height').removeAttr('width'); $this.wrap( '<div class="fluid-width-video-wrapper"></div>' ).parent( '.fluid-width-video-wrapper' ).css( 'padding-top', (aspectRatio * 100) + '%' );
}); $this.removeAttr( 'height' ).removeAttr( 'width' );
}); }
}; );
// Works with either jQuery or Zepto }
);
};
// Works with either jQuery or Zepto
})( window.jQuery || window.Zepto ); })( window.jQuery || window.Zepto );

View File

@@ -1,119 +1,138 @@
function sp_viewport() { function sp_viewport() {
var e = window, a = 'inner'; var e = window, a = 'inner';
if (!('innerWidth' in window )) { if ( ! ('innerWidth' in window )) {
a = 'client'; a = 'client';
e = document.documentElement || document.body; e = document.documentElement || document.body;
} }
return { width : e[ a+'Width' ] , height : e[ a+'Height' ] }; return { width : e[ a + 'Width' ] , height : e[ a + 'Height' ] };
} }
(function($) { (function($) {
/* Header */ /* Header */
if ( ! $('.sp-header').length ) { if ( ! $( '.sp-header' ).length ) {
$('body').prepend( '<div class="sp-header sp-header-loaded"></div>' ); $( 'body' ).prepend( '<div class="sp-header sp-header-loaded"></div>' );
} }
/* Countdown */ /* Countdown */
$("[data-countdown]").each(function() { $( "[data-countdown]" ).each(
var $this = $(this); function() {
// Get countdown time var $this = $( this );
var countDownDate = new Date($(this).data('countdown')).getTime(); // Get countdown time
// Iterate every second var countDownDate = new Date( $( this ).data( 'countdown' ) ).getTime();
var x = setInterval(function() { // Iterate every second
var x = setInterval(
// Get todays date and time function() {
var now = new Date();
// Get todays date and time
// Convert curent date and time to UTC var now = new Date();
var tzDifference = now.getTimezoneOffset();
var nowutc = new Date(now.getTime() + tzDifference * 60 * 1000); // Convert curent date and time to UTC
var tzDifference = now.getTimezoneOffset();
// Find the distance between now and the count down date var nowutc = new Date( now.getTime() + tzDifference * 60 * 1000 );
var distance = countDownDate - nowutc;
if ( distance < 0 ) { // Find the distance between now and the count down date
distance = 0; var distance = countDownDate - nowutc;
} if ( distance < 0 ) {
distance = 0;
// Time calculations for days, hours, minutes and seconds }
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); // Time calculations for days, hours, minutes and seconds
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var days = Math.floor( distance / (1000 * 60 * 60 * 24) );
var seconds = Math.floor((distance % (1000 * 60)) / 1000); var hours = Math.floor( (distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60) );
var minutes = Math.floor( (distance % (1000 * 60 * 60)) / (1000 * 60) );
// Output the result var seconds = Math.floor( (distance % (1000 * 60)) / 1000 );
$this.html("<span>"+(days < 10 ? '0' + days : days)+" <small>" + localized_strings.days + "</small></span> "
+ "<span>"+('0' + hours).slice(-2)+" <small>" + localized_strings.hrs + "</small></span> " // Output the result
+ "<span>"+('0' + minutes).slice(-2)+" <small>" + localized_strings.mins + "</small></span> " $this.html(
+ "<span>"+('0' + seconds).slice(-2)+" <small>" + localized_strings.secs + "</small></span>" ); "<span>" + (days < 10 ? '0' + days : days) + " <small>" + localized_strings.days + "</small></span> "
}, 1000); + "<span>" + ('0' + hours).slice( -2 ) + " <small>" + localized_strings.hrs + "</small></span> "
}); + "<span>" + ('0' + minutes).slice( -2 ) + " <small>" + localized_strings.mins + "</small></span> "
+ "<span>" + ('0' + seconds).slice( -2 ) + " <small>" + localized_strings.secs + "</small></span>"
);
},
1000
);
}
);
/* Scrollable Tables */ /* Scrollable Tables */
$(".sp-scrollable-table").wrap("<div class=\"sp-scrollable-table-wrapper\"></div>"); $( ".sp-scrollable-table" ).wrap( "<div class=\"sp-scrollable-table-wrapper\"></div>" );
/* Selector Redirect */ /* Selector Redirect */
$(".sp-selector-redirect").change(function() { $( ".sp-selector-redirect" ).change(
window.location = $(this).val(); function() {
}); window.location = $( this ).val();
}
);
/* Template Tabs */ /* Template Tabs */
$(".sp-tab-menu-item a").click(function() { $( ".sp-tab-menu-item a" ).click(
$template = $(this).data("sp-tab"); function() {
$(this).closest(".sp-tab-menu-item").addClass("sp-tab-menu-item-active").siblings(".sp-tab-menu-item").removeClass("sp-tab-menu-item-active"); $template = $( this ).data( "sp-tab" );
$(this).closest(".sp-tab-group").find(".sp-tab-content-"+$template).show().siblings(".sp-tab-content").hide(); $( this ).closest( ".sp-tab-menu-item" ).addClass( "sp-tab-menu-item-active" ).siblings( ".sp-tab-menu-item" ).removeClass( "sp-tab-menu-item-active" );
return false; $( this ).closest( ".sp-tab-group" ).find( ".sp-tab-content-" + $template ).show().siblings( ".sp-tab-content" ).hide();
}); return false;
}
);
/* API method to get paging information */ /* API method to get paging information */
$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings ) $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
{ {
return { return {
"iStart": oSettings._iDisplayStart, "iStart": oSettings._iDisplayStart,
"iEnd": oSettings.fnDisplayEnd(), "iEnd": oSettings.fnDisplayEnd(),
"iLength": oSettings._iDisplayLength, "iLength": oSettings._iDisplayLength,
"iTotal": oSettings.fnRecordsTotal(), "iTotal": oSettings.fnRecordsTotal(),
"iFilteredTotal": oSettings.fnRecordsDisplay(), "iFilteredTotal": oSettings.fnRecordsDisplay(),
"iPage": oSettings._iDisplayLength === -1 ? "iPage": oSettings._iDisplayLength === -1 ?
0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ), 0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
"iTotalPages": oSettings._iDisplayLength === -1 ? "iTotalPages": oSettings._iDisplayLength === -1 ?
0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength ) 0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
}; };
} }
/* Data Tables */ /* Data Tables */
$(".sp-data-table").each(function() { $( ".sp-data-table" ).each(
sortable = $(this).hasClass("sp-sortable-table"); function() {
paginated = $(this).hasClass("sp-paginated-table"); sortable = $( this ).hasClass( "sp-sortable-table" );
display_length = parseInt($(this).attr("data-sp-rows")); paginated = $( this ).hasClass( "sp-paginated-table" );
if ( display_length == undefined || isNaN( display_length ) ) display_length = 10; display_length = parseInt( $( this ).attr( "data-sp-rows" ) );
if ( $(this).find("tbody tr").length <= display_length ) paginated = false; if ( display_length == undefined || isNaN( display_length ) ) {
if ( sortable || paginated ) { display_length = 10;
$(this).dataTable({ }
"order": [], if ( $( this ).find( "tbody tr" ).length <= display_length ) {
"autoWidth": false, paginated = false;
"searching": false, }
"info": false, if ( sortable || paginated ) {
"paging": paginated, $( this ).dataTable(
"lengthChange": false, {
"pagingType": "simple_numbers", "order": [],
"pageLength": display_length, "autoWidth": false,
"ordering": sortable, "searching": false,
"language": { "info": false,
"aria": { "paging": paginated,
"sortAscending": "", "lengthChange": false,
"sortDescending": "" "pagingType": "simple_numbers",
}, "pageLength": display_length,
"paginate": { "ordering": sortable,
"previous": localized_strings.previous, "language": {
"next": localized_strings.next, "aria": {
} "sortAscending": "",
}, "sortDescending": ""
"columnDefs": [ },
{ "type": "num-fmt", "targets": [ ".data-number", ".data-rank" ] }, "paginate": {
] "previous": localized_strings.previous,
}); "next": localized_strings.next,
}
},
"columnDefs": [
{ "type": "num-fmt", "targets": [ ".data-number", ".data-rank" ] },
]
}
);
}
} }
}); );
})(jQuery); })( jQuery );

View File

@@ -2,13 +2,15 @@
/** /**
* iCal Feed * iCal Feed
* *
* @author ThemeBoy * @author ThemeBoy
* @category Feeds * @category Feeds
* @package SportsPress/Feeds * @package SportsPress/Feeds
* @version 2.7.5 * @version 2.7.5
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( 'sp_calendar' !== get_post_type( $post ) ) { if ( 'sp_calendar' !== get_post_type( $post ) ) {
wp_die( __( 'ERROR: This is not a valid feed template.', 'sportspress' ), '', array( 'response' => 404 ) ); wp_die( __( 'ERROR: This is not a valid feed template.', 'sportspress' ), '', array( 'response' => 404 ) );
@@ -16,7 +18,7 @@ if ( 'sp_calendar' !== get_post_type( $post ) ) {
// Get events in calendar // Get events in calendar
$calendar = new SP_Calendar( $post ); $calendar = new SP_Calendar( $post );
$events = $calendar->data(); $events = $calendar->data();
// Get blog locale // Get blog locale
$locale = substr( get_locale(), 0, 2 ); $locale = substr( get_locale(), 0, 2 );
@@ -29,41 +31,43 @@ $timezone = sanitize_option( 'timezone_string', get_option( 'timezone_string' )
// Get the URL // Get the URL
$url = add_query_arg( 'feed', 'sp-ical', get_post_permalink( $post ) ); $url = add_query_arg( 'feed', 'sp-ical', get_post_permalink( $post ) );
$url = wordwrap( $url , 60, "\r\n\t", true ); $url = wordwrap( $url, 60, "\r\n\t", true );
$output = $output =
"BEGIN:VCALENDAR\r\n" . "BEGIN:VCALENDAR\r\n" .
"VERSION:2.0\r\n" . "VERSION:2.0\r\n" .
"PRODID:-//ThemeBoy//SportsPress//" . strtoupper( $locale ) . "\r\n" . 'PRODID:-//ThemeBoy//SportsPress//' . strtoupper( $locale ) . "\r\n" .
"CALSCALE:GREGORIAN\r\n" . "CALSCALE:GREGORIAN\r\n" .
"METHOD:PUBLISH\r\n" . "METHOD:PUBLISH\r\n" .
"URL:" . $url . "\r\n" . 'URL:' . $url . "\r\n" .
"X-FROM-URL:" . $url . "\r\n" . 'X-FROM-URL:' . $url . "\r\n" .
"NAME:" . $post->post_title . "\r\n" . 'NAME:' . $post->post_title . "\r\n" .
"X-WR-CALNAME:" . $post->post_title . "\r\n" . 'X-WR-CALNAME:' . $post->post_title . "\r\n" .
"DESCRIPTION:" . $post->post_title . "\r\n" . 'DESCRIPTION:' . $post->post_title . "\r\n" .
"X-WR-CALDESC:" . $post->post_title . "\r\n" . 'X-WR-CALDESC:' . $post->post_title . "\r\n" .
"REFRESH-INTERVAL;VALUE=DURATION:PT2M\r\n" . "REFRESH-INTERVAL;VALUE=DURATION:PT2M\r\n" .
"X-PUBLISHED-TTL:PT2M\r\n" . "X-PUBLISHED-TTL:PT2M\r\n" .
"TZID:" . $timezone . "\r\n" . 'TZID:' . $timezone . "\r\n" .
"X-WR-TIMEZONE:" . $timezone . "\r\n"; 'X-WR-TIMEZONE:' . $timezone . "\r\n";
// Loop through each event // Loop through each event
foreach ( $events as $event): foreach ( $events as $event ) :
// Define date format // Define date format
$date_format = 'Ymd\THis'; $date_format = 'Ymd\THis';
// Get description // Get description
$description = preg_replace( '/([\,;])/','\\\$1', $event->post_content ); $description = preg_replace( '/([\,;])/', '\\\$1', $event->post_content );
$description = wordwrap( $description , 60, "\n\t" ); $description = wordwrap( $description, 60, "\n\t" );
// Initialize end time // Initialize end time
$end = new DateTime( $event->post_date ); $end = new DateTime( $event->post_date );
// Get full time minutes // Get full time minutes
$minutes = get_post_meta( $event->ID, 'sp_minutes', true ); $minutes = get_post_meta( $event->ID, 'sp_minutes', true );
if ( '' === $minutes ) $minutes = get_option( 'sportspress_event_minutes', 90 ); if ( '' === $minutes ) {
$minutes = get_option( 'sportspress_event_minutes', 90 );
}
// Add full time minutes to end time // Add full time minutes to end time
$end->add( new DateInterval( 'PT' . $minutes . 'M' ) ); $end->add( new DateInterval( 'PT' . $minutes . 'M' ) );
@@ -74,7 +78,7 @@ foreach ( $events as $event):
// Get venue information // Get venue information
$venues = get_the_terms( $event->ID, 'sp_venue' ); $venues = get_the_terms( $event->ID, 'sp_venue' );
if ( $venues ) { if ( $venues ) {
$venue = reset( $venues ); $venue = reset( $venues );
$location .= $venue->name; $location .= $venue->name;
// Get venue term meta // Get venue term meta
@@ -84,11 +88,11 @@ foreach ( $events as $event):
// Add details to location // Add details to location
$address = sp_array_value( $meta, 'sp_address', false ); $address = sp_array_value( $meta, 'sp_address', false );
if ( false !== $address ) { if ( false !== $address ) {
$location = $venue->name . '\, ' . preg_replace('/([\,;])/','\\\$1', $address); $location = $venue->name . '\, ' . preg_replace( '/([\,;])/', '\\\$1', $address );
} }
// Generate geo tag // Generate geo tag
$latitude = sp_array_value( $meta, 'sp_latitude', false ); $latitude = sp_array_value( $meta, 'sp_latitude', false );
$longitude = sp_array_value( $meta, 'sp_longitude', false ); $longitude = sp_array_value( $meta, 'sp_longitude', false );
if ( false !== $latitude && false !== $longitude ) { if ( false !== $latitude && false !== $longitude ) {
$geo = $latitude . ';' . $longitude; $geo = $latitude . ';' . $longitude;
@@ -96,17 +100,19 @@ foreach ( $events as $event):
$geo = false; $geo = false;
} }
} }
$location = wordwrap( $location , 60, "\r\n\t" ); $location = wordwrap( $location, 60, "\r\n\t" );
// Get title or write summary based on scores // Get title or write summary based on scores
$results = array(); $results = array();
$teams = (array)get_post_meta( $event->ID, 'sp_team', false ); $teams = (array) get_post_meta( $event->ID, 'sp_team', false );
$teams = array_filter( $teams ); $teams = array_filter( $teams );
$teams = array_unique( $teams ); $teams = array_unique( $teams );
if ( ! empty( $teams ) ) { if ( ! empty( $teams ) ) {
$event_results = get_post_meta( $event->ID, 'sp_results', true ); $event_results = get_post_meta( $event->ID, 'sp_results', true );
foreach( $teams as $team_id ) { foreach ( $teams as $team_id ) {
if ( ! $team_id ) continue; if ( ! $team_id ) {
continue;
}
$team = get_post( $team_id ); $team = get_post( $team_id );
if ( $team ) { if ( $team ) {
@@ -134,51 +140,57 @@ foreach ( $events as $event):
} else { } else {
$summary = $event->post_title; $summary = $event->post_title;
} }
//Convert &#[0-9]+ entities to UTF-8 // Convert &#[0-9]+ entities to UTF-8
$summary = preg_replace_callback("/(&#[0-9]+;)/", function($m) { return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); }, $summary); $summary = preg_replace_callback(
'/(&#[0-9]+;)/',
function( $m ) {
return mb_convert_encoding( $m[1], 'UTF-8', 'HTML-ENTITIES' );
},
$summary
);
$summary = apply_filters( 'sportspress_ical_feed_summary', $summary, $event ); $summary = apply_filters( 'sportspress_ical_feed_summary', $summary, $event );
// Append to output string // Append to output string
$output .= $output .=
"BEGIN:VEVENT\r\n" . "BEGIN:VEVENT\r\n" .
"SUMMARY:" . preg_replace( '/([\,;])/','\\\$1', $summary ) . "\r\n" . 'SUMMARY:' . preg_replace( '/([\,;])/', '\\\$1', $summary ) . "\r\n" .
"UID:$event->ID\r\n" . "UID:$event->ID\r\n" .
"STATUS:CONFIRMED\r\n" . "STATUS:CONFIRMED\r\n" .
"DTSTAMP:19700101T000000\r\n". "DTSTAMP:19700101T000000\r\n" .
"DTSTART:" . mysql2date( $date_format, $event->post_date ) . "\r\n" . 'DTSTART:' . mysql2date( $date_format, $event->post_date ) . "\r\n" .
"DTEND:" . $end->format( $date_format ) . "\r\n" . 'DTEND:' . $end->format( $date_format ) . "\r\n" .
"LAST-MODIFIED:" . mysql2date( $date_format, $event->post_modified_gmt ) . "\r\n"; 'LAST-MODIFIED:' . mysql2date( $date_format, $event->post_modified_gmt ) . "\r\n";
if ( $description ) { if ( $description ) {
$output .= "DESCRIPTION:" . $description . "\r\n"; $output .= 'DESCRIPTION:' . $description . "\r\n";
} }
if ( $location ) { if ( $location ) {
$output .= "LOCATION:" . $location . "\r\n"; $output .= 'LOCATION:' . $location . "\r\n";
} }
if ( $geo ) { if ( $geo ) {
$output .= "GEO:" . $geo . "\r\n"; $output .= 'GEO:' . $geo . "\r\n";
} }
$output .= "END:VEVENT\r\n"; $output .= "END:VEVENT\r\n";
endforeach; endforeach;
// End output // End output
$output .= "END:VCALENDAR"; $output .= 'END:VCALENDAR';
// Print headers // Print headers
header('Content-type: text/calendar; charset=utf-8'); header( 'Content-type: text/calendar; charset=utf-8' );
// The E-Tag is not being changed when the output file is generated Some Webdav clients do not like this and // The E-Tag is not being changed when the output file is generated Some Webdav clients do not like this and
// do not then 'see' that the file has changed updates to the calendars are then not displayed to the user. // do not then 'see' that the file has changed updates to the calendars are then not displayed to the user.
// Props @garygomm https://wordpress.org/support/topic/calendar-feed-issue-not-updating-after-change/ // Props @garygomm https://wordpress.org/support/topic/calendar-feed-issue-not-updating-after-change/
$etag = md5($output); $etag = md5( $output );
header('Etag:' . '"'.$etag.'"'); header( 'Etag:' . '"' . $etag . '"' );
header('Content-Disposition: inline; filename=' . $post->post_name . '.ics'); header( 'Content-Disposition: inline; filename=' . $post->post_name . '.ics' );
// Print content // Print content
echo wp_kses_post( $output ); echo wp_kses_post( $output );

View File

@@ -4,11 +4,11 @@
* *
* The SportsPress custom post class handles individual post data. * The SportsPress custom post class handles individual post data.
* *
* @class SP_Custom_Post * @class SP_Custom_Post
* @version 2.6.5 * @version 2.6.5
* @package SportsPress/Abstracts * @package SportsPress/Abstracts
* @category Abstract Class * @category Abstract Class
* @author ThemeBoy * @author ThemeBoy
*/ */
abstract class SP_Custom_Post { abstract class SP_Custom_Post {
@@ -25,11 +25,11 @@ abstract class SP_Custom_Post {
* @param mixed $post * @param mixed $post
*/ */
public function __construct( $post ) { public function __construct( $post ) {
if ( $post instanceof WP_Post || $post instanceof SP_Custom_Post ): if ( $post instanceof WP_Post || $post instanceof SP_Custom_Post ) :
$this->ID = absint( $post->ID ); $this->ID = absint( $post->ID );
$this->post = $post; $this->post = $post;
else: else :
$this->ID = absint( $post ); $this->ID = absint( $post );
$this->post = get_post( $this->ID ); $this->post = get_post( $this->ID );
endif; endif;
} }
@@ -53,9 +53,9 @@ abstract class SP_Custom_Post {
* @return bool * @return bool
*/ */
public function __get( $key ) { public function __get( $key ) {
if ( ! isset( $key ) ): if ( ! isset( $key ) ) :
return $this->post; return $this->post;
else: else :
$value = get_post_meta( $this->ID, 'sp_' . $key, true ); $value = get_post_meta( $this->ID, 'sp_' . $key, true );
endif; endif;
@@ -77,7 +77,7 @@ abstract class SP_Custom_Post {
* *
* @access public * @access public
* @param string $taxonomy The taxonomy. * @param string $taxonomy The taxonomy.
* @return array|false|WP_Error See `get_the_terms()` * @return array|false|WP_Error See `get_the_terms()`
*/ */
public function get_terms_sorted_by_sp_order( $taxonomy ) { public function get_terms_sorted_by_sp_order( $taxonomy ) {
$terms = get_the_terms( $this->ID, $taxonomy ); $terms = get_the_terms( $this->ID, $taxonomy );

View File

@@ -4,70 +4,70 @@
* *
* The SportsPress secondary post class extends custom posts with handling of secondary post types. * The SportsPress secondary post class extends custom posts with handling of secondary post types.
* *
* @class SP_Secondary_Post * @class SP_Secondary_Post
* @version 2.5.3 * @version 2.5.3
* @package SportsPress/Abstracts * @package SportsPress/Abstracts
* @category Abstract Class * @category Abstract Class
* @author ThemeBoy * @author ThemeBoy
*/ */
abstract class SP_Secondary_Post extends SP_Custom_Post { abstract class SP_Secondary_Post extends SP_Custom_Post {
/** @var string The date filter for events. */ /** @var string The date filter for events. */
public $date = 0; public $date = 0;
/** @var string The date to range from. */ /** @var string The date to range from. */
public $from = 'now'; public $from = 'now';
/** @var string The date to range to. */ /** @var string The date to range to. */
public $to = 'now'; public $to = 'now';
/** @var string The number of days to query in the past. */ /** @var string The number of days to query in the past. */
public $past = 0; public $past = 0;
/** @var string The number of days to query in the future. */ /** @var string The number of days to query in the future. */
public $future = 0; public $future = 0;
/** @var boolean Determines whether the date range is relative. */ /** @var boolean Determines whether the date range is relative. */
public $relative = false; public $relative = false;
/** /**
* __construct function. * __construct function.
* *
* @access public * @access public
* @param mixed $post * @param mixed $post
*/ */
public function __construct( $post ) { public function __construct( $post ) {
if ( $post instanceof WP_Post || $post instanceof SP_Secondary_Post ): if ( $post instanceof WP_Post || $post instanceof SP_Secondary_Post ) :
$this->ID = absint( $post->ID ); $this->ID = absint( $post->ID );
$this->post = $post; $this->post = $post;
else: else :
$this->ID = absint( $post ); $this->ID = absint( $post );
$this->post = get_post( $this->ID ); $this->post = get_post( $this->ID );
endif; endif;
} }
public function range( $where = '', $format = 'Y-m-d' ) { public function range( $where = '', $format = 'Y-m-d' ) {
$from = new DateTime( $this->from ); $from = new DateTime( $this->from );
$to = new DateTime( $this->to ); $to = new DateTime( $this->to );
$to->modify( '+1 day' ); $to->modify( '+1 day' );
$where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'"; $where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'";
return $where; return $where;
} }
public function relative( $where = '', $format = 'Y-m-d' ) { public function relative( $where = '', $format = 'Y-m-d' ) {
$from = new DateTime( 'now' ); $from = new DateTime( 'now' );
$to = new DateTime( 'now' ); $to = new DateTime( 'now' );
$from->modify( '-' . abs( (int) $this->past ) . ' day' ); $from->modify( '-' . abs( (int) $this->past ) . ' day' );
$to->modify( '+' . abs( (int) $this->future ) . ' day' ); $to->modify( '+' . abs( (int) $this->future ) . ' day' );
$to->modify( '+1 day' ); $to->modify( '+1 day' );
$where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'"; $where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'";
return $where; return $where;
} }
} }

View File

@@ -6,10 +6,10 @@ if ( ! defined( 'ABSPATH' ) ) {
/** /**
* SportsPress Admin. * SportsPress Admin.
* *
* @class SP_Admin_AJAX * @class SP_Admin_AJAX
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 1.7 * @version 1.7
*/ */
class SP_Admin_AJAX { class SP_Admin_AJAX {
@@ -59,10 +59,10 @@ class SP_Admin_AJAX {
function save_inline_results() { function save_inline_results() {
check_ajax_referer( 'sp-save-inline-results', 'nonce' ); check_ajax_referer( 'sp-save-inline-results', 'nonce' );
$id = sp_array_value( $_POST, 'post_id' ); $id = sp_array_value( $_POST, 'post_id' );
$results = sp_array_value( $_POST, 'results' ); $results = sp_array_value( $_POST, 'results' );
if ( sp_update_main_results ( $id, $results ) ) { if ( sp_update_main_results( $id, $results ) ) {
wp_send_json_success(); wp_send_json_success();
} else { } else {
wp_send_json_error(); wp_send_json_error();

View File

@@ -2,144 +2,149 @@
/** /**
* Load assets. * Load assets.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 2.6.15 * @version 2.6.15
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Assets' ) ) : if ( ! class_exists( 'SP_Admin_Assets' ) ) :
/**
* SP_Admin_Assets Class
*/
class SP_Admin_Assets {
/** /**
* Hook in tabs. * SP_Admin_Assets Class
*/ */
public function __construct() { class SP_Admin_Assets {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
}
/** /**
* Enqueue styles * Hook in tabs.
*/ */
public function admin_styles( $hook ) { public function __construct() {
// Sitewide menu CSS add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
wp_enqueue_style( 'sportspress-admin-menu-styles', SP()->plugin_url() . '/assets/css/menu.css', array(), SP_VERSION ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
$screen = get_current_screen();
if ( in_array( $screen->id, sp_get_screen_ids() ) ) {
// Admin styles for SP pages only
wp_enqueue_style( 'jquery-chosen', SP()->plugin_url() . '/assets/css/chosen.css', array(), '1.1.0' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION );
} elseif ( strpos( $screen->id, 'sportspress-config' ) !== false ) {
wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION );
} }
if ( strpos( $screen->id, 'sportspress-overview' ) !== false ) { /**
wp_enqueue_style( 'sportspress-admin-slickmap', SP()->plugin_url() . '/assets/css/slickmap.css', array(), '1.1.0' ); * Enqueue styles
*/
public function admin_styles( $hook ) {
// Sitewide menu CSS
wp_enqueue_style( 'sportspress-admin-menu-styles', SP()->plugin_url() . '/assets/css/menu.css', array(), SP_VERSION );
$screen = get_current_screen();
if ( in_array( $screen->id, sp_get_screen_ids() ) ) {
// Admin styles for SP pages only
wp_enqueue_style( 'jquery-chosen', SP()->plugin_url() . '/assets/css/chosen.css', array(), '1.1.0' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION );
} elseif ( strpos( $screen->id, 'sportspress-config' ) !== false ) {
wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION );
}
if ( strpos( $screen->id, 'sportspress-overview' ) !== false ) {
wp_enqueue_style( 'sportspress-admin-slickmap', SP()->plugin_url() . '/assets/css/slickmap.css', array(), '1.1.0' );
}
if ( in_array( $screen->id, array( 'dashboard' ) ) ) {
wp_enqueue_style( 'sportspress-admin-dashboard-styles', SP()->plugin_url() . '/assets/css/dashboard.css', array(), SP_VERSION );
}
if ( in_array( $screen->id, array( 'customize' ) ) ) {
wp_enqueue_style( 'sportspress-admin-customize-styles', SP()->plugin_url() . '/assets/css/customize.css', array(), SP_VERSION );
}
if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) {
wp_enqueue_style( 'sportspress-admin-equation-styles', SP()->plugin_url() . '/assets/css/equation.css', array(), SP_VERSION );
}
if ( in_array( $screen->id, apply_filters( 'sportspress_admin_datepicker_screen_ids', array( 'sp_calendar', 'sp_table', 'sp_list', 'widgets' ) ) ) || in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) {
wp_enqueue_style( 'jquery-ui-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css' );
wp_enqueue_style( 'sportspress-admin-datepicker-styles', SP()->plugin_url() . '/assets/css/datepicker.css', array( 'jquery-ui-style' ), SP_VERSION );
}
do_action( 'sportspress_admin_css', $screen );
} }
if ( in_array( $screen->id, array( 'dashboard' ) ) ) { /**
wp_enqueue_style( 'sportspress-admin-dashboard-styles', SP()->plugin_url() . '/assets/css/dashboard.css', array(), SP_VERSION ); * Enqueue scripts
} */
public function admin_scripts( $hook ) {
global $wp_query, $post;
if ( in_array( $screen->id, array( 'customize' ) ) ) { $screen = get_current_screen();
wp_enqueue_style( 'sportspress-admin-customize-styles', SP()->plugin_url() . '/assets/css/customize.css', array(), SP_VERSION );
}
if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) { // Register scripts
wp_enqueue_style( 'sportspress-admin-equation-styles', SP()->plugin_url() . '/assets/css/equation.css', array(), SP_VERSION ); wp_register_script( 'chosen', SP()->plugin_url() . '/assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
}
if ( in_array( $screen->id, apply_filters( 'sportspress_admin_datepicker_screen_ids', array( 'sp_calendar', 'sp_table', 'sp_list', 'widgets' ) ) ) || in_array( $hook, array('post.php', 'post-new.php') ) ) { wp_register_script( 'jquery-tiptip', SP()->plugin_url() . '/assets/js/jquery.tipTip.min.js', array( 'jquery' ), '1.3', true );
wp_enqueue_style( 'jquery-ui-style' , '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css' );
wp_enqueue_style( 'sportspress-admin-datepicker-styles', SP()->plugin_url() . '/assets/css/datepicker.css', array( 'jquery-ui-style' ), SP_VERSION );
}
do_action( 'sportspress_admin_css', $screen ); wp_register_script( 'jquery-caret', SP()->plugin_url() . '/assets/js/jquery.caret.min.js', array( 'jquery' ), '1.02', true );
}
/** wp_register_script( 'jquery-fitvids', SP()->plugin_url() . '/assets/js/jquery.fitvids.js', array( 'jquery' ), '1.1', true );
* Enqueue scripts
*/
public function admin_scripts($hook) {
global $wp_query, $post;
$screen = get_current_screen(); wp_register_script( 'sportspress-admin-equationbuilder', SP()->plugin_url() . '/assets/js/admin/equationbuilder.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable' ), SP_VERSION, true );
// Register scripts wp_register_script( 'sportspress-admin-colorpicker', SP()->plugin_url() . '/assets/js/admin/colorpicker.js', array( 'jquery', 'wp-color-picker', 'iris' ), SP_VERSION, true );
wp_register_script( 'chosen', SP()->plugin_url() . '/assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
wp_register_script( 'jquery-tiptip', SP()->plugin_url() . '/assets/js/jquery.tipTip.min.js', array( 'jquery' ), '1.3', true ); wp_register_script( 'sportspress-admin-widgets', SP()->plugin_url() . '/assets/js/admin/widgets.js', array( 'jquery' ), SP_VERSION, true );
wp_register_script( 'jquery-caret', SP()->plugin_url() . '/assets/js/jquery.caret.min.js', array( 'jquery' ), '1.02', true ); wp_register_script( 'sportspress-admin-quickeditor', SP()->plugin_url() . '/assets/js/admin/quickeditor.js', array( 'jquery' ), SP_VERSION, true );
wp_register_script( 'jquery-fitvids', SP()->plugin_url() . '/assets/js/jquery.fitvids.js', array( 'jquery' ), '1.1', true ); // SportsPress admin pages
if ( in_array( $screen->id, sp_get_screen_ids() ) || strpos( $screen->id, 'sportspress-config' ) || in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) {
wp_register_script( 'sportspress-admin-equationbuilder', SP()->plugin_url() . '/assets/js/admin/equationbuilder.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable' ), SP_VERSION, true ); wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'chosen' );
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-ui-draggable' );
wp_enqueue_script( 'jquery-ui-droppable' );
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'jquery-tiptip' );
wp_enqueue_script( 'jquery-caret' );
wp_enqueue_script( 'jquery-fitvids' );
wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret', 'jquery-fitvids' ), SP_VERSION, true );
wp_register_script( 'sportspress-admin-colorpicker', SP()->plugin_url() . '/assets/js/admin/colorpicker.js', array( 'jquery', 'wp-color-picker', 'iris' ), SP_VERSION, true ); $strings = apply_filters(
'sportspress_localized_strings',
array(
'none' => __( 'None', 'sportspress' ),
'remove_text' => __( '&mdash; Remove &mdash;', 'sportspress' ),
'days' => __( 'days', 'sportspress' ),
'hrs' => __( 'hrs', 'sportspress' ),
'mins' => __( 'mins', 'sportspress' ),
'secs' => __( 'secs', 'sportspress' ),
'displaying_posts' => html_entity_decode( __( 'Displaying %1$s&#8211;%2$s of %3$s', 'sportspress' ) ),
)
);
wp_register_script( 'sportspress-admin-widgets', SP()->plugin_url() . '/assets/js/admin/widgets.js', array( 'jquery' ), SP_VERSION, true ); // Localize scripts
wp_localize_script( 'sportspress-admin', 'localized_strings', $strings );
}
wp_register_script( 'sportspress-admin-quickeditor', SP()->plugin_url() . '/assets/js/admin/quickeditor.js', array( 'jquery' ), SP_VERSION, true ); if ( in_array( $screen->id, array( 'widgets' ) ) ) {
wp_enqueue_script( 'sportspress-admin-widgets' );
}
// SportsPress admin pages // Edit color
if ( in_array( $screen->id, sp_get_screen_ids() ) || strpos( $screen->id, 'sportspress-config' ) || in_array($hook, array('post.php', 'post-new.php') ) ) { if ( in_array( $screen->id, array( 'sp_outcome' ) ) ) {
wp_enqueue_script( 'sportspress-admin-colorpicker' );
}
wp_enqueue_script( 'jquery' ); // Edit equation
wp_enqueue_script( 'chosen' ); if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) {
wp_enqueue_script( 'jquery-ui-core' ); wp_enqueue_script( 'sportspress-admin-equationbuilder' );
wp_enqueue_script( 'jquery-ui-draggable' ); }
wp_enqueue_script( 'jquery-ui-droppable' );
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'jquery-tiptip' );
wp_enqueue_script( 'jquery-caret' );
wp_enqueue_script( 'jquery-fitvids' );
wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret', 'jquery-fitvids' ), SP_VERSION, true );
$strings = apply_filters( 'sportspress_localized_strings', array(
'none' => __( 'None', 'sportspress' ),
'remove_text' => __( '&mdash; Remove &mdash;', 'sportspress' ),
'days' => __( 'days', 'sportspress' ),
'hrs' => __( 'hrs', 'sportspress' ),
'mins' => __( 'mins', 'sportspress' ),
'secs' => __( 'secs', 'sportspress' ),
'displaying_posts' => html_entity_decode( __( 'Displaying %s&#8211;%s of %s', 'sportspress' ) ),
) );
// Localize scripts // Quick edit
wp_localize_script( 'sportspress-admin', 'localized_strings', $strings ); if ( in_array( $screen->id, array( 'edit-sp_player' ) ) ) {
} wp_enqueue_script( 'sportspress-admin-quickeditor' );
}
if ( in_array( $screen->id, array( 'widgets' ) ) ) {
wp_enqueue_script( 'sportspress-admin-widgets' );
}
// Edit color
if ( in_array( $screen->id, array( 'sp_outcome' ) ) ) {
wp_enqueue_script( 'sportspress-admin-colorpicker' );
}
// Edit equation
if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) {
wp_enqueue_script( 'sportspress-admin-equationbuilder' );
}
// Quick edit
if ( in_array( $screen->id, array( 'edit-sp_player' ) ) ) {
wp_enqueue_script( 'sportspress-admin-quickeditor' );
} }
} }
}
endif; endif;

View File

@@ -2,126 +2,130 @@
/** /**
* Admin Dashboard * Admin Dashboard
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Dashboard' ) ) : if ( ! class_exists( 'SP_Admin_Dashboard' ) ) :
/** /**
* SP_Admin_Dashboard Class * SP_Admin_Dashboard Class
*/ */
class SP_Admin_Dashboard { class SP_Admin_Dashboard {
/** /**
* Hook in tabs. * Hook in tabs.
*/ */
public function __construct() { public function __construct() {
// Only hook in admin parts if the user has admin access // Only hook in admin parts if the user has admin access
if ( current_user_can( 'view_sportspress_reports' ) || current_user_can( 'manage_sportspress' ) || current_user_can( 'publish_sp_events' ) ) { if ( current_user_can( 'view_sportspress_reports' ) || current_user_can( 'manage_sportspress' ) || current_user_can( 'publish_sp_events' ) ) {
add_action( 'wp_dashboard_setup', array( $this, 'init' ) ); add_action( 'wp_dashboard_setup', array( $this, 'init' ) );
} }
} }
/** /**
* Init dashboard widgets * Init dashboard widgets
*/ */
public function init() { public function init() {
//wp_add_dashboard_widget( 'sportspress_dashboard_news', __( 'Sports News', 'sportspress' ), array( $this, 'news_widget' ), null, null, 'side' ); // wp_add_dashboard_widget( 'sportspress_dashboard_news', __( 'Sports News', 'sportspress' ), array( $this, 'news_widget' ), null, null, 'side' );
wp_add_dashboard_widget( 'sportspress_dashboard_status', __( 'SportsPress', 'sportspress' ), array( $this, 'status_widget' ) ); wp_add_dashboard_widget( 'sportspress_dashboard_status', __( 'SportsPress', 'sportspress' ), array( $this, 'status_widget' ) );
add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 ); add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 );
} }
/** /**
* Add links to At a Glance * Add links to At a Glance
*/ */
function glance_items( $items = array() ) { function glance_items( $items = array() ) {
$post_types = apply_filters( 'sportspress_glance_items', array( 'sp_event', 'sp_team', 'sp_player', 'sp_staff' ) ); $post_types = apply_filters( 'sportspress_glance_items', array( 'sp_event', 'sp_team', 'sp_player', 'sp_staff' ) );
foreach ( $post_types as $type ): foreach ( $post_types as $type ) :
if ( ! post_type_exists( $type ) ) continue; if ( ! post_type_exists( $type ) ) {
$num_posts = wp_count_posts( $type ); continue;
if ( $num_posts ): }
$published = intval( $num_posts->publish ); $num_posts = wp_count_posts( $type );
$post_type = get_post_type_object( $type ); if ( $num_posts ) :
$text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'sportspress' ); $published = intval( $num_posts->publish );
$text = sprintf( $text, number_format_i18n( $published ) ); $post_type = get_post_type_object( $type );
if ( current_user_can( $post_type->cap->edit_posts ) ): $text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'sportspress' );
$output = '<a href="edit.php?post_type=' . $post_type->name . '">' . $text . '</a>'; $text = sprintf( $text, number_format_i18n( $published ) );
else: if ( current_user_can( $post_type->cap->edit_posts ) ) :
$output = '<span>' . $text . '</span>'; $output = '<a href="edit.php?post_type=' . $post_type->name . '">' . $text . '</a>';
endif; else :
echo '<li class="post-count ' . eac_attr( $post_type->name ) . '-count">' . esc_html( $output ) . '</li>'; $output = '<span>' . $text . '</span>';
endif; endif;
endforeach; echo '<li class="post-count ' . eac_attr( $post_type->name ) . '-count">' . esc_html( $output ) . '</li>';
return $items; endif;
} endforeach;
return $items;
}
/** /**
* Show status widget * Show status widget
*/ */
public function status_widget() { public function status_widget() {
?> ?>
<ul class="sp_status_list"> <ul class="sp_status_list">
<?php <?php
$count = wp_count_posts( 'sp_event' ); $count = wp_count_posts( 'sp_event' );
$scheduled_count = isset( $count->future ) ? $count->future : 0; $scheduled_count = isset( $count->future ) ? $count->future : 0;
$published_count = isset( $count->publish ) ? $count->publish : 0; $published_count = isset( $count->publish ) ? $count->publish : 0;
$next_event = sp_get_next_event(); $next_event = sp_get_next_event();
if ( $next_event ): if ( $next_event ) :
$now = new DateTime( current_time( 'mysql', 0 ) ); $now = new DateTime( current_time( 'mysql', 0 ) );
$date = new DateTime( $next_event->post_date ); $date = new DateTime( $next_event->post_date );
$interval = date_diff( $now, $date ); $interval = date_diff( $now, $date );
?> ?>
<li class="countdown" data-countdown="<?php echo str_replace( '-', '/', get_gmt_from_date( $next_event->post_date ) ); ?>"> <li class="countdown" data-countdown="<?php echo str_replace( '-', '/', get_gmt_from_date( $next_event->post_date ) ); ?>">
<a href="<?php echo get_edit_post_link( $next_event->ID ); ?>"> <a href="<?php echo get_edit_post_link( $next_event->ID ); ?>">
<?php printf( __( '<strong>%s</strong> until next event', 'sportspress' ), $interval->days . ' ' . __( 'days', 'sportspress' ) . ' ' . sprintf( '%02s:%02s:%02s', $interval->h, $interval->i, $interval->s ) ); ?> <?php printf( __( '<strong>%s</strong> until next event', 'sportspress' ), $interval->days . ' ' . __( 'days', 'sportspress' ) . ' ' . sprintf( '%02s:%02s:%02s', $interval->h, $interval->i, $interval->s ) ); ?>
(<?php echo esc_html( $next_event->post_title ); ?>) (<?php echo esc_html( $next_event->post_title ); ?>)
</a> </a>
</li> </li>
<?php endif; ?> <?php endif; ?>
<li class="events-scheduled"> <li class="events-scheduled">
<a href="<?php echo admin_url( 'edit.php?post_type=sp_event&post_status=future' ); ?>"> <a href="<?php echo admin_url( 'edit.php?post_type=sp_event&post_status=future' ); ?>">
<?php printf( _n( '<strong>%s event</strong> scheduled', '<strong>%s events</strong> scheduled', $scheduled_count, 'sportspress' ), $scheduled_count ); ?> <?php printf( _n( '<strong>%s event</strong> scheduled', '<strong>%s events</strong> scheduled', $scheduled_count, 'sportspress' ), $scheduled_count ); ?>
</a> </a>
</li> </li>
<li class="events-published"> <li class="events-published">
<a href="<?php echo admin_url( 'edit.php?post_type=sp_event&post_status=publish' ); ?>"> <a href="<?php echo admin_url( 'edit.php?post_type=sp_event&post_status=publish' ); ?>">
<?php printf( _n( '<strong>%s event</strong> published', '<strong>%s events</strong> published', $published_count, 'sportspress' ), $published_count ); ?> <?php printf( _n( '<strong>%s event</strong> published', '<strong>%s events</strong> published', $published_count, 'sportspress' ), $published_count ); ?>
</a> </a>
</li> </li>
</ul> </ul>
<?php <?php
} }
/** /**
* Show news widget * Show news widget
*/ */
public function news_widget() { public function news_widget() {
$rss = fetch_feed("https://tboy.co/sportsnews/"); $rss = fetch_feed( 'https://tboy.co/sportsnews/' );
if (!is_wp_error($rss)) { // Checks that the object is created correctly if ( ! is_wp_error( $rss ) ) { // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 2. // Figure out how many total items there are, but limit it to 2.
$maxitems = $rss->get_item_quantity(5); $maxitems = $rss->get_item_quantity( 5 );
// Build an array of all the items, starting with element 0 (first element). // Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items(0, $maxitems); $rss_items = $rss->get_items( 0, $maxitems );
} }
if (!empty($maxitems)) { if ( ! empty( $maxitems ) ) {
?> ?>
<div class="rss-widget"> <div class="rss-widget">
<ul> <ul>
<?php foreach ($rss_items as $item) { ?> <?php foreach ( $rss_items as $item ) { ?>
<li><a class="rsswidget" href="<?php echo esc_url( $item->get_permalink() ); ?>" target="_blank"><?php echo esc_attr( $item->get_title() ); ?></a> <span class="rss-date"><?php echo esc_html( $item->get_date('j F Y') ); ?></span></li> <li><a class="rsswidget" href="<?php echo esc_url( $item->get_permalink() ); ?>" target="_blank"><?php echo esc_attr( $item->get_title() ); ?></a> <span class="rss-date"><?php echo esc_html( $item->get_date( 'j F Y' ) ); ?></span></li>
<?php } ?> <?php } ?>
</ul> </ul>
</div> </div>
<?php <?php
} }
} }
} }
endif; endif;
return new SP_Admin_Dashboard(); return new SP_Admin_Dashboard();

View File

@@ -4,11 +4,11 @@
* *
* Methods which tweak the WP Editor. * Methods which tweak the WP Editor.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 2.4 * @version 2.4
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly exit; // Exit if accessed directly
@@ -51,8 +51,8 @@ class SP_Admin_Editor {
* @return array * @return array
*/ */
public function add_tinymce_lang( $arr ) { public function add_tinymce_lang( $arr ) {
$arr['sp_shortcodes_button'] = SP()->plugin_path() . '/assets/js/admin/editor-lang.php'; $arr['sp_shortcodes_button'] = SP()->plugin_path() . '/assets/js/admin/editor-lang.php';
return $arr; return $arr;
} }
/** /**

View File

@@ -2,166 +2,172 @@
/** /**
* Setup importers for SP data. * Setup importers for SP data.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 2.5.1 * @version 2.5.1
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Importers' ) ) : if ( ! class_exists( 'SP_Admin_Importers' ) ) :
/**
* SP_Admin_Importers Class
*/
class SP_Admin_Importers {
/** /**
* Hook in tabs. * SP_Admin_Importers Class
*/ */
public function __construct() { class SP_Admin_Importers {
add_action( 'admin_init', array( $this, 'register_importers' ) );
}
/** /**
* Add menu items * Hook in tabs.
*/ */
public function register_importers() { public function __construct() {
global $pagenow; add_action( 'admin_init', array( $this, 'register_importers' ) );
$importers = apply_filters( 'sportspress_importers', array( }
'sp_event_csv' => array(
'name' => __( 'SportsPress Events (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>events</strong> from a csv file.', 'sportspress'),
'callback' => array( $this, 'events_importer' ),
),
'sp_fixture_csv' => array(
'name' => __( 'SportsPress Fixtures (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>upcoming events</strong> from a csv file.', 'sportspress'),
'callback' => array( $this, 'fixtures_importer' ),
),
'sp_team_csv' => array(
'name' => __( 'SportsPress Teams (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>teams</strong> from a csv file.', 'sportspress'),
'callback' => array( $this, 'teams_importer' ),
),
'sp_player_csv' => array(
'name' => __( 'SportsPress Players (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>players</strong> from a csv file.', 'sportspress'),
'callback' => array( $this, 'players_importer' ),
),
'sp_staff_csv' => array(
'name' => __( 'SportsPress Staff (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>staff</strong> from a csv file.', 'sportspress'),
'callback' => array( $this, 'staff_importer' ),
),
) );
if ( 'import.php' !== $pagenow ) { /**
$importers['sp_event_performance_csv'] = array( * Add menu items
'name' => __( 'SportsPress Box Score (CSV)', 'sportspress' ), */
'description' => '<a href="' . admin_url( add_query_arg( array( 'post_type' => 'sp_event' ), 'edit.php' ) ) . '">' . sprintf( __( 'Select %s', 'sportspress' ), __( 'Event', 'sportspress' ) ) . '</a>', public function register_importers() {
'callback' => array( $this, 'event_performance_importer' ), global $pagenow;
$importers = apply_filters(
'sportspress_importers',
array(
'sp_event_csv' => array(
'name' => __( 'SportsPress Events (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>events</strong> from a csv file.', 'sportspress' ),
'callback' => array( $this, 'events_importer' ),
),
'sp_fixture_csv' => array(
'name' => __( 'SportsPress Fixtures (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>upcoming events</strong> from a csv file.', 'sportspress' ),
'callback' => array( $this, 'fixtures_importer' ),
),
'sp_team_csv' => array(
'name' => __( 'SportsPress Teams (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>teams</strong> from a csv file.', 'sportspress' ),
'callback' => array( $this, 'teams_importer' ),
),
'sp_player_csv' => array(
'name' => __( 'SportsPress Players (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>players</strong> from a csv file.', 'sportspress' ),
'callback' => array( $this, 'players_importer' ),
),
'sp_staff_csv' => array(
'name' => __( 'SportsPress Staff (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>staff</strong> from a csv file.', 'sportspress' ),
'callback' => array( $this, 'staff_importer' ),
),
)
); );
if ( 'import.php' !== $pagenow ) {
$importers['sp_event_performance_csv'] = array(
'name' => __( 'SportsPress Box Score (CSV)', 'sportspress' ),
'description' => '<a href="' . admin_url( add_query_arg( array( 'post_type' => 'sp_event' ), 'edit.php' ) ) . '">' . sprintf( __( 'Select %s', 'sportspress' ), __( 'Event', 'sportspress' ) ) . '</a>',
'callback' => array( $this, 'event_performance_importer' ),
);
}
foreach ( $importers as $id => $importer ) {
register_importer( $id, $importer['name'], $importer['description'], $importer['callback'] );
}
} }
foreach ( $importers as $id => $importer ) { /**
register_importer( $id, $importer['name'], $importer['description'], $importer['callback'] ); * Add menu item
*/
public function events_importer() {
$this->includes();
require 'importers/class-sp-event-importer.php';
// Dispatch
$importer = new SP_Event_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function event_performance_importer() {
$this->includes();
require 'importers/class-sp-event-performance-importer.php';
// Dispatch
$importer = new SP_Event_Performance_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function fixtures_importer() {
$this->includes();
require 'importers/class-sp-fixture-importer.php';
// Dispatch
$importer = new SP_Fixture_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function teams_importer() {
$this->includes();
require 'importers/class-sp-team-importer.php';
// Dispatch
$importer = new SP_Team_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function players_importer() {
$this->includes();
require 'importers/class-sp-player-importer.php';
// Dispatch
$importer = new SP_Player_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function staff_importer() {
$this->includes();
require 'importers/class-sp-staff-importer.php';
// Dispatch
$importer = new SP_Staff_Importer();
$importer->dispatch();
}
public static function includes() {
// Load Importer API
require_once ABSPATH . 'wp-admin/includes/import.php';
if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) ) {
require $class_wp_importer;
}
}
require 'importers/class-sp-importer.php';
} }
} }
/**
* Add menu item
*/
public function events_importer() {
$this->includes();
require 'importers/class-sp-event-importer.php';
// Dispatch
$importer = new SP_Event_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function event_performance_importer() {
$this->includes();
require 'importers/class-sp-event-performance-importer.php';
// Dispatch
$importer = new SP_Event_Performance_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function fixtures_importer() {
$this->includes();
require 'importers/class-sp-fixture-importer.php';
// Dispatch
$importer = new SP_Fixture_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function teams_importer() {
$this->includes();
require 'importers/class-sp-team-importer.php';
// Dispatch
$importer = new SP_Team_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function players_importer() {
$this->includes();
require 'importers/class-sp-player-importer.php';
// Dispatch
$importer = new SP_Player_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function staff_importer() {
$this->includes();
require 'importers/class-sp-staff-importer.php';
// Dispatch
$importer = new SP_Staff_Importer();
$importer->dispatch();
}
public static function includes() {
// Load Importer API
require_once ABSPATH . 'wp-admin/includes/import.php';
if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) )
require $class_wp_importer;
}
require 'importers/class-sp-importer.php';
}
}
endif; endif;
return new SP_Admin_Importers(); return new SP_Admin_Importers();

View File

@@ -2,283 +2,293 @@
/** /**
* Setup menus in WP admin. * Setup menus in WP admin.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Menus' ) ) : if ( ! class_exists( 'SP_Admin_Menus' ) ) :
/**
* SP_Admin_Menus Class
*/
class SP_Admin_Menus {
/** /**
* Hook in tabs. * SP_Admin_Menus Class
*/ */
public function __construct() { class SP_Admin_Menus {
add_filter( 'admin_menu', array( $this, 'menu_clean' ), 5 );
add_action( 'admin_menu', array( $this, 'admin_menu' ), 6 );
add_action( 'admin_menu', array( $this, 'config_menu' ), 7 );
add_action( 'admin_menu', array( $this, 'leagues_menu' ), 20 );
add_action( 'admin_menu', array( $this, 'seasons_menu' ), 21 );
add_action( 'admin_head', array( $this, 'menu_highlight' ) ); /**
add_action( 'admin_head', array( $this, 'menu_rename' ) ); * Hook in tabs.
add_action( 'parent_file', array( $this, 'parent_file' ) ); */
add_filter( 'menu_order', array( $this, 'menu_order' ) ); public function __construct() {
add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) ); add_filter( 'admin_menu', array( $this, 'menu_clean' ), 5 );
add_filter( 'sportspress_sitemap_taxonomy_post_types', array( $this, 'sitemap_taxonomy_post_types' ), 10, 2 ); add_action( 'admin_menu', array( $this, 'admin_menu' ), 6 );
} add_action( 'admin_menu', array( $this, 'config_menu' ), 7 );
add_action( 'admin_menu', array( $this, 'leagues_menu' ), 20 );
add_action( 'admin_menu', array( $this, 'seasons_menu' ), 21 );
/** add_action( 'admin_head', array( $this, 'menu_highlight' ) );
* Add menu item add_action( 'admin_head', array( $this, 'menu_rename' ) );
*/ add_action( 'parent_file', array( $this, 'parent_file' ) );
public function admin_menu() { add_filter( 'menu_order', array( $this, 'menu_order' ) );
global $menu; add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) );
add_filter( 'sportspress_sitemap_taxonomy_post_types', array( $this, 'sitemap_taxonomy_post_types' ), 10, 2 );
if ( current_user_can( 'manage_sportspress' ) )
$menu[] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
$main_page = add_menu_page( __( 'SportsPress', 'sportspress' ), __( 'SportsPress', 'sportspress' ), 'manage_sportspress', 'sportspress', array( $this, 'settings_page' ), apply_filters( 'sportspress_menu_icon', null ), '51.5' );
}
/**
* Add menu item
*/
public function config_menu() {
add_submenu_page( 'sportspress', __( 'Configure', 'sportspress' ), __( 'Configure', 'sportspress' ), 'manage_sportspress', 'sportspress-config', array( $this, 'config_page' ) );
}
/**
* Add menu item
*/
public function leagues_menu() {
add_submenu_page( 'sportspress', __( 'Leagues', 'sportspress' ), __( 'Leagues', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_league');
}
/**
* Add menu item
*/
public function seasons_menu() {
add_submenu_page( 'sportspress', __( 'Seasons', 'sportspress' ), __( 'Seasons', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_season');
}
/**
* Highlights the correct top level admin menu item for post type add screens.
*
* @access public
* @return void
*/
public function menu_highlight() {
global $typenow;
$screen = get_current_screen();
if ( ! is_object( $screen ) ) return;
if ( $screen->id == 'sp_role' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_staff', 'edit-tags.php?taxonomy=sp_role&post_type=sp_staff' );
} elseif ( is_sp_config_type( $typenow ) ) {
$this->highlight_admin_menu( 'sportspress', 'sportspress-config' );
} elseif ( $typenow == 'sp_calendar' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_event', 'edit.php?post_type=sp_calendar' );
} elseif ( $typenow == 'sp_table' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_team', 'edit.php?post_type=sp_table' );
} elseif ( $typenow == 'sp_list' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_list' );
} }
}
/** /**
* Renames admin menu items. * Add menu item
* */
* @access public public function admin_menu() {
* @return void global $menu;
*/
public function menu_rename() {
global $menu, $submenu;
if ( isset( $submenu['sportspress'] ) && isset( $submenu['sportspress'][0] ) && isset( $submenu['sportspress'][0][0] ) ) if ( current_user_can( 'manage_sportspress' ) ) {
$submenu['sportspress'][0][0] = __( 'Settings', 'sportspress' ); $menu[] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
} }
public function parent_file( $parent_file ) { $main_page = add_menu_page( __( 'SportsPress', 'sportspress' ), __( 'SportsPress', 'sportspress' ), 'manage_sportspress', 'sportspress', array( $this, 'settings_page' ), apply_filters( 'sportspress_menu_icon', null ), '51.5' );
global $current_screen; }
$taxonomy = $current_screen->taxonomy;
if ( in_array( $taxonomy, array( 'sp_league', 'sp_season' ) ) )
$parent_file = 'sportspress';
return $parent_file;
}
/** /**
* Reorder the SP menu items in admin. * Add menu item
* */
* @param mixed $menu_order public function config_menu() {
* @return array add_submenu_page( 'sportspress', __( 'Configure', 'sportspress' ), __( 'Configure', 'sportspress' ), 'manage_sportspress', 'sportspress-config', array( $this, 'config_page' ) );
*/ }
public function menu_order( $menu_order ) {
// Initialize our custom order array
$sportspress_menu_order = array();
// Get the index of our custom separator /**
$sportspress_separator = array_search( 'separator-sportspress', $menu_order ); * Add menu item
*/
public function leagues_menu() {
add_submenu_page( 'sportspress', __( 'Leagues', 'sportspress' ), __( 'Leagues', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_league' );
}
// Get index of menu items /**
$sportspress_event = array_search( 'edit.php?post_type=sp_event', $menu_order ); * Add menu item
$sportspress_team = array_search( 'edit.php?post_type=sp_team', $menu_order ); */
$sportspress_player = array_search( 'edit.php?post_type=sp_player', $menu_order ); public function seasons_menu() {
$sportspress_staff = array_search( 'edit.php?post_type=sp_staff', $menu_order ); add_submenu_page( 'sportspress', __( 'Seasons', 'sportspress' ), __( 'Seasons', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_season' );
}
// Loop through menu order and do some rearranging /**
foreach ( $menu_order as $index => $item ): * Highlights the correct top level admin menu item for post type add screens.
*
* @access public
* @return void
*/
public function menu_highlight() {
global $typenow;
$screen = get_current_screen();
if ( ! is_object( $screen ) ) {
return;
}
if ( $screen->id == 'sp_role' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_staff', 'edit-tags.php?taxonomy=sp_role&post_type=sp_staff' );
} elseif ( is_sp_config_type( $typenow ) ) {
$this->highlight_admin_menu( 'sportspress', 'sportspress-config' );
} elseif ( $typenow == 'sp_calendar' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_event', 'edit.php?post_type=sp_calendar' );
} elseif ( $typenow == 'sp_table' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_team', 'edit.php?post_type=sp_table' );
} elseif ( $typenow == 'sp_list' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_list' );
}
}
if ( ( ( 'sportspress' ) == $item ) ): /**
$sportspress_menu_order[] = 'separator-sportspress'; * Renames admin menu items.
$sportspress_menu_order[] = $item; *
$sportspress_menu_order[] = 'edit.php?post_type=sp_event'; * @access public
$sportspress_menu_order[] = 'edit.php?post_type=sp_team'; * @return void
$sportspress_menu_order[] = 'edit.php?post_type=sp_player'; */
$sportspress_menu_order[] = 'edit.php?post_type=sp_staff'; public function menu_rename() {
unset( $menu_order[ $sportspress_separator ] ); global $menu, $submenu;
unset( $menu_order[ $sportspress_event ] );
unset( $menu_order[ $sportspress_team ] );
unset( $menu_order[ $sportspress_player ] );
unset( $menu_order[ $sportspress_staff ] );
// Apply to added menu items if ( isset( $submenu['sportspress'] ) && isset( $submenu['sportspress'][0] ) && isset( $submenu['sportspress'][0][0] ) ) {
$menu_items = apply_filters( 'sportspress_menu_items', array() ); $submenu['sportspress'][0][0] = __( 'Settings', 'sportspress' );
foreach ( $menu_items as $menu_item ): }
$sportspress_menu_order[] = $menu_item; }
$index = array_search( $menu_item, $menu_order );
unset( $menu_order[ $index ] );
endforeach;
elseif ( !in_array( $item, array( 'separator-sportspress' ) ) ) : public function parent_file( $parent_file ) {
$sportspress_menu_order[] = $item; global $current_screen;
$taxonomy = $current_screen->taxonomy;
if ( in_array( $taxonomy, array( 'sp_league', 'sp_season' ) ) ) {
$parent_file = 'sportspress';
}
return $parent_file;
}
/**
* Reorder the SP menu items in admin.
*
* @param mixed $menu_order
* @return array
*/
public function menu_order( $menu_order ) {
// Initialize our custom order array
$sportspress_menu_order = array();
// Get the index of our custom separator
$sportspress_separator = array_search( 'separator-sportspress', $menu_order );
// Get index of menu items
$sportspress_event = array_search( 'edit.php?post_type=sp_event', $menu_order );
$sportspress_team = array_search( 'edit.php?post_type=sp_team', $menu_order );
$sportspress_player = array_search( 'edit.php?post_type=sp_player', $menu_order );
$sportspress_staff = array_search( 'edit.php?post_type=sp_staff', $menu_order );
// Loop through menu order and do some rearranging
foreach ( $menu_order as $index => $item ) :
if ( ( ( 'sportspress' ) == $item ) ) :
$sportspress_menu_order[] = 'separator-sportspress';
$sportspress_menu_order[] = $item;
$sportspress_menu_order[] = 'edit.php?post_type=sp_event';
$sportspress_menu_order[] = 'edit.php?post_type=sp_team';
$sportspress_menu_order[] = 'edit.php?post_type=sp_player';
$sportspress_menu_order[] = 'edit.php?post_type=sp_staff';
unset( $menu_order[ $sportspress_separator ] );
unset( $menu_order[ $sportspress_event ] );
unset( $menu_order[ $sportspress_team ] );
unset( $menu_order[ $sportspress_player ] );
unset( $menu_order[ $sportspress_staff ] );
// Apply to added menu items
$menu_items = apply_filters( 'sportspress_menu_items', array() );
foreach ( $menu_items as $menu_item ) :
$sportspress_menu_order[] = $menu_item;
$index = array_search( $menu_item, $menu_order );
unset( $menu_order[ $index ] );
endforeach;
elseif ( ! in_array( $item, array( 'separator-sportspress' ) ) ) :
$sportspress_menu_order[] = $item;
endif;
endforeach;
// Return order
return $sportspress_menu_order;
}
/**
* custom_menu_order
*
* @return bool
*/
public function custom_menu_order() {
if ( ! current_user_can( 'manage_sportspress' ) ) {
return false;
}
return true;
}
/**
* Clean the SP menu items in admin.
*/
public function menu_clean() {
global $menu, $submenu, $current_user;
// 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; endif;
endforeach; // 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;
// Return order // Remove "Venues", "Leagues" and "Seasons" links from Teams submenu
return $sportspress_menu_order; if ( isset( $submenu['edit.php?post_type=sp_team'] ) ) :
$submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_venues' ) );
$submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], 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;
$user_roles = $current_user->roles;
$user_role = array_shift( $user_roles );
if ( in_array( $user_role, array( 'sp_player', 'sp_staff', 'sp_event_manager', 'sp_team_manager' ) ) ) :
remove_menu_page( 'upload.php' );
remove_menu_page( 'edit-comments.php' );
remove_menu_page( 'tools.php' );
endif;
}
/**
* Init the config page
*/
public function config_page() {
include 'views/html-admin-config.php';
}
/**
* 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' );
}
public static function highlight_admin_menu( $p = 'sportspress', $s = 'sportspress' ) {
global $parent_file, $submenu_file;
$parent_file = $p;
$submenu_file = $s;
}
public static function sitemap_taxonomy_post_types( $post_types = array(), $taxonomy = 'sp_venue' ) {
$post_types = array_intersect( $post_types, sp_primary_post_types() );
// Remove teams from venues taxonomy post type array
if ( $taxonomy === 'sp_venue' && ( $key = array_search( 'sp_team', $post_types ) ) !== false ) :
unset( $post_types[ $key ] );
endif;
return $post_types;
}
} }
/**
* custom_menu_order
* @return bool
*/
public function custom_menu_order() {
if ( ! current_user_can( 'manage_sportspress' ) )
return false;
return true;
}
/**
* Clean the SP menu items in admin.
*/
public function menu_clean() {
global $menu, $submenu, $current_user;
// 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 "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 "Venues", "Leagues" and "Seasons" links from Teams submenu
if ( isset( $submenu['edit.php?post_type=sp_team'] ) ):
$submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_venues' ) );
$submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], 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;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if ( in_array( $user_role, array( 'sp_player', 'sp_staff', 'sp_event_manager', 'sp_team_manager' ) ) ):
remove_menu_page( 'upload.php' );
remove_menu_page( 'edit-comments.php' );
remove_menu_page( 'tools.php' );
endif;
}
/**
* Init the config page
*/
public function config_page() {
include( 'views/html-admin-config.php' );
}
/**
* 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' );
}
public static function highlight_admin_menu( $p = 'sportspress', $s = 'sportspress' ) {
global $parent_file, $submenu_file;
$parent_file = $p;
$submenu_file = $s;
}
public static function sitemap_taxonomy_post_types( $post_types = array(), $taxonomy = 'sp_venue' ) {
$post_types = array_intersect( $post_types, sp_primary_post_types() );
// Remove teams from venues taxonomy post type array
if ( $taxonomy === 'sp_venue' && ( $key = array_search( 'sp_team', $post_types ) ) !== false ):
unset( $post_types[ $key ] );
endif;
return $post_types;
}
}
endif; endif;
return new SP_Admin_Menus(); return new SP_Admin_Menus();

View File

@@ -2,145 +2,149 @@
/** /**
* Display notices in admin. * Display notices in admin.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 2.3 * @version 2.3
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Notices' ) ) : if ( ! class_exists( 'SP_Admin_Notices' ) ) :
/**
* SP_Admin_Notices Class
*/
class SP_Admin_Notices {
/** /**
* Hook in tabs. * SP_Admin_Notices Class
*/ */
public function __construct() { class SP_Admin_Notices {
add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) );
add_action( 'sportspress_updated', array( $this, 'reset_admin_notices' ) );
add_action( 'admin_print_styles', array( $this, 'add_notices' ) );
}
/** /**
* Reset notices for themes when switched or a new version of SP is installed * Hook in tabs.
*/ */
public function reset_admin_notices() { public function __construct() {
update_option( 'sportspress_admin_notices', array( 'template_files', 'theme_support' ) ); add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) );
} add_action( 'sportspress_updated', array( $this, 'reset_admin_notices' ) );
add_action( 'admin_print_styles', array( $this, 'add_notices' ) );
/**
* Add notices + styles if needed.
*/
public function add_notices() {
$screen = get_current_screen();
$notices = get_option( 'sportspress_admin_notices', array() );
if ( ! is_object( $screen ) ) return;
if ( ! get_option( 'sportspress_completed_setup' ) && ! in_array( $screen->id, array( 'dashboard_page_sp-about', 'dashboard_page_sp-credits', 'dashboard_page_sp-translators' ) ) ) {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'setup_notice' ) );
} }
if ( 'post' == $screen->base ) { /**
$post_id = get_the_ID(); * Reset notices for themes when switched or a new version of SP is installed
if ( ! apply_filters( 'sportspress_user_can', current_user_can( 'edit_post', $post_id ), $post_id ) ) { */
add_action( 'admin_notices', array( $this, 'no_access_notice' ) ); public function reset_admin_notices() {
} update_option( 'sportspress_admin_notices', array( 'template_files', 'theme_support' ) );
} }
if ( ! empty( $_GET['hide_theme_support_notice'] ) ) { /**
$notices = array_diff( $notices, array( 'theme_support' ) ); * Add notices + styles if needed.
update_option( 'sportspress_admin_notices', $notices ); */
} public function add_notices() {
$screen = get_current_screen();
$notices = get_option( 'sportspress_admin_notices', array() );
if ( ! empty( $_GET['hide_template_files_notice'] ) ) { if ( ! is_object( $screen ) ) {
$notices = array_diff( $notices, array( 'template_files' ) ); return;
update_option( 'sportspress_admin_notices', $notices );
}
if ( in_array( 'theme_support', $notices ) && ! current_theme_supports( 'sportspress' ) && ! in_array( $screen->id, array( 'toplevel_page_sportspress', 'dashboard_page_sp-about', 'dashboard_page_sp-credits', 'dashboard_page_sp-translators' ) ) ) {
$template = get_option( 'template' );
if ( ! in_array( $template, array( 'twentyfifteen', 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ) {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'theme_check_notice' ) );
}
}
if ( in_array( 'template_files', $notices ) ) {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'template_file_check_notice' ) );
}
}
/**
* Show the setup notices
*/
public function setup_notice() {
include( 'views/html-notice-install.php' );
}
/**
* Displays a notice when the user doesn't have access to edit a post type
*/
public function no_access_notice() {
include( 'views/html-notice-no-access.php' );
}
/**
* Show the Theme Check notice
*/
public function theme_check_notice() {
include( 'views/html-notice-theme-support.php' );
}
/**
* Show a notice highlighting bad template files
*/
public function template_file_check_notice() {
if ( isset( $_GET['page'] ) && 'sportspress' == $_GET['page'] && isset( $_GET['tab'] ) && 'status' == $_GET['tab'] ) {
return;
}
$status = include( 'class-sp-admin-status.php' );
$core_templates = $status->scan_template_files( SP()->plugin_path() . '/templates' );
$outdated = false;
foreach ( $core_templates as $file ) {
$theme_file = false;
if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
$theme_file = get_stylesheet_directory() . '/' . $file;
} elseif ( file_exists( get_stylesheet_directory() . '/sportspress/' . $file ) ) {
$theme_file = get_stylesheet_directory() . '/sportspress/' . $file;
} elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
$theme_file = get_template_directory() . '/' . $file;
} elseif( file_exists( get_template_directory() . '/sportspress/' . $file ) ) {
$theme_file = get_template_directory() . '/sportspress/' . $file;
} }
if ( $theme_file ) { if ( ! get_option( 'sportspress_completed_setup' ) && ! in_array( $screen->id, array( 'dashboard_page_sp-about', 'dashboard_page_sp-credits', 'dashboard_page_sp-translators' ) ) ) {
$core_version = $status->get_file_version( SP()->plugin_path() . '/templates/' . $file ); wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
$theme_version = $status->get_file_version( $theme_file ); add_action( 'admin_notices', array( $this, 'setup_notice' ) );
}
if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) { if ( 'post' == $screen->base ) {
$outdated = true; $post_id = get_the_ID();
break; if ( ! apply_filters( 'sportspress_user_can', current_user_can( 'edit_post', $post_id ), $post_id ) ) {
add_action( 'admin_notices', array( $this, 'no_access_notice' ) );
} }
} }
if ( ! empty( $_GET['hide_theme_support_notice'] ) ) {
$notices = array_diff( $notices, array( 'theme_support' ) );
update_option( 'sportspress_admin_notices', $notices );
}
if ( ! empty( $_GET['hide_template_files_notice'] ) ) {
$notices = array_diff( $notices, array( 'template_files' ) );
update_option( 'sportspress_admin_notices', $notices );
}
if ( in_array( 'theme_support', $notices ) && ! current_theme_supports( 'sportspress' ) && ! in_array( $screen->id, array( 'toplevel_page_sportspress', 'dashboard_page_sp-about', 'dashboard_page_sp-credits', 'dashboard_page_sp-translators' ) ) ) {
$template = get_option( 'template' );
if ( ! in_array( $template, array( 'twentyfifteen', 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ) {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'theme_check_notice' ) );
}
}
if ( in_array( 'template_files', $notices ) ) {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'template_file_check_notice' ) );
}
} }
if ( $outdated ) { /**
include( 'views/html-notice-template-check.php' ); * Show the setup notices
*/
public function setup_notice() {
include 'views/html-notice-install.php';
}
/**
* Displays a notice when the user doesn't have access to edit a post type
*/
public function no_access_notice() {
include 'views/html-notice-no-access.php';
}
/**
* Show the Theme Check notice
*/
public function theme_check_notice() {
include 'views/html-notice-theme-support.php';
}
/**
* Show a notice highlighting bad template files
*/
public function template_file_check_notice() {
if ( isset( $_GET['page'] ) && 'sportspress' == $_GET['page'] && isset( $_GET['tab'] ) && 'status' == $_GET['tab'] ) {
return;
}
$status = include 'class-sp-admin-status.php';
$core_templates = $status->scan_template_files( SP()->plugin_path() . '/templates' );
$outdated = false;
foreach ( $core_templates as $file ) {
$theme_file = false;
if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
$theme_file = get_stylesheet_directory() . '/' . $file;
} elseif ( file_exists( get_stylesheet_directory() . '/sportspress/' . $file ) ) {
$theme_file = get_stylesheet_directory() . '/sportspress/' . $file;
} elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
$theme_file = get_template_directory() . '/' . $file;
} elseif ( file_exists( get_template_directory() . '/sportspress/' . $file ) ) {
$theme_file = get_template_directory() . '/sportspress/' . $file;
}
if ( $theme_file ) {
$core_version = $status->get_file_version( SP()->plugin_path() . '/templates/' . $file );
$theme_version = $status->get_file_version( $theme_file );
if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) {
$outdated = true;
break;
}
}
}
if ( $outdated ) {
include 'views/html-notice-template-check.php';
}
} }
} }
}
endif; endif;
return new SP_Admin_Notices(); return new SP_Admin_Notices();

View File

@@ -2,102 +2,111 @@
/** /**
* Adds settings to the permalinks admin settings page. * Adds settings to the permalinks admin settings page.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Permalink_Settings' ) ) : if ( ! class_exists( 'SP_Admin_Permalink_Settings' ) ) :
/**
* SP_Admin_Permalink_Settings Class
*/
class SP_Admin_Permalink_Settings {
/** /**
* Hook in tabs. * SP_Admin_Permalink_Settings Class
*/ */
public function __construct() { class SP_Admin_Permalink_Settings {
$this->slugs = apply_filters( 'sportspress_permalink_slugs', array(
array( 'event', __( 'Events', 'sportspress' ) ),
array( 'venue', __( 'Venues', 'sportspress' ) ),
array( 'calendar', __( 'Calendars', 'sportspress' ) ),
array( 'team', __( 'Teams', 'sportspress' ) ),
array( 'league', __( 'Leagues', 'sportspress' ) ),
array( 'season', __( 'Seasons', 'sportspress' ) ),
array( 'table', __( 'League Tables', 'sportspress' ) ),
array( 'player', __( 'Players', 'sportspress' ) ),
array( 'position', __( 'Positions', 'sportspress' ) ),
array( 'list', __( 'Player Lists', 'sportspress' ) ),
array( 'staff', __( 'Staff', 'sportspress' ) ),
) );
add_action( 'admin_init', array( $this, 'settings_init' ) ); /**
add_action( 'admin_init', array( $this, 'settings_save' ) ); * Hook in tabs.
} */
public function __construct() {
/** $this->slugs = apply_filters(
* Init our settings 'sportspress_permalink_slugs',
*/ array(
public function settings_init() { array( 'event', __( 'Events', 'sportspress' ) ),
// Add a section to the permalinks page array( 'venue', __( 'Venues', 'sportspress' ) ),
add_settings_section( 'sportspress-permalink', __( 'SportsPress', 'sportspress' ), array( $this, 'settings' ), 'permalink' ); array( 'calendar', __( 'Calendars', 'sportspress' ) ),
array( 'team', __( 'Teams', 'sportspress' ) ),
// Add our settings array( 'league', __( 'Leagues', 'sportspress' ) ),
foreach ( $this->slugs as $slug ): array( 'season', __( 'Seasons', 'sportspress' ) ),
add_settings_field( array( 'table', __( 'League Tables', 'sportspress' ) ),
$slug[0], // id array( 'player', __( 'Players', 'sportspress' ) ),
$slug[1], // setting title array( 'position', __( 'Positions', 'sportspress' ) ),
array( $this, 'slug_input' ), // display callback array( 'list', __( 'Player Lists', 'sportspress' ) ),
'permalink', // settings page array( 'staff', __( 'Staff', 'sportspress' ) ),
'sportspress-permalink' // settings section )
); );
endforeach;
}
/** add_action( 'admin_init', array( $this, 'settings_init' ) );
* Show a slug input box. add_action( 'admin_init', array( $this, 'settings_save' ) );
*/ }
public function slug_input() {
$slug = array_shift( $this->slugs );
$key = $slug[0];
$text = get_option( 'sportspress_' . $key . '_slug', null );
?><fieldset><input id="sportspress_<?php echo esc_attr( $key ); ?>_slug" name="sportspress_<?php echo esc_attr( $key ); ?>_slug" type="text" class="regular-text code" value="<?php echo esc_attr( $text ); ?>" placeholder="<?php echo esc_attr( $key ); ?>"></fieldset><?php
}
/** /**
* Show the settings * Init our settings
*/ */
public function settings() { public function settings_init() {
echo wpautop( __( 'These settings control the permalinks used for SportsPress. These settings only apply when <strong>not using "default" permalinks above</strong>.', 'sportspress' ) ); // Add a section to the permalinks page
} add_settings_section( 'sportspress-permalink', __( 'SportsPress', 'sportspress' ), array( $this, 'settings' ), 'permalink' );
/** // Add our settings
* Save the settings foreach ( $this->slugs as $slug ) :
*/ add_settings_field(
public function settings_save() { $slug[0], // id
if ( ! is_admin() ) $slug[1], // setting title
return; array( $this, 'slug_input' ), // display callback
'permalink', // settings page
if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['sportspress_event_slug'] ) ): 'sportspress-permalink' // settings section
foreach ( $this->slugs as $slug ): );
$key = 'sportspress_' . $slug[0] . '_slug';
$value = null;
if ( isset( $_POST[ $key ] ) )
$value = sanitize_text_field( $_POST[ $key ] );
if ( empty( $value ) )
delete_option( $key );
else
update_option( $key, $value );
endforeach; endforeach;
sp_flush_rewrite_rules(); }
endif;
/**
* Show a slug input box.
*/
public function slug_input() {
$slug = array_shift( $this->slugs );
$key = $slug[0];
$text = get_option( 'sportspress_' . $key . '_slug', null );
?><fieldset><input id="sportspress_<?php echo esc_attr( $key ); ?>_slug" name="sportspress_<?php echo esc_attr( $key ); ?>_slug" type="text" class="regular-text code" value="<?php echo esc_attr( $text ); ?>" placeholder="<?php echo esc_attr( $key ); ?>"></fieldset>
<?php
}
/**
* Show the settings
*/
public function settings() {
echo wpautop( __( 'These settings control the permalinks used for SportsPress. These settings only apply when <strong>not using "default" permalinks above</strong>.', 'sportspress' ) );
}
/**
* Save the settings
*/
public function settings_save() {
if ( ! is_admin() ) {
return;
}
if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['sportspress_event_slug'] ) ) :
foreach ( $this->slugs as $slug ) :
$key = 'sportspress_' . $slug[0] . '_slug';
$value = null;
if ( isset( $_POST[ $key ] ) ) {
$value = sanitize_text_field( $_POST[ $key ] );
}
if ( empty( $value ) ) {
delete_option( $key );
} else {
update_option( $key, $value );
}
endforeach;
sp_flush_rewrite_rules();
endif;
}
} }
}
endif; endif;
return new SP_Admin_Permalink_Settings(); return new SP_Admin_Permalink_Settings();

View File

@@ -2,122 +2,126 @@
/** /**
* Post Types Admin * Post Types Admin
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 2.0 * @version 2.0
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Post_Types' ) ) : if ( ! class_exists( 'SP_Admin_Post_Types' ) ) :
/**
* SP_Admin_Post_Types Class
*/
class SP_Admin_Post_Types {
/** /**
* Constructor * SP_Admin_Post_Types Class
*/ */
public function __construct() { class SP_Admin_Post_Types {
add_action( 'admin_init', array( $this, 'include_post_type_handlers' ) );
add_action( 'save_post', array( $this, 'unflag_post' ) );
add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
add_filter( 'sportspress_meta_boxes', array( $this, 'meta_boxes' ) );
}
/** /**
* Conditonally load classes and functions only needed when viewing a post type. * Constructor
*/ */
public function include_post_type_handlers() { public function __construct() {
include_once( 'post-types/class-sp-admin-meta-boxes.php' ); add_action( 'admin_init', array( $this, 'include_post_type_handlers' ) );
include_once( 'post-types/class-sp-admin-cpt-result.php' ); add_action( 'save_post', array( $this, 'unflag_post' ) );
include_once( 'post-types/class-sp-admin-cpt-outcome.php' ); add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
include_once( 'post-types/class-sp-admin-cpt-performance.php' ); add_filter( 'sportspress_meta_boxes', array( $this, 'meta_boxes' ) );
include_once( 'post-types/class-sp-admin-cpt-column.php' ); }
include_once( 'post-types/class-sp-admin-cpt-metric.php' );
include_once( 'post-types/class-sp-admin-cpt-statistic.php' );
include_once( 'post-types/class-sp-admin-cpt-event.php' );
include_once( 'post-types/class-sp-admin-cpt-team.php' );
include_once( 'post-types/class-sp-admin-cpt-player.php' );
include_once( 'post-types/class-sp-admin-cpt-staff.php' );
do_action( 'sportspress_include_post_type_handlers' );
}
/** /**
* Unflag preset and sample posts. * Conditonally load classes and functions only needed when viewing a post type.
*/ */
public function unflag_post( $post_id ) { public function include_post_type_handlers() {
$post_types = sp_post_types(); include_once 'post-types/class-sp-admin-meta-boxes.php';
$config_types = sp_config_types(); include_once 'post-types/class-sp-admin-cpt-result.php';
$post_type = get_post_type( $post_id ); include_once 'post-types/class-sp-admin-cpt-outcome.php';
if ( in_array( $post_type, $post_types ) ): include_once 'post-types/class-sp-admin-cpt-performance.php';
delete_post_meta( $post_id, '_sp_sample' ); include_once 'post-types/class-sp-admin-cpt-column.php';
elseif ( in_array( $post_type, $config_types ) ): include_once 'post-types/class-sp-admin-cpt-metric.php';
delete_post_meta( $post_id, '_sp_preset' ); include_once 'post-types/class-sp-admin-cpt-statistic.php';
endif; include_once 'post-types/class-sp-admin-cpt-event.php';
} include_once 'post-types/class-sp-admin-cpt-team.php';
include_once 'post-types/class-sp-admin-cpt-player.php';
include_once 'post-types/class-sp-admin-cpt-staff.php';
do_action( 'sportspress_include_post_type_handlers' );
}
/** /**
* Change messages when a post type is updated. * Unflag preset and sample posts.
* */
* @param array $messages public function unflag_post( $post_id ) {
* @return array $post_types = sp_post_types();
*/ $config_types = sp_config_types();
public function post_updated_messages( $messages ) { $post_type = get_post_type( $post_id );
global $typenow, $post; if ( in_array( $post_type, $post_types ) ) :
delete_post_meta( $post_id, '_sp_sample' );
elseif ( in_array( $post_type, $config_types ) ) :
delete_post_meta( $post_id, '_sp_preset' );
endif;
}
if ( is_sp_config_type( $typenow ) ): /**
$obj = get_post_type_object( $typenow ); * Change messages when a post type is updated.
*
* @param array $messages
* @return array
*/
public function post_updated_messages( $messages ) {
global $typenow, $post;
for ( $i = 0; $i <= 10; $i++ ): if ( is_sp_config_type( $typenow ) ) :
$messages['post'][ $i ] = __( 'Settings saved.', 'sportspress' ) . $obj = get_post_type_object( $typenow );
for ( $i = 0; $i <= 10; $i++ ) :
$messages['post'][ $i ] = __( 'Settings saved.', 'sportspress' ) .
' <a href="' . esc_url( admin_url( 'edit.php?post_type=' . $typenow ) ) . '">' . ' <a href="' . esc_url( admin_url( 'edit.php?post_type=' . $typenow ) ) . '">' .
__( 'View All', 'sportspress' ) . '</a>'; __( 'View All', 'sportspress' ) . '</a>';
endfor; endfor;
elseif ( is_sp_post_type( $typenow ) ): elseif ( is_sp_post_type( $typenow ) ) :
$obj = get_post_type_object( $typenow ); $obj = get_post_type_object( $typenow );
$messages['post'][1] = __( 'Changes saved.', 'sportspress' ) . $messages['post'][1] = __( 'Changes saved.', 'sportspress' ) .
' <a href="' . esc_url( get_permalink($post->ID) ) . '">' . $obj->labels->view_item . '</a>'; ' <a href="' . esc_url( get_permalink( $post->ID ) ) . '">' . $obj->labels->view_item . '</a>';
$messages['post'][4] = __( 'Changes saved.', 'sportspress' ); $messages['post'][4] = __( 'Changes saved.', 'sportspress' );
$messages['post'][6] = __( 'Success!', 'sportspress' ) . $messages['post'][6] = __( 'Success!', 'sportspress' ) .
' <a href="' . esc_url( get_permalink($post->ID) ) . '">' . $obj->labels->view_item . '</a>'; ' <a href="' . esc_url( get_permalink( $post->ID ) ) . '">' . $obj->labels->view_item . '</a>';
$messages['post'][7] = __( 'Changes saved.', 'sportspress' ); $messages['post'][7] = __( 'Changes saved.', 'sportspress' );
$messages['post'][8] = __( 'Success!', 'sportspress' ) . $messages['post'][8] = __( 'Success!', 'sportspress' ) .
' <a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink($post->ID) ) ) . '">' . ' <a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '">' .
sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . '</a>'; sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . '</a>';
$messages['post'][9] = sprintf( $messages['post'][9] = sprintf(
__( 'Scheduled for: <b>%1$s</b>.', 'sportspress' ), __( 'Scheduled for: <b>%1$s</b>.', 'sportspress' ),
date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post->ID) ) ) . date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) ),
' <a target="_blank" href="' . esc_url( get_permalink($post->ID) ) . '">' . esc_url( get_permalink( $post->ID ) )
sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . '</a>'; ) .
' <a target="_blank" href="' . esc_url( get_permalink( $post->ID ) ) . '">' .
sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . '</a>';
$messages['post'][10] = __( 'Success!', 'sportspress' ) . $messages['post'][10] = __( 'Success!', 'sportspress' ) .
' <a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink($post->ID) ) ) . '">' . ' <a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '">' .
sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . '</a>'; sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . '</a>';
endif; endif;
return $messages; return $messages;
} }
/** /**
* Remove meta boxes as needed * Remove meta boxes as needed
*/ */
public static function meta_boxes( $meta_boxes ) { public static function meta_boxes( $meta_boxes ) {
if ( 'manual' != get_option( 'sportspress_player_columns', 'auto' ) ) { if ( 'manual' != get_option( 'sportspress_player_columns', 'auto' ) ) {
unset( $meta_boxes['sp_player']['columns'] ); unset( $meta_boxes['sp_player']['columns'] );
}
return $meta_boxes;
} }
return $meta_boxes;
} }
}
endif; endif;
return new SP_Admin_Post_Types(); return new SP_Admin_Post_Types();

View File

@@ -4,11 +4,11 @@
* *
* The SportsPress admin sample data class stores demo content. * The SportsPress admin sample data class stores demo content.
* *
* @class SP_Admin_Sample_Data * @class SP_Admin_Sample_Data
* @version 2.5 * @version 2.5
* @package SportsPress/Admin * @package SportsPress/Admin
* @category Class * @category Class
* @author ThemeBoy * @author ThemeBoy
*/ */
class SP_Admin_Sample_Data { class SP_Admin_Sample_Data {
@@ -23,18 +23,18 @@ class SP_Admin_Sample_Data {
// Initialize inserted ids array // Initialize inserted ids array
$inserted_ids = array( $inserted_ids = array(
'sp_league' => array(), 'sp_league' => array(),
'sp_season' => array(), 'sp_season' => array(),
'sp_venue' => array(), 'sp_venue' => array(),
'sp_position' => array(), 'sp_position' => array(),
'sp_role' => array(), 'sp_role' => array(),
'sp_event' => array(), 'sp_event' => array(),
'sp_calendar' => array(), 'sp_calendar' => array(),
'sp_team' => array(), 'sp_team' => array(),
'sp_table' => array(), 'sp_table' => array(),
'sp_player' => array(), 'sp_player' => array(),
'sp_list' => array(), 'sp_list' => array(),
'sp_staff' => array(), 'sp_staff' => array(),
); );
// Terms to insert // Terms to insert
@@ -44,33 +44,33 @@ class SP_Admin_Sample_Data {
$taxonomies['sp_league'] = array( _x( 'Primary League', 'example', 'sportspress' ), _x( 'Secondary League', 'example', 'sportspress' ) ); $taxonomies['sp_league'] = array( _x( 'Primary League', 'example', 'sportspress' ), _x( 'Secondary League', 'example', 'sportspress' ) );
// Seasons // Seasons
$current_year = date( 'Y' ); $current_year = date( 'Y' );
$current_year = intval( $current_year ); $current_year = intval( $current_year );
$taxonomies['sp_season'] = array( $current_year - 1, $current_year, $current_year + 1 ); $taxonomies['sp_season'] = array( $current_year - 1, $current_year, $current_year + 1 );
// Venues // Venues
$taxonomies['sp_venue'] = array( $taxonomies['sp_venue'] = array(
array( array(
'name' => 'Bentleigh', 'name' => 'Bentleigh',
'meta' => array( 'meta' => array(
'sp_address' => '12A Bolinda Street, Bentleigh VIC 3204, Australia', 'sp_address' => '12A Bolinda Street, Bentleigh VIC 3204, Australia',
'sp_latitude' => -37.920537, 'sp_latitude' => -37.920537,
'sp_longitude' => 145.043199, 'sp_longitude' => 145.043199,
), ),
), ),
array( array(
'name' => 'Essendon', 'name' => 'Essendon',
'meta' => array( 'meta' => array(
'sp_address' => '74 Napier Street, Essendon VIC 3040, Australia', 'sp_address' => '74 Napier Street, Essendon VIC 3040, Australia',
'sp_latitude' => -37.751940, 'sp_latitude' => -37.751940,
'sp_longitude' => 144.919549, 'sp_longitude' => 144.919549,
), ),
), ),
array( array(
'name' => 'Kensington', 'name' => 'Kensington',
'meta' => array( 'meta' => array(
'sp_address' => '50 Altona Street, Kensington, Victoria, Australia', 'sp_address' => '50 Altona Street, Kensington, Victoria, Australia',
'sp_latitude' => -37.797789, 'sp_latitude' => -37.797789,
'sp_longitude' => 144.924709, 'sp_longitude' => 144.924709,
), ),
), ),
@@ -92,14 +92,21 @@ class SP_Admin_Sample_Data {
} }
// Insert term // Insert term
$inserted = wp_insert_term( $name, $taxonomy, array( 'description' => $name, 'slug' => sanitize_title( $name ) ) ); $inserted = wp_insert_term(
$name,
$taxonomy,
array(
'description' => $name,
'slug' => sanitize_title( $name ),
)
);
// Add meta to term if is array // Add meta to term if is array
if ( ! is_wp_error( $inserted ) && is_array( $term ) && array_key_exists( 'meta', $term ) ) { if ( ! is_wp_error( $inserted ) && is_array( $term ) && array_key_exists( 'meta', $term ) ) {
$t_id = sp_array_value( $inserted, 'term_id', 1 ); $t_id = sp_array_value( $inserted, 'term_id', 1 );
$meta = sp_array_value( $term, 'meta' ); $meta = sp_array_value( $term, 'meta' );
update_option( "taxonomy_$t_id", $meta ); update_option( "taxonomy_$t_id", $meta );
// Add to inserted ids array // Add to inserted ids array
$inserted_ids[ $taxonomy ][] = $t_id; $inserted_ids[ $taxonomy ][] = $t_id;
} }
@@ -113,15 +120,15 @@ class SP_Admin_Sample_Data {
$teams = array( $teams = array(
array( array(
'name' => 'Bluebirds', 'name' => 'Bluebirds',
'url' => 'http://tboy.co/bluebirds', 'url' => 'http://tboy.co/bluebirds',
), ),
array( array(
'name' => 'Eagles', 'name' => 'Eagles',
'url' => 'http://tboy.co/eagles', 'url' => 'http://tboy.co/eagles',
), ),
array( array(
'name' => 'Kangaroos', 'name' => 'Kangaroos',
'url' => 'http://tboy.co/kangaroos', 'url' => 'http://tboy.co/kangaroos',
), ),
); );
@@ -160,19 +167,35 @@ class SP_Admin_Sample_Data {
* Insert teams * Insert teams
*/ */
foreach ( $teams as $index => $team ) { foreach ( $teams as $index => $team ) {
$post['post_title'] = $team['name']; $post['post_title'] = $team['name'];
$post['post_type'] = 'sp_team'; $post['post_type'] = 'sp_team';
$post['post_status'] = 'publish'; $post['post_status'] = 'publish';
$post['post_content'] = sprintf( $sample_content, __( 'Team', 'sportspress' ), __( 'Teams', 'sportspress' ), add_query_arg( 'post_type', 'sp_team', admin_url( 'edit.php' ) ) ); $post['post_content'] = sprintf( $sample_content, __( 'Team', 'sportspress' ), __( 'Teams', 'sportspress' ), add_query_arg( 'post_type', 'sp_team', admin_url( 'edit.php' ) ) );
// Terms // Terms
$post['tax_input'] = array(); $post['tax_input'] = array();
$taxonomies = array( 'sp_league', 'sp_season' ); $taxonomies = array( 'sp_league', 'sp_season' );
foreach ( $taxonomies as $taxonomy ) { foreach ( $taxonomies as $taxonomy ) {
$post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) ); $post['tax_input'][ $taxonomy ] = get_terms(
}; $taxonomy,
array(
'hide_empty' => 0,
'fields' => 'ids',
)
);
}
$post['tax_input']['sp_venue'] = get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $index ) ); $post['tax_input']['sp_venue'] = get_terms(
'sp_venue',
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'id',
'order' => 'ASC',
'number' => 1,
'offset' => $index,
)
);
// Insert post // Insert post
$id = wp_insert_post( $post ); $id = wp_insert_post( $post );
@@ -189,13 +212,13 @@ class SP_Admin_Sample_Data {
// Get columns // Get columns
$columns = array( 'team' ); $columns = array( 'team' );
$args = array( $args = array(
'post_type' => array( 'sp_performance', 'sp_statistic' ), 'post_type' => array( 'sp_performance', 'sp_statistic' ),
'posts_per_page' => 2, 'posts_per_page' => 2,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
'order' => 'ASC', 'order' => 'ASC',
); );
$vars = get_posts( $args ); $vars = get_posts( $args );
foreach ( $vars as $var ) { foreach ( $vars as $var ) {
$columns[] = $var->post_name; $columns[] = $var->post_name;
} }
@@ -204,24 +227,39 @@ class SP_Admin_Sample_Data {
* Insert players * Insert players
*/ */
foreach ( $players as $index => $name ) { foreach ( $players as $index => $name ) {
$post['post_title'] = $name; $post['post_title'] = $name;
$post['post_type'] = 'sp_player'; $post['post_type'] = 'sp_player';
$post['post_status'] = 'publish'; $post['post_status'] = 'publish';
$post['post_content'] = sprintf( $sample_content, __( 'Player', 'sportspress' ), __( 'Players', 'sportspress' ), add_query_arg( 'post_type', 'sp_player', admin_url( 'edit.php' ) ) ); $post['post_content'] = sprintf( $sample_content, __( 'Player', 'sportspress' ), __( 'Players', 'sportspress' ), add_query_arg( 'post_type', 'sp_player', admin_url( 'edit.php' ) ) );
// Terms // Terms
$post['tax_input'] = array(); $post['tax_input'] = array();
$taxonomies = array( 'sp_league', 'sp_season' ); $taxonomies = array( 'sp_league', 'sp_season' );
foreach ( $taxonomies as $taxonomy ) { foreach ( $taxonomies as $taxonomy ) {
$post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) ); $post['tax_input'][ $taxonomy ] = get_terms(
}; $taxonomy,
array(
'hide_empty' => 0,
'fields' => 'ids',
)
);
}
$taxonomies = array( 'sp_position' ); $taxonomies = array( 'sp_position' );
foreach ( $taxonomies as $taxonomy ) { foreach ( $taxonomies as $taxonomy ) {
$terms = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'slug', 'number' => 1, 'offset' => $index % 4 ) ); $terms = get_terms(
$taxonomy,
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'slug',
'number' => 1,
'offset' => $index % 4,
)
);
if ( $terms && ! is_wp_error( $terms ) ) { if ( $terms && ! is_wp_error( $terms ) ) {
$post['tax_input'][ $taxonomy ] = $terms; $post['tax_input'][ $taxonomy ] = $terms;
} }
}; }
// Insert post // Insert post
$id = wp_insert_post( $post ); $id = wp_insert_post( $post );
@@ -233,13 +271,13 @@ class SP_Admin_Sample_Data {
update_post_meta( $id, '_sp_sample', 1 ); update_post_meta( $id, '_sp_sample', 1 );
// Calculate meta // Calculate meta
$nationality = array_rand( $countries->countries ); $nationality = array_rand( $countries->countries );
$team_index = floor( $index / 4 ); $team_index = floor( $index / 4 );
$past_team_index = ( $team_index + 1 ) % 3; $past_team_index = ( $team_index + 1 ) % 3;
$current_team = sp_array_value( $inserted_ids['sp_team'], $team_index, 0 ); $current_team = sp_array_value( $inserted_ids['sp_team'], $team_index, 0 );
$past_team = sp_array_value( $inserted_ids['sp_team'], $past_team_index, 0 ); $past_team = sp_array_value( $inserted_ids['sp_team'], $past_team_index, 0 );
$primary_league = reset( $post['tax_input']['sp_league'] ); $primary_league = reset( $post['tax_input']['sp_league'] );
$season_teams = $season_stats = array(); $season_teams = $season_stats = array();
foreach ( $post['tax_input']['sp_season'] as $season_index => $season_id ) { foreach ( $post['tax_input']['sp_season'] as $season_index => $season_id ) {
$season_stats[ $season_id ] = array(); $season_stats[ $season_id ] = array();
if ( $season_index == 0 ) { if ( $season_index == 0 ) {
@@ -253,7 +291,7 @@ class SP_Admin_Sample_Data {
} }
} }
} }
$player_stats = array( $primary_league => $season_stats ); $player_stats = array( $primary_league => $season_stats );
$player_leagues = array( $primary_league => $season_teams ); $player_leagues = array( $primary_league => $season_teams );
// Update meta // Update meta
@@ -268,30 +306,32 @@ class SP_Admin_Sample_Data {
} }
// Get columns // Get columns
$columns = array(); $columns = array();
$args = array( $args = array(
'post_type' => 'sp_performance', 'post_type' => 'sp_performance',
'posts_per_page' => -1, 'posts_per_page' => -1,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
'order' => 'ASC', 'order' => 'ASC',
); );
$performance_posts = get_posts( $args ); $performance_posts = get_posts( $args );
foreach ( $performance_posts as $performance_post ) { foreach ( $performance_posts as $performance_post ) {
if ( sizeof( $columns ) >= 5 ) continue; if ( sizeof( $columns ) >= 5 ) {
continue;
}
$columns[] = $performance_post->post_name; $columns[] = $performance_post->post_name;
} }
$args = array( $args = array(
'post_type' => 'sp_result', 'post_type' => 'sp_result',
'posts_per_page' => -1, 'posts_per_page' => -1,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
'order' => 'ASC', 'order' => 'ASC',
); );
$result_posts = get_posts( $args ); $result_posts = get_posts( $args );
$args = array( $args = array(
'post_type' => 'sp_outcome', 'post_type' => 'sp_outcome',
'posts_per_page' => -1, 'posts_per_page' => -1,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
'order' => 'ASC', 'order' => 'ASC',
); );
$outcome_posts = get_posts( $args ); $outcome_posts = get_posts( $args );
@@ -299,22 +339,37 @@ class SP_Admin_Sample_Data {
* Insert staff * Insert staff
*/ */
foreach ( $staff as $index => $name ) { foreach ( $staff as $index => $name ) {
$post['post_title'] = $name; $post['post_title'] = $name;
$post['post_type'] = 'sp_staff'; $post['post_type'] = 'sp_staff';
$post['post_status'] = 'publish'; $post['post_status'] = 'publish';
$post['post_content'] = sprintf( $sample_content, __( 'Staff', 'sportspress' ), __( 'Staff', 'sportspress' ), add_query_arg( 'post_type', 'sp_staff', admin_url( 'edit.php' ) ) ); $post['post_content'] = sprintf( $sample_content, __( 'Staff', 'sportspress' ), __( 'Staff', 'sportspress' ), add_query_arg( 'post_type', 'sp_staff', admin_url( 'edit.php' ) ) );
// Terms // Terms
$post['tax_input'] = array(); $post['tax_input'] = array();
$taxonomies = array( 'sp_league', 'sp_season' ); $taxonomies = array( 'sp_league', 'sp_season' );
foreach ( $taxonomies as $taxonomy ) { foreach ( $taxonomies as $taxonomy ) {
$post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) ); $post['tax_input'][ $taxonomy ] = get_terms(
}; $taxonomy,
array(
'hide_empty' => 0,
'fields' => 'ids',
)
);
}
$taxonomies = array( 'sp_role' ); $taxonomies = array( 'sp_role' );
foreach ( $taxonomies as $taxonomy ) { foreach ( $taxonomies as $taxonomy ) {
$terms = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'slug', 'number' => 1, 'offset' => $index % 4 ) ); $terms = get_terms(
$taxonomy,
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'slug',
'number' => 1,
'offset' => $index % 4,
)
);
$post['tax_input'][ $taxonomy ] = $terms; $post['tax_input'][ $taxonomy ] = $terms;
}; }
// Insert post // Insert post
$id = wp_insert_post( $post ); $id = wp_insert_post( $post );
@@ -326,8 +381,8 @@ class SP_Admin_Sample_Data {
update_post_meta( $id, '_sp_sample', 1 ); update_post_meta( $id, '_sp_sample', 1 );
// Calculate meta // Calculate meta
$team_index = floor( $index / 4 ); $team_index = floor( $index / 4 );
$past_teams = $inserted_ids['sp_team']; $past_teams = $inserted_ids['sp_team'];
$current_team = sp_array_value( $past_teams, $team_index, 0 ); $current_team = sp_array_value( $past_teams, $team_index, 0 );
unset( $past_teams[ $team_index ] ); unset( $past_teams[ $team_index ] );
@@ -347,27 +402,67 @@ class SP_Admin_Sample_Data {
// Determine team index and post status // Determine team index and post status
$i = $index % 3; $i = $index % 3;
if ( $index < 3 ) { if ( $index < 3 ) {
$post_status = 'publish'; $post_status = 'publish';
$post_year = $current_year - 1; $post_year = $current_year - 1;
$event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ); $event_season = get_terms(
'sp_season',
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'id',
'order' => 'ASC',
'number' => 1,
)
);
} else { } else {
$post_status = 'future'; $post_status = 'future';
$post_year = $current_year + 1; $post_year = $current_year + 1;
$event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'DESC', 'number' => 1 ) ); $event_season = get_terms(
'sp_season',
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'id',
'order' => 'DESC',
'number' => 1,
)
);
} }
// The away team should be the next inserted team, or the first if this is the last event // The away team should be the next inserted team, or the first if this is the last event
if ( $i == 2 ) $away_index = 0; if ( $i == 2 ) {
else $away_index = $i + 1; $away_index = 0;
} else {
$away_index = $i + 1;
}
$post = array( $post = array(
'post_title' => $teams[ $i ]['name'] . ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ' . $teams[ $away_index ]['name'], 'post_title' => $teams[ $i ]['name'] . ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ' . $teams[ $away_index ]['name'],
'post_type' => 'sp_event', 'post_type' => 'sp_event',
'post_status' => $post_status, 'post_status' => $post_status,
'post_content' => sprintf( $sample_content, __( 'Event', 'sportspress' ), __( 'Events', 'sportspress' ), add_query_arg( 'post_type', 'sp_event', admin_url( 'edit.php' ) ) ), 'post_content' => sprintf( $sample_content, __( 'Event', 'sportspress' ), __( 'Events', 'sportspress' ), add_query_arg( 'post_type', 'sp_event', admin_url( 'edit.php' ) ) ),
'post_date' => $post_year . '-' . sprintf( '%02d', 3 + $i * 3 ) . '-' . sprintf( '%02d', 5 + $i * 10 ) . ' ' . ( 18 + $i ) . ':00:00', 'post_date' => $post_year . '-' . sprintf( '%02d', 3 + $i * 3 ) . '-' . sprintf( '%02d', 5 + $i * 10 ) . ' ' . ( 18 + $i ) . ':00:00',
'tax_input' => array( 'tax_input' => array(
'sp_league' => get_terms( 'sp_league', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ), 'sp_league' => get_terms(
'sp_league',
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'id',
'order' => 'ASC',
'number' => 1,
)
),
'sp_season' => $event_season, 'sp_season' => $event_season,
'sp_venue' => get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $i ) ), 'sp_venue' => get_terms(
'sp_venue',
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'id',
'order' => 'ASC',
'number' => 1,
'offset' => $i,
)
),
), ),
); );
@@ -383,23 +478,23 @@ class SP_Admin_Sample_Data {
// Calculate home and away team ids // Calculate home and away team ids
$home_team_index = ( $i ) % 3; $home_team_index = ( $i ) % 3;
$away_team_index = ( $i + 1 ) % 3; $away_team_index = ( $i + 1 ) % 3;
$home_team_id = sp_array_value( $inserted_ids['sp_team'], $home_team_index, 0 ); $home_team_id = sp_array_value( $inserted_ids['sp_team'], $home_team_index, 0 );
$away_team_id = sp_array_value( $inserted_ids['sp_team'], $away_team_index, 0 ); $away_team_id = sp_array_value( $inserted_ids['sp_team'], $away_team_index, 0 );
$event_teams = array( $event_teams = array(
$home_team_id, $home_team_id,
$away_team_id, $away_team_id,
); );
// Initialize meta // Initialize meta
$event_players = array( 0 ); $event_players = array( 0 );
$performance = $results = array(); $performance = $results = array();
if ( $home_team_id ) { if ( $home_team_id ) {
// Add home team player performance // Add home team player performance
$performance[ $home_team_id ] = array(); $performance[ $home_team_id ] = array();
for ( $j = 0; $j < 4; $j ++ ) { for ( $j = 0; $j < 4; $j ++ ) {
$player_id = sp_array_value( $inserted_ids['sp_player'], $home_team_index * 4 + $j ); $player_id = sp_array_value( $inserted_ids['sp_player'], $home_team_index * 4 + $j );
$event_players[] = $player_id; $event_players[] = $player_id;
$player_performance = array(); $player_performance = array();
foreach ( $performance_posts as $performance_post ) { foreach ( $performance_posts as $performance_post ) {
$player_performance[ $performance_post->post_name ] = rand( 0, 1 ); $player_performance[ $performance_post->post_name ] = rand( 0, 1 );
@@ -413,7 +508,9 @@ class SP_Admin_Sample_Data {
$results[ $home_team_id ][ $result_post->post_name ] = 1 + $result_post_index; $results[ $home_team_id ][ $result_post->post_name ] = 1 + $result_post_index;
} }
$outcome = reset( $outcome_posts ); $outcome = reset( $outcome_posts );
if ( is_object( $outcome ) ) $results[ $home_team_id ]['outcome'] = array( $outcome->post_name ); if ( is_object( $outcome ) ) {
$results[ $home_team_id ]['outcome'] = array( $outcome->post_name );
}
} }
// Separate teams with zero // Separate teams with zero
@@ -422,8 +519,8 @@ class SP_Admin_Sample_Data {
if ( $away_team_id ) { if ( $away_team_id ) {
$performance[ $away_team_id ] = array(); $performance[ $away_team_id ] = array();
for ( $j = 0; $j < 4; $j ++ ) { for ( $j = 0; $j < 4; $j ++ ) {
$player_id = sp_array_value( $inserted_ids['sp_player'], $away_team_index * 4 + $j ); $player_id = sp_array_value( $inserted_ids['sp_player'], $away_team_index * 4 + $j );
$event_players[] = $player_id; $event_players[] = $player_id;
$player_performance = array(); $player_performance = array();
foreach ( $performance_posts as $performance_post ) { foreach ( $performance_posts as $performance_post ) {
$player_performance[ $performance_post->post_name ] = rand( 0, 1 ); $player_performance[ $performance_post->post_name ] = rand( 0, 1 );
@@ -437,15 +534,17 @@ class SP_Admin_Sample_Data {
$results[ $away_team_id ][ $result_post->post_name ] = '0'; $results[ $away_team_id ][ $result_post->post_name ] = '0';
} }
$outcome = next( $outcome_posts ); $outcome = next( $outcome_posts );
if ( is_object( $outcome ) ) $results[ $away_team_id ]['outcome'] = array( $outcome->post_name ); if ( is_object( $outcome ) ) {
$results[ $away_team_id ]['outcome'] = array( $outcome->post_name );
}
} }
if ( 'publish' === $post_status ) { if ( 'publish' === $post_status ) {
// Swap results for last event only // Swap results for last event only
if ( $i == 2 ) { if ( $i == 2 ) {
$k = array_keys( $results ); $k = array_keys( $results );
$v = array_values( $results ); $v = array_values( $results );
$rv = array_reverse( $v ); $rv = array_reverse( $v );
$results = array_combine( $k, $rv ); $results = array_combine( $k, $rv );
} }
@@ -466,10 +565,10 @@ class SP_Admin_Sample_Data {
* Insert calendar * Insert calendar
*/ */
$post = array( $post = array(
'post_title' => _x( 'Fixtures & Results', 'example', 'sportspress' ), 'post_title' => _x( 'Fixtures & Results', 'example', 'sportspress' ),
'post_type' => 'sp_calendar', 'post_type' => 'sp_calendar',
'post_status' => 'publish', 'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'Calendar', 'sportspress' ), __( 'Calendars', 'sportspress' ), add_query_arg( 'post_type', 'sp_calendar', admin_url( 'edit.php' ) ) ) 'post_content' => sprintf( $sample_content, __( 'Calendar', 'sportspress' ), __( 'Calendars', 'sportspress' ), add_query_arg( 'post_type', 'sp_calendar', admin_url( 'edit.php' ) ) ),
); );
// Insert post // Insert post
@@ -495,16 +594,32 @@ class SP_Admin_Sample_Data {
/* /*
* Insert league table * Insert league table
*/ */
$leagues = get_terms( 'sp_league', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ); $leagues = get_terms(
$league = reset( $leagues ); 'sp_league',
$seasons = get_terms( 'sp_season', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ); array(
$season = reset( $seasons ); 'hide_empty' => 0,
$post = array( 'orderby' => 'id',
'post_title' => $league->name . ' ' . $season->name, 'order' => 'ASC',
'post_type' => 'sp_table', 'number' => 1,
'post_status' => 'publish', )
);
$league = reset( $leagues );
$seasons = get_terms(
'sp_season',
array(
'hide_empty' => 0,
'orderby' => 'id',
'order' => 'ASC',
'number' => 1,
)
);
$season = reset( $seasons );
$post = array(
'post_title' => $league->name . ' ' . $season->name,
'post_type' => 'sp_table',
'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'League Table', 'sportspress' ), __( 'League Tables', 'sportspress' ), add_query_arg( 'post_type', 'sp_table', admin_url( 'edit.php' ) ) ), 'post_content' => sprintf( $sample_content, __( 'League Table', 'sportspress' ), __( 'League Tables', 'sportspress' ), add_query_arg( 'post_type', 'sp_table', admin_url( 'edit.php' ) ) ),
'tax_input' => array( 'tax_input' => array(
'sp_league' => $league->term_id, 'sp_league' => $league->term_id,
'sp_season' => $season->term_id, 'sp_season' => $season->term_id,
), ),
@@ -520,12 +635,12 @@ class SP_Admin_Sample_Data {
update_post_meta( $id, '_sp_sample', 1 ); update_post_meta( $id, '_sp_sample', 1 );
// Get columns // Get columns
$columns = array(); $columns = array();
$args = array( $args = array(
'post_type' => 'sp_column', 'post_type' => 'sp_column',
'posts_per_page' => 8, 'posts_per_page' => 8,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
'order' => 'ASC', 'order' => 'ASC',
); );
$column_posts = get_posts( $args ); $column_posts = get_posts( $args );
foreach ( $column_posts as $column_post ) { foreach ( $column_posts as $column_post ) {
@@ -542,9 +657,9 @@ class SP_Admin_Sample_Data {
*/ */
foreach ( $inserted_ids['sp_team'] as $index => $team_id ) { foreach ( $inserted_ids['sp_team'] as $index => $team_id ) {
$post = array( $post = array(
'post_title' => get_the_title( $team_id ) . ' ' . _x( 'Roster', 'example', 'sportspress' ), 'post_title' => get_the_title( $team_id ) . ' ' . _x( 'Roster', 'example', 'sportspress' ),
'post_type' => 'sp_list', 'post_type' => 'sp_list',
'post_status' => 'publish', 'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'Player List', 'sportspress' ), __( 'Player Lists', 'sportspress' ), add_query_arg( 'post_type', 'sp_list', admin_url( 'edit.php' ) ) ), 'post_content' => sprintf( $sample_content, __( 'Player List', 'sportspress' ), __( 'Player Lists', 'sportspress' ), add_query_arg( 'post_type', 'sp_list', admin_url( 'edit.php' ) ) ),
); );
@@ -561,12 +676,12 @@ class SP_Admin_Sample_Data {
$list_players = array_slice( $inserted_ids['sp_player'], $index * 4, 4 ); $list_players = array_slice( $inserted_ids['sp_player'], $index * 4, 4 );
// Get columns // Get columns
$columns = array(); $columns = array();
$args = array( $args = array(
'post_type' => array( 'sp_metric' ), 'post_type' => array( 'sp_metric' ),
'posts_per_page' => 2, 'posts_per_page' => 2,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
'order' => 'ASC', 'order' => 'ASC',
); );
$column_posts = get_posts( $args ); $column_posts = get_posts( $args );
foreach ( $column_posts as $column_post ) { foreach ( $column_posts as $column_post ) {
@@ -587,9 +702,9 @@ class SP_Admin_Sample_Data {
* Insert player list for player ranking * Insert player list for player ranking
*/ */
$post = array( $post = array(
'post_title' => _x( 'Player Ranking', 'example', 'sportspress' ), 'post_title' => _x( 'Player Ranking', 'example', 'sportspress' ),
'post_type' => 'sp_list', 'post_type' => 'sp_list',
'post_status' => 'publish', 'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'Player List', 'sportspress' ), __( 'Player Lists', 'sportspress' ), add_query_arg( 'post_type', 'sp_list', admin_url( 'edit.php' ) ) ), 'post_content' => sprintf( $sample_content, __( 'Player List', 'sportspress' ), __( 'Player Lists', 'sportspress' ), add_query_arg( 'post_type', 'sp_list', admin_url( 'edit.php' ) ) ),
); );
@@ -603,9 +718,11 @@ class SP_Admin_Sample_Data {
update_post_meta( $id, '_sp_sample', 1 ); update_post_meta( $id, '_sp_sample', 1 );
// Get columns // Get columns
$columns = array( 'team' ); $columns = array( 'team' );
$performance_post = reset( $performance_posts ); $performance_post = reset( $performance_posts );
if ( is_object( $performance_post ) ) $columns[] = $performance_post->post_name; if ( is_object( $performance_post ) ) {
$columns[] = $performance_post->post_name;
}
// Update meta // Update meta
update_post_meta( $id, 'sp_format', 'list' ); update_post_meta( $id, 'sp_format', 'list' );
@@ -613,7 +730,9 @@ class SP_Admin_Sample_Data {
update_post_meta( $id, 'sp_columns', $columns ); update_post_meta( $id, 'sp_columns', $columns );
update_post_meta( $id, 'sp_grouping', '0' ); update_post_meta( $id, 'sp_grouping', '0' );
update_post_meta( $id, 'sp_order', 'DESC' ); update_post_meta( $id, 'sp_order', 'DESC' );
if ( is_object( $performance_post ) ) update_post_meta( $id, 'sp_orderby', $performance_post->post_name ); if ( is_object( $performance_post ) ) {
update_post_meta( $id, 'sp_orderby', $performance_post->post_name );
}
/* /*
* Update player list and league table per team * Update player list and league table per team
@@ -631,21 +750,21 @@ class SP_Admin_Sample_Data {
*/ */
public static function delete_posts() { public static function delete_posts() {
$post_types = sp_post_types(); $post_types = sp_post_types();
$args = array( $args = array(
'post_type' => $post_types, 'post_type' => $post_types,
'posts_per_page' => -1, 'posts_per_page' => -1,
'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
'meta_query' => array( 'meta_query' => array(
array( array(
'key' => '_sp_sample', 'key' => '_sp_sample',
'value' => 1 'value' => 1,
) ),
), ),
); );
// Delete posts // Delete posts
$old_posts = get_posts( $args ); $old_posts = get_posts( $args );
foreach( $old_posts as $post ): foreach ( $old_posts as $post ) :
wp_delete_post( $post->ID, true ); wp_delete_post( $post->ID, true );
endforeach; endforeach;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -4,11 +4,11 @@
* *
* The SportsPress admin sports class stores preset sport data. * The SportsPress admin sports class stores preset sport data.
* *
* @class SP_Admin_Sports * @class SP_Admin_Sports
* @version 2.6 * @version 2.6
* @package SportsPress/Admin * @package SportsPress/Admin
* @category Class * @category Class
* @author ThemeBoy * @author ThemeBoy
*/ */
class SP_Admin_Sports { class SP_Admin_Sports {
@@ -20,18 +20,18 @@ class SP_Admin_Sports {
*/ */
public static function get_presets() { public static function get_presets() {
if ( empty( self::$presets ) ) { if ( empty( self::$presets ) ) {
$presets = array(); $presets = array();
self::$options = array( self::$options = array(
'team-sports' => array(), 'team-sports' => array(),
'racket-sports' => array(), 'racket-sports' => array(),
'water-sports' => array(), 'water-sports' => array(),
'target-sports' => array(), 'target-sports' => array(),
'esports' => array(), 'esports' => array(),
'other' => array(), 'other' => array(),
); );
foreach ( self::$options as $slug => $options ) { foreach ( self::$options as $slug => $options ) {
$dir = scandir( SP()->plugin_path() . '/presets/' . $slug ); $dir = scandir( SP()->plugin_path() . '/presets/' . $slug );
$files = array(); $files = array();
if ( $dir ) { if ( $dir ) {
foreach ( $dir as $key => $value ) { foreach ( $dir as $key => $value ) {
@@ -40,13 +40,15 @@ class SP_Admin_Sports {
} }
} }
} }
foreach( $files as $file ) { foreach ( $files as $file ) {
$json_data = file_get_contents( SP()->plugin_path() . '/presets/' . $slug . '/' . $file ); $json_data = file_get_contents( SP()->plugin_path() . '/presets/' . $slug . '/' . $file );
$data = json_decode( $json_data, true ); $data = json_decode( $json_data, true );
if ( ! is_array( $data ) ) continue; if ( ! is_array( $data ) ) {
$id = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file ); continue;
}
$id = preg_replace( '/\\.[^.\\s]{3,4}$/', '', $file );
$presets[ $id ] = $data; $presets[ $id ] = $data;
$name = array_key_exists( 'name', $data ) ? __( $data['name'], 'sportspress' ) : $id; $name = array_key_exists( 'name', $data ) ? __( $data['name'], 'sportspress' ) : $id;
// Conditionally append filename in parentheses for clarity // Conditionally append filename in parentheses for clarity
if ( false === strpos( str_replace( ' ', '', strtolower( $data['name'] ) ), str_replace( '-', '', $id ) ) ) { if ( false === strpos( str_replace( ' ', '', strtolower( $data['name'] ) ), str_replace( '-', '', $id ) ) ) {
@@ -69,15 +71,19 @@ class SP_Admin_Sports {
public static function get_preset( $id ) { public static function get_preset( $id ) {
$json_data = @file_get_contents( SP()->plugin_path() . '/presets/' . $id . '.json', true ); $json_data = @file_get_contents( SP()->plugin_path() . '/presets/' . $id . '.json', true );
if ( $json_data ) return json_decode( $json_data, true ); if ( $json_data ) {
return json_decode( $json_data, true );
}
$dir = scandir( SP()->plugin_path() . '/presets' ); $dir = scandir( SP()->plugin_path() . '/presets' );
if ( $dir ) { if ( $dir ) {
foreach ( $dir as $key => $value ) { foreach ( $dir as $key => $value ) {
if ( substr( $value, 0, 1 ) !== '.' && strpos( $value, '.' ) === false ) { if ( substr( $value, 0, 1 ) !== '.' && strpos( $value, '.' ) === false ) {
$json_data = @file_get_contents( SP()->plugin_path() . '/presets/' . $value . '/' . $id . '.json', true ); $json_data = @file_get_contents( SP()->plugin_path() . '/presets/' . $value . '/' . $id . '.json', true );
if ( $json_data ) return json_decode( $json_data, true ); if ( $json_data ) {
return json_decode( $json_data, true );
}
} }
} }
} }
@@ -99,19 +105,21 @@ class SP_Admin_Sports {
// Positions // Positions
$positions = sp_array_value( $preset, 'positions', array() ); $positions = sp_array_value( $preset, 'positions', array() );
$i = 0; $i = 0;
foreach ( $positions as $position ) { foreach ( $positions as $position ) {
if ( is_string( $position ) ) { if ( is_string( $position ) ) {
$name = $position; $name = $position;
$sections = array( 0, 1 ); $sections = array( 0, 1 );
} else { } else {
$name = sp_array_value( $position, 'name', __( 'Position', 'sportspress' ) ); $name = sp_array_value( $position, 'name', __( 'Position', 'sportspress' ) );
$sections = sp_array_value( $position, 'sections', array( 0, 1 ) ); $sections = sp_array_value( $position, 'sections', array( 0, 1 ) );
} }
$term = wp_insert_term( $name, 'sp_position' ); $term = wp_insert_term( $name, 'sp_position' );
if ( is_wp_error( $term ) ) continue; if ( is_wp_error( $term ) ) {
$t_id = $term['term_id']; continue;
$term_meta = get_option( "taxonomy_$t_id" ); }
$t_id = $term['term_id'];
$term_meta = get_option( "taxonomy_$t_id" );
$term_meta['sp_sections'] = $sections; $term_meta['sp_sections'] = $sections;
update_option( "taxonomy_$t_id", $term_meta ); update_option( "taxonomy_$t_id", $term_meta );
update_term_meta( $t_id, 'sp_order', $i + 1 ); update_term_meta( $t_id, 'sp_order', $i + 1 );
@@ -120,11 +128,13 @@ class SP_Admin_Sports {
// Outcomes // Outcomes
$post_type = 'sp_outcome'; $post_type = 'sp_outcome';
$outcomes = sp_array_value( $preset, 'outcomes', array() ); $outcomes = sp_array_value( $preset, 'outcomes', array() );
self::delete_preset_posts( $post_type ); self::delete_preset_posts( $post_type );
foreach ( $outcomes as $index => $outcome ) { foreach ( $outcomes as $index => $outcome ) {
$post = self::get_post_array( $outcome, $post_type ); $post = self::get_post_array( $outcome, $post_type );
if ( empty( $post ) ) continue; if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $index ); $id = self::insert_preset_post( $post, $index );
update_post_meta( $id, 'sp_abbreviation', sp_array_value( $outcome, 'abbreviation', null ) ); update_post_meta( $id, 'sp_abbreviation', sp_array_value( $outcome, 'abbreviation', null ) );
update_post_meta( $id, 'sp_condition', sp_array_value( $outcome, 'condition', null ) ); update_post_meta( $id, 'sp_condition', sp_array_value( $outcome, 'condition', null ) );
@@ -132,14 +142,18 @@ class SP_Admin_Sports {
// Results // Results
$post_type = 'sp_result'; $post_type = 'sp_result';
$results = sp_array_value( $preset, 'results', array() ); $results = sp_array_value( $preset, 'results', array() );
self::delete_preset_posts( $post_type ); self::delete_preset_posts( $post_type );
$primary_result = 0; $primary_result = 0;
foreach ( $results as $index => $result ) { foreach ( $results as $index => $result ) {
$post = self::get_post_array( $result, $post_type ); $post = self::get_post_array( $result, $post_type );
if ( empty( $post ) ) continue; if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $index ); $id = self::insert_preset_post( $post, $index );
if ( is_array( $result ) && array_key_exists( 'primary', $result ) ) $primary_result = $post['post_name']; if ( is_array( $result ) && array_key_exists( 'primary', $result ) ) {
$primary_result = $post['post_name'];
}
update_post_meta( $id, 'sp_equation', sp_array_value( $result, 'equation', null ) ); update_post_meta( $id, 'sp_equation', sp_array_value( $result, 'equation', null ) );
} }
@@ -147,12 +161,14 @@ class SP_Admin_Sports {
$i = 0; $i = 0;
// Performance // Performance
$post_type = 'sp_performance'; $post_type = 'sp_performance';
$performances = sp_array_value( $preset, 'performance', array() ); $performances = sp_array_value( $preset, 'performance', array() );
self::delete_preset_posts( $post_type ); self::delete_preset_posts( $post_type );
foreach ( $performances as $index => $performance ) { foreach ( $performances as $index => $performance ) {
$post = self::get_post_array( $performance, $post_type ); $post = self::get_post_array( $performance, $post_type );
if ( empty( $post ) ) continue; if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $index ); $id = self::insert_preset_post( $post, $index );
if ( isset( $performance['position'] ) ) { if ( isset( $performance['position'] ) ) {
wp_set_object_terms( $id, $performance['position'], 'sp_position', false ); wp_set_object_terms( $id, $performance['position'], 'sp_position', false );
@@ -170,11 +186,13 @@ class SP_Admin_Sports {
// Columns // Columns
$post_type = 'sp_column'; $post_type = 'sp_column';
$columns = sp_array_value( $preset, 'columns', array() ); $columns = sp_array_value( $preset, 'columns', array() );
self::delete_preset_posts( $post_type ); self::delete_preset_posts( $post_type );
foreach ( $columns as $index => $column ) { foreach ( $columns as $index => $column ) {
$post = self::get_post_array( $column, $post_type ); $post = self::get_post_array( $column, $post_type );
if ( empty( $post ) ) continue; if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $index ); $id = self::insert_preset_post( $post, $index );
update_post_meta( $id, 'sp_equation', sp_array_value( $column, 'equation', null ) ); update_post_meta( $id, 'sp_equation', sp_array_value( $column, 'equation', null ) );
update_post_meta( $id, 'sp_precision', sp_array_value( $column, 'precision', 0 ) ); update_post_meta( $id, 'sp_precision', sp_array_value( $column, 'precision', 0 ) );
@@ -184,40 +202,45 @@ class SP_Admin_Sports {
// Metrics // Metrics
$post_type = 'sp_metric'; $post_type = 'sp_metric';
$metrics = sp_array_value( $preset, 'metrics', array() ); $metrics = sp_array_value( $preset, 'metrics', array() );
self::delete_preset_posts( $post_type ); self::delete_preset_posts( $post_type );
foreach ( $metrics as $index => $metric ) { foreach ( $metrics as $index => $metric ) {
$post = self::get_post_array( $metric, $post_type ); $post = self::get_post_array( $metric, $post_type );
if ( empty( $post ) ) continue; if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $i + $index ); $id = self::insert_preset_post( $post, $i + $index );
$i ++; $i ++;
} }
// Event Specs // Event Specs
$post_type = 'sp_spec'; $post_type = 'sp_spec';
$specs = sp_array_value( $preset, 'specs', array() ); $specs = sp_array_value( $preset, 'specs', array() );
self::delete_preset_posts( $post_type ); self::delete_preset_posts( $post_type );
foreach ( $specs as $index => $spec ) { foreach ( $specs as $index => $spec ) {
$post = self::get_post_array( $spec, $post_type ); $post = self::get_post_array( $spec, $post_type );
if ( empty( $post ) ) continue; if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $i + $index ); $id = self::insert_preset_post( $post, $i + $index );
$i ++; $i ++;
} }
// Statistics // Statistics
$post_type = 'sp_statistic'; $post_type = 'sp_statistic';
$statistics = sp_array_value( $preset, 'statistics', array() ); $statistics = sp_array_value( $preset, 'statistics', array() );
self::delete_preset_posts( $post_type ); self::delete_preset_posts( $post_type );
foreach ( $statistics as $index => $statistic ) { foreach ( $statistics as $index => $statistic ) {
$post = self::get_post_array( $statistic, $post_type ); $post = self::get_post_array( $statistic, $post_type );
if ( empty( $post ) ) continue; if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $i + $index ); $id = self::insert_preset_post( $post, $i + $index );
update_post_meta( $id, 'sp_equation', sp_array_value( $statistic, 'equation', null ) ); update_post_meta( $id, 'sp_equation', sp_array_value( $statistic, 'equation', null ) );
update_post_meta( $id, 'sp_precision', sp_array_value( $statistic, 'precision', 0 ) ); update_post_meta( $id, 'sp_precision', sp_array_value( $statistic, 'precision', 0 ) );
update_post_meta( $id, 'sp_type', sp_array_value( $statistic, 'type', 'total' ) ); update_post_meta( $id, 'sp_type', sp_array_value( $statistic, 'type', 'total' ) );
} }
// Options // Options
$options = sp_array_value( $preset, 'options', array() ); $options = sp_array_value( $preset, 'options', array() );
foreach ( $options as $option => $value ) { foreach ( $options as $option => $value ) {
@@ -230,20 +253,20 @@ class SP_Admin_Sports {
public static function delete_preset_posts( $post_type = null ) { public static function delete_preset_posts( $post_type = null ) {
$args = array( $args = array(
'post_type' => $post_type, 'post_type' => $post_type,
'posts_per_page' => -1, 'posts_per_page' => -1,
'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), 'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
'meta_query' => array( 'meta_query' => array(
array( array(
'key' => '_sp_preset', 'key' => '_sp_preset',
'value' => 1 'value' => 1,
) ),
) ),
); );
// Delete posts // Delete posts
$old_posts = get_posts( $args ); $old_posts = get_posts( $args );
foreach( $old_posts as $post ): foreach ( $old_posts as $post ) :
wp_delete_post( $post->ID, true ); wp_delete_post( $post->ID, true );
endforeach; endforeach;
} }
@@ -252,15 +275,19 @@ class SP_Admin_Sports {
$post_array = array(); $post_array = array();
if ( is_string( $post ) ) { if ( is_string( $post ) ) {
$post_array['post_title'] = $post; $post_array['post_title'] = $post;
$post_array['post_name'] = sp_get_eos_safe_slug( $post_array['post_title'] ); $post_array['post_name'] = sp_get_eos_safe_slug( $post_array['post_title'] );
} elseif ( is_array( $post ) ) { } elseif ( is_array( $post ) ) {
if ( ! array_key_exists( 'name', $post ) ) $post_array = array(); if ( ! array_key_exists( 'name', $post ) ) {
$post_array = array();
}
$post_array['post_title'] = $post['name']; $post_array['post_title'] = $post['name'];
$post_array['post_name'] = sp_array_value( $post, 'id', sp_get_eos_safe_slug( $post_array['post_title'] ) ); $post_array['post_name'] = sp_array_value( $post, 'id', sp_get_eos_safe_slug( $post_array['post_title'] ) );
} }
// Return empty array if post with same slug already exists // Return empty array if post with same slug already exists
if ( get_page_by_path( $post_array['post_name'], OBJECT, $post_type ) ) return array(); if ( get_page_by_path( $post_array['post_name'], OBJECT, $post_type ) ) {
return array();
}
// Set post type // Set post type
$post_array['post_type'] = $post_type; $post_array['post_type'] = $post_type;
@@ -275,9 +302,9 @@ class SP_Admin_Sports {
public static function insert_preset_post( $post, $index = 0 ) { public static function insert_preset_post( $post, $index = 0 ) {
// Increment menu order by 10 and publish post // Increment menu order by 10 and publish post
$post['menu_order'] = $index * 10 + 10; $post['menu_order'] = $index * 10 + 10;
$post['post_status'] = 'publish'; $post['post_status'] = 'publish';
$id = wp_insert_post( $post ); $id = wp_insert_post( $post );
// Flag as preset // Flag as preset
update_post_meta( $id, '_sp_preset', 1 ); update_post_meta( $id, '_sp_preset', 1 );
@@ -287,21 +314,26 @@ class SP_Admin_Sports {
/** /**
* Sport category names * Sport category names
*
* @return null * @return null
*/ */
public static function sport_category_names() { public static function sport_category_names() {
return apply_filters( 'sportspress_sport_categories', array( return apply_filters(
'team-sports' => __( 'Team Sports', 'sportspress' ), 'sportspress_sport_categories',
'racket-sports' => __( 'Racket Sports', 'sportspress' ), array(
'water-sports' => __( 'Water Sports', 'sportspress' ), 'team-sports' => __( 'Team Sports', 'sportspress' ),
'target-sports' => __( 'Target Sports', 'sportspress' ), 'racket-sports' => __( 'Racket Sports', 'sportspress' ),
'esports' => __( 'Esports', 'sportspress' ), 'water-sports' => __( 'Water Sports', 'sportspress' ),
'other' => __( 'Other', 'sportspress' ), 'target-sports' => __( 'Target Sports', 'sportspress' ),
) ); 'esports' => __( 'Esports', 'sportspress' ),
'other' => __( 'Other', 'sportspress' ),
)
);
} }
/** /**
* Sport preset names for localization * Sport preset names for localization
*
* @return null * @return null
*/ */
public static function sport_preset_names() { public static function sport_preset_names() {

View File

@@ -2,75 +2,78 @@
/** /**
* Debug/Status page * Debug/Status page
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 1.4 * @version 1.4
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Status' ) ) : if ( ! class_exists( 'SP_Admin_Status' ) ) :
/**
* SP_Admin_Status Class
*/
class SP_Admin_Status {
/** /**
* Retrieve metadata from a file. Based on WP Core's get_file_data function * SP_Admin_Status Class
*
* @since 0.8
* @param string $file Path to the file
* @param array $all_headers List of headers, in the format array('HeaderKey' => 'Header Name')
*/ */
public function get_file_version( $file ) { class SP_Admin_Status {
// We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' );
// Pull only the first 8kiB of the file in. /**
$file_data = fread( $fp, 8192 ); * Retrieve metadata from a file. Based on WP Core's get_file_data function
*
* @since 0.8
* @param string $file Path to the file
* @param array $all_headers List of headers, in the format array('HeaderKey' => 'Header Name')
*/
public function get_file_version( $file ) {
// We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' );
// PHP will close file handle, but we are good citizens. // Pull only the first 8kiB of the file in.
fclose( $fp ); $file_data = fread( $fp, 8192 );
// Make sure we catch CR-only line endings. // PHP will close file handle, but we are good citizens.
$file_data = str_replace( "\r", "\n", $file_data ); fclose( $fp );
$version = '';
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) // Make sure we catch CR-only line endings.
$version = _cleanup_header_comment( $match[1] ); $file_data = str_replace( "\r", "\n", $file_data );
$version = '';
return $version ; if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) {
} $version = _cleanup_header_comment( $match[1] );
}
/**
* Scan the template files return $version;
* }
* @access public
* @param string $template_path /**
* @return array * Scan the template files
*/ *
public function scan_template_files( $template_path ) { * @access public
$files = scandir( $template_path ); * @param string $template_path
$result = array(); * @return array
if ( $files ) { */
foreach ( $files as $key => $value ) { public function scan_template_files( $template_path ) {
if ( ! in_array( $value, array( ".",".." ) ) ) { $files = scandir( $template_path );
if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) { $result = array();
$sub_files = $this->scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value ); if ( $files ) {
foreach ( $sub_files as $sub_file ) { foreach ( $files as $key => $value ) {
$result[] = $value . DIRECTORY_SEPARATOR . $sub_file; if ( ! in_array( $value, array( '.', '..' ) ) ) {
if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
$sub_files = $this->scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
foreach ( $sub_files as $sub_file ) {
$result[] = $value . DIRECTORY_SEPARATOR . $sub_file;
}
} else {
$result[] = $value;
} }
} else {
$result[] = $value;
} }
} }
} }
return $result;
} }
return $result;
} }
}
endif; endif;

View File

@@ -6,11 +6,11 @@ if ( ! defined( 'ABSPATH' ) ) {
/** /**
* Handles taxonomies in admin * Handles taxonomies in admin
* *
* @class SP_Admin_Taxonomies * @class SP_Admin_Taxonomies
* @version 2.7.9 * @version 2.7.9
* @package SportsPress/Admin * @package SportsPress/Admin
* @category Class * @category Class
* @author ThemeBoy * @author ThemeBoy
*/ */
class SP_Admin_Taxonomies { class SP_Admin_Taxonomies {
@@ -71,7 +71,7 @@ class SP_Admin_Taxonomies {
* @param mixed $term Term (category) being edited * @param mixed $term Term (category) being edited
*/ */
public function edit_taxonomy_fields( $term ) { public function edit_taxonomy_fields( $term ) {
$t_id = $term->term_id; $t_id = $term->term_id;
?> ?>
<?php if ( function_exists( 'get_term_meta' ) ) { ?> <?php if ( function_exists( 'get_term_meta' ) ) { ?>
<?php $order = get_term_meta( $t_id, 'sp_order', true ); ?> <?php $order = get_term_meta( $t_id, 'sp_order', true ); ?>
@@ -80,7 +80,7 @@ class SP_Admin_Taxonomies {
<td><input name="sp_order" class="sp-number-input" type="text" step="1" size="4" id="sp_order" value="<?php echo (int) $order; ?>"></td> <td><input name="sp_order" class="sp-number-input" type="text" step="1" size="4" id="sp_order" value="<?php echo (int) $order; ?>"></td>
</tr> </tr>
<?php } ?> <?php } ?>
<?php <?php
} }
/** /**
@@ -91,25 +91,25 @@ class SP_Admin_Taxonomies {
*/ */
public function add_venue_fields() { public function add_venue_fields() {
$args = array( $args = array(
'orderby' => 'id', 'orderby' => 'id',
'order' => 'DESC', 'order' => 'DESC',
'hide_empty' => false, 'hide_empty' => false,
'number' => 1, 'number' => 1,
); );
// Get latitude and longitude from the last added venue // Get latitude and longitude from the last added venue
$terms = get_terms( 'sp_venue', $args ); $terms = get_terms( 'sp_venue', $args );
if ( $terms && array_key_exists( 0, $terms) && is_object( reset( $terms ) ) ): if ( $terms && array_key_exists( 0, $terms ) && is_object( reset( $terms ) ) ) :
$term = reset( $terms ); $term = reset( $terms );
$t_id = $term->term_id; $t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" ); $term_meta = get_option( "taxonomy_$t_id" );
$latitude = sp_array_value( $term_meta, 'sp_latitude', '-37.8165647' ); $latitude = sp_array_value( $term_meta, 'sp_latitude', '-37.8165647' );
$longitude = sp_array_value( $term_meta, 'sp_longitude', '144.9475055' ); $longitude = sp_array_value( $term_meta, 'sp_longitude', '144.9475055' );
$address = sp_array_value( $term_meta, 'sp_address', '' ); $address = sp_array_value( $term_meta, 'sp_address', '' );
endif; endif;
// Sanitize latitude and longitude, fallback to default. // Sanitize latitude and longitude, fallback to default.
if( ! is_numeric( $latitude) || ! is_numeric( $longitude) ): if ( ! is_numeric( $latitude ) || ! is_numeric( $longitude ) ) :
$latitude = '-37.8165647'; $latitude = '-37.8165647';
$longitude = '144.9475055'; $longitude = '144.9475055';
endif; endif;
?> ?>
@@ -129,7 +129,7 @@ class SP_Admin_Taxonomies {
<label for="term_meta[sp_longitude]"><?php _e( 'Longitude', 'sportspress' ); ?></label> <label for="term_meta[sp_longitude]"><?php _e( 'Longitude', 'sportspress' ); ?></label>
<input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr( $longitude ); ?>"> <input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr( $longitude ); ?>">
</div> </div>
<?php <?php
do_action( 'sp_admin_geocoder_scripts' ); do_action( 'sp_admin_geocoder_scripts' );
} }
@@ -140,11 +140,11 @@ class SP_Admin_Taxonomies {
* @param mixed $term Term (category) being edited * @param mixed $term Term (category) being edited
*/ */
public function edit_venue_fields( $term ) { public function edit_venue_fields( $term ) {
$t_id = $term->term_id; $t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" ); $term_meta = get_option( "taxonomy_$t_id" );
$latitude = is_numeric( $term_meta['sp_latitude'] ) ? $term_meta['sp_latitude'] : ''; $latitude = is_numeric( $term_meta['sp_latitude'] ) ? $term_meta['sp_latitude'] : '';
$longitude = is_numeric( $term_meta['sp_longitude'] ) ? $term_meta['sp_longitude'] : ''; $longitude = is_numeric( $term_meta['sp_longitude'] ) ? $term_meta['sp_longitude'] : '';
$address = $term_meta['sp_address'] ? $term_meta['sp_address'] : ''; $address = $term_meta['sp_address'] ? $term_meta['sp_address'] : '';
?> ?>
<tr class="form-field"> <tr class="form-field">
<td colspan="2"> <td colspan="2">
@@ -170,7 +170,7 @@ class SP_Admin_Taxonomies {
<input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr( $longitude ); ?>"> <input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr( $longitude ); ?>">
</td> </td>
</tr> </tr>
<?php <?php
do_action( 'sp_admin_geocoder_scripts' ); do_action( 'sp_admin_geocoder_scripts' );
} }
@@ -184,16 +184,29 @@ class SP_Admin_Taxonomies {
?> ?>
<div class="form-field"> <div class="form-field">
<label><?php _e( 'Statistics', 'sportspress' ); ?></label> <label><?php _e( 'Statistics', 'sportspress' ); ?></label>
<select name="term_meta[sp_sections][]" id="term_meta[sp_sections][]" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple"> <select name="term_meta[sp_sections][]" id="term_meta[sp_sections][]" class="widefat chosen-select
<?php
if ( is_rtl() ) :
?>
chosen-rtl<?php endif; ?>" multiple="multiple">
<?php <?php
$options = apply_filters( 'sportspress_performance_sections', array( 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) ); $options = apply_filters(
foreach ( $options as $key => $value ): 'sportspress_performance_sections',
array(
0 => __( 'Offense', 'sportspress' ),
1 => __(
'Defense',
'sportspress'
),
)
);
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( true ), $value ); printf( '<option value="%s" %s>%s</option>', $key, selected( true ), $value );
endforeach; endforeach;
?> ?>
</select> </select>
</div> </div>
<?php <?php
} }
/** /**
@@ -203,17 +216,30 @@ class SP_Admin_Taxonomies {
* @param mixed $term Term (category) being edited * @param mixed $term Term (category) being edited
*/ */
public function edit_position_fields( $term ) { public function edit_position_fields( $term ) {
$t_id = $term->term_id; $t_id = $term->term_id;
$sections = sp_get_term_sections( $t_id ); $sections = sp_get_term_sections( $t_id );
?> ?>
<tr class="form-field"> <tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[sp_sections]"><?php _e( 'Statistics', 'sportspress' ); ?></label></th> <th scope="row" valign="top"><label for="term_meta[sp_sections]"><?php _e( 'Statistics', 'sportspress' ); ?></label></th>
<input type="hidden" name="term_meta[sp_sections]" value=""> <input type="hidden" name="term_meta[sp_sections]" value="">
<td> <td>
<select name="term_meta[sp_sections][]" id="term_meta[sp_sections][]" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple"> <select name="term_meta[sp_sections][]" id="term_meta[sp_sections][]" class="widefat chosen-select
<?php
if ( is_rtl() ) :
?>
chosen-rtl<?php endif; ?>" multiple="multiple">
<?php <?php
$options = apply_filters( 'sportspress_performance_sections', array( 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) ); $options = apply_filters(
foreach ( $options as $key => $value ): 'sportspress_performance_sections',
array(
0 => __( 'Offense', 'sportspress' ),
1 => __(
'Defense',
'sportspress'
),
)
);
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( in_array( $key, $sections ), true, false ), $value ); printf( '<option value="%s" %s>%s</option>', $key, selected( in_array( $key, $sections ), true, false ), $value );
endforeach; endforeach;
?> ?>
@@ -227,7 +253,7 @@ class SP_Admin_Taxonomies {
<td><input name="sp_order" class="sp-number-input" type="text" step="1" size="4" id="sp_order" value="<?php echo (int) $order; ?>"></td> <td><input name="sp_order" class="sp-number-input" type="text" step="1" size="4" id="sp_order" value="<?php echo (int) $order; ?>"></td>
</tr> </tr>
<?php } ?> <?php } ?>
<?php <?php
} }
/** /**
@@ -239,12 +265,12 @@ class SP_Admin_Taxonomies {
*/ */
public function save_fields( $term_id ) { public function save_fields( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) { if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id; $t_id = $term_id;
$term_meta = get_option( "taxonomy_$t_id" ); $term_meta = get_option( "taxonomy_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] ); $cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) { foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][ $key ] ) ) { if ( isset( $_POST['term_meta'][ $key ] ) ) {
$term_meta[$key] = sanitize_text_field( $_POST['term_meta'][ $key ] ); $term_meta[ $key ] = sanitize_text_field( $_POST['term_meta'][ $key ] );
} }
} }
update_option( "taxonomy_$t_id", $term_meta ); update_option( "taxonomy_$t_id", $term_meta );
@@ -263,13 +289,15 @@ class SP_Admin_Taxonomies {
*/ */
public function taxonomy_columns( $columns ) { public function taxonomy_columns( $columns ) {
$new_columns = array(); $new_columns = array();
if ( function_exists( 'get_term_meta' ) ) $new_columns['sp_order'] = __( 'Order', 'sportspress' );
if ( array_key_exists('posts', $columns) ) { if ( function_exists( 'get_term_meta' ) ) {
$new_columns['posts'] = $columns['posts']; $new_columns['sp_order'] = __( 'Order', 'sportspress' );
}
unset( $columns['posts'] ); if ( array_key_exists( 'posts', $columns ) ) {
$new_columns['posts'] = $columns['posts'];
unset( $columns['posts'] );
} }
return array_merge( $columns, $new_columns ); return array_merge( $columns, $new_columns );
@@ -283,12 +311,12 @@ class SP_Admin_Taxonomies {
* @return array * @return array
*/ */
public function venue_columns( $columns ) { public function venue_columns( $columns ) {
$new_columns = array(); $new_columns = array();
$new_columns['sp_address'] = __( 'Address', 'sportspress' ); $new_columns['sp_address'] = __( 'Address', 'sportspress' );
if ( array_key_exists('posts', $columns) ) { if ( array_key_exists( 'posts', $columns ) ) {
$new_columns['posts'] = $columns['posts']; $new_columns['posts'] = $columns['posts'];
unset( $columns['posts'] ); unset( $columns['posts'] );
} }
unset( $columns['description'] ); unset( $columns['description'] );
@@ -305,14 +333,16 @@ class SP_Admin_Taxonomies {
* @return array * @return array
*/ */
public function position_columns( $columns ) { public function position_columns( $columns ) {
$new_columns = array(); $new_columns = array();
$new_columns['sp_sections'] = __( 'Statistics', 'sportspress' ); $new_columns['sp_sections'] = __( 'Statistics', 'sportspress' );
if ( function_exists( 'get_term_meta' ) ) $new_columns['sp_order'] = __( 'Order', 'sportspress' ); if ( function_exists( 'get_term_meta' ) ) {
$new_columns['sp_order'] = __( 'Order', 'sportspress' );
if ( array_key_exists('posts', $columns) ) { }
$new_columns['posts'] = $columns['posts'];
unset( $columns['posts'] ); if ( array_key_exists( 'posts', $columns ) ) {
$new_columns['posts'] = $columns['posts'];
unset( $columns['posts'] );
} }
unset( $columns['description'] ); unset( $columns['description'] );
@@ -341,13 +371,22 @@ class SP_Admin_Taxonomies {
$columns .= $address; $columns .= $address;
} elseif ( $column == 'sp_sections' ) { } elseif ( $column == 'sp_sections' ) {
$options = apply_filters( 'sportspress_performance_sections', array( 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) ); $options = apply_filters(
'sportspress_performance_sections',
array(
0 => __( 'Offense', 'sportspress' ),
1 => __(
'Defense',
'sportspress'
),
)
);
$sections = sp_get_term_sections( $id ); $sections = sp_get_term_sections( $id );
$section_names = array(); $section_names = array();
if ( is_array( $sections ) ) { if ( is_array( $sections ) ) {
foreach ( $sections as $section ) { foreach ( $sections as $section ) {
if ( array_key_exists( $section, $options ) ) { if ( array_key_exists( $section, $options ) ) {
@@ -355,7 +394,7 @@ class SP_Admin_Taxonomies {
} }
} }
} }
$columns .= implode( ', ', $section_names ); $columns .= implode( ', ', $section_names );
} elseif ( $column == 'sp_order' ) { } elseif ( $column == 'sp_order' ) {

View File

@@ -10,404 +10,447 @@
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Admin_Welcome class. * SP_Admin_Welcome class.
*/ */
class SP_Admin_Welcome { class SP_Admin_Welcome {
private $plugin; private $plugin;
/** /**
* __construct function. * __construct function.
* *
* @access public * @access public
* @return void * @return void
*/ */
public function __construct() { public function __construct() {
$this->plugin = 'sportspress/sportspress.php'; $this->plugin = 'sportspress/sportspress.php';
add_action( 'admin_menu', array( $this, 'admin_menus') ); add_action( 'admin_menu', array( $this, 'admin_menus' ) );
add_action( 'admin_head', array( $this, 'admin_head' ) ); add_action( 'admin_head', array( $this, 'admin_head' ) );
add_action( 'admin_init', array( $this, 'welcome' ) ); add_action( 'admin_init', array( $this, 'welcome' ) );
} }
/** /**
* Add admin menus/screens * Add admin menus/screens
* *
* @access public * @access public
* @return void * @return void
*/ */
public function admin_menus() { public function admin_menus() {
if ( empty( $_GET['page'] ) ) { if ( empty( $_GET['page'] ) ) {
return; return;
} }
$welcome_page_name = __( 'About SportsPress', 'sportspress' ); $welcome_page_name = __( 'About SportsPress', 'sportspress' );
$welcome_page_title = __( 'Welcome to SportsPress', 'sportspress' ); $welcome_page_title = __( 'Welcome to SportsPress', 'sportspress' );
switch ( $_GET['page'] ) { switch ( $_GET['page'] ) {
case 'sp-about' : case 'sp-about':
$page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-about', array( $this, 'about_screen' ) ); $page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-about', array( $this, 'about_screen' ) );
add_action( 'admin_print_styles-'. $page, array( $this, 'admin_css' ) ); add_action( 'admin_print_styles-' . $page, array( $this, 'admin_css' ) );
break; break;
case 'sp-credits' : case 'sp-credits':
$page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-credits', array( $this, 'credits_screen' ) ); $page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-credits', array( $this, 'credits_screen' ) );
add_action( 'admin_print_styles-'. $page, array( $this, 'admin_css' ) ); add_action( 'admin_print_styles-' . $page, array( $this, 'admin_css' ) );
break; break;
case 'sp-translators' : case 'sp-translators':
$page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-translators', array( $this, 'translators_screen' ) ); $page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-translators', array( $this, 'translators_screen' ) );
add_action( 'admin_print_styles-'. $page, array( $this, 'admin_css' ) ); add_action( 'admin_print_styles-' . $page, array( $this, 'admin_css' ) );
break; break;
} }
} }
/** /**
* admin_css function. * admin_css function.
* *
* @access public * @access public
* @return void * @return void
*/ */
public function admin_css() { public function admin_css() {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ), array(), SP_VERSION ); wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ), array(), SP_VERSION );
} }
/** /**
* Add styles just for this page, and remove dashboard page links. * Add styles just for this page, and remove dashboard page links.
* *
* @access public * @access public
* @return void * @return void
*/ */
public function admin_head() { public function admin_head() {
remove_submenu_page( 'index.php', 'sp-about' ); remove_submenu_page( 'index.php', 'sp-about' );
remove_submenu_page( 'index.php', 'sp-credits' ); remove_submenu_page( 'index.php', 'sp-credits' );
remove_submenu_page( 'index.php', 'sp-translators' ); remove_submenu_page( 'index.php', 'sp-translators' );
} }
/** /**
* Into text/links shown on all about pages. * Into text/links shown on all about pages.
* *
* @access private * @access private
* @return void * @return void
*/ */
private function intro() { private function intro() {
// Flush after upgrades // Flush after upgrades
if ( ! empty( $_GET['sp-updated'] ) || ! empty( $_GET['sp-installed'] ) ) if ( ! empty( $_GET['sp-updated'] ) || ! empty( $_GET['sp-installed'] ) ) {
flush_rewrite_rules(); flush_rewrite_rules();
}
// Get major version number // Get major version number
$version = explode( '.', SP()->version, 3 ); $version = explode( '.', SP()->version, 3 );
unset( $version[2] ); unset( $version[2] );
$display_version = implode( '.', $version ); $display_version = implode( '.', $version );
?> ?>
<h1 class="sp-welcome-logo"><?php echo apply_filters( 'sportspress_logo', '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/welcome/sportspress' . ( class_exists( 'SportsPress_Pro' ) ? '-pro' : '' ) . '.png" alt="' . __( 'SportsPress', 'sportspress' ) . '">' ); ?></h1> <h1 class="sp-welcome-logo"><?php echo apply_filters( 'sportspress_logo', '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/welcome/sportspress' . ( class_exists( 'SportsPress_Pro' ) ? '-pro' : '' ) . '.png" alt="' . __( 'SportsPress', 'sportspress' ) . '">' ); ?></h1>
<div class="sp-badge"><?php printf( __( 'Version %s', 'sportspress' ), SP()->version ); ?></div> <div class="sp-badge"><?php printf( __( 'Version %s', 'sportspress' ), SP()->version ); ?></div>
<div class="about-text sp-about-text"> <div class="about-text sp-about-text">
<?php <?php
if ( ! empty( $_GET['sp-installed'] ) ) if ( ! empty( $_GET['sp-installed'] ) ) {
$message = __( 'Thanks, all done!', 'sportspress' ); $message = __( 'Thanks, all done!', 'sportspress' );
elseif ( ! empty( $_GET['sp-updated'] ) ) } elseif ( ! empty( $_GET['sp-updated'] ) ) {
$message = __( 'Thank you for updating to the latest version!', 'sportspress' ); $message = __( 'Thank you for updating to the latest version!', 'sportspress' );
else } else {
$message = __( 'Thanks for installing!', 'sportspress' ); $message = __( 'Thanks for installing!', 'sportspress' );
}
printf( __( '%s SportsPress %s has lots of refinements we think you&#8217;ll love.', 'sportspress' ), $message, $display_version ); printf( __( '%1$s SportsPress %2$s has lots of refinements we think you&#8217;ll love.', 'sportspress' ), $message, $display_version );
?> ?>
</div> </div>
<p class="sportspress-actions"> <a href="
<a href="<?php echo admin_url( add_query_arg( array( 'page' => 'sportspress', 'tab' => 'general' ), 'admin.php' ) ); ?>" class="button button-primary"><?php _e( 'Settings', 'sportspress' ); ?></a> <?php
<a href="<?php echo esc_url( apply_filters( 'sportspress_docs_url', 'http://tboy.co/docs', 'sportspress' ) ); ?>" class="docs button button-primary"><?php _e( 'Docs', 'sportspress' ); ?></a> echo admin_url(
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://wordpress.org/plugins/sportspress" data-text="An open-source (free) #WordPress plugin that helps you build professional league websites" data-via="ThemeBoy" data-size="large" data-hashtags="SportsPress">Tweet</a> add_query_arg(
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> array(
</p> 'page' => 'sportspress',
'tab' => 'general',
),
'admin.php'
)
);
?>
" class="button button-primary"><?php _e( 'Settings', 'sportspress' ); ?></a>
<a href="<?php echo esc_url( apply_filters( 'sportspress_docs_url', 'http://tboy.co/docs', 'sportspress' ) ); ?>" class="docs button button-primary"><?php _e( 'Docs', 'sportspress' ); ?></a>
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://wordpress.org/plugins/sportspress" data-text="An open-source (free) #WordPress plugin that helps you build professional league websites" data-via="ThemeBoy" data-size="large" data-hashtags="SportsPress">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</p>
<h2 class="nav-tab-wrapper"> <h2 class="nav-tab-wrapper">
<a class="nav-tab <?php if ( $_GET['page'] == 'sp-about' ) echo 'nav-tab-active'; ?>" href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sp-about' ), 'index.php' ) ) ); ?>"> <a class="nav-tab
<?php _e( 'Welcome', 'sportspress' ); ?> <?php
</a><a class="nav-tab <?php if ( $_GET['page'] == 'sp-credits' ) echo 'nav-tab-active'; ?>" href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sp-credits' ), 'index.php' ) ) ); ?>"> if ( $_GET['page'] == 'sp-about' ) {
<?php _e( 'Credits', 'sportspress' ); ?> echo 'nav-tab-active';}
</a> ?>
</h2> " href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sp-about' ), 'index.php' ) ) ); ?>">
<?php <?php _e( 'Welcome', 'sportspress' ); ?>
} </a><a class="nav-tab
<?php
if ( $_GET['page'] == 'sp-credits' ) {
echo 'nav-tab-active';}
?>
" href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sp-credits' ), 'index.php' ) ) ); ?>">
<?php _e( 'Credits', 'sportspress' ); ?>
</a>
</h2>
<?php
}
/** /**
* Output the about screen. * Output the about screen.
*/ */
public function about_screen() { public function about_screen() {
include_once( 'class-sp-admin-settings.php' ); include_once 'class-sp-admin-settings.php';
$class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' ); $class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' );
?> ?>
<div class="wrap about-wrap about-sportspress-wrap"> <div class="wrap about-wrap about-sportspress-wrap">
<?php $this->intro(); ?> <?php $this->intro(); ?>
<?php <?php
// Save settings // Save settings
if ( isset( $_POST['timezone_string'] ) ): if ( isset( $_POST['timezone_string'] ) ) :
update_option( 'timezone_string', sanitize_text_field( $_POST['timezone_string'] ) ); update_option( 'timezone_string', sanitize_text_field( $_POST['timezone_string'] ) );
update_option( 'sportspress_basic_setup', 1 ); update_option( 'sportspress_basic_setup', 1 );
endif; endif;
if ( isset( $_POST['sportspress_sport'] ) && ! empty( $_POST['sportspress_sport'] ) ): if ( isset( $_POST['sportspress_sport'] ) && ! empty( $_POST['sportspress_sport'] ) ) :
$sport = sanitize_text_field( $_POST['sportspress_sport'] ); $sport = sanitize_text_field( $_POST['sportspress_sport'] );
SP_Admin_Sports::apply_preset( $sport ); SP_Admin_Sports::apply_preset( $sport );
update_option( 'sportspress_sport', $sport ); update_option( 'sportspress_sport', $sport );
delete_option( '_sp_needs_welcome' ); delete_option( '_sp_needs_welcome' );
update_option( 'sportspress_installed', 1 ); update_option( 'sportspress_installed', 1 );
?> ?>
<div id="message" class="updated sportspress-message"> <div id="message" class="updated sportspress-message">
<p><strong><?php _e( 'Your settings have been saved.', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Your settings have been saved.', 'sportspress' ); ?></strong></p>
</div> </div>
<?php <?php
endif; endif;
if ( isset( $_POST['add_sample_data'] ) ): if ( isset( $_POST['add_sample_data'] ) ) :
SP_Admin_Sample_Data::delete_posts(); SP_Admin_Sample_Data::delete_posts();
SP_Admin_Sample_Data::insert_posts(); SP_Admin_Sample_Data::insert_posts();
endif; endif;
do_action( 'sportspress_before_welcome_features' ); do_action( 'sportspress_before_welcome_features' );
?> ?>
<div class="feature-section one-col"> <div class="feature-section one-col">
<div class="col"> <div class="col">
<h2>New Features 🌟</h2> <h2>New Features 🌟</h2>
</div> </div>
</div> </div>
<div class="feature-section three-col"> <div class="feature-section three-col">
<div class="col"> <div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-conditional-equations.png" alt="Screenshot"> <img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-conditional-equations.png" alt="Screenshot">
<h3>Conditional Equations</h3> <h3>Conditional Equations</h3>
<p>Use the newly introduced conditional operators <strong>&gt;</strong>, <strong>&lt;</strong>, <strong>&equiv;</strong>, <strong>&ne;</strong>, <strong>&ge;</strong>, and <strong>&le;</strong> to calculate the relationship between variables, then insert that calculation into more complex equations. Visit the <a href="<?php echo add_query_arg( array( 'page' => 'sportspress-config' ), admin_url( 'admin.php' ) ); ?>">Configure</a> page to edit variables and equations.</p> <p>Use the newly introduced conditional operators <strong>&gt;</strong>, <strong>&lt;</strong>, <strong>&equiv;</strong>, <strong>&ne;</strong>, <strong>&ge;</strong>, and <strong>&le;</strong> to calculate the relationship between variables, then insert that calculation into more complex equations. Visit the <a href="<?php echo add_query_arg( array( 'page' => 'sportspress-config' ), admin_url( 'admin.php' ) ); ?>">Configure</a> page to edit variables and equations.</p>
</div> </div>
<div class="col"> <div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-event-specs.png" alt="Screenshot"> <img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-event-specs.png" alt="Screenshot">
<h3>Event Specs</h3> <h3>Event Specs</h3>
<p>Measure and display additional details per event using the new <strong>Event Specs</strong> variables. They are customizable and can be useful for keeping track of information like player of the match, attendance, and venue weather. <p>Measure and display additional details per event using the new <strong>Event Specs</strong> variables. They are customizable and can be useful for keeping track of information like player of the match, attendance, and venue weather.
</div> </div>
<div class="col"> <div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-next-team.png" alt="Screenshot"> <img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-next-team.png" alt="Screenshot">
<h3>Next Team Column</h3> <h3>Next Team Column</h3>
<p>Provide a quick overview of who each team is playing next using the new <strong>Next Team</strong> preset for <a href="<?php echo add_query_arg( array( 'post_type' => 'sp_column' ), admin_url( 'edit.php' ) ); ?>">league table columns</a>. This will automatically display the next team's name or logo that links to the next match for each team in the table.<p> <p>Provide a quick overview of who each team is playing next using the new <strong>Next Team</strong> preset for <a href="<?php echo add_query_arg( array( 'post_type' => 'sp_column' ), admin_url( 'edit.php' ) ); ?>">league table columns</a>. This will automatically display the next team's name or logo that links to the next match for each team in the table.<p>
</div> </div>
</div> </div>
<?php if ( ! class_exists( 'SportsPress_Pro' ) ) { ?> <?php if ( ! class_exists( 'SportsPress_Pro' ) ) { ?>
<hr> <hr>
<div class="feature-section one-col"> <div class="feature-section one-col">
<div class="col"> <div class="col">
<h2>SportsPress Pro Updates 🏆</h2> <h2>SportsPress Pro Updates 🏆</h2>
</div> </div>
</div> </div>
<div class="feature-section three-col"> <div class="feature-section three-col">
<div class="col"> <div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-results-matrix.png" alt="Results Matrix"> <img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-results-matrix.png" alt="Results Matrix">
<h3>Results Matrix</h3> <h3>Results Matrix</h3>
<p>Display matches between home and away team in a grid. Create or select an existing calendar and select the <strong>Matrix</strong> layout to convert the calendar to an interactive results matrix!</p> <p>Display matches between home and away team in a grid. Create or select an existing calendar and select the <strong>Matrix</strong> layout to convert the calendar to an interactive results matrix!</p>
</div> </div>
<div class="col"> <div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-midseason-transfers.png" alt="Midseason Transfers"> <img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-midseason-transfers.png" alt="Midseason Transfers">
<h3>Midseason Transfers</h3> <h3>Midseason Transfers</h3>
<p>Keep track of players that switched teams during a season by adding one or more extra rows to their statistics table. Display the team and partial statistics before and after the transfer.<p> <p>Keep track of players that switched teams during a season by adding one or more extra rows to their statistics table. Display the team and partial statistics before and after the transfer.<p>
</div> </div>
<div class="col"> <div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-vertical-timelines.png" alt="Vertical Timelines"> <img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-vertical-timelines.png" alt="Vertical Timelines">
<h3>Vertical Timelines</h3> <h3>Vertical Timelines</h3>
<p>Display a match commentary style play-by-play timeline within events. <a href="<?php echo esc_url( apply_filters( 'sportspress_pro_url', 'http://tboy.co/pro' ) ); ?>">Upgrade to SportsPress Pro</a> to get access to <strong>Timelines</strong> and other pro features.<p> <p>Display a match commentary style play-by-play timeline within events. <a href="<?php echo esc_url( apply_filters( 'sportspress_pro_url', 'http://tboy.co/pro' ) ); ?>">Upgrade to SportsPress Pro</a> to get access to <strong>Timelines</strong> and other pro features.<p>
</div> </div>
</div> </div>
<a class="button button-primary button-hero" href="<?php echo esc_url( apply_filters( 'sportspress_pro_url', 'http://tboy.co/pro' ) ); ?>"><?php _e( 'Upgrade to Pro', 'sportspress' ); ?></a> <a class="button button-primary button-hero" href="<?php echo esc_url( apply_filters( 'sportspress_pro_url', 'http://tboy.co/pro' ) ); ?>"><?php _e( 'Upgrade to Pro', 'sportspress' ); ?></a>
<p><?php _e( 'Get SportsPress Pro to get access to all modules. You can upgrade any time without losing any of your data.','sportspress' ); ?></p> <p><?php _e( 'Get SportsPress Pro to get access to all modules. You can upgrade any time without losing any of your data.', 'sportspress' ); ?></p>
<?php } ?> <?php } ?>
<hr> <hr>
<div class="feature-section one-col"> <div class="feature-section one-col">
<div class="col"> <div class="col">
<h2>Player Data Improvements</h2> <h2>Player Data Improvements</h2>
</div> </div>
</div> </div>
<div class="feature-section three-col"> <div class="feature-section three-col">
<div class="col"> <div class="col">
<h3>Player Assignments</h3> <h3>Player Assignments</h3>
<p>Players will now be saved using a new data format that allows them to belong to multiple leagues, seasons, and teams and be accurately selected in <a href="<?php echo add_query_arg( array( 'post_type' => 'sp_list' ), admin_url( 'edit.php' ) ); ?>">player lists</a>.</p> <p>Players will now be saved using a new data format that allows them to belong to multiple leagues, seasons, and teams and be accurately selected in <a href="<?php echo add_query_arg( array( 'post_type' => 'sp_list' ), admin_url( 'edit.php' ) ); ?>">player lists</a>.</p>
</div> </div>
<div class="col"> <div class="col">
<h3>Current Team Column</h3> <h3>Current Team Column</h3>
<p>The <strong>Team</strong> column in player lists will now display only the current team that player belongs to, determined by the <strong>Current Team</strong> setting of each player.</p> <p>The <strong>Team</strong> column in player lists will now display only the current team that player belongs to, determined by the <strong>Current Team</strong> setting of each player.</p>
</div> </div>
<div class="col"> <div class="col">
<h3>Squad Number Zero</h3> <h3>Squad Number Zero</h3>
<p>It's now possible to import players with the squad number <strong>0 (zero)</strong> or any other value that would previously be interpreted as empty.</p> <p>It's now possible to import players with the squad number <strong>0 (zero)</strong> or any other value that would previously be interpreted as empty.</p>
</div> </div>
</div> </div>
<hr> <hr>
<div class="feature-section one-col"> <div class="feature-section one-col">
<div class="col"> <div class="col">
<h2>Other Notes</h2> <h2>Other Notes</h2>
</div> </div>
</div> </div>
<div class="feature-section three-col"> <div class="feature-section three-col">
<div class="col"> <div class="col">
<h3>Countdown Images</h3> <h3>Countdown Images</h3>
<p>A new option has been added to the <strong>Countdown</strong> widget, allowing you to display a featured image from the next event.</p> <p>A new option has been added to the <strong>Countdown</strong> widget, allowing you to display a featured image from the next event.</p>
</div> </div>
<div class="col"> <div class="col">
<h3>Relative Date in Shortcodes</h3> <h3>Relative Date in Shortcodes</h3>
<p>You'll now be able to select a relative date range when inserting calendar-related shortcodes from the visual editor.</p> <p>You'll now be able to select a relative date range when inserting calendar-related shortcodes from the visual editor.</p>
</div> </div>
<div class="col"> <div class="col">
<h3>Short Names</h3> <h3>Short Names</h3>
<p>Teams have been given a <strong>Short Name</strong> setting in addition to the existing <strong>Abbreviation</strong> for added customizability.</p> <p>Teams have been given a <strong>Short Name</strong> setting in addition to the existing <strong>Abbreviation</strong> for added customizability.</p>
</div> </div>
</div> </div>
<?php do_action( 'sportspress_after_welcome_features' ); ?> <?php do_action( 'sportspress_after_welcome_features' ); ?>
<a href="
<?php
echo esc_url(
admin_url(
add_query_arg(
array(
'page' => 'sportspress',
'tab' => 'general',
),
'admin.php'
)
)
);
?>
"><?php _e( 'Go to SportsPress Settings', 'sportspress' ); ?></a>
</div>
<?php
}
<a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sportspress', 'tab' => 'general' ), 'admin.php' ) ) ); ?>"><?php _e( 'Go to SportsPress Settings', 'sportspress' ); ?></a> /**
</div> * Output the credits.
<?php */
} public function credits_screen() {
?>
<div class="wrap about-wrap about-sportspress-wrap">
<?php $this->intro(); ?>
<p class="about-description"><?php printf( __( 'SportsPress is developed and maintained by a worldwide team of passionate individuals and backed by an awesome developer community. Want to see your name? <a href="%s">Contribute to SportsPress</a>.', 'sportspress' ), 'https://github.com/ThemeBoy/SportsPress/blob/master/CONTRIBUTING.md' ); ?></p>
/** <div class="sp-feature feature-section col one-col">
* Output the credits. <?php echo wp_kses_post( $this->contributors() ); ?>
*/ </div>
public function credits_screen() { </div>
?> <?php
<div class="wrap about-wrap about-sportspress-wrap"> }
<?php $this->intro(); ?>
<p class="about-description"><?php printf( __( 'SportsPress is developed and maintained by a worldwide team of passionate individuals and backed by an awesome developer community. Want to see your name? <a href="%s">Contribute to SportsPress</a>.', 'sportspress' ), 'https://github.com/ThemeBoy/SportsPress/blob/master/CONTRIBUTING.md' ); ?></p>
<div class="sp-feature feature-section col one-col"> /**
<?php echo wp_kses_post( $this->contributors() ); ?> * Output the translators screen
</div> */
</div> public function translators_screen() {
<?php ?>
} <div class="wrap about-wrap about-sportspress-wrap">
/** <?php $this->intro(); ?>
* Output the translators screen
*/
public function translators_screen() {
?>
<div class="wrap about-wrap about-sportspress-wrap">
<?php $this->intro(); ?> <p class="about-description"><?php printf( __( 'SportsPress has been kindly translated into several other languages thanks to our translation team. Want to see your name? <a href="%s">Translate SportsPress</a>.', 'sportspress' ), 'https://translate.wordpress.org/projects/wp-plugins/sportspress' ); ?></p>
</div>
<?php
}
<p class="about-description"><?php printf( __( 'SportsPress has been kindly translated into several other languages thanks to our translation team. Want to see your name? <a href="%s">Translate SportsPress</a>.', 'sportspress' ), 'https://translate.wordpress.org/projects/wp-plugins/sportspress' ); ?></p> /**
</div> * Render Contributors List
<?php *
} * @access public
* @return string $contributor_list HTML formatted list of contributors.
*/
public function contributors() {
$contributors = $this->get_contributors();
/** if ( empty( $contributors ) ) {
* Render Contributors List return '';
* }
* @access public
* @return string $contributor_list HTML formatted list of contributors.
*/
public function contributors() {
$contributors = $this->get_contributors();
if ( empty( $contributors ) ) { $contributor_list = '<ul class="wp-people-group">';
return '';
}
$contributor_list = '<ul class="wp-people-group">'; foreach ( $contributors as $contributor ) {
$contributor_list .= '<li class="wp-person">';
$contributor_list .= sprintf(
'<a href="%s" title="%s">',
esc_url( 'https://github.com/' . $contributor->login ),
esc_html( sprintf( __( 'View %s', 'sportspress' ), $contributor->login ) )
);
$contributor_list .= sprintf( '<img src="%s" width="64" height="64" class="gravatar" alt="%s" />', esc_url( $contributor->avatar_url ), esc_html( $contributor->login ) );
$contributor_list .= '</a>';
$contributor_list .= sprintf( '<a class="web" href="%s">%s</a>', esc_url( 'https://github.com/' . $contributor->login ), esc_html( $contributor->login ) );
$contributor_list .= '</a>';
$contributor_list .= '</li>';
}
foreach ( $contributors as $contributor ) { $contributor_list .= '</ul>';
$contributor_list .= '<li class="wp-person">';
$contributor_list .= sprintf( '<a href="%s" title="%s">',
esc_url( 'https://github.com/' . $contributor->login ),
esc_html( sprintf( __( 'View %s', 'sportspress' ), $contributor->login ) )
);
$contributor_list .= sprintf( '<img src="%s" width="64" height="64" class="gravatar" alt="%s" />', esc_url( $contributor->avatar_url ), esc_html( $contributor->login ) );
$contributor_list .= '</a>';
$contributor_list .= sprintf( '<a class="web" href="%s">%s</a>', esc_url( 'https://github.com/' . $contributor->login ), esc_html( $contributor->login ) );
$contributor_list .= '</a>';
$contributor_list .= '</li>';
}
$contributor_list .= '</ul>'; return $contributor_list;
}
return $contributor_list; /**
} * Retrieve list of contributors from GitHub.
*
* @access public
* @return mixed
*/
public function get_contributors() {
$contributors = get_transient( 'sportspress_contributors' );
/** if ( false !== $contributors ) {
* Retrieve list of contributors from GitHub. return $contributors;
* }
* @access public
* @return mixed
*/
public function get_contributors() {
$contributors = get_transient( 'sportspress_contributors' );
if ( false !== $contributors ) { $response = wp_remote_get( 'https://api.github.com/repos/ThemeBoy/SportsPress/contributors', array( 'sslverify' => false ) );
return $contributors;
}
$response = wp_remote_get( 'https://api.github.com/repos/ThemeBoy/SportsPress/contributors', array( 'sslverify' => false ) ); if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
return array();
}
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) { $contributors = json_decode( wp_remote_retrieve_body( $response ) );
return array();
}
$contributors = json_decode( wp_remote_retrieve_body( $response ) ); if ( ! is_array( $contributors ) ) {
return array();
}
if ( ! is_array( $contributors ) ) { set_transient( 'sportspress_contributors', $contributors, HOUR_IN_SECONDS );
return array();
}
set_transient( 'sportspress_contributors', $contributors, HOUR_IN_SECONDS ); return $contributors;
}
return $contributors; /**
} * Sends user to the welcome page on first activation
*/
public function welcome() {
/** // Bail if no activation redirect transient is set
* Sends user to the welcome page on first activation if ( ! get_transient( '_sp_activation_redirect' ) ) {
*/ return;
public function welcome() { }
// Bail if no activation redirect transient is set // Delete the redirect transient
if ( ! get_transient( '_sp_activation_redirect' ) ) delete_transient( '_sp_activation_redirect' );
return;
// Delete the redirect transient // Bail if we are waiting to install or update via the interface update/install links
delete_transient( '_sp_activation_redirect' ); if ( get_option( '_sp_needs_update' ) == 1 || get_option( '_sp_needs_pages' ) == 1 ) {
return;
}
// Bail if we are waiting to install or update via the interface update/install links // Bail if activating from network, or bulk, or within an iFrame
if ( get_option( '_sp_needs_update' ) == 1 || get_option( '_sp_needs_pages' ) == 1 ) if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) ) {
return; return;
}
// Bail if activating from network, or bulk, or within an iFrame if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action'] ) && ( isset( $_GET['plugin'] ) && strstr( $_GET['plugin'], 'sportspress.php' ) ) ) {
if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) ) return;
return; }
if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action'] ) && ( isset( $_GET['plugin'] ) && strstr( $_GET['plugin'], 'sportspress.php' ) ) ) if ( ! get_option( 'sportspress_completed_setup' ) ) {
return; wp_redirect( admin_url( 'admin.php?page=sp-setup' ) );
exit;
}
if ( ! get_option( 'sportspress_completed_setup' ) ) { wp_redirect( admin_url( 'index.php?page=sp-about' ) );
wp_redirect( admin_url( 'admin.php?page=sp-setup' ) ); exit;
exit; }
}
wp_redirect( admin_url( 'index.php?page=sp-about' ) );
exit;
}
} }
new SP_Admin_Welcome(); new SP_Admin_Welcome();

View File

@@ -6,11 +6,11 @@ if ( ! defined( 'ABSPATH' ) ) {
/** /**
* SportsPress Admin. * SportsPress Admin.
* *
* @class SP_Admin * @class SP_Admin
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 2.5.1 * @version 2.5.1
*/ */
class SP_Admin { class SP_Admin {
@@ -36,32 +36,32 @@ class SP_Admin {
*/ */
public function includes() { public function includes() {
// Functions // Functions
include_once( 'sp-admin-functions.php' ); include_once 'sp-admin-functions.php';
// Classes // Classes
include_once( 'class-sp-admin-post-types.php' ); include_once 'class-sp-admin-post-types.php';
include_once( 'class-sp-admin-taxonomies.php' ); include_once 'class-sp-admin-taxonomies.php';
include_once( 'class-sp-admin-ajax.php' ); include_once 'class-sp-admin-ajax.php';
// Classes we only need if the ajax is not-ajax // Classes we only need if the ajax is not-ajax
if ( ! is_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-welcome.php';
include( 'class-sp-admin-notices.php' ); include 'class-sp-admin-notices.php';
include( 'class-sp-admin-assets.php' ); include 'class-sp-admin-assets.php';
include( 'class-sp-admin-permalink-settings.php' ); include 'class-sp-admin-permalink-settings.php';
if ( 'yes' == get_option( 'sportspress_rich_editing', 'yes' ) ): if ( 'yes' == get_option( 'sportspress_rich_editing', 'yes' ) ) :
include( 'class-sp-admin-editor.php' ); include 'class-sp-admin-editor.php';
endif; endif;
} }
// Setup/welcome // Setup/welcome
if ( ! empty( $_GET['page'] ) ) { if ( ! empty( $_GET['page'] ) ) {
switch ( $_GET['page'] ) { switch ( $_GET['page'] ) {
case 'sp-setup' : case 'sp-setup':
include_once( 'class-sp-admin-setup-wizard.php' ); include_once 'class-sp-admin-setup-wizard.php';
break; break;
} }
} }
} }
@@ -73,8 +73,8 @@ class SP_Admin {
$screen = get_current_screen(); $screen = get_current_screen();
switch ( $screen->id ) { switch ( $screen->id ) {
case 'dashboard' : case 'dashboard':
include( 'class-sp-admin-dashboard.php' ); include 'class-sp-admin-dashboard.php';
break; break;
} }
} }
@@ -85,7 +85,7 @@ class SP_Admin {
public function prevent_admin_access() { public function prevent_admin_access() {
$prevent_access = false; $prevent_access = false;
if ( 'yes' == get_option( 'sportspress_lock_down_admin' ) && ! is_ajax() && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_sportspress' ) ) && basename( $_SERVER["SCRIPT_FILENAME"] ) !== 'admin-post.php' ) { if ( 'yes' == get_option( 'sportspress_lock_down_admin' ) && ! is_ajax() && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_sportspress' ) ) && basename( $_SERVER['SCRIPT_FILENAME'] ) !== 'admin-post.php' ) {
$prevent_access = true; $prevent_access = true;
} }
@@ -134,4 +134,4 @@ class SP_Admin {
} }
} }
return new SP_Admin(); return new SP_Admin();

View File

@@ -2,13 +2,15 @@
/** /**
* Event importer - import events into SportsPress. * Event importer - import events into SportsPress.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Importers * @package SportsPress/Admin/Importers
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) { if ( class_exists( 'WP_Importer' ) ) {
class SP_Event_Importer extends SP_Importer { class SP_Event_Importer extends SP_Importer {
@@ -20,20 +22,21 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void * @return void
*/ */
public function __construct() { public function __construct() {
$this->import_page = 'sp_event_csv'; $this->import_page = 'sp_event_csv';
$this->import_label = __( 'Import Events', 'sportspress' ); $this->import_label = __( 'Import Events', 'sportspress' );
$this->columns = array( $this->columns = array(
'post_date' => __( 'Date', 'sportspress' ), 'post_date' => __( 'Date', 'sportspress' ),
'post_time' => __( 'Time', 'sportspress' ), 'post_time' => __( 'Time', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ), 'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ), 'sp_team' => __( 'Teams', 'sportspress' ),
'sp_results' => __( 'Results', 'sportspress' ), 'sp_results' => __( 'Results', 'sportspress' ),
'sp_outcome' => __( 'Outcome', 'sportspress' ), 'sp_outcome' => __( 'Outcome', 'sportspress' ),
'sp_player' => __( 'Players', 'sportspress' ), 'sp_player' => __( 'Players', 'sportspress' ),
); );
$performance_labels = sp_get_var_labels( 'sp_performance' ); $performance_labels = sp_get_var_labels( 'sp_performance' );
if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) ) if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) ) {
$this->columns = array_merge( $this->columns, $performance_labels ); $this->columns = array_merge( $this->columns, $performance_labels );
}
} }
/** /**
@@ -47,7 +50,7 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'post_title' ) ) { function import( $array = array(), $columns = array( 'post_title' ) ) {
$this->imported = $this->skipped = 0; $this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ): if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer(); $this->footer();
die(); die();
endif; endif;
@@ -56,29 +59,31 @@ if ( class_exists( 'WP_Importer' ) ) {
// Get event format, league, and season from post vars // Get event format, league, and season from post vars
$event_format = ( empty( $_POST['sp_format'] ) ? false : sanitize_text_field( $_POST['sp_format'] ) ); $event_format = ( empty( $_POST['sp_format'] ) ? false : sanitize_text_field( $_POST['sp_format'] ) );
$league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_league'] ) ); $league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_league'] ) );
$season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_season'] ) ); $season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_season'] ) );
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) ); $date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) );
// Get labels from result and performance post types // Get labels from result and performance post types
$result_labels = sp_get_var_labels( 'sp_result' ); $result_labels = sp_get_var_labels( 'sp_result' );
$performance_labels = sp_get_var_labels( 'sp_performance' ); $performance_labels = sp_get_var_labels( 'sp_performance' );
foreach ( $rows as $row ): foreach ( $rows as $row ) :
$row = array_filter( $row ); $row = array_filter( $row );
if ( empty( $row ) ) continue; if ( empty( $row ) ) {
continue;
}
$meta = array(); $meta = array();
foreach ( $columns as $index => $key ): foreach ( $columns as $index => $key ) :
$meta[ $key ] = sp_array_value( $row, $index ); $meta[ $key ] = sp_array_value( $row, $index );
endforeach; endforeach;
// Slice array into event, team, and player // Slice array into event, team, and player
$event = array_slice( $row, 0, 3 ); $event = array_slice( $row, 0, 3 );
$team = array_slice( $row, 3, 3 ); $team = array_slice( $row, 3, 3 );
$player = array_slice( $row, 6 ); $player = array_slice( $row, 6 );
// Get event details // Get event details
@@ -105,16 +110,16 @@ if ( class_exists( 'WP_Importer' ) ) {
$player = array( $player = array(
sp_array_value( $meta, 'sp_player' ), sp_array_value( $meta, 'sp_player' ),
); );
unset( $meta['sp_player' ] ); unset( $meta['sp_player'] );
foreach ( $performance_labels as $key => $label ): foreach ( $performance_labels as $key => $label ) :
$player[] = sp_array_value( $meta, $key, '' ); $player[] = sp_array_value( $meta, $key, '' );
endforeach; endforeach;
// Add new event if date is given // Add new event if date is given
if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ): if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ) :
// Add player performance to last event if available // Add player performance to last event if available
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ): if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ) :
update_post_meta( $id, 'sp_players', $players ); update_post_meta( $id, 'sp_players', $players );
endif; endif;
@@ -122,9 +127,9 @@ if ( class_exists( 'WP_Importer' ) ) {
list( $date, $time, $venue ) = $event; list( $date, $time, $venue ) = $event;
// Format date // Format date
$date = str_replace( '/', '-', trim( $date ) ); $date = str_replace( '/', '-', trim( $date ) );
$date_array = explode( '-', $date ); $date_array = explode( '-', $date );
switch ( $date_format ): switch ( $date_format ) :
case 'dd/mm/yyyy': case 'dd/mm/yyyy':
$date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' . $date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' .
substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' . substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' .
@@ -142,12 +147,17 @@ if ( class_exists( 'WP_Importer' ) ) {
endswitch; endswitch;
// Add time to date if given // Add time to date if given
if ( ! empty( $time ) ): if ( ! empty( $time ) ) :
$date .= ' ' . trim( $time ); $date .= ' ' . trim( $time );
endif; endif;
// Define post type args // Define post type args
$args = array( 'post_type' => 'sp_event', 'post_status' => 'publish', 'post_date' => $date, 'post_title' => __( 'Event', 'sportspress' ) ); $args = array(
'post_type' => 'sp_event',
'post_status' => 'publish',
'post_date' => $date,
'post_title' => __( 'Event', 'sportspress' ),
);
// Insert event // Insert event
$id = wp_insert_post( $args ); $id = wp_insert_post( $args );
@@ -159,17 +169,17 @@ if ( class_exists( 'WP_Importer' ) ) {
update_post_meta( $id, '_sp_import', 1 ); update_post_meta( $id, '_sp_import', 1 );
// Update event format // Update event format
if ( $event_format ): if ( $event_format ) :
update_post_meta( $id, 'sp_format', $event_format ); update_post_meta( $id, 'sp_format', $event_format );
endif; endif;
// Update league // Update league
if ( $league ): if ( $league ) :
wp_set_object_terms( $id, $league, 'sp_league', false ); wp_set_object_terms( $id, $league, 'sp_league', false );
endif; endif;
// Update season // Update season
if ( $season ): if ( $season ) :
wp_set_object_terms( $id, $season, 'sp_season', false ); wp_set_object_terms( $id, $season, 'sp_season', false );
endif; endif;
@@ -182,7 +192,7 @@ if ( class_exists( 'WP_Importer' ) ) {
endif; endif;
// Add new team if team name is given // Add new team if team name is given
if ( sizeof( $team ) > 0 && ! empty( $team[0] ) ): if ( sizeof( $team ) > 0 && ! empty( $team[0] ) ) :
// List team columns // List team columns
list( $team_name, $result, $outcome ) = $team; list( $team_name, $result, $outcome ) = $team;
@@ -191,20 +201,31 @@ if ( class_exists( 'WP_Importer' ) ) {
$team_object = get_page_by_title( stripslashes( $team_name ), OBJECT, 'sp_team' ); $team_object = get_page_by_title( stripslashes( $team_name ), OBJECT, 'sp_team' );
// Get or insert team // Get or insert team
if ( $team_object ): if ( $team_object ) :
// Make sure team is published // Make sure team is published
if ( $team_object->post_status != 'publish' ): if ( $team_object->post_status != 'publish' ) :
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) ); wp_update_post(
array(
'ID' => $team_object->ID,
'post_status' => 'publish',
)
);
endif; endif;
// Get team ID // Get team ID
$team_id = $team_object->ID; $team_id = $team_object->ID;
else: else :
// Insert team // Insert team
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team_name ) ) ); $team_id = wp_insert_post(
array(
'post_type' => 'sp_team',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $team_name ),
)
);
// Flag as import // Flag as import
update_post_meta( $team_id, '_sp_import', 1 ); update_post_meta( $team_id, '_sp_import', 1 );
@@ -212,17 +233,17 @@ if ( class_exists( 'WP_Importer' ) ) {
endif; endif;
// Update league // Update league
if ( $league ): if ( $league ) :
wp_set_object_terms( $team_id, $league, 'sp_league', true ); wp_set_object_terms( $team_id, $league, 'sp_league', true );
endif; endif;
// Update season // Update season
if ( $season ): if ( $season ) :
wp_set_object_terms( $team_id, $season, 'sp_season', true ); wp_set_object_terms( $team_id, $season, 'sp_season', true );
endif; endif;
// Add to event if exists // Add to event if exists
if ( isset( $id ) ): if ( isset( $id ) ) :
// Add team to event // Add team to event
add_post_meta( $id, 'sp_team', $team_id ); add_post_meta( $id, 'sp_team', $team_id );
@@ -235,21 +256,21 @@ if ( class_exists( 'WP_Importer' ) ) {
// Create team results array from result keys // Create team results array from result keys
$team_results = array(); $team_results = array();
if ( sizeof( $result_labels ) > 0 ): if ( sizeof( $result_labels ) > 0 ) :
foreach( $result_labels as $key => $label ): foreach ( $result_labels as $key => $label ) :
$team_results[ $key ] = trim( array_shift( $results ) ); $team_results[ $key ] = trim( array_shift( $results ) );
endforeach; endforeach;
$team_results[ 'outcome' ] = array(); $team_results['outcome'] = array();
endif; endif;
// Explode outcomes into array // Explode outcomes into array
$outcomes = explode( '|', $outcome ); $outcomes = explode( '|', $outcome );
// Add outcome slugs to team outcomes array // Add outcome slugs to team outcomes array
foreach ( $outcomes as $outcome ): foreach ( $outcomes as $outcome ) :
// Continue if outcome doesn't exist // Continue if outcome doesn't exist
if ( $outcome == null ): if ( $outcome == null ) :
continue; continue;
endif; endif;
@@ -259,24 +280,35 @@ if ( class_exists( 'WP_Importer' ) ) {
// Get or insert outcome // Get or insert outcome
$outcome_object = get_page_by_title( stripslashes( $outcome ), OBJECT, 'sp_outcome' ); $outcome_object = get_page_by_title( stripslashes( $outcome ), OBJECT, 'sp_outcome' );
if ( $outcome_object ): if ( $outcome_object ) :
// Make sure outcome is published // Make sure outcome is published
if ( $outcome_object->post_status != 'publish' ): if ( $outcome_object->post_status != 'publish' ) :
wp_update_post( array( 'ID' => $outcome_object->ID, 'post_status' => 'publish' ) ); wp_update_post(
array(
'ID' => $outcome_object->ID,
'post_status' => 'publish',
)
);
endif; endif;
// Get outcome slug // Get outcome slug
$outcome_slug = $outcome_object->post_name; $outcome_slug = $outcome_object->post_name;
else: else :
// Insert outcome // Insert outcome
$outcome_id = wp_insert_post( array( 'post_type' => 'sp_outcome', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $outcome ) ) ); $outcome_id = wp_insert_post(
array(
'post_type' => 'sp_outcome',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $outcome ),
)
);
// Get outcome slug // Get outcome slug
$post_data = get_post( $outcome_id, ARRAY_A ); $post_data = get_post( $outcome_id, ARRAY_A );
$outcome_slug = $post_data['post_name']; $outcome_slug = $post_data['post_name'];
// Flag as import // Flag as import
update_post_meta( $outcome_id, '_sp_import', 1 ); update_post_meta( $outcome_id, '_sp_import', 1 );
@@ -284,7 +316,7 @@ if ( class_exists( 'WP_Importer' ) ) {
endif; endif;
// Add to team results array // Add to team results array
$team_results[ 'outcome' ][] = $outcome_slug; $team_results['outcome'][] = $outcome_slug;
endforeach; endforeach;
@@ -292,7 +324,7 @@ if ( class_exists( 'WP_Importer' ) ) {
$event_results = get_post_meta( $id, 'sp_results', true ); $event_results = get_post_meta( $id, 'sp_results', true );
// Create new array if results not exists // Create new array if results not exists
if ( ! $event_results ): if ( ! $event_results ) :
$event_results = array(); $event_results = array();
endif; endif;
@@ -317,9 +349,9 @@ if ( class_exists( 'WP_Importer' ) ) {
// Update event with new name // Update event with new name
$post = array( $post = array(
'ID' => $id, 'ID' => $id,
'post_title' => $title, 'post_title' => $title,
'post_name' => $id, 'post_name' => $id,
); );
wp_update_post( $post ); wp_update_post( $post );
@@ -328,7 +360,7 @@ if ( class_exists( 'WP_Importer' ) ) {
endif; endif;
// Add new player if player name is given // Add new player if player name is given
if ( sizeof( $player ) > 0 && ! empty( $player[0] ) ): if ( sizeof( $player ) > 0 && ! empty( $player[0] ) ) :
// Get and unset player name leaving us with the performance // Get and unset player name leaving us with the performance
$player_name = $player[0]; $player_name = $player[0];
@@ -338,11 +370,16 @@ if ( class_exists( 'WP_Importer' ) ) {
$player_object = get_page_by_title( stripslashes( $player_name ), OBJECT, 'sp_player' ); $player_object = get_page_by_title( stripslashes( $player_name ), OBJECT, 'sp_player' );
// Get or insert player // Get or insert player
if ( $player_object ): if ( $player_object ) :
// Make sure player is published // Make sure player is published
if ( $player_object->post_status != 'publish' ): if ( $player_object->post_status != 'publish' ) :
wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) ); wp_update_post(
array(
'ID' => $player_object->ID,
'post_status' => 'publish',
)
);
endif; endif;
// Get player ID // Get player ID
@@ -351,10 +388,16 @@ if ( class_exists( 'WP_Importer' ) ) {
// Get player number // Get player number
$player_number = get_post_meta( $player_id, 'sp_number', true ); $player_number = get_post_meta( $player_id, 'sp_number', true );
else: else :
// Insert player // Insert player
$player_id = wp_insert_post( array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $player_name ) ) ); $player_id = wp_insert_post(
array(
'post_type' => 'sp_player',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $player_name ),
)
);
// Flag as import // Flag as import
update_post_meta( $player_id, '_sp_import', 1 ); update_post_meta( $player_id, '_sp_import', 1 );
@@ -368,29 +411,29 @@ if ( class_exists( 'WP_Importer' ) ) {
endif; endif;
// Update league // Update league
if ( $league ): if ( $league ) :
wp_set_object_terms( $player_id, $league, 'sp_league', true ); wp_set_object_terms( $player_id, $league, 'sp_league', true );
endif; endif;
// Update season // Update season
if ( $season ): if ( $season ) :
wp_set_object_terms( $player_id, $season, 'sp_season', true ); wp_set_object_terms( $player_id, $season, 'sp_season', true );
endif; endif;
// Add to event if exists // Add to event if exists
if ( isset( $id ) ): if ( isset( $id ) ) :
// Add player to event // Add player to event
add_post_meta( $id, 'sp_player', $player_id ); add_post_meta( $id, 'sp_player', $player_id );
// Add player performance to array if team is available // Add player performance to array if team is available
if ( isset( $team_id ) ): if ( isset( $team_id ) ) :
// Initialize performance array // Initialize performance array
$performance = array( 'number' => $player_number ); $performance = array( 'number' => $player_number );
// Map keys to player performance // Map keys to player performance
foreach ( $performance_labels as $key => $label ): foreach ( $performance_labels as $key => $label ) :
$performance[ $key ] = array_shift( $player ); $performance[ $key ] = array_shift( $player );
endforeach; endforeach;
$players[ $team_id ][ $player_id ] = $performance; $players[ $team_id ][ $player_id ] = $performance;
@@ -398,17 +441,17 @@ if ( class_exists( 'WP_Importer' ) ) {
// Get player teams // Get player teams
$player_teams = get_post_meta( $player_id, 'sp_team', false ); $player_teams = get_post_meta( $player_id, 'sp_team', false );
$current_team = get_post_meta( $player_id, 'sp_current_team', true ); $current_team = get_post_meta( $player_id, 'sp_current_team', true );
$past_teams = get_post_meta( $player_id, 'sp_past_team', false ); $past_teams = get_post_meta( $player_id, 'sp_past_team', false );
// Add team if not exists in player // Add team if not exists in player
if ( ! in_array( $team_id, $player_teams ) ): if ( ! in_array( $team_id, $player_teams ) ) :
add_post_meta( $player_id, 'sp_team', $team_id ); add_post_meta( $player_id, 'sp_team', $team_id );
endif; endif;
// Add as past team or set current team if not set // Add as past team or set current team if not set
if ( ! $current_team ): if ( ! $current_team ) :
update_post_meta( $player_id, 'sp_current_team', $team_id ); update_post_meta( $player_id, 'sp_current_team', $team_id );
elseif ( $current_team != $team_id && ! in_array( $team_id, $past_teams ) ): elseif ( $current_team != $team_id && ! in_array( $team_id, $past_teams ) ) :
add_post_meta( $player_id, 'sp_past_team', $team_id ); add_post_meta( $player_id, 'sp_past_team', $team_id );
endif; endif;
@@ -421,13 +464,13 @@ if ( class_exists( 'WP_Importer' ) ) {
endforeach; endforeach;
// Add player performance to last event if available // Add player performance to last event if available
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ): if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ) :
update_post_meta( $id, 'sp_players', $players ); update_post_meta( $id, 'sp_players', $players );
endif; endif;
// Show Result // Show Result
echo '<div class="updated settings-error below-h2"><p> echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> events and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).' ' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> events and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>'; </p></div>';
$this->import_end(); $this->import_end();
@@ -437,7 +480,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache * Performs post-import cleanup of files and the cache
*/ */
function import_end() { function import_end() {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_event') . '">' . __( 'View Events', 'sportspress' ) . '</a>' . '</p>'; echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_event' ) . '">' . __( 'View Events', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' ); do_action( 'import_end' );
} }
@@ -450,7 +493,7 @@ if ( class_exists( 'WP_Importer' ) ) {
*/ */
function greet() { function greet() {
echo '<div class="narrow">'; echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>'; echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Events need to be defined with columns in a specific order (3+ columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/events-sample.csv' ) . '</p>'; echo '<p>' . sprintf( __( 'Events need to be defined with columns in a specific order (3+ columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/events-sample.csv' ) . '</p>';
echo '<p>' . sprintf( __( 'Supports CSV files generated by <a href="%s">LeagueLobster</a>.', 'sportspress' ), 'http://tboy.co/leaguelobster' ) . '</p>'; echo '<p>' . sprintf( __( 'Supports CSV files generated by <a href="%s">LeagueLobster</a>.', 'sportspress' ), 'http://tboy.co/leaguelobster' ) . '</p>';
wp_import_upload_form( 'admin.php?import=sp_event_csv&step=1' ); wp_import_upload_form( 'admin.php?import=sp_event_csv&step=1' );
@@ -473,11 +516,11 @@ if ( class_exists( 'WP_Importer' ) ) {
<fieldset id="post-formats-select"> <fieldset id="post-formats-select">
<ul> <ul>
<?php <?php
foreach( (new SP_Formats)->event as $name => $title ) { foreach ( ( new SP_Formats() )->event as $name => $title ) {
?> ?>
<li><input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $name ); ?>" checked="checked"> <label for="post-format-<?php echo esc_attr( $name ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $name ); ?>"><?php echo esc_html( $title ); ?></label></li> <li><input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $name ); ?>" checked="checked"> <label for="post-format-<?php echo esc_attr( $name ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $name ); ?>"><?php echo esc_html( $title ); ?></label></li>
<?php <?php
} }
?> ?>
</ul> </ul>
</fieldset> </fieldset>
@@ -485,56 +528,60 @@ if ( class_exists( 'WP_Importer' ) ) {
</tr> </tr>
<tr> <tr>
<th scope="row"><label><?php _e( 'League', 'sportspress' ); ?></label><br/></th> <th scope="row"><label><?php _e( 'League', 'sportspress' ); ?></label><br/></th>
<td><?php <td>
<?php
$args = array( $args = array(
'taxonomy' => 'sp_league', 'taxonomy' => 'sp_league',
'name' => 'sp_league', 'name' => 'sp_league',
'values' => 'slug', 'values' => 'slug',
'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ), 'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ),
); );
if ( ! sp_dropdown_taxonomies( $args ) ): if ( ! sp_dropdown_taxonomies( $args ) ) :
echo '<p>' . __( 'None', 'sportspress' ) . '</p>'; echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) ); sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
endif; endif;
?></td> ?>
</td>
</tr> </tr>
<tr> <tr>
<th scope="row"><label><?php _e( 'Season', 'sportspress' ); ?></label><br/></th> <th scope="row"><label><?php _e( 'Season', 'sportspress' ); ?></label><br/></th>
<td><?php <td>
<?php
$args = array( $args = array(
'taxonomy' => 'sp_season', 'taxonomy' => 'sp_season',
'name' => 'sp_season', 'name' => 'sp_season',
'values' => 'slug', 'values' => 'slug',
'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ), 'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ),
); );
if ( ! sp_dropdown_taxonomies( $args ) ): if ( ! sp_dropdown_taxonomies( $args ) ) :
echo '<p>' . __( 'None', 'sportspress' ) . '</p>'; echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) ); sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
endif; endif;
?></td> ?>
</td>
</tr> </tr>
<tr> <tr>
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<?php _e( 'Date Format', 'sportspress' ); ?> <?php _e( 'Date Format', 'sportspress' ); ?>
</th> </th>
<td class="forminp forminp-radio"> <td class="forminp forminp-radio">
<fieldset> <fieldset>
<ul> <ul>
<li> <li>
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label> <label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
</li> </li>
<li> <li>
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label> <label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
</li> </li>
<li> <li>
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label> <label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
</li> </li>
</ul> </ul>
</fieldset> </fieldset>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<?php <?php
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* Event Performance importer - import box scores into SportsPress. * Event Performance importer - import box scores into SportsPress.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Importers * @package SportsPress/Admin/Importers
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) { if ( class_exists( 'WP_Importer' ) ) {
class SP_Event_Performance_Importer extends SP_Importer { class SP_Event_Performance_Importer extends SP_Importer {
@@ -20,14 +22,15 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void * @return void
*/ */
public function __construct() { public function __construct() {
$this->import_page = 'sp_event_performance_csv'; $this->import_page = 'sp_event_performance_csv';
$this->import_label = __( 'Import Box Score', 'sportspress' ); $this->import_label = __( 'Import Box Score', 'sportspress' );
$this->columns = array( $this->columns = array(
'sp_player' => __( 'Player', 'sportspress' ), 'sp_player' => __( 'Player', 'sportspress' ),
); );
$performance_labels = sp_get_var_labels( 'sp_performance' ); $performance_labels = sp_get_var_labels( 'sp_performance' );
if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) ) if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) ) {
$this->columns = array_merge( $this->columns, $performance_labels ); $this->columns = array_merge( $this->columns, $performance_labels );
}
} }
/** /**
@@ -41,7 +44,7 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'sp_player' ) ) { function import( $array = array(), $columns = array( 'sp_player' ) ) {
$this->imported = $this->skipped = 0; $this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ): if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer(); $this->footer();
die(); die();
endif; endif;
@@ -52,36 +55,44 @@ if ( class_exists( 'WP_Importer' ) ) {
$event = ( empty( $_POST['sp_event'] ) ? false : sanitize_text_field( $_POST['sp_event'] ) ); $event = ( empty( $_POST['sp_event'] ) ? false : sanitize_text_field( $_POST['sp_event'] ) );
$teams = ( empty( $_POST['sp_teams'] ) ? false : sanitize_text_field( $_POST['sp_teams'] ) ); $teams = ( empty( $_POST['sp_teams'] ) ? false : sanitize_text_field( $_POST['sp_teams'] ) );
$index = ( empty( $_POST['sp_index'] ) ? false : sanitize_text_field( $_POST['sp_index'] ) ); $index = ( empty( $_POST['sp_index'] ) ? false : sanitize_text_field( $_POST['sp_index'] ) );
$team = ( empty( $_POST['sp_team'] ) ? false : sanitize_text_field( $_POST['sp_team'] ) ); $team = ( empty( $_POST['sp_team'] ) ? false : sanitize_text_field( $_POST['sp_team'] ) );
$team_players = array( 0 ); $team_players = array( 0 );
$team_performance = array(); $team_performance = array();
$name_index = (int) array_search( 'sp_player', $columns ); $name_index = (int) array_search( 'sp_player', $columns );
foreach ( $rows as $row ): foreach ( $rows as $row ) :
$row = array_filter( $row ); $row = array_filter( $row );
if ( empty( $row ) ) continue; if ( empty( $row ) ) {
continue;
}
$player_name = sp_array_value( $row, $name_index ); $player_name = sp_array_value( $row, $name_index );
if ( ! $player_name ): if ( ! $player_name ) :
$this->skipped ++; $this->skipped ++;
continue; continue;
endif; endif;
$player_object = get_page_by_title( stripslashes( $player_name ), OBJECT, 'sp_player' ); $player_object = get_page_by_title( stripslashes( $player_name ), OBJECT, 'sp_player' );
if ( $player_object ): if ( $player_object ) :
// Get player ID // Get player ID
$player_id = $player_object->ID; $player_id = $player_object->ID;
else: else :
// Insert player // Insert player
$player_id = wp_insert_post( array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $player_name ) ) ); $player_id = wp_insert_post(
array(
'post_type' => 'sp_player',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $player_name ),
)
);
// Flag as import // Flag as import
update_post_meta( $player_id, '_sp_import', 1 ); update_post_meta( $player_id, '_sp_import', 1 );
@@ -89,10 +100,12 @@ if ( class_exists( 'WP_Importer' ) ) {
endif; endif;
$team_players[] = $player_id; $team_players[] = $player_id;
$player = array(); $player = array();
foreach ( $columns as $i => $key ): foreach ( $columns as $i => $key ) :
if ( 'sp_player' === $key ) continue; if ( 'sp_player' === $key ) {
continue;
}
$player[ $key ] = sp_array_value( $row, $i, '' ); $player[ $key ] = sp_array_value( $row, $i, '' );
endforeach; endforeach;
@@ -100,13 +113,13 @@ if ( class_exists( 'WP_Importer' ) ) {
endforeach; endforeach;
if ( $event && $team ): if ( $event && $team ) :
$the_players = get_post_meta( $event, 'sp_player', false ); $the_players = get_post_meta( $event, 'sp_player', false );
$players = array(); $players = array();
for ( $i = 0; $i < $teams; $i++ ): for ( $i = 0; $i < $teams; $i++ ) :
if ( $index == $i ): if ( $index == $i ) :
array_push( $players, $team_players ); array_push( $players, $team_players );
else: else :
array_push( $players, sp_array_between( $the_players, 0, $i ) ); array_push( $players, sp_array_between( $the_players, 0, $i ) );
endif; endif;
endfor; endfor;
@@ -114,15 +127,15 @@ if ( class_exists( 'WP_Importer' ) ) {
$this->imported = sizeof( $team_players ) - 1; $this->imported = sizeof( $team_players ) - 1;
$performance = (array) get_post_meta( $event, 'sp_players', true ); $performance = (array) get_post_meta( $event, 'sp_players', true );
$performance = array_filter( $performance ); $performance = array_filter( $performance );
$performance[ $team ] = $team_performance; $performance[ $team ] = $team_performance;
update_post_meta( $event, 'sp_players', $performance ); update_post_meta( $event, 'sp_players', $performance );
endif; endif;
// Show Result // Show Result
echo '<div class="updated settings-error below-h2"><p> echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> rows and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).' ' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> rows and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>'; </p></div>';
$this->import_end( $event ); $this->import_end( $event );
@@ -132,7 +145,15 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache * Performs post-import cleanup of files and the cache
*/ */
function import_end( $event = 0 ) { function import_end( $event = 0 ) {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( add_query_arg( array( 'post' => $event, 'action' => 'edit' ), 'post.php' ) ) . '">' . __( 'View Event', 'sportspress' ) . '</a>' . '</p>'; echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url(
add_query_arg(
array(
'post' => $event,
'action' => 'edit',
),
'post.php'
)
) . '">' . __( 'View Event', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' ); do_action( 'import_end' );
} }
@@ -149,8 +170,14 @@ if ( class_exists( 'WP_Importer' ) ) {
echo '<div class="narrow">'; echo '<div class="narrow">';
if ( $event ) { if ( $event ) {
$args = array_merge( $_REQUEST, array( 'import' => 'sp_event_performance_csv', 'step' => '1' ) ); $args = array_merge(
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>'; $_REQUEST,
array(
'import' => 'sp_event_performance_csv',
'step' => '1',
)
);
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Box scores need to be defined with columns in a specific order. <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/event-performance-sample.csv' ) . '</p>'; echo '<p>' . sprintf( __( 'Box scores need to be defined with columns in a specific order. <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/event-performance-sample.csv' ) . '</p>';
wp_import_upload_form( add_query_arg( $args, 'admin.php' ) ); wp_import_upload_form( add_query_arg( $args, 'admin.php' ) );
} else { } else {
@@ -167,10 +194,10 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void * @return void
*/ */
function options() { function options() {
$event = sp_array_value( $_REQUEST, 'event', 0, 'key' ); $event = sp_array_value( $_REQUEST, 'event', 0, 'key' );
$teams = sp_array_value( $_REQUEST, 'teams', 0, 'key' ); $teams = sp_array_value( $_REQUEST, 'teams', 0, 'key' );
$index = sp_array_value( $_REQUEST, 'index', 0, 'key' ); $index = sp_array_value( $_REQUEST, 'index', 0, 'key' );
$team = sp_array_value( $_REQUEST, 'team', 0, 'key' ); $team = sp_array_value( $_REQUEST, 'team', 0, 'key' );
$include = get_post_meta( $event, 'sp_team', false ); $include = get_post_meta( $event, 'sp_team', false );
?> ?>
<table class="form-table"> <table class="form-table">
@@ -192,10 +219,10 @@ if ( class_exists( 'WP_Importer' ) ) {
<?php <?php
$args = array( $args = array(
'post_type' => 'sp_team', 'post_type' => 'sp_team',
'name' => 'sp_team', 'name' => 'sp_team',
'values' => 'ID', 'values' => 'ID',
'selected' => $team, 'selected' => $team,
'include' => $include, 'include' => $include,
); );
sp_dropdown_pages( $args ); sp_dropdown_pages( $args );
?> ?>

View File

@@ -2,13 +2,15 @@
/** /**
* Fixture importer - import fixtures into SportsPress. * Fixture importer - import fixtures into SportsPress.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Importers * @package SportsPress/Admin/Importers
* @version 2.7 * @version 2.7
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) { if ( class_exists( 'WP_Importer' ) ) {
class SP_Fixture_Importer extends SP_Importer { class SP_Fixture_Importer extends SP_Importer {
@@ -20,17 +22,17 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void * @return void
*/ */
public function __construct() { public function __construct() {
$this->import_page = 'sp_fixture_csv'; $this->import_page = 'sp_fixture_csv';
$this->import_label = __( 'Import Fixtures', 'sportspress' ); $this->import_label = __( 'Import Fixtures', 'sportspress' );
$this->columns = array( $this->columns = array(
'post_date' => __( 'Date', 'sportspress' ), 'post_date' => __( 'Date', 'sportspress' ),
'post_time' => __( 'Time', 'sportspress' ), 'post_time' => __( 'Time', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ), 'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_home' => __( 'Home', 'sportspress' ), 'sp_home' => __( 'Home', 'sportspress' ),
'sp_away' => __( 'Away', 'sportspress' ), 'sp_away' => __( 'Away', 'sportspress' ),
'sp_day' => __( 'Match Day', 'sportspress' ), 'sp_day' => __( 'Match Day', 'sportspress' ),
); );
$this->optionals = array( 'sp_day' ); $this->optionals = array( 'sp_day' );
} }
/** /**
@@ -44,7 +46,7 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'post_title' ) ) { function import( $array = array(), $columns = array( 'post_title' ) ) {
$this->imported = $this->skipped = 0; $this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ): if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer(); $this->footer();
die(); die();
endif; endif;
@@ -53,19 +55,21 @@ if ( class_exists( 'WP_Importer' ) ) {
// Get event format, league, and season from post vars // Get event format, league, and season from post vars
$event_format = ( empty( $_POST['sp_format'] ) ? false : $_POST['sp_format'] ); $event_format = ( empty( $_POST['sp_format'] ) ? false : $_POST['sp_format'] );
$league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : $_POST['sp_league'] ); $league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : $_POST['sp_league'] );
$season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : $_POST['sp_season'] ); $season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : $_POST['sp_season'] );
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : $_POST['sp_date_format'] ); $date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : $_POST['sp_date_format'] );
foreach ( $rows as $row ): foreach ( $rows as $row ) :
$row = array_filter( $row ); $row = array_filter( $row );
if ( empty( $row ) ) continue; if ( empty( $row ) ) {
continue;
}
$meta = array(); $meta = array();
foreach ( $columns as $index => $key ): foreach ( $columns as $index => $key ) :
$meta[ $key ] = sp_array_value( $row, $index ); $meta[ $key ] = sp_array_value( $row, $index );
endforeach; endforeach;
@@ -83,15 +87,15 @@ if ( class_exists( 'WP_Importer' ) ) {
); );
// Add new event if date is given // Add new event if date is given
if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ): if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ) :
// List event columns // List event columns
list( $date, $time, $venue, $day ) = $event; list( $date, $time, $venue, $day ) = $event;
// Format date // Format date
$date = str_replace( '/', '-', trim( $date ) ); $date = str_replace( '/', '-', trim( $date ) );
$date_array = explode( '-', $date ); $date_array = explode( '-', $date );
switch ( $date_format ): switch ( $date_format ) :
case 'dd/mm/yyyy': case 'dd/mm/yyyy':
$date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' . $date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' .
substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' . substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' .
@@ -109,12 +113,17 @@ if ( class_exists( 'WP_Importer' ) ) {
endswitch; endswitch;
// Add time to date if given // Add time to date if given
if ( ! empty( $time ) ): if ( ! empty( $time ) ) :
$date .= ' ' . trim( $time ); $date .= ' ' . trim( $time );
endif; endif;
// Define post type args // Define post type args
$args = array( 'post_type' => 'sp_event', 'post_status' => 'publish', 'post_date' => $date, 'post_title' => __( 'Event', 'sportspress' ) ); $args = array(
'post_type' => 'sp_event',
'post_status' => 'publish',
'post_date' => $date,
'post_title' => __( 'Event', 'sportspress' ),
);
// Insert event // Insert event
$id = wp_insert_post( $args ); $id = wp_insert_post( $args );
@@ -123,25 +132,25 @@ if ( class_exists( 'WP_Importer' ) ) {
update_post_meta( $id, '_sp_import', 1 ); update_post_meta( $id, '_sp_import', 1 );
// Update event format // Update event format
if ( $event_format ): if ( $event_format ) :
update_post_meta( $id, 'sp_format', $event_format ); update_post_meta( $id, 'sp_format', $event_format );
endif; endif;
// Update league // Update league
if ( $league ): if ( $league ) :
wp_set_object_terms( $id, $league, 'sp_league', false ); wp_set_object_terms( $id, $league, 'sp_league', false );
endif; endif;
// Update season // Update season
if ( $season ): if ( $season ) :
wp_set_object_terms( $id, $season, 'sp_season', false ); wp_set_object_terms( $id, $season, 'sp_season', false );
endif; endif;
// Update venue // Update venue
if ( $venue == '' ) { if ( $venue == '' ) {
$team = reset( $teams ); $team = reset( $teams );
$team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' ); $team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' );
$venue = sp_get_the_term_id( $team_object->ID, 'sp_venue' ); $venue = sp_get_the_term_id( $team_object->ID, 'sp_venue' );
} }
wp_set_object_terms( $id, $venue, 'sp_venue', false ); wp_set_object_terms( $id, $venue, 'sp_venue', false );
@@ -156,30 +165,41 @@ if ( class_exists( 'WP_Importer' ) ) {
endif; endif;
// Add teams to event // Add teams to event
if ( sizeof( $teams ) > 0 ): if ( sizeof( $teams ) > 0 ) :
foreach ( $teams as $team_name ): foreach ( $teams as $team_name ) :
if ( '' !== $team_name ): if ( '' !== $team_name ) :
// Find out if team exists // Find out if team exists
$team_object = get_page_by_title( stripslashes( $team_name ), OBJECT, 'sp_team' ); $team_object = get_page_by_title( stripslashes( $team_name ), OBJECT, 'sp_team' );
// Get or insert team // Get or insert team
if ( $team_object ): if ( $team_object ) :
// Make sure team is published // Make sure team is published
if ( $team_object->post_status != 'publish' ): if ( $team_object->post_status != 'publish' ) :
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) ); wp_update_post(
array(
'ID' => $team_object->ID,
'post_status' => 'publish',
)
);
endif; endif;
// Get team ID // Get team ID
$team_id = $team_object->ID; $team_id = $team_object->ID;
else: else :
// Insert team // Insert team
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team_name ) ) ); $team_id = wp_insert_post(
array(
'post_type' => 'sp_team',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $team_name ),
)
);
// Flag as import // Flag as import
update_post_meta( $team_id, '_sp_import', 1 ); update_post_meta( $team_id, '_sp_import', 1 );
@@ -187,17 +207,17 @@ if ( class_exists( 'WP_Importer' ) ) {
endif; endif;
// Update league // Update league
if ( $league ): if ( $league ) :
wp_set_object_terms( $team_id, $league, 'sp_league', true ); wp_set_object_terms( $team_id, $league, 'sp_league', true );
endif; endif;
// Update season // Update season
if ( $season ): if ( $season ) :
wp_set_object_terms( $team_id, $season, 'sp_season', true ); wp_set_object_terms( $team_id, $season, 'sp_season', true );
endif; endif;
// Add to event if exists // Add to event if exists
if ( isset( $id ) ): if ( isset( $id ) ) :
// Add team to event // Add team to event
add_post_meta( $id, 'sp_team', $team_id ); add_post_meta( $id, 'sp_team', $team_id );
@@ -217,19 +237,19 @@ if ( class_exists( 'WP_Importer' ) ) {
// Update event with new name // Update event with new name
$post = array( $post = array(
'ID' => $id, 'ID' => $id,
'post_title' => $title, 'post_title' => $title,
'post_name' => $id, 'post_name' => $id,
); );
wp_update_post( $post ); wp_update_post( $post );
endif; endif;
else: else :
// Add empty team to event // Add empty team to event
add_post_meta( $id, 'sp_team', -1 ); add_post_meta( $id, 'sp_team', -1 );
endif; endif;
endforeach; endforeach;
@@ -240,7 +260,7 @@ if ( class_exists( 'WP_Importer' ) ) {
// Show Result // Show Result
echo '<div class="updated settings-error below-h2"><p> echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> events and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).' ' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> events and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>'; </p></div>';
$this->import_end(); $this->import_end();
@@ -250,7 +270,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache * Performs post-import cleanup of files and the cache
*/ */
function import_end() { function import_end() {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_event') . '">' . __( 'View Fixtures', 'sportspress' ) . '</a>' . '</p>'; echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_event' ) . '">' . __( 'View Fixtures', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' ); do_action( 'import_end' );
} }
@@ -263,7 +283,7 @@ if ( class_exists( 'WP_Importer' ) ) {
*/ */
function greet() { function greet() {
echo '<div class="narrow">'; echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>'; echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Fixtures need to be defined with columns in a specific order (4+ columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/fixtures-sample.csv' ) . '</p>'; echo '<p>' . sprintf( __( 'Fixtures need to be defined with columns in a specific order (4+ columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/fixtures-sample.csv' ) . '</p>';
echo '<p>' . sprintf( __( 'Supports CSV files generated by <a href="%s">LeagueLobster</a>.', 'sportspress' ), 'http://tboy.co/leaguelobster' ) . '</p>'; echo '<p>' . sprintf( __( 'Supports CSV files generated by <a href="%s">LeagueLobster</a>.', 'sportspress' ), 'http://tboy.co/leaguelobster' ) . '</p>';
wp_import_upload_form( 'admin.php?import=sp_fixture_csv&step=1' ); wp_import_upload_form( 'admin.php?import=sp_fixture_csv&step=1' );
@@ -293,56 +313,60 @@ if ( class_exists( 'WP_Importer' ) ) {
</tr> </tr>
<tr> <tr>
<th scope="row"><label><?php _e( 'League', 'sportspress' ); ?></label><br/></th> <th scope="row"><label><?php _e( 'League', 'sportspress' ); ?></label><br/></th>
<td><?php <td>
<?php
$args = array( $args = array(
'taxonomy' => 'sp_league', 'taxonomy' => 'sp_league',
'name' => 'sp_league', 'name' => 'sp_league',
'values' => 'slug', 'values' => 'slug',
'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ), 'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ),
); );
if ( ! sp_dropdown_taxonomies( $args ) ): if ( ! sp_dropdown_taxonomies( $args ) ) :
echo '<p>' . __( 'None', 'sportspress' ) . '</p>'; echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) ); sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
endif; endif;
?></td> ?>
</td>
</tr> </tr>
<tr> <tr>
<th scope="row"><label><?php _e( 'Season', 'sportspress' ); ?></label><br/></th> <th scope="row"><label><?php _e( 'Season', 'sportspress' ); ?></label><br/></th>
<td><?php <td>
<?php
$args = array( $args = array(
'taxonomy' => 'sp_season', 'taxonomy' => 'sp_season',
'name' => 'sp_season', 'name' => 'sp_season',
'values' => 'slug', 'values' => 'slug',
'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ), 'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ),
); );
if ( ! sp_dropdown_taxonomies( $args ) ): if ( ! sp_dropdown_taxonomies( $args ) ) :
echo '<p>' . __( 'None', 'sportspress' ) . '</p>'; echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) ); sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
endif; endif;
?></td> ?>
</td>
</tr> </tr>
<tr> <tr>
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<?php _e( 'Date Format', 'sportspress' ); ?> <?php _e( 'Date Format', 'sportspress' ); ?>
</th> </th>
<td class="forminp forminp-radio"> <td class="forminp forminp-radio">
<fieldset> <fieldset>
<ul> <ul>
<li> <li>
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label> <label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
</li> </li>
<li> <li>
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label> <label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
</li> </li>
<li> <li>
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label> <label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
</li> </li>
</ul> </ul>
</fieldset> </fieldset>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<?php <?php
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* SportsPress Importer * SportsPress Importer
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Importers * @package SportsPress/Admin/Importers
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) { if ( class_exists( 'WP_Importer' ) ) {
class SP_Importer extends WP_Importer { class SP_Importer extends WP_Importer {
@@ -21,7 +23,7 @@ if ( class_exists( 'WP_Importer' ) ) {
var $imported; var $imported;
var $skipped; var $skipped;
var $import_label; var $import_label;
var $columns = array(); var $columns = array();
var $optionals = array(); var $optionals = array();
/** /**
@@ -35,7 +37,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Enqueue scripts * Enqueue scripts
*/ */
public function admin_scripts() { public function admin_scripts() {
wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret' ), SP_VERSION, true ); wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret' ), SP_VERSION, true );
} }
/** /**
@@ -46,32 +48,36 @@ if ( class_exists( 'WP_Importer' ) ) {
function dispatch() { function dispatch() {
$this->header(); $this->header();
if ( ! empty( $_POST['delimiter'] ) ) if ( ! empty( $_POST['delimiter'] ) ) {
$this->delimiter = stripslashes( trim( sanitize_text_field( $_POST['delimiter'] ) ) ); $this->delimiter = stripslashes( trim( sanitize_text_field( $_POST['delimiter'] ) ) );
}
if ( ! $this->delimiter ) if ( ! $this->delimiter ) {
$this->delimiter = ','; $this->delimiter = ',';
}
$step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step']; $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
switch ( $step ): switch ( $step ) :
case 0: case 0:
$this->greet(); $this->greet();
break; break;
case 1: case 1:
check_admin_referer( 'import-upload' ); check_admin_referer( 'import-upload' );
if ( $this->handle_upload() ): if ( $this->handle_upload() ) :
if ( $this->id ) if ( $this->id ) {
$file = get_attached_file( $this->id ); $file = get_attached_file( $this->id );
else } else {
$file = ABSPATH . $this->file_url; $file = ABSPATH . $this->file_url;
}
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) ); add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
if ( function_exists( 'gc_enable' ) ) if ( function_exists( 'gc_enable' ) ) {
gc_enable(); gc_enable();
}
@set_time_limit(0); @set_time_limit( 0 );
@ob_flush(); @ob_flush();
@flush(); @flush();
@@ -80,7 +86,7 @@ if ( class_exists( 'WP_Importer' ) ) {
break; break;
case 2: case 2:
check_admin_referer( 'import-upload' ); check_admin_referer( 'import-upload' );
if ( isset( $_POST['sp_import'] ) ): if ( isset( $_POST['sp_import'] ) ) :
$columns = array_filter( sp_array_value( $_POST, 'sp_columns', array( 'post_title' ) ) ); $columns = array_filter( sp_array_value( $_POST, 'sp_columns', array( 'post_title' ) ) );
$this->import( $_POST['sp_import'], array_values( $columns ) ); $this->import( $_POST['sp_import'], array_values( $columns ) );
endif; endif;
@@ -100,7 +106,7 @@ if ( class_exists( 'WP_Importer' ) ) {
?> ?>
<select name="sp_columns[]" data-index="<?php echo array_search( $selected, array_keys( $this->columns ) ); ?>"> <select name="sp_columns[]" data-index="<?php echo array_search( $selected, array_keys( $this->columns ) ); ?>">
<option value="0">&mdash; <?php _e( 'Disable', 'sportspress' ); ?> &mdash;</option> <option value="0">&mdash; <?php _e( 'Disable', 'sportspress' ); ?> &mdash;</option>
<?php foreach ( $this->columns as $key => $label ): ?> <?php foreach ( $this->columns as $key => $label ) : ?>
<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $selected, $key ); ?>><?php echo esc_html( $label ); ?></option> <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $selected, $key ); ?>><?php echo esc_html( $label ); ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
@@ -119,26 +125,26 @@ if ( class_exists( 'WP_Importer' ) ) {
$this->imported = $this->skipped = 0; $this->imported = $this->skipped = 0;
if ( ! is_file($file) ): if ( ! is_file( $file ) ) :
$this->footer(); $this->footer();
die(); die();
endif; endif;
ini_set( 'auto_detect_line_endings', '1' ); ini_set( 'auto_detect_line_endings', '1' );
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ): if ( ( $handle = fopen( $file, 'r' ) ) !== false ) :
$header = fgetcsv( $handle, 0, $this->delimiter ); $header = fgetcsv( $handle, 0, $this->delimiter );
if ( sizeof( $header ) >= 1 ): if ( sizeof( $header ) >= 1 ) :
$action = 'admin.php?import=' . $this->import_page . '&step=2'; $action = 'admin.php?import=' . $this->import_page . '&step=2';
?> ?>
<form enctype="multipart/form-data" id="import-upload-form" class="sportspress" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>"> <form enctype="multipart/form-data" id="import-upload-form" class="sportspress" method="post" action="<?php echo esc_attr( wp_nonce_url( $action, 'import-upload' ) ); ?>">
<?php $this->options(); ?> <?php $this->options(); ?>
<table class="wp-list-table sp-data-table sp-import-table widefat fixed pages"> <table class="wp-list-table sp-data-table sp-import-table widefat fixed pages">
<thead> <thead>
<tr> <tr>
<?php foreach ( $this->columns as $key => $label ): ?> <?php foreach ( $this->columns as $key => $label ) : ?>
<th scope="col" class="manage-column"> <th scope="col" class="manage-column">
<?php $this->dropdown( $key ); ?> <?php $this->dropdown( $key ); ?>
</th> </th>
@@ -149,21 +155,35 @@ if ( class_exists( 'WP_Importer' ) ) {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ): ?> <?php while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== false ) : ?>
<tr> <tr>
<?php $index = 0; foreach ( $this->columns as $key => $label ): $value = sp_array_value( $row, $index ); ?> <?php
$index = 0;
foreach ( $this->columns as $key => $label ) :
$value = sp_array_value( $row, $index );
?>
<td> <td>
<input type="text" class="widefat" value="<?php echo esc_attr( $value ); ?>" name="sp_import[]"<?php if ( in_array( $key, $this->optionals ) ) { ?> placeholder="<?php _e( 'Default', 'sportspress' ); ?>"<?php } ?>> <input type="text" class="widefat" value="<?php echo esc_attr( $value ); ?>" name="sp_import[]"
<?php
if ( in_array( $key, $this->optionals ) ) {
?>
placeholder="<?php _e( 'Default', 'sportspress' ); ?>"<?php } ?>>
</td> </td>
<?php $index ++; endforeach; ?> <?php
$index ++;
endforeach;
?>
<td class="sp-actions-column"> <td class="sp-actions-column">
<a href="#" title="<?php _e( 'Delete row', 'sportspress' ); ?>" class="dashicons dashicons-dismiss sp-delete-row"></a> <a href="#" title="<?php _e( 'Delete row', 'sportspress' ); ?>" class="dashicons dashicons-dismiss sp-delete-row"></a>
<a href="#" title="<?php _e( 'Insert row after', 'sportspress' ); ?>" class="dashicons dashicons-plus-alt sp-add-row"></a> <a href="#" title="<?php _e( 'Insert row after', 'sportspress' ); ?>" class="dashicons dashicons-plus-alt sp-add-row"></a>
</td> </td>
</tr> </tr>
<?php $this->imported++; endwhile; ?> <?php
$this->imported++;
endwhile;
?>
<tr> <tr>
<?php foreach ( $this->columns as $key => $label ): ?> <?php foreach ( $this->columns as $key => $label ) : ?>
<td> <td>
<input type="text" class="widefat" name="sp_import[]"> <input type="text" class="widefat" name="sp_import[]">
</td> </td>
@@ -172,17 +192,17 @@ if ( class_exists( 'WP_Importer' ) ) {
<a href="#" title="<?php _e( 'Insert row after', 'sportspress' ); ?>" class="dashicons dashicons-plus-alt sp-add-row"></a> <a href="#" title="<?php _e( 'Insert row after', 'sportspress' ); ?>" class="dashicons dashicons-plus-alt sp-add-row"></a>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<p class="sp-post-count alignright"> <p class="sp-post-count alignright">
<?php printf( __( 'Displaying %s&#8211;%s of %s', 'sportspress' ), 1, $this->imported+1, $this->imported+1 ); ?> <?php printf( __( 'Displaying %1$s&#8211;%2$s of %3$s', 'sportspress' ), 1, $this->imported + 1, $this->imported + 1 ); ?>
</p> </p>
<p class="submit"> <p class="submit">
<input type="submit" class="button button-primary button-hero" value="<?php echo esc_attr( $this->import_label ); ?>" /> <input type="submit" class="button button-primary button-hero" value="<?php echo esc_attr( $this->import_label ); ?>" />
</p> </p>
</form> </form>
<?php <?php
else: else :
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'sportspress' ) . '</strong><br />'; echo '<p><strong>' . __( 'Sorry, there has been an error.', 'sportspress' ) . '</strong><br />';
_e( 'The CSV is invalid.', 'sportspress' ) . '</p>'; _e( 'The CSV is invalid.', 'sportspress' ) . '</p>';
@@ -191,7 +211,7 @@ if ( class_exists( 'WP_Importer' ) ) {
endif; endif;
fclose( $handle ); fclose( $handle );
endif; endif;
} }
@@ -199,7 +219,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* format_data_from_csv function. * format_data_from_csv function.
* *
* @access public * @access public
* @param mixed $data * @param mixed $data
* @param string $enc * @param string $enc
* @return string * @return string
*/ */
@@ -239,7 +259,6 @@ if ( class_exists( 'WP_Importer' ) ) {
return false; return false;
} }
} }
return true; return true;
@@ -276,6 +295,7 @@ if ( class_exists( 'WP_Importer' ) ) {
/** /**
* Added to http_request_timeout filter to force timeout at 60 seconds during import * Added to http_request_timeout filter to force timeout at 60 seconds during import
*
* @param int $val * @param int $val
* @return int 60 * @return int 60
*/ */

View File

@@ -2,13 +2,15 @@
/** /**
* Official importer - import officials into SportsPress. * Official importer - import officials into SportsPress.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Importers * @package SportsPress/Admin/Importers
* @version 2.5.1 * @version 2.5.1
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) { if ( class_exists( 'WP_Importer' ) ) {
class SP_Official_Importer extends SP_Importer { class SP_Official_Importer extends SP_Importer {
@@ -20,9 +22,9 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void * @return void
*/ */
public function __construct() { public function __construct() {
$this->import_page = 'sp_official_csv'; $this->import_page = 'sp_official_csv';
$this->import_label = __( 'Import Officials', 'sportspress' ); $this->import_label = __( 'Import Officials', 'sportspress' );
$this->columns = array( $this->columns = array(
'post_title' => __( 'Name', 'sportspress' ), 'post_title' => __( 'Name', 'sportspress' ),
); );
parent::__construct(); parent::__construct();
@@ -39,33 +41,39 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'post_title' ) ) { function import( $array = array(), $columns = array( 'post_title' ) ) {
$this->imported = $this->skipped = 0; $this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ): if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer(); $this->footer();
die(); die();
endif; endif;
$rows = array_chunk( $array, sizeof( $columns ) ); $rows = array_chunk( $array, sizeof( $columns ) );
foreach ( $rows as $row ): foreach ( $rows as $row ) :
$row = array_filter( $row ); $row = array_filter( $row );
if ( empty( $row ) ) continue; if ( empty( $row ) ) {
continue;
}
$meta = array(); $meta = array();
foreach ( $columns as $index => $key ): foreach ( $columns as $index => $key ) :
$meta[ $key ] = sp_array_value( $row, $index ); $meta[ $key ] = sp_array_value( $row, $index );
endforeach; endforeach;
$name = sp_array_value( $meta, 'post_title' ); $name = sp_array_value( $meta, 'post_title' );
if ( ! $name ): if ( ! $name ) :
$this->skipped++; $this->skipped++;
continue; continue;
endif; endif;
$args = array( 'post_type' => 'sp_official', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) ); $args = array(
'post_type' => 'sp_official',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $name ),
);
$id = wp_insert_post( $args ); $id = wp_insert_post( $args );
@@ -75,7 +83,7 @@ if ( class_exists( 'WP_Importer' ) ) {
// Show Result // Show Result
echo '<div class="updated settings-error below-h2"><p> echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> officials and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).' ' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> officials and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>'; </p></div>';
$this->import_end(); $this->import_end();
@@ -85,7 +93,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache * Performs post-import cleanup of files and the cache
*/ */
function import_end() { function import_end() {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_official') . '">' . __( 'View Officials', 'sportspress' ) . '</a>' . '</p>'; echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_official' ) . '">' . __( 'View Officials', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' ); do_action( 'import_end' );
} }
@@ -108,7 +116,7 @@ if ( class_exists( 'WP_Importer' ) ) {
*/ */
function greet() { function greet() {
echo '<div class="narrow">'; echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>'; echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Officials need to be defined with columns in a specific order. <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/officials-sample.csv' ) . '</p>'; echo '<p>' . sprintf( __( 'Officials need to be defined with columns in a specific order. <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/officials-sample.csv' ) . '</p>';
wp_import_upload_form( 'admin.php?import=sp_official_csv&step=1' ); wp_import_upload_form( 'admin.php?import=sp_official_csv&step=1' );
echo '</div>'; echo '</div>';

View File

@@ -2,13 +2,15 @@
/** /**
* Player importer - import players into SportsPress. * Player importer - import players into SportsPress.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Importers * @package SportsPress/Admin/Importers
* @version 2.7 * @version 2.7
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) { if ( class_exists( 'WP_Importer' ) ) {
class SP_Player_Importer extends SP_Importer { class SP_Player_Importer extends SP_Importer {
@@ -20,17 +22,17 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void * @return void
*/ */
public function __construct() { public function __construct() {
$this->import_page = 'sp_player_csv'; $this->import_page = 'sp_player_csv';
$this->import_label = __( 'Import Players', 'sportspress' ); $this->import_label = __( 'Import Players', 'sportspress' );
$this->columns = array( $this->columns = array(
'sp_number' => __( 'Squad Number', 'sportspress' ), 'sp_number' => __( 'Squad Number', 'sportspress' ),
'post_title' => __( 'Name', 'sportspress' ), 'post_title' => __( 'Name', 'sportspress' ),
'sp_position' => __( 'Positions', 'sportspress' ), 'sp_position' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ), 'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ), 'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ), 'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_nationality' => __( 'Nationality', 'sportspress' ), 'sp_nationality' => __( 'Nationality', 'sportspress' ),
'post_date' => __( 'Date of Birth', 'sportspress' ), 'post_date' => __( 'Date of Birth', 'sportspress' ),
); );
parent::__construct(); parent::__construct();
} }
@@ -46,21 +48,23 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'post_title' ) ) { function import( $array = array(), $columns = array( 'post_title' ) ) {
$this->imported = $this->skipped = 0; $this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ): if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer(); $this->footer();
die(); die();
endif; endif;
$rows = array_chunk( $array, sizeof( $columns ) ); $rows = array_chunk( $array, sizeof( $columns ) );
// Get Date of Birth format from post vars // Get Date of Birth format from post vars
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) ); $date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) );
foreach ( $rows as $row ): foreach ( $rows as $row ) :
$row = array_filter( $row, 'strlen' ); $row = array_filter( $row, 'strlen' );
if ( empty( $row ) ) continue; if ( empty( $row ) ) {
continue;
}
$meta = array(); $meta = array();
@@ -76,17 +80,17 @@ if ( class_exists( 'WP_Importer' ) ) {
$meta[ $p ] = ''; $meta[ $p ] = '';
} }
foreach ( $columns as $index => $key ): foreach ( $columns as $index => $key ) :
$meta[ $key ] = sp_array_value( $row, $index ); $meta[ $key ] = sp_array_value( $row, $index );
endforeach; endforeach;
$name = sp_array_value( $meta, 'post_title' ); $name = sp_array_value( $meta, 'post_title' );
$date = sp_array_value( $meta, 'post_date' ); $date = sp_array_value( $meta, 'post_date' );
// Format date of birth // Format date of birth
$date = str_replace( '/', '-', trim( $date ) ); $date = str_replace( '/', '-', trim( $date ) );
$date_array = explode( '-', $date ); $date_array = explode( '-', $date );
switch ( $date_format ): switch ( $date_format ) :
case 'dd/mm/yyyy': case 'dd/mm/yyyy':
$date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' . $date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' .
substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' . substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' .
@@ -103,28 +107,37 @@ if ( class_exists( 'WP_Importer' ) ) {
substr( str_pad( sp_array_value( $date_array, 2, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ); substr( str_pad( sp_array_value( $date_array, 2, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 );
endswitch; endswitch;
if ( ! $name ): if ( ! $name ) :
$this->skipped++; $this->skipped++;
continue; continue;
endif; endif;
// Get or insert player // Get or insert player
$player_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_player' ) : false; $player_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_player' ) : false;
if ( $player_object ): if ( $player_object ) :
if ( $player_object->post_status != 'publish' ): if ( $player_object->post_status != 'publish' ) :
wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) ); wp_update_post(
array(
'ID' => $player_object->ID,
'post_status' => 'publish',
)
);
endif; endif;
$id = $player_object->ID; $id = $player_object->ID;
// Handle preservable data. // Handle preservable data.
foreach ( $preservable_metas_keys as $p ) { foreach ( $preservable_metas_keys as $p ) {
$terms = wp_get_object_terms( $id, $p, array( 'fields' => 'names' ) ); $terms = wp_get_object_terms( $id, $p, array( 'fields' => 'names' ) );
$meta[ $p ] .= '|' . implode( '|', $terms ); $meta[ $p ] .= '|' . implode( '|', $terms );
} }
else: else :
$args = array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) ); $args = array(
'post_type' => 'sp_player',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $name ),
);
// Check if a DoB was set // Check if a DoB was set
if( '0000-00-00' !== $date ){ if ( '0000-00-00' !== $date ) {
$args['post_date'] = $date; $args['post_date'] = $date;
} }
$id = wp_insert_post( $args ); $id = wp_insert_post( $args );
@@ -148,18 +161,29 @@ if ( class_exists( 'WP_Importer' ) ) {
wp_set_object_terms( $id, $seasons, 'sp_season', false ); wp_set_object_terms( $id, $seasons, 'sp_season', false );
// Update teams // Update teams
$teams = (array)explode( '|', sp_array_value( $meta, 'sp_team' ) ); $teams = (array) explode( '|', sp_array_value( $meta, 'sp_team' ) );
$i = 0; $i = 0;
foreach ( $teams as $team ): foreach ( $teams as $team ) :
// Get or insert team // Get or insert team
$team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' ); $team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' );
if ( $team_object ): if ( $team_object ) :
if ( $team_object->post_status != 'publish' ): if ( $team_object->post_status != 'publish' ) :
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) ); wp_update_post(
array(
'ID' => $team_object->ID,
'post_status' => 'publish',
)
);
endif; endif;
$team_id = $team_object->ID; $team_id = $team_object->ID;
else: else :
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team ) ) ); $team_id = wp_insert_post(
array(
'post_type' => 'sp_team',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $team ),
)
);
// Flag as import // Flag as import
update_post_meta( $team_id, '_sp_import', 1 ); update_post_meta( $team_id, '_sp_import', 1 );
wp_set_object_terms( $team_id, $leagues, 'sp_league', false ); wp_set_object_terms( $team_id, $leagues, 'sp_league', false );
@@ -170,7 +194,7 @@ if ( class_exists( 'WP_Importer' ) ) {
add_post_meta( $id, 'sp_team', $team_id ); add_post_meta( $id, 'sp_team', $team_id );
// Update current team if first in array, otherwise use as past team // Update current team if first in array, otherwise use as past team
if ( $i == 0 ): if ( $i == 0 ) :
update_post_meta( $id, 'sp_current_team', $team_id ); update_post_meta( $id, 'sp_current_team', $team_id );
else : else :
add_post_meta( $id, 'sp_past_team', $team_id ); add_post_meta( $id, 'sp_past_team', $team_id );
@@ -181,7 +205,9 @@ if ( class_exists( 'WP_Importer' ) ) {
// Update nationality // Update nationality
$nationality = trim( strtolower( sp_array_value( $meta, 'sp_nationality' ) ) ); $nationality = trim( strtolower( sp_array_value( $meta, 'sp_nationality' ) ) );
if ( $nationality == '*' ) $nationality = ''; if ( $nationality == '*' ) {
$nationality = '';
}
update_post_meta( $id, 'sp_nationality', $nationality ); update_post_meta( $id, 'sp_nationality', $nationality );
$this->imported++; $this->imported++;
@@ -190,7 +216,7 @@ if ( class_exists( 'WP_Importer' ) ) {
// Show Result // Show Result
echo '<div class="updated settings-error below-h2"><p> echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> players and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).' ' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> players and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>'; </p></div>';
$this->import_end(); $this->import_end();
@@ -200,7 +226,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache * Performs post-import cleanup of files and the cache
*/ */
function import_end() { function import_end() {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_player') . '">' . __( 'View Players', 'sportspress' ) . '</a>' . '</p>'; echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_player' ) . '">' . __( 'View Players', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' ); do_action( 'import_end' );
} }
@@ -223,7 +249,7 @@ if ( class_exists( 'WP_Importer' ) ) {
*/ */
function greet() { function greet() {
echo '<div class="narrow">'; echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>'; echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Players need to be defined with columns in a specific order (8 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/players-sample.csv' ) . '</p>'; echo '<p>' . sprintf( __( 'Players need to be defined with columns in a specific order (8 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/players-sample.csv' ) . '</p>';
wp_import_upload_form( 'admin.php?import=sp_player_csv&step=1' ); wp_import_upload_form( 'admin.php?import=sp_player_csv&step=1' );
echo '</div>'; echo '</div>';
@@ -243,22 +269,22 @@ if ( class_exists( 'WP_Importer' ) ) {
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<?php _e( 'Date of Birth Format', 'sportspress' ); ?> <?php _e( 'Date of Birth Format', 'sportspress' ); ?>
</th> </th>
<td class="forminp forminp-radio"> <td class="forminp forminp-radio">
<fieldset> <fieldset>
<ul> <ul>
<li> <li>
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label> <label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
</li> </li>
<li> <li>
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label> <label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
</li> </li>
<li> <li>
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label> <label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
</li> </li>
</ul> </ul>
</fieldset> </fieldset>
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<label> <label>

View File

@@ -2,13 +2,15 @@
/** /**
* Staff importer - import staff into SportsPress. * Staff importer - import staff into SportsPress.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Importers * @package SportsPress/Admin/Importers
* @version 2.5.5 * @version 2.5.5
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) { if ( class_exists( 'WP_Importer' ) ) {
class SP_Staff_Importer extends SP_Importer { class SP_Staff_Importer extends SP_Importer {
@@ -20,14 +22,14 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void * @return void
*/ */
public function __construct() { public function __construct() {
$this->import_page = 'sp_staff_csv'; $this->import_page = 'sp_staff_csv';
$this->import_label = __( 'Import Staff', 'sportspress' ); $this->import_label = __( 'Import Staff', 'sportspress' );
$this->columns = array( $this->columns = array(
'post_title' => __( 'Name', 'sportspress' ), 'post_title' => __( 'Name', 'sportspress' ),
'sp_role' => __( 'Jobs', 'sportspress' ), 'sp_role' => __( 'Jobs', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ), 'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ), 'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ), 'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_nationality' => __( 'Nationality', 'sportspress' ), 'sp_nationality' => __( 'Nationality', 'sportspress' ),
); );
parent::__construct(); parent::__construct();
@@ -44,42 +46,53 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'post_title' ) ) { function import( $array = array(), $columns = array( 'post_title' ) ) {
$this->imported = $this->skipped = 0; $this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ): if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer(); $this->footer();
die(); die();
endif; endif;
$rows = array_chunk( $array, sizeof( $columns ) ); $rows = array_chunk( $array, sizeof( $columns ) );
foreach ( $rows as $row ): foreach ( $rows as $row ) :
$row = array_filter( $row ); $row = array_filter( $row );
if ( empty( $row ) ) continue; if ( empty( $row ) ) {
continue;
}
$meta = array(); $meta = array();
foreach ( $columns as $index => $key ): foreach ( $columns as $index => $key ) :
$meta[ $key ] = sp_array_value( $row, $index ); $meta[ $key ] = sp_array_value( $row, $index );
endforeach; endforeach;
$name = sp_array_value( $meta, 'post_title' ); $name = sp_array_value( $meta, 'post_title' );
if ( ! $name ): if ( ! $name ) :
$this->skipped++; $this->skipped++;
continue; continue;
endif; endif;
// Get or insert staff // Get or insert staff
$staff_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_staff' ) : false; $staff_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_staff' ) : false;
if ( $staff_object ): if ( $staff_object ) :
if ( $staff_object->post_status != 'publish' ): if ( $staff_object->post_status != 'publish' ) :
wp_update_post( array( 'ID' => $staff_object->ID, 'post_status' => 'publish' ) ); wp_update_post(
array(
'ID' => $staff_object->ID,
'post_status' => 'publish',
)
);
endif; endif;
$id = $staff_object->ID; $id = $staff_object->ID;
else: else :
$args = array( 'post_type' => 'sp_staff', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) ); $args = array(
$id = wp_insert_post( $args ); 'post_type' => 'sp_staff',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $name ),
);
$id = wp_insert_post( $args );
// Flag as import // Flag as import
update_post_meta( $id, '_sp_import', 1 ); update_post_meta( $id, '_sp_import', 1 );
@@ -98,18 +111,29 @@ if ( class_exists( 'WP_Importer' ) ) {
wp_set_object_terms( $id, $seasons, 'sp_season', false ); wp_set_object_terms( $id, $seasons, 'sp_season', false );
// Update teams // Update teams
$teams = (array)explode( '|', sp_array_value( $meta, 'sp_team' ) ); $teams = (array) explode( '|', sp_array_value( $meta, 'sp_team' ) );
$i = 0; $i = 0;
foreach ( $teams as $team ): foreach ( $teams as $team ) :
// Get or insert team // Get or insert team
$team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' ); $team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' );
if ( $team_object ): if ( $team_object ) :
if ( $team_object->post_status != 'publish' ): if ( $team_object->post_status != 'publish' ) :
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) ); wp_update_post(
array(
'ID' => $team_object->ID,
'post_status' => 'publish',
)
);
endif; endif;
$team_id = $team_object->ID; $team_id = $team_object->ID;
else: else :
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team ) ) ); $team_id = wp_insert_post(
array(
'post_type' => 'sp_team',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $team ),
)
);
// Flag as import // Flag as import
update_post_meta( $team_id, '_sp_import', 1 ); update_post_meta( $team_id, '_sp_import', 1 );
wp_set_object_terms( $team_id, $leagues, 'sp_league', false ); wp_set_object_terms( $team_id, $leagues, 'sp_league', false );
@@ -120,7 +144,7 @@ if ( class_exists( 'WP_Importer' ) ) {
add_post_meta( $id, 'sp_team', $team_id ); add_post_meta( $id, 'sp_team', $team_id );
// Update current team if first in array // Update current team if first in array
if ( $i == 0 ): if ( $i == 0 ) :
update_post_meta( $id, 'sp_current_team', $team_id ); update_post_meta( $id, 'sp_current_team', $team_id );
endif; endif;
@@ -129,7 +153,9 @@ if ( class_exists( 'WP_Importer' ) ) {
// Update nationality // Update nationality
$nationality = trim( strtolower( sp_array_value( $meta, 'sp_nationality' ) ) ); $nationality = trim( strtolower( sp_array_value( $meta, 'sp_nationality' ) ) );
if ( $nationality == '*' ) $nationality = ''; if ( $nationality == '*' ) {
$nationality = '';
}
update_post_meta( $id, 'sp_nationality', $nationality ); update_post_meta( $id, 'sp_nationality', $nationality );
$this->imported++; $this->imported++;
@@ -138,7 +164,7 @@ if ( class_exists( 'WP_Importer' ) ) {
// Show Result // Show Result
echo '<div class="updated settings-error below-h2"><p> echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> staff and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).' ' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> staff and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>'; </p></div>';
$this->import_end(); $this->import_end();
@@ -148,7 +174,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache * Performs post-import cleanup of files and the cache
*/ */
function import_end() { function import_end() {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_staff') . '">' . __( 'View Staff', 'sportspress' ) . '</a>' . '</p>'; echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_staff' ) . '">' . __( 'View Staff', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' ); do_action( 'import_end' );
} }
@@ -171,7 +197,7 @@ if ( class_exists( 'WP_Importer' ) ) {
*/ */
function greet() { function greet() {
echo '<div class="narrow">'; echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>'; echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Staff need to be defined with columns in a specific order (6 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/staff-sample.csv' ) . '</p>'; echo '<p>' . sprintf( __( 'Staff need to be defined with columns in a specific order (6 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/staff-sample.csv' ) . '</p>';
wp_import_upload_form( 'admin.php?import=sp_staff_csv&step=1' ); wp_import_upload_form( 'admin.php?import=sp_staff_csv&step=1' );
echo '</div>'; echo '</div>';

View File

@@ -2,13 +2,15 @@
/** /**
* Team importer - import teams into SportsPress. * Team importer - import teams into SportsPress.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Importers * @package SportsPress/Admin/Importers
* @version 2.5.5 * @version 2.5.5
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) { if ( class_exists( 'WP_Importer' ) ) {
class SP_Team_Importer extends SP_Importer { class SP_Team_Importer extends SP_Importer {
@@ -20,15 +22,15 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void * @return void
*/ */
public function __construct() { public function __construct() {
$this->import_page = 'sp_team_csv'; $this->import_page = 'sp_team_csv';
$this->import_label = __( 'Import Teams', 'sportspress' ); $this->import_label = __( 'Import Teams', 'sportspress' );
$this->columns = array( $this->columns = array(
'post_title' => __( 'Name', 'sportspress' ), 'post_title' => __( 'Name', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ), 'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ), 'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_url' => __( 'Site URL', 'sportspress' ), 'sp_url' => __( 'Site URL', 'sportspress' ),
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ), 'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
'sp_venue' => __( 'Home', 'sportspress' ), 'sp_venue' => __( 'Home', 'sportspress' ),
); );
parent::__construct(); parent::__construct();
} }
@@ -44,42 +46,53 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'post_title' ) ) { function import( $array = array(), $columns = array( 'post_title' ) ) {
$this->imported = $this->skipped = 0; $this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ): if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer(); $this->footer();
die(); die();
endif; endif;
$rows = array_chunk( $array, sizeof( $columns ) ); $rows = array_chunk( $array, sizeof( $columns ) );
foreach ( $rows as $row ): foreach ( $rows as $row ) :
$row = array_filter( $row ); $row = array_filter( $row );
if ( empty( $row ) ) continue; if ( empty( $row ) ) {
continue;
}
$meta = array(); $meta = array();
foreach ( $columns as $index => $key ): foreach ( $columns as $index => $key ) :
$meta[ $key ] = sp_array_value( $row, $index ); $meta[ $key ] = sp_array_value( $row, $index );
endforeach; endforeach;
$name = sp_array_value( $meta, 'post_title' ); $name = sp_array_value( $meta, 'post_title' );
if ( ! $name ): if ( ! $name ) :
$this->skipped++; $this->skipped++;
continue; continue;
endif; endif;
// Get or insert team // Get or insert team
$team_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_team' ) : false; $team_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_team' ) : false;
if ( $team_object ): if ( $team_object ) :
if ( $team_object->post_status != 'publish' ): if ( $team_object->post_status != 'publish' ) :
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) ); wp_update_post(
array(
'ID' => $team_object->ID,
'post_status' => 'publish',
)
);
endif; endif;
$id = $team_object->ID; $id = $team_object->ID;
else: else :
$args = array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) ); $args = array(
$id = wp_insert_post( $args ); 'post_type' => 'sp_team',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $name ),
);
$id = wp_insert_post( $args );
// Flag as import // Flag as import
update_post_meta( $id, '_sp_import', 1 ); update_post_meta( $id, '_sp_import', 1 );
@@ -107,7 +120,7 @@ if ( class_exists( 'WP_Importer' ) ) {
// Show Result // Show Result
echo '<div class="updated settings-error below-h2"><p> echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> teams and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).' ' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> teams and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>'; </p></div>';
$this->import_end(); $this->import_end();
@@ -117,7 +130,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache * Performs post-import cleanup of files and the cache
*/ */
function import_end() { function import_end() {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_team') . '">' . __( 'View Teams', 'sportspress' ) . '</a>' . '</p>'; echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_team' ) . '">' . __( 'View Teams', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' ); do_action( 'import_end' );
} }
@@ -130,7 +143,7 @@ if ( class_exists( 'WP_Importer' ) ) {
*/ */
function greet() { function greet() {
echo '<div class="narrow">'; echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>'; echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Teams need to be defined with columns in a specific order (3 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/teams-sample.csv' ) . '</p>'; echo '<p>' . sprintf( __( 'Teams need to be defined with columns in a specific order (3 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/teams-sample.csv' ) . '</p>';
wp_import_upload_form( 'admin.php?import=sp_team_csv&step=1' ); wp_import_upload_form( 'admin.php?import=sp_team_csv&step=1' );
echo '</div>'; echo '</div>';

View File

@@ -2,160 +2,170 @@
/** /**
* Admin functions for the calendars post type * Admin functions for the calendars post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Calendar' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Calendar' ) ) :
/**
* SP_Admin_CPT_Calendar Class
*/
class SP_Admin_CPT_Calendar extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Calendar Class
*/ */
public function __construct() { class SP_Admin_CPT_Calendar extends SP_Admin_CPT {
$this->type = 'sp_calendar';
// Admin Columns /**
add_filter( 'manage_edit-sp_calendar_columns', array( $this, 'edit_columns' ) ); * Constructor
add_action( 'manage_sp_calendar_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); */
public function __construct() {
$this->type = 'sp_calendar';
// Filtering // Admin Columns
add_action( 'restrict_manage_posts', array( $this, 'filters' ) ); add_filter( 'manage_edit-sp_calendar_columns', array( $this, 'edit_columns' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) ); add_action( 'manage_sp_calendar_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/** // Filtering
* Change the columns shown in admin. add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
*/ add_filter( 'parse_query', array( $this, 'filters_query' ) );
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_team' => __( 'Team', 'sportspress' ),
'sp_events' => __( 'Events', 'sportspress' ),
'sp_layout' => __( 'Layout', 'sportspress' ),
), $existing_columns );
return apply_filters( 'sportspress_calendar_admin_columns', $columns );
}
/** // Call SP_Admin_CPT constructor
* Define our custom columns shown in admin. parent::__construct();
* @param string $column }
*/
public function custom_columns( $column, $post_id ) { /**
switch ( $column ): * Change the columns shown in admin.
case 'sp_league': */
echo get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : __( 'All', 'sportspress' ); public function edit_columns( $existing_columns ) {
break; unset( $existing_columns['author'], $existing_columns['date'] );
case 'sp_season': $columns = array_merge(
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : __( 'All', 'sportspress' ); array(
break; 'cb' => '<input type="checkbox" />',
case 'sp_venue': 'title' => __( 'Title', 'sportspress' ),
echo get_the_terms ( $post_id, 'sp_venue' ) ? the_terms( $post_id, 'sp_venue' ) : __( 'All', 'sportspress' ); 'sp_league' => __( 'League', 'sportspress' ),
break; 'sp_season' => __( 'Season', 'sportspress' ),
case 'sp_team': 'sp_venue' => __( 'Venue', 'sportspress' ),
$teams = (array)get_post_meta( $post_id, 'sp_team', false ); 'sp_team' => __( 'Team', 'sportspress' ),
$teams = array_filter( $teams ); 'sp_events' => __( 'Events', 'sportspress' ),
if ( empty( $teams ) ): 'sp_layout' => __( 'Layout', 'sportspress' ),
echo __( 'All', 'sportspress' ); ),
else: $existing_columns
$current_team = get_post_meta( $post_id, 'sp_current_team', true ); );
foreach( $teams as $team_id ): return apply_filters( 'sportspress_calendar_admin_columns', $columns );
if ( ! $team_id ) continue; }
$team = get_post( $team_id );
if ( $team ): /**
echo esc_html( $team->post_title ); * Define our custom columns shown in admin.
if ( $team_id == $current_team ): *
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>'; * @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_league':
echo get_the_terms( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : __( 'All', 'sportspress' );
break;
case 'sp_season':
echo get_the_terms( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : __( 'All', 'sportspress' );
break;
case 'sp_venue':
echo get_the_terms( $post_id, 'sp_venue' ) ? the_terms( $post_id, 'sp_venue' ) : __( 'All', 'sportspress' );
break;
case 'sp_team':
$teams = (array) get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
if ( empty( $teams ) ) :
echo __( 'All', 'sportspress' );
else :
$current_team = get_post_meta( $post_id, 'sp_current_team', true );
foreach ( $teams as $team_id ) :
if ( ! $team_id ) {
continue;
}
$team = get_post( $team_id );
if ( $team ) :
echo esc_html( $team->post_title );
if ( $team_id == $current_team ) :
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
endif;
echo '<br>';
endif; endif;
echo '<br>'; endforeach;
endif; endif;
endforeach; break;
endif; case 'sp_events':
break; $calendar = new SP_Calendar( $post_id );
case 'sp_events': echo sizeof( $calendar->data() );
$calendar = new SP_Calendar( $post_id ); break;
echo sizeof( $calendar->data() ); case 'sp_layout':
break; echo esc_html( sp_array_value( SP()->formats->calendar, get_post_meta( $post_id, 'sp_format', true ), '&mdash;' ) );
case 'sp_layout': break;
echo esc_html( sp_array_value( SP()->formats->calendar, get_post_meta( $post_id, 'sp_format', true ), '&mdash;' ) ); endswitch;
break; }
endswitch;
}
/** /**
* Show a category filter box * Show a category filter box
*/ */
public function filters() { public function filters() {
global $typenow, $wp_query; global $typenow, $wp_query;
if ( $typenow != 'sp_calendar' ) if ( $typenow != 'sp_calendar' ) {
return; return;
}
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null; $selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array( $args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ), 'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league', 'taxonomy' => 'sp_league',
'name' => 'sp_league', 'name' => 'sp_league',
'selected' => $selected 'selected' => $selected,
); );
sp_dropdown_taxonomies( $args ); sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null; $selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array( $args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ), 'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season', 'taxonomy' => 'sp_season',
'name' => 'sp_season', 'name' => 'sp_season',
'selected' => $selected 'selected' => $selected,
); );
sp_dropdown_taxonomies( $args ); sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_REQUEST['team'] ) : null; $selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_REQUEST['team'] ) : null;
$args = array( $args = array(
'post_type' => 'sp_team', 'post_type' => 'sp_team',
'name' => 'team', 'name' => 'team',
'show_option_none' => __( 'Show all teams', 'sportspress' ), 'show_option_none' => __( 'Show all teams', 'sportspress' ),
'selected' => $selected, 'selected' => $selected,
'values' => 'ID', 'values' => 'ID',
); );
wp_dropdown_pages( $args ); wp_dropdown_pages( $args );
} }
/** /**
* Filter in admin based on options * Filter in admin based on options
* *
* @param mixed $query * @param mixed $query
*/ */
public function filters_query( $query ) { public function filters_query( $query ) {
global $typenow, $wp_query; global $typenow, $wp_query;
if ( $typenow == 'sp_calendar' ) { if ( $typenow == 'sp_calendar' ) {
if ( ! empty( $_GET['team'] ) ) { if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] ); $query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team'; $query->query_vars['meta_key'] = 'sp_team';
} }
}
} }
} }
}
endif; endif;

View File

@@ -2,80 +2,84 @@
/** /**
* Admin functions for the columns post type * Admin functions for the columns post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Column' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Column' ) ) :
/**
* SP_Admin_CPT_Column Class
*/
class SP_Admin_CPT_Column extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Column Class
*/ */
public function __construct() { class SP_Admin_CPT_Column extends SP_Admin_CPT {
$this->type = 'sp_column';
// Admin Columns /**
add_filter( 'manage_edit-sp_column_columns', array( $this, 'edit_columns' ) ); * Constructor
add_action( 'manage_sp_column_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); */
public function __construct() {
// Call SP_Admin_CPT constructor $this->type = 'sp_column';
parent::__construct();
}
/** // Admin Columns
* Change the columns shown in admin. add_filter( 'manage_edit-sp_column_columns', array( $this, 'edit_columns' ) );
*/ add_action( 'manage_sp_column_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
'sp_precision' => __( 'Decimal Places', 'sportspress' ),
'sp_order' => __( 'Sort Order', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_column_admin_columns', $columns );
}
/** // Call SP_Admin_CPT constructor
* Define our custom columns shown in admin. parent::__construct();
* @param string $column }
*/
public function custom_columns( $column, $post_id ) { /**
switch ( $column ): * Change the columns shown in admin.
case 'sp_key': */
global $post; public function edit_columns( $existing_columns ) {
echo esc_html( $post->post_name ); $columns = array(
break; 'cb' => '<input type="checkbox" />',
case 'sp_equation': 'title' => __( 'Label', 'sportspress' ),
echo wp_kses_post( sp_get_post_equation( $post_id ) ); 'sp_key' => __( 'Key', 'sportspress' ),
break; 'sp_equation' => __( 'Equation', 'sportspress' ),
case 'sp_precision': 'sp_precision' => __( 'Decimal Places', 'sportspress' ),
echo esc_html( sp_get_post_precision( $post_id ) ); 'sp_order' => __( 'Sort Order', 'sportspress' ),
break; 'sp_description' => __( 'Description', 'sportspress' ),
case 'sp_order': );
echo esc_html( sp_get_post_order( $post_id ) ); return apply_filters( 'sportspress_column_admin_columns', $columns );
break; }
case 'sp_description':
global $post; /**
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>'; * Define our custom columns shown in admin.
break; *
endswitch; * @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_key':
global $post;
echo esc_html( $post->post_name );
break;
case 'sp_equation':
echo wp_kses_post( sp_get_post_equation( $post_id ) );
break;
case 'sp_precision':
echo esc_html( sp_get_post_precision( $post_id ) );
break;
case 'sp_order':
echo esc_html( sp_get_post_order( $post_id ) );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
} }
}
endif; endif;

View File

@@ -2,217 +2,235 @@
/** /**
* Admin functions for the events post type * Admin functions for the events post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Event' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Event' ) ) :
/**
* SP_Admin_CPT_Event Class
*/
class SP_Admin_CPT_Event extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Event Class
*/ */
public function __construct() { class SP_Admin_CPT_Event extends SP_Admin_CPT {
$this->type = 'sp_event';
// Post title fields /**
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 ); * Constructor
*/
public function __construct() {
$this->type = 'sp_event';
// Empty data filter // Post title fields
add_filter( 'wp_insert_post_empty_content', array( $this, 'wp_insert_post_empty_content' ), 99, 2 ); add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
// Before data updates // Empty data filter
add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ), 99, 2 ); add_filter( 'wp_insert_post_empty_content', array( $this, 'wp_insert_post_empty_content' ), 99, 2 );
// Admin Columns // Before data updates
add_filter( 'manage_edit-sp_event_columns', array( $this, 'edit_columns' ) ); add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ), 99, 2 );
add_filter( 'manage_edit-sp_event_sortable_columns', array( $this, 'sortable_columns' ) );
add_action( 'pre_get_posts', array( $this, 'orderby_columns' ) );
add_action( 'manage_sp_event_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Filtering // Admin Columns
add_action( 'restrict_manage_posts', array( $this, 'filters' ) ); add_filter( 'manage_edit-sp_event_columns', array( $this, 'edit_columns' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) ); add_filter( 'manage_edit-sp_event_sortable_columns', array( $this, 'sortable_columns' ) );
add_action( 'pre_get_posts', array( $this, 'orderby_columns' ) );
add_action( 'manage_sp_event_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Post states // Filtering
add_filter( 'display_post_states', array( $this, 'post_states' ), 10, 2 ); add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/** // Post states
* Change title boxes in admin. add_filter( 'display_post_states', array( $this, 'post_states' ), 10, 2 );
* @param string $text
* @param object $post
* @return string
*/
public function enter_title_here( $text, $post ) {
if ( $post->post_type == 'sp_event' )
return __( '(Auto)', 'sportspress' );
return $text; // Call SP_Admin_CPT constructor
} parent::__construct();
}
/** /**
* Mark as not empty when saving event if teams are selected for auto title. * Change title boxes in admin.
* *
* @param array $maybe_empty * @param string $text
* @param array $postarr * @param object $post
* @return bool * @return string
*/ */
public function wp_insert_post_empty_content( $maybe_empty, $postarr ) { public function enter_title_here( $text, $post ) {
if ( $maybe_empty && 'sp_event' === sp_array_value( $postarr, 'post_type' ) ): if ( $post->post_type == 'sp_event' ) {
$teams = sp_array_value( $postarr, 'sp_team', array() ); return __( '(Auto)', 'sportspress' );
$teams = array_filter( $teams );
if ( sizeof( $teams ) ) return false;
endif;
return $maybe_empty;
}
/**
* Auto-generate an event title based on the team playing if left blank.
*
* @param array $data
* @param array $postarr
* @return array
*/
public function wp_insert_post_data( $data, $postarr ) {
if ( $data['post_type'] == 'sp_event' && $data['post_title'] == '' ):
$teams = sp_array_value( $postarr, 'sp_team', array() );
$teams = array_filter( $teams );
$team_names = array();
foreach ( $teams as $team ):
while ( is_array( $team ) ) {
$team = array_shift( array_filter( $team ) );
}
if ( $team > 0 ) $team_names[] = sp_team_short_name( $team );
endforeach;
$team_names = array_unique( $team_names );
$reverse_teams = get_option( 'sportspress_event_reverse_teams', 'no' ) === 'yes' ? true : false;
if ( $reverse_teams ) {
$team_names = array_reverse( $team_names );
} }
$data['post_title'] = implode( ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ', $team_names ); return $text;
endif;
return $data;
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['comments'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'sp_format' => '<span class="dashicons sp-icon-calendar sp-tip" title="' . __( 'Format', 'sportspress' ) . '"></span>',
'title' => null,
'date' => __( 'Date', 'sportspress' ),
'sp_time' => __( 'Time', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_day' => __( 'Match Day', 'sportspress' ),
), $existing_columns, array(
'title' => __( 'Event', 'sportspress' ),
) );
return apply_filters( 'sportspress_event_admin_columns', $columns );
}
/**
* Change the sortable columns in admin.
*/
public function sortable_columns( $columns ) {
$columns['sp_day'] = 'sp_day';
return $columns;
}
/**
* Define the sortable columns in admin.
*/
public function orderby_columns( $query ) {
if ( ! is_admin() ) return;
$orderby = $query->get( 'orderby');
if ( 'sp_day' == $orderby ) {
$query->set( 'meta_key','sp_day' );
$query->set( 'orderby','meta_value_num' );
} }
}
/** /**
* Define our custom columns shown in admin. * Mark as not empty when saving event if teams are selected for auto title.
* @param string $column *
*/ * @param array $maybe_empty
public function custom_columns( $column, $post_id ) { * @param array $postarr
switch ( $column ): * @return bool
case 'sp_format': */
$format = get_post_meta( $post_id, 'sp_format', true ); public function wp_insert_post_empty_content( $maybe_empty, $postarr ) {
$formats = new SP_Formats(); if ( $maybe_empty && 'sp_event' === sp_array_value( $postarr, 'post_type' ) ) :
$event_formats = $formats->event; $teams = sp_array_value( $postarr, 'sp_team', array() );
if ( array_key_exists( $format, $event_formats ) ):
echo '<span class="dashicons sp-icon-' . $format . ' sp-tip" title="' . $event_formats[ $format ] . '"></span>';
endif;
break;
case 'sp_time':
echo apply_filters( 'sportspress_event_time_admin', get_post_time( 'H:i', false, $post_id, true ) );
break;
case 'sp_team':
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams ); $teams = array_filter( $teams );
$teams = array_unique( $teams ); if ( sizeof( $teams ) ) {
return false;
}
endif;
return $maybe_empty;
}
/**
* Auto-generate an event title based on the team playing if left blank.
*
* @param array $data
* @param array $postarr
* @return array
*/
public function wp_insert_post_data( $data, $postarr ) {
if ( $data['post_type'] == 'sp_event' && $data['post_title'] == '' ) :
$teams = sp_array_value( $postarr, 'sp_team', array() );
$teams = array_filter( $teams );
$team_names = array();
foreach ( $teams as $team ) :
while ( is_array( $team ) ) {
$team = array_shift( array_filter( $team ) );
}
if ( $team > 0 ) {
$team_names[] = sp_team_short_name( $team );
}
endforeach;
$team_names = array_unique( $team_names );
$reverse_teams = get_option( 'sportspress_event_reverse_teams', 'no' ) === 'yes' ? true : false; $reverse_teams = get_option( 'sportspress_event_reverse_teams', 'no' ) === 'yes' ? true : false;
if ( $reverse_teams ) { if ( $reverse_teams ) {
$teams = array_reverse( $teams , true ); $team_names = array_reverse( $team_names );
} }
if ( empty( $teams ) ):
echo '&mdash;'; $data['post_title'] = implode( ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ', $team_names );
else:
$results = get_post_meta( $post_id, 'sp_results', true ); endif;
$main_result = get_option( 'sportspress_primary_result', null );
echo '<input type="hidden" name="sp_post_id" value="' . $post_id . '">'; return $data;
echo '<div class="sp-results">'; }
foreach( $teams as $team_id ):
if ( ! $team_id ) continue; /**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['comments'] );
$columns = array_merge(
array(
'cb' => '<input type="checkbox" />',
'sp_format' => '<span class="dashicons sp-icon-calendar sp-tip" title="' . __( 'Format', 'sportspress' ) . '"></span>',
'title' => null,
'date' => __( 'Date', 'sportspress' ),
'sp_time' => __( 'Time', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_day' => __( 'Match Day', 'sportspress' ),
),
$existing_columns,
array(
'title' => __( 'Event', 'sportspress' ),
)
);
return apply_filters( 'sportspress_event_admin_columns', $columns );
}
/**
* Change the sortable columns in admin.
*/
public function sortable_columns( $columns ) {
$columns['sp_day'] = 'sp_day';
return $columns;
}
/**
* Define the sortable columns in admin.
*/
public function orderby_columns( $query ) {
if ( ! is_admin() ) {
return;
}
$orderby = $query->get( 'orderby' );
if ( 'sp_day' == $orderby ) {
$query->set( 'meta_key', 'sp_day' );
$query->set( 'orderby', 'meta_value_num' );
}
}
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_format':
$format = get_post_meta( $post_id, 'sp_format', true );
$formats = new SP_Formats();
$event_formats = $formats->event;
if ( array_key_exists( $format, $event_formats ) ) :
echo '<span class="dashicons sp-icon-' . $format . ' sp-tip" title="' . $event_formats[ $format ] . '"></span>';
endif;
break;
case 'sp_time':
echo apply_filters( 'sportspress_event_time_admin', get_post_time( 'H:i', false, $post_id, true ) );
break;
case 'sp_team':
$teams = (array) get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
$teams = array_unique( $teams );
$reverse_teams = get_option( 'sportspress_event_reverse_teams', 'no' ) === 'yes' ? true : false;
if ( $reverse_teams ) {
$teams = array_reverse( $teams, true );
}
if ( empty( $teams ) ) :
echo '&mdash;';
else :
$results = get_post_meta( $post_id, 'sp_results', true );
$main_result = get_option( 'sportspress_primary_result', null );
echo '<input type="hidden" name="sp_post_id" value="' . $post_id . '">';
echo '<div class="sp-results">';
foreach ( $teams as $team_id ) :
if ( ! $team_id ) {
continue;
}
$team = get_post( $team_id ); $team = get_post( $team_id );
if ( $team ): if ( $team ) :
$team_results = sportspress_array_value( $results, $team_id, null ); $team_results = sportspress_array_value( $results, $team_id, null );
if ( $main_result ): if ( $main_result ) :
$team_result = sportspress_array_value( $team_results, $main_result, null ); $team_result = sportspress_array_value( $team_results, $main_result, null );
else: else :
if ( is_array( $team_results ) ): if ( is_array( $team_results ) ) :
end( $team_results ); end( $team_results );
$team_result = prev( $team_results ); $team_result = prev( $team_results );
$main_result = key( $team_results ); $main_result = key( $team_results );
else: else :
$team_result = null; $team_result = null;
endif; endif;
endif; endif;
if ( is_array( $team_results ) ): if ( is_array( $team_results ) ) :
unset( $team_results['outcome'] ); unset( $team_results['outcome'] );
$team_results = array_filter( $team_results, 'sp_filter_non_empty' ); $team_results = array_filter( $team_results, 'sp_filter_non_empty' );
$team_results = implode( ' | ', $team_results ); $team_results = implode( ' | ', $team_results );
@@ -223,129 +241,134 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT {
echo esc_html( $team->post_title ); echo esc_html( $team->post_title );
echo '<br>'; echo '<br>';
endif; endif;
endforeach; endforeach;
echo '</div>'; echo '</div>';
if ( current_user_can( 'edit_others_sp_events' ) ) { if ( current_user_can( 'edit_others_sp_events' ) ) {
?> ?>
<div class="row-actions sp-row-actions"><span class="inline hide-if-no-js"><a href="#" class="sp-edit-results"><?php _e( 'Edit Results', 'sportspress' ); ?></a></span></div> <div class="row-actions sp-row-actions"><span class="inline hide-if-no-js"><a href="#" class="sp-edit-results"><?php _e( 'Edit Results', 'sportspress' ); ?></a></span></div>
<p class="inline-edit-save sp-inline-edit-save hidden"> <p class="inline-edit-save sp-inline-edit-save hidden">
<a href="#inline-edit" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></a> <a href="#inline-edit" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></a>
<a href="#inline-edit" class="button-primary save alignright"><?php _e( 'Update' ); ?></a> <a href="#inline-edit" class="button-primary save alignright"><?php _e( 'Update' ); ?></a>
</p> </p>
<?php <?php
}
endif;
break;
case 'sp_league':
echo get_the_terms( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;';
break;
case 'sp_season':
echo get_the_terms( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;';
break;
case 'sp_venue':
echo get_the_terms( $post_id, 'sp_venue' ) ? the_terms( $post_id, 'sp_venue' ) : '&mdash;';
break;
case 'sp_day':
$day = get_post_meta( $post_id, 'sp_day', true );
if ( '' === $day ) {
$day = __( 'Default', 'sportspress' );
} }
endif; echo esc_html( $day );
break; break;
case 'sp_league': endswitch;
echo get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;';
break;
case 'sp_season':
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;';
break;
case 'sp_venue':
echo get_the_terms ( $post_id, 'sp_venue' ) ? the_terms( $post_id, 'sp_venue' ) : '&mdash;';
break;
case 'sp_day':
$day = get_post_meta ( $post_id, 'sp_day', true );
if ( '' === $day ) $day = __( 'Default', 'sportspress' );
echo esc_html( $day );
break;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_event' )
return;
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_REQUEST['team'] ) : null;
$args = array(
'post_type' => 'sp_team',
'name' => 'team',
'show_option_none' => __( 'Show all teams', 'sportspress' ),
'selected' => $selected,
'values' => 'ID',
);
wp_dropdown_pages( $args );
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['match_day'] ) ? sanitize_text_field( $_REQUEST['match_day'] ) : null;
echo '<input name="match_day" type="text" class="sp-tablenav-input" placeholder="' . __( 'Match Day', 'sportspress' ) . '" value="' . $selected . '">';
if ( current_user_can( 'edit_others_sp_events' ) )
wp_nonce_field( 'sp-save-inline-results', 'sp-inline-nonce', false );
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
if ( $typenow == 'sp_event' ) {
//Avoid overriding relation operator if already set
if ( !isset( $query->query_vars['meta_query']['relation'] ) )
$query->query_vars['meta_query']['relation'] = 'AND';
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_query'][] = array(
'key' => 'sp_team',
'value' => $_GET['team'],
);
} }
if ( ! empty( $_GET['match_day'] ) ) { /**
$query->query_vars['meta_query'][] = array( * Show a category filter box
'key' => 'sp_day', */
'value' => $_GET['match_day'], public function filters() {
); global $typenow, $wp_query;
if ( $typenow != 'sp_event' ) {
return;
}
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_REQUEST['team'] ) : null;
$args = array(
'post_type' => 'sp_team',
'name' => 'team',
'show_option_none' => __( 'Show all teams', 'sportspress' ),
'selected' => $selected,
'values' => 'ID',
);
wp_dropdown_pages( $args );
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['match_day'] ) ? sanitize_text_field( $_REQUEST['match_day'] ) : null;
echo '<input name="match_day" type="text" class="sp-tablenav-input" placeholder="' . __( 'Match Day', 'sportspress' ) . '" value="' . $selected . '">';
if ( current_user_can( 'edit_others_sp_events' ) ) {
wp_nonce_field( 'sp-save-inline-results', 'sp-inline-nonce', false );
}
} }
}
}
/** /**
* Replace displayed post state for events * Filter in admin based on options
* *
* @param array $post_states * @param mixed $query
* @param object $post */
*/ public function filters_query( $query ) {
public function post_states( $post_states, $post ) { global $typenow, $wp_query;
$status = get_post_meta( $post->ID, 'sp_status', true );
if ( 'postponed' == $status ) { if ( $typenow == 'sp_event' ) {
$post_states = array( __( 'Postponed', 'sportspress' ) ); // Avoid overriding relation operator if already set
} elseif ( 'cancelled' == $status ) { if ( ! isset( $query->query_vars['meta_query']['relation'] ) ) {
$post_states = array( __( 'Canceled', 'sportspress' ) ); $query->query_vars['meta_query']['relation'] = 'AND';
} elseif ( 'tbd' == $status ) { }
$post_states = array( __( 'TBD', 'sportspress' ) );
}
return $post_states; if ( ! empty( $_GET['team'] ) ) {
} $query->query_vars['meta_query'][] = array(
} 'key' => 'sp_team',
'value' => $_GET['team'],
);
}
if ( ! empty( $_GET['match_day'] ) ) {
$query->query_vars['meta_query'][] = array(
'key' => 'sp_day',
'value' => $_GET['match_day'],
);
}
}
}
/**
* Replace displayed post state for events
*
* @param array $post_states
* @param object $post
*/
public function post_states( $post_states, $post ) {
$status = get_post_meta( $post->ID, 'sp_status', true );
if ( 'postponed' == $status ) {
$post_states = array( __( 'Postponed', 'sportspress' ) );
} elseif ( 'cancelled' == $status ) {
$post_states = array( __( 'Canceled', 'sportspress' ) );
} elseif ( 'tbd' == $status ) {
$post_states = array( __( 'TBD', 'sportspress' ) );
}
return $post_states;
}
}
endif; endif;

View File

@@ -2,154 +2,166 @@
/** /**
* Admin functions for the player lists post type * Admin functions for the player lists post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_List' ) ) : if ( ! class_exists( 'SP_Admin_CPT_List' ) ) :
/**
* SP_Admin_CPT_List Class
*/
class SP_Admin_CPT_List extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_List Class
*/ */
public function __construct() { class SP_Admin_CPT_List extends SP_Admin_CPT {
$this->type = 'sp_list';
// Admin Columns /**
add_filter( 'manage_edit-sp_list_columns', array( $this, 'edit_columns' ) ); * Constructor
add_action( 'manage_sp_list_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); */
public function __construct() {
$this->type = 'sp_list';
// Filtering // Admin Columns
add_action( 'restrict_manage_posts', array( $this, 'filters' ) ); add_filter( 'manage_edit-sp_list_columns', array( $this, 'edit_columns' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) ); add_action( 'manage_sp_list_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/** // Filtering
* Change the columns shown in admin. add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
*/ add_filter( 'parse_query', array( $this, 'filters_query' ) );
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_team' => __( 'Team', 'sportspress' ),
'sp_player' => __( 'Players', 'sportspress' ),
'sp_layout' => __( 'Layout', 'sportspress' ),
), $existing_columns );
return apply_filters( 'sportspress_list_admin_columns', $columns );
}
/** // Call SP_Admin_CPT constructor
* Define our custom columns shown in admin. parent::__construct();
* @param string $column }
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_player':
$select = get_post_meta( $post_id, 'sp_select', true );
if ( 'manual' == $select ):
$players = array_filter( get_post_meta( $post_id, 'sp_player' ) );
echo sizeof( $players );
else:
_e( 'Auto', 'sportspress' );
endif;
break;
case 'sp_league':
echo get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : __( 'All', 'sportspress' );
break;
case 'sp_season':
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : __( 'All', 'sportspress' );
break;
case 'sp_team':
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
if ( empty( $teams ) ):
echo __( 'All', 'sportspress' );
else:
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
if ( $team ) echo esc_html( $team->post_title ) . '<br>';
endforeach;
endif;
break;
case 'sp_layout':
echo esc_html( sp_array_value( SP()->formats->list, get_post_meta( $post_id, 'sp_format', true ), '&mdash;' ) );
break;
endswitch;
}
/** /**
* Show a category filter box * Change the columns shown in admin.
*/ */
public function filters() { public function edit_columns( $existing_columns ) {
global $typenow, $wp_query; unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge(
array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_team' => __( 'Team', 'sportspress' ),
'sp_player' => __( 'Players', 'sportspress' ),
'sp_layout' => __( 'Layout', 'sportspress' ),
),
$existing_columns
);
return apply_filters( 'sportspress_list_admin_columns', $columns );
}
if ( $typenow != 'sp_list' ) /**
return; * Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_player':
$select = get_post_meta( $post_id, 'sp_select', true );
if ( 'manual' == $select ) :
$players = array_filter( get_post_meta( $post_id, 'sp_player' ) );
echo sizeof( $players );
else :
_e( 'Auto', 'sportspress' );
endif;
break;
case 'sp_league':
echo get_the_terms( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : __( 'All', 'sportspress' );
break;
case 'sp_season':
echo get_the_terms( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : __( 'All', 'sportspress' );
break;
case 'sp_team':
$teams = (array) get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
if ( empty( $teams ) ) :
echo __( 'All', 'sportspress' );
else :
foreach ( $teams as $team_id ) :
if ( ! $team_id ) {
continue;
}
$team = get_post( $team_id );
if ( $team ) {
echo esc_html( $team->post_title ) . '<br>';
}
endforeach;
endif;
break;
case 'sp_layout':
echo esc_html( sp_array_value( SP()->formats->list, get_post_meta( $post_id, 'sp_format', true ), '&mdash;' ) );
break;
endswitch;
}
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null; /**
$args = array( * Show a category filter box
'show_option_all' => __( 'Show all leagues', 'sportspress' ), */
'taxonomy' => 'sp_league', public function filters() {
'name' => 'sp_league', global $typenow, $wp_query;
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null; if ( $typenow != 'sp_list' ) {
$args = array( return;
'show_option_all' => __( 'Show all seasons', 'sportspress' ), }
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_REQUEST['team'] ) : null; $selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array( $args = array(
'post_type' => 'sp_team', 'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'name' => 'team', 'taxonomy' => 'sp_league',
'show_option_none' => __( 'Show all teams', 'sportspress' ), 'name' => 'sp_league',
'selected' => $selected, 'selected' => $selected,
'values' => 'ID', );
); sp_dropdown_taxonomies( $args );
wp_dropdown_pages( $args );
}
/** $selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
* Filter in admin based on options $args = array(
* 'show_option_all' => __( 'Show all seasons', 'sportspress' ),
* @param mixed $query 'taxonomy' => 'sp_season',
*/ 'name' => 'sp_season',
public function filters_query( $query ) { 'selected' => $selected,
global $typenow, $wp_query; );
sp_dropdown_taxonomies( $args );
if ( $typenow == 'sp_list' ) { $selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_REQUEST['team'] ) : null;
$args = array(
'post_type' => 'sp_team',
'name' => 'team',
'show_option_none' => __( 'Show all teams', 'sportspress' ),
'selected' => $selected,
'values' => 'ID',
);
wp_dropdown_pages( $args );
}
if ( ! empty( $_GET['team'] ) ) { /**
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] ); * Filter in admin based on options
$query->query_vars['meta_key'] = 'sp_team'; *
} * @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
if ( $typenow == 'sp_list' ) {
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
}
}
} }
} }
}
endif; endif;

View File

@@ -2,68 +2,72 @@
/** /**
* Admin functions for the columns post type * Admin functions for the columns post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Metric' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Metric' ) ) :
/**
* SP_Admin_CPT_Metric Class
*/
class SP_Admin_CPT_Metric extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Metric Class
*/ */
public function __construct() { class SP_Admin_CPT_Metric extends SP_Admin_CPT {
$this->type = 'sp_metric';
// Admin Columns /**
add_filter( 'manage_edit-sp_metric_columns', array( $this, 'edit_columns' ) ); * Constructor
add_action( 'manage_sp_metric_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); */
public function __construct() {
// Call SP_Admin_CPT constructor $this->type = 'sp_metric';
parent::__construct();
}
/** // Admin Columns
* Change the columns shown in admin. add_filter( 'manage_edit-sp_metric_columns', array( $this, 'edit_columns' ) );
*/ add_action( 'manage_sp_metric_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Variable', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_metric_admin_columns', $columns );
}
/** // Call SP_Admin_CPT constructor
* Define our custom columns shown in admin. parent::__construct();
* @param string $column }
*/
public function custom_columns( $column, $post_id ) { /**
switch ( $column ): * Change the columns shown in admin.
case 'sp_key': */
global $post; public function edit_columns( $existing_columns ) {
echo esc_html( $post->post_name ); $columns = array(
break; 'cb' => '<input type="checkbox" />',
case 'sp_description': 'title' => __( 'Label', 'sportspress' ),
global $post; 'sp_key' => __( 'Variable', 'sportspress' ),
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>'; 'sp_description' => __( 'Description', 'sportspress' ),
break; );
endswitch; return apply_filters( 'sportspress_metric_admin_columns', $columns );
}
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_key':
global $post;
echo esc_html( $post->post_name );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
} }
}
endif; endif;

View File

@@ -2,51 +2,56 @@
/** /**
* Admin functions for the officials post type * Admin functions for the officials post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.5.1 * @version 2.5.1
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Official' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Official' ) ) :
/**
* SP_Admin_CPT_Official Class
*/
class SP_Admin_CPT_Official extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Official Class
*/ */
public function __construct() { class SP_Admin_CPT_Official extends SP_Admin_CPT {
$this->type = 'sp_official';
// Post title fields /**
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 ); * Constructor
*/
public function __construct() {
$this->type = 'sp_official';
// Call SP_Admin_CPT constructor // Post title fields
parent::__construct(); add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Change title boxes in admin.
*
* @param string $text
* @param object $post
* @return string
*/
public function enter_title_here( $text, $post ) {
if ( $post->post_type == 'sp_official' ) {
return __( 'Name', 'sportspress' );
}
return $text;
}
} }
/**
* Change title boxes in admin.
* @param string $text
* @param object $post
* @return string
*/
public function enter_title_here( $text, $post ) {
if ( $post->post_type == 'sp_official' )
return __( 'Name', 'sportspress' );
return $text;
}
}
endif; endif;
return new SP_Admin_CPT_Official(); return new SP_Admin_CPT_Official();

View File

@@ -2,73 +2,77 @@
/** /**
* Admin functions for the outcomes post type * Admin functions for the outcomes post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Outcome' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Outcome' ) ) :
/**
* SP_Admin_CPT_Outcome Class
*/
class SP_Admin_CPT_Outcome extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Outcome Class
*/ */
public function __construct() { class SP_Admin_CPT_Outcome extends SP_Admin_CPT {
$this->type = 'sp_outcome';
// Admin Columns /**
add_filter( 'manage_edit-sp_outcome_columns', array( $this, 'edit_columns' ) ); * Constructor
add_action( 'manage_sp_outcome_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); */
public function __construct() {
// Call SP_Admin_CPT constructor $this->type = 'sp_outcome';
parent::__construct();
}
/** // Admin Columns
* Change the columns shown in admin. add_filter( 'manage_edit-sp_outcome_columns', array( $this, 'edit_columns' ) );
*/ add_action( 'manage_sp_outcome_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Variable', 'sportspress' ),
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_outcome_admin_columns', $columns );
}
/** // Call SP_Admin_CPT constructor
* Define our custom columns shown in admin. parent::__construct();
* @param string $column }
*/
public function custom_columns( $column, $post_id ) { /**
switch ( $column ): * Change the columns shown in admin.
case 'sp_key': */
global $post; public function edit_columns( $existing_columns ) {
echo esc_html( $post->post_name ); $columns = array(
break; 'cb' => '<input type="checkbox" />',
case 'sp_abbreviation': 'title' => __( 'Label', 'sportspress' ),
global $post; 'sp_key' => __( 'Variable', 'sportspress' ),
echo esc_html( sp_get_post_abbreviation( $post->ID ) ); 'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
break; 'sp_description' => __( 'Description', 'sportspress' ),
case 'sp_description': );
global $post; return apply_filters( 'sportspress_outcome_admin_columns', $columns );
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>'; }
break;
endswitch; /**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_key':
global $post;
echo esc_html( $post->post_name );
break;
case 'sp_abbreviation':
global $post;
echo esc_html( sp_get_post_abbreviation( $post->ID ) );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
} }
}
endif; endif;

View File

@@ -2,82 +2,86 @@
/** /**
* Admin functions for the performance post type * Admin functions for the performance post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Performance' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Performance' ) ) :
/**
* SP_Admin_CPT_Performance Class
*/
class SP_Admin_CPT_Performance extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Performance Class
*/ */
public function __construct() { class SP_Admin_CPT_Performance extends SP_Admin_CPT {
$this->type = 'sp_performance';
// Admin Columns /**
add_filter( 'manage_edit-sp_performance_columns', array( $this, 'edit_columns' ) ); * Constructor
add_action( 'manage_sp_performance_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); */
public function __construct() {
// Call SP_Admin_CPT constructor $this->type = 'sp_performance';
parent::__construct();
}
/** // Admin Columns
* Change the columns shown in admin. add_filter( 'manage_edit-sp_performance_columns', array( $this, 'edit_columns' ) );
*/ add_action( 'manage_sp_performance_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'sp_icon' => __( 'Icon', 'sportspress' ),
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Variable', 'sportspress' ),
'sp_section' => __( 'Category', 'sportspress' ),
'sp_config_format' => __( 'Format', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_performance_admin_columns', $columns );
}
/** // Call SP_Admin_CPT constructor
* Define our custom columns shown in admin. parent::__construct();
* @param string $column }
*/
public function custom_columns( $column, $post_id ) { /**
switch ( $column ): * Change the columns shown in admin.
case 'sp_icon': */
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : ''; public function edit_columns( $existing_columns ) {
break; $columns = array(
case 'sp_key': 'cb' => '<input type="checkbox" />',
global $post; 'sp_icon' => __( 'Icon', 'sportspress' ),
echo esc_html( $post->post_name ); 'title' => __( 'Label', 'sportspress' ),
break; 'sp_key' => __( 'Variable', 'sportspress' ),
case 'sp_section': 'sp_section' => __( 'Category', 'sportspress' ),
global $post; 'sp_config_format' => __( 'Format', 'sportspress' ),
echo esc_html( sp_get_post_section( $post->ID ) ); 'sp_description' => __( 'Description', 'sportspress' ),
break; );
case 'sp_config_format': return apply_filters( 'sportspress_performance_admin_columns', $columns );
global $post; }
echo esc_html( sp_get_post_format( $post->ID ) );
break; /**
case 'sp_description': * Define our custom columns shown in admin.
global $post; *
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>'; * @param string $column
break; */
endswitch; public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_icon':
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : '';
break;
case 'sp_key':
global $post;
echo esc_html( $post->post_name );
break;
case 'sp_section':
global $post;
echo esc_html( sp_get_post_section( $post->ID ) );
break;
case 'sp_config_format':
global $post;
echo esc_html( sp_get_post_format( $post->ID ) );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
} }
}
endif; endif;

View File

@@ -2,226 +2,245 @@
/** /**
* Admin functions for the players post type * Admin functions for the players post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Player' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Player' ) ) :
/**
* SP_Admin_CPT_Player Class
*/
class SP_Admin_CPT_Player extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Player Class
*/ */
public function __construct() { class SP_Admin_CPT_Player extends SP_Admin_CPT {
$this->type = 'sp_player';
// Post title fields /**
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 ); * Constructor
*/
public function __construct() {
$this->type = 'sp_player';
// Admin columns // Post title fields
add_filter( 'manage_edit-sp_player_columns', array( $this, 'edit_columns' ) ); add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
add_action( 'manage_sp_player_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Filtering // Admin columns
add_action( 'restrict_manage_posts', array( $this, 'filters' ) ); add_filter( 'manage_edit-sp_player_columns', array( $this, 'edit_columns' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) ); add_action( 'manage_sp_player_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Quick edit // Filtering
add_action( 'quick_edit_custom_box', array( $this, 'quick_edit_number' ), 10, 2 ); add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_action( 'quick_edit_custom_box', array( $this, 'quick_edit_teams' ), 10, 2 ); add_filter( 'parse_query', array( $this, 'filters_query' ) );
add_action( 'save_post', array( $this, 'quick_save' ) );
// Bulk edit
add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit_teams' ), 10, 2 );
add_action( 'wp_ajax_save_bulk_edit_sp_player', array( $this, 'bulk_save' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/** // Quick edit
* Change title boxes in admin. add_action( 'quick_edit_custom_box', array( $this, 'quick_edit_number' ), 10, 2 );
* @param string $text add_action( 'quick_edit_custom_box', array( $this, 'quick_edit_teams' ), 10, 2 );
* @param object $post add_action( 'save_post', array( $this, 'quick_save' ) );
* @return string
*/
public function enter_title_here( $text, $post ) {
if ( $post->post_type == 'sp_player' )
return __( 'Name', 'sportspress' );
return $text; // Bulk edit
} add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit_teams' ), 10, 2 );
add_action( 'wp_ajax_save_bulk_edit_sp_player', array( $this, 'bulk_save' ) );
/** // Call SP_Admin_CPT constructor
* Change the columns shown in admin. parent::__construct();
*/ }
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'sp_number' => '<span class="dashicons sp-icon-tshirt sp-tip" title="' . __( 'Squad Number', 'sportspress' ) . '"></span>',
'title' => null,
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
), $existing_columns, array(
'title' => __( 'Name', 'sportspress' )
) );
return apply_filters( 'sportspress_player_admin_columns', $columns );
}
/** /**
* Define our custom columns shown in admin. * Change title boxes in admin.
* @param string $column *
*/ * @param string $text
public function custom_columns( $column, $post_id ) { * @param object $post
switch ( $column ): * @return string
case 'sp_number': */
echo esc_html( get_post_meta ( $post_id, 'sp_number', true ) ); public function enter_title_here( $text, $post ) {
break; if ( $post->post_type == 'sp_player' ) {
case 'sp_position': return __( 'Name', 'sportspress' );
echo get_the_terms( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '&mdash;';
break;
case 'sp_team':
$current_teams = get_post_meta( $post_id, 'sp_current_team', false );
$past_teams = get_post_meta( $post_id, 'sp_past_team', false );
$current_teams = array_filter( $current_teams );
$past_teams = array_filter( $past_teams );
echo '<span class="hidden sp-player-teams" data-current-teams="' . implode( ',', $current_teams ) . '" data-past-teams="' . implode( ',', $past_teams ) . '"></span>';
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
$teams = array_unique( $teams );
if ( empty( $teams ) ):
echo '&mdash;';
else:
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
if ( $team ):
echo esc_html( $team->post_title );
if ( in_array( $team_id, $current_teams ) ):
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
endif;
echo '<br>';
endif;
endforeach;
endif;
break;
case 'sp_league':
echo get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;';
break;
case 'sp_season':
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;';
break;
case 'sp_venue':
echo get_the_terms ( $post_id, 'sp_venue' ) ? the_terms( $post_id, 'sp_venue' ) : '&mdash;';
break;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_player' )
return;
if ( taxonomy_exists( 'sp_position' ) ):
$selected = isset( $_REQUEST['sp_position'] ) ? sanitize_key( $_REQUEST['sp_position'] ) : null;
$args = array(
'show_option_all' => __( 'Show all positions', 'sportspress' ),
'taxonomy' => 'sp_position',
'name' => 'sp_position',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
endif;
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_REQUEST['team'] ) : null;
$args = array(
'post_type' => 'sp_team',
'name' => 'team',
'show_option_none' => __( 'Show all teams', 'sportspress' ),
'selected' => $selected,
'values' => 'ID',
);
wp_dropdown_pages( $args );
if ( taxonomy_exists( 'sp_league' ) ):
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
endif;
if ( taxonomy_exists( 'sp_season' ) ):
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
endif;
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
if ( empty ( $query->query_vars['post_type'] ) || $query->query_vars['post_type'] !== 'sp_player' ) return $query;
global $typenow, $wp_query;
if ( $typenow == 'sp_player' ) {
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
} }
return $text;
} }
return $query; /**
} * Change the columns shown in admin.
*/
/** public function edit_columns( $existing_columns ) {
* Quick edit squad number unset( $existing_columns['author'], $existing_columns['date'] );
* $columns = array_merge(
* @param string $column_name array(
* @param string $post_type 'cb' => '<input type="checkbox" />',
*/ 'sp_number' => '<span class="dashicons sp-icon-tshirt sp-tip" title="' . __( 'Squad Number', 'sportspress' ) . '"></span>',
public function quick_edit_number( $column_name, $post_type ) { 'title' => null,
if ( $this->type !== $post_type ) return; 'sp_position' => __( 'Positions', 'sportspress' ),
if ( 'sp_number' !== $column_name ) return; 'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
static $print_nonce = true; 'sp_season' => __( 'Seasons', 'sportspress' ),
if ( $print_nonce ) { ),
$print_nonce = false; $existing_columns,
wp_nonce_field( plugin_basename( __FILE__ ), 'sp_player_edit_nonce' ); array(
'title' => __( 'Name', 'sportspress' ),
)
);
return apply_filters( 'sportspress_player_admin_columns', $columns );
} }
?>
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_number':
echo esc_html( get_post_meta( $post_id, 'sp_number', true ) );
break;
case 'sp_position':
echo get_the_terms( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '&mdash;';
break;
case 'sp_team':
$current_teams = get_post_meta( $post_id, 'sp_current_team', false );
$past_teams = get_post_meta( $post_id, 'sp_past_team', false );
$current_teams = array_filter( $current_teams );
$past_teams = array_filter( $past_teams );
echo '<span class="hidden sp-player-teams" data-current-teams="' . implode( ',', $current_teams ) . '" data-past-teams="' . implode( ',', $past_teams ) . '"></span>';
$teams = (array) get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
$teams = array_unique( $teams );
if ( empty( $teams ) ) :
echo '&mdash;';
else :
foreach ( $teams as $team_id ) :
if ( ! $team_id ) {
continue;
}
$team = get_post( $team_id );
if ( $team ) :
echo esc_html( $team->post_title );
if ( in_array( $team_id, $current_teams ) ) :
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
endif;
echo '<br>';
endif;
endforeach;
endif;
break;
case 'sp_league':
echo get_the_terms( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;';
break;
case 'sp_season':
echo get_the_terms( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;';
break;
case 'sp_venue':
echo get_the_terms( $post_id, 'sp_venue' ) ? the_terms( $post_id, 'sp_venue' ) : '&mdash;';
break;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_player' ) {
return;
}
if ( taxonomy_exists( 'sp_position' ) ) :
$selected = isset( $_REQUEST['sp_position'] ) ? sanitize_key( $_REQUEST['sp_position'] ) : null;
$args = array(
'show_option_all' => __( 'Show all positions', 'sportspress' ),
'taxonomy' => 'sp_position',
'name' => 'sp_position',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
endif;
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_REQUEST['team'] ) : null;
$args = array(
'post_type' => 'sp_team',
'name' => 'team',
'show_option_none' => __( 'Show all teams', 'sportspress' ),
'selected' => $selected,
'values' => 'ID',
);
wp_dropdown_pages( $args );
if ( taxonomy_exists( 'sp_league' ) ) :
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
endif;
if ( taxonomy_exists( 'sp_season' ) ) :
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
endif;
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
if ( empty( $query->query_vars['post_type'] ) || $query->query_vars['post_type'] !== 'sp_player' ) {
return $query;
}
global $typenow, $wp_query;
if ( $typenow == 'sp_player' ) {
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
}
}
return $query;
}
/**
* Quick edit squad number
*
* @param string $column_name
* @param string $post_type
*/
public function quick_edit_number( $column_name, $post_type ) {
if ( $this->type !== $post_type ) {
return;
}
if ( 'sp_number' !== $column_name ) {
return;
}
static $print_nonce = true;
if ( $print_nonce ) {
$print_nonce = false;
wp_nonce_field( plugin_basename( __FILE__ ), 'sp_player_edit_nonce' );
}
?>
<fieldset class="inline-edit-col-right"> <fieldset class="inline-edit-col-right">
<div class="inline-edit-col"> <div class="inline-edit-col">
<label> <label>
@@ -230,27 +249,35 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
</label> </label>
</div> </div>
</fieldset> </fieldset>
<?php <?php
} }
/** /**
* Quick edit teams * Quick edit teams
* *
* @param string $column_name * @param string $column_name
* @param string $post_type * @param string $post_type
*/ */
public function quick_edit_teams( $column_name, $post_type ) { public function quick_edit_teams( $column_name, $post_type ) {
if ( $this->type !== $post_type ) return; if ( $this->type !== $post_type ) {
if ( 'sp_team' !== $column_name ) return; return;
}
if ( 'sp_team' !== $column_name ) {
return;
}
$teams = get_posts( array( $teams = get_posts(
'post_type' => 'sp_team', array(
'numberposts' => -1, 'post_type' => 'sp_team',
'post_status' => 'publish', 'numberposts' => -1,
) ); 'post_status' => 'publish',
)
if ( ! $teams ) return; );
?>
if ( ! $teams ) {
return;
}
?>
<fieldset class="inline-edit-col-right"> <fieldset class="inline-edit-col-right">
<div class="inline-edit-col"> <div class="inline-edit-col">
<span class="title inline-edit-categories-label"><?php _e( 'Current Teams', 'sportspress' ); ?></span> <span class="title inline-edit-categories-label"><?php _e( 'Current Teams', 'sportspress' ); ?></span>
@@ -269,57 +296,75 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
</ul> </ul>
</div> </div>
</fieldset> </fieldset>
<?php <?php
}
/**
* Save quick edit boxes
*
* @param int $post_id
*/
public function quick_save( $post_id ) {
if ( empty( $_POST ) ) return $post_id;
if ( ! current_user_can( 'edit_post', $post_id ) ) return $post_id;;
$_POST += array( "{$this->type}_edit_nonce" => '' );
if ( ! wp_verify_nonce( $_POST["{$this->type}_edit_nonce"], plugin_basename( __FILE__ ) ) ) return $post_id;;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;
if ( isset( $post->post_type ) && $post->post_type == 'revision' ) return $post_id;
if ( isset( $_POST[ 'sp_number' ] ) ) {
update_post_meta( $post_id, 'sp_number', $_POST[ 'sp_number' ] );
} }
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) ); /**
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) ); * Save quick edit boxes
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) ); *
} * @param int $post_id
*/
public function quick_save( $post_id ) {
if ( empty( $_POST ) ) {
return $post_id;
}
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
/** $_POST += array( "{$this->type}_edit_nonce" => '' );
* Bulk edit teams if ( ! wp_verify_nonce( $_POST[ "{$this->type}_edit_nonce" ], plugin_basename( __FILE__ ) ) ) {
* return $post_id;
* @param string $column_name }
* @param string $post_type
*/
public function bulk_edit_teams( $column_name, $post_type ) {
if ( $this->type !== $post_type ) return;
if ( 'sp_team' !== $column_name ) return;
static $print_nonce = true; if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
if ( $print_nonce ) { return $post_id;
$print_nonce = false; }
wp_nonce_field( plugin_basename( __FILE__ ), 'sp_player_edit_nonce' ); if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
return $post_id;
}
if ( isset( $_POST['sp_number'] ) ) {
update_post_meta( $post_id, 'sp_number', $_POST['sp_number'] );
}
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
} }
$teams = get_posts( array( /**
'post_type' => 'sp_team', * Bulk edit teams
'numberposts' => -1, *
'post_status' => 'publish', * @param string $column_name
) ); * @param string $post_type
*/
if ( ! $teams ) return; public function bulk_edit_teams( $column_name, $post_type ) {
?> if ( $this->type !== $post_type ) {
return;
}
if ( 'sp_team' !== $column_name ) {
return;
}
static $print_nonce = true;
if ( $print_nonce ) {
$print_nonce = false;
wp_nonce_field( plugin_basename( __FILE__ ), 'sp_player_edit_nonce' );
}
$teams = get_posts(
array(
'post_type' => 'sp_team',
'numberposts' => -1,
'post_status' => 'publish',
)
);
if ( ! $teams ) {
return;
}
?>
<fieldset class="inline-edit-col-right"> <fieldset class="inline-edit-col-right">
<div class="inline-edit-col"> <div class="inline-edit-col">
<span class="title inline-edit-categories-label"><?php _e( 'Current Teams', 'sportspress' ); ?></span> <span class="title inline-edit-categories-label"><?php _e( 'Current Teams', 'sportspress' ); ?></span>
@@ -338,35 +383,39 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
</ul> </ul>
</div> </div>
</fieldset> </fieldset>
<?php <?php
}
/**
* Save bulk edit boxes
*/
public function bulk_save() {
$_POST += array( "nonce" => '' );
if ( ! wp_verify_nonce( $_POST["nonce"], plugin_basename( __FILE__ ) ) ) return;
$post_ids = ( ! empty( $_POST[ 'post_ids' ] ) ) ? $_POST[ 'post_ids' ] : array();
$current_teams = sp_array_value( $_POST, 'current_teams', array() );
$past_teams = sp_array_value( $_POST, 'past_teams', array() );
$teams = array_merge( $current_teams, $past_teams );
if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
foreach ( $post_ids as $post_id ) {
if ( ! current_user_can( 'edit_post', $post_id ) ) continue;
sp_add_post_meta_recursive( $post_id, 'sp_current_team', $current_teams );
sp_add_post_meta_recursive( $post_id, 'sp_past_team', $past_teams );
sp_add_post_meta_recursive( $post_id, 'sp_team', $teams );
}
} }
die(); /**
* Save bulk edit boxes
*/
public function bulk_save() {
$_POST += array( 'nonce' => '' );
if ( ! wp_verify_nonce( $_POST['nonce'], plugin_basename( __FILE__ ) ) ) {
return;
}
$post_ids = ( ! empty( $_POST['post_ids'] ) ) ? $_POST['post_ids'] : array();
$current_teams = sp_array_value( $_POST, 'current_teams', array() );
$past_teams = sp_array_value( $_POST, 'past_teams', array() );
$teams = array_merge( $current_teams, $past_teams );
if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
foreach ( $post_ids as $post_id ) {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
continue;
}
sp_add_post_meta_recursive( $post_id, 'sp_current_team', $current_teams );
sp_add_post_meta_recursive( $post_id, 'sp_past_team', $past_teams );
sp_add_post_meta_recursive( $post_id, 'sp_team', $teams );
}
}
die();
}
} }
}
endif; endif;

View File

@@ -2,68 +2,72 @@
/** /**
* Admin functions for the results post type * Admin functions for the results post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Result' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Result' ) ) :
/**
* SP_Admin_CPT_Result Class
*/
class SP_Admin_CPT_Result extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Result Class
*/ */
public function __construct() { class SP_Admin_CPT_Result extends SP_Admin_CPT {
$this->type = 'sp_result';
// Admin Columns /**
add_filter( 'manage_edit-sp_result_columns', array( $this, 'edit_columns' ) ); * Constructor
add_action( 'manage_sp_result_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); */
public function __construct() {
// Call SP_Admin_CPT constructor $this->type = 'sp_result';
parent::__construct();
}
/** // Admin Columns
* Change the columns shown in admin. add_filter( 'manage_edit-sp_result_columns', array( $this, 'edit_columns' ) );
*/ add_action( 'manage_sp_result_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Variable', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_result_admin_columns', $columns );
}
/** // Call SP_Admin_CPT constructor
* Define our custom columns shown in admin. parent::__construct();
* @param string $column }
*/
public function custom_columns( $column, $post_id ) { /**
switch ( $column ): * Change the columns shown in admin.
case 'sp_key': */
global $post; public function edit_columns( $existing_columns ) {
echo esc_html( $post->post_name ) . 'for, ' . esc_html( $post->post_name ) . 'against'; $columns = array(
break; 'cb' => '<input type="checkbox" />',
case 'sp_description': 'title' => __( 'Label', 'sportspress' ),
global $post; 'sp_key' => __( 'Variable', 'sportspress' ),
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>'; 'sp_description' => __( 'Description', 'sportspress' ),
break; );
endswitch; return apply_filters( 'sportspress_result_admin_columns', $columns );
}
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_key':
global $post;
echo esc_html( $post->post_name ) . 'for, ' . esc_html( $post->post_name ) . 'against';
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
} }
}
endif; endif;

View File

@@ -2,68 +2,72 @@
/** /**
* Admin functions for the columns post type * Admin functions for the columns post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Spec' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Spec' ) ) :
/**
* SP_Admin_CPT_Spec Class
*/
class SP_Admin_CPT_Spec extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Spec Class
*/ */
public function __construct() { class SP_Admin_CPT_Spec extends SP_Admin_CPT {
$this->type = 'sp_spec';
// Admin Columns /**
add_filter( 'manage_edit-sp_spec_columns', array( $this, 'edit_columns' ) ); * Constructor
add_action( 'manage_sp_spec_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); */
public function __construct() {
// Call SP_Admin_CPT constructor $this->type = 'sp_spec';
parent::__construct();
}
/** // Admin Columns
* Change the columns shown in admin. add_filter( 'manage_edit-sp_spec_columns', array( $this, 'edit_columns' ) );
*/ add_action( 'manage_sp_spec_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Variable', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_spec_admin_columns', $columns );
}
/** // Call SP_Admin_CPT constructor
* Define our custom columns shown in admin. parent::__construct();
* @param string $column }
*/
public function custom_columns( $column, $post_id ) { /**
switch ( $column ): * Change the columns shown in admin.
case 'sp_key': */
global $post; public function edit_columns( $existing_columns ) {
echo esc_html( $post->post_name ); $columns = array(
break; 'cb' => '<input type="checkbox" />',
case 'sp_description': 'title' => __( 'Label', 'sportspress' ),
global $post; 'sp_key' => __( 'Variable', 'sportspress' ),
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>'; 'sp_description' => __( 'Description', 'sportspress' ),
break; );
endswitch; return apply_filters( 'sportspress_spec_admin_columns', $columns );
}
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_key':
global $post;
echo esc_html( $post->post_name );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
} }
}
endif; endif;

View File

@@ -2,169 +2,182 @@
/** /**
* Admin functions for the staff post type * Admin functions for the staff post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Staff' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Staff' ) ) :
/**
* SP_Admin_CPT_Staff Class
*/
class SP_Admin_CPT_Staff extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Staff Class
*/ */
public function __construct() { class SP_Admin_CPT_Staff extends SP_Admin_CPT {
$this->type = 'sp_staff';
// Post title fields /**
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 ); * Constructor
*/
public function __construct() {
$this->type = 'sp_staff';
// Admin Columns // Post title fields
add_filter( 'manage_edit-sp_staff_columns', array( $this, 'edit_columns' ) ); add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
add_action( 'manage_sp_staff_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Filtering // Admin Columns
add_action( 'restrict_manage_posts', array( $this, 'filters' ) ); add_filter( 'manage_edit-sp_staff_columns', array( $this, 'edit_columns' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) ); add_action( 'manage_sp_staff_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/** // Filtering
* Change title boxes in admin. add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
* @param string $text add_filter( 'parse_query', array( $this, 'filters_query' ) );
* @param object $post
* @return string
*/
public function enter_title_here( $text, $post ) {
if ( $post->post_type == 'sp_staff' )
return __( 'Name', 'sportspress' );
return $text; // Call SP_Admin_CPT constructor
} parent::__construct();
}
/** /**
* Change the columns shown in admin. * Change title boxes in admin.
*/ *
public function edit_columns( $existing_columns ) { * @param string $text
unset( $existing_columns['author'], $existing_columns['date'] ); * @param object $post
$columns = array_merge( array( * @return string
'cb' => '<input type="checkbox" />', */
'title' => null, public function enter_title_here( $text, $post ) {
'sp_role' => __( 'Job', 'sportspress' ), if ( $post->post_type == 'sp_staff' ) {
'sp_team' => __( 'Teams', 'sportspress' ), return __( 'Name', 'sportspress' );
'sp_league' => __( 'Leagues', 'sportspress' ), }
'sp_season' => __( 'Seasons', 'sportspress' ),
), $existing_columns, array(
'title' => __( 'Name', 'sportspress' )
) );
return apply_filters( 'sportspress_staff_admin_columns', $columns );
}
/** return $text;
* Define our custom columns shown in admin. }
* @param string $column
*/ /**
public function custom_columns( $column, $post_id ) { * Change the columns shown in admin.
switch ( $column ): */
case 'sp_role': public function edit_columns( $existing_columns ) {
echo get_the_terms( $post_id, 'sp_role' ) ? the_terms( $post_id, 'sp_role' ) : '&mdash;'; unset( $existing_columns['author'], $existing_columns['date'] );
break; $columns = array_merge(
case 'sp_team': array(
$teams = (array)get_post_meta( $post_id, 'sp_team', false ); 'cb' => '<input type="checkbox" />',
$teams = array_filter( $teams ); 'title' => null,
if ( empty( $teams ) ): 'sp_role' => __( 'Job', 'sportspress' ),
echo '&mdash;'; 'sp_team' => __( 'Teams', 'sportspress' ),
else: 'sp_league' => __( 'Leagues', 'sportspress' ),
$current_teams = get_post_meta( $post_id, 'sp_current_team', false ); 'sp_season' => __( 'Seasons', 'sportspress' ),
foreach( $teams as $team_id ): ),
if ( ! $team_id ) continue; $existing_columns,
$team = get_post( $team_id ); array(
if ( $team ): 'title' => __( 'Name', 'sportspress' ),
echo esc_html( $team->post_title ); )
if ( in_array( $team_id, $current_teams ) ): );
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>'; return apply_filters( 'sportspress_staff_admin_columns', $columns );
}
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_role':
echo get_the_terms( $post_id, 'sp_role' ) ? the_terms( $post_id, 'sp_role' ) : '&mdash;';
break;
case 'sp_team':
$teams = (array) get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
if ( empty( $teams ) ) :
echo '&mdash;';
else :
$current_teams = get_post_meta( $post_id, 'sp_current_team', false );
foreach ( $teams as $team_id ) :
if ( ! $team_id ) {
continue;
}
$team = get_post( $team_id );
if ( $team ) :
echo esc_html( $team->post_title );
if ( in_array( $team_id, $current_teams ) ) :
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
endif;
echo '<br>';
endif; endif;
echo '<br>'; endforeach;
endif; endif;
endforeach; break;
endif; case 'sp_league':
break; echo get_the_terms( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;';
case 'sp_league': break;
echo get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;'; case 'sp_season':
break; echo get_the_terms( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;';
case 'sp_season': break;
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;'; endswitch;
break; }
endswitch;
}
/** /**
* Show a category filter box * Show a category filter box
*/ */
public function filters() { public function filters() {
global $typenow, $wp_query; global $typenow, $wp_query;
if ( $typenow != 'sp_staff' ) if ( $typenow != 'sp_staff' ) {
return; return;
}
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_REQUEST['team'] ) : null; $selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_REQUEST['team'] ) : null;
$args = array( $args = array(
'post_type' => 'sp_team', 'post_type' => 'sp_team',
'name' => 'team', 'name' => 'team',
'show_option_none' => __( 'Show all teams', 'sportspress' ), 'show_option_none' => __( 'Show all teams', 'sportspress' ),
'selected' => $selected, 'selected' => $selected,
'values' => 'ID', 'values' => 'ID',
); );
wp_dropdown_pages( $args ); wp_dropdown_pages( $args );
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null; $selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array( $args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ), 'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league', 'taxonomy' => 'sp_league',
'name' => 'sp_league', 'name' => 'sp_league',
'selected' => $selected 'selected' => $selected,
); );
sp_dropdown_taxonomies( $args ); sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null; $selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array( $args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ), 'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season', 'taxonomy' => 'sp_season',
'name' => 'sp_season', 'name' => 'sp_season',
'selected' => $selected 'selected' => $selected,
); );
sp_dropdown_taxonomies( $args ); sp_dropdown_taxonomies( $args );
} }
/** /**
* Filter in admin based on options * Filter in admin based on options
* *
* @param mixed $query * @param mixed $query
*/ */
public function filters_query( $query ) { public function filters_query( $query ) {
global $typenow, $wp_query; global $typenow, $wp_query;
if ( $typenow == 'sp_staff' ) { if ( $typenow == 'sp_staff' ) {
if ( ! empty( $_GET['team'] ) ) { if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] ); $query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team'; $query->query_vars['meta_key'] = 'sp_team';
} }
}
} }
} }
}
endif; endif;

View File

@@ -2,80 +2,84 @@
/** /**
* Admin functions for the statistics post type * Admin functions for the statistics post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Statistic' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Statistic' ) ) :
/**
* SP_Admin_CPT_Statistic Class
*/
class SP_Admin_CPT_Statistic extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Statistic Class
*/ */
public function __construct() { class SP_Admin_CPT_Statistic extends SP_Admin_CPT {
$this->type = 'sp_statistic';
// Admin Columns /**
add_filter( 'manage_edit-sp_statistic_columns', array( $this, 'edit_columns' ) ); * Constructor
add_action( 'manage_sp_statistic_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); */
public function __construct() {
// Call SP_Admin_CPT constructor $this->type = 'sp_statistic';
parent::__construct();
}
/** // Admin Columns
* Change the columns shown in admin. add_filter( 'manage_edit-sp_statistic_columns', array( $this, 'edit_columns' ) );
*/ add_action( 'manage_sp_statistic_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'sp_icon' => __( 'Icon', 'sportspress' ),
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
'sp_precision' => __( 'Decimal Places', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_statistic_admin_columns', $columns );
}
/** // Call SP_Admin_CPT constructor
* Define our custom columns shown in admin. parent::__construct();
* @param string $column }
*/
public function custom_columns( $column, $post_id ) { /**
switch ( $column ): * Change the columns shown in admin.
case 'sp_icon': */
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : ''; public function edit_columns( $existing_columns ) {
break; $columns = array(
case 'sp_key': 'cb' => '<input type="checkbox" />',
global $post; 'sp_icon' => __( 'Icon', 'sportspress' ),
echo esc_html( $post->post_name ); 'title' => __( 'Label', 'sportspress' ),
break; 'sp_key' => __( 'Key', 'sportspress' ),
case 'sp_equation': 'sp_equation' => __( 'Equation', 'sportspress' ),
echo esc_html( sp_get_post_equation( $post_id ) ); 'sp_precision' => __( 'Decimal Places', 'sportspress' ),
break; 'sp_description' => __( 'Description', 'sportspress' ),
case 'sp_precision': );
echo esc_html( sp_get_post_precision( $post_id ) ); return apply_filters( 'sportspress_statistic_admin_columns', $columns );
break; }
case 'sp_description':
global $post; /**
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>'; * Define our custom columns shown in admin.
break; *
endswitch; * @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_icon':
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : '';
break;
case 'sp_key':
global $post;
echo esc_html( $post->post_name );
break;
case 'sp_equation':
echo esc_html( sp_get_post_equation( $post_id ) );
break;
case 'sp_precision':
echo esc_html( sp_get_post_precision( $post_id ) );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
} }
}
endif; endif;

View File

@@ -2,136 +2,144 @@
/** /**
* Admin functions for the league tables post type * Admin functions for the league tables post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.5 * @version 2.5
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Table' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Table' ) ) :
/**
* SP_Admin_CPT_Table Class
*/
class SP_Admin_CPT_Table extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Table Class
*/ */
public function __construct() { class SP_Admin_CPT_Table extends SP_Admin_CPT {
$this->type = 'sp_table';
// Admin Columns /**
add_filter( 'manage_edit-sp_table_columns', array( $this, 'edit_columns' ) ); * Constructor
add_action( 'manage_sp_table_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); */
public function __construct() {
$this->type = 'sp_table';
// Filtering // Admin Columns
add_action( 'restrict_manage_posts', array( $this, 'filters' ) ); add_filter( 'manage_edit-sp_table_columns', array( $this, 'edit_columns' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) ); add_action( 'manage_sp_table_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/** // Filtering
* Change the columns shown in admin. add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
*/ add_filter( 'parse_query', array( $this, 'filters_query' ) );
public function edit_columns( $existing_columns ) {
unset( $existing_columns['date'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
), $existing_columns );
return apply_filters( 'sportspress_table_admin_columns', $columns );
}
/** // Call SP_Admin_CPT constructor
* Define our custom columns shown in admin. parent::__construct();
* @param string $column }
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_league':
echo get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;';
break;
case 'sp_season':
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;';
break;
case 'sp_team':
$select = get_post_meta( $post_id, 'sp_select', true );
if ( 'manual' == $select ):
$teams = array_filter( get_post_meta( $post_id, 'sp_team' ) );
echo sizeof( $teams );
else:
_e( 'Auto', 'sportspress' );
endif;
break;
endswitch;
}
/** /**
* Show a category filter box * Change the columns shown in admin.
*/ */
public function filters() { public function edit_columns( $existing_columns ) {
global $typenow, $wp_query; unset( $existing_columns['date'] );
$columns = array_merge(
array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
),
$existing_columns
);
return apply_filters( 'sportspress_table_admin_columns', $columns );
}
if ( $typenow != 'sp_table' ) /**
return; * Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_league':
echo get_the_terms( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;';
break;
case 'sp_season':
echo get_the_terms( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;';
break;
case 'sp_team':
$select = get_post_meta( $post_id, 'sp_select', true );
if ( 'manual' == $select ) :
$teams = array_filter( get_post_meta( $post_id, 'sp_team' ) );
echo sizeof( $teams );
else :
_e( 'Auto', 'sportspress' );
endif;
break;
endswitch;
}
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null; /**
$args = array( * Show a category filter box
'show_option_all' => __( 'Show all leagues', 'sportspress' ), */
'taxonomy' => 'sp_league', public function filters() {
'name' => 'sp_league', global $typenow, $wp_query;
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null; if ( $typenow != 'sp_table' ) {
$args = array( return;
'show_option_all' => __( 'Show all seasons', 'sportspress' ), }
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_REQUEST['team'] ) : null; $selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array( $args = array(
'post_type' => 'sp_team', 'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'name' => 'team', 'taxonomy' => 'sp_league',
'show_option_none' => __( 'Show all teams', 'sportspress' ), 'name' => 'sp_league',
'selected' => $selected, 'selected' => $selected,
'values' => 'ID', );
); sp_dropdown_taxonomies( $args );
wp_dropdown_pages( $args );
}
/** $selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
* Filter in admin based on options $args = array(
* 'show_option_all' => __( 'Show all seasons', 'sportspress' ),
* @param mixed $query 'taxonomy' => 'sp_season',
*/ 'name' => 'sp_season',
public function filters_query( $query ) { 'selected' => $selected,
global $typenow, $wp_query; );
sp_dropdown_taxonomies( $args );
if ( $typenow == 'sp_table' ) { $selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_REQUEST['team'] ) : null;
$args = array(
'post_type' => 'sp_team',
'name' => 'team',
'show_option_none' => __( 'Show all teams', 'sportspress' ),
'selected' => $selected,
'values' => 'ID',
);
wp_dropdown_pages( $args );
}
if ( ! empty( $_GET['team'] ) ) { /**
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] ); * Filter in admin based on options
$query->query_vars['meta_key'] = 'sp_team'; *
} * @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
if ( $typenow == 'sp_table' ) {
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
}
}
} }
} }
}
endif; endif;

View File

@@ -2,131 +2,142 @@
/** /**
* Admin functions for the teams post type * Admin functions for the teams post type
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 2.6 * @version 2.6
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) if ( ! class_exists( 'SP_Admin_CPT' ) ) {
include( 'class-sp-admin-cpt.php' ); require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Team' ) ) : if ( ! class_exists( 'SP_Admin_CPT_Team' ) ) :
/**
* SP_Admin_CPT_Team Class
*/
class SP_Admin_CPT_Team extends SP_Admin_CPT {
/** /**
* Constructor * SP_Admin_CPT_Team Class
*/ */
public function __construct() { class SP_Admin_CPT_Team extends SP_Admin_CPT {
$this->type = 'sp_team';
// Post title fields /**
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 ); * Constructor
*/
public function __construct() {
$this->type = 'sp_team';
// Admin Columns // Post title fields
add_filter( 'manage_edit-sp_team_columns', array( $this, 'edit_columns' ) ); add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
add_action( 'manage_sp_team_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Filtering // Admin Columns
add_action( 'restrict_manage_posts', array( $this, 'filters' ) ); add_filter( 'manage_edit-sp_team_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_team_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct(); // Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Change title boxes in admin.
*
* @param string $text
* @param object $post
* @return string
*/
public function enter_title_here( $text, $post ) {
if ( $post->post_type == 'sp_team' ) {
return __( 'Name', 'sportspress' );
}
return $text;
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge(
array(
'cb' => '<input type="checkbox" />',
'sp_icon' => '<span class="dashicons sp-icon-shield sp-tip" title="' . __( 'Logo', 'sportspress' ) . '"></span>',
'title' => null,
'sp_short_name' => __( 'Short Name', 'sportspress' ),
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
),
$existing_columns,
array(
'title' => __( 'Team', 'sportspress' ),
)
);
return apply_filters( 'sportspress_team_admin_columns', $columns );
}
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_icon':
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : '';
break;
case 'sp_short_name':
$short_name = get_post_meta( $post_id, 'sp_short_name', true );
echo $short_name ? esc_html( $short_name ) : '&mdash;';
break;
case 'sp_abbreviation':
$abbreviation = get_post_meta( $post_id, 'sp_abbreviation', true );
echo $abbreviation ? esc_html( $abbreviation ) : '&mdash;';
break;
case 'sp_league':
echo get_the_terms( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;';
break;
case 'sp_season':
echo get_the_terms( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;';
break;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_team' ) {
return;
}
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
}
} }
/**
* Change title boxes in admin.
* @param string $text
* @param object $post
* @return string
*/
public function enter_title_here( $text, $post ) {
if ( $post->post_type == 'sp_team' )
return __( 'Name', 'sportspress' );
return $text;
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'sp_icon' => '<span class="dashicons sp-icon-shield sp-tip" title="' . __( 'Logo', 'sportspress' ) . '"></span>',
'title' => null,
'sp_short_name' => __( 'Short Name', 'sportspress' ),
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
), $existing_columns, array(
'title' => __( 'Team', 'sportspress' ),
) );
return apply_filters( 'sportspress_team_admin_columns', $columns );
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_icon':
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : '';
break;
case 'sp_short_name':
$short_name = get_post_meta ( $post_id, 'sp_short_name', true );
echo $short_name ? esc_html( $short_name ) : '&mdash;';
break;
case 'sp_abbreviation':
$abbreviation = get_post_meta ( $post_id, 'sp_abbreviation', true );
echo $abbreviation ? esc_html( $abbreviation ) : '&mdash;';
break;
case 'sp_league':
echo get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;';
break;
case 'sp_season':
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;';
break;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_team' )
return;
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
}
}
endif; endif;
return new SP_Admin_CPT_Team(); return new SP_Admin_CPT_Team();

View File

@@ -2,66 +2,70 @@
/** /**
* Admin functions for post types * Admin functions for post types
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Post_Types * @package SportsPress/Admin/Post_Types
* @version 0.7 * @version 0.7
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_CPT' ) ) : if ( ! class_exists( 'SP_Admin_CPT' ) ) :
/**
* SP_Admin_CPT Class
*/
class SP_Admin_CPT {
protected $type = '';
/** /**
* Constructor * SP_Admin_CPT Class
*/ */
public function __construct() { class SP_Admin_CPT {
// Insert into X media browser
add_filter( 'media_view_strings', array( $this, 'change_insert_into_post' ) ); protected $type = '';
/**
* Constructor
*/
public function __construct() {
// Insert into X media browser
add_filter( 'media_view_strings', array( $this, 'change_insert_into_post' ) );
}
/**
* Change label for insert buttons.
*
* @access public
* @param array $strings
* @return array
*/
function change_insert_into_post( $strings ) {
global $post_type;
if ( $post_type == $this->type ) {
$obj = get_post_type_object( $this->type );
$strings['insertIntoPost'] = sprintf( __( 'Insert into %s', 'sportspress' ), $obj->labels->singular_name );
$strings['uploadedToThisPost'] = sprintf( __( 'Uploaded to this %s', 'sportspress' ), $obj->labels->singular_name );
}
return $strings;
}
/**
* Check if we're editing or adding an event
*
* @return boolean
*/
private function is_editing() {
if ( ! empty( $_GET['post_type'] ) && $this->type == $_GET['post_type'] ) {
return true;
}
if ( ! empty( $_GET['post'] ) && $this->type == get_post_type( $_GET['post'] ) ) {
return true;
}
if ( ! empty( $_REQUEST['post_id'] ) && $this->type == get_post_type( $_REQUEST['post_id'] ) ) {
return true;
}
return false;
}
} }
/** endif;
* Change label for insert buttons.
* @access public
* @param array $strings
* @return array
*/
function change_insert_into_post( $strings ) {
global $post_type;
if ( $post_type == $this->type ) {
$obj = get_post_type_object( $this->type );
$strings['insertIntoPost'] = sprintf( __( 'Insert into %s', 'sportspress' ), $obj->labels->singular_name );
$strings['uploadedToThisPost'] = sprintf( __( 'Uploaded to this %s', 'sportspress' ), $obj->labels->singular_name );
}
return $strings;
}
/**
* Check if we're editing or adding an event
* @return boolean
*/
private function is_editing() {
if ( ! empty( $_GET['post_type'] ) && $this->type == $_GET['post_type'] ) {
return true;
}
if ( ! empty( $_GET['post'] ) && $this->type == get_post_type( $_GET['post'] ) ) {
return true;
}
if ( ! empty( $_REQUEST['post_id'] ) && $this->type == get_post_type( $_REQUEST['post_id'] ) ) {
return true;
}
return false;
}
}
endif;

View File

@@ -4,13 +4,15 @@
* *
* Sets up the write panels used by custom post types * Sets up the write panels used by custom post types
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.6.8 * @version 2.6.8
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Admin_Meta_Boxes * SP_Admin_Meta_Boxes
@@ -27,202 +29,202 @@ class SP_Admin_Meta_Boxes {
*/ */
public function __construct() { public function __construct() {
$meta_boxes = array( $meta_boxes = array(
'sp_outcome' => array( 'sp_outcome' => array(
'details' => array( 'details' => array(
'title' => __( 'Details', 'sportspress' ), 'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Outcome_Details::save', 'save' => 'SP_Meta_Box_Outcome_Details::save',
'output' => 'SP_Meta_Box_Outcome_Details::output', 'output' => 'SP_Meta_Box_Outcome_Details::output',
'context' => 'normal', 'context' => 'normal',
'priority' => 'high', 'priority' => 'high',
), ),
), ),
'sp_result' => array( 'sp_result' => array(
'details' => array( 'details' => array(
'title' => __( 'Details', 'sportspress' ), 'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Result_Details::save', 'save' => 'SP_Meta_Box_Result_Details::save',
'output' => 'SP_Meta_Box_Result_Details::output', 'output' => 'SP_Meta_Box_Result_Details::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'equation' => array( 'equation' => array(
'title' => __( 'Equation', 'sportspress' ), 'title' => __( 'Equation', 'sportspress' ),
'save' => 'SP_Meta_Box_Result_Equation::save', 'save' => 'SP_Meta_Box_Result_Equation::save',
'output' => 'SP_Meta_Box_Result_Equation::output', 'output' => 'SP_Meta_Box_Result_Equation::output',
'context' => 'normal', 'context' => 'normal',
'priority' => 'high', 'priority' => 'high',
), ),
), ),
'sp_performance' => array( 'sp_performance' => array(
'details' => array( 'details' => array(
'title' => __( 'Details', 'sportspress' ), 'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Performance_Details::save', 'save' => 'SP_Meta_Box_Performance_Details::save',
'output' => 'SP_Meta_Box_Performance_Details::output', 'output' => 'SP_Meta_Box_Performance_Details::output',
'context' => 'normal', 'context' => 'normal',
'priority' => 'high', 'priority' => 'high',
), ),
'equation' => array( 'equation' => array(
'title' => __( 'Equation', 'sportspress' ), 'title' => __( 'Equation', 'sportspress' ),
'save' => 'SP_Meta_Box_Performance_Equation::save', 'save' => 'SP_Meta_Box_Performance_Equation::save',
'output' => 'SP_Meta_Box_Performance_Equation::output', 'output' => 'SP_Meta_Box_Performance_Equation::output',
'context' => 'normal', 'context' => 'normal',
'priority' => 'high', 'priority' => 'high',
), ),
), ),
'sp_column' => array( 'sp_column' => array(
'details' => array( 'details' => array(
'title' => __( 'Details', 'sportspress' ), 'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Column_Details::save', 'save' => 'SP_Meta_Box_Column_Details::save',
'output' => 'SP_Meta_Box_Column_Details::output', 'output' => 'SP_Meta_Box_Column_Details::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'equation' => array( 'equation' => array(
'title' => __( 'Equation', 'sportspress' ), 'title' => __( 'Equation', 'sportspress' ),
'save' => 'SP_Meta_Box_Column_Equation::save', 'save' => 'SP_Meta_Box_Column_Equation::save',
'output' => 'SP_Meta_Box_Column_Equation::output', 'output' => 'SP_Meta_Box_Column_Equation::output',
'context' => 'normal', 'context' => 'normal',
'priority' => 'high', 'priority' => 'high',
), ),
), ),
'sp_metric' => array( 'sp_metric' => array(
'details' => array( 'details' => array(
'title' => __( 'Details', 'sportspress' ), 'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Metric_Details::save', 'save' => 'SP_Meta_Box_Metric_Details::save',
'output' => 'SP_Meta_Box_Metric_Details::output', 'output' => 'SP_Meta_Box_Metric_Details::output',
'context' => 'normal', 'context' => 'normal',
'priority' => 'high', 'priority' => 'high',
), ),
), ),
'sp_statistic' => array( 'sp_statistic' => array(
'details' => array( 'details' => array(
'title' => __( 'Details', 'sportspress' ), 'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Statistic_Details::save', 'save' => 'SP_Meta_Box_Statistic_Details::save',
'output' => 'SP_Meta_Box_Statistic_Details::output', 'output' => 'SP_Meta_Box_Statistic_Details::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'equation' => array( 'equation' => array(
'title' => __( 'Equation', 'sportspress' ), 'title' => __( 'Equation', 'sportspress' ),
'save' => 'SP_Meta_Box_Statistic_Equation::save', 'save' => 'SP_Meta_Box_Statistic_Equation::save',
'output' => 'SP_Meta_Box_Statistic_Equation::output', 'output' => 'SP_Meta_Box_Statistic_Equation::output',
'context' => 'normal', 'context' => 'normal',
'priority' => 'high', 'priority' => 'high',
), ),
), ),
'sp_event' => array( 'sp_event' => array(
'shortcode' => array( 'shortcode' => array(
'title' => __( 'Shortcodes', 'sportspress' ), 'title' => __( 'Shortcodes', 'sportspress' ),
'output' => 'SP_Meta_Box_Event_Shortcode::output', 'output' => 'SP_Meta_Box_Event_Shortcode::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'format' => array( 'format' => array(
'title' => __( 'Format', 'sportspress' ), 'title' => __( 'Format', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Format::save', 'save' => 'SP_Meta_Box_Event_Format::save',
'output' => 'SP_Meta_Box_Event_Format::output', 'output' => 'SP_Meta_Box_Event_Format::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'mode' => array( 'mode' => array(
'title' => __( 'Mode', 'sportspress' ), 'title' => __( 'Mode', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Mode::save', 'save' => 'SP_Meta_Box_Event_Mode::save',
'output' => 'SP_Meta_Box_Event_Mode::output', 'output' => 'SP_Meta_Box_Event_Mode::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'details' => array( 'details' => array(
'title' => __( 'Details', 'sportspress' ), 'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Details::save', 'save' => 'SP_Meta_Box_Event_Details::save',
'output' => 'SP_Meta_Box_Event_Details::output', 'output' => 'SP_Meta_Box_Event_Details::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'team' => array( 'team' => array(
'title' => __( 'Teams', 'sportspress' ), 'title' => __( 'Teams', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Teams::save', 'save' => 'SP_Meta_Box_Event_Teams::save',
'output' => 'SP_Meta_Box_Event_Teams::output', 'output' => 'SP_Meta_Box_Event_Teams::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'results' => array( 'results' => array(
'title' => __( 'Results', 'sportspress' ), 'title' => __( 'Results', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Results::save', 'save' => 'SP_Meta_Box_Event_Results::save',
'output' => 'SP_Meta_Box_Event_Results::output', 'output' => 'SP_Meta_Box_Event_Results::output',
'context' => 'normal', 'context' => 'normal',
'priority' => 'high', 'priority' => 'high',
), ),
'performance' => array( 'performance' => array(
'title' => __( 'Box Score', 'sportspress' ), 'title' => __( 'Box Score', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Performance::save', 'save' => 'SP_Meta_Box_Event_Performance::save',
'output' => 'SP_Meta_Box_Event_Performance::output', 'output' => 'SP_Meta_Box_Event_Performance::output',
'context' => 'normal', 'context' => 'normal',
'priority' => 'high', 'priority' => 'high',
), ),
), ),
'sp_team' => array( 'sp_team' => array(
'details' => array( 'details' => array(
'title' => __( 'Details', 'sportspress' ), 'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Team_Details::save', 'save' => 'SP_Meta_Box_Team_Details::save',
'output' => 'SP_Meta_Box_Team_Details::output', 'output' => 'SP_Meta_Box_Team_Details::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'staff' => array( 'staff' => array(
'title' => __( 'Staff', 'sportspress' ), 'title' => __( 'Staff', 'sportspress' ),
'save' => 'SP_Meta_Box_Team_Staff::save', 'save' => 'SP_Meta_Box_Team_Staff::save',
'output' => 'SP_Meta_Box_Team_Staff::output', 'output' => 'SP_Meta_Box_Team_Staff::output',
'context' => 'normal', 'context' => 'normal',
'priority' => 'high', 'priority' => 'high',
), ),
), ),
'sp_player' => array( 'sp_player' => array(
'shortcode' => array( 'shortcode' => array(
'title' => __( 'Shortcodes', 'sportspress' ), 'title' => __( 'Shortcodes', 'sportspress' ),
'output' => 'SP_Meta_Box_Player_Shortcode::output', 'output' => 'SP_Meta_Box_Player_Shortcode::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'columns' => array( 'columns' => array(
'title' => __( 'Columns', 'sportspress' ), 'title' => __( 'Columns', 'sportspress' ),
'save' => 'SP_Meta_Box_Player_Columns::save', 'save' => 'SP_Meta_Box_Player_Columns::save',
'output' => 'SP_Meta_Box_Player_Columns::output', 'output' => 'SP_Meta_Box_Player_Columns::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'details' => array( 'details' => array(
'title' => __( 'Details', 'sportspress' ), 'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Player_Details::save', 'save' => 'SP_Meta_Box_Player_Details::save',
'output' => 'SP_Meta_Box_Player_Details::output', 'output' => 'SP_Meta_Box_Player_Details::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'metrics' => array( 'metrics' => array(
'title' => __( 'Metrics', 'sportspress' ), 'title' => __( 'Metrics', 'sportspress' ),
'save' => 'SP_Meta_Box_Player_Metrics::save', 'save' => 'SP_Meta_Box_Player_Metrics::save',
'output' => 'SP_Meta_Box_Player_Metrics::output', 'output' => 'SP_Meta_Box_Player_Metrics::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'statistics' => array( 'statistics' => array(
'title' => __( 'Statistics', 'sportspress' ), 'title' => __( 'Statistics', 'sportspress' ),
'save' => 'SP_Meta_Box_Player_Statistics::save', 'save' => 'SP_Meta_Box_Player_Statistics::save',
'output' => 'SP_Meta_Box_Player_Statistics::output', 'output' => 'SP_Meta_Box_Player_Statistics::output',
'context' => 'normal', 'context' => 'normal',
'priority' => 'high', 'priority' => 'high',
), ),
), ),
'sp_staff' => array( 'sp_staff' => array(
'shortcode' => array( 'shortcode' => array(
'title' => __( 'Shortcode', 'sportspress' ), 'title' => __( 'Shortcode', 'sportspress' ),
'output' => 'SP_Meta_Box_Staff_Shortcode::output', 'output' => 'SP_Meta_Box_Staff_Shortcode::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'details' => array( 'details' => array(
'title' => __( 'Details', 'sportspress' ), 'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Staff_Details::save', 'save' => 'SP_Meta_Box_Staff_Details::save',
'output' => 'SP_Meta_Box_Staff_Details::output', 'output' => 'SP_Meta_Box_Staff_Details::output',
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
), ),
@@ -303,7 +305,7 @@ class SP_Admin_Meta_Boxes {
remove_meta_box( 'postimagediv', 'sp_performance', 'side' ); remove_meta_box( 'postimagediv', 'sp_performance', 'side' );
add_meta_box( 'postimagediv', __( 'Icon', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_performance', 'side', 'low' ); add_meta_box( 'postimagediv', __( 'Icon', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_performance', 'side', 'low' );
remove_meta_box( 'postimagediv', 'sp_statistic', 'side' ); remove_meta_box( 'postimagediv', 'sp_statistic', 'side' );
add_meta_box( 'postimagediv', __( 'Icon', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_statistic', 'side', 'low' ); add_meta_box( 'postimagediv', __( 'Icon', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_statistic', 'side', 'low' );
} }
@@ -311,17 +313,31 @@ class SP_Admin_Meta_Boxes {
/** /**
* Check if we're saving, then trigger an action based on the post type * Check if we're saving, then trigger an action based on the post type
* *
* @param int $post_id * @param int $post_id
* @param object $post * @param object $post
*/ */
public function save_meta_boxes( $post_id, $post ) { public function save_meta_boxes( $post_id, $post ) {
if ( empty( $post_id ) || empty( $post ) ) return; if ( empty( $post_id ) || empty( $post ) ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; return;
if ( is_int( wp_is_post_revision( $post ) ) ) return; }
if ( is_int( wp_is_post_autosave( $post ) ) ) return; if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
if ( empty( $_POST['sportspress_meta_nonce'] ) || ! wp_verify_nonce( $_POST['sportspress_meta_nonce'], 'sportspress_save_data' ) ) return; return;
if ( ! apply_filters( 'sportspress_user_can', current_user_can( 'edit_post', $post_id ), $post_id ) ) return; }
if ( ! is_sp_post_type( $post->post_type ) && ! is_sp_config_type( $post->post_type ) ) return; if ( is_int( wp_is_post_revision( $post ) ) ) {
return;
}
if ( is_int( wp_is_post_autosave( $post ) ) ) {
return;
}
if ( empty( $_POST['sportspress_meta_nonce'] ) || ! wp_verify_nonce( $_POST['sportspress_meta_nonce'], 'sportspress_save_data' ) ) {
return;
}
if ( ! apply_filters( 'sportspress_user_can', current_user_can( 'edit_post', $post_id ), $post_id ) ) {
return;
}
if ( ! is_sp_post_type( $post->post_type ) && ! is_sp_config_type( $post->post_type ) ) {
return;
}
do_action( 'sportspress_process_' . $post->post_type . '_meta', $post_id, $post ); do_action( 'sportspress_process_' . $post->post_type . '_meta', $post_id, $post );
} }

View File

@@ -2,13 +2,15 @@
/** /**
* Calendar Columns * Calendar Columns
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Calendar_Columns * SP_Meta_Box_Calendar_Columns
@@ -19,9 +21,9 @@ class SP_Meta_Box_Calendar_Columns {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$selected = (array) get_post_meta( $post->ID, 'sp_columns', true ); $selected = (array) get_post_meta( $post->ID, 'sp_columns', true );
$title_format = get_option( 'sportspress_event_list_title_format', 'title' ); $title_format = get_option( 'sportspress_event_list_title_format', 'title' );
$time_format = get_option( 'sportspress_event_list_time_format', 'combined' ); $time_format = get_option( 'sportspress_event_list_time_format', 'combined' );
if ( is_array( $selected ) ) { if ( is_array( $selected ) ) {
$selected = array_filter( $selected ); $selected = array_filter( $selected );
@@ -30,11 +32,11 @@ class SP_Meta_Box_Calendar_Columns {
$columns = array(); $columns = array();
if ( 'teams' === $title_format ) { if ( 'teams' === $title_format ) {
$columns[ 'event' ] = __( 'Home', 'sportspress' ) . ' | ' . __( 'Away', 'sportspress' ); $columns['event'] = __( 'Home', 'sportspress' ) . ' | ' . __( 'Away', 'sportspress' );
} elseif ( 'homeaway' === $title_format ) { } elseif ( 'homeaway' === $title_format ) {
$columns[ 'event' ] = __( 'Teams', 'sportspress' ); $columns['event'] = __( 'Teams', 'sportspress' );
} else { } else {
$columns[ 'event' ] = __( 'Title', 'sportspress' ); $columns['event'] = __( 'Title', 'sportspress' );
} }
if ( 'time' === $time_format || 'separate' === $time_format ) { if ( 'time' === $time_format || 'separate' === $time_format ) {
@@ -47,27 +49,27 @@ class SP_Meta_Box_Calendar_Columns {
$columns['results'] = __( 'Results', 'sportspress' ); $columns['results'] = __( 'Results', 'sportspress' );
} }
$columns['league'] = __( 'League', 'sportspress' ); $columns['league'] = __( 'League', 'sportspress' );
$columns['season'] = __( 'Season', 'sportspress' ); $columns['season'] = __( 'Season', 'sportspress' );
$columns['venue'] = __( 'Venue', 'sportspress' ); $columns['venue'] = __( 'Venue', 'sportspress' );
$columns['article'] = __( 'Article', 'sportspress' ); $columns['article'] = __( 'Article', 'sportspress' );
$columns['day'] = __( 'Match Day', 'sportspress' ); $columns['day'] = __( 'Match Day', 'sportspress' );
$columns = apply_filters( 'sportspress_calendar_columns', $columns ); $columns = apply_filters( 'sportspress_calendar_columns', $columns );
?> ?>
<div class="sp-instance"> <div class="sp-instance">
<ul class="categorychecklist form-no-clear"> <ul class="categorychecklist form-no-clear">
<?php <?php
foreach ( $columns as $key => $label ) { foreach ( $columns as $key => $label ) {
?> ?>
<li> <li>
<label> <label>
<input type="checkbox" name="sp_columns[]" value="<?php echo esc_attr( $key ); ?>" id="sp_columns_<?php echo esc_attr( $key ); ?>" <?php checked( ! is_array( $selected ) || in_array( $key, $selected ) ); ?>> <input type="checkbox" name="sp_columns[]" value="<?php echo esc_attr( $key ); ?>" id="sp_columns_<?php echo esc_attr( $key ); ?>" <?php checked( ! is_array( $selected ) || in_array( $key, $selected ) ); ?>>
<?php echo esc_html( $label ); ?> <?php echo esc_html( $label ); ?>
</label> </label>
</li> </li>
<?php <?php
} }
?> ?>
</div> </div>
<?php <?php
@@ -79,4 +81,4 @@ class SP_Meta_Box_Calendar_Columns {
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array(), 'text' ) ); update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array(), 'text' ) );
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* Calendar Events * Calendar Events
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Calendar_Data * SP_Meta_Box_Calendar_Data
@@ -19,8 +21,8 @@ class SP_Meta_Box_Calendar_Data {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$calendar = new SP_Calendar( $post ); $calendar = new SP_Calendar( $post );
$data = $calendar->data(); $data = $calendar->data();
$usecolumns = $calendar->columns; $usecolumns = $calendar->columns;
self::table( $data, $usecolumns ); self::table( $data, $usecolumns );
} }
@@ -37,11 +39,11 @@ class SP_Meta_Box_Calendar_Data {
*/ */
public static function table( $data = array(), $usecolumns = null ) { public static function table( $data = array(), $usecolumns = null ) {
$title_format = get_option( 'sportspress_event_list_title_format', 'title' ); $title_format = get_option( 'sportspress_event_list_title_format', 'title' );
$time_format = get_option( 'sportspress_event_list_time_format', 'combined' ); $time_format = get_option( 'sportspress_event_list_time_format', 'combined' );
if ( is_array( $usecolumns ) ) { if ( is_array( $usecolumns ) ) {
$usecolumns = array_filter( $usecolumns ); $usecolumns = array_filter( $usecolumns );
}else{ } else {
$usecolumns = array(); $usecolumns = array();
} }
?> ?>
@@ -57,7 +59,11 @@ class SP_Meta_Box_Calendar_Data {
<label for="sp_columns_event"> <label for="sp_columns_event">
<?php <?php
if ( 'teams' == $title_format ) { if ( 'teams' == $title_format ) {
_e( 'Home', 'sportspress' ); ?> | <?php _e( 'Away', 'sportspress' ); _e( 'Home', 'sportspress' );
?>
|
<?php
_e( 'Away', 'sportspress' );
} elseif ( 'homeaway' == $title_format ) { } elseif ( 'homeaway' == $title_format ) {
_e( 'Teams', 'sportspress' ); _e( 'Teams', 'sportspress' );
} else { } else {
@@ -127,50 +133,64 @@ class SP_Meta_Box_Calendar_Data {
</thead> </thead>
<tbody> <tbody>
<?php <?php
if ( is_array( $data ) ): if ( is_array( $data ) ) :
if ( sizeof( $data ) > 0 ): if ( sizeof( $data ) > 0 ) :
$main_result = get_option( 'sportspress_primary_result', null ); $main_result = get_option( 'sportspress_primary_result', null );
$i = 0; $i = 0;
foreach ( $data as $event ): foreach ( $data as $event ) :
$teams = get_post_meta( $event->ID, 'sp_team' ); $teams = get_post_meta( $event->ID, 'sp_team' );
$results = get_post_meta( $event->ID, 'sp_results', true ); $results = get_post_meta( $event->ID, 'sp_results', true );
$video = get_post_meta( $event->ID, 'sp_video', true ); $video = get_post_meta( $event->ID, 'sp_video', true );
$main_results = array(); $main_results = array();
?> ?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>"> <tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
">
<td><?php echo get_post_time( get_option( 'date_format' ), false, $event, true ); ?></td> <td><?php echo get_post_time( get_option( 'date_format' ), false, $event, true ); ?></td>
<?php if ( is_array( $usecolumns ) && in_array( 'event', $usecolumns ) ) { ?> <?php if ( is_array( $usecolumns ) && in_array( 'event', $usecolumns ) ) { ?>
<td> <td>
<div class="sp-title-format sp-title-format-title<?php if ( $title_format && $title_format != 'title' ): ?> hidden<?php endif; ?>"><?php echo esc_html( $event->post_title ); ?></div> <div class="sp-title-format sp-title-format-title
<div class="sp-title-format sp-title-format-teams sp-title-format-homeaway<?php if ( ! in_array( $title_format, array( 'teams', 'homeaway' ) ) ): ?> hidden<?php endif; ?>"> <?php
if ( $title_format && $title_format != 'title' ) :
?>
hidden<?php endif; ?>"><?php echo esc_html( $event->post_title ); ?></div>
<div class="sp-title-format sp-title-format-teams sp-title-format-homeaway
<?php
if ( ! in_array( $title_format, array( 'teams', 'homeaway' ) ) ) :
?>
hidden<?php endif; ?>">
<?php <?php
if ( $teams ): foreach ( $teams as $team ): if ( $teams ) :
$name = get_the_title( $team ); foreach ( $teams as $team ) :
if ( $name ): $name = get_the_title( $team );
$team_results = sp_array_value( $results, $team, null ); if ( $name ) :
$team_results = sp_array_value( $results, $team, null );
if ( $main_result ): if ( $main_result ) :
$team_result = sp_array_value( $team_results, $main_result, null ); $team_result = sp_array_value( $team_results, $main_result, null );
else: else :
if ( is_array( $team_results ) ): if ( is_array( $team_results ) ) :
end( $team_results ); end( $team_results );
$team_result = prev( $team_results ); $team_result = prev( $team_results );
else: else :
$team_result = null; $team_result = null;
endif;
endif; endif;
endif;
if ( $team_result != null ): if ( $team_result != null ) :
$team_result = apply_filters( 'sportspress_calendar_team_result_admin', $team_result, $event->ID, $team ); $team_result = apply_filters( 'sportspress_calendar_team_result_admin', $team_result, $event->ID, $team );
$main_results[] = $team_result; $main_results[] = $team_result;
unset( $team_results['outcome'] ); unset( $team_results['outcome'] );
$team_results = implode( ' | ', $team_results ); $team_results = implode( ' | ', $team_results );
echo '<a class="result sp-tip" title="' . $team_results . '" href="' . get_edit_post_link( $event->ID ) . '">' . $team_result . '</a> '; echo '<a class="result sp-tip" title="' . $team_results . '" href="' . get_edit_post_link( $event->ID ) . '">' . $team_result . '</a> ';
endif; endif;
echo esc_html( $name ) . '<br>'; echo esc_html( $name ) . '<br>';
endif; endif;
endforeach; else: endforeach; else :
echo '&mdash;'; echo '&mdash;';
endif; endif;
?> ?>
@@ -185,24 +205,24 @@ class SP_Meta_Box_Calendar_Data {
<?php } else { ?> <?php } else { ?>
<td> <td>
<?php <?php
if ( ! empty( $main_results ) ): if ( ! empty( $main_results ) ) :
echo implode( ' - ', $main_results ); echo implode( ' - ', $main_results );
else: else :
echo apply_filters( 'sportspress_event_time_admin', get_post_time( get_option( 'time_format' ), false, $event, true ), $event->ID ); echo apply_filters( 'sportspress_event_time_admin', get_post_time( get_option( 'time_format' ), false, $event, true ), $event->ID );
endif; endif;
?> ?>
</td> </td>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
<?php if ( ( is_array( $usecolumns ) && in_array( 'results', $usecolumns ) ) && in_array( $time_format, array( 'separate', 'results' ) ) ) { ?> <?php if ( ( is_array( $usecolumns ) && in_array( 'results', $usecolumns ) ) && in_array( $time_format, array( 'separate', 'results' ) ) ) { ?>
<td> <td>
<?php <?php
if ( ! empty( $main_results ) ): if ( ! empty( $main_results ) ) :
echo implode( ' - ', $main_results ); echo implode( ' - ', $main_results );
else: else :
echo '-'; echo '-';
endif; endif;
?> ?>
</td> </td>
<?php } ?> <?php } ?>
<?php if ( is_array( $usecolumns ) && in_array( 'league', $usecolumns ) ) { ?> <?php if ( is_array( $usecolumns ) && in_array( 'league', $usecolumns ) ) { ?>
@@ -217,17 +237,17 @@ class SP_Meta_Box_Calendar_Data {
<?php if ( is_array( $usecolumns ) && in_array( 'article', $usecolumns ) ) { ?> <?php if ( is_array( $usecolumns ) && in_array( 'article', $usecolumns ) ) { ?>
<td> <td>
<a href="<?php echo get_edit_post_link( $event->ID ); ?>#sp_articlediv"> <a href="<?php echo get_edit_post_link( $event->ID ); ?>#sp_articlediv">
<?php if ( $video ): ?> <?php if ( $video ) : ?>
<div class="dashicons dashicons-video-alt"></div> <div class="dashicons dashicons-video-alt"></div>
<?php elseif ( has_post_thumbnail( $event->ID ) ): ?> <?php elseif ( has_post_thumbnail( $event->ID ) ) : ?>
<div class="dashicons dashicons-camera"></div> <div class="dashicons dashicons-camera"></div>
<?php endif; ?> <?php endif; ?>
<?php <?php
if ( $event->post_content == null ): if ( $event->post_content == null ) :
_e( 'None', 'sportspress' ); _e( 'None', 'sportspress' );
elseif ( $event->post_status == 'publish' ): elseif ( $event->post_status == 'publish' ) :
_e( 'Recap', 'sportspress' ); _e( 'Recap', 'sportspress' );
else: else :
_e( 'Preview', 'sportspress' ); _e( 'Preview', 'sportspress' );
endif; endif;
?> ?>
@@ -251,7 +271,7 @@ class SP_Meta_Box_Calendar_Data {
<?php <?php
$i++; $i++;
endforeach; endforeach;
else: else :
?> ?>
<tr class="sp-row alternate"> <tr class="sp-row alternate">
<td colspan="<?php echo sizeof( $usecolumns ); ?>"> <td colspan="<?php echo sizeof( $usecolumns ); ?>">
@@ -260,14 +280,14 @@ class SP_Meta_Box_Calendar_Data {
</tr> </tr>
<?php <?php
endif; endif;
else: else :
?> ?>
<tr class="sp-row alternate"> <tr class="sp-row alternate">
<td colspan="<?php echo sizeof( $usecolumns ); ?>"> <td colspan="<?php echo sizeof( $usecolumns ); ?>">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?> <?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
</td> </td>
</tr> </tr>
<?php <?php
endif; endif;
?> ?>
</tbody> </tbody>

View File

@@ -2,13 +2,15 @@
/** /**
* Calendar Details * Calendar Details
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Calendar_Details * SP_Meta_Box_Calendar_Details
@@ -19,22 +21,22 @@ class SP_Meta_Box_Calendar_Details {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$taxonomies = get_object_taxonomies( 'sp_calendar' ); $taxonomies = get_object_taxonomies( 'sp_calendar' );
$caption = get_post_meta( $post->ID, 'sp_caption', true ); $caption = get_post_meta( $post->ID, 'sp_caption', true );
$status = get_post_meta( $post->ID, 'sp_status', true ); $status = get_post_meta( $post->ID, 'sp_status', true );
$date = get_post_meta( $post->ID, 'sp_date', true ); $date = get_post_meta( $post->ID, 'sp_date', true );
$date_from = get_post_meta( $post->ID, 'sp_date_from', true ); $date_from = get_post_meta( $post->ID, 'sp_date_from', true );
$date_to = get_post_meta( $post->ID, 'sp_date_to', true ); $date_to = get_post_meta( $post->ID, 'sp_date_to', true );
$date_past = get_post_meta( $post->ID, 'sp_date_past', true ); $date_past = get_post_meta( $post->ID, 'sp_date_past', true );
$date_future = get_post_meta( $post->ID, 'sp_date_future', true ); $date_future = get_post_meta( $post->ID, 'sp_date_future', true );
$date_relative = get_post_meta( $post->ID, 'sp_date_relative', true ); $date_relative = get_post_meta( $post->ID, 'sp_date_relative', true );
$event_format = get_post_meta( $post->ID, 'sp_event_format', true ); $event_format = get_post_meta( $post->ID, 'sp_event_format', true );
$day = get_post_meta( $post->ID, 'sp_day', true ); $day = get_post_meta( $post->ID, 'sp_day', true );
$teams = get_post_meta( $post->ID, 'sp_team', false ); $teams = get_post_meta( $post->ID, 'sp_team', false );
$players = get_post_meta( $post->ID, 'sp_player', false ); $players = get_post_meta( $post->ID, 'sp_player', false );
$table_id = get_post_meta( $post->ID, 'sp_table', true ); $table_id = get_post_meta( $post->ID, 'sp_table', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true ); $orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true ); $order = get_post_meta( $post->ID, 'sp_order', true );
?> ?>
<div> <div>
<p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p>
@@ -44,8 +46,8 @@ class SP_Meta_Box_Calendar_Details {
<p> <p>
<?php <?php
$args = array( $args = array(
'name' => 'sp_status', 'name' => 'sp_status',
'id' => 'sp_status', 'id' => 'sp_status',
'selected' => $status, 'selected' => $status,
); );
sp_dropdown_statuses( $args ); sp_dropdown_statuses( $args );
@@ -55,7 +57,7 @@ class SP_Meta_Box_Calendar_Details {
<p> <p>
<select name="sp_event_format" class="postform"> <select name="sp_event_format" class="postform">
<option value="all">All</option> <option value="all">All</option>
<?php foreach ( SP()->formats->event as $key => $format ): ?> <?php foreach ( SP()->formats->event as $key => $format ) : ?>
<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $event_format, $key ); ?>><?php echo esc_html( $format ); ?></option> <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $event_format, $key ); ?>><?php echo esc_html( $format ); ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
@@ -65,8 +67,8 @@ class SP_Meta_Box_Calendar_Details {
<p> <p>
<?php <?php
$args = array( $args = array(
'name' => 'sp_date', 'name' => 'sp_date',
'id' => 'sp_date', 'id' => 'sp_date',
'selected' => $date, 'selected' => $date,
); );
sp_dropdown_dates( $args ); sp_dropdown_dates( $args );
@@ -112,17 +114,17 @@ class SP_Meta_Box_Calendar_Details {
<p> <p>
<?php <?php
$args = array( $args = array(
'post_type' => 'sp_team', 'post_type' => 'sp_team',
'name' => 'sp_team[]', 'name' => 'sp_team[]',
'selected' => $teams, 'selected' => $teams,
'values' => 'ID', 'values' => 'ID',
'class' => 'widefat', 'class' => 'widefat',
'property' => 'multiple', 'property' => 'multiple',
'chosen' => true, 'chosen' => true,
'placeholder' => __( 'All', 'sportspress' ), 'placeholder' => __( 'All', 'sportspress' ),
); );
if ( ! sp_dropdown_pages( $args ) ): if ( ! sp_dropdown_pages( $args ) ) :
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) ); sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
endif; endif;
?> ?>
</p> </p>
@@ -130,17 +132,17 @@ class SP_Meta_Box_Calendar_Details {
<p> <p>
<?php <?php
$args = array( $args = array(
'post_type' => 'sp_player', 'post_type' => 'sp_player',
'name' => 'sp_player[]', 'name' => 'sp_player[]',
'selected' => $players, 'selected' => $players,
'values' => 'ID', 'values' => 'ID',
'class' => 'widefat', 'class' => 'widefat',
'property' => 'multiple', 'property' => 'multiple',
'chosen' => true, 'chosen' => true,
'placeholder' => __( 'All', 'sportspress' ), 'placeholder' => __( 'All', 'sportspress' ),
); );
if ( ! sp_dropdown_pages( $args ) ): if ( ! sp_dropdown_pages( $args ) ) :
sp_post_adder( 'sp_player', __( 'Add New', 'sportspress' ) ); sp_post_adder( 'sp_player', __( 'Add New', 'sportspress' ) );
endif; endif;
?> ?>
</p> </p>
@@ -184,4 +186,4 @@ class SP_Meta_Box_Calendar_Details {
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array(), 'int' ) ); sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array(), 'int' ) );
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array(), 'int' ) ); sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array(), 'int' ) );
} }
} }

View File

@@ -4,13 +4,15 @@
* *
* Based on a tutorial by Steve Thomas. * Based on a tutorial by Steve Thomas.
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Calendar_Feeds * SP_Meta_Box_Calendar_Feeds
@@ -21,7 +23,7 @@ class SP_Meta_Box_Calendar_Feeds {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$feeds = new SP_Feeds(); $feeds = new SP_Feeds();
$calendar_feeds = $feeds->calendar; $calendar_feeds = $feeds->calendar;
?> ?>
<div> <div>
@@ -52,4 +54,4 @@ class SP_Meta_Box_Calendar_Feeds {
</div> </div>
<?php <?php
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* Calendar Format * Calendar Format
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Calendar_Format * SP_Meta_Box_Calendar_Format
@@ -23,7 +25,7 @@ class SP_Meta_Box_Calendar_Format {
$the_format = get_post_meta( $post->ID, 'sp_format', true ); $the_format = get_post_meta( $post->ID, 'sp_format', true );
?> ?>
<div id="post-formats-select"> <div id="post-formats-select">
<?php foreach ( SP()->formats->calendar as $key => $format ): ?> <?php foreach ( SP()->formats->calendar as $key => $format ) : ?>
<input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( true, ( $key == 'calendar' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $format ); ?></label><br> <input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( true, ( $key == 'calendar' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $format ); ?></label><br>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
@@ -36,4 +38,4 @@ class SP_Meta_Box_Calendar_Format {
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'calendar', 'text' ) ); update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'calendar', 'text' ) );
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* Calendar Shortcode * Calendar Shortcode
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 1.6.1 * @version 1.6.1
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Calendar_Shortcode * SP_Meta_Box_Calendar_Shortcode
@@ -20,7 +22,9 @@ class SP_Meta_Box_Calendar_Shortcode {
*/ */
public static function output( $post ) { public static function output( $post ) {
$the_format = get_post_meta( $post->ID, 'sp_format', true ); $the_format = get_post_meta( $post->ID, 'sp_format', true );
if ( ! $the_format ) $the_format = 'calendar'; if ( ! $the_format ) {
$the_format = 'calendar';
}
?> ?>
<p class="howto"> <p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?> <?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
@@ -28,4 +32,4 @@ class SP_Meta_Box_Calendar_Shortcode {
<p><input type="text" value="<?php sp_shortcode_template( 'event_' . $the_format, $post->ID ); ?>" readonly="readonly" class="code widefat"></p> <p><input type="text" value="<?php sp_shortcode_template( 'event_' . $the_format, $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php <?php
} }
} }

View File

@@ -2,16 +2,19 @@
/** /**
* Column Details * Column Details
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Config' ) ) if ( ! class_exists( 'SP_Meta_Box_Config' ) ) {
include( 'class-sp-meta-box-config.php' ); require 'class-sp-meta-box-config.php';
}
/** /**
* SP_Meta_Box_Column_Details * SP_Meta_Box_Column_Details
@@ -23,13 +26,15 @@ class SP_Meta_Box_Column_Details extends SP_Meta_Box_Config {
*/ */
public static function output( $post ) { public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' ); wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) ); $equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
$order = get_post_meta( $post->ID, 'sp_order', true ); $order = get_post_meta( $post->ID, 'sp_order', true );
$priority = get_post_meta( $post->ID, 'sp_priority', true ); $priority = get_post_meta( $post->ID, 'sp_priority', true );
$precision = get_post_meta( $post->ID, 'sp_precision', true ); $precision = get_post_meta( $post->ID, 'sp_precision', true );
// Defaults // Defaults
if ( $precision == '' ) $precision = 0; if ( $precision == '' ) {
$precision = 0;
}
?> ?>
<p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p>
<p> <p>
@@ -45,19 +50,22 @@ class SP_Meta_Box_Column_Details extends SP_Meta_Box_Config {
<select name="sp_priority"> <select name="sp_priority">
<?php <?php
$options = array( '0' => __( 'Disable', 'sportspress' ) ); $options = array( '0' => __( 'Disable', 'sportspress' ) );
$count = wp_count_posts( 'sp_column' ); $count = wp_count_posts( 'sp_column' );
for( $i = 1; $i <= $count->publish; $i++ ): for ( $i = 1; $i <= $count->publish; $i++ ) :
$options[ $i ] = $i; $options[ $i ] = $i;
endfor; endfor;
foreach ( $options as $key => $value ): foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $priority, false ), $value ); printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $priority, false ), $value );
endforeach; endforeach;
?> ?>
</select> </select>
<select name="sp_order"> <select name="sp_order">
<?php <?php
$options = array( 'DESC' => __( 'Descending', 'sportspress' ), 'ASC' => __( 'Ascending', 'sportspress' ) ); $options = array(
foreach ( $options as $key => $value ): 'DESC' => __( 'Descending', 'sportspress' ),
'ASC' => __( 'Ascending', 'sportspress' ),
);
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $order, false ), $value ); printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $order, false ), $value );
endforeach; endforeach;
?> ?>
@@ -75,4 +83,4 @@ class SP_Meta_Box_Column_Details extends SP_Meta_Box_Config {
update_post_meta( $post_id, 'sp_priority', sp_array_value( $_POST, 'sp_priority', '0', 'int' ) ); update_post_meta( $post_id, 'sp_priority', sp_array_value( $_POST, 'sp_priority', '0', 'int' ) );
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', 'DESC', 'text' ) ); update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', 'DESC', 'text' ) );
} }
} }

View File

@@ -2,16 +2,19 @@
/** /**
* Column Equation * Column Equation
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 1.9.4 * @version 1.9.4
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Equation' ) ) if ( ! class_exists( 'SP_Meta_Box_Equation' ) ) {
include( 'class-sp-meta-box-equation.php' ); require 'class-sp-meta-box-equation.php';
}
/** /**
* SP_Meta_Box_Column_Equation * SP_Meta_Box_Column_Equation
@@ -25,4 +28,4 @@ class SP_Meta_Box_Column_Equation extends SP_Meta_Box_Equation {
$equation = get_post_meta( $post->ID, 'sp_equation', true ); $equation = get_post_meta( $post->ID, 'sp_equation', true );
self::builder( $post->post_title, $equation, array( 'team_event', 'outcome', 'result', 'subset', 'preset' ) ); self::builder( $post->post_title, $equation, array( 'team_event', 'outcome', 'result', 'subset', 'preset' ) );
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* Config type meta box functions * Config type meta box functions
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 1.0 * @version 1.0
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Config * SP_Meta_Box_Config
@@ -26,14 +28,16 @@ class SP_Meta_Box_Config {
global $wpdb; global $wpdb;
$key = isset( $post['sp_key'] ) ? $post['sp_key'] : null; $key = isset( $post['sp_key'] ) ? $post['sp_key'] : null;
if ( ! $key ) $key = $post['post_title']; if ( ! $key ) {
$id = sp_array_value( $post, 'post_ID', 'var' ); $key = $post['post_title'];
}
$id = sp_array_value( $post, 'post_ID', 'var' );
$title = sp_get_eos_safe_slug( $key, $id ); $title = sp_get_eos_safe_slug( $key, $id );
$check_sql = "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; $check_sql = "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $title, $post['post_type'], $id ) ); $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $title, $post['post_type'], $id ) );
if ( $post_name_check ): if ( $post_name_check ) :
wp_delete_post( $post_name_check, true ); wp_delete_post( $post_name_check, true );
$post['post_status'] = 'draft'; $post['post_status'] = 'draft';
endif; endif;

View File

@@ -2,13 +2,15 @@
/** /**
* Equation meta box functions * Equation meta box functions
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Equation * SP_Meta_Box_Equation
@@ -23,88 +25,146 @@ class SP_Meta_Box_Equation {
} }
public static function builder( $title = 'f(x)', $equation = '', $groups = array() ) { public static function builder( $title = 'f(x)', $equation = '', $groups = array() ) {
if ( $title == '' ) $title = 'f(x)'; if ( $title == '' ) {
$title = 'f(x)';
}
$options = array(); // Multidimensional equation part options $options = array(); // Multidimensional equation part options
$parts = array(); // Flattened equation part options $parts = array(); // Flattened equation part options
// Add groups to options // Add groups to options
foreach ( $groups as $group ): foreach ( $groups as $group ) :
switch ( $group ): switch ( $group ) :
case 'player_event': case 'player_event':
$options[ 'Events' ] = array( '$eventsattended' => __( 'Attended', 'sportspress' ), '$eventsplayed' => __( 'Played', 'sportspress' ), '$eventsstarted' => __( 'Started', 'sportspress' ), '$eventssubbed' => __( 'Substituted', 'sportspress' ), '$eventminutes' => __( 'Minutes', 'sportspress' ) ); $options['Events'] = array(
'$eventsattended' => __( 'Attended', 'sportspress' ),
'$eventsplayed' => __( 'Played', 'sportspress' ),
'$eventsstarted' => __( 'Started', 'sportspress' ),
'$eventssubbed' => __( 'Substituted', 'sportspress' ),
'$eventminutes' => __( 'Minutes', 'sportspress' ),
);
break; break;
case 'team_event': case 'team_event':
$options[ 'Events' ] = array( '$eventsplayed' => __( 'Played', 'sportspress' ), '$eventminutes' => __( 'Minutes', 'sportspress' ) ); $options['Events'] = array(
'$eventsplayed' => __( 'Played', 'sportspress' ),
'$eventminutes' => __( 'Minutes', 'sportspress' ),
);
break; break;
case 'result': case 'result':
$options[ 'Results' ] = self::optgroup( 'sp_result', array( 'for' => '(' . __( 'for', 'sportspress' ) . ')', 'against' => '(' . __( 'against', 'sportspress' ) . ')' ), null, false ); $options['Results'] = self::optgroup(
'sp_result',
array(
'for' => '(' . __( 'for', 'sportspress' ) . ')',
'against' => '(' . __(
'against',
'sportspress'
) . ')',
),
null,
false
);
break; break;
case 'outcome': case 'outcome':
$options[ 'Outcomes' ] = self::optgroup( 'sp_outcome' ); $options['Outcomes'] = self::optgroup( 'sp_outcome' );
break; break;
case 'preset': case 'preset':
$options[ 'Presets' ] = array( '$gamesback' => __( 'Games Back', 'sportspress' ), '$homerecord' => __( 'Home Record', 'sportspress' ), '$awayrecord' => __( 'Away Record', 'sportspress' ), '$streak' => __( 'Streak', 'sportspress' ), '$form' => __( 'Form', 'sportspress' ), '$last5' => __( 'Last 5', 'sportspress' ), '$last10' => __( 'Last 10', 'sportspress' ) ); $options['Presets'] = array(
'$gamesback' => __( 'Games Back', 'sportspress' ),
'$homerecord' => __( 'Home Record', 'sportspress' ),
'$awayrecord' => __( 'Away Record', 'sportspress' ),
'$streak' => __( 'Streak', 'sportspress' ),
'$form' => __( 'Form', 'sportspress' ),
'$last5' => __( 'Last 5', 'sportspress' ),
'$last10' => __( 'Last 10', 'sportspress' ),
);
break; break;
case 'subset': case 'subset':
$options[ 'Subsets' ] = array( '_home' => '@' . __( 'Home', 'sportspress' ), '_away' => '@' . __( 'Away', 'sportspress' ), '_venue' => '@' . __( 'Venue', 'sportspress' ) ); $options['Subsets'] = array(
'_home' => '@' . __( 'Home', 'sportspress' ),
'_away' => '@' . __( 'Away', 'sportspress' ),
'_venue' => '@' . __( 'Venue', 'sportspress' ),
);
break; break;
case 'performance': case 'performance':
$options[ 'Performance' ] = self::optgroup( 'sp_performance' ); $options['Performance'] = self::optgroup( 'sp_performance' );
break; break;
case 'metric': case 'metric':
$options[ 'Metrics' ] = self::optgroup( 'sp_metric' ); $options['Metrics'] = self::optgroup( 'sp_metric' );
break; break;
endswitch; endswitch;
endforeach; endforeach;
// Add operators to options // Add operators to options
$options[ 'Operators' ] = array( '+' => '&#43;', '-' => '&minus;', '*' => '&times;', '/' => '&divide;', '(' => '(', ')' => ')' ); $options['Operators'] = array(
'+' => '&#43;',
'-' => '&minus;',
'*' => '&times;',
'/' => '&divide;',
'(' => '(',
')' => ')',
);
// Create array of constants // Create array of constants
$max = 10; $max = 10;
$constants = array(); $constants = array();
for ( $i = 0; $i <= $max; $i ++ ): for ( $i = 0; $i <= $max; $i ++ ) :
$constants[$i] = $i; $constants[ $i ] = $i;
endfor; endfor;
// Add 100 to constants // Add 100 to constants
$constants[100] = 100; $constants[100] = 100;
// Add constants to options // Add constants to options
$options[ 'Constants' ] = (array) $constants; $options['Constants'] = (array) $constants;
$options = apply_filters( 'sportspress_equation_options', $options ); $options = apply_filters( 'sportspress_equation_options', $options );
?> ?>
<div class="sp-equation-builder"> <div class="sp-equation-builder">
<div class="sp-data-table-container sp-equation-parts"> <div class="sp-data-table-container sp-equation-parts">
<table class="widefat sp-data-table"> <table class="widefat sp-data-table">
<?php $i = 0; foreach ( $options as $label => $option ): ?> <?php $i = 0; foreach ( $options as $label => $option ) : ?>
<tr<?php if ( $i % 2 == 0 ): ?> class="alternate"<?php endif; ?>> <tr
<?php
if ( $i % 2 == 0 ) :
?>
class="alternate"<?php endif; ?>>
<th><?php _e( $label, 'sportspress' ); ?></th> <th><?php _e( $label, 'sportspress' ); ?></th>
<td> <td>
<?php foreach ( $option as $key => $value ): $parts[ $key ] = $value; <?php
?><span class="button" data-variable="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value ); ?></span><?php foreach ( $option as $key => $value ) :
endforeach; ?> $parts[ $key ] = $value;
?>
<span class="button" data-variable="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value ); ?></span>
<?php
endforeach;
?>
</td> </td>
</tr> </tr>
<?php $i++; endforeach; ?> <?php
$i++;
endforeach;
?>
</table> </table>
</div> </div>
<div class="sp-equation"> <div class="sp-equation">
<span class="sp-equation-variable"><?php echo esc_html( $title ); ?> = </span> <span class="sp-equation-variable"><?php echo esc_html( $title ); ?> = </span>
<span class="sp-equation-formula"><?php <span class="sp-equation-formula">
<?php
$equation = trim( $equation ); $equation = trim( $equation );
if ( $equation !== '' ): if ( $equation !== '' ) :
$equation = explode( ' ', $equation ); $equation = explode( ' ', $equation );
foreach ( $equation as $part ): foreach ( $equation as $part ) :
if ( array_key_exists( $part, $parts ) ) { if ( array_key_exists( $part, $parts ) ) {
$name = $parts[ $part ]; $name = $parts[ $part ];
} else { } else {
$name = $part; $name = $part;
} ?><span class="button"><?php echo esc_html( $name ); ?><span class="remove">&times;</span><input type="hidden" name="sp_equation[]" value="<?php echo esc_attr( $part ); ?>"></span><?php }
endforeach; ?>
<span class="button"><?php echo esc_html( $name ); ?><span class="remove">&times;</span><input type="hidden" name="sp_equation[]" value="<?php echo esc_attr( $part ); ?>"></span>
<?php
endforeach;
endif; endif;
?></span> ?>
</span>
</div> </div>
</div> </div>
<?php <?php
@@ -115,21 +175,21 @@ class SP_Meta_Box_Equation {
// Get posts // Get posts
$args = array( $args = array(
'post_type' => $type, 'post_type' => $type,
'numberposts' => -1, 'numberposts' => -1,
'posts_per_page' => -1, 'posts_per_page' => -1,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
'order' => 'ASC', 'order' => 'ASC',
'meta_query' => array( 'meta_query' => array(
'relation' => 'OR', 'relation' => 'OR',
array( array(
'key' => 'sp_format', 'key' => 'sp_format',
'value' => 'number', 'value' => 'number',
'compare' => 'NOT EXISTS', 'compare' => 'NOT EXISTS',
), ),
array( array(
'key' => 'sp_format', 'key' => 'sp_format',
'value' => array( 'equation', 'text' ), 'value' => array( 'equation', 'text' ),
'compare' => 'NOT IN', 'compare' => 'NOT IN',
), ),
), ),
@@ -137,22 +197,24 @@ class SP_Meta_Box_Equation {
$vars = get_posts( $args ); $vars = get_posts( $args );
// Add extra vars to the array // Add extra vars to the array
if ( isset( $defaults ) && is_array( $defaults ) ): if ( isset( $defaults ) && is_array( $defaults ) ) :
foreach ( $defaults as $key => $value ): foreach ( $defaults as $key => $value ) :
$arr[ $key ] = $value; $arr[ $key ] = $value;
endforeach; endforeach;
endif; endif;
// Add vars to the array // Add vars to the array
if ( isset( $variations ) && is_array( $variations ) ): if ( isset( $variations ) && is_array( $variations ) ) :
foreach ( $vars as $var ): foreach ( $vars as $var ) :
if ( $totals ) $arr[ '$' . $var->post_name ] = $var->post_title; if ( $totals ) {
foreach ( $variations as $key => $value ): $arr[ '$' . $var->post_name ] = $var->post_title;
}
foreach ( $variations as $key => $value ) :
$arr[ '$' . $var->post_name . $key ] = $var->post_title . ' ' . $value; $arr[ '$' . $var->post_name . $key ] = $var->post_title . ' ' . $value;
endforeach; endforeach;
endforeach; endforeach;
else: else :
foreach ( $vars as $var ): foreach ( $vars as $var ) :
$arr[ '$' . $var->post_name ] = $var->post_title; $arr[ '$' . $var->post_name ] = $var->post_title;
endforeach; endforeach;
endif; endif;
@@ -162,6 +224,7 @@ class SP_Meta_Box_Equation {
/** /**
* Equation part labels for localization * Equation part labels for localization
*
* @return null * @return null
*/ */
public static function equation_part_labels() { public static function equation_part_labels() {
@@ -170,4 +233,4 @@ class SP_Meta_Box_Equation {
__( 'Subsets', 'sportspress' ); __( 'Subsets', 'sportspress' );
__( 'Constants', 'sportspress' ); __( 'Constants', 'sportspress' );
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* Event Details * Event Details
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Event_Details * SP_Meta_Box_Event_Details
@@ -19,9 +21,9 @@ class SP_Meta_Box_Event_Details {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$day = get_post_meta( $post->ID, 'sp_day', true ); $day = get_post_meta( $post->ID, 'sp_day', true );
$taxonomies = get_object_taxonomies( 'sp_event' ); $taxonomies = get_object_taxonomies( 'sp_event' );
$minutes = get_post_meta( $post->ID, 'sp_minutes', true ); $minutes = get_post_meta( $post->ID, 'sp_minutes', true );
?> ?>
<?php do_action( 'sportspress_event_details_meta_box', $post ); ?> <?php do_action( 'sportspress_event_details_meta_box', $post ); ?>
<div class="sp-event-day-field"> <div class="sp-event-day-field">
@@ -39,7 +41,9 @@ class SP_Meta_Box_Event_Details {
</div> </div>
<?php <?php
foreach ( $taxonomies as $taxonomy ) { foreach ( $taxonomies as $taxonomy ) {
if ( 'sp_venue' == $taxonomy ) continue; if ( 'sp_venue' == $taxonomy ) {
continue;
}
sp_taxonomy_field( $taxonomy, $post, true, true, __( 'None', 'sportspress' ) ); sp_taxonomy_field( $taxonomy, $post, true, true, __( 'None', 'sportspress' ) );
} }
?> ?>
@@ -48,14 +52,14 @@ class SP_Meta_Box_Event_Details {
<p> <p>
<?php <?php
$terms = get_the_terms( $post->ID, 'sp_venue' ); $terms = get_the_terms( $post->ID, 'sp_venue' );
$args = array( $args = array(
'taxonomy' => 'sp_venue', 'taxonomy' => 'sp_venue',
'name' => 'tax_input[sp_venue][]', 'name' => 'tax_input[sp_venue][]',
'class' => 'sp-has-dummy', 'class' => 'sp-has-dummy',
'selected' => sp_get_the_term_id_or_meta( $post->ID, 'sp_venue' ), 'selected' => sp_get_the_term_id_or_meta( $post->ID, 'sp_venue' ),
'values' => 'term_id', 'values' => 'term_id',
'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ), 'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ),
'chosen' => true, 'chosen' => true,
); );
if ( in_array( 'sp_venue', apply_filters( 'sportspress_event_auto_taxonomies', array( 'sp_venue' ) ) ) ) { if ( in_array( 'sp_venue', apply_filters( 'sportspress_event_auto_taxonomies', array( 'sp_venue' ) ) ) ) {
$args['show_option_all'] = __( '(Auto)', 'sportspress' ); $args['show_option_all'] = __( '(Auto)', 'sportspress' );
@@ -75,10 +79,10 @@ class SP_Meta_Box_Event_Details {
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_day', sp_array_value( $_POST, 'sp_day', null, 'text' ) ); update_post_meta( $post_id, 'sp_day', sp_array_value( $_POST, 'sp_day', null, 'text' ) );
update_post_meta( $post_id, 'sp_minutes', sp_array_value( $_POST, 'sp_minutes', get_option( 'sportspress_event_minutes', 90 ), 'int' ) ); update_post_meta( $post_id, 'sp_minutes', sp_array_value( $_POST, 'sp_minutes', get_option( 'sportspress_event_minutes', 90 ), 'int' ) );
$venues = array_filter( sp_array_value( sp_array_value( $_POST, 'tax_input', array() ), 'sp_venue', array() ) ); $venues = array_filter( sp_array_value( sp_array_value( $_POST, 'tax_input', array() ), 'sp_venue', array() ) );
if ( empty( $venues ) ) { if ( empty( $venues ) ) {
$teams = sp_array_value( $_POST, 'sp_team', array(), 'int' ); $teams = sp_array_value( $_POST, 'sp_team', array(), 'int' );
$team = reset( $teams ); $team = reset( $teams );
$venue = sp_get_the_term_id( $team, 'sp_venue' ); $venue = sp_get_the_term_id( $team, 'sp_venue' );
wp_set_post_terms( $post_id, $venue, 'sp_venue' ); wp_set_post_terms( $post_id, $venue, 'sp_venue' );
} }

View File

@@ -2,13 +2,15 @@
/** /**
* Event Format * Event Format
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Event_Format * SP_Meta_Box_Event_Format
@@ -23,7 +25,7 @@ class SP_Meta_Box_Event_Format {
$the_format = get_post_meta( $post->ID, 'sp_format', true ); $the_format = get_post_meta( $post->ID, 'sp_format', true );
?> ?>
<div id="post-formats-select"> <div id="post-formats-select">
<?php foreach ( SP()->formats->event as $key => $format ): ?> <?php foreach ( SP()->formats->event as $key => $format ) : ?>
<input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( true, ( $key == 'league' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $format ); ?></label><br> <input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( true, ( $key == 'league' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $format ); ?></label><br>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
@@ -36,4 +38,4 @@ class SP_Meta_Box_Event_Format {
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'league', 'text' ) ); update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'league', 'text' ) );
} }
} }

View File

@@ -5,34 +5,41 @@
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Event_Mode * SP_Meta_Box_Event_Mode
*/ */
class SP_Meta_Box_Event_Mode { class SP_Meta_Box_Event_Mode {
/** /**
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$the_mode = sp_get_post_mode( $post->ID ); $the_mode = sp_get_post_mode( $post->ID );
?> ?>
<div id="post-formats-select"> <div id="post-formats-select">
<?php foreach ( array( 'team' => __( 'Team vs team', 'sportspress' ), 'player' => __( 'Player vs player', 'sportspress' ) ) as $key => $mode ): ?> <?php
<input type="radio" name="sp_mode" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( $the_mode, $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $mode ); ?></label><br> foreach ( array(
<?php endforeach; ?> 'team' => __( 'Team vs team', 'sportspress' ),
</div> 'player' => __( 'Player vs player', 'sportspress' ),
<?php ) as $key => $mode ) :
} ?>
<input type="radio" name="sp_mode" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( $the_mode, $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $mode ); ?></label><br>
<?php endforeach; ?>
</div>
<?php
}
/** /**
* Save meta box data * Save meta box data
*/ */
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_mode', sp_array_value( $_POST, 'sp_mode', 'team', 'text' ) ); update_post_meta( $post_id, 'sp_mode', sp_array_value( $_POST, 'sp_mode', 'team', 'text' ) );
} }
} }

View File

@@ -6,70 +6,76 @@
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Event_Officials * SP_Meta_Box_Event_Officials
*/ */
class SP_Meta_Box_Event_Officials { class SP_Meta_Box_Event_Officials {
/** /**
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$duties = get_terms( array( $duties = get_terms(
'taxonomy' => 'sp_duty', array(
'hide_empty' => false, 'taxonomy' => 'sp_duty',
'orderby' => 'meta_value_num', 'hide_empty' => false,
'meta_query' => array( 'orderby' => 'meta_value_num',
'relation' => 'OR', 'meta_query' => array(
array( 'relation' => 'OR',
'key' => 'sp_order', array(
'compare' => 'NOT EXISTS' 'key' => 'sp_order',
), 'compare' => 'NOT EXISTS',
array( ),
'key' => 'sp_order', array(
'compare' => 'EXISTS' 'key' => 'sp_order',
), 'compare' => 'EXISTS',
), ),
) ); ),
)
);
$officials = (array) get_post_meta( $post->ID, 'sp_officials', true ); $officials = (array) get_post_meta( $post->ID, 'sp_officials', true );
if ( is_array( $duties ) && sizeof( $duties ) ) { if ( is_array( $duties ) && sizeof( $duties ) ) {
foreach ( $duties as $duty ) { foreach ( $duties as $duty ) {
?> ?>
<p><strong><?php echo esc_html( $duty->name ); ?></strong></p> <p><strong><?php echo esc_html( $duty->name ); ?></strong></p>
<p><?php <p>
$args = array( <?php
'post_type' => 'sp_official', $args = array(
'name' => 'sp_officials[' . $duty->term_id . '][]', 'post_type' => 'sp_official',
'selected' => sp_array_value( $officials, $duty->term_id, array() ), 'name' => 'sp_officials[' . $duty->term_id . '][]',
'values' => 'ID', 'selected' => sp_array_value( $officials, $duty->term_id, array() ),
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Officials', 'sportspress' ) ), 'values' => 'ID',
'class' => 'widefat', 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Officials', 'sportspress' ) ),
'property' => 'multiple', 'class' => 'widefat',
'chosen' => true, 'property' => 'multiple',
); 'chosen' => true,
);
if ( ! sp_dropdown_pages( $args ) ) { if ( ! sp_dropdown_pages( $args ) ) {
sp_post_adder( 'sp_official', __( 'Add New', 'sportspress' ) ); sp_post_adder( 'sp_official', __( 'Add New', 'sportspress' ) );
} }
?></p> ?>
<?php </p>
} <?php
} else { }
sp_taxonomy_adder( 'sp_duty', 'sp_official', __( 'Duty', 'sportspress' ) ); } else {
} sp_taxonomy_adder( 'sp_duty', 'sp_official', __( 'Duty', 'sportspress' ) );
} }
}
/** /**
* Save meta box data * Save meta box data
*/ */
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_officials', sp_array_value( $_POST, 'sp_officials', array(), 'int' ) ); update_post_meta( $post_id, 'sp_officials', sp_array_value( $_POST, 'sp_officials', array(), 'int' ) );
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* Event Performance * Event Performance
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Event_Performance * SP_Meta_Box_Event_Performance
@@ -22,32 +24,35 @@ class SP_Meta_Box_Event_Performance {
$event = new SP_Event( $post ); $event = new SP_Event( $post );
list( $labels, $columns, $stats, $teams, $formats, $order, $timed, $stars ) = $event->performance( true ); list( $labels, $columns, $stats, $teams, $formats, $order, $timed, $stars ) = $event->performance( true );
if ( 'yes' == get_option( 'sportspress_event_performance_show_minutes', 'no' ) ) if ( 'yes' == get_option( 'sportspress_event_performance_show_minutes', 'no' ) ) {
$timeline = $event->timeline( true ); $timeline = $event->timeline( true );
else } else {
$timeline = false; $timeline = false;
}
// Determine if columns are auto or manual // Determine if columns are auto or manual
if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) ) if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) ) {
$manual = true; $manual = true;
else } else {
$manual = false; $manual = false;
}
// Determine if we need checkboxes // Determine if we need checkboxes
if ( $manual ) if ( $manual ) {
$has_checkboxes = true; $has_checkboxes = true;
else } else {
$has_checkboxes = false; $has_checkboxes = false;
}
// Get player number option // Get player number option
$numbers = 'yes' == get_option( 'sportspress_event_show_player_numbers', 'yes' ) ? true : false; $numbers = 'yes' == get_option( 'sportspress_event_show_player_numbers', 'yes' ) ? true : false;
// Get positions // Get positions
$positions = array(); $positions = array();
if ( 'yes' == get_option( 'sportspress_event_show_position', 'yes' ) && taxonomy_exists( 'sp_position' ) ): if ( 'yes' == get_option( 'sportspress_event_show_position', 'yes' ) && taxonomy_exists( 'sp_position' ) ) :
$args = array( $args = array(
'hide_empty' => false, 'hide_empty' => false,
'parent' => 0, 'parent' => 0,
'include_children' => true, 'include_children' => true,
); );
$positions = get_terms( 'sp_position', $args ); $positions = get_terms( 'sp_position', $args );
@@ -55,7 +60,7 @@ class SP_Meta_Box_Event_Performance {
// Apply filters to labels // Apply filters to labels
$labels = apply_filters( 'sportspress_event_performance_labels_admin', $labels ); $labels = apply_filters( 'sportspress_event_performance_labels_admin', $labels );
// Check if individual mode // Check if individual mode
$is_individual = 'player' === sp_get_post_mode( $post->ID ); $is_individual = 'player' === sp_get_post_mode( $post->ID );
@@ -95,27 +100,29 @@ class SP_Meta_Box_Event_Performance {
<?php self::footer( sp_array_value( $stats, -1 ), $labels, 0, $positions, $status, false, $numbers, -1, $formats ); ?> <?php self::footer( sp_array_value( $stats, -1 ), $labels, 0, $positions, $status, false, $numbers, -1, $formats ); ?>
<tbody> <tbody>
<?php <?php
foreach ( $teams as $key => $team_id ): foreach ( $teams as $key => $team_id ) :
if ( -1 == $team_id ) continue; if ( -1 == $team_id ) {
continue;
}
// Get results for players in the team // Get results for players in the team
$players = sp_array_between( (array)get_post_meta( $post_id, 'sp_player', false ), 0, $key ); $players = sp_array_between( (array) get_post_meta( $post_id, 'sp_player', false ), 0, $key );
$players[] = -1; $players[] = -1;
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) ); $data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
// Get team timeline // Get team timeline
if ( is_array( $timeline ) ): if ( is_array( $timeline ) ) :
$team_timeline = (array) sp_array_value( $timeline, $team_id, array() ); $team_timeline = (array) sp_array_value( $timeline, $team_id, array() );
else: else :
$team_timeline = false; $team_timeline = false;
endif; endif;
foreach ( $data as $player_id => $player_performance ): foreach ( $data as $player_id => $player_performance ) :
// Get player timeline // Get player timeline
if ( is_array( $team_timeline ) ): if ( is_array( $team_timeline ) ) :
$player_timeline = (array) sp_array_value( $team_timeline, $player_id, array() ); $player_timeline = (array) sp_array_value( $team_timeline, $player_id, array() );
else: else :
$player_timeline = false; $player_timeline = false;
endif; endif;
@@ -129,27 +136,46 @@ class SP_Meta_Box_Event_Performance {
<?php <?php
} else { } else {
$i = 0; $i = 0;
foreach ( $teams as $key => $team_id ): foreach ( $teams as $key => $team_id ) :
if ( -1 == $team_id ) continue; if ( -1 == $team_id ) {
continue;
}
if ( -1 == $sections ) { if ( -1 == $sections ) {
// Get results for players in the team // Get results for players in the team
$players = sp_array_between( (array)get_post_meta( $post_id, 'sp_player', false ), 0, $key ); $players = sp_array_between( (array) get_post_meta( $post_id, 'sp_player', false ), 0, $key );
$players[] = -1; $players[] = -1;
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) ); $data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
// Get team timeline // Get team timeline
if ( is_array( $timeline ) ): if ( is_array( $timeline ) ) :
$team_timeline = (array) sp_array_value( $timeline, $team_id, array() ); $team_timeline = (array) sp_array_value( $timeline, $team_id, array() );
else: else :
$team_timeline = false; $team_timeline = false;
endif; endif;
?> ?>
<div> <div>
<p> <p>
<strong><?php echo get_the_title( $team_id ); ?></strong> <strong><?php echo get_the_title( $team_id ); ?></strong>
<a class="add-new-h2 sp-add-new-h2" href="<?php echo esc_url( admin_url( add_query_arg( array( 'import' => 'sp_event_performance_csv', 'event' => $post_id, 'team' => $team_id, 'teams' => sizeof( $teams ), 'index' => $key ), 'admin.php' ) ) ); ?>"><?php _e( 'Import', 'sportspress' ); ?></a> <a class="add-new-h2 sp-add-new-h2" href="
<?php
echo esc_url(
admin_url(
add_query_arg(
array(
'import' => 'sp_event_performance_csv',
'event' => $post_id,
'team' => $team_id,
'teams' => sizeof( $teams ),
'index' => $key,
),
'admin.php'
)
)
);
?>
"><?php _e( 'Import', 'sportspress' ); ?></a>
</p> </p>
<?php self::table( $labels, $columns, $data, $team_id, $has_checkboxes && $i === 0, $positions, $status, -1, $formats, $order, $numbers, $team_timeline, $timed, $stars ); ?> <?php self::table( $labels, $columns, $data, $team_id, $has_checkboxes && $i === 0, $positions, $status, -1, $formats, $order, $numbers, $team_timeline, $timed, $stars ); ?>
<?php do_action( 'sportspress_after_event_performance_table_admin', $labels, $columns, $data, $team_id ); ?> <?php do_action( 'sportspress_after_event_performance_table_admin', $labels, $columns, $data, $team_id ); ?>
@@ -158,21 +184,21 @@ class SP_Meta_Box_Event_Performance {
<?php <?php
// Get labels by section // Get labels by section
$args = array( $args = array(
'post_type' => 'sp_performance', 'post_type' => 'sp_performance',
'numberposts' => 100, 'numberposts' => 100,
'posts_per_page' => 100, 'posts_per_page' => 100,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
'order' => 'ASC', 'order' => 'ASC',
'meta_query' => array( 'meta_query' => array(
'relation' => 'OR', 'relation' => 'OR',
array( array(
'key' => 'sp_format', 'key' => 'sp_format',
'value' => 'number', 'value' => 'number',
'compare' => 'NOT EXISTS', 'compare' => 'NOT EXISTS',
), ),
array( array(
'key' => 'sp_format', 'key' => 'sp_format',
'value' => 'equation', 'value' => 'equation',
'compare' => '!=', 'compare' => '!=',
), ),
), ),
@@ -181,12 +207,12 @@ class SP_Meta_Box_Event_Performance {
$performances = get_posts( $args ); $performances = get_posts( $args );
$labels = array( array(), array() ); $labels = array( array(), array() );
foreach ( $performances as $performance ): foreach ( $performances as $performance ) :
$section = get_post_meta( $performance->ID, 'sp_section', true ); $section = get_post_meta( $performance->ID, 'sp_section', true );
if ( '' === $section ) { if ( '' === $section ) {
$section = -1; $section = -1;
} }
switch ( $section ): switch ( $section ) :
case 1: case 1:
$labels[1][ $performance->post_name ] = $performance->post_title; $labels[1][ $performance->post_name ] = $performance->post_title;
break; break;
@@ -194,47 +220,65 @@ class SP_Meta_Box_Event_Performance {
$labels[0][ $performance->post_name ] = $performance->post_title; $labels[0][ $performance->post_name ] = $performance->post_title;
endswitch; endswitch;
endforeach; endforeach;
$offense = (array)get_post_meta( $post_id, 'sp_offense', false ); $offense = (array) get_post_meta( $post_id, 'sp_offense', false );
$defense = (array)get_post_meta( $post_id, 'sp_defense', false ); $defense = (array) get_post_meta( $post_id, 'sp_defense', false );
$data = array(); $data = array();
if ( sizeof( $offense ) || sizeof( $defense ) ) { if ( sizeof( $offense ) || sizeof( $defense ) ) {
// Get results for offensive players in the team // Get results for offensive players in the team
$offense = sp_array_between( $offense, 0, $key ); $offense = sp_array_between( $offense, 0, $key );
$offense[] = -1; $offense[] = -1;
$data[0] = sp_array_combine( $offense, sp_array_value( $stats, $team_id, array() ) ); $data[0] = sp_array_combine( $offense, sp_array_value( $stats, $team_id, array() ) );
// Get results for defensive players in the team // Get results for defensive players in the team
$defense = sp_array_between( $defense, 0, $key ); $defense = sp_array_between( $defense, 0, $key );
$defense[] = -1; $defense[] = -1;
$data[1] = sp_array_combine( $defense, sp_array_value( $stats, $team_id, array() ) ); $data[1] = sp_array_combine( $defense, sp_array_value( $stats, $team_id, array() ) );
} else { } else {
// Get results for all players in the team // Get results for all players in the team
$players = sp_array_between( (array)get_post_meta( $post_id, 'sp_player', false ), 0, $key ); $players = sp_array_between( (array) get_post_meta( $post_id, 'sp_player', false ), 0, $key );
$players[] = -1; $players[] = -1;
$data[0] = $data[1] = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) ); $data[0] = $data[1] = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
} }
// Get team timeline // Get team timeline
if ( is_array( $timeline ) ): if ( is_array( $timeline ) ) :
$team_timeline = (array) sp_array_value( $timeline, $team_id, array() ); $team_timeline = (array) sp_array_value( $timeline, $team_id, array() );
else: else :
$team_timeline = false; $team_timeline = false;
endif; endif;
// Determine order of sections // Determine order of sections
if ( 1 == $sections ) { if ( 1 == $sections ) {
$section_order = array( 1 => __( 'Defense', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ) ); $section_order = array(
1 => __( 'Defense', 'sportspress' ),
0 => __( 'Offense', 'sportspress' ),
);
} else { } else {
$section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) ); $section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) );
} }
foreach ( $section_order as $section_id => $section_label ) { foreach ( $section_order as $section_id => $section_label ) {
?> ?>
<div> <div>
<p> <p>
<strong><?php echo get_the_title( $team_id ); ?> &mdash; <?php echo esc_html( $section_label ); ?></strong> <strong><?php echo get_the_title( $team_id ); ?> &mdash; <?php echo esc_html( $section_label ); ?></strong>
<a class="add-new-h2 sp-add-new-h2" href="<?php echo esc_url( admin_url( add_query_arg( array( 'import' => 'sp_event_performance_csv', 'event' => $post_id, 'team' => $team_id ), 'admin.php' ) ) ); ?>"><?php _e( 'Import', 'sportspress' ); ?></a> <a class="add-new-h2 sp-add-new-h2" href="
<?php
echo esc_url(
admin_url(
add_query_arg(
array(
'import' => 'sp_event_performance_csv',
'event' => $post_id,
'team' => $team_id,
),
'admin.php'
)
)
);
?>
"><?php _e( 'Import', 'sportspress' ); ?></a>
</p> </p>
<?php self::table( $labels[ $section_id ], $columns, $data[ $section_id ], $team_id, ( $has_checkboxes && 0 === $i ), $positions, $status, $section_id, $formats, $order, $numbers, $team_timeline, $timed, $stars ); ?> <?php self::table( $labels[ $section_id ], $columns, $data[ $section_id ], $team_id, ( $has_checkboxes && 0 === $i ), $positions, $status, $section_id, $formats, $order, $numbers, $team_timeline, $timed, $stars ); ?>
<?php do_action( 'sportspress_after_event_performance_table_admin', $labels[ $section_id ], $columns, $data[ $section_id ], $team_id ); ?> <?php do_action( 'sportspress_after_event_performance_table_admin', $labels[ $section_id ], $columns, $data[ $section_id ], $team_id ); ?>
@@ -259,11 +303,11 @@ class SP_Meta_Box_Event_Performance {
<tbody> <tbody>
<?php <?php
if ( 1 == $section && is_array( $order ) && sizeof( $order ) ) { if ( 1 == $section && is_array( $order ) && sizeof( $order ) ) {
$players = array(); $players = array();
$player_order = sp_array_value( $order, $team_id, array() ); $player_order = sp_array_value( $order, $team_id, array() );
if ( is_array( $player_order ) && sizeof( $player_order ) ) { if ( is_array( $player_order ) && sizeof( $player_order ) ) {
foreach ( $player_order as $key ) { foreach ( $player_order as $key ) {
if ( array_key_exists( $key, $data ) ): if ( array_key_exists( $key, $data ) ) :
$players[ $key ] = $data[ $key ]; $players[ $key ] = $data[ $key ];
endif; endif;
} }
@@ -276,12 +320,12 @@ class SP_Meta_Box_Event_Performance {
$data = $players; $data = $players;
} }
foreach ( $data as $player_id => $player_performance ): foreach ( $data as $player_id => $player_performance ) :
// Get player timeline // Get player timeline
if ( is_array( $team_timeline ) ): if ( is_array( $team_timeline ) ) :
$player_timeline = (array) sp_array_value( $team_timeline, $player_id, array() ); $player_timeline = (array) sp_array_value( $team_timeline, $player_id, array() );
else: else :
$player_timeline = false; $player_timeline = false;
endif; endif;
@@ -315,22 +359,28 @@ class SP_Meta_Box_Event_Performance {
<?php _e( 'Position', 'sportspress' ); ?> <?php _e( 'Position', 'sportspress' ); ?>
</th> </th>
<?php } ?> <?php } ?>
<?php $i = 0; foreach ( $labels as $key => $label ): ?> <?php $i = 0; foreach ( $labels as $key => $label ) : ?>
<?php if ( 'equation' === sp_array_value( $formats, $key, 'number' ) ) continue; ?> <?php
if ( 'equation' === sp_array_value( $formats, $key, 'number' ) ) {
continue;}
?>
<th> <th>
<?php if ( $has_checkboxes ): ?> <?php if ( $has_checkboxes ) : ?>
<?php if ( 0 == $i ): ?> <?php if ( 0 == $i ) : ?>
<input type="hidden" name="sp_columns[]" value=""> <input type="hidden" name="sp_columns[]" value="">
<?php endif; ?> <?php endif; ?>
<label for="sp_columns_<?php echo esc_attr( $key ); ?>"> <label for="sp_columns_<?php echo esc_attr( $key ); ?>">
<input type="checkbox" name="sp_columns[]" value="<?php echo esc_attr( $key ); ?>" id="sp_columns_<?php echo esc_attr( $key ); ?>" <?php checked( ! is_array( $columns ) || in_array( $key, $columns ) ); ?>> <input type="checkbox" name="sp_columns[]" value="<?php echo esc_attr( $key ); ?>" id="sp_columns_<?php echo esc_attr( $key ); ?>" <?php checked( ! is_array( $columns ) || in_array( $key, $columns ) ); ?>>
<?php echo esc_html( $label ); ?> <?php echo esc_html( $label ); ?>
</label> </label>
<?php else: ?> <?php else : ?>
<?php echo esc_html( $label ); ?> <?php echo esc_html( $label ); ?>
<?php endif; ?> <?php endif; ?>
</th> </th>
<?php $i++; endforeach; ?> <?php
$i++;
endforeach;
?>
<?php if ( apply_filters( 'sportspress_event_performance_show_status', $status, $section ) ) { ?> <?php if ( apply_filters( 'sportspress_event_performance_show_status', $status, $section ) ) { ?>
<th> <th>
<?php _e( 'Status', 'sportspress' ); ?> <?php _e( 'Status', 'sportspress' ); ?>
@@ -363,13 +413,16 @@ class SP_Meta_Box_Event_Performance {
<?php if ( ! empty( $positions ) ) { ?> <?php if ( ! empty( $positions ) ) { ?>
<td>&nbsp;</td> <td>&nbsp;</td>
<?php } ?> <?php } ?>
<?php foreach( $labels as $column => $label ): <?php
if ( 'equation' === sp_array_value( $formats, $column, 'number' ) ) continue; foreach ( $labels as $column => $label ) :
$player_id = 0; if ( 'equation' === sp_array_value( $formats, $column, 'number' ) ) {
continue;
}
$player_id = 0;
$player_performance = sp_array_value( $data, $player_id, array() ); $player_performance = sp_array_value( $data, $player_id, array() );
$value = sp_array_value( $player_performance, $column, '' ); $value = sp_array_value( $player_performance, $column, '' );
$format = sp_array_value( $formats, $column, 'number' ); $format = sp_array_value( $formats, $column, 'number' );
$placeholder = sp_get_format_placeholder( $format ); $placeholder = sp_get_format_placeholder( $format );
?> ?>
<td><input type="text" name="sp_players[<?php echo esc_attr( $team_id ); ?>][<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>]" placeholder="<?php echo trim( $placeholder ); ?>" value="<?php echo esc_attr( $value ); ?>" data-sp-format="<?php echo esc_attr( $format ); ?>" /></td> <td><input type="text" name="sp_players[<?php echo esc_attr( $team_id ); ?>][<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>]" placeholder="<?php echo trim( $placeholder ); ?>" value="<?php echo esc_attr( $value ); ?>" data-sp-format="<?php echo esc_attr( $format ); ?>" /></td>
<?php endforeach; ?> <?php endforeach; ?>
@@ -389,10 +442,12 @@ class SP_Meta_Box_Event_Performance {
* Admin edit table row * Admin edit table row
*/ */
public static function row( $labels = array(), $player_id = 0, $player_performance = array(), $team_id = 0, $data = array(), $positions = true, $status = true, $sortable = true, $numbers = true, $section = -1, $formats = array(), $player_timeline = array(), $timed = array(), $stars = array() ) { public static function row( $labels = array(), $player_id = 0, $player_performance = array(), $team_id = 0, $data = array(), $positions = true, $status = true, $sortable = true, $numbers = true, $section = -1, $formats = array(), $player_timeline = array(), $timed = array(), $stars = array() ) {
if ( $player_id <= 0 ) return; if ( $player_id <= 0 ) {
return;
}
$stars_type = get_option( 'sportspress_event_performance_stars_type', 0 ); $stars_type = get_option( 'sportspress_event_performance_stars_type', 0 );
$value = sp_array_value( $player_performance, 'number', '' ); $value = sp_array_value( $player_performance, 'number', '' );
?> ?>
<tr class="sp-row sp-post" data-player="<?php echo esc_attr( $player_id ); ?>"> <tr class="sp-row sp-post" data-player="<?php echo esc_attr( $player_id ); ?>">
<?php if ( $sortable ) { ?> <?php if ( $sortable ) { ?>
@@ -413,51 +468,55 @@ class SP_Meta_Box_Event_Performance {
<td> <td>
<?php <?php
$selected = (array) sp_array_value( $player_performance, 'position', null ); $selected = (array) sp_array_value( $player_performance, 'position', null );
if ( $selected == null ): if ( $selected == null ) :
$selected = (array) sp_get_the_term_id( $player_id, 'sp_position', 0 ); $selected = (array) sp_get_the_term_id( $player_id, 'sp_position', 0 );
endif; endif;
$args = array( $args = array(
'taxonomy' => 'sp_position', 'taxonomy' => 'sp_position',
'name' => 'sp_players[' . $team_id . '][' . $player_id . '][position][]', 'name' => 'sp_players[' . $team_id . '][' . $player_id . '][position][]',
'values' => 'term_id', 'values' => 'term_id',
'orderby' => 'meta_value_num', 'orderby' => 'meta_value_num',
'meta_query' => array( 'meta_query' => array(
'relation' => 'OR', 'relation' => 'OR',
array( array(
'key' => 'sp_order', 'key' => 'sp_order',
'compare' => 'NOT EXISTS' 'compare' => 'NOT EXISTS',
), ),
array( array(
'key' => 'sp_order', 'key' => 'sp_order',
'compare' => 'EXISTS' 'compare' => 'EXISTS',
), ),
), ),
'selected' => $selected, 'selected' => $selected,
'class' => 'sp-position', 'class' => 'sp-position',
'property' => 'multiple', 'property' => 'multiple',
'chosen' => true, 'chosen' => true,
'include_children' => ( 'no' == get_option( 'sportspress_event_hide_child_positions', 'no' ) ), 'include_children' => ( 'no' == get_option( 'sportspress_event_hide_child_positions', 'no' ) ),
); );
sp_dropdown_taxonomies( $args ); sp_dropdown_taxonomies( $args );
?> ?>
</td> </td>
<?php } ?> <?php } ?>
<?php foreach( $labels as $column => $label ): <?php
if ( 'equation' === sp_array_value( $formats, $column, 'number' ) ) continue; foreach ( $labels as $column => $label ) :
$value = sp_array_value( $player_performance, $column, '' ); if ( 'equation' === sp_array_value( $formats, $column, 'number' ) ) {
$intval = intval( $value ); continue;
}
$value = sp_array_value( $player_performance, $column, '' );
$intval = intval( $value );
$placeholder = sp_get_format_placeholder( sp_array_value( $formats, $column, 'number' ) ); $placeholder = sp_get_format_placeholder( sp_array_value( $formats, $column, 'number' ) );
?> ?>
<td> <td>
<?php $format = sp_array_value( $formats, $column, 'number' ); ?> <?php $format = sp_array_value( $formats, $column, 'number' ); ?>
<?php if ( 'time' === $format ) { ?> <?php if ( 'time' === $format ) { ?>
<?php <?php
$intval = intval( $value ); $intval = intval( $value );
$timeval = gmdate( 'i:s', $intval ); $timeval = gmdate( 'i:s', $intval );
$hours = floor( $intval / 3600 ); $hours = floor( $intval / 3600 );
if ( '00' != $hours ) if ( '00' != $hours ) {
$timeval = $hours . ':' . $timeval; $timeval = $hours . ':' . $timeval;
}
$timeval = preg_replace( '/^0/', '', $timeval ); $timeval = preg_replace( '/^0/', '', $timeval );
?> ?>
@@ -479,11 +538,14 @@ class SP_Meta_Box_Event_Performance {
} else { } else {
$times = false; $times = false;
} }
if ( is_array( $times ) ) { if ( is_array( $times ) ) {
?> ?>
<hr> <hr>
<?php for ( $i = 0; $i < $intval; $i++ ) { ?><input class="sp-sync-input small-text" type="text" name="sp_timeline[<?php echo esc_attr( $team_id ); ?>][<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>][<?php echo $i; ?>]" value="<?php echo esc_attr( sp_array_value( $times, $i, '' ) ); ?>" placeholder="-" /><?php } ?> <?php
for ( $i = 0; $i < $intval; $i++ ) {
?>
<input class="sp-sync-input small-text" type="text" name="sp_timeline[<?php echo esc_attr( $team_id ); ?>][<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>][<?php echo $i; ?>]" value="<?php echo esc_attr( sp_array_value( $times, $i, '' ) ); ?>" placeholder="-" /><?php } ?>
<span class="description"><?php _e( 'mins', 'sportspress' ); ?></span> <span class="description"><?php _e( 'mins', 'sportspress' ); ?></span>
<?php <?php
} }
@@ -531,17 +593,21 @@ class SP_Meta_Box_Event_Performance {
*/ */
public static function status_select( $team_id, $player_id, $value = null ) { public static function status_select( $team_id, $player_id, $value = null ) {
if ( ! $team_id || ! $player_id ) if ( ! $team_id || ! $player_id ) {
return '&mdash;'; return '&mdash;';
}
$options = apply_filters( 'sportspress_event_performance_status_options', array( $options = apply_filters(
'lineup' => __( 'Starting Lineup', 'sportspress' ), 'sportspress_event_performance_status_options',
'sub' => __( 'Substitute', 'sportspress' ), array(
) ); 'lineup' => __( 'Starting Lineup', 'sportspress' ),
'sub' => __( 'Substitute', 'sportspress' ),
)
);
$output = '<select class="sp-sync-select" name="sp_players[' . $team_id . '][' . $player_id . '][status]">'; $output = '<select class="sp-sync-select" name="sp_players[' . $team_id . '][' . $player_id . '][status]">';
foreach( $options as $key => $name ): foreach ( $options as $key => $name ) :
$output .= '<option value="' . $key . '"' . ( $key == $value ? ' selected' : '' ) . '>' . $name . '</option>'; $output .= '<option value="' . $key . '"' . ( $key == $value ? ' selected' : '' ) . '>' . $name . '</option>';
endforeach; endforeach;
@@ -556,17 +622,20 @@ class SP_Meta_Box_Event_Performance {
*/ */
public static function sub_select( $team_id, $player_id, $value, $data = array() ) { public static function sub_select( $team_id, $player_id, $value, $data = array() ) {
if ( ! $team_id || ! $player_id ) if ( ! $team_id || ! $player_id ) {
return '&mdash;'; return '&mdash;';
}
$output = '<select class="sp-sync-select" name="sp_players[' . $team_id . '][' . $player_id . '][sub]" style="display: none;">'; $output = '<select class="sp-sync-select" name="sp_players[' . $team_id . '][' . $player_id . '][sub]" style="display: none;">';
$output .= '<option value="0">' . __( 'None', 'sportspress' ) . '</option>'; $output .= '<option value="0">' . __( 'None', 'sportspress' ) . '</option>';
// Add players as selectable options // Add players as selectable options
foreach( $data as $id => $performance ): foreach ( $data as $id => $performance ) :
if ( ! $id || $id == $player_id ) continue; if ( ! $id || $id == $player_id ) {
$number = get_post_meta( $id, 'sp_number', true ); continue;
}
$number = get_post_meta( $id, 'sp_number', true );
$output .= '<option value="' . $id . '"' . ( $id == $value ? ' selected' : '' ) . '>' . ( $number ? $number . '. ' : '' ) . get_the_title( $id ) . '</option>'; $output .= '<option value="' . $id . '"' . ( $id == $value ? ' selected' : '' ) . '>' . ( $number ? $number . '. ' : '' ) . get_the_title( $id ) . '</option>';
endforeach; endforeach;

View File

@@ -2,13 +2,15 @@
/** /**
* Event Results * Event Results
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Event_Results * SP_Meta_Box_Event_Results
@@ -20,12 +22,13 @@ class SP_Meta_Box_Event_Results {
*/ */
public static function output( $post ) { public static function output( $post ) {
// Determine if we need checkboxes // Determine if we need checkboxes
if ( 'manual' == get_option( 'sportspress_event_result_columns', 'auto' ) ) if ( 'manual' == get_option( 'sportspress_event_result_columns', 'auto' ) ) {
$has_checkboxes = true; $has_checkboxes = true;
else } else {
$has_checkboxes = false; $has_checkboxes = false;
}
$event = new SP_Event( $post ); $event = new SP_Event( $post );
list( $columns, $usecolumns, $data ) = $event->results( true ); list( $columns, $usecolumns, $data ) = $event->results( true );
self::table( $columns, $usecolumns, $data, $has_checkboxes ); self::table( $columns, $usecolumns, $data, $has_checkboxes );
} }
@@ -34,7 +37,7 @@ class SP_Meta_Box_Event_Results {
* Save meta box data * Save meta box data
*/ */
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
$results = (array)sp_array_value( $_POST, 'sp_results', array(), 'text' ); $results = (array) sp_array_value( $_POST, 'sp_results', array(), 'text' );
$main_result = get_option( 'sportspress_primary_result', null ); $main_result = get_option( 'sportspress_primary_result', null );
// Get player performance // Get player performance
@@ -57,15 +60,25 @@ class SP_Meta_Box_Event_Results {
if ( ! $finished ) { if ( ! $finished ) {
foreach ( $performance as $team => $players ) { foreach ( $performance as $team => $players ) {
foreach ( $players as $player => $pp ) { foreach ( $players as $player => $pp ) {
if ( 0 >= $player ) continue; if ( 0 >= $player ) {
continue;
}
foreach ( $pp as $pk => $pv ) { foreach ( $pp as $pk => $pv ) {
if ( in_array( $pk, apply_filters( 'sportspress_event_auto_result_bypass_keys', array( 'number', 'status', 'sub' ) ) ) ) continue; if ( in_array( $pk, apply_filters( 'sportspress_event_auto_result_bypass_keys', array( 'number', 'status', 'sub' ) ) ) ) {
continue;
}
if ( is_array( $pv ) ) continue; if ( is_array( $pv ) ) {
continue;
}
$pv = trim( $pv ); $pv = trim( $pv );
if ( '' == $pv ) continue; if ( '' == $pv ) {
if ( ! ctype_digit( $pv ) ) continue; continue;
}
if ( ! ctype_digit( $pv ) ) {
continue;
}
$finished = true; $finished = true;
break; break;
@@ -73,16 +86,16 @@ class SP_Meta_Box_Event_Results {
} }
} }
} }
if ( $finished ) { if ( $finished ) {
// Get results with equations // Get results with equations
$args = array( $args = array(
'post_type' => 'sp_result', 'post_type' => 'sp_result',
'numberposts' => -1, 'numberposts' => -1,
'posts_per_page' => -1, 'posts_per_page' => -1,
'meta_query' => array( 'meta_query' => array(
array( array(
'key' => 'sp_equation', 'key' => 'sp_equation',
'compare' => 'EXISTS', 'compare' => 'EXISTS',
), ),
), ),
@@ -96,25 +109,26 @@ class SP_Meta_Box_Event_Results {
$precision[ $result->post_name ] = (int) get_post_meta( $result->ID, 'sp_precision', true ); $precision[ $result->post_name ] = (int) get_post_meta( $result->ID, 'sp_precision', true );
} }
// Apply equations to empty results // Apply equations to empty results
foreach ( $equations as $key => $equation ) { foreach ( $equations as $key => $equation ) {
if ( '' == $equation ) continue; if ( '' == $equation ) {
continue;
}
foreach ( $results as $team => $team_results ) { foreach ( $results as $team => $team_results ) {
if ( '' === sp_array_value( $team_results, $key, '' ) ) { if ( '' === sp_array_value( $team_results, $key, '' ) ) {
$totals = array(); $totals = array();
$players = sp_array_value( $performance, $team, array() ); $players = sp_array_value( $performance, $team, array() );
foreach ( $players as $player => $pp ) { foreach ( $players as $player => $pp ) {
foreach ( $pp as $pk => $pv ) { foreach ( $pp as $pk => $pv ) {
$value = sp_array_value( $totals, $pk, 0 ); $value = sp_array_value( $totals, $pk, 0 );
$value += floatval( $pv ); $value += floatval( $pv );
$totals[ $pk ] = $value; $totals[ $pk ] = $value;
} }
} }
$totals[ 'eventsplayed' ] = 1; $totals['eventsplayed'] = 1;
$totals = apply_filters( 'sportspress_event_result_equation_vars', $totals, $performance, $team ); $totals = apply_filters( 'sportspress_event_result_equation_vars', $totals, $performance, $team );
$results[ $team ][ $key ] = sp_solve( $equation, $totals, sp_array_value( $precision, $key, 0 ), '' ); $results[ $team ][ $key ] = sp_solve( $equation, $totals, sp_array_value( $precision, $key, 0 ), '' );
} }
} }
} }
} }
@@ -138,55 +152,61 @@ class SP_Meta_Box_Event_Results {
if ( count( $primary_results ) && ! in_array( null, $primary_results ) ) { if ( count( $primary_results ) && ! in_array( null, $primary_results ) ) {
if ( count( array_unique( $primary_results ) ) === 1 ) { if ( count( array_unique( $primary_results ) ) === 1 ) {
$args = array( $args = array(
'post_type' => 'sp_outcome', 'post_type' => 'sp_outcome',
'numberposts' => -1, 'numberposts' => -1,
'posts_per_page' => -1, 'posts_per_page' => -1,
'meta_key' => 'sp_condition', 'meta_key' => 'sp_condition',
'meta_value' => '=', 'meta_value' => '=',
); );
$outcomes = get_posts( $args ); $outcomes = get_posts( $args );
foreach ( $results as $team => $team_results ) { foreach ( $results as $team => $team_results ) {
if ( array_key_exists( 'outcome', $team_results ) ) continue; if ( array_key_exists( 'outcome', $team_results ) ) {
continue;
}
if ( $outcomes ) { if ( $outcomes ) {
$results[ $team ][ 'outcome' ] = array(); $results[ $team ]['outcome'] = array();
foreach ( $outcomes as $outcome ) { foreach ( $outcomes as $outcome ) {
$results[ $team ][ 'outcome' ][] = $outcome->post_name; $results[ $team ]['outcome'][] = $outcome->post_name;
} }
} }
} }
} else { } else {
// Get default outcomes // Get default outcomes
$args = array( $args = array(
'post_type' => 'sp_outcome', 'post_type' => 'sp_outcome',
'numberposts' => -1, 'numberposts' => -1,
'posts_per_page' => -1, 'posts_per_page' => -1,
'meta_key' => 'sp_condition', 'meta_key' => 'sp_condition',
'meta_value' => 'else', 'meta_value' => 'else',
); );
$default_outcomes = get_posts( $args ); $default_outcomes = get_posts( $args );
// Get greater than outcomes // Get greater than outcomes
$args = array( $args = array(
'post_type' => 'sp_outcome', 'post_type' => 'sp_outcome',
'numberposts' => -1, 'numberposts' => -1,
'posts_per_page' => -1, 'posts_per_page' => -1,
'meta_key' => 'sp_condition', 'meta_key' => 'sp_condition',
'meta_value' => '>', 'meta_value' => '>',
); );
$gt_outcomes = get_posts( $args ); $gt_outcomes = get_posts( $args );
if ( empty ( $gt_outcomes ) ) $gt_outcomes = $default_outcomes; if ( empty( $gt_outcomes ) ) {
$gt_outcomes = $default_outcomes;
}
// Get less than outcomes // Get less than outcomes
$args = array( $args = array(
'post_type' => 'sp_outcome', 'post_type' => 'sp_outcome',
'numberposts' => -1, 'numberposts' => -1,
'posts_per_page' => -1, 'posts_per_page' => -1,
'meta_key' => 'sp_condition', 'meta_key' => 'sp_condition',
'meta_value' => '<', 'meta_value' => '<',
); );
$lt_outcomes = get_posts( $args ); $lt_outcomes = get_posts( $args );
if ( empty ( $lt_outcomes ) ) $lt_outcomes = $default_outcomes; if ( empty( $lt_outcomes ) ) {
$lt_outcomes = $default_outcomes;
}
// Get min and max values // Get min and max values
$min = min( $primary_results ); $min = min( $primary_results );
@@ -201,9 +221,9 @@ class SP_Meta_Box_Event_Results {
} else { } else {
$outcomes = $default_outcomes; $outcomes = $default_outcomes;
} }
$results[ $key ][ 'outcome' ] = array(); $results[ $key ]['outcome'] = array();
foreach ( $outcomes as $outcome ) { foreach ( $outcomes as $outcome ) {
$results[ $key ][ 'outcome' ][] = $outcome->post_name; $results[ $key ]['outcome'][] = $outcome->post_name;
} }
} }
} }
@@ -220,20 +240,20 @@ class SP_Meta_Box_Event_Results {
*/ */
public static function table( $columns = array(), $usecolumns = array(), $data = array(), $has_checkboxes = false ) { public static function table( $columns = array(), $usecolumns = array(), $data = array(), $has_checkboxes = false ) {
// Get results with equations // Get results with equations
$args = array( $args = array(
'post_type' => 'sp_result', 'post_type' => 'sp_result',
'numberposts' => -1, 'numberposts' => -1,
'posts_per_page' => -1, 'posts_per_page' => -1,
'meta_query' => array( 'meta_query' => array(
array( array(
'key' => 'sp_equation', 'key' => 'sp_equation',
'compare' => 'NOT IN', 'compare' => 'NOT IN',
'value' => null 'value' => null,
), ),
), ),
); );
$dynamic_results = get_posts( $args ); $dynamic_results = get_posts( $args );
$auto_columns = wp_list_pluck( $dynamic_results, 'post_name' ); $auto_columns = wp_list_pluck( $dynamic_results, 'post_name' );
?> ?>
<div class="sp-data-table-container"> <div class="sp-data-table-container">
<table class="widefat sp-data-table sp-results-table"> <table class="widefat sp-data-table sp-results-table">
@@ -242,14 +262,14 @@ class SP_Meta_Box_Event_Results {
<th class="column-team"> <th class="column-team">
<?php _e( 'Team', 'sportspress' ); ?> <?php _e( 'Team', 'sportspress' ); ?>
</th> </th>
<?php foreach ( $columns as $key => $label ): ?> <?php foreach ( $columns as $key => $label ) : ?>
<th class="column-<?php echo esc_attr( $key ); ?>"> <th class="column-<?php echo esc_attr( $key ); ?>">
<?php if ( $has_checkboxes ): ?> <?php if ( $has_checkboxes ) : ?>
<label for="sp_result_columns_<?php echo esc_attr( $key ); ?>"> <label for="sp_result_columns_<?php echo esc_attr( $key ); ?>">
<input type="checkbox" name="sp_result_columns[]" value="<?php echo esc_attr( $key ); ?>" id="sp_result_columns_<?php echo esc_attr( $key ); ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>> <input type="checkbox" name="sp_result_columns[]" value="<?php echo esc_attr( $key ); ?>" id="sp_result_columns_<?php echo esc_attr( $key ); ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
<?php echo esc_html( $label ); ?> <?php echo esc_html( $label ); ?>
</label> </label>
<?php else: ?> <?php else : ?>
<?php echo esc_html( $label ); ?> <?php echo esc_html( $label ); ?>
<?php endif; ?> <?php endif; ?>
</th> </th>
@@ -262,35 +282,48 @@ class SP_Meta_Box_Event_Results {
<tbody> <tbody>
<?php <?php
$i = 0; $i = 0;
foreach ( $data as $team_id => $team_results ): foreach ( $data as $team_id => $team_results ) :
if ( ! $team_id || -1 == $team_id ) continue; if ( ! $team_id || -1 == $team_id ) {
continue;
}
?> ?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>" data-team="<?php echo esc_attr( $team_id ); ?>"> <tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
" data-team="<?php echo esc_attr( $team_id ); ?>">
<td> <td>
<?php echo get_the_title( $team_id ); ?> <?php echo get_the_title( $team_id ); ?>
</td> </td>
<?php foreach( $columns as $column => $label ): <?php
foreach ( $columns as $column => $label ) :
$value = sp_array_value( $team_results, $column, '' ); $value = sp_array_value( $team_results, $column, '' );
?> ?>
<td><input class="sp-team-<?php echo esc_attr( $column ); ?>-input" type="text" name="sp_results[<?php echo esc_attr( $team_id ); ?>][<?php echo esc_attr( $column ); ?>]" value="<?php echo esc_attr( $value ); ?>"<?php if ( in_array( $column, $auto_columns ) ) { ?> placeholder="<?php _e( '(Auto)', 'sportspress' ); ?>"<?php } ?> /></td> <td><input class="sp-team-<?php echo esc_attr( $column ); ?>-input" type="text" name="sp_results[<?php echo esc_attr( $team_id ); ?>][<?php echo esc_attr( $column ); ?>]" value="<?php echo esc_attr( $value ); ?>"
<?php
if ( in_array( $column, $auto_columns ) ) {
?>
placeholder="<?php _e( '(Auto)', 'sportspress' ); ?>"<?php } ?> /></td>
<?php endforeach; ?> <?php endforeach; ?>
<td> <td>
<?php <?php
$values = sp_array_value( $team_results, 'outcome', '' ); $values = sp_array_value( $team_results, 'outcome', '' );
if ( ! is_array( $values ) ) if ( ! is_array( $values ) ) {
$values = array( $values ); $values = array( $values );
}
$args = array( $args = array(
'post_type' => 'sp_outcome', 'post_type' => 'sp_outcome',
'name' => 'sp_results[' . $team_id . '][outcome][]', 'name' => 'sp_results[' . $team_id . '][outcome][]',
'option_none_value' => '', 'option_none_value' => '',
'sort_order' => 'ASC', 'sort_order' => 'ASC',
'sort_column' => 'menu_order', 'sort_column' => 'menu_order',
'selected' => $values, 'selected' => $values,
'class' => 'sp-outcome', 'class' => 'sp-outcome',
'property' => 'multiple', 'property' => 'multiple',
'chosen' => true, 'chosen' => true,
'placeholder' => __( '(Auto)', 'sportspress' ), 'placeholder' => __( '(Auto)', 'sportspress' ),
); );
sp_dropdown_pages( $args ); sp_dropdown_pages( $args );
?> ?>
@@ -305,4 +338,4 @@ class SP_Meta_Box_Event_Results {
</div> </div>
<?php <?php
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* Event Shortcode * Event Shortcode
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Event_Shortcode * SP_Meta_Box_Event_Shortcode
@@ -19,27 +21,30 @@ class SP_Meta_Box_Event_Shortcode {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$shortcodes = apply_filters( 'sportspress_event_shortcodes', array( $shortcodes = apply_filters(
'event_results' => __( 'Results', 'sportspress' ), 'sportspress_event_shortcodes',
'event_details' => __( 'Details', 'sportspress' ), array(
'event_performance' => __( 'Box Score', 'sportspress' ), 'event_results' => __( 'Results', 'sportspress' ),
'event_venue' => __( 'Venue', 'sportspress' ), 'event_details' => __( 'Details', 'sportspress' ),
'event_officials' => __( 'Officials', 'sportspress' ), 'event_performance' => __( 'Box Score', 'sportspress' ),
'event_teams' => __( 'Teams', 'sportspress' ), 'event_venue' => __( 'Venue', 'sportspress' ),
'event_full' => __( 'Full Info', 'sportspress' ), 'event_officials' => __( 'Officials', 'sportspress' ),
) ); 'event_teams' => __( 'Teams', 'sportspress' ),
'event_full' => __( 'Full Info', 'sportspress' ),
)
);
if ( $shortcodes ) { if ( $shortcodes ) {
?> ?>
<p class="howto"> <p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?> <?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
</p> </p>
<?php foreach ( $shortcodes as $id => $label ) { ?> <?php foreach ( $shortcodes as $id => $label ) { ?>
<p> <p>
<strong><?php echo esc_html( $label ); ?></strong> <strong><?php echo esc_html( $label ); ?></strong>
</p> </p>
<p><input type="text" value="<?php sp_shortcode_template( $id, $post->ID ); ?>" readonly="readonly" class="code widefat"></p> <p><input type="text" value="<?php sp_shortcode_template( $id, $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php } ?> <?php } ?>
<?php <?php
} }
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* Event Specs * Event Specs
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Event_Specs * SP_Meta_Box_Event_Specs
@@ -23,23 +25,23 @@ class SP_Meta_Box_Event_Specs {
$metrics = get_post_meta( $post->ID, 'sp_specs', true ); $metrics = get_post_meta( $post->ID, 'sp_specs', true );
$args = array( $args = array(
'post_type' => 'sp_spec', 'post_type' => 'sp_spec',
'numberposts' => -1, 'numberposts' => -1,
'posts_per_page' => -1, 'posts_per_page' => -1,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
'order' => 'ASC', 'order' => 'ASC',
); );
$vars = get_posts( $args ); $vars = get_posts( $args );
if ( $vars ): if ( $vars ) :
foreach ( $vars as $var ): foreach ( $vars as $var ) :
?> ?>
<p><strong><?php echo esc_html( $var->post_title ); ?></strong></p> <p><strong><?php echo esc_html( $var->post_title ); ?></strong></p>
<p><input type="text" name="sp_specs[<?php echo esc_attr( $var->post_name ); ?>]" value="<?php echo esc_attr( sp_array_value( $metrics, $var->post_name, '' ) ); ?>" /></p> <p><input type="text" name="sp_specs[<?php echo esc_attr( $var->post_name ); ?>]" value="<?php echo esc_attr( sp_array_value( $metrics, $var->post_name, '' ) ); ?>" /></p>
<?php <?php
endforeach; endforeach;
else: else :
sp_post_adder( 'sp_spec', __( 'Add New', 'sportspress' ) ); sp_post_adder( 'sp_spec', __( 'Add New', 'sportspress' ) );
endif; endif;
} }
@@ -50,4 +52,4 @@ class SP_Meta_Box_Event_Specs {
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_specs', sp_array_value( $_POST, 'sp_specs', array(), 'text' ) ); update_post_meta( $post_id, 'sp_specs', sp_array_value( $_POST, 'sp_specs', array(), 'text' ) );
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* Event Teams * Event Teams
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Event_Teams * SP_Meta_Box_Event_Teams
@@ -19,32 +21,32 @@ class SP_Meta_Box_Event_Teams {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$limit = get_option( 'sportspress_event_teams', 2 ); $limit = get_option( 'sportspress_event_teams', 2 );
$teams = (array) get_post_meta( $post->ID, 'sp_team', false ); $teams = (array) get_post_meta( $post->ID, 'sp_team', false );
$post_type = sp_get_post_mode_type( $post->ID ); $post_type = sp_get_post_mode_type( $post->ID );
if ( $limit && 'sp_player' !== $post_type ) { if ( $limit && 'sp_player' !== $post_type ) {
for ( $i = 0; $i < $limit; $i ++ ): for ( $i = 0; $i < $limit; $i ++ ) :
$team = array_shift( $teams ); $team = array_shift( $teams );
?> ?>
<div class="sp-instance"> <div class="sp-instance">
<p class="sp-tab-select sp-title-generator"> <p class="sp-tab-select sp-title-generator">
<?php <?php
$args = array( $args = array(
'post_type' => $post_type, 'post_type' => $post_type,
'name' => 'sp_team[]', 'name' => 'sp_team[]',
'class' => 'sportspress-pages', 'class' => 'sportspress-pages',
'show_option_none' => __( '&mdash; None &mdash;', 'sportspress' ), 'show_option_none' => __( '&mdash; None &mdash;', 'sportspress' ),
'values' => 'ID', 'values' => 'ID',
'selected' => $team, 'selected' => $team,
'chosen' => true, 'chosen' => true,
'tax_query' => array(), 'tax_query' => array(),
); );
if ( 'yes' == get_option( 'sportspress_event_filter_teams_by_league', 'no' ) ) { if ( 'yes' == get_option( 'sportspress_event_filter_teams_by_league', 'no' ) ) {
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 ); $league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
if ( $league_id ) { if ( $league_id ) {
$args['tax_query'][] = array( $args['tax_query'][] = array(
'taxonomy' => 'sp_league', 'taxonomy' => 'sp_league',
'terms' => $league_id, 'terms' => $league_id,
); );
} }
} }
@@ -53,7 +55,7 @@ class SP_Meta_Box_Event_Teams {
if ( $season_id ) { if ( $season_id ) {
$args['tax_query'][] = array( $args['tax_query'][] = array(
'taxonomy' => 'sp_season', 'taxonomy' => 'sp_season',
'terms' => $season_id, 'terms' => $season_id,
); );
} }
} }
@@ -64,34 +66,34 @@ class SP_Meta_Box_Event_Teams {
?> ?>
</p> </p>
<?php <?php
$tabs = array(); $tabs = array();
$sections = get_option( 'sportspress_event_performance_sections', -1 ); $sections = get_option( 'sportspress_event_performance_sections', -1 );
if ( 0 == $sections ) { if ( 0 == $sections ) {
$tabs['sp_offense'] = array( $tabs['sp_offense'] = array(
'label' => __( 'Offense', 'sportspress' ), 'label' => __( 'Offense', 'sportspress' ),
'post_type' => 'sp_player', 'post_type' => 'sp_player',
); );
$tabs['sp_defense'] = array( $tabs['sp_defense'] = array(
'label' => __( 'Defense', 'sportspress' ), 'label' => __( 'Defense', 'sportspress' ),
'post_type' => 'sp_player', 'post_type' => 'sp_player',
); );
} elseif ( 1 == $sections ) { } elseif ( 1 == $sections ) {
$tabs['sp_defense'] = array( $tabs['sp_defense'] = array(
'label' => __( 'Defense', 'sportspress' ), 'label' => __( 'Defense', 'sportspress' ),
'post_type' => 'sp_player', 'post_type' => 'sp_player',
); );
$tabs['sp_offense'] = array( $tabs['sp_offense'] = array(
'label' => __( 'Offense', 'sportspress' ), 'label' => __( 'Offense', 'sportspress' ),
'post_type' => 'sp_player', 'post_type' => 'sp_player',
); );
} else { } else {
$tabs['sp_player'] = array( $tabs['sp_player'] = array(
'label' => __( 'Players', 'sportspress' ), 'label' => __( 'Players', 'sportspress' ),
'post_type' => 'sp_player', 'post_type' => 'sp_player',
); );
} }
$tabs['sp_staff'] = array( $tabs['sp_staff'] = array(
'label' => __( 'Staff', 'sportspress' ), 'label' => __( 'Staff', 'sportspress' ),
'post_type' => 'sp_staff', 'post_type' => 'sp_staff',
); );
?> ?>
@@ -99,21 +101,25 @@ class SP_Meta_Box_Event_Teams {
<ul id="sp_team-tabs" class="sp-tab-bar category-tabs"> <ul id="sp_team-tabs" class="sp-tab-bar category-tabs">
<?php <?php
$j = 0; $j = 0;
foreach ( $tabs as $slug => $tab ) { foreach ( $tabs as $slug => $tab ) {
?> ?>
<li class="<?php if ( 0 == $j ) { ?>tabs<?php } ?>"><a href="#<?php echo esc_attr( $slug ); ?>-all"><?php echo esc_html( $tab['label'] ); ?></a></li> <li class="
<?php
if ( 0 == $j ) {
?>
tabs<?php } ?>"><a href="#<?php echo esc_attr( $slug ); ?>-all"><?php echo esc_html( $tab['label'] ); ?></a></li>
<?php <?php
$j++; $j++;
} }
?> ?>
</ul> </ul>
<?php <?php
$j = 0; $j = 0;
foreach ( $tabs as $slug => $tab ) { foreach ( $tabs as $slug => $tab ) {
do_action( 'sportspress_event_teams_meta_box_checklist', $post->ID, $tab['post_type'], ( 0 == $j ? 'block' : 'none' ), $team, $i, $slug ); do_action( 'sportspress_event_teams_meta_box_checklist', $post->ID, $tab['post_type'], ( 0 == $j ? 'block' : 'none' ), $team, $i, $slug );
$j++; $j++;
} }
?> ?>
<?php } ?> <?php } ?>
</div> </div>
<?php <?php
@@ -123,17 +129,17 @@ class SP_Meta_Box_Event_Teams {
<p><strong><?php printf( __( 'Select %s:', 'sportspress' ), sp_get_post_mode_label( $post->ID ) ); ?></strong></p> <p><strong><?php printf( __( 'Select %s:', 'sportspress' ), sp_get_post_mode_label( $post->ID ) ); ?></strong></p>
<?php <?php
$args = array( $args = array(
'post_type' => $post_type, 'post_type' => $post_type,
'name' => 'sp_team[]', 'name' => 'sp_team[]',
'selected' => $teams, 'selected' => $teams,
'values' => 'ID', 'values' => 'ID',
'class' => 'widefat', 'class' => 'widefat',
'property' => 'multiple', 'property' => 'multiple',
'chosen' => true, 'chosen' => true,
'placeholder' => __( 'None', 'sportspress' ), 'placeholder' => __( 'None', 'sportspress' ),
); );
if ( ! sp_dropdown_pages( $args ) ): if ( ! sp_dropdown_pages( $args ) ) :
sp_post_adder( $post_type, __( 'Add New', 'sportspress' ) ); sp_post_adder( $post_type, __( 'Add New', 'sportspress' ) );
endif; endif;
} }
wp_nonce_field( 'sp-get-players', 'sp-get-players-nonce', false ); wp_nonce_field( 'sp-get-players', 'sp-get-players-nonce', false );
@@ -156,7 +162,7 @@ class SP_Meta_Box_Event_Teams {
} }
sp_update_post_meta_recursive( $post_id, 'sp_player', $players ); sp_update_post_meta_recursive( $post_id, 'sp_player', $players );
} else { } else {
$tabs = array(); $tabs = array();
$sections = get_option( 'sportspress_event_performance_sections', -1 ); $sections = get_option( 'sportspress_event_performance_sections', -1 );
if ( -1 == $sections ) { if ( -1 == $sections ) {
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array(), 'int' ) ); sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array(), 'int' ) );

View File

@@ -2,13 +2,15 @@
/** /**
* Event Video * Event Video
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_Event_Video * SP_Meta_Box_Event_Video
@@ -20,8 +22,8 @@ class SP_Meta_Box_Event_Video {
*/ */
public static function output( $post ) { public static function output( $post ) {
$video = get_post_meta( $post->ID, 'sp_video', true ); $video = get_post_meta( $post->ID, 'sp_video', true );
if ( $video ): if ( $video ) :
?> ?>
<fieldset class="sp-video-embed"> <fieldset class="sp-video-embed">
<?php echo apply_filters( 'the_content', '[embed width="254"]' . $video . '[/embed]' ); ?> <?php echo apply_filters( 'the_content', '[embed width="254"]' . $video . '[/embed]' ); ?>
<p><a href="#" class="sp-remove-video"><?php _e( 'Remove video', 'sportspress' ); ?></a></p> <p><a href="#" class="sp-remove-video"><?php _e( 'Remove video', 'sportspress' ); ?></a></p>
@@ -32,7 +34,11 @@ class SP_Meta_Box_Event_Video {
<p><input class="widefat" type="text" name="sp_video" id="sp_video" value="<?php echo esc_url( $video ); ?>"></p> <p><input class="widefat" type="text" name="sp_video" id="sp_video" value="<?php echo esc_url( $video ); ?>"></p>
<p><a href="#" class="sp-remove-video"><?php _e( 'Cancel', 'sportspress' ); ?></a></p> <p><a href="#" class="sp-remove-video"><?php _e( 'Cancel', 'sportspress' ); ?></a></p>
</fieldset> </fieldset>
<fieldset class="sp-video-adder<?php if ( $video ): ?> hidden<?php endif; ?>"> <fieldset class="sp-video-adder
<?php
if ( $video ) :
?>
hidden<?php endif; ?>">
<p><a href="#" class="sp-add-video"><?php _e( 'Add video', 'sportspress' ); ?></a></p> <p><a href="#" class="sp-add-video"><?php _e( 'Add video', 'sportspress' ); ?></a></p>
</fieldset> </fieldset>
<?php <?php
@@ -44,4 +50,4 @@ class SP_Meta_Box_Event_Video {
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_video', sp_array_value( $_POST, 'sp_video', null, 'text' ) ); update_post_meta( $post_id, 'sp_video', sp_array_value( $_POST, 'sp_video', null, 'text' ) );
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* List Columns * List Columns
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_List_Columns * SP_Meta_Box_List_Columns
@@ -19,8 +21,8 @@ class SP_Meta_Box_List_Columns {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$selected = (array)get_post_meta( $post->ID, 'sp_columns', true ); $selected = (array) get_post_meta( $post->ID, 'sp_columns', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true ); $orderby = get_post_meta( $post->ID, 'sp_orderby', true );
?> ?>
<p><strong><?php _e( 'General', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'General', 'sportspress' ); ?></strong></p>
<ul class="categorychecklist form-no-clear"> <ul class="categorychecklist form-no-clear">
@@ -33,7 +35,8 @@ class SP_Meta_Box_List_Columns {
} else { } else {
_e( 'Rank', 'sportspress' ); _e( 'Rank', 'sportspress' );
} }
?> ?>
</label> </label>
</li> </li>
<li> <li>
@@ -72,4 +75,4 @@ class SP_Meta_Box_List_Columns {
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array(), 'key' ) ); update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array(), 'key' ) );
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* List Data * List Data
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_List_Data * SP_Meta_Box_List_Data
@@ -21,8 +23,8 @@ class SP_Meta_Box_List_Data {
public static function output( $post ) { public static function output( $post ) {
global $pagenow; global $pagenow;
if ( is_admin() && in_array( $pagenow, array( 'post-new.php' ) ) && 'sp_list' == get_post_type() ) { if ( is_admin() && in_array( $pagenow, array( 'post-new.php' ) ) && 'sp_list' == get_post_type() ) {
self::table( ); self::table();
}else{ } else {
$list = new SP_Player_List( $post ); $list = new SP_Player_List( $post );
list( $columns, $data, $placeholders, $merged, $orderby ) = $list->data( true ); list( $columns, $data, $placeholders, $merged, $orderby ) = $list->data( true );
$adjustments = $list->adjustments; $adjustments = $list->adjustments;
@@ -62,8 +64,11 @@ class SP_Meta_Box_List_Data {
<?php if ( array_key_exists( 'position', $columns ) ) { ?> <?php if ( array_key_exists( 'position', $columns ) ) { ?>
<th><?php _e( 'Position', 'sportspress' ); ?></th> <th><?php _e( 'Position', 'sportspress' ); ?></th>
<?php } ?> <?php } ?>
<?php foreach ( $columns as $key => $label ): ?> <?php foreach ( $columns as $key => $label ) : ?>
<?php if ( in_array( $key, array( 'number', 'team', 'position' ) ) ) continue; ?> <?php
if ( in_array( $key, array( 'number', 'team', 'position' ) ) ) {
continue;}
?>
<th><label for="sp_columns_<?php echo esc_attr( $key ); ?>"> <th><label for="sp_columns_<?php echo esc_attr( $key ); ?>">
<?php echo esc_html( $label ); ?> <?php echo esc_html( $label ); ?>
</label></th> </label></th>
@@ -72,19 +77,27 @@ class SP_Meta_Box_List_Data {
</thead> </thead>
<tbody> <tbody>
<?php <?php
if ( is_array( $data ) && sizeof( $data ) > 0 ): if ( is_array( $data ) && sizeof( $data ) > 0 ) :
$i = 0; $i = 0;
foreach ( $data as $player_id => $player_stats ): foreach ( $data as $player_id => $player_stats ) :
if ( !$player_id ) continue; if ( ! $player_id ) {
$teams = get_post_meta( $player_id, 'sp_team', false ); continue;
$div = get_term( $player_id, 'sp_season' ); }
$teams = get_post_meta( $player_id, 'sp_team', false );
$div = get_term( $player_id, 'sp_season' );
$number = get_post_meta( $player_id, 'sp_number', true ); $number = get_post_meta( $player_id, 'sp_number', true );
$default_name = sp_array_value( $player_stats, 'name', '' ); $default_name = sp_array_value( $player_stats, 'name', '' );
if ( $default_name == null ) if ( $default_name == null ) {
$default_name = get_the_title( $player_id ); $default_name = get_the_title( $player_id );
}
?> ?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>"> <tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
">
<?php if ( array_key_exists( 'number', $columns ) ) { ?> <?php if ( array_key_exists( 'number', $columns ) ) { ?>
<td> <td>
<?php <?php
@@ -97,7 +110,10 @@ class SP_Meta_Box_List_Data {
</td> </td>
<?php } ?> <?php } ?>
<td> <td>
<?php if ( $show_player_photo ) echo get_the_post_thumbnail( $player_id, 'sportspress-fit-mini' ); ?> <?php
if ( $show_player_photo ) {
echo get_the_post_thumbnail( $player_id, 'sportspress-fit-mini' );}
?>
<span class="sp-default-value"> <span class="sp-default-value">
<span class="sp-default-value-input"><?php echo esc_html( $default_name ); ?></span> <span class="sp-default-value-input"><?php echo esc_html( $default_name ); ?></span>
<a class="dashicons dashicons-edit sp-edit" title="<?php _e( 'Edit', 'sportspress' ); ?>"></a> <a class="dashicons dashicons-edit sp-edit" title="<?php _e( 'Edit', 'sportspress' ); ?>"></a>
@@ -112,14 +128,16 @@ class SP_Meta_Box_List_Data {
<td> <td>
<?php <?php
$selected = sp_array_value( $player_stats, 'team', get_post_meta( get_the_ID(), 'sp_team', true ) ); $selected = sp_array_value( $player_stats, 'team', get_post_meta( get_the_ID(), 'sp_team', true ) );
if ( ! $selected ) $selected = get_post_meta( $player_id, 'sp_team', true ); if ( ! $selected ) {
$selected = get_post_meta( $player_id, 'sp_team', true );
}
$include = get_post_meta( $player_id, 'sp_team' ); $include = get_post_meta( $player_id, 'sp_team' );
$args = array( $args = array(
'post_type' => 'sp_team', 'post_type' => 'sp_team',
'name' => 'sp_players[' . $player_id . '][team]', 'name' => 'sp_players[' . $player_id . '][team]',
'include' => $include, 'include' => $include,
'selected' => $selected, 'selected' => $selected,
'values' => 'ID', 'values' => 'ID',
); );
wp_dropdown_pages( $args ); wp_dropdown_pages( $args );
?> ?>
@@ -129,33 +147,36 @@ class SP_Meta_Box_List_Data {
<td> <td>
<?php <?php
$selected = sp_array_value( $player_stats, 'position', null ); $selected = sp_array_value( $player_stats, 'position', null );
$args = array( $args = array(
'taxonomy' => 'sp_position', 'taxonomy' => 'sp_position',
'name' => 'sp_players[' . $player_id . '][position]', 'name' => 'sp_players[' . $player_id . '][position]',
'show_option_blank' => __( '(Auto)', 'sportspress' ), 'show_option_blank' => __( '(Auto)', 'sportspress' ),
'values' => 'term_id', 'values' => 'term_id',
'orderby' => 'meta_value_num', 'orderby' => 'meta_value_num',
'meta_query' => array( 'meta_query' => array(
'relation' => 'OR', 'relation' => 'OR',
array( array(
'key' => 'sp_order', 'key' => 'sp_order',
'compare' => 'NOT EXISTS' 'compare' => 'NOT EXISTS',
), ),
array( array(
'key' => 'sp_order', 'key' => 'sp_order',
'compare' => 'EXISTS' 'compare' => 'EXISTS',
), ),
), ),
'selected' => $selected, 'selected' => $selected,
'include_children' => ( 'no' == get_option( 'sportspress_event_hide_child_positions', 'no' ) ), 'include_children' => ( 'no' == get_option( 'sportspress_event_hide_child_positions', 'no' ) ),
); );
sp_dropdown_taxonomies( $args ); sp_dropdown_taxonomies( $args );
?> ?>
</td> </td>
<?php } ?> <?php } ?>
<?php foreach( $columns as $column => $label ): <?php
if ( in_array( $column, array( 'number', 'team', 'position' ) ) ) continue; foreach ( $columns as $column => $label ) :
$value = sp_array_value( $player_stats, $column, '' ); if ( in_array( $column, array( 'number', 'team', 'position' ) ) ) {
continue;
}
$value = sp_array_value( $player_stats, $column, '' );
$placeholder = sp_array_value( sp_array_value( $placeholders, $player_id, array() ), $column, 0 ); $placeholder = sp_array_value( sp_array_value( $placeholders, $player_id, array() ), $column, 0 );
?> ?>
<td><input type="text" name="sp_players[<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" data-placeholder="<?php echo esc_attr( $placeholder ); ?>" data-matrix="<?php echo esc_attr( $player_id ); ?>_<?php echo esc_attr( $column ); ?>" data-adjustment="<?php echo esc_attr( sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $column, 0 ) ); ?>" /></td> <td><input type="text" name="sp_players[<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" data-placeholder="<?php echo esc_attr( $placeholder ); ?>" data-matrix="<?php echo esc_attr( $player_id ); ?>_<?php echo esc_attr( $column ); ?>" data-adjustment="<?php echo esc_attr( sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $column, 0 ) ); ?>" /></td>
@@ -164,14 +185,19 @@ class SP_Meta_Box_List_Data {
<?php <?php
$i++; $i++;
endforeach; endforeach;
else: else :
?> ?>
<tr class="sp-row alternate"> <tr class="sp-row alternate">
<td colspan="<?php $colspan = sizeof( $columns ) + ( apply_filters( 'sportspress_has_teams', true ) ? 3 : 2 ); echo esc_attr( $colspan ); ?>"> <td colspan="
<?php
$colspan = sizeof( $columns ) + ( apply_filters( 'sportspress_has_teams', true ) ? 3 : 2 );
echo esc_attr( $colspan );
?>
">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Data', 'sportspress' ) ); ?> <?php printf( __( 'Select %s', 'sportspress' ), __( 'Data', 'sportspress' ) ); ?>
</td> </td>
</tr> </tr>
<?php <?php
endif; endif;
?> ?>
</tbody> </tbody>
@@ -183,27 +209,41 @@ class SP_Meta_Box_List_Data {
<tr> <tr>
<th>#</th> <th>#</th>
<th><?php _e( 'Player', 'sportspress' ); ?></th> <th><?php _e( 'Player', 'sportspress' ); ?></th>
<?php foreach ( $columns as $key => $label ): if ( in_array( $key, array( 'number', 'team', 'position' ) ) ) continue; ?> <?php
foreach ( $columns as $key => $label ) :
if ( in_array( $key, array( 'number', 'team', 'position' ) ) ) {
continue;}
?>
<th><?php echo esc_html( $label ); ?></th> <th><?php echo esc_html( $label ); ?></th>
<?php endforeach; ?> <?php endforeach; ?>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php <?php
if ( is_array( $data ) && sizeof( $data ) > 0 ): if ( is_array( $data ) && sizeof( $data ) > 0 ) :
$i = 0; $i = 0;
foreach ( $data as $player_id => $player_stats ): foreach ( $data as $player_id => $player_stats ) :
if ( !$player_id ) continue; if ( ! $player_id ) {
$div = get_term( $player_id, 'sp_season' ); continue;
}
$div = get_term( $player_id, 'sp_season' );
$number = get_post_meta( $player_id, 'sp_number', true ); $number = get_post_meta( $player_id, 'sp_number', true );
?> ?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>"> <tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
">
<td><?php echo ( $number ? $number : '&nbsp;' ); ?></td> <td><?php echo ( $number ? $number : '&nbsp;' ); ?></td>
<td> <td>
<?php echo get_the_title( $player_id ); ?> <?php echo get_the_title( $player_id ); ?>
</td> </td>
<?php foreach( $columns as $column => $label ): <?php
if ( in_array( $column, array( 'number', 'team', 'position' ) ) ) continue; foreach ( $columns as $column => $label ) :
if ( in_array( $column, array( 'number', 'team', 'position' ) ) ) {
continue;
}
$value = sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $column, '' ); $value = sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $column, '' );
?> ?>
<td><input type="text" name="sp_adjustments[<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="0" data-matrix="<?php echo esc_attr( $player_id ); ?>_<?php echo esc_attr( $column ); ?>" /></td> <td><input type="text" name="sp_adjustments[<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="0" data-matrix="<?php echo esc_attr( $player_id ); ?>_<?php echo esc_attr( $column ); ?>" /></td>
@@ -212,14 +252,19 @@ class SP_Meta_Box_List_Data {
<?php <?php
$i++; $i++;
endforeach; endforeach;
else: else :
?> ?>
<tr class="sp-row alternate"> <tr class="sp-row alternate">
<td colspan="<?php $colspan = sizeof( $columns ) + 3; echo esc_attr( $colspan ); ?>"> <td colspan="
<?php
$colspan = sizeof( $columns ) + 3;
echo esc_attr( $colspan );
?>
">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?> <?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
</td> </td>
</tr> </tr>
<?php <?php
endif; endif;
?> ?>
</tbody> </tbody>
@@ -227,4 +272,4 @@ class SP_Meta_Box_List_Data {
</div> </div>
<?php <?php
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* List Details * List Details
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_List_Details * SP_Meta_Box_List_Details
@@ -19,24 +21,24 @@ class SP_Meta_Box_List_Details {
* Output the metabox * Output the metabox
*/ */
public static function output( $post ) { public static function output( $post ) {
$taxonomies = get_object_taxonomies( 'sp_list' ); $taxonomies = get_object_taxonomies( 'sp_list' );
$caption = get_post_meta( $post->ID, 'sp_caption', true ); $caption = get_post_meta( $post->ID, 'sp_caption', true );
$team_id = get_post_meta( $post->ID, 'sp_team', true ); $team_id = get_post_meta( $post->ID, 'sp_team', true );
$era = get_post_meta( $post->ID, 'sp_era', true ); $era = get_post_meta( $post->ID, 'sp_era', true );
$grouping = get_post_meta( $post->ID, 'sp_grouping', true ); $grouping = get_post_meta( $post->ID, 'sp_grouping', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true ); $orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true ); $order = get_post_meta( $post->ID, 'sp_order', true );
$select = get_post_meta( $post->ID, 'sp_select', true ); $select = get_post_meta( $post->ID, 'sp_select', true );
$number = get_post_meta( $post->ID, 'sp_number', true ); $number = get_post_meta( $post->ID, 'sp_number', true );
$crop = get_post_meta( $post->ID, 'sp_crop', true ); $crop = get_post_meta( $post->ID, 'sp_crop', true );
$date = get_post_meta( $post->ID, 'sp_date', true ); $date = get_post_meta( $post->ID, 'sp_date', true );
$date_from = get_post_meta( $post->ID, 'sp_date_from', true ); $date_from = get_post_meta( $post->ID, 'sp_date_from', true );
$date_to = get_post_meta( $post->ID, 'sp_date_to', true ); $date_to = get_post_meta( $post->ID, 'sp_date_to', true );
$date_past = get_post_meta( $post->ID, 'sp_date_past', true ); $date_past = get_post_meta( $post->ID, 'sp_date_past', true );
$date_relative = get_post_meta( $post->ID, 'sp_date_relative', true ); $date_relative = get_post_meta( $post->ID, 'sp_date_relative', true );
$continents = SP()->countries->continents; $continents = SP()->countries->continents;
$nationalities = get_post_meta( $post->ID, 'sp_nationality', false ); $nationalities = get_post_meta( $post->ID, 'sp_nationality', false );
$default_nationality = get_option( 'sportspress_default_nationality' , false ); $default_nationality = get_option( 'sportspress_default_nationality', false );
?> ?>
<div> <div>
<p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p>
@@ -47,8 +49,8 @@ class SP_Meta_Box_List_Details {
<p> <p>
<?php <?php
$args = array( $args = array(
'name' => 'sp_date', 'name' => 'sp_date',
'id' => 'sp_date', 'id' => 'sp_date',
'selected' => $date, 'selected' => $date,
); );
sp_dropdown_dates( $args ); sp_dropdown_dates( $args );
@@ -85,13 +87,13 @@ class SP_Meta_Box_List_Details {
<p class="sp-tab-select sp-team-era-selector"> <p class="sp-tab-select sp-team-era-selector">
<?php <?php
$args = array( $args = array(
'post_type' => 'sp_team', 'post_type' => 'sp_team',
'name' => 'sp_team', 'name' => 'sp_team',
'show_option_all' => __( 'All', 'sportspress' ), 'show_option_all' => __( 'All', 'sportspress' ),
'selected' => $team_id, 'selected' => $team_id,
'values' => 'ID', 'values' => 'ID',
); );
if ( ! sp_dropdown_pages( $args ) ): if ( ! sp_dropdown_pages( $args ) ) :
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) ); sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
endif; endif;
?> ?>
@@ -103,12 +105,16 @@ class SP_Meta_Box_List_Details {
</p> </p>
<p><strong><?php _e( 'Nationality', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Nationality', 'sportspress' ); ?></strong></p>
<p> <p>
<select id="sp_nationality" name="sp_nationality[]" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple"> <select id="sp_nationality" name="sp_nationality[]" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select
<?php
if ( is_rtl() ) :
?>
chosen-rtl<?php endif; ?>" multiple="multiple">
<option value=""></option> <option value=""></option>
<?php foreach ( $continents as $continent => $countries ): ?> <?php foreach ( $continents as $continent => $countries ) : ?>
<optgroup label="<?php echo esc_attr( $continent ); ?>"> <optgroup label="<?php echo esc_attr( $continent ); ?>">
<?php foreach ( $countries as $code => $country ): ?> <?php foreach ( $countries as $code => $country ) : ?>
<option value="<?php echo esc_attr( $code ); ?>" <?php selected ( in_array( $code, $nationalities ) ); ?>><?php echo esc_html( $country ); ?></option> <option value="<?php echo esc_attr( $code ); ?>" <?php selected( in_array( $code, $nationalities ) ); ?>><?php echo esc_html( $country ); ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</optgroup> </optgroup>
<?php endforeach; ?> <?php endforeach; ?>
@@ -127,12 +133,12 @@ class SP_Meta_Box_List_Details {
$args = array( $args = array(
'prepend_options' => array( 'prepend_options' => array(
'number' => __( 'Squad Number', 'sportspress' ), 'number' => __( 'Squad Number', 'sportspress' ),
'name' => __( 'Name', 'sportspress' ), 'name' => __( 'Name', 'sportspress' ),
), ),
'post_type' => array( 'sp_performance', 'sp_metric', 'sp_statistic' ), 'post_type' => array( 'sp_performance', 'sp_metric', 'sp_statistic' ),
'name' => 'sp_orderby', 'name' => 'sp_orderby',
'selected' => $orderby, 'selected' => $orderby,
'values' => 'slug', 'values' => 'slug',
); );
sp_dropdown_pages( $args ); sp_dropdown_pages( $args );
?> ?>
@@ -160,11 +166,11 @@ class SP_Meta_Box_List_Details {
<?php <?php
if ( 'manual' == $select ) { if ( 'manual' == $select ) {
$player_filters = array( 'sp_league', 'sp_season' ); $player_filters = array( 'sp_league', 'sp_season' );
if ( $team_id ) { if ( $team_id ) {
if ( in_array( $era, [ 'all', 'past' ] ) ) { if ( in_array( $era, array( 'all', 'past' ) ) ) {
$player_filters[] = 'sp_past_team'; $player_filters[] = 'sp_past_team';
} }
if ( in_array( $era, [ 'all', 'current' ] ) ) { if ( in_array( $era, array( 'all', 'current' ) ) ) {
$player_filters[] = 'sp_current_team'; $player_filters[] = 'sp_current_team';
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* List Format * List Format
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9 * @version 2.7.9
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_List_Format * SP_Meta_Box_List_Format
@@ -23,7 +25,7 @@ class SP_Meta_Box_List_Format {
$the_format = get_post_meta( $post->ID, 'sp_format', true ); $the_format = get_post_meta( $post->ID, 'sp_format', true );
?> ?>
<div id="post-formats-select"> <div id="post-formats-select">
<?php foreach ( SP()->formats->list as $key => $format ): ?> <?php foreach ( SP()->formats->list as $key => $format ) : ?>
<input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( true, ( $key == 'list' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $format ); ?></label><br> <input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( true, ( $key == 'list' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $format ); ?></label><br>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
@@ -36,4 +38,4 @@ class SP_Meta_Box_List_Format {
public static function save( $post_id, $post ) { public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'list', 'key' ) ); update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'list', 'key' ) );
} }
} }

View File

@@ -2,13 +2,15 @@
/** /**
* List Shortcode * List Shortcode
* *
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin/Meta_Boxes * @package SportsPress/Admin/Meta_Boxes
* @version 1.6.1 * @version 1.6.1
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/** /**
* SP_Meta_Box_List_Shortcode * SP_Meta_Box_List_Shortcode
@@ -20,7 +22,9 @@ class SP_Meta_Box_List_Shortcode {
*/ */
public static function output( $post ) { public static function output( $post ) {
$the_format = get_post_meta( $post->ID, 'sp_format', true ); $the_format = get_post_meta( $post->ID, 'sp_format', true );
if ( ! $the_format ) $the_format = 'list'; if ( ! $the_format ) {
$the_format = 'list';
}
?> ?>
<p class="howto"> <p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?> <?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
@@ -28,4 +32,4 @@ class SP_Meta_Box_List_Shortcode {
<p><input type="text" value="<?php sp_shortcode_template( 'player_' . $the_format, $post->ID ); ?>" readonly="readonly" class="code widefat"></p> <p><input type="text" value="<?php sp_shortcode_template( 'player_' . $the_format, $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php <?php
} }
} }

Some files were not shown because too many files have changed in this diff Show More