GravityView  1.19.4
The best, easiest way to display Gravity Forms entries on your website.
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
GravityView_Entry_Link_Shortcode Class Reference

Handle the [gv_entry_link] shortcode. More...

Public Member Functions

 __construct ()
 
 delete_shortcode ($atts, $content=null, $context= 'gv_delete_entry_link')
 Backward compatibility for existing gv_delete_entry_link shortcodes Forces $atts['action'] to "delete". More...
 
 edit_shortcode ($atts, $content=null, $context= 'gv_edit_entry_link')
 Backward compatibility for existing gv_edit_entry_link shortcode Forces $atts['action'] to "edit". More...
 
 read_shortcode ($atts, $content=null, $context= 'gv_entry_link')
 Generate a link to an entry. More...
 

Private Member Functions

 add_hooks ()
 Add shortcodes. More...
 
 get_anchor_text ($content=null)
 Get the anchor text for the link. More...
 
 get_entry ($entry_id=0)
 Get entry array from entry_id parameter. More...
 
 get_link_atts ()
 Parse shortcode atts to fetch link_atts, which will be added to the output of the HTML anchor tag generated by shortcode Only used when return value of shortcode is not "url". More...
 
 get_url ()
 Get the URL for the entry. More...
 
 has_cap ()
 Check whether the user has the capability to see the shortcode output, depending on the action ('read', 'edit', 'delete') More...
 
 maybe_add_field_values_query_args ($url)
 Allow passing URL params to dynamically populate the Edit Entry form If field_values key is set, run it through parse_str() and add the values to $url. More...
 
 shortcode ($atts, $content=null, $context= 'gv_entry_link')
 Generate a link to an entry. More...
 

Private Attributes

 $entry = array()
 array Entry fetched using the $atts['entry_id'] shortcode setting. More...
 
 $settings = array()
 array The final settings for the shortcode, after merging passed $atts with self::$defaults More...
 
 $view_id = 0
 int If set, generate a link to the entry for this View ID. More...
 

Static Private Attributes

static $defaults
 array The accepted shortcode attribute pairs, with defaults set More...
 

Detailed Description

Handle the [gv_entry_link] shortcode.

Replaces [gv_edit_entry_link] and [gv_delete_entry_link] shortcodes

Since
1.15

Definition at line 10 of file class-gravityview-entry-link-shortcode.php.

Constructor & Destructor Documentation

__construct ( )

Definition at line 44 of file class-gravityview-entry-link-shortcode.php.

References add_hooks().

Member Function Documentation

add_hooks ( )
private

Add shortcodes.

Since
1.15

Definition at line 53 of file class-gravityview-entry-link-shortcode.php.

Referenced by __construct().

delete_shortcode (   $atts,
  $content = null,
  $context = 'gv_delete_entry_link' 
)

Backward compatibility for existing gv_delete_entry_link shortcodes Forces $atts['action'] to "delete".

Since
1.15 Generate a link to an entry. The link can be an edit, delete, or standard link.
1.15
Parameters
array$atts{ string $action What type of link to generate. Options: read, edit, and delete. Default: read string $view_id Define the ID for the View. If not set, use current View ID, if exists. string $entry_id ID of the entry to edit. If undefined, uses the current entry ID, if exists. string $post_id ID of the base post or page to use for an embedded View string $link_atts Pass anchor tag attributes (target=_blank to open Edit Entry link in a new window, for example) string $return What should the shortcode return: link HTML (html) or the URL (url). Default: html string $field_values Only used for action="edit". Parameters to pass in to the prefill data in Edit Entry form. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {
See also
https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } }
Parameters
string | null$contentUsed as link anchor text, if specified.
string$contextCurrent shortcode being called. Not used.
Returns
null|string If admin or an error occurred, returns null. Otherwise, returns entry link output. If `$atts['return']` is 'url', the entry link URL. Otherwise, entry link <a> HTML tag.

Definition at line 87 of file class-gravityview-entry-link-shortcode.php.

