8889841cEditor/Full_Site/Template_Utils.php000064400000004174150444366050013341 0ustar00> $blocks Array of parsed block objects. * * @return array> Block references to the passed blocks and their inner blocks. */ public static function flatten_blocks( &$blocks ) { $all_blocks = []; $queue = []; foreach ( $blocks as &$block ) { $queue[] = &$block; } $queue_count = count( $queue ); while ( $queue_count > 0 ) { $block = &$queue[0]; array_shift( $queue ); $all_blocks[] = &$block; if ( ! empty( $block['innerBlocks'] ) ) { foreach ( $block['innerBlocks'] as &$inner_block ) { $queue[] = &$inner_block; } } $queue_count = count( $queue ); } return $all_blocks; } /** * Parses wp_template content and injects the current theme's stylesheet as a theme attribute into * each wp_template_part. * * @since 4.14.18 * * @param string $template_content serialized wp_template content. * * @return string Updated wp_template content. */ public static function inject_theme_attribute_in_content( $template_content ) { $has_updated_content = false; $new_content = ''; $template_blocks = parse_blocks( $template_content ); $blocks = static::flatten_blocks( $template_blocks ); foreach ( $blocks as &$block ) { if ( 'core/template-part' === $block['blockName'] && ! isset( $block['attrs']['theme'] ) ) { $block['attrs']['theme'] = wp_get_theme()->get_stylesheet(); $has_updated_content = true; } } if ( $has_updated_content ) { foreach ( $template_blocks as &$block ) { $new_content .= serialize_block( $block ); } return $new_content; } return $template_content; } } Translations_Loader.php000064400000012156150444366050011240 0ustar00 */ protected $loaded_domains = []; /** * Switches the locale to the one specified. * * Note: the method will not check what the current locale is and will just load the * translations specified. The burden of checking the current locale is on the caller. * * @since 5.0.8 * * @param string $locale The locale to switch to. * @param array $domains A map from text domains to the directory containing the translations. * * @return bool Whether the locale was switched or not. */ public function load( string $locale, array $domains = [] ): bool { if ( empty( $domains ) ) { return false; } /** * Fires before the locale translations are loaded. * * @since 5.0.8 * * @param string $locale The locale that will be loaded. * @param array $domains The list of domains translations will be loaded for. */ do_action( 'tec_locale_translations_load_before', $locale, $domains ); $this->has_loaded_translations = true; $this->override_locale = $locale; $this->loaded_domains = $domains; /* * The `plugin_locale` filter will be applied in `load_plugin_textdomain()` to determine * the language file to load. */ add_filter( 'plugin_locale', [ $this, 'override_locale' ] ); $this->load_locale_translations( $domains, $locale ); remove_filter( 'plugin_locale', [ $this, 'override_locale' ] ); /** * Fires after the locale translations are loaded. * * @since 5.0.8 * * @param string $locale The locale that has been loaded. * @param array $domains The list of domains translations have been loaded for. */ do_action( 'tec_locale_translations_load_after', $locale, $domains ); return true; } /** * A proxy method to return the current override locale if set, or the input locale otherwise. * * Used during filter application. * * @since 5.0.8 * * @param string $locale The locale to override. * * @return string The overridden locale. * * @internal This function is public only for the purpose of being used as a filter callback. */ public function override_locale( $locale ) { return $this->override_locale ?: $locale; } /** * Returns whether the locale has been switched or not. * * @since 5.0.8 * * @return bool Whether the locale has been switched or not. */ public function has_loaded_translations(): bool { return $this->has_loaded_translations; } /** * Restored the locale to the previous one and removes the class filters. * * @since 5.0.8 * * @return void Translations for each domain will be reloaded. */ public function restore() { if ( ! $this->has_loaded_translations ) { return; } $this->override_locale = ''; /** * Fires before the locale translations are restored. * * @since 5.0.8 * * @param array $domains The list of domains translations will be loaded for. */ do_action( 'tec_locale_translations_restore_before', $this->loaded_domains ); // Reload the translations using the currently determined locale. $this->load_locale_translations( $this->loaded_domains, determine_locale() ); /** * Fires after the locale translations are restored. * * @since 5.0.8 * * @param array $domains The list of domains translations have been loaded for. */ do_action( 'tec_locale_translations_restore_after', $this->loaded_domains ); $this->has_loaded_translations = false; } /** * Load the translations for the map of domains for the current locale. * * @since 5.0.8 * * @param array $domains A map from text domains to the directory containing the translations. * @param string $locale The locale to load the translations for. * * @return void Translations for each domain will be loaded for the current plugin locale. */ protected function load_locale_translations( array $domains, string $locale ): void { global $l10n; if ( ! is_array( $l10n ) ) { $l10n = []; } foreach ( $domains as $domain => $lang_dir ) { unload_textdomain( $domain, true ); if ( $locale === 'en_US' ) { // There is no `en_US` language pack since it's the default, no-op the translations. $l10n[ $domain ] = new \NOOP_Translations(); } else { // Load the translations using the wrapper Common function. $dir = is_string( $lang_dir ) && ! empty( $lang_dir ) ? $lang_dir : false; \Tribe__Main::instance()->load_text_domain( $domain, $dir ); } } } } Storage/Timed_Option.php000064400000022314150444366050011264 0ustar00active = false; } /** * Activate the usage of Database Timed Options. * * @since 5.0.6 * * @return void */ public function activate(): void { $this->active = true; } /** * Is the timed options active? * * @since 5.0.6 * * @return bool */ public function is_active(): bool { /** * Allows the modification of the state of usage for Timed Options. * * @since 5.0.6 * * @param bool $active Whether we use Database Timed Options or a glorified Memoization system. */ return (bool) apply_filters( 'tec_common_timed_option_is_active', $this->active ); } /** * Gets the option name for a given timed option, by attaching a prefix and allowing filtering. * * @since 5.0.6 * * @param string $key Key for the option we are trying to get the option name for. * * @return string */ public function get_option_name( string $key ): string { /** * Allows the modification of where we store the Transient Data. * * @since 5.0.6 * * @param string $option_name Name of the option where all the transient data will live. */ return (string) apply_filters( 'tec_common_timed_option_name', $this->option_name_prefix . $key, $this->option_name_prefix ); } /** * Fetches the value of a given timed option. * * @since 5.0.6 * * @param string $key Key for the option we are trying to get. * @param mixed $default Default value when the option is either expired or not-set. * @param bool $force If we should expire cache and fetch from the database. * * @return mixed|null */ public function get( $key, $default = null, bool $force = false ) { /** * Allows the filtering the default timed_option value. * * @since 5.0.6 * * @param mixed $default Default value when the option is either expired or not-set. * @param string $key Key for the option we are trying to get. * @param bool $force If we should expire cache and fetch from the database. */ $default = apply_filters( 'tec_common_timed_option_default_value', $default, $key, $force ); /** * Allows the filtering to short-circuit the whole fetch logic. * * @since 5.0.6 * * @param mixed|null $pre If anything diff than null it will short-circuit. * @param string $key Key for the option we are trying to get. * @param mixed $default Default value when the option is either expired or not-set. * @param bool $force If we should expire cache and fetch from the database. */ $pre = apply_filters( 'tec_common_timed_option_pre_value', null, $key, $default, $force ); if ( null !== $pre ) { return $pre; } $time = time(); // If we have a stored value that is not expired, use it. if ( ! $force && isset( $this->data[ $key ] ) && is_numeric( $this->data[ $key ]['expiration'] ) && $time < $this->data[ $key ]['expiration'] ) { /** * Allows the filtering of the cached value of the timed option. * * @since 5.0.6 * * @param mixed $value If anything diff than null it will short-circuit. * @param string $key Key for the option we are trying to get. * @param mixed $default Default value when the option is either expired or not-set. * @param bool $force If we should expire cache and fetch from the database. * @param bool $cache If the value was pulled from cache. */ return apply_filters( 'tec_common_timed_option_value', $this->data[ $key ]['value'], $key, $default, $force, true ); } $timed_option = null; if ( $this->is_active() ) { $timed_option_name = $this->get_option_name( $key ); if ( true === $force ) { wp_cache_delete( $timed_option_name, 'options' ); } $timed_option = get_option( $timed_option_name, null ); } // Bail with default when non-existent. if ( empty( $timed_option ) ) { if ( $this->is_active() ) { // Avoids next request check, forces auto-loading. $this->set( $key, null, 0 ); } return $default; } // Bail with default when expired. if ( $time >= $timed_option['expiration'] ) { $this->delete( $key ); return $default; } $this->data[ $key ] = $timed_option; /** * Allows the filtering of the value of the timed option. * * @since 5.0.6 * * @param mixed $value If anything diff than null it will short-circuit. * @param string $key Key for the option we are trying to get. * @param mixed $default Default value when the option is either expired or not-set. * @param bool $force If we should expire cache and fetch from the database. * @param bool $cache If the value was pulled from cache. */ return apply_filters( 'tec_common_timed_option_value', $timed_option['value'], $key, $default, $force, false ); } /** * Delete a given timed option based on a key. * Will also clear local cache. * * @since 5.0.6 * * @param string $key Which timed option we are checking. * * @return bool */ public function delete( $key ): bool { $key = (string) $key; $updated = false; if ( $this->is_active() ) { $timed_option_name = $this->get_option_name( $key ); $updated = update_option( $timed_option_name, null, true ); wp_cache_delete( $timed_option_name, 'options' ); } // Bail with default when non-existent. if ( ! isset( $this->data[ $key ] ) ) { return $updated; } unset( $this->data[ $key ] ); return $updated; } /** * Checks if a given timed option exists. * * @since 5.0.6 * * @param string $key Which timed option we are checking. * @param bool $force Clears the cache before get_option() * * @return bool */ public function exists( $key, bool $force = false ): bool { /** * Allows the filtering to short-circuit the whole exists logic. * * @since 5.0.6 * * @param mixed|null $pre If anything diff than null it will short-circuit. * @param string $key Key for the option we are trying to get. * @param bool $force If we should expire cache and fetch from the database. */ $pre = apply_filters( 'tec_common_timed_option_pre_exists', null, $key, $force ); if ( null !== $pre ) { return (bool) $pre; } $time = time(); $cached = false; $timed_option = null; // If we have a stored value that is not expired, use it. if ( ! $force && isset( $this->data[ $key ] ) && is_numeric( $this->data[ $key ]['expiration'] ) && $time < $this->data[ $key ]['expiration'] ) { $cached = true; $timed_option = $this->data[ $key ]; } elseif ( $this->is_active() ) { $timed_option_name = $this->get_option_name( $key ); if ( true === $force ) { wp_cache_delete( $timed_option_name, 'options' ); } $timed_option = get_option( $timed_option_name, null ); } $exists = true; if ( null === $timed_option ) { $exists = false; } if ( ! is_array( $timed_option ) ) { $exists = false; } if ( ! isset( $timed_option['expiration'] ) || ! is_numeric( $timed_option['expiration'] ) ) { $exists = false; } /** * Does a particular timed option key exists. * * @since 5.0.6 * * @param mixed $exists If anything diff than null it will short-circuit. * @param string $key Key for the option we are trying to get. * @param bool $force If we should expire cache and fetch from the database. * @param bool $cached If the value was pulled from cache. */ return (bool) apply_filters( 'tec_common_timed_option_exists', $exists, $key, $force, $cached ); } /** * Update the value of a timed option on the database and on local cache. * * @since 5.0.6 * * @param string $key Key for this option. * @param mixed $value Value stored for this option. * @param int $expiration Expiration in seconds for this timed option. * * @return bool */ public function set( $key, $value, int $expiration = DAY_IN_SECONDS ): bool { $key = (string) $key; $data = [ 'key' => $key, 'value' => $value, 'expiration' => time() + $expiration, ]; $this->data[ $key ] = $data; $updated = true; if ( $this->is_active() ) { $updated = update_option( $this->get_option_name( $key ), $data, true ); } return $updated; } }Context/Post_Request_Type.php000064400000010124150444366050012344 0ustar00 $post_type The post type or post types to check. * * @return bool Whether the current request is one to quick edit a single post of the specified post type or not. */ public function is_inline_editing_post( $post_type ): bool { if ( ! ( ! empty( $post_type ) && wp_doing_ajax() && tribe_get_request_var( 'action' ) === 'inline-save' ) ) { return false; } $post_id = tribe_get_request_var( 'post_ID', null ); if ( empty( $post_id ) || ! is_numeric( $post_id ) ) { return false; } return in_array( get_post_type( $post_id ), (array) $post_type, true ); } /** * Whether the current request is one to edit a list of the specified post types or not. * * The admin edit screen for a post type is the one that lists all the posts of that typ, * it has the URL `/wp-admin/edit.php?post_type=`. * * @since 5.0.13 * * @param string|array $post_type The post type or post types to check. * * @return bool Whether the current request is one to edit a list of the specified post types or not. */ public function is_editing_post_list( $post_type ): bool { // Quick check: are we on the `/wp-admin/edit.php` page? global $pagenow; if ( $pagenow !== 'edit.php' ) { return false; } // Run some more thorough checks for the post type(s). $post_types = array_filter( (array) $post_type ); return $this->is_editing_post( $post_types ); } /** * Whether we are currently creating a new post, a post of post type(s) or not. * * @since 4.7.7 * * @param null $post_type The optional post type to check. * * @return bool Whether we are currently creating a new post, a post of post type(s) or not. */ public function is_new_post( $post_type = null ): bool { global $pagenow; $is_new = 'post-new.php' === $pagenow; return $is_new && $this->is_editing_post( $post_type ); } /** * Whether we are currently editing a post(s), post type(s) or not. * * @since 4.7.7 * * @param null|array|string|int $post_or_type A post ID, post type, an array of post types or post IDs, `null` * to just make sure we are currently editing a post. * * @return bool */ public function is_editing_post( $post_or_type = null ): bool { global $pagenow; $is_new = 'post-new.php' === $pagenow; $is_post = 'post.php' === $pagenow; $is_editing = 'edit.php' === $pagenow; if ( ! ( $is_new || $is_post || $is_editing ) ) { return false; } if ( ! empty( $post_or_type ) ) { $lookup = []; // Prevent a slew of warnings every time we call this. if ( isset( $_REQUEST ) ) { $lookup[] = (array) $_REQUEST; } if ( isset( $_GET ) ) { $lookup[] = (array) $_GET; } if ( isset( $_POST ) ) { $lookup[] = (array) $_POST; } if ( empty( $lookup ) ) { return false; } $current_post = Arr::get_in_any( $lookup, 'post', get_post() ); if ( is_numeric( $post_or_type ) ) { $post = $is_post ? get_post( $post_or_type ) : null; return ! empty( $post ) && $post == $current_post; } $post_types = is_array( $post_or_type ) ? $post_or_type : [ $post_or_type ]; $post = $is_post ? get_post( $current_post ) : null; if ( count( array_filter( $post_types, 'is_numeric' ) ) === count( $post_types ) ) { return ! empty( $post ) && in_array( $post->ID, $post_types ); } if ( $is_post && $post instanceof WP_Post ) { $post_type = $post->post_type; } else { $post_type = Arr::get_in_any( $lookup, 'post_type', 'post' ); } return (bool) count( array_intersect( $post_types, [ $post_type ] ) ); } return $is_new || $is_post; } } Provider/Controller.php000064400000007101150444366050011200 0ustar00container->singleton( static::class, $this ); if ( ! $this->is_active() ) { return; } $this->container->setVar( static::class . '_registered', true ); $this->do_register(); } /** * Registers the filters and actions hooks added by the controller. * * @since 5.0.17 * * @return void */ abstract protected function do_register(): void; /** * Removes the filters and actions hooks added by the controller. * * Bound implementations should not be removed in this method! * * @since 5.0.17 * * @return void Filters and actions hooks added by the controller are be removed. */ abstract public function unregister(): void; /** * Whether the controller is active or not. * * Controllers will be active by default, if that is not the case, the controller should override this method. * * @since 5.0.17 * * @return bool Whether the controller is active or not. */ public function is_active(): bool { return true; } /** * Logs a message at the `debug` level. * * @since 5.0.17 * * @param string $message The message to log. * @param array $context An array of context to log with the message. * * @return void The message is logged. */ protected function debug( string $message, array $context = [] ): void { do_action( 'tribe_log', Log::DEBUG, $message, array_merge( [ 'controller' => static::class, ], $context ) ); } /** * Logs a message at the `warning` level. * * @since 5.0.17 * * @param string $message The message to log. * @param array $context An array of context to log with the message. * * @return void The message is logged. */ protected function warning( string $message, array $context = [] ): void { do_action( 'tribe_log', Log::WARNING, $message, array_merge( [ 'controller' => static::class, ], $context ) ); } /** * Logs a message at the `error` level. * * @since 5.0.17 * * @param string $message The message to log. * @param array $context An array of context to log with the message. * * @return void The message is logged. */ protected function error( string $message, array $context = [] ): void { do_action( 'tribe_log', Log::ERROR, $message, array_merge( [ 'controller' => static::class, ], $context ) ); } /** * Returns whether any instance of this controller has been registered or not. * * @since 5.0.17 * * @return bool Whether any instance of this controller has been registered or not. */ public static function is_registered(): bool { return (bool) tribe()->getVar( static::class . '_registered' ); } } Libraries/Installer/Provider.php000064400000001746150444366050012737 0ustar00container->singleton( static::class, $this ); $hook_prefix = $this->container->make( Libraries\Provider::class )->get_hook_prefix(); Installer\Config::set_hook_prefix( $hook_prefix ); add_filter( "stellarwp/installer/{$hook_prefix}/button_classes", [ $this, 'filter_button_classes' ] ); } /** * Filters the installer button classes. * * @since 5.0.10 * * @param array|mixed $classes The button classes. * * @return array */ public function filter_button_classes( $classes ) { if ( ! is_array( $classes ) ) { $classes = (array) $classes; } $classes[] = 'components-button'; $classes[] = 'is-primary'; $classes[] = 'tec-admin__notice-install-content-button'; return $classes; } } Libraries/Provider.php000064400000001233150444366050010771 0ustar00container->singleton( static::class, $this ); tribe_register_provider( Installer\Provider::class ); DB\Config::setHookPrefix( $this->get_hook_prefix() ); } /** * Gets the hook prefix. * * @since 5.0.10 * * @return string */ public function get_hook_prefix(): string { return static::$hook_prefix; } } GeneratorCommonLoader.php000064400000000266150515530160011510 0ustar00