Jesse Graupmann
Forum Replies Created
-
Turns out your plugin is doing what it needs to, it just won’t add the link if it thinks it’s on the wrong page.
In your plugins/enable-media-replace/enable-media-replace.php just change line 69 from
if ($on_media_edit_screen == true) {to
if ($on_media_edit_screen == true || substr($post->post_mime_type, 0, 5) == 'image') {BOOM!
Now hard would it be to add a ‘SWAP’ button in addition to the ‘REPLACE’?
😉 Thanks. I’ll have to do a little more research. Let me know if you beat me to it.
This is where I was referring to:
http://wpseek.com/function/wp_image_editor/
function wp_image_editor($post_id, $msg = false)If you added this code to line 148 of that file you can see that anywhere you try to edit a photo, you can always access the replace button.
<div class="imgedit-group"> <div class="imgedit-group"> <div class="imgedit-submit"> <input type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'your-replace-function')" class="button button-primary" value="<?php esc_attr_e( 'Replace Image' ); ?>" /> </div> </div> </div>I realized I don’t see any hooks other than the javascript imageEdit.init, and I don’t really know if that is a hook.
<script type="text/javascript">jQuery( function() { imageEdit.init(<?php echo $post_id; ?>); });</script>This flow works:
Media > Library > Edit
http://wordpress/wp-admin/post.php?post=2088&action=editThis flow doesn’t Work:
Post > Add New > Set Featured Image > Edit Image
http://www.example.com/wp-admin/post.php?post=2088&action=edit&image-editorAll Posts > Edit > ACF Image (Edit Link) > Edit Image
http://www.example.com/wp-admin/post.php?post=959&action=edit#, http://www.example.com/wp-admin/post.php?post=2088&action=edit&image-editorI use Advanced Custom Fields (http://www.advancedcustomfields.com/pro) and occasionally the Post Thumbnail which is set via ‘Set Featured Image’. The problem is they only show controls to rotate, scale, crop and thumbnail settings. It’s all the information you will see when you click that ‘Edit Image’ button in your screenshot. But because it’s only THAT information, your link is not getting rendered inside that area. So the only way to access it is to go through the library – not directly from a Featured Image or ACF Image field.
So I need your Replace Image to render UI inside the ‘Edit Image’ section, not just the images’s edit page accessed from the Library tab.
Does that make more sense?
Forum: Plugins
In reply to: [WordPress Social Login] How to show social profile avatar in a loop?Or, if you want a more condensed version
foreach(get_users(array('role'=>'traveller')) as $user ) { echo sprintf('%2$s<br /><img src="%1$s" title="%2$s" alt="%2$s" width="%3$s" height="%3$s" ><br />', get_best_avatar( $user -> ID, 150 ), $user -> display_name, 150); }Forum: Plugins
In reply to: [WordPress Social Login] How to show social profile avatar in a loop?Riffaz,
First, to generate the image you need to make sure ‘get_best_gravatar’, ‘get_best_avatar’, and ‘wsl_get_user_custom_avatar’ are functions that exist in your project. Ideally just throw them in your functions.php somewhere and your page/templates will be able to use them.
After that, you just need to pass the correct variables. In your case you have the $user object. For the image title you’ll need the user’s display name and for the image avatar function we need the user’s ID. This is a number and is used by ‘get_best_avatar’ to get all the items it needs for the rest of the stuff.
IN FUNCTIONS.PHP
if(!function_exists('get_best_gravatar')){ /** * @source http://gravatar.com/site/implement/images/php/ */ function get_best_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) { $url = 'http://www.gravatar.com/avatar/'; $url .= md5( strtolower( trim( $email ) ) ); $url .= "?s=$s&d=$d&r=$r"; if ( $img ) { $url = '<img src="' . $url . '"'; foreach ( $atts as $key => $val ) $url .= ' ' . $key . '="' . $val . '"'; $url .= ' />'; } return $url; } } if(!function_exists('get_best_avatar')){ function get_best_avatar ($user_id, $size=150){ $avatar = FALSE; if(function_exists('wsl_get_user_custom_avatar')){ $avatar = wsl_get_user_custom_avatar( $user_id ); } if(!$avatar){ $email = get_the_author_meta ('email', $user_id); $avatar = get_best_gravatar ($email, $size, 'mm', 'g', false); } return $avatar; } }ON YOUR CONTRIBUTORS PAGE
$size = 150; $users = get_users(array('role'=>'traveller')); foreach( $users as $user ) { $avatar = get_best_avatar( $user -> ID, $size ); // Ideally show a user's chosen display name, nicename is their login and you don't usually want to show that off. $author_name = empty( $user -> display_name ) ? $user -> user_nicename : $user -> display_name; echo $author_name; ?> <br /> <img src="<?php echo $avatar; ?>" title="<?php echo $author_name; ?>" src="" alt="<?php echo $author_name; ?>" width="<?php echo $size; ?>" height="<?php echo $size; ?>" /> <br /> <?php }Enjoy!
Forum: Plugins
In reply to: [WordPress Social Login] How to show social profile avatar in a loop?The wsl_get_user_custom_avatar function works for me. But it would seem $post->post_author is not the ID of the author. And your $user_id variable is never defined so it will always break. Below is a version that is working for me. I’ve added a gravatar fallback for when the image isn’t found. If you check the ‘get_best_gravatar’ function, you’ll see that $d can be a fallback for gravatar.
<?php if(!function_exists('get_best_gravatar')){ /** * @source http://gravatar.com/site/implement/images/php/ */ function get_best_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) { $url = 'http://www.gravatar.com/avatar/'; $url .= md5( strtolower( trim( $email ) ) ); $url .= "?s=$s&d=$d&r=$r"; if ( $img ) { $url = '<img src="' . $url . '"'; foreach ( $atts as $key => $val ) $url .= ' ' . $key . '="' . $val . '"'; $url .= ' />'; } return $url; } } if(!function_exists('get_best_avatar')){ function get_best_avatar ($user_id, $size=150){ $avatar = wsl_get_user_custom_avatar( $user_id ); if(!$avatar){ $email = get_the_author_meta ('email', $user_id); $avatar = get_best_gravatar ($email, $size, 'mm', 'g', false); } return $avatar; } } // query $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'traveller', 'posts_per_page' => 15, 'orderby' => 'rand', 'paged' => $paged ); query_posts( $args); // the post while (have_posts()) : the_post(); // author $author_id = get_the_author_meta('ID', $post->post_author); //$author_id = 10; // override for known id $author_display = get_the_author_meta('display_name', $author_id); $avatar = get_best_avatar($author_id, 150); // output the_title(); ?> <br/> <img src="<?php echo $avatar; ?>" title="<?php echo $author_display; ?>" src="" alt="<?php echo $author_display; ?>" width="150" height="150" /> <br/> <?php endwhile; ?>Forum: Plugins
In reply to: [WordPress Social Login] How to change the iconsYou might be interested in Generate wsl widget with Font Awesome icons from the code snipets page.
function wsl_use_fontawesome_icons( $provider_id, $provider_name, $authenticate_url ) { ?> <a rel = "nofollow" href = "<?php echo $authenticate_url; ?>" data-provider = "<?php echo $provider_id ?>" class = "wp-social-login-provider wp-social-login-provider-<?php echo strtolower( $provider_id ); ?>" > <span> <i class="fa fa-<?php echo strtolower( $provider_id ); ?>"></i> Sign in with <?php echo $provider_name; ?> </span> </a> <?php } add_filter( 'wsl_render_auth_widget_alter_provider_icon_markup', 'wsl_use_fontawesome_icons', 10, 3 );Take a look at ACF’s flexible content.
Forum: Plugins
In reply to: [Advanced Custom Fields: Nav Menu Field] ACF 5 compatibilityI just went ahead and created a GitHub repo that includes the code above + the original plugin.
https://github.com/jgraup/advanced-custom-fields-nav-menu-field
Forum: Plugins
In reply to: [Advanced Custom Fields: Nav Menu Field] ACF 5 compatibilityI can’t seem to edit the post above so I’ll supply a fix for #2 here. ACF had changed the way variables are stored and recalled. In addition, the function ‘format_value_for_api’ was changed to ‘format_value’.
#2 [FIXED]
/plugins/advanced-custom-fields-nav-menu-field/nav-menu-v5.php<?php // ACF Pro v5 Port by Jesse Graupmann (http://justgooddesign.com) // Original from http://faisonz.com/wordpress-plugins/advanced-custom-fields-nav-menu-field/ by Faison Zutavern (http://faisonz.com) class acf_field_nav_menu_v5 extends acf_field { var $settings,$defaults; function __construct() { // vars $this->name = 'nav_menu'; $this->label = __('Nav Menu', 'acf'); $this->category = __("Relational",'acf'); // Basic, Content, Choice, etc $this->defaults = array( 'save_format' => 'id', 'allow_null' => 0, 'container' => 'div' ); parent::__construct(); $this->settings = array( 'path' => apply_filters('acf/helpers/get_path', __FILE__), 'dir' => apply_filters('acf/helpers/get_dir', __FILE__), 'version' => '1.1.2' ); } function render_field_settings( $field ) { // Create Field Options HTML acf_render_field_setting( $field, array( 'label' => __('Return Value','acf'), 'type' => 'radio', 'name' => 'save_format', 'layout' => 'horizontal', 'choices' => array( 'object' => __("Nav Menu Object",'acf'), 'menu' => __("Nav Menu HTML",'acf'), 'id' => __("Nav Menu ID",'acf') ) )); $choices = $this->get_allowed_nav_container_tags(); $usingMenu = $field['save_format'] === 'menu' ? '*' : '.'; acf_render_field_setting( $field, array( 'label' => __('Menu Container','acf'), 'instructions' => __('What to wrap the Menu\'s ul with.<br />Only used when returning HTML' . $usingMenu,'acf'), 'type' => 'select', 'name' => 'container', 'choices' => $choices )); acf_render_field_setting( $field, array( 'label' => __('Allow Null?','acf'), 'type' => 'radio', 'name' => 'allow_null', 'choices' => array( 1 => __("Yes",'acf'), 0 => __("No",'acf'), ), 'layout' => 'horizontal', )); } function render_field( $field ) { // create Field HTML echo sprintf( '<select id="%d" class="%s" name="%s">', $field['id'], $field['class'], $field['name'] ); if( $field['allow_null'] ) { echo '<option value=""> - Select - </option>'; } // Nav Menus $nav_menus = $this->get_nav_menus(); foreach( $nav_menus as $nav_menu_id => $nav_menu_name ) { $selected = selected( $field['value'], $nav_menu_id ); echo sprintf( '<option value="%1$d" %3$s>%2$s</option>', $nav_menu_id, $nav_menu_name, $selected ); } echo '</select>'; } function get_nav_menus() { $navs = get_terms('nav_menu', array( 'hide_empty' => false ) ); $nav_menus = array(); foreach( $navs as $nav ) { $nav_menus[ $nav->term_id ] = $nav->name; } return $nav_menus; } function get_allowed_nav_container_tags() { $tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) ); $formatted_tags = array( array( '0' => 'None' ) ); foreach( $tags as $tag ) { $formatted_tags[0][$tag] = ucfirst( $tag ); } return $formatted_tags; } function format_value( $value, $post_id, $field ) { // defaults $field = array_merge($this->defaults, $field); if( !$value ) { return false; } // check format if( $field['save_format'] == 'object' ) { $wp_menu_object = wp_get_nav_menu_object( $value ); if( !$wp_menu_object ) { return false; } $menu_object = new stdClass; $menu_object->ID = $wp_menu_object->term_id; $menu_object->name = $wp_menu_object->name; $menu_object->slug = $wp_menu_object->slug; $menu_object->count = $wp_menu_object->count; return $menu_object; } elseif( $field['save_format'] == 'menu' ) { ob_start(); wp_nav_menu( array( 'menu' => $value, 'container' => $field['container'] ) ); return ob_get_clean(); } return $value; } } // create field new acf_field_nav_menu_v5();Does it help to get the post’s ID first?
http://www.advancedcustomfields.com/resources/get_field/
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php global $post; $post_ID = $post->ID; echo get_field( "first_name", $post_ID ); ?> <?php endwhile; endif; ?>Forum: Plugins
In reply to: [Advanced Custom Fields: Nav Menu Field] I am stupid….HelpHey firstforward,
You shouldn’t hard-code your location, just get a relative path from the functions.php to your nav-menu-v4.php. You should also put your ‘advanced-custom-fields-nav-menu-field’ in the plugins folder or inside your theme’s folder — just not at the root /wp-content/themes/ folder.
Be sure to adjust $relativePath to whatever it takes to get to your file.
/** * Assumes we are in functions.php, importing the file from inside the plugins directory. * * /wp-content/themes/my_theme/functions.php <- you are here * /wp-content/plugins/advanced-custom-fields-nav-menu-field/nav-menu-v4.php * */ // __FILE__ is functions.php and now we'll have an absolute path to its folder $functionsDir = dirname(__FILE__); $relativePath = '/../../plugins/advanced-custom-fields-nav-menu-field/nav-menu-v4.php'; include_once($functionsDir . $relativePath);Cheers
Forum: Plugins
In reply to: [Advanced Custom Fields: Nav Menu Field] ACF 5 compatibilityI had this same problem last night so I attempted to create a ACF v5 PRO port. This worked for me but there is probably a better way — *use at your own risk*
Based on the Creating A New Field Type I needed 2 things to make this work. In (#1) fz-acf-nav-menu.php, register v5 support in via (#2) nav-menu-v5.php.
#1
Register v5 port in /plugins/advanced-custom-fields-nav-menu-field/fz-acf-nav-menu.php<?php /* Plugin Name: Advanced Custom Fields: Nav Menu Field Plugin URI: http://faisonz.com/wordpress-plugins/advanced-custom-fields-nav-menu-field/ Description: Add-On plugin for Advanced Custom Fields (ACF) that adds a 'Nav Menu' Field type. <br>ACF v5 PRO port by <a href="http://www.justgooddesign.com">Jesse Graupmann</a>. Version: 1.1.2.5 Author: Faison Zutavern + (ACF v5 PRO port by Jesse Graupmann) Author URI: http://faisonz.com | http://www.justgooddesign.com License: GPL2 or later */ class acf_field_nav_menu_plugin { function __construct() { // version 4+ add_action('acf/register_fields', array($this, 'register_fields')); // version 5+ add_action('acf/include_field_types', array($this, 'include_field_types')); } function register_fields() { include_once('nav-menu-v4.php'); } function include_field_types() { include_once('nav-menu-v5.php'); } } new acf_field_nav_menu_plugin();#2
Create the v5 file at /plugins/advanced-custom-fields-nav-menu-field/nav-menu-v5.php and use the following:<?php // ACF Pro v5 Port by Jesse Graupmann (http://justgooddesign.com) // Original from http://faisonz.com/wordpress-plugins/advanced-custom-fields-nav-menu-field/ by Faison Zutavern (http://faisonz.com) class acf_field_nav_menu_v5 extends acf_field { var $settings, $defaults; function __construct() { $this->name = 'nav_menu'; $this->label = __('Nav Menu', 'acf'); $this->category = __("Relational",'acf'); // Basic, Content, Choice, etc $this->defaults = array( 'save_format' => 'id', 'allow_null' => 0, 'container' => 'div' ); parent::__construct(); $this->settings = array( 'path' => apply_filters('acf/helpers/get_path', __FILE__), 'dir' => apply_filters('acf/helpers/get_dir', __FILE__), 'version' => '1.1.2' ); } function render_field_settings( $field ) { $field = array_merge($this->defaults, $field); $key = $field['name']; // Create Field Options HTML acf_render_field_setting( $field, array( 'label' => __('Return Value','acf'), 'type' => 'radio', 'name' => 'fields['.$key.'][save_format]', 'value' => $field['save_format'], 'layout' => 'horizontal', 'choices' => array( 'object' => __("Nav Menu Object",'acf'), 'menu' => __("Nav Menu HTML",'acf'), 'id' => __("Nav Menu ID",'acf') ) )); $choices = $this->get_allowed_nav_container_tags(); acf_render_field_setting( $field, array( 'label' => __('Menu Container','acf'), 'instructions' => __('What to wrap the Menu\'s ul with.<br />Only used when returning HTML.','acf'), 'type' => 'select', 'name' => 'fields['.$key.'][container]', 'value' => $field['container'], 'choices' => $choices )); acf_render_field_setting( $field, array( 'label' => __('Allow Null?','acf'), 'type' => 'radio', 'name' => 'fields['.$key.'][allow_null]', 'value' => $field['allow_null'], 'choices' => array( 1 => __("Yes",'acf'), 0 => __("No",'acf'), ), 'layout' => 'horizontal', )); } function render_field( $field ) { // create Field HTML echo sprintf( '<select id="%d" class="%s" name="%s">', $field['id'], $field['class'], $field['name'] ); if( $field['allow_null'] ) { echo '<option value=""> - Select - </option>'; } // Nav Menus $nav_menus = $this->get_nav_menus(); foreach( $nav_menus as $nav_menu_id => $nav_menu_name ) { $selected = selected( $field['value'], $nav_menu_id ); echo sprintf( '<option value="%1$d" %3$s>%2$s</option>', $nav_menu_id, $nav_menu_name, $selected ); } echo '</select>'; } function get_nav_menus() { $navs = get_terms('nav_menu', array( 'hide_empty' => false ) ); $nav_menus = array(); foreach( $navs as $nav ) { $nav_menus[ $nav->term_id ] = $nav->name; } return $nav_menus; } function get_allowed_nav_container_tags() { $tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) ); $formatted_tags = array( array( '0' => 'None' ) ); foreach( $tags as $tag ) { $formatted_tags[0][$tag] = ucfirst( $tag ); } return $formatted_tags; } function format_value_for_api( $value, $post_id, $field ) { $field = array_merge($this->defaults, $field); if( !$value ) { return false; } // check format if( $field['save_format'] == 'object' ) { $wp_menu_object = wp_get_nav_menu_object( $value ); if( !$wp_menu_object ) { return false; } $menu_object = new stdClass; $menu_object->ID = $wp_menu_object->term_id; $menu_object->name = $wp_menu_object->name; $menu_object->slug = $wp_menu_object->slug; $menu_object->count = $wp_menu_object->count; return $menu_object; } elseif( $field['save_format'] == 'menu' ) { ob_start(); wp_nav_menu( array( 'menu' => $value, 'container' => $field['container'] ) ); return ob_get_clean(); } return $value; } } // create field new acf_field_nav_menu_v5();And that should be it.
(Optional) I was able to get the values back out by using:
<?php $post_id = 259; // your post id here $acf_field_id = 'sidebar_menu'; // your acf field id here $field = get_field($acf_field_id, $post_id); if($field){ $items = wp_get_nav_menu_items($field ); if($items){ // view menu as json // echo json_encode($items); // OR grab all the titles $titles = array(); foreach($items as $key => $value){ $titles[] = $value ->title; } print_r($titles); } }Hope this helps someone,
Enjoy!