| @@ -1,21 +1,30 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Core\Hooks; |
| 4 | 4 | |
| 5 | +if (!defined('ABSPATH')) { | |
| 6 | + exit; | |
| 7 | +} | |
| 8 | + | |
| 5 | 9 | use BitCode\BitForm\Admin\Admin_Bar; |
| 6 | 10 | use BitCode\BitForm\API\Route\Routes; |
| 7 | 11 | use BitCode\BitForm\Core\Ajax\AjaxService; |
| 12 | +use BitCode\BitForm\Core\Api\BitFormPublicApi; | |
| 8 | 13 | use BitCode\BitForm\Core\Capability\Request; |
| 9 | 14 | use BitCode\BitForm\Core\Database\FormModel; |
| 10 | 15 | use BitCode\BitForm\Core\Fallback\FormFallback; |
| 11 | 16 | use BitCode\BitForm\Core\Form\FormHandler; |
| 12 | 17 | use BitCode\BitForm\Core\Integration\Integrations; |
| 18 | +use BitCode\BitForm\Core\Util\CacheCompat; | |
| 13 | 19 | use BitCode\BitForm\Core\Util\FileDownloadProvider; |
| 14 | -use BitCode\BitForm\Core\Util\GutenBlockProvider; | |
| 20 | +use BitCode\BitForm\Core\Util\Translation\TranslationManager; | |
| 15 | 21 | use BitCode\BitForm\Core\Util\Utilities; |
| 22 | +use BitCode\BitForm\Core\WorkFlow\WorkflowExecutor; | |
| 16 | 23 | use BitCode\BitForm\Frontend\ConversationalFormView; |
| 17 | 24 | use BitCode\BitForm\Frontend\StandaloneFormView; |
| 25 | +use BitCode\BitForm\Widgets\RegisterBitformBricksWidget; | |
| 26 | +use BitCode\BitForm\Widgets\RegisterGutenBlock; | |
| 18 | 27 | |
| 19 | 28 | class Hooks |
| 20 | 29 | { |
| 21 | 30 | public static function init_hooks() |
| @@ -21,10 +30,15 @@ | ||
| 21 | 30 | public static function init_hooks() |
| 22 | 31 | { |
| 23 | 32 | add_action('init', [PostType::class, 'registerBitformsPostType']); |
| 24 | 33 | add_action('init', [PostType::class, 'registerCustomPostType']); |
| 34 | + add_action('update_option_bitform_custom_post_types', [PostType::class, 'scheduleRewriteFlush']); | |
| 35 | + add_filter('wp_robots', [PostType::class, 'noindexBitformsPages']); | |
| 25 | 36 | add_action('bitforms_exec_integrations', [Integrations::class, 'integrationExecutionHelper'], 1, 5); |
| 26 | - add_action('init', [Hooks::class, 'localization_setup']); | |
| 37 | + // Reclaim safety net for queued workflows whose browser-fired trigger was lost | |
| 38 | + add_action('bitforms_reclaim_workflow', [WorkflowExecutor::class, 'reclaim'], 10, 4); | |
| 39 | + add_action('bitforms_reclaim_sweep', [WorkflowExecutor::class, 'sweep']); | |
| 40 | + add_filter('bitform_default_submit_confirmation_excluded_action_ids', ['BitCode\BitForm\Core\WorkFlow\Helper', 'workflowReferencedActionIds'], 10, 3); | |
| 27 | 41 | add_action('init', [Hooks::class, 'init_classes']); |
| 28 | 42 | add_action('init', [Hooks::class, 'versionUpdateRunFallbacks']); |
| 29 | 43 | add_action('rest_api_init', [Hooks::class, 'registerRoutes']); |
| 30 | 44 | add_filter('plugin_action_links_' . plugin_basename(BITFORMS_PLUGIN_MAIN_FILE), [Hooks::class, 'plugin_action_links']); |
| @@ -31,9 +45,22 @@ | ||
| 31 | 45 | add_action('bitform_dequeue_scripts', [Hooks::class, 'dequeueScripts'], 1000, 100); |
| 32 | 46 | add_action('bitform_dequeue_styles', [Hooks::class, 'dequeueStyles'], 1000, 100); |
| 33 | 47 | add_action('init', [ConversationalFormView::class, 'conversationalFormView']); |
| 34 | 48 | add_action('init', [StandaloneFormView::class, 'standaloneFormView']); |
| 35 | - // add_action('wp_footer', [Hooks::class, 'updateBitFormVersion'], 9999, 0); | |
| 49 | + add_action('bitform_admin_form_changed', [Hooks::class, 'invalidateCustomUrlCache']); | |
| 50 | + \BitCode\BitForm\Core\Util\CacheCompat::registerPurgeHooks(); | |
| 51 | + add_action('wp_footer', [Hooks::class, 'updateBitFormVersion'], 9999, 0); | |
| 52 | + | |
| 53 | + // Register the BitForm widget for Gutenberg, and Bricks Builder | |
| 54 | + add_action('init', [new RegisterGutenBlock(), 'register']); | |
| 55 | + add_action('init', [RegisterBitformBricksWidget::class, 'register_widgets'], 11); | |
| 56 | + // Add Bit Form menu to admin bar by "manage_bitform" capability | |
| 57 | + add_filter('bitforms_form_access_capability', [Hooks::class, 'bitformMenuAccessCapability']); | |
| 58 | + | |
| 59 | + // Public API bridge for sibling Bit Apps plugins (Bit CRM). Consumers call | |
| 60 | + add_filter('bitform/api/crm_integrated_forms', fn ($default = null) => BitFormPublicApi::getCrmIntegratedForms(), 10, 1); | |
| 61 | + add_filter('bitform/api/toggle_form_status', fn ($default = null, $formId = 0, $status = 0) => BitFormPublicApi::toggleFormStatus($formId, $status), 10, 3); | |
| 62 | + add_filter('bitform/api/create_form_url', fn ($default = null, $args = []) => BitFormPublicApi::getCreateFormUrl($args), 10, 2); | |
| 36 | 63 | } |
| 37 | 64 | |
| 38 | 65 | public static function updateBitFormVersion() |
| 39 | 66 | { |
| @@ -40,8 +67,12 @@ | ||
| 40 | 67 | $currentBitFormVersion = BITFORMS_VERSION; |
| 41 | 68 | $installedBitFormVersion = get_option('bitforms_version'); |
| 42 | 69 | if ($currentBitFormVersion !== $installedBitFormVersion) { |
| 43 | 70 | (new FormFallback())->resetJsGeneratedPageIds(); |
| 71 | + // Without this the regenerated bundle keeps its ?bfv= URL and browsers | |
| 72 | + // and CDNs keep serving the stale file. | |
| 73 | + $formUpdateVersion = (int) get_option('bitform_form_update_version'); | |
| 74 | + update_option('bitform_form_update_version', $formUpdateVersion ? $formUpdateVersion + 1 : 1); | |
| 44 | 75 | update_option('bitforms_version', $currentBitFormVersion); |
| 45 | 76 | } |
| 46 | 77 | } |
| 47 | 78 | |
| @@ -71,10 +102,10 @@ | ||
| 71 | 102 | 'generated_script_page_ids' => ['operator' => 'LIKE', 'value' => $value], |
| 72 | 103 | ]; |
| 73 | 104 | $forms = $formModel->get('generated_script_page_ids,id', $condtions); |
| 74 | 105 | foreach ($forms as $form) { |
| 75 | - $pageIds = json_decode($form->generated_script_page_ids); | |
| 76 | - if (property_exists($pageIds, $postId)) { | |
| 106 | + $pageIds = Utilities::jsonObj($form->generated_script_page_ids ?? ''); | |
| 107 | + if ($pageIds && property_exists($pageIds, $postId)) { | |
| 77 | 108 | unset($pageIds->{$postId}); |
| 78 | 109 | $formModel->update(['generated_script_page_ids' => \wp_json_encode($pageIds)], ['id' => $form->id]); |
| 79 | 110 | } |
| 80 | 111 | } |
| @@ -81,31 +112,30 @@ | ||
| 81 | 112 | } |
| 82 | 113 | } |
| 83 | 114 | } |
| 84 | 115 | |
| 85 | - public static function localization_setup() | |
| 86 | - { | |
| 87 | - load_plugin_textdomain('bit-form', false, dirname(BITFORMS_PLUGIN_BASENAME) . '/languages'); | |
| 88 | - } | |
| 89 | - | |
| 90 | 116 | public static function init_classes() |
| 91 | 117 | { |
| 92 | 118 | if (Request::Check('admin')) { |
| 93 | 119 | (new Admin_Bar())->register(); |
| 120 | + TranslationManager::boot('admin'); | |
| 94 | 121 | } |
| 95 | 122 | if (Request::Check('ajax')) { |
| 96 | 123 | new AjaxService(); |
| 124 | + TranslationManager::boot('ajax'); | |
| 97 | 125 | } |
| 98 | 126 | if (Request::Check('frontend')) { |
| 99 | 127 | $formHandler = new FormHandler(); |
| 100 | 128 | $formHandler->frontend; |
| 129 | + TranslationManager::boot('frontend'); | |
| 130 | + CacheCompat::register(); | |
| 101 | 131 | } |
| 102 | 132 | if (Request::isPluginPage()) { |
| 103 | 133 | (new FileDownloadProvider())->register(); |
| 104 | 134 | } |
| 105 | - if (current_user_can('edit_posts')) { | |
| 106 | - (new GutenBlockProvider())->register(); | |
| 107 | - } | |
| 135 | + // if (current_user_can('edit_posts')) { | |
| 136 | + // (new RegisterGutenBlock())->register(); | |
| 137 | + // } | |
| 108 | 138 | include BITFORMS_PLUGIN_DIR_PATH . 'includes' . DIRECTORY_SEPARATOR . 'Frontend' . DIRECTORY_SEPARATOR . 'InitRoutes.php'; |
| 109 | 139 | } |
| 110 | 140 | |
| 111 | 141 | public static function versionUpdateRunFallbacks() |
| @@ -117,11 +147,12 @@ | ||
| 117 | 147 | } |
| 118 | 148 | |
| 119 | 149 | public static function plugin_action_links($links) |
| 120 | 150 | { |
| 121 | - $links[] = '<a href="https://docs.form.bitapps.pro" target="_blank">' . __('Docs') . '</a>'; | |
| 122 | - if (!Utilities::isPro()) { | |
| 123 | - $links[] = '<a href="https://www.bitapps.pro/bit-form" target="_blank">' . __('Upgrade to Pro') . '</a>'; | |
| 151 | + $links[] = '<a href="https://bit-form.com/wp-docs/" target="_blank">' . __('Docs', 'bit-form') . '</a>'; | |
| 152 | + if (!Utilities::isProLicensed()) { | |
| 153 | + $links[] = '<a href="https://bit-form.com/#pricing" target="_blank"><strong>' . __('Upgrade to Pro', 'bit-form') . '</strong></a>'; | |
| 154 | + // $links[] = '<a href="https://bitapps.pro/christmas-wordpress-plugin-deal/#bit-form-pricing?link_type=promo&utm_source=bit-form&utm_medium=update_button&utm_campaign=christmas&utm_content=plugins_list_directory" target="_blank"><strong>' . __('Get 50% Off! Christmas Deal.', 'bit-form') . '</strong></a>'; | |
| 124 | 155 | } |
| 125 | 156 | return $links; |
| 126 | 157 | } |
| 127 | 158 | |
| @@ -150,6 +181,22 @@ | ||
| 150 | 181 | if (!is_array($bitform_dequeued_styles)) { |
| 151 | 182 | $bitform_dequeued_styles = []; |
| 152 | 183 | } |
| 153 | 184 | $bitform_dequeued_styles = array_merge($bitform_dequeued_styles, $formIds); |
| 185 | + } | |
| 186 | + | |
| 187 | + public static function invalidateCustomUrlCache() | |
| 188 | + { | |
| 189 | + delete_transient('bitform_standalone_url_map'); | |
| 190 | + delete_transient('bitform_conversational_url_map'); | |
| 191 | + } | |
| 192 | + | |
| 193 | + public static function bitformMenuAccessCapability() | |
| 194 | + { | |
| 195 | + if (current_user_can('manage_bitform')) { | |
| 196 | + return 'manage_bitform'; | |
| 197 | + } elseif (current_user_can('access_bitform')) { | |
| 198 | + return 'access_bitform'; | |
| 199 | + } | |
| 200 | + return 'manage_options'; | |
| 154 | 201 | } |
| 155 | 202 | } |