$value ) { if( $value['active'] && ! $value['valid_key'] ) { $msg = sprintf( __( 'Hi there, thanks for your purchase. One last step, please activate your %s here now.', ARVE_SLUG ), $value['name'], get_admin_url() . 'admin.php?page=nextgenthemes-licenses' ); new ARVE_Admin_Notice_Factory( $key . '-activation-notice', "
$msg
", false ); } } } function nextgenthemes_get_products() { $products = array( 'arve_pro' => array( 'name' => 'Advanced Responsive Video Embedder Pro', 'type' => 'plugin', 'author' => 'Nicolas Jonas', 'url' => 'https://nextgenthemes.com/plugins/advanced-responsive-video-embedder-pro/', ), 'arve_amp' => array( 'name' => 'ARVE Accelerated Mobile Pages Addon', 'type' => 'plugin', 'author' => 'Nicolas Jonas', 'url' => 'https://nextgenthemes.com/plugins/arve-accelerated-mobile-pages-addon/', ) ); $products = apply_filters( 'nextgenthemes_products', $products ); foreach ( $products as $key => $value ) { $products[ $key ]['slug'] = $key; $products[ $key ]['installed'] = false; $products[ $key ]['active'] = false; $products[ $key ]['valid_key'] = nextgenthemes_has_valid_key( $key ); $version_define = strtoupper( $key ) . '_VERSION'; $file_define = strtoupper( $key ) . '_FILE'; if( defined( $version_define ) ) { $products[ $key ]['version'] = constant( $version_define ); } if( defined( $file_define ) ) { $products[ $key ]['file'] = constant( $file_define ); } if ( 'plugin' == $value['type'] ) { $file_slug = str_replace( '_', '-', $key ); $products[ $key ]['installed'] = nextgenthemes_is_plugin_installed( "$file_slug/$file_slug.php" ); if ( ! empty( $products[ $key ]['file'] ) ) { $plugin_basename = plugin_basename( $products[ $key ]['file'] ); $products[ $key ]['active'] = is_plugin_active( $plugin_basename ); } } } return $products; } function nextgenthemes_is_plugin_installed( $plugin_basename ) { $plugins = get_plugins(); if( array_key_exists( $plugin_basename, $plugins ) ) { return true; } else { return false; } } /** * Register the administration menu for this plugin into the WordPress Dashboard menu. * * @since 1.0.0 */ function nextgenthemes_menus() { $plugin_screen_hook_suffix = add_menu_page( __( 'Nextgenthemes', ARVE_SLUG ), # Page Title __( 'Nextgenthemes', ARVE_SLUG ), # Menu Tile 'manage_options', # capability 'nextgenthemes', # menu-slug '__return_empty_string', # function 'dashicons-admin-settings', # icon_url null # position ); /* add_submenu_page( 'nextgenthemes', # parent_slug __( 'Addons and Themes', ARVE_SLUG ), # Page Title __( 'Addons and Themes', ARVE_SLUG ), # Menu Tile 'manage_options', # capability 'nextgenthemes', # menu-slug function() { require_once plugin_dir_path( __FILE__ ) . 'html-ad-page.php'; } ); */ add_submenu_page( 'nextgenthemes', # parent_slug __( 'Licenses', ARVE_SLUG ), # Page Title __( 'Licenses', ARVE_SLUG ), # Menu Tile 'manage_options', # capability 'nextgenthemes-licenses', # menu-slug 'nextgenthemes_licenses_page' # function ); } function nextgenthemes_register_settings() { add_settings_section( 'keys', # id, __( 'Licenses', ARVE_SLUG ), # title, '__return_empty_string', # callback, 'nextgenthemes-licenses' # page ); foreach ( nextgenthemes_get_products() as $product_slug => $product ) : $option_basename = "nextgenthemes_{$product_slug}_key"; $option_keyname = $option_basename . '[key]'; add_settings_field( $option_keyname, # id, $product['name'], # title, 'nextgenthemes_key_callback', # callback, 'nextgenthemes-licenses', # page, 'keys', # section array( # args 'product' => $product, 'label_for' => $option_keyname, 'option_basename' => $option_basename, 'attr' => array( 'type' => 'text', 'id' => $option_keyname, 'name' => $option_keyname, 'class' => 'arve-license-input', 'value' => nextgenthemes_get_defined_key( $product_slug ) ? __( 'is defined (wp-config.php?)', ARVE_SLUG ) : nextgenthemes_get_key( $product_slug, 'option_only' ), ) ) ); register_setting( 'nextgenthemes', # option_group $option_basename, # option_name 'nextgenthemes_validate_license' # validation callback ); endforeach; } function nextgenthemes_key_callback( $args ) { echo ''; printf( '', arve_attr( array( 'type' => 'hidden', 'id' => $args['option_basename'] . '[product]', 'name' => $args['option_basename'] . '[product]', 'value' => $args['product']['slug'], ) ) ); printf( '', arve_attr( $args['attr'] ), nextgenthemes_get_defined_key( $args['product']['slug'] ) ? ' disabled' : '' ); $defined_key = nextgenthemes_get_defined_key( $args['product']['slug'] ); $key = nextgenthemes_get_key( $args['product']['slug'] ); if( $defined_key || ! empty( $key ) ) { submit_button( __('Activate License', ARVE_SLUG ), 'primary', $args['option_basename'] . '[activate_key]', false ); submit_button( __('Deactivate License', ARVE_SLUG ), 'secondary', $args['option_basename'] . '[deactivate_key]', false ); submit_button( __('Check License', ARVE_SLUG ), 'secondary', $args['option_basename'] . '[check_key]', false ); } echo '
'; echo ''; echo __( 'License Status: ', ARVE_SLUG ) . nextgenthemes_get_key_status( $args['product']['slug'] ); echo '
'; if( $args['product']['installed'] && ! $args['product']['active'] ) { printf( '%s', __( 'Plugin is installed but not activated', ARVE_SLUG ) ); } elseif( ! $args['product']['active'] ) { printf( '%s', arve_attr( array( 'href' => $args['product']['url'], 'class' => 'button button-primary', ) ), __( 'Not installed, check it out', ARVE_SLUG ) ); } } function nextgenthemes_validate_license( $input ) { if( ! is_array( $input ) ) { return sanitize_text_field( $input ); } $product = $input['product']; if ( $defined_key = nextgenthemes_get_defined_key( $product ) ) { $option_key = $key = $defined_key; } else { $key = sanitize_text_field( $input['key'] ); $option_key = nextgenthemes_get_key( $product ); } if( ( $key != $option_key ) || isset( $input['activate_key'] ) ) { nextgenthemes_api_update_key_status( $product, $key, 'activate' ); } elseif ( isset( $input['deactivate_key'] ) ) { nextgenthemes_api_update_key_status( $product, $key, 'deactivate' ); } elseif ( isset( $input['check_key'] ) ) { nextgenthemes_api_update_key_status( $product, $key, 'check' ); } return $key; } function nextgenthemes_get_key( $product, $option_only = false ) { if( ! $option_only && $defined_key = nextgenthemes_get_defined_key( $product ) ) { return $defined_key; } return get_option( "nextgenthemes_{$product}_key" ); } function nextgenthemes_get_key_status( $product ) { return get_option( "nextgenthemes_{$product}_key_status" ); } function nextgenthemes_update_key_status( $product, $key ) { update_option( "nextgenthemes_{$product}_key_status", $key ); } function nextgenthemes_has_valid_key( $product ) { return ( 'valid' == nextgenthemes_get_key_status( $product ) ) ? true : false; } function nextgenthemes_api_update_key_status( $product, $key, $action ) { $products = nextgenthemes_get_products(); $key_status = nextgenthemes_api_action( $products[ $product ]['name'], $key, $action ); nextgenthemes_update_key_status( $product, $key_status ); } function nextgenthemes_get_defined_key( $slug ) { $constant_name = str_replace( '-', '_', strtoupper( $slug . '_KEY' ) ); if( defined( $constant_name ) && constant( $constant_name ) ) { return constant( $constant_name ); } else { return false; } } function nextgenthemes_licenses_page() { ?>