plugin install

This commit is contained in:
Tony Volpe
2024-06-18 17:29:05 -04:00
parent e1aaedd1ae
commit 41f50eacc4
5880 changed files with 1057631 additions and 39681 deletions

View File

@@ -0,0 +1,66 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Embed_Form\Config;
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
/**
* Config items for the Embed Form I18N
*
* @since 2.6
*/
class GF_Embed_Config_I18N extends GF_Config {
protected $name = 'gform_admin_config';
protected $script_to_localize = 'gform_gravityforms_admin_vendors';
/**
* Determine if the config should enqueue its data.
*
* @since 2.6.2
*
* @return bool
*/
public function should_enqueue() {
return \GFCommon::is_form_editor();
}
/**
* Config data.
*
* @return array[]
*/
public function data() {
return array(
'components' => array(
'embed_form' => array(
'i18n' => array(
'title' => esc_html__( 'Embed Form', 'gravityforms' ),
'id' => esc_html__( 'Form ID: %s', 'gravityforms' ),
'add_title' => esc_html__( 'Add to Existing Content', 'gravityforms' ),
'add_post_type_choice_label' => esc_html__( '%1$sAdd to Existing Content:%2$s %3$s', 'gravityforms' ),
'add_dropdown_placeholder' => esc_html__( 'Select a %s', 'gravityforms' ),
'add_trigger_aria_text' => esc_html__( 'Select a post', 'gravityforms' ),
'add_search_aria_text' => esc_html__( 'Search all %ss', 'gravityforms' ),
'add_button_label' => esc_html__( 'Insert Form', 'gravityforms' ),
'create_title' => esc_html__( 'Create New', 'gravityforms' ),
'create_post_type_choice_label' => esc_html__( '%1$sCreate New:%2$s %3$s', 'gravityforms' ),
'create_placeholder' => esc_html__( 'Enter %s Name', 'gravityforms' ),
'create_button_label' => esc_html__( 'Create', 'gravityforms' ),
'dialog_title' => esc_html__( 'Unsaved Changes', 'gravityforms' ),
'dialog_content' => esc_html__( 'Oops! You have unsaved changes in the form, before you can continue with embedding it please save your changes.', 'gravityforms' ),
'dialog_confirm_text' => esc_html__( 'Save Changes', 'gravityforms' ),
'dialog_confirm_saving' => esc_html__( 'Saving', 'gravityforms' ),
'dialog_cancel_text' => esc_html__( 'Cancel', 'gravityforms' ),
'dialog_close_title' => esc_html__( 'Close this dialog and return to form editor.', 'gravityforms' ),
'shortcode_title' => esc_html__( 'Not Using the Block Editor?', 'gravityforms' ),
'shortcode_description' => esc_html__( 'Copy and paste the shortcode within your page builder.', 'gravityforms' ),
'shortcode_button_label' => esc_html__( 'Copy Shortcode', 'gravityforms' ),
'shortcode_button_copied' => esc_html__( 'Copied', 'gravityforms' ),
'shortcode_helper' => esc_html__( '%1$sLearn more%2$s about the shortcode.', 'gravityforms' ),
),
),
),
);
}
}

View File

