$my_plugin_name, 'dependency_plugin_name' => $dependency_plugin_name, 'version_to_check' => $version_to_check, ]; $success = false; } else { // Get the plugin dependency info. $version = wpbmod_get_plugin_version( WP_PLUGIN_DIR . '/' . $path_to_plugin ); // Compare version. $is_required_version = ! version_compare( $version, $version_to_check, '>=' ); if ( $is_required_version ) { $template_payload = [ 'my_plugin_name' => $my_plugin_name, 'dependency_plugin_name' => $dependency_plugin_name, 'version_to_check' => $version_to_check, ]; $success = false; } } if ( ! $success ) { add_action( 'admin_notices', function () use ( $template_payload ) { wpbmod_include_template( 'required-plugin-notification.php', $template_payload ); } ); } return $success; } endif; if ( ! function_exists( 'wpbmod_get_plugin_version' ) ) : /** * Get the plugin version, parsing main plugin file. * * @param string $plugin_file_path * * @return bool|string */ function wpbmod_get_plugin_version( $plugin_file_path ) { // phpcs:ignore:WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $plugin_data = file_get_contents( $plugin_file_path ); if ( preg_match( '/^[ \t\/*#@]*[Vv]ersion\s*:\s*([^\r\n]+)/m', $plugin_data, $matches ) ) { return trim( $matches[1] ); } return false; } endif; if ( ! function_exists( 'wpbmod_get_template' ) ) : /** * Include template from templates dir. * * @param string $template * @param array $variables - passed variables to the template. * * @param bool $once * * @return mixed * @since 1.0 */ function wpbmod_include_template( $template, $variables = [], $once = false ) { // phpcs:ignore:WordPress.PHP.DontExtract.extract_extract is_array( $variables ) && extract( $variables ); if ( $once ) { return require_once wpbmod_template( $template ); } else { return require wpbmod_template( $template ); } } endif; if ( ! function_exists( 'wpbmod_get_template' ) ) : /** * Output template from templates dir. * * @param string $template * @param array $variables - passed variables to the template. * * @param bool $once * * @return string * @since 1.0 */ function wpbmod_get_template( $template, $variables = [], $once = false ) { ob_start(); $output = wpbmod_include_template( $template, $variables, $once ); if ( 1 === $output ) { $output = ob_get_contents(); } ob_end_clean(); return $output; } endif; if ( ! function_exists( 'wpbmod_template' ) ) : /** * Shorthand for getting to plugin templates. * * @param string $file * * @since 1.0 * * @return string */ function wpbmod_template( $file ) { return WPBMOD_TEMPLATES_DIR . '/' . $file; } endif;