└── re-skinning.content.splitter.php
/re-skinning.content.splitter.php:
--------------------------------------------------------------------------------
1 | post_types = apply_filters( 'autopaging_post_types', get_option( $this->option_name_post_types, $this->post_types_default ) );
36 | $this->num_pages = absint( apply_filters( 'autopaging_num_pages_default', get_option( $this->option_name_num_pages, $this->num_pages_default ) ) );
37 | if ( 0 == $this->num_pages )
38 | $this->num_pages = $this->num_pages_default;
39 | $this->num_words = absint( apply_filters( 'autopaging_num_words_default', get_option( $this->option_name_num_words, $this->num_words_default ) ) );
40 | if ( 0 == $this->num_words )
41 | $this->num_words = $this->num_words_default;
42 | }
43 | public function uninstall() {
44 | delete_option( 'autopaging_post_types' );
45 | delete_option( 'autopaging_paging_type' );
46 | delete_option( 'autopaging_num_pages' );
47 | delete_option( 'autopaging_num_words' );
48 | }
49 | public function filter_plugin_action_links( $actions, $file ) {
50 | if ( false !== strpos( $file, basename( __FILE__ ) ) )
51 | $actions[ 'settings' ] = 'Settings';
52 |
53 | return $actions;
54 | }
55 | public function action_admin_init() {
56 | register_setting( 'reading', $this->option_name_post_types, array( $this, 'sanitize_supported_post_types' ) );
57 | register_setting( 'reading', $this->option_name_paging_type, array( $this, 'sanitize_paging_type' ) );
58 | register_setting( 'reading', $this->option_name_num_pages, array( $this, 'sanitize_num_pages' ) );
59 | register_setting( 'reading', $this->option_name_num_words, array( $this, 'sanitize_num_words' ) );
60 | add_settings_section( 'autopaging', __( 'Automatically Paginate Posts', 'autopaging' ), '__return_false', 'reading' );
61 | add_settings_field( 'autopaging-post-types', __( 'Supported post types:', 'autopaging' ), array( $this, 'settings_field_post_types' ), 'reading', 'autopaging' );
62 | add_settings_field( 'autopaging-paging-type', __( 'Split post by:', 'autopaging' ), array( $this, 'settings_field_paging_type' ), 'reading', 'autopaging' );
63 | }
64 | public function settings_field_post_types() {
65 | $post_types = get_post_types( array(
66 | 'public' => true
67 | ), 'objects' );
68 | unset( $post_types[ 'attachment' ] );
69 | $current_types = get_option( $this->option_name_post_types, $this->post_types_default );
70 | foreach ( $post_types as $post_type => $atts ) :
71 | ?>
72 | />
73 | true
81 | ) );
82 | unset( $post_types[ 'attachment' ] );
83 | foreach ( $post_types_checked as $post_type ) {
84 | if ( array_key_exists( $post_type, $post_types ) )
85 | $post_types_sanitized[] = $post_type;
86 | }
87 | }
88 | return $post_types_sanitized;
89 | }
90 | public function settings_field_paging_type() {
91 | $paging_type = get_option( $this->option_name_paging_type, $this->paging_type_default );
92 | if ( ! in_array( $paging_type, $this->paging_types_allowed ) ) {
93 | $paging_type = $this->paging_type_default;
94 | }
95 | $labels = array(
96 | 'pages' => __( 'Total number of pages: ', 'autopaging' ),
97 | 'words' => __( 'Approximate words per page: ', 'autopaging' ),
98 | );
99 | foreach ( $this->paging_types_allowed as $type ) :
100 | $type_escaped = esc_attr( $type );
101 | $func = 'settings_field_num_' . $type;
102 | ?>
103 |
/>
106 | paging_types_allowed ) ? $type : $this->paging_type_default; 110 | } 111 | public function settings_field_num_pages() { 112 | $num_pages = get_option( $this->option_name_num_pages, $this->num_pages_default ); 113 | $max_pages = apply_filters( 'autopaging_max_num_pages', 10 ); 114 | ?> 115 | 120 | option_name_num_words ) ) 127 | ?> 128 | 129 | 130 | post_types as $post_type ) { 141 | add_meta_box( 'autopaging', __( 'Post Autopaging', 'autopaging' ), array( $this, 'meta_box_autopaging' ), $post_type, 'side' ); 142 | } 143 | } 144 | public function meta_box_autopaging( $post ) { 145 | ?> 146 |147 | ID, $this->meta_key_disable_autopaging, true ) ); ?> /> 148 |
149 | 150 |<!--nextpage-->' ); ?>
151 | meta_key_disable_autopaging, $this->meta_key_disable_autopaging . '_wpnonce' ); 153 | } 154 | public function action_save_post( $post_id ) { 155 | if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 156 | return; 157 | if ( isset( $_POST[ $this->meta_key_disable_autopaging . '_wpnonce' ] ) && wp_verify_nonce( $_POST[ $this->meta_key_disable_autopaging . '_wpnonce' ], $this->meta_key_disable_autopaging ) ) { 158 | $disable = isset( $_POST[ $this->meta_key_disable_autopaging ] ) ? true : false; 159 | if ( $disable ) 160 | update_post_meta( $post_id, $this->meta_key_disable_autopaging, true ); 161 | else 162 | delete_post_meta( $post_id, $this->meta_key_disable_autopaging ); 163 | } 164 | } 165 | public function filter_the_posts( $posts ) { 166 | if ( ! is_admin() ) { 167 | foreach( $posts as $the_post ) { 168 | if ( in_array( $the_post->post_type, $this->post_types ) && ! preg_match( '##i', $the_post->post_content ) && ! (bool) get_post_meta( $the_post->ID, $this->meta_key_disable_autopaging, true ) ) { 169 | $num_pages = absint( apply_filters( 'autopaging_num_pages', absint( $this->num_pages ), $the_post ) ); 170 | $num_words = absint( apply_filters( 'autopaging_num_words', absint( $this->num_words ), $the_post ) ); 171 | if ( $num_pages < 2 && empty( $num_words ) ) 172 | continue; 173 | $content = $the_post->post_content; 174 | $content = preg_replace( '#(.+?)
#i', "$1\r\n\r\n", $content ); 175 | $content = preg_replace( '#