admin ) ) { $wpmem->load_admin(); } } /** * List the WP-Members content settings. * * @since 3.3.5 */ public function content() { $this->list_settings( array( 'content' ), array() ); } /** * List the WP-Members option settings. * * @since 3.3.5 */ public function options() { $this->list_settings( array( 'options' ), array() ); } /** * Lists WP-Members settings. * * @since 3.3.5 * * @param array $args * @param array $assoc_args */ private function list_settings( $args, $assoc_args ) { global $wpmem; if ( 'content' == $args[0] ) { $settings = $this->settings( 'content' ); } else { $settings = $this->settings( 'options' ); } if ( 'content' == $args[0] ) { // @todo Add custom post types, and look for admin where all possible post types are assembled. $post_types = array_merge( array( 'post', 'page' ), $wpmem->admin->post_types() ); foreach( $post_types as $post_type ) { foreach ( $settings as $setting => $description ) { if ( 'autoex' != $setting ) { $list[] = array( 'Setting' => $setting . ' ' . $post_type, 'Description' => $description . ' ' . $post_type, 'Value' => $wpmem->{$setting}[ $post_type ], 'Option' => ( 0 == $wpmem->{$setting}[ $post_type ] ) ? 'Disabled' : 'Enabled', ); } else { $list[] = array( 'Setting' => $setting . ' ' . $post_type, 'Description' => $description . ' ' . $post_type, 'Value' => $wpmem->{$setting}[ $post_type ]['enabled'], 'Option' => ( 0 == $wpmem->{$setting}[ $post_type ]['enabled'] ) ? 'Disabled' : 'Enabled', ); $list[] = array( 'Setting' => '', 'Description' => $post_type . ' excerpt word length:', 'Value' => $wpmem->{$setting}[ $post_type ]['length'], 'Option' => '', ); } } $list[] = array( 'Setting' => '', 'Description' => '', 'Value' => '', 'Option' => '' ); } } else { foreach ( $settings as $setting => $description ) { if ( 'captcha' == $setting ) { $option = WP_Members_Captcha::type( $wpmem->{$setting} ); } else { $option = ( 0 == $wpmem->{$setting} ) ? 'Disabled' : 'Enabled'; } $list[] = array( 'Setting' => $setting, 'Description' => $description, 'Value' => $wpmem->{$setting}, 'Option' => $option, ); } } $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'Description', 'Setting', 'Value', 'Option' ) ); $formatter->display_items( $list ); } /** * List custom post types for WP-Members management. * * @since 3.3.5 * * @subcommand post-types */ public function post_types() { global $wpmem; $post_types = $wpmem->admin->post_types(); if ( empty( $post_types ) ) { WP_CLI::line( 'No custom post types are available for WP-Members settings' ); } else { foreach ( $post_types as $post_type ) { $enabled = ( array_key_exists( $post_type, $wpmem->post_types ) ) ? "Enabled" : "Disabled"; $list[] = array( 'Post Type' => $post_type, 'Value' => $enabled, ); } WP_CLI::line( 'Custom post type settings for WP-Members:' ); $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'Post Type', 'Value' ) ); $formatter->display_items( $list ); } } /** * Manage post type. * * ## OPTIONS * * [--enable=] * : enable the specified post type. * * [--disable=] * : disable the specified post type. * * @since 3.3.5 * * @subcommand post-type */ public function post_type( $args, $assoc_args ) { global $wpmem; if ( isset( $assoc_args['enable'] ) || isset( $assoc_args['disable'] ) ) { $post_types = $wpmem->admin->post_types(); if ( ( isset( $assoc_args['enable'] ) && ! array_key_exists( $assoc_args['enable'], $post_types ) ) || ( isset( $assoc_args['disable'] ) && ! array_key_exists( $assoc_args['disable'], $post_types ) ) ) { WP_CLI::error( 'Not an available post type. Try [wp mem settings post_types]' ); } // Handle disable. if ( isset( $assoc_args['disable'] ) ) { unset( $wpmem->post_types[ $assoc_args['disable'] ] ); wpmem_update_option( 'wpmembers_settings', 'post_types', $wpmem->post_types, true ); WP_CLI::success( sprintf( 'Disabled %s post type.', $assoc_args['disable'] ) ); } if ( isset( $assoc_args['enable'] ) ) { $cpt_obj = get_post_type_object( $assoc_args['enable'] ); $new_post_types = array_merge($wpmem->post_types, array( $cpt_obj->name => $cpt_obj->labels->name ) ); wpmem_update_option( 'wpmembers_settings', 'post_types', $new_post_types, true ); WP_CLI::success( sprintf( 'Enabled %s post type.', $assoc_args['enable'] ) ); } } else { WP_CLI::error( 'Must specify an option: --enable= or --disable=' ); } } /** * Enable a WP-Members setting. * * ## OPTIONS * *