References $content, and shortcode().

edit_shortcode (   $atts,
  $content = null,
  $context = 'gv_edit_entry_link' 
)

Backward compatibility for existing gv_edit_entry_link shortcode Forces $atts['action'] to "edit".

Since
1.15 Generate a link to an entry. The link can be an edit, delete, or standard link.
1.15
Parameters
array$atts{ string $action What type of link to generate. Options: read, edit, and delete. Default: read string $view_id Define the ID for the View. If not set, use current View ID, if exists. string $entry_id ID of the entry to edit. If undefined, uses the current entry ID, if exists. string $post_id ID of the base post or page to use for an embedded View string $link_atts Pass anchor tag attributes (target=_blank to open Edit Entry link in a new window, for example) string $return What should the shortcode return: link HTML (html) or the URL (url). Default: html string $field_values Only used for action="edit". Parameters to pass in to the prefill data in Edit Entry form. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {
See also
https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } }
Parameters
string | null$contentUsed as link anchor text, if specified.
string$contextCurrent shortcode being called. Not used.
Returns
null|string If admin or an error occurred, returns null. Otherwise, returns entry link output. If `$atts['return']` is 'url', the entry link URL. Otherwise, entry link <a> HTML tag.

Definition at line 74 of file class-gravityview-entry-link-shortcode.php.

References $content, and shortcode().

get_anchor_text (   $content = null)
private

Get the anchor text for the link.

If content inside shortcode is defined, use that as the text. Otherwise, use default values.

Only used when return value of shortcode is not "url"

Since
1.15
Parameters
string | null$contentContent inside shortcode, if defined
Returns
string Text to use for HTML anchor

Definition at line 197 of file class-gravityview-entry-link-shortcode.php.

References $content.

Referenced by shortcode().

get_entry (   $entry_id = 0)
private

Get entry array from entry_id parameter.

If no $entry_id

Since
1.15 GVCommon::get_entry GravityView_frontend::getSingleEntry
Parameters
int$entry_idGravity Forms Entry ID. If not passed, current View's current entry ID will be used, if found.
Returns
array|bool Gravity Forms array, if found. Otherwise, false.

Definition at line 284 of file class-gravityview-entry-link-shortcode.php.

References $entry, GVCommon\get_entry(), GravityView_frontend\getInstance(), and GravityView_View\getInstance().

Referenced by shortcode().

get_link_atts ( )
private

Parse shortcode atts to fetch link_atts, which will be added to the output of the HTML anchor tag generated by shortcode Only used when return value of shortcode is not "url".

Since
1.15
See also
gravityview_get_link() See acceptable attributes here
Returns
array Array of attributes to be added

Definition at line 175 of file class-gravityview-entry-link-shortcode.php.

References $link_atts, and GravityView_Delete_Entry\get_confirm_dialog().

Referenced by shortcode().

get_url ( )
private

Get the URL for the entry.

Uses the post_id, view_id params as defined in the shortcode attributes.

Since
1.15
Parameters
string | null$contentContent inside shortcode, if defined
Returns
string|boolean If URL is fetched, the URL to the entry link. If not found, returns false.

Definition at line 228 of file class-gravityview-entry-link-shortcode.php.

References $url, GravityView_API\entry_link(), GravityView_Delete_Entry\get_delete_link(), GravityView_Edit_Entry\get_edit_link(), and maybe_add_field_values_query_args().

Referenced by shortcode().

has_cap ( )
private

Check whether the user has the capability to see the shortcode output, depending on the action ('read', 'edit', 'delete')

Since
1.15
Returns
bool True: has cap.

Definition at line 256 of file class-gravityview-entry-link-shortcode.php.

References GravityView_Delete_Entry\check_user_cap_delete_entry(), and GravityView_Edit_Entry\check_user_cap_edit_entry().

Referenced by shortcode().

maybe_add_field_values_query_args (   $url)
private

Allow passing URL params to dynamically populate the Edit Entry form If field_values key is set, run it through parse_str() and add the values to $url.

