se, 'expected' => $values['expected'], // WC doesn't use this, but it's useful for us ); } return $rows; } /** * Saves errors or messages to WooCommerce Log (woocommerce/logs/plugin-id-xxx.txt) * * @since 2.0.0 * @param string $message error or message to save to log * @param string $log_id optional log id to segment the files by, defaults to plugin id * @param string $level optional log level represents log's tag, defaults to notice */ public function log( $message, $log_id = null, $level = null ) { if ( is_null( $log_id ) ) { $log_id = $this->get_id(); } if ( is_null( $level ) ) { $level = \WC_Log_Levels::NOTICE; } if ( ! is_object( $this->logger ) ) { $this->logger = new \WC_Logger(); } $this->logger->log( $level, $message, array( 'source' => $log_id, ) ); } /** Getter methods ******************************************************/ /** * Gets the main plugin file. * * @since 5.0.0 * * @return string */ public function get_plugin_file() { $slug = dirname( plugin_basename( $this->get_file() ) ); return trailingslashit( $slug ) . $slug . '.php'; } /** * The implementation for this abstract method should simply be: * * Return __FILE__; * * @since 2.0.0 * @return string the full path and filename of the plugin file */ abstract protected function get_file(); /** * Returns the plugin id * * @since 2.0.0 * @return string plugin id */ public function get_id() { return $this->id; } /** * Returns the plugin id with dashes in place of underscores, and * appropriate for use in frontend element names, classes and ids * * @since 2.0.0 * @return string plugin id with dashes in place of underscores */ public function get_id_dasherized() { return str_replace( '_', '-', $this->get_id() ); } /** * Returns the plugin full name including "WooCommerce", ie * "WooCommerce X". This method is defined abstract for localization purposes * * @since 2.0.0 * @return string plugin name */ abstract public function get_plugin_name(); /** * Gets the dependency handler. * * @since 5.2.0.1 * * @return Dependencies */ public function get_dependency_handler() { return $this->dependency_handler; } /** * Gets the lifecycle handler instance. * * @since 5.1.0 * * @return \WooCommerce\Facebook\Lifecycle */ public function get_lifecycle_handler() { return $this->lifecycle_handler; } /** * Gets the admin message handler. * * @return AdminMessageHandler */ public function get_message_handler() { return $this->message_handler; } /** * Gets the admin notice handler instance. * * @since 3.0.0 * * @return AdminNoticeHandler */ public function get_admin_notice_handler() { return $this->admin_notice_handler; } /** * Returns the plugin version name. Defaults to wc_{plugin id}_version * * @since 2.0.0 * @return string the plugin version name */ public function get_plugin_version_name() { return 'wc_' . $this->get_id() . '_version'; } /** * Returns the current version of the plugin * * @since 2.0.0 * @return string plugin version */ public function get_version() { return $this->version; } /** * Returns the "Configure" plugin action link to go directly to the plugin * settings page (if any) * * @since 2.0.0 * @see SV_WC_Plugin::get_settings_url() * @param string $plugin_id optional plugin identifier. Note that this can be a * sub-identifier for plugins with multiple parallel settings pages * (ie a gateway that supports both credit cards and echecks) * @return string plugin configure link */ public function get_settings_link( $plugin_id = null ) { $settings_url = $this->get_settings_url( $plugin_id ); if ( $settings_url ) { return sprintf( '%s', $settings_url, esc_html__( 'Configure', 'facebook-for-woocommerce' ) ); } // no settings return ''; } /** * Gets the plugin configuration URL * * @since 2.0.0 * @see SV_WC_Plugin::get_settings_link() * @param string $plugin_id optional plugin identifier. Note that this can be a * sub-identifier for plugins with multiple parallel settings pages * (ie a gateway that supports both credit cards and echecks) * @return string plugin settings URL */ // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter public function get_settings_url( $plugin_id = null ) { // stub method return ''; } /** * Returns the admin configuration url for the admin general configuration page * * @since 3.0.0 * @return string admin configuration url for the admin general configuration page */ public function get_general_configuration_url() { return admin_url( 'admin.php?page=wc-settings&tab=general' ); } /** * Gets the plugin documentation url, used for the 'Docs' plugin action * * @since 2.0.0 * @return string documentation URL */ public function get_documentation_url() { return null; } /** * Gets the support URL, used for the 'Support' plugin action link * * @since 4.0.0 * @return string support url */ public function get_support_url() { return null; } /** * Gets the plugin sales page URL. * * @since 5.1.0 * * @return string */ public function get_sales_page_url() { return ''; } /** * Gets the plugin reviews page URL. * * Used for the 'Reviews' plugin action and review prompts. * * @since 5.1.0 * * @return string */ public function get_reviews_url() { return $this->get_sales_page_url() ? $this->get_sales_page_url() . '#comments' : ''; } /** * Gets the plugin's path without a trailing slash. * * E.g. /path/to/wp-content/plugins/plugin-directory * * @since 2.0.0 * * @return string */ public function get_plugin_path() { if ( null === $this->plugin_path ) { $this->plugin_path = untrailingslashit( plugin_dir_path( $this->get_file() ) ); } return $this->plugin_path; } /** * Gets the plugin's URL without a trailing slash. * * E.g. http://skyverge.com/wp-content/plugins/plugin-directory * * @since 2.0.0 * * @return string */ public function get_plugin_url() { if ( null === $this->plugin_url ) { $this->plugin_url = untrailingslashit( plugins_url( '/', $this->get_file() ) ); } return $this->plugin_url; } /** * Returns the loaded framework __FILE__ * * @since 4.0.0 * @return string */ public function get_framework_file() { return __FILE__; } /** * Gets the loaded framework path, without trailing slash. * * This matches the path to the highest version of the framework currently loaded. * * @since 4.0.0 * @return string */ public function get_framework_path() { return untrailingslashit( plugin_dir_path( $this->get_framework_file() ) ); } /** * Gets the absolute path to the loaded framework image directory, without a trailing slash. * * @since 4.0.0 * * @return string */ public function get_framework_assets_path() { return $this->get_framework_path() . '/assets'; } /** * Gets the loaded framework assets URL without a trailing slash. * * @since 4.0.0 * * @return string */ public function get_framework_assets_url() { return untrailingslashit( plugins_url( '/assets', $this->get_framework_file() ) ); } /** * Determines whether a plugin is active. * * @since 2.0.0 * * @param string $plugin_name plugin name, as the plugin-filename.php * @return boolean true if the named plugin is installed and active */ public function is_plugin_active( $plugin_name ) { $is_active = false; if ( is_string( $plugin_name ) ) { if ( ! array_key_exists( $plugin_name, $this->active_plugins ) ) { $active_plugins = (array) get_option( 'active_plugins', [] ); if ( is_multisite() ) { $active_plugins = array_merge( $active_plugins, array_keys( get_site_option( 'active_sitewide_plugins', [] ) ) ); } $plugin_filenames = []; foreach ( $active_plugins as $plugin ) { if ( Helper::str_exists( $plugin, '/' ) ) { // normal plugin name (plugin-dir/plugin-filename.php) list( , $filename ) = explode( '/', $plugin ); } else { // no directory, just plugin file $filename = $plugin; } $plugin_filenames[] = $filename; } $this->active_plugins[ $plugin_name ] = in_array( $plugin_name, $plugin_filenames, true ); } $is_active = (bool) $this->active_plugins[ $plugin_name ]; } return $is_active; } }