54 add_shortcode(
'gv_entry_link', array( $this,
'read_shortcode' ) );
55 add_shortcode(
'gv_edit_entry_link', array( $this,
'edit_shortcode' ) );
56 add_shortcode(
'gv_delete_entry_link', array( $this,
'delete_shortcode' ) );
76 $atts = shortcode_atts( self::$defaults, $atts );
78 $atts[
'action'] =
'edit';
92 $atts = shortcode_atts( self::$defaults, $atts );
94 $atts[
'action'] =
'delete';
126 if ( ! class_exists(
'GravityView_frontend' ) || ! class_exists(
'GravityView_View' ) ) {
127 gravityview()->log->error(
'GravityView_frontend or GravityView_View do not exist.' );
132 $this->settings = shortcode_atts( self::$defaults, $atts, $context );
136 if ( empty( $this->view_id ) ) {
137 gravityview()->log->error(
'A View ID was not defined and we are not inside a View' );
142 $this->entry = $this->
get_entry( $this->settings[
'entry_id'] );
144 if ( empty( $this->entry ) ) {
145 gravityview()->log->error(
'An Entry ID was not defined or found. Entry ID: {entry_id}', array(
'entry_id' => $this->settings[
'entry_id'] ) );
150 gravityview()->log->debug(
'{context} atts:', array(
'context' => $context,
'data' => $atts ) );
153 gravityview()->log->error(
'User does not have the capability to {action} this entry: {entry_id}', array(
'action' => esc_attr( $this->settings[
'action'] ),
'entry_id' => $this->entry[
'id'] ) );
161 gravityview()->log->error(
'Link returned false; View or Post may not exist.' );
167 if (
'url' === $this->settings[
'return'] ) {
190 $return = apply_filters(
'gravityview/shortcodes/gv_entry_link/output', $return, compact(
'url',
'link_text',
'link_atts',
'atts',
'content',
'context' ) );
205 wp_parse_str( $this->settings[
'link_atts'],
$link_atts );
207 if (
'delete' === $this->settings[
'action'] ) {
231 switch ( $this->settings[
'action'] ) {
233 $anchor_text = __(
'Edit Entry',
'gk-gravityview' );
236 $anchor_text = __(
'Delete Entry',
'gk-gravityview' );
239 $anchor_text = __(
'View Details',
'gk-gravityview' );
259 $post_id = empty( $this->settings[
'post_id'] ) ? $this->view_id : $this->settings[
'post_id'];
261 switch ( $this->settings[
'action'] ) {
286 switch ( $this->settings[
'action'] ) {
315 if ( empty( $entry_id ) ) {
318 if ( ! $backup_entry ) {
319 gravityview()->log->error(
'No entry defined (or entry id not valid number)', array(
'data' => $this->settings ) );
325 }
else if ( in_array( $entry_id, [
'first',
'last' ] ) ) {
329 gravityview()->log->error(
"A View with ID {$this->view_id} was not found." );
334 if ( ! isset(
$entry[ $entry_id ] ) ) {
335 $entry =
'last' === $entry_id ? $view->get_entries( null )->first() : $view->get_entries( null )->last();
349 gravityview()->log->error(
'No entries match the entry ID defined: {entry_id}', array(
'entry_id' => $entry_id ) );
367 if (
$url && ! empty( $this->settings[
'field_values'] ) ) {
369 wp_parse_str( $this->settings[
'field_values'], $field_values );
371 $url = add_query_arg( $field_values,
$url );
if(!GravityView_Delete_Entry::check_user_cap_delete_entry( $entry, $field_settings)) $link_text
static get_delete_link( $entry, $view_id=0, $post_id=null)
Generate a nonce link with the base URL of the current View embed.
static get_edit_link( $entry, $view_id, $post_id=null, $field_values='')
The edit entry link creates a secure link with a nonce.
Handle the [gv_entry_link] shortcode.
static getInstance( $passed_post=NULL)
$settings
array The final settings for the shortcode, after merging passed $atts with self::$defaults ...
static check_user_cap_edit_entry( $entry, $view=0)
checks if user has permissions to edit a specific entry
$entry
array Entry fetched using the $atts['entry_id'] shortcode setting.
gravityview_get_link( $href='', $anchor_text='', $atts=array())
Generate an HTML anchor tag with a list of supported attributes.
$view_id
int If set, generate a link to the entry for this View ID.
has_cap()
Check whether the user has the capability to see the shortcode output, depending on the action ('read...
add_hooks()
Add shortcodes.
get_anchor_text( $content=null)
Get the anchor text for the link.
if(empty( $field_settings['content'])) $content
static get_confirm_dialog()
Get the onclick attribute for the confirm dialogs that warns users before they delete an entry...
static check_user_cap_delete_entry( $entry, $field=array(), $view=0)
checks if user has permissions to view the link or delete a specific entry
static by_id( $post_id)
Construct a instance from a post ID.
edit_shortcode( $atts=array(), $content=null, $context='gv_edit_entry_link')
Backward compatibility for existing gv_edit_entry_link shortcode Forces $atts['action'] to "edit"...
get_entry( $entry_id=0)
Get entry array from entry_id parameter.
maybe_add_field_values_query_args( $url)
Allow passing URL params to dynamically populate the Edit Entry form If field_values key is set...
get_link_atts()
Parse shortcode atts to fetch link_atts, which will be added to the output of the HTML anchor tag gen...
delete_shortcode( $atts=array(), $content=null, $context='gv_delete_entry_link')
Backward compatibility for existing gv_delete_entry_link shortcodes Forces $atts['action'] to "delete...
shortcode( $atts, $content=null, $context='gv_entry_link')
Generate a link to an entry.
read_shortcode( $atts, $content=null, $context='gv_entry_link')
Generate a link to an entry.
gravityview()
The main GravityView wrapper function.
get_url()
Get the URL for the entry.
static $defaults
array The accepted shortcode attribute pairs, with defaults set
static get_entry( $entry_slug, $force_allow_ids=false, $check_entry_display=true, $view=null)
Return a single entry object.
static entry_link( $entry, $post_id=NULL, $add_directory_args=true, $view_id=0)
return href for single entry
new GravityView_Entry_Link_Shortcode
static getInstance()
Get the one true instantiated self.