builder
3 weeks ago
form-migrator
3 weeks ago
plugin-updates
8 years ago
settings
3 weeks ago
views
3 weeks ago
class-evf-admin-addons.php
4 months ago
class-evf-admin-assets.php
4 days ago
class-evf-admin-builder.php
2 months ago
class-evf-admin-dashboard.php
3 weeks ago
class-evf-admin-editor.php
4 years ago
class-evf-admin-embed-wizard.php
2 years ago
class-evf-admin-entries-table-list.php
2 months ago
class-evf-admin-entries.php
2 months ago
class-evf-admin-form-templates.php
3 weeks ago
class-evf-admin-forms-table-list.php
4 months ago
class-evf-admin-forms.php
4 months ago
class-evf-admin-import-export.php
3 weeks ago
class-evf-admin-menus.php
3 weeks ago
class-evf-admin-notices.php
4 months ago
class-evf-admin-preview-confirmation.php
11 months ago
class-evf-admin-settings.php
3 weeks ago
class-evf-admin-tools.php
2 months ago
class-evf-admin-welcome.php
2 years ago
class-evf-admin.php
2 months ago
class-evf-base-list-table.php
4 months ago
evf-admin-functions.php
3 weeks ago
class-evf-admin-embed-wizard.php
100 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Embed Wizard. |
| 4 | * |
| 5 | * @package EverestForms/Admin |
| 6 | * @version 2.0.8 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Embed Wizard Class. |
| 13 | * |
| 14 | * @since 2.0.8 |
| 15 | */ |
| 16 | class EVF_Admin_Embed_Wizard { |
| 17 | |
| 18 | /** |
| 19 | * Initialize class. |
| 20 | * |
| 21 | * @since 2.0.8 |
| 22 | */ |
| 23 | public static function init() { |
| 24 | add_filter( 'default_title', array( __CLASS__, 'set_embed_page_title' ), 10, 2 ); |
| 25 | add_filter( 'default_content', array( __CLASS__, 'set_embed_page_content' ), 10, 2 ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Set default title for newly created pages. |
| 30 | * |
| 31 | * @since 2.0.8 |
| 32 | * |
| 33 | * @param string $post_title Default post title. |
| 34 | * @param \WP_Post $post Post object. |
| 35 | */ |
| 36 | public static function set_embed_page_title( $post_title, $post ) { |
| 37 | |
| 38 | $meta = self::get_meta(); |
| 39 | |
| 40 | self::delete_meta(); |
| 41 | |
| 42 | return empty( $meta['embed_page_title'] ) ? $post_title : $meta['embed_page_title']; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Insert the form into the new page. |
| 47 | * |
| 48 | * @since 2.0.8 |
| 49 | * @param string $post_content Default post content. |
| 50 | * @param \WP_Post $post Post object. |
| 51 | */ |
| 52 | public static function set_embed_page_content( $post_content, $post ) { |
| 53 | $meta = self::get_meta(); |
| 54 | |
| 55 | $form_id = ! empty( $meta['form_id'] ) ? $meta['form_id'] : 0; |
| 56 | $page_id = ! empty( $meta['embed_page'] ) ? $meta['embed_page'] : 0; |
| 57 | |
| 58 | if ( ! empty( $page_id ) || empty( $form_id ) ) { |
| 59 | return $post_content; |
| 60 | } |
| 61 | $pattern = '[everest_form id="%d"]'; |
| 62 | |
| 63 | return sprintf( $pattern, absint( $form_id ) ); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | /** |
| 68 | * Set user's embed meta data for Everest Forms. |
| 69 | * |
| 70 | * @since 2.0.8 |
| 71 | * @param array $data Data array to set as embed meta data. |
| 72 | */ |
| 73 | public static function set_meta( $data ) { |
| 74 | update_user_meta( get_current_user_id(), 'everest_forms_form_embed', $data ); |
| 75 | } |
| 76 | |
| 77 | |
| 78 | /** |
| 79 | * Get user's embed meta data for Everest Forms. |
| 80 | * |
| 81 | * @since 2.0.8 |
| 82 | * @return array User's embed meta data for Everest Forms. |
| 83 | */ |
| 84 | public static function get_meta() { |
| 85 | |
| 86 | return get_user_meta( get_current_user_id(), 'everest_forms_form_embed', true ); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Delete user's embed meta data for Everest Forms. |
| 91 | * |
| 92 | * @since 2.0.8 |
| 93 | */ |
| 94 | public static function delete_meta() { |
| 95 | |
| 96 | delete_user_meta( get_current_user_id(), 'everest_forms_form_embed' ); |
| 97 | } |
| 98 | } |
| 99 | EVF_Admin_Embed_Wizard::init(); |
| 100 |