Giter VIP home page Giter VIP logo

add-add-new-to-meta-box-select-advanced's Introduction

add-add-new-to-meta-box-select-advanced

A VERY quickly made plugin that adds an 'Add New' link after any Meta Box Select Advanced field that uses select2 for selecting related posts.

Trying to satisfy my needs described here: https://metabox.io/support/topic/is-it-possible-to-inline-add-a-new-record-on-a-related-post-type/

What It Does

add-add-new-to-meta-box-select-advanced.php adds Thickbox & custom JS to the Post Edit & New screens. add_add_new_to_mb.js places an "Add New" button (after a setTimeout) immediately following any Select Advanced field, for "post" types only (doesn't work for adding new Users or Terms, etc).

Usage for End Users / WP Admin

If a user does not find the related post in the Select Advanced field:

  • User can click the "Add New" button
  • A modal (or new window) will open to the "Add New" screen for the related post type
  • User can add a new post, then close the modal/window
  • User can then search for the post they just added and it will display in the Select Advanced field

For Developers

You can customize a few options in the add_add_new_to_mb.js file. Look for the aanConfig object (that stands for 'add Add New config').

You will definitely want to customize the baseUrl to match your WP site. If your site is just in the root of your domain, remove the /app from the beginning of the baseUrl.

Here are the other aanConfig options:

  • useModal: boolean - determines if the "Add New" screen opens in a modal or in a new window, if set to true it a modal will open, if false a new window will open (Default: true)
  • modalParams: string - currently this is pretty much irrelevant, but I were to improve the script to load an actual modal view of the Add New screen, then this would be a required parameter (Default: '&TB_iframe=true')
  • modalWidth: string or number - the width of the modal (Default: '600')
  • modalHeight: string or number - the height of the modal (Default: '550')
  • baseUrl: string - the relative path to the Add New screen for you WP site (Default: '/app/wp-admin/post-new.php?post_type=')
  • linkText: string - the text that will display inside the anchor element (Default: 'Add New')
  • linkClass: string - any classes you want to add to the anchor element, remove button if you would rather just show a plain text link Note: thickbox class is automatically added if useModal is true (Default: 'button')
  • linkStyle: string - any inline styles you want to apply to the anchor element (Default: 'margin-left:1rem;')

Misc References

These are for my memory and easy access later:

What & Why

My clients needed the ability to add a new post if it didn't already exist in the Meta Box Select Advanced dropdown. So this hacky solution opens the "Add New Post" page for whatever custom post type the select field is using. Then the user can save (publish) the new entry, close the window that opened up & do a search for what they just added and the ajax query should pick it up.

This is an EXTREMELY quick and simple solution. It has lots of potential for error, but it works great for my uses.

Contributors: Brandon Pfeiffer - @brandonjp - brandonjp.com Donate something: https://www.paypal.me/brandonjp

add-add-new-to-meta-box-select-advanced's People

Contributors

brandonjp avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.