' . wp_kses_post(
sprintf(
// Translators: %1$s is the required page builder title, %2$s is the opening anchor tag to plugins.php, %3$s is the closing anchor tag, %4$s is the plugin title.
__( 'The default page builder is set to %1$s. Please %2$sinstall & activate%3$s the %4$s to start editing the steps.', 'cartflows' ), //phpcs:ignore
'' . esc_html( $required_plugins['title'] ) . '',
'',
'',
'' . esc_html( implode( ', ', $titles ) ) . ''
)
) . '
';
}
return $notices;
}
/**
* Get required plugin titles from their slugs.
*
* @since 2.1.6
* @param array $plugins plugins array.
* @return array
*/
public function generate_plugin_titles( $plugins ) {
$titles = array();
if ( ! is_array( $plugins ) || empty( $plugins ) ) {
return $titles;
}
foreach ( $plugins as $plugin ) {
if ( 'ultimate-addons-for-gutenberg' === $plugin['slug'] ) {
$title = 'Spectra'; // Don't add this for translation as it is a plugin name.
} else {
$slug_parts = explode( '-', $plugin['slug'] );
$title = implode( ' ', array_map( 'ucfirst', $slug_parts ) ); // Convert each part to title case.
}
$titles[] = $title;
}
return $titles;
}
/**
* Get required plugin status.
*/
public function get_required_plugins_data() {
$missing_plugins_data = array();
$page_builder_plugins = \Cartflows_Helper::get_plugins_groupby_page_builders();
foreach ( $page_builder_plugins as $slug => $data ) {
$missing_plugins_data[ $slug ] = 'no';
$current_page_builder_data = $page_builder_plugins[ $slug ];
foreach ( $current_page_builder_data['plugins'] as $plugin ) {
if ( 'activate' === $plugin['status'] || 'install' === $plugin['status'] ) {
$missing_plugins_data[ $slug ] = 'yes';
}
}
// Divi.
if ( 'divi' === $slug ) {
if ( 'activate' === $current_page_builder_data['theme-status'] ) {
$missing_plugins_data[ $slug ] = 'yes';
}
}
}
return $missing_plugins_data;
}
/**
* Get required plugin status
*/
public function get_any_required_plugins_status() {
$default_page_builder = \Cartflows_Helper::get_common_setting( 'default_page_builder' );
$any_inactive = 'no';
$page_builder_plugins = \Cartflows_Helper::get_plugins_groupby_page_builders();
if ( isset( $page_builder_plugins[ $default_page_builder ] ) ) {
$current_page_builder_data = $page_builder_plugins[ $default_page_builder ];
foreach ( $current_page_builder_data['plugins'] as $plugin ) {
if ( 'activate' === $plugin['status'] || 'install' === $plugin['status'] ) {
$any_inactive = 'yes';
}
}
// Divi.
if ( 'divi' === $default_page_builder ) {
if ( 'activate' === $current_page_builder_data['theme-status'] ) {
$any_inactive = 'yes';
}
}
}
return $any_inactive;
}
/**
* Get CartFlows plugin status
*
* @since 1.11.8
*
* @return string
*/
public function get_cartflows_pro_plugin_status() {
$status = $this->get_plugin_status( 'cartflows-pro/cartflows-pro.php' );
if ( 'active' === $status && ! _is_cartflows_pro() ) {
$status = 'inactive';
}
return $status;
}
/**
* Get plugin status
*
* @since 1.1.4
*
* @param string $plugin_init_file Plguin init file.
* @return mixed
*/
public function get_plugin_status( $plugin_init_file ) {
$installed_plugins = get_plugins();
if ( ! isset( $installed_plugins[ $plugin_init_file ] ) ) {
return 'not-installed';
} elseif ( is_plugin_active( $plugin_init_file ) ) {
return 'active';
} else {
return 'inactive';
}
}
/**
* Get plugin status
*
* @since 1.1.4
*
* @param string $theme_name Theme slug file.
* @return string
*/
public function get_themes_status( $theme_name ) {
$theme = wp_get_theme();
// Theme installed and activate.
if ( $theme_name === $theme->name || $theme_name === $theme->parent_theme ) {
return 'active';
}
// Theme installed but not activate.
foreach ( (array) wp_get_themes() as $theme_dir => $theme ) {
if ( $theme_name === $theme->name || $theme_name === $theme->parent_theme ) {
return 'inactive';
}
}
// If none of the above conditions are found then the theme is not installed.
return 'not-installed';
}
/**
* Settings app scripts
*
* @param array $localize Variable names.
*/
public function settings_app_scripts( $localize ) {
$handle = 'wcf-react-settings';
$build_path = CARTFLOWS_ADMIN_CORE_DIR . 'assets/build/';
$build_url = CARTFLOWS_ADMIN_CORE_URL . 'assets/build/';
$script_asset_path = $build_path . 'settings-app.asset.php';
$script_info = file_exists( $script_asset_path )
? include $script_asset_path
: array(
'dependencies' => array(),
'version' => CARTFLOWS_VER,
);
$script_dep = array_merge( $script_info['dependencies'], array( 'updates' ) );
wp_register_script(
$handle,
$build_url . 'settings-app.js',
$script_dep,
$script_info['version'],
true
);
wp_register_style(
$handle,
$build_url . 'settings-app.css',
array(),
CARTFLOWS_VER
);
wp_enqueue_script( $handle );
wp_set_script_translations( $handle, 'cartflows' );
wp_enqueue_style( $handle );
wp_style_add_data( $handle, 'rtl', 'replace' );
$localize['is_flows_limit'] = false; // Removed the flow count condition.
$localize = $this->debugger_scripts( $localize );
$localize['save_learn_completed_nonce'] = wp_create_nonce( 'cartflows_save_learn_completed' );
$localize['activate_plugin_nonce'] = wp_create_nonce( 'cartflows_activate_plugin' );
wp_localize_script( $handle, 'cartflows_admin', $localize );
}
/**
* Settings app scripts
*
* @param array $localize Variable names.
*/
public function editor_app_scripts( $localize ) {
$handle = 'wcf-editor-app';
$build_path = CARTFLOWS_ADMIN_CORE_DIR . 'assets/build/';
$build_url = CARTFLOWS_ADMIN_CORE_URL . 'assets/build/';
$script_asset_path = $build_path . 'editor-app.asset.php';
$script_info = file_exists( $script_asset_path )
? include $script_asset_path
: array(
'dependencies' => array(),
'version' => CARTFLOWS_VER,
);
wp_register_script(
$handle,
$build_url . 'editor-app.js',
$script_info['dependencies'],
$script_info['version'],
true
);
wp_register_style(
$handle,
$build_url . 'editor-app.css',
array(),
CARTFLOWS_VER
);
wp_enqueue_script( $handle );
wp_set_script_translations( $handle, 'cartflows' );
wp_enqueue_style( $handle );
wp_style_add_data( $handle, 'rtl', 'replace' );
$localize['flow_id'] = isset( $_GET['flow_id'] ) ? intval( $_GET['flow_id'] ) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
$step_id = isset( $_GET['step_id'] ) ? intval( $_GET['step_id'] ) : false; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( $step_id ) {
$meta_options = AdminHelper::get_step_meta_options( $step_id );
$localize['options'] = $meta_options['options'];
}
wp_localize_script( $handle, 'cartflows_admin', $localize );
}
/**
* Debugger scripts.
*
* @param array $localize Variable names.
*/
public function debugger_scripts( $localize ) {
$logs = LogStatus::get_instance()->get_log_files();
$viewed_log = '';
$viewed_log_file = '';
// Calling this function on CartFlows action hook. Hence ignoring nonce.
if ( ! empty( $_REQUEST['log_file'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
$filename = sanitize_text_field( wp_unslash( $_REQUEST['log_file'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $logs[ $filename ] ) ) {
$viewed_log = $filename;
$viewed_log_file = $viewed_log . '.log';
}
} elseif ( ! empty( $logs ) ) {
$viewed_log = current( $logs ) ? pathinfo( current( $logs ), PATHINFO_FILENAME ) : '';
$viewed_log_file = $viewed_log . '.log';
}
if ( ! empty( $viewed_log_file ) ) {
$file_content = file_get_contents( CARTFLOWS_LOG_DIR . $viewed_log_file );
$localize['file_content'] = $file_content;
$localize['log_key'] = $viewed_log;
}
$localize['logs'] = $logs;
return $localize;
}
/**
* CHeck if it is current page by parameters
*
* @param string $page_slug Menu name.
* @param string $action Menu name.
*
* @return string page url
*/
public function is_current_page( $page_slug = '', $action = '' ) {
$page_matched = false;
if ( empty( $page_slug ) ) {
return false;
}
$current_page_slug = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
$current_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! is_array( $action ) ) {
$action = explode( ' ', $action );
}
if ( $page_slug === $current_page_slug && in_array( $current_action, $action, true ) ) {
$page_matched = true;
}
return $page_matched;
}
/**
* Add footer link.
*/
public function add_footer_link() {
$logs_page_url = add_query_arg(
array(
'page' => CARTFLOWS_SLUG,
'path' => 'wcf-log',
),
admin_url( '/admin.php' )
);
return ' |