$val ) { // Check against default strings. Only save if different. if ( html_entity_decode( wpmem_gettext( $key ) ) != html_entity_decode( $val ) ) { $settings['text'][ $key ] = $val; } else { if ( ! empty( $old_settings['text'] ) && array_key_exists( $key, $old_settings['text'] ) ) { $settings['text'][ $key ] = $val; } } } // Double check settings for defaults. foreach ( $settings['text'] as $k => $v ) { if ( wpmem_gettext( $k ) == $v ) { unset( $settings['text'][ $k ] ); } } } // If there are any changes, update settings. if ( ! empty( $settings ) ) { update_option( 'wpmembers_dropins', $settings ); } else { // Delete if empty. delete_option( 'wpmembers_dropins' ); } $wpmem_dropins_saved = true; } if ( $wpmem_dropins_saved ) { ?>

'Dropins' ), array_slice( $tabs, 1 ) ); } /** * Builds the Dropins tab in the admin. * * @since 3.1.9 * * @param string $tab The WP-Members admin panel tab being displayed. */ function wpmem_render_dropins_tab( $tab ) { if ( $tab == 'dropins' ) { wpmem_a_render_dropins_table(); } return; } /** * Check dropins directory. * * @since 3.1.9 * * @return boolean */ function wpmem_dropins_check_dir() { /** This filter is documented in inc/class-wp-members.php */ $folder = apply_filters( 'wpmem_dropin_folder', WPMEM_DROPIN_DIR ); $check = false; if ( file_exists( $folder ) ) { $file = $folder . '.htaccess'; if ( ! file_exists ( $file ) ) { $check = wpmem_dropins_create_htaccess( $file ); } else { $handle = fopen( $file, "r" ); if ( $handle ) { // Read file line-by-line while ( ( $buffer = fgets( $handle ) ) !== false ) { if ( strpos( $buffer, "Options -Indexes" ) !== false ) $check = true; break; } } fclose( $handle ); $check = ( false === $check ) ? wpmem_dropins_create_htaccess( $file ) : $check; } } return $check; } /** * Creates .htaccess in dropins directory if none exists. * * @since 3.1.9 * * @param string * @return boolean */ function wpmem_dropins_create_htaccess( $file ) { $handle = fopen( $file, "w" ); fwrite( $handle, "Options -Indexes" ); fclose( $handle ); return ( $handle ) ? true : false; } /** * Function to display the table of fields in the field manager tab. * * @since 3.1.9 * * @global object $wpmem */ function wpmem_a_render_dropins_table() { global $wpmem; // Get the dropin folder. /** This filter is documented in inc/class-wp-members.php */ $folder = apply_filters( 'wpmem_dropin_folder', WPMEM_DROPIN_DIR ); // Set file headers for dropins. $headers = array( 'Dropin Name' => 'Dropin Name', 'Dropin Description' => 'Dropin Description', 'Version' => 'Version', ); // Array container for dropin file info. $field_items = array(); // Parse dropins. foreach ( glob( $folder . '*.php' ) as $filename ) { $file_data = get_file_data( $filename, $headers ); $filename = explode( '/', $filename ); $filename = end( $filename ); if ( ! empty( $file_data['Dropin Name'] ) ) { $field_items[] = array( 'dropin_name' => $file_data['Dropin Name'], 'dropin_file' => $filename, 'dropin_version' => $file_data['Version'], 'dropin_description' => $file_data['Dropin Description'], ); } } // Set up table. $table = new WP_Members_Dropins_Table(); $heading = __( 'Manage Dropins', 'wp-members' ); $loc_info = __( 'Current dropin folder: ', 'wp-members' ); $loc_desc = __( 'You can change location of the dropin folder using the wpmem_dropin_folder filter.', 'wp-members' ); echo '
'; printf( '

%s

', $heading ); printf( '

%s

', $loc_info ); printf( '

%s

', $loc_desc ); printf( '
', wpmem_admin_form_post_url() ); $table->items = $field_items; $table->prepare_items(); $table->display(); echo '
'; echo '
'; } /** * Extends the WP_List_Table to create a table of dropin files. * * @since 3.1.9 */ class WP_Members_Dropins_Table extends WP_List_Table { /** * Constructor. * * @since 3.1.9 */ function __construct(){ global $status, $page; //Set parent defaults parent::__construct( array( 'singular' => 'dropin', 'plural' => 'dropins', 'ajax' => false, ) ); $this->dropins = get_option( 'wpmembers_dropins', array() ); //print_r( $this->dropins ); } /** * Checkbox at start of row. * * @since 3.1.9 * * @param $item * @return string The checkbox. */ function column_cb( $item ) { global $wpmem; $checked = checked( true, in_array( $item['dropin_file'], $wpmem->dropins_enabled ), false ); //return sprintf( '', $item['dropin_file'], __( 'delete', 'wp-members' ) ); return sprintf( '', $this->_args['singular'], $item['dropin_file'], $checked ); } /** * Returns table columns. * * @since 3.1.9 * * @return array */ function get_columns() { return array( 'cb' => '', 'dropin_name' => __( 'Name', 'wp-members' ), 'dropin_file' => __( 'File', 'wp-members' ), 'dropin_version' => __( 'Version', 'wp-members' ), 'dropin_description' => __( 'Description', 'wp-members' ), ); } /** * Set up table columns. * * @since 3.1.9 */ function prepare_items() { $columns = $this->get_columns(); $hidden = array(); $sortable = array(); $this->_column_headers = array( $columns, $hidden, $sortable ); $this->process_bulk_action(); } /** * Iterates through the columns * * @since 3.1.9 * * @param array $item * @param string $column_name * @return string $item[ $column_name ] */ function column_default( $item, $column_name ) { switch( $column_name ) { default: return $item[ $column_name ]; } } /** * Sets actions in the bulk menu. * * @since 3.1.9 * * @return array $actions */ function get_bulk_actions() { $actions = array( //'delete' => __( 'Delete Selected', 'wp-members' ), 'save' => __( 'Save Settings', 'wp-members' ), ); return $actions; } /** * Handles "delete" column - checkbox * * @since 3.1.9 * * @param array $item * @return string */ function column_delete( $item ) { } /** * Sets rows so that they have field IDs in the id. * * @since 3.1.9 * * @global wpmem * @param array $columns */ function single_row( $columns ) { echo ''; echo $this->single_row_columns( $columns ); echo "\n"; } public function process_bulk_action() { global $wpmem; //nonce validations,etc $dir_chk = wpmem_dropins_check_dir(); //echo ( $dir_chk ) ? '.htaccess OK!' : 'NO .htaccess!!!'; $action = $this->current_action(); switch ( $action ) { case 'delete': // Do whatever you want //wp_safe_redirect( esc_url( add_query_arg() ) ); break; case 'save': $settings = array(); //echo "SAVING SETTINGS";print_r( $_REQUEST['dropin'] ); if ( wpmem_get( 'dropin' ) ) { foreach( wpmem_get( 'dropin' ) as $dropin ) { $settings[] = $dropin; } update_option( 'wpmembers_dropins', $settings, true ); } else { delete_option( 'wpmembers_dropins' ); } $wpmem->dropins_enabled = $settings; echo '

' . __( 'WP-Members Dropin settings were updated', 'wp-members' ) . '

'; break; default: // do nothing or something else return; break; } return; } } // End of file.