@@ -0,0 +1,234 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Embed_Form\Config;
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
/**
* Config items for the Embed Form UI.
*
* @since 2.6
*/
class GF_Embed_Config extends GF_Config {
protected $name = 'gform_admin_config';
protected $script_to_localize = 'gform_gravityforms_admin_vendors';
/**
* Determine if the config should enqueue its data.
*
* @since 2.6.2
*
* @return bool
*/
public function should_enqueue() {
return \GFCommon::is_form_editor();
}
/**
* Config data.
*
* @return array[]
*/
public function data() {
return array(
'components' => array(
'embed_form' => array(
'urls' => $this->get_urls(),
'data' => array(
'form_id' => array(
'value' => rgget( 'id' ),
'default' => 1,
),
'post_types' => array(
'value' => $this->get_available_post_types(),
'default' => $this->placeholder_post_types(),
),
'items' => array(
'value' => $this->get_items_by_type(),
'default' => $this->placeholder_items(),
),
),
),
),
);
}
/**
* Get the various URLs for the Embed UI.
*
* @since 2.6
*
* @return array
*/
private function get_urls() {
$edit_link = '';
$post_type_object = get_post_type_object( 'page' );
if ( ! empty( $post_type_object->_edit_link ) ) {
$edit_link = admin_url( str_replace( '%d', '%1$s', $post_type_object->_edit_link ) . '&action=edit' );
}
/**
* Allows the edit post link to be customized.
*
* @since 2.6.2
*
* @param string $link The edit link. Use %1$s as the placeholder for the ID.
*/
$edit_link = apply_filters( 'gform_embed_edit_post_link', $edit_link );
return [
'edit_post' => [
'value' => $edit_link,
'default' => 'https://gravity.loc/wp-admin/post.php?post=%1$s&action=edit',
],
'shortcode_docs' => 'https://docs.gravityforms.com/shortcodes/',
];
}
/**
* Get the Post Types data for the Embed UI.
*
* @since 2.6
*
* @return array
*/
private function get_available_post_types() {
$types = array(
array(
'slug' => 'page',
'label' => get_post_type_object( 'page' )->labels->singular_name,
),
array(
'slug' => 'post',
'label' => get_post_type_object( 'post' )->labels->singular_name,
),
);
/**
* Allows users to modify the post types sent as selectable options in the Embed UI.
*
* @since 2.6
*
* @param array $types
*
* @return array
*/
return apply_filters( 'gform_embed_post_types', $types );
}
/**
* Get the items to localize for each post type.
*
* @since 2.6
*
* @return array
*/
private function get_items_by_type() {
$types = $this->get_available_post_types();
$data = array();
foreach ( $types as $type ) {
$slug = $type['slug'];
$label = $type['label'];
$items = get_posts( array( 'post_type' => $slug, 'posts_per_page' => 5 ) );
array_walk( $items, function ( &$item ) {
$item = array(
'value' => $item->ID,
'label' => $item->post_title,
);
} );
$data[ $slug ]['entries'] = $items;
$data[ $slug ]['count'] = $this->get_total_posts_by_type( $slug );
}
return $data;
}
/**
* Get the totals for the given post type.
*
* @since 2.6
*
* @param string $type - The Post Type to query for.
*
* @return array
*/
private function get_total_posts_by_type( $type ) {
$args = array(
'post_type' => $type,
'post_status' => 'publish',
);
$query = new \WP_Query( $args );
return $query->found_posts;
}
/**
* Get the placeholder post type values for use in Mocks.
*
* @since 2.6
*
* @return array
*/
private function placeholder_post_types() {
return array(
array( 'slug' => 'page', 'label' => __( 'Page', 'gravityforms' ) ),
array( 'slug' => 'post', 'label' => __( 'Post', 'gravityforms' ) ),
);
}
/**
* Get the placeholder post items for use in Mocks.
*
* @since 2.6
*
* @return array
*/
private function placeholder_items() {
return array(
'post' => array(
'count' => 2,
'entries' => array(
array(
'value' => 1,
'label' => 'Post One',
),
array(
'value' => 2,
'label' => 'Post Two',
),
),
),
'page' => array(
'count' => 25,
'entries' => array(
array(
'value' => 3,
'label' => 'Page Three',
),
array(
'value' => 4,
'label' => 'Page Four',
),
array(
'value' => 5,
'label' => 'Page Five',
),
array(
'value' => 6,
'label' => 'Page Six',
),
array(
'value' => 7,
'label' => 'Page Seven',
),
),
)
);
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Embed_Form\Config;
use Gravity_Forms\Gravity_Forms\Config\GF_Config;
use Gravity_Forms\Gravity_Forms\Embed_Form\Endpoints\GF_Embed_Endpoint_Create_With_Block;
use Gravity_Forms\Gravity_Forms\Embed_Form\Endpoints\GF_Embed_Endpoint_Get_Posts;
/**
* Config items for the Embed Forms REST Endpoints.
*
* @since 2.6
*/
class GF_Embed_Endpoints_Config extends GF_Config {
protected $script_to_localize = 'gform_gravityforms_admin_vendors';
protected $name = 'gform_admin_config';
protected $overwrite = false;
/**
* Determine if the config should enqueue its data.
*
* @since 2.6.2
*
* @return bool
*/
public function should_enqueue() {
return \GFCommon::is_form_editor();
}
/**
* Config data.
*
* @return array[]
*/
public function data() {
return array(
'components' => array(
'embed_form' => array(
'endpoints' => $this->get_endpoints(),
),
),
);
}
/**
* Get the various endpoints for the Embed UI.
*
* @since 2.6
*
* @return array
*/
private function get_endpoints() {
return array(
// Endpoint to get posts for typeahead
'get_posts' => array(
'action' => array(
'value' => 'gf_embed_query_posts',
'default' => 'mock_endpoint',
),
'nonce' => array(
'value' => wp_create_nonce( GF_Embed_Endpoint_Get_Posts::ACTION_NAME ),
'default' => 'nonce',
)
),
// Endpoint to create a new page with our block inserted.
'create_post_with_block' => array(
'action' => array(
'value' => GF_Embed_Endpoint_Create_With_Block::ACTION_NAME,
'default' => 'mock_endpoint',
),
'nonce' => array(
'value' => wp_create_nonce( GF_Embed_Endpoint_Create_With_Block::ACTION_NAME ),
'default' => 'nonce',
)
)
);
}
}