Since
1.15
Parameters
string$hrefURL

Definition at line 321 of file class-gravityview-entry-link-shortcode.php.

References $url.

Referenced by get_url().

read_shortcode (   $atts,
  $content = null,
  $context = 'gv_entry_link' 
)

Generate a link to an entry.

Since
1.15 The link can be an edit, delete, or standard link.
1.15
Parameters
array$atts{ string $action What type of link to generate. Options: read, edit, and delete. Default: read string $view_id Define the ID for the View. If not set, use current View ID, if exists. string $entry_id ID of the entry to edit. If undefined, uses the current entry ID, if exists. string $post_id ID of the base post or page to use for an embedded View string $link_atts Pass anchor tag attributes (target=_blank to open Edit Entry link in a new window, for example) string $return What should the shortcode return: link HTML (html) or the URL (url). Default: html string $field_values Only used for action="edit". Parameters to pass in to the prefill data in Edit Entry form. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {
See also
https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } }
Parameters
string | null$contentUsed as link anchor text, if specified.
string$contextCurrent shortcode being called. Not used.
Returns
null|string If admin or an error occurred, returns null. Otherwise, returns entry link output. If `$atts['return']` is 'url', the entry link URL. Otherwise, entry link <a> HTML tag.

Definition at line 63 of file class-gravityview-entry-link-shortcode.php.

References $content, and shortcode().

shortcode (   $atts,
  $content = null,
  $context = 'gv_entry_link' 
)
private

Generate a link to an entry.

The link can be an edit, delete, or standard link.

Since
1.15
Parameters
array$atts{ string $action What type of link to generate. Options: read, edit, and delete. Default: read string $view_id Define the ID for the View. If not set, use current View ID, if exists. string $entry_id ID of the entry to edit. If undefined, uses the current entry ID, if exists. string $post_id ID of the base post or page to use for an embedded View string $link_atts Pass anchor tag attributes (target=_blank to open Edit Entry link in a new window, for example) string $return What should the shortcode return: link HTML (html) or the URL (url). Default: html string $field_values Only used for action="edit". Parameters to pass in to the prefill data in Edit Entry form. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {
See also
https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ } }
Parameters
string | null$contentUsed as link anchor text, if specified.
string$contextCurrent shortcode being called. Not used.
Returns
null|string If admin or an error occurred, returns null. Otherwise, returns entry link output. If `$atts['return']` is 'url', the entry link URL. Otherwise, entry link <a> HTML tag.

Definition at line 113 of file class-gravityview-entry-link-shortcode.php.

References $content, $link_atts, $link_text, $url, get_anchor_text(), get_entry(), get_link_atts(), get_url(), GravityView_View\getInstance(), gravityview_get_link(), has_cap(), and GravityView_Plugin\is_admin().

Referenced by delete_shortcode(), edit_shortcode(), and read_shortcode().

Field Documentation

$defaults
staticprivate
Initial value:
= array(
'action' => 'read',
'view_id' => 0,
'entry_id' => 0,
'post_id' => 0,
'link_atts' => '',
'return' => 'html',
'field_values' => '',
)

array The accepted shortcode attribute pairs, with defaults set

Since
1.15

Definition at line 28 of file class-gravityview-entry-link-shortcode.php.

$entry = array()
private

array Entry fetched using the $atts['entry_id'] shortcode setting.

Since
1.15

Definition at line 16 of file class-gravityview-entry-link-shortcode.php.

Referenced by get_entry().

$settings = array()
private

array The final settings for the shortcode, after merging passed $atts with self::$defaults

Since
1.15

Definition at line 42 of file class-gravityview-entry-link-shortcode.php.

$view_id = 0
private

int If set, generate a link to the entry for this View ID.

Required when used outside a View. Otherwise, current View ID is used.

Since
1.15

Definition at line 22 of file class-gravityview-entry-link-shortcode.php.


The documentation for this class was generated from the following file: