Changeset 1236662
- Timestamp:
- 09/02/2015 09:01:57 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
genesis-featured-images/trunk/genesis-featured-images.php
r1222768 r1236662 4 4 Plugin URI: http://www.wpsmith.net/genesis-featured-images 5 5 Description: Sets a default image for post thumbnails for the Genesis framework. 6 Version: 0.5. 16 Version: 0.5. 7 7 Author: Travis Smith 8 8 Author URI: http://www.wpsmith.net/ … … 27 27 */ 28 28 29 define( 'GFI_DOMAIN' 29 define( 'GFI_DOMAIN', 'genesis-featured-images' ); 30 30 define( 'GFI_PLUGIN_DIR', dirname( __FILE__ ) ); 31 define( 'GFI_URL' , WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)) );31 define( 'GFI_URL') ); 32 32 define( 'GFI_PREFIX', '_gfi_' ); 33 33 34 34 /* Prevent direct access to the plugin */ 35 if ( ! defined( 'ABSPATH' ) ) {36 35 if ( !defined( 'ABSPATH' ) ) { 36 wp_die( __( 'Sorry, you are not allowed to access this page directly.', 'GFI' ) ); 37 37 } 38 38 … … 42 42 * Checks for minimum Genesis Theme version before allowing plugin to activate 43 43 * 44 * @author Nathan Rice45 * @uses gfi_truncate()46 * @since 0.144 * @author Nathan Rice 45 * @uses gfi_truncate() 46 * @since 0.1 47 47 * @version 0.2 48 48 */ 49 49 function gfi_activation_check() { 50 50 51 51 $latest = '2.0'; 52 52 53 $theme_info = get_theme_data( TEMPLATEPATH . '/style.css' );53 s' ); 54 54 55 if ( basename( TEMPLATEPATH ) != 'genesis') {56 57 58 55 ) { 56 deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate ourself 57 wp_die( sprintf( __( 'Sorry, you can\'t activate unless you have installed and actived %1$sGenesis%2$s or a %3$sGenesis Child Theme%2$s', 'GFI' ), '<a href="http://wpsmith.net/go/genesis">', '</a>', '<a href="http://wpsmith.net/go/spthemes">' ) ); 58 } 59 59 60 $version = gfi_truncate( $theme_info['Version'], 3 );60 , 3 ); 61 61 62 63 64 65 62 if ( version_compare( $version, $latest, '<' ) ) { 63 deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate ourself 64 wp_die( sprintf( __( 'Sorry, you can\'t activate without %1$sGenesis %2$s%3$s or greater', 'GFI' ), '<a href="http://wpsmith.net/go/genesis">', $latest, '</a>' ) ); 65 } 66 66 } 67 67 … … 70 70 * Used to cutoff a string to a set length if it exceeds the specified length 71 71 * 72 * @author Nick Croft73 * @since 0.172 * @author Nick Croft 73 * @since 0.1 74 74 * @version 0.2 75 75 76 * @param string $str Any string that might need to be shortened 76 77 * @param string $length Any whole integer 78 77 79 * @return string 78 80 */ 79 function gfi_truncate( $str, $length =10 ) {81 function gfi_truncate( $str, $length10 ) { 80 82 81 82 83 84 85 83 if ( strlen( $str ) > $length ) { 84 return substr( $str, 0, $length ); 85 } else { 86 $res = $str; 87 } 86 88 87 89 return $res; 88 90 } 89 91 90 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ) 92 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'gfi_action_links' ); 91 93 /** 92 94 * Add "Settings" link to plugin page 93 95 */ 94 function gfi_action_links( $links) {96 function gfi_action_links() { 95 97 $gif_settings_link = sprintf( '<a href="%s">%s</a>', 96 98 admin_url( 'admin.php?page=genesis' ), 97 99 __( 'Settings', GFI_DOMAIN ) ); 98 100 array_unshift( $links, $gif_settings_link ); 101 99 102 return $links; 100 103 } … … 124 127 */ 125 128 function gfi_remove_do_post_image() { 126 127 128 129 130 131 132 133 134 135 136 foreach ( $wp_filter as $hook => $priority){137 138 139 foreach( $functions as $function) {140 141 142 143 144 145 146 147 148 149 150 151 152 129 130 global $wp_filter; 131 132 // List of genesis_* functions to be replaced with gfi_* functions. 133 // We save some bytes and add the ubiquitous 'genesis_' later on. 134 $functions = array( 135 'do_post_image', 136 ); 137 138 // Loop through all hooks (yes, stored under the $wp_filter global) 139 { 140 141 // Loop through our array of functions for each hook 142 ) { 143 144 // has_action returns int for the priority 145 if ( $priority = has_action( $hook, 'genesis_' . $function ) ) { 146 147 // If there's a function hooked in, remove the genesis_* function 148 // from whichever hook we're looping through at the time. 149 remove_action( $hook, 'genesis_' . $function, $priority ); 150 151 // Add a replacement function in at an earlier time. 152 add_action( $hook, 'gfi_' . $function, 5 ); 153 } 154 } 155 } 153 156 } 154 157 … … 157 160 global $prefix; 158 161 if ( ! is_singular() && genesis_get_option( 'content_archive_thumbnail' ) ) { 159 if ( genesis_get_custom_field( $prefix . 'custom_feat_img' ) ) 160 $img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_custom_field( $prefix . 'custom_feat_img' ), 'attr' => array( 'class' => 'alignleft post-image' ) ) ); 161 else 162 $img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'alignleft post-image' ) ) ); 162 if ( genesis_get_custom_field( $prefix . 'custom_feat_img' ) ) { 163 $img = genesis_get_image( array( 164 'format' => 'html', 165 'size' => genesis_get_custom_field( $prefix . 'custom_feat_img' ), 166 'attr' => array( 'class' => 'alignleft post-image' ) 167 ) ); 168 } else { 169 $img = genesis_get_image( array( 170 'format' => 'html', 171 'size' => genesis_get_option( 'image_size' ), 172 'attr' => array( 'class' => 'alignleft post-image' ) 173 ) ); 174 } 163 175 printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), $img ); 164 176 } … … 166 178 167 179 168 169 180 ?>
Note: See TracChangeset
for help on using the changeset viewer.