WordPress.org

Forums

Custom Post Widget
[resolved] Feature Suggestion: Easy Edit Links (12 posts)

  1. grapepress
    Member
    Posted 4 years ago #

    I just had an idea that I think could really enhance this plugin further.

    Part A): It would be great if in the Admin area, on the Widgets page, if there could be a Edit link within the Content Block widget that when clicked would take the user to the edit screen for the selected post (ie, Content Block).

    Part B): In the same vein, it could also be helpful if it were possible to display an Edit link for the respective post (Content Block) when the widget Content Block is displayed on the public website (only when the user is logged in). This would be similar to how things function when the user is logged in and typically sees Edit links for Posts and Pages. I would imagine that some users might not want the Edit links displayed (for example, if displaying them causes display issues), so it would probably be good to have an option to disable this feature as well.

    The advantage of having Edit links available in the above ways is that it simplifies things for users who might not fully understand the connections between content blocks, widgets and where the content is ultimately displayed.

    Thanks for your consideration!
    :-)

    http://wordpress.org/extend/plugins/custom-post-widget/

  2. grapepress
    Member
    Posted 4 years ago #

    I've played a little with the code and adding the following on line 37 of post-widget.php is half-way there:
    | <a href="<?php echo get_edit_post_link( $currentID ); ?>">Edit Content Block</a>

    This doesn't work fully in that $currentID is just ending up with the last ID of the loop for building the select box. Ideally this Edit link would always be in sync with what is selected in the select box, so the Edit link href needs to be updated via Javascript anyway. Using the above to build the initial link and then having a Javascript to update the link (the "post=" value) with the Option value for the Selected item should do the trick. I don't think this would be too hard, but I'm not sure I have the time right this second to do up the Javascript. If I do I'll post it here to share. :-)

  3. Johan van der Wijk
    Member
    Plugin Author

    Posted 4 years ago #

    Thanks for the suggestion, I'll consider these features for my next release. Adding the edit link on the page should not be to difficult but I am not sure if it is possible to do this in the widgets page.

  4. grapepress
    Member
    Posted 4 years ago #

    Thanks for considering it. I worked some more on the Edit link for the Admin Widgets page. It still is not working yet, but perhaps the below will save you some time:

    | <a id="<?php echo $this->get_field_id("custom_post_id"); ?>_edit_link" href="<?php echo get_edit_post_link( $currentID ); ?>">Edit Content Block</a><script type="text/javascript">jQuery('#<?php echo $this->get_field_id("custom_post_id"); ?>').change(function(){ jQuery('#<?php echo $this->get_field_id("custom_post_id"); ?>_edit_link').attr('href')=jQuery('#<?php echo $this->get_field_id("custom_post_id"); ?>_edit_link').attr('href').replace(/post=([0-9]+)/, 'post=5'); }); jQuery('#<?php echo $this->get_field_id("custom_post_id"); ?>').change();</script>

    The Replace currently just has "post=5" in it for testing purposes, but at the moment that was not working correctly anyway. I can confirm that the Change event is firing correctly, but there is something I'm overlooking somewhere. I was editing this code via the WordPress Admin area (to save time), which is not what I'm used to (I usually use Notepad++) and was a bit harder to work with. I also don't work with RegEx super often, so I may be misunderstanding something there as well (in the Replace function).

    I hope the above helps, and thanks again for this great plugin and for considering my request!
    :-)

  5. Johan van der Wijk
    Member
    Plugin Author

    Posted 3 years ago #

    I finally managed to include an edit link on the Widget settings page. I hope you find this useful: http://plugins.trac.wordpress.org/browser/custom-post-widget/tags/1.8.4/trunk/screenshot-2.png

  6. jcdesign
    Member
    Posted 3 years ago #

    Johan, I thought adding an edit-post-link on the front end for widgets was also helpful - that way, the user can get directly to the relevant content with one click, without going to the widgets page (also makes sense if you won't be letting them access the widgets page). I added this at line 69 of post-widget.php:

    echo edit_post_link('edit', '', '', $custom_post_id);

    Your plugin, by the way, ROCKS.

  7. Johan van der Wijk
    Member
    Plugin Author

    Posted 3 years ago #

    That is definitely a nice addition! Thanks for the suggestion :)

  8. grapepress
    Member
    Posted 3 years ago #

    Yes! Both of these are exactly what I was wanting! Thank you both of you for your hard work. This makes this excellent plugin even better!

    :-)

  9. Neil040
    Member
    Posted 3 years ago #

    That is brilliant thanks all! I was trying to do that as I make use of your custom widget post content quite a bit and this makes it super easy for clients to edit them without going back and seeking in the dashboard, especially useful with different content in widgets on different pages.

    I just had to make sure to add it before "echo $after_widget;" which I am sure I was supposed to but must have put it after first which placed it outside the widget content block.

    Will you be adding that line for the front end in a future update? Will keep the code in a safe place else so can always add it back in.

  10. Johan van der Wijk
    Member
    Plugin Author

    Posted 3 years ago #

    Hi Neil, I am not sure if I am going to put the editing link on the front end because this might cause layout issues for some users but I will test this to see what happens.

  11. grapepress
    Member
    Posted 3 years ago #

    What about adding an option in the back end to turn this on or off? Then those that wish to use it can turn it on and make whatever adjustments they need to for their theme, and those that don't wish to use it can just turn it off. As long as you give the html of the Edit link some kind of css class or id so that it can be styled this should be pretty workable, I would think.

    Plus, it will only be visible for logged in users, correct (just like Edit links for Posts/Pages are only visible to logged in users)?

  12. Neil040
    Member
    Posted 3 years ago #

    Good point Johan, I never did like the edit this post link on the front and usually removed it as it can make the layout look a bit ugly. Now I like it for the content widgets as I said, more handy with several of those on the page.

    As grapepress suggest, a toggle to display option would be great but otherwise no worries now I know how to add it in manually that will be fine.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Post Widget
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic