Add filter to shortcode template meta box

This commit is contained in:
Brian Miyaji
2015-02-09 13:43:17 +11:00
parent 440e00ecf3
commit 1e35d206fa
8 changed files with 51 additions and 9 deletions

View File

@@ -25,7 +25,7 @@ class SP_Meta_Box_Calendar_Shortcode {
<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>
<p><input type="text" value="[event_<?php echo $the_format; ?> <?php echo $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

@@ -33,7 +33,7 @@ class SP_Meta_Box_Event_Shortcode {
<p> <p>
<strong><?php echo $label; ?></strong> <strong><?php echo $label; ?></strong>
</p> </p>
<p><input type="text" value="[<?php echo $id; ?> <?php echo $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

@@ -25,7 +25,7 @@ class SP_Meta_Box_List_Shortcode {
<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>
<p><input type="text" value="[player_<?php echo $the_format; ?> <?php echo $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
} }
} }

View File

@@ -26,11 +26,11 @@ class SP_Meta_Box_Player_Shortcode {
<p> <p>
<strong><?php _e( 'Details', 'sportspress' ); ?></strong> <strong><?php _e( 'Details', 'sportspress' ); ?></strong>
</p> </p>
<p><input type="text" value="[player_details <?php echo $post->ID; ?>]" readonly="readonly" class="code widefat"></p> <p><input type="text" value="<?php sp_shortcode_template( 'player_details', $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<p> <p>
<strong><?php _e( 'Statistics', 'sportspress' ); ?></strong> <strong><?php _e( 'Statistics', 'sportspress' ); ?></strong>
</p> </p>
<p><input type="text" value="[player_statistics <?php echo $post->ID; ?>]" readonly="readonly" class="code widefat"></p> <p><input type="text" value="<?php sp_shortcode_template( 'player_statistics', $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php <?php
} }
} }

View File

@@ -23,7 +23,7 @@ class SP_Meta_Box_Staff_Shortcode {
<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>
<p><input type="text" value="[staff <?php echo $post->ID; ?>]" readonly="readonly" class="code widefat"></p> <p><input type="text" value="<?php sp_shortcode_template( 'staff', $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php <?php
} }
} }

View File

@@ -23,7 +23,7 @@ class SP_Meta_Box_Table_Shortcode {
<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>
<p><input type="text" value="[league_table <?php echo $post->ID; ?>]" readonly="readonly" class="code widefat"></p> <p><input type="text" value="<?php sp_shortcode_template( 'league_table', $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php <?php
} }
} }

View File

@@ -74,11 +74,11 @@ function sp_get_template( $template_name, $args = array(), $template_path = '',
return; return;
} }
do_action( 'sportspress_before_template_part', $template_name, $template_path, $located, $args ); do_action( 'sportspress_before_template', $template_name, $template_path, $located, $args );
include( $located ); include( $located );
do_action( 'sportspress_after_template_part', $template_name, $template_path, $located, $args ); do_action( 'sportspress_after_template', $template_name, $template_path, $located, $args );
} }
/** /**
@@ -1196,6 +1196,10 @@ function sp_get_text_options() {
return array_unique( $strings ); return array_unique( $strings );
} }
/**
* Display a link to review SportsPress
* @return null
*/
function sp_review_link() { function sp_review_link() {
?> ?>
<p> <p>
@@ -1205,3 +1209,30 @@ function sp_review_link() {
</p> </p>
<?php <?php
} }
/**
* Return shortcode template for meta boxes
* @return null
*/
function sp_get_shortcode_template( $shortcode, $id = null, $args = array() ) {
$args = apply_filters( 'sportspress_shortcode_template_args', $args );
$output = '[' . $shortcode;
if ( $id ) {
$output .= ' ' . $id;
}
if ( sizeof( $args ) ) {
foreach ( $args as $key => $value ) {
$output .= ' ' . $key . '="' . $value . '"';
}
}
$output .= ']';
return esc_attr( $output );
}
/**
* Display shortcode template for meta boxes
* @return null
*/
function sp_shortcode_template( $shortcode, $id = null, $args = array() ) {
echo sp_get_shortcode_template( $shortcode, $id, $args );
}

View File

@@ -19,6 +19,17 @@ add_shortcode( 'league-table', 'SP_Shortcodes::league_table' );
add_shortcode( 'player-list', 'SP_Shortcodes::player_list' ); add_shortcode( 'player-list', 'SP_Shortcodes::player_list' );
add_shortcode( 'player-gallery', 'SP_Shortcodes::player_gallery' ); add_shortcode( 'player-gallery', 'SP_Shortcodes::player_gallery' );
/* Actions */
function sportspress_before_template_part_action( $template_name, $template_path, $located, $args ) {
do_action( 'sportspress_before_template_part', $template_name, $template_path, $located, $args );
}
add_action( 'sportspress_before_template', 'sportspress_before_template_part_action', 10, 4 );
function sportspress_after_template_part_action( $template_name, $template_path, $located, $args ) {
do_action( 'sportspress_after_template_part', $template_name, $template_path, $located, $args );
}
add_action( 'sportspress_after_template', 'sportspress_after_template_part_action', 10, 4 );
/* Functions */ /* Functions */
function sportspress_flush_rewrite_rules() { function sportspress_flush_rewrite_rules() {
return sp_flush_rewrite_rules(); return sp_flush_rewrite_rules();