From 4c2266bb5e5235688fdd9ec6604fb0861097642d Mon Sep 17 00:00:00 2001 From: "DESKTOP-7GJRB4Q\\mlako" Date: Thu, 21 Sep 2017 15:52:16 +0300 Subject: [PATCH 01/63] Add SM taxonomies to default search results (GitHub isssue #91) --- includes/class-sm-search.php | 85 ++++++++++++++++++++++++++++++++++++ readme.txt | 3 ++ sermons.php | 1 + 3 files changed, 89 insertions(+) create mode 100644 includes/class-sm-search.php diff --git a/includes/class-sm-search.php b/includes/class-sm-search.php new file mode 100644 index 0000000..4430c70 --- /dev/null +++ b/includes/class-sm-search.php @@ -0,0 +1,85 @@ +posts}.post_status = 'publish')"; + } + + return $where; + } + + /** + * Include taxonomies to default search + * + * @global $wpdb + * + * @param string $join + * + * @return string + */ + public function join( $join ) { + global $wpdb; + + if ( is_search() ) { + $join .= "LEFT JOIN {$wpdb->term_relationships} tr ON {$wpdb->posts}.ID = tr.object_id INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id=tr.term_taxonomy_id INNER JOIN {$wpdb->terms} t ON t.term_id = tt.term_id"; + } + + return $join; + } + + /** + * + * @global $wpdb + * + * @param int $groupby + * + * @return string + */ + public function groupby( $groupby ) { + global $wpdb; + + // we need to group on post ID + $groupby_id = "{$wpdb->posts}.ID"; + if ( ! is_search() || strpos( $groupby, $groupby_id ) !== false ) { + return $groupby; + } + // groupby was empty, use ours + if ( ! strlen( trim( $groupby ) ) ) { + return $groupby_id; + } + + // wasn't empty, append ours + return $groupby . ", " . $groupby_id; + } +} + +$search = new SM_Search; +$search->hook(); diff --git a/readme.txt b/readme.txt index 1961167..512b119 100755 --- a/readme.txt +++ b/readme.txt @@ -89,6 +89,9 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man 2. Sermon Files == Changelog == += 2.7 = +* Add SM taxonomies to default search results (GitHub isssue #91) + = 2.6.2 = * Add more `` elements for more styling options * Fix podcast feed not working diff --git a/sermons.php b/sermons.php index a9ee031..77716b2 100755 --- a/sermons.php +++ b/sermons.php @@ -84,6 +84,7 @@ private function includes() { $includes = array( '/includes/class-sm-dates.php', // Dates operations '/includes/class-sm-dates-wp.php', // Attach to WP filters + '/includes/class-sm-search.php', // Search '/includes/sm-deprecated-functions.php', // Deprecated SM functions '/includes/sm-core-functions.php', // Deprecated SM functions '/includes/legacy-php.php', // Old PHP compatibility fixes From ffc89a5685c36255d47d998571b58f093a7fba5b Mon Sep 17 00:00:00 2001 From: Nikola Date: Thu, 21 Sep 2017 15:02:04 +0200 Subject: [PATCH 02/63] Ignore .idea files It's annoying to tell PhpStorm each time to ignore them --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file From ee253a888fdc795f0fd11415b7693e0ee8a5d3a2 Mon Sep 17 00:00:00 2001 From: "DESKTOP-7GJRB4Q\\mlako" Date: Thu, 21 Sep 2017 16:08:15 +0300 Subject: [PATCH 03/63] Add SM taxonomies to default wp search results This closes #91 --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index 512b119..7073038 100755 --- a/readme.txt +++ b/readme.txt @@ -89,6 +89,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man 2. Sermon Files == Changelog == + = 2.7 = * Add SM taxonomies to default search results (GitHub isssue #91) From 29fb015c563a240b4680d7fa91c3827d378a5118 Mon Sep 17 00:00:00 2001 From: Nikola Date: Thu, 21 Sep 2017 15:13:32 +0200 Subject: [PATCH 04/63] Rewrite changelog message --- readme.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/readme.txt b/readme.txt index 7073038..763ad4a 100755 --- a/readme.txt +++ b/readme.txt @@ -89,9 +89,8 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man 2. Sermon Files == Changelog == - = 2.7 = -* Add SM taxonomies to default search results (GitHub isssue #91) +* Add WordPress search support to sermons = 2.6.2 = * Add more `` elements for more styling options From 6ca6b5f8fa7412c224ce59a1bcc1cc7a1cd08bb0 Mon Sep 17 00:00:00 2001 From: Nikola Date: Thu, 21 Sep 2017 15:43:16 +0200 Subject: [PATCH 05/63] API: Add initial files Related to #49 --- .../api/class-sm-rest-sermons-controller.php | 36 ++ includes/class-sm-api.php | 129 +++++ includes/sm-core-functions.php | 17 + .../vendor/abstract-wp-rest-controller.php | 492 ++++++++++++++++++ sermons.php | 1 + 5 files changed, 675 insertions(+) create mode 100644 includes/api/class-sm-rest-sermons-controller.php create mode 100644 includes/class-sm-api.php create mode 100644 includes/vendor/abstract-wp-rest-controller.php diff --git a/includes/api/class-sm-rest-sermons-controller.php b/includes/api/class-sm-rest-sermons-controller.php new file mode 100644 index 0000000..7190c5f --- /dev/null +++ b/includes/api/class-sm-rest-sermons-controller.php @@ -0,0 +1,36 @@ +namespace, '/' . $this->rest_base, array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_items' ), + ), + 'schema' => array( $this, 'get_public_item_schema' ), + ) ); + } +} \ No newline at end of file diff --git a/includes/class-sm-api.php b/includes/class-sm-api.php new file mode 100644 index 0000000..6891d89 --- /dev/null +++ b/includes/class-sm-api.php @@ -0,0 +1,129 @@ +rest_api_init(); + } + + /** + * Init WP REST API + */ + private function rest_api_init() { + // REST API was included starting WordPress 4.4 + if ( ! class_exists( 'WP_REST_Server' ) ) { + return; + } + + $this->rest_api_includes(); + + // Init REST API routes + add_action( 'rest_api_init', array( $this, 'register_rest_routes' ), 10 ); + } + + /** + * Include REST API classes. + * + * @since 3.0.0 + */ + private function rest_api_includes() { + include_once 'api/class-sm-rest-sermons-controller.php'; + + if ( ! class_exists( 'WP_REST_Controller' ) ) { + include_once ABSPATH . 'wp-includes/rest-api/endpoints/class-wp-rest-controller.php'; + } + } + + /** + * Sermon Manager API + */ + public static function add_endpoint() { + add_rewrite_endpoint( 'sm-api', EP_ALL ); + } + + /** + * Add new query vars + * + * @param array $vars + * + * @return string[] + */ + public function add_query_vars( $vars ) { + $vars[] = 'sm-api'; + + return $vars; + } + + /** + * API request - Trigger any API requests + */ + public function handle_api_requests() { + global $wp; + + if ( ! empty( $_GET['sm-api'] ) ) { + $wp->query_vars['sm-api'] = $_GET['sm-api']; + } + + // sm-api endpoint requests. + if ( ! empty( $wp->query_vars['sm-api'] ) ) { + + // Buffer, we won't want any output here. + ob_start(); + + // No cache headers. + nocache_headers(); + + // Clean the API request. + $api_request = strtolower( sm_clean( $wp->query_vars['sm-api'] ) ); + + // Trigger generic action before request hook. + do_action( 'sm_api_request', $api_request ); + + // Is there actually something hooked into this API request? If not trigger 400 - Bad request. + status_header( has_action( 'sm_api_' . $api_request ) ? 200 : 400 ); + + // Trigger an action which plugins can hook into to fulfill the request. + do_action( 'sm_api_' . $api_request ); + + // Done, clear buffer and exit. + ob_end_clean(); + die( '-1' ); + } + } + + /** + * Register REST API routes + */ + public function register_rest_routes() { + $controllers = array( + 'SM_REST_Sermons_Controller', + ); + + foreach ( $controllers as $controller ) { + $this->$controller = new $controller(); + $this->$controller->register_routes(); + } + } +} + +new SM_API(); \ No newline at end of file diff --git a/includes/sm-core-functions.php b/includes/sm-core-functions.php index e75d2e3..b233e31 100644 --- a/includes/sm-core-functions.php +++ b/includes/sm-core-functions.php @@ -76,4 +76,21 @@ function sm_the_date( $d = '', $before = '', $after = '' ) { * @param string $after HTML output after the date. */ echo apply_filters( 'the_date', $the_date, $d, $before, $after ); +} + +/** + * Clean variables using sanitize_text_field. Arrays are cleaned recursively. + * Non-scalar values are ignored. + * + * @param string|array $var + * + * @return string|array + * @since 2.7 + */ +function sm_clean( $var ) { + if ( is_array( $var ) ) { + return array_map( 'sm_clean', $var ); + } else { + return is_scalar( $var ) ? sanitize_text_field( $var ) : $var; + } } \ No newline at end of file diff --git a/includes/vendor/abstract-wp-rest-controller.php b/includes/vendor/abstract-wp-rest-controller.php new file mode 100644 index 0000000..072ba19 --- /dev/null +++ b/includes/vendor/abstract-wp-rest-controller.php @@ -0,0 +1,492 @@ + 405 ) ); + } + + /** + * Get a collection of items. + * + * @param WP_REST_Request $request Full data about the request. + * @return WP_Error|WP_REST_Response + */ + public function get_items( $request ) { + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + } + + /** + * Check if a given request has access to get a specific item. + * + * @param WP_REST_Request $request Full data about the request. + * @return WP_Error|boolean + */ + public function get_item_permissions_check( $request ) { + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + } + + /** + * Get one item from the collection. + * + * @param WP_REST_Request $request Full data about the request. + * @return WP_Error|WP_REST_Response + */ + public function get_item( $request ) { + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + } + + /** + * Check if a given request has access to create items. + * + * @param WP_REST_Request $request Full data about the request. + * @return WP_Error|boolean + */ + public function create_item_permissions_check( $request ) { + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + } + + /** + * Create one item from the collection. + * + * @param WP_REST_Request $request Full data about the request. + * @return WP_Error|WP_REST_Response + */ + public function create_item( $request ) { + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + } + + /** + * Check if a given request has access to update a specific item. + * + * @param WP_REST_Request $request Full data about the request. + * @return WP_Error|boolean + */ + public function update_item_permissions_check( $request ) { + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + } + + /** + * Update one item from the collection. + * + * @param WP_REST_Request $request Full data about the request. + * @return WP_Error|WP_REST_Response + */ + public function update_item( $request ) { + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + } + + /** + * Check if a given request has access to delete a specific item. + * + * @param WP_REST_Request $request Full data about the request. + * @return WP_Error|boolean + */ + public function delete_item_permissions_check( $request ) { + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + } + + /** + * Delete one item from the collection. + * + * @param WP_REST_Request $request Full data about the request. + * @return WP_Error|WP_REST_Response + */ + public function delete_item( $request ) { + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + } + + /** + * Prepare the item for create or update operation. + * + * @param WP_REST_Request $request Request object. + * @return WP_Error|object $prepared_item + */ + protected function prepare_item_for_database( $request ) { + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + } + + /** + * Prepare the item for the REST response. + * + * @param mixed $item WordPress representation of the item. + * @param WP_REST_Request $request Request object. + * + * @return WP_Error|WP_REST_Response + */ + public function prepare_item_for_response( $item, $request ) { + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + } + + /** + * Prepare a response for inserting into a collection. + * + * @param WP_REST_Response $response Response object. + * + * @return array|WP_REST_Response + */ + public function prepare_response_for_collection( $response ) { + if ( ! ( $response instanceof WP_REST_Response ) ) { + return $response; + } + + $data = (array) $response->get_data(); + $server = rest_get_server(); + + if ( method_exists( $server, 'get_compact_response_links' ) ) { + $links = call_user_func( array( $server, 'get_compact_response_links' ), $response ); + } else { + $links = call_user_func( array( $server, 'get_response_links' ), $response ); + } + + if ( ! empty( $links ) ) { + $data['_links'] = $links; + } + + return $data; + } + + /** + * Filter a response based on the context defined in the schema. + * + * @param array $data + * @param string $context + * @return array + */ + public function filter_response_by_context( $data, $context ) { + + $schema = $this->get_item_schema(); + foreach ( $data as $key => $value ) { + if ( empty( $schema['properties'][ $key ] ) || empty( $schema['properties'][ $key ]['context'] ) ) { + continue; + } + + if ( ! in_array( $context, $schema['properties'][ $key ]['context'] ) ) { + unset( $data[ $key ] ); + } + + if ( 'object' === $schema['properties'][ $key ]['type'] && ! empty( $schema['properties'][ $key ]['properties'] ) ) { + foreach ( $schema['properties'][ $key ]['properties'] as $attribute => $details ) { + if ( empty( $details['context'] ) ) { + continue; + } + if ( ! in_array( $context, $details['context'] ) ) { + if ( isset( $data[ $key ][ $attribute ] ) ) { + unset( $data[ $key ][ $attribute ] ); + } + } + } + } + } + + return $data; + } + + /** + * Get the item's schema, conforming to JSON Schema. + * + * @return array + */ + public function get_item_schema() { + return $this->add_additional_fields_schema( array() ); + } + + /** + * Get the item's schema for display / public consumption purposes. + * + * @return array + */ + public function get_public_item_schema() { + + $schema = $this->get_item_schema(); + + foreach ( $schema['properties'] as &$property ) { + if ( isset( $property['arg_options'] ) ) { + unset( $property['arg_options'] ); + } + } + + return $schema; + } + + /** + * Get the query params for collections. + * + * @return array + */ + public function get_collection_params() { + return array( + 'context' => $this->get_context_param(), + 'page' => array( + 'description' => __( 'Current page of the collection.', 'woocommerce' ), + 'type' => 'integer', + 'default' => 1, + 'sanitize_callback' => 'absint', + 'validate_callback' => 'rest_validate_request_arg', + 'minimum' => 1, + ), + 'per_page' => array( + 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), + 'type' => 'integer', + 'default' => 10, + 'minimum' => 1, + 'maximum' => 100, + 'sanitize_callback' => 'absint', + 'validate_callback' => 'rest_validate_request_arg', + ), + 'search' => array( + 'description' => __( 'Limit results to those matching a string.', 'woocommerce' ), + 'type' => 'string', + 'sanitize_callback' => 'sanitize_text_field', + 'validate_callback' => 'rest_validate_request_arg', + ), + ); + } + + /** + * Get the magical context param. + * + * Ensures consistent description between endpoints, and populates enum from schema. + * + * @param array $args + * @return array + */ + public function get_context_param( $args = array() ) { + $param_details = array( + 'description' => __( 'Scope under which the request is made; determines fields present in response.', 'woocommerce' ), + 'type' => 'string', + 'sanitize_callback' => 'sanitize_key', + 'validate_callback' => 'rest_validate_request_arg', + ); + $schema = $this->get_item_schema(); + if ( empty( $schema['properties'] ) ) { + return array_merge( $param_details, $args ); + } + $contexts = array(); + foreach ( $schema['properties'] as $key => $attributes ) { + if ( ! empty( $attributes['context'] ) ) { + $contexts = array_merge( $contexts, $attributes['context'] ); + } + } + if ( ! empty( $contexts ) ) { + $param_details['enum'] = array_unique( $contexts ); + rsort( $param_details['enum'] ); + } + return array_merge( $param_details, $args ); + } + + /** + * Add the values from additional fields to a data object. + * + * @param array $object + * @param WP_REST_Request $request + * @return array modified object with additional fields. + */ + protected function add_additional_fields_to_object( $object, $request ) { + + $additional_fields = $this->get_additional_fields(); + + foreach ( $additional_fields as $field_name => $field_options ) { + + if ( ! $field_options['get_callback'] ) { + continue; + } + + $object[ $field_name ] = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type() ); + } + + return $object; + } + + /** + * Update the values of additional fields added to a data object. + * + * @param array $object + * @param WP_REST_Request $request + */ + protected function update_additional_fields_for_object( $object, $request ) { + + $additional_fields = $this->get_additional_fields(); + + foreach ( $additional_fields as $field_name => $field_options ) { + + if ( ! $field_options['update_callback'] ) { + continue; + } + + // Don't run the update callbacks if the data wasn't passed in the request. + if ( ! isset( $request[ $field_name ] ) ) { + continue; + } + + call_user_func( $field_options['update_callback'], $request[ $field_name ], $object, $field_name, $request, $this->get_object_type() ); + } + } + + /** + * Add the schema from additional fields to an schema array. + * + * The type of object is inferred from the passed schema. + * + * @param array $schema Schema array. + * + * @return array $schema Schema array. + */ + protected function add_additional_fields_schema( $schema ) { + if ( empty( $schema['title'] ) ) { + return $schema; + } + + /** + * Can't use $this->get_object_type otherwise we cause an inf loop. + */ + $object_type = $schema['title']; + + $additional_fields = $this->get_additional_fields( $object_type ); + + foreach ( $additional_fields as $field_name => $field_options ) { + if ( ! $field_options['schema'] ) { + continue; + } + + $schema['properties'][ $field_name ] = $field_options['schema']; + } + + return $schema; + } + + /** + * Get all the registered additional fields for a given object-type. + * + * @param string $object_type + * @return array + */ + protected function get_additional_fields( $object_type = null ) { + + if ( ! $object_type ) { + $object_type = $this->get_object_type(); + } + + if ( ! $object_type ) { + return array(); + } + + global $wp_rest_additional_fields; + + if ( ! $wp_rest_additional_fields || ! isset( $wp_rest_additional_fields[ $object_type ] ) ) { + return array(); + } + + return $wp_rest_additional_fields[ $object_type ]; + } + + /** + * Get the object type this controller is responsible for managing. + * + * @return string + */ + protected function get_object_type() { + $schema = $this->get_item_schema(); + + if ( ! $schema || ! isset( $schema['title'] ) ) { + return null; + } + + return $schema['title']; + } + + /** + * Get an array of endpoint arguments from the item schema for the controller. + * + * @param string $method HTTP method of the request. The arguments + * for `CREATABLE` requests are checked for required + * values and may fall-back to a given default, this + * is not done on `EDITABLE` requests. Default is + * WP_REST_Server::CREATABLE. + * @return array $endpoint_args + */ + public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) { + + $schema = $this->get_item_schema(); + $schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array(); + $endpoint_args = array(); + + foreach ( $schema_properties as $field_id => $params ) { + + // Arguments specified as `readonly` are not allowed to be set. + if ( ! empty( $params['readonly'] ) ) { + continue; + } + + $endpoint_args[ $field_id ] = array( + 'validate_callback' => 'rest_validate_request_arg', + 'sanitize_callback' => 'rest_sanitize_request_arg', + ); + + if ( isset( $params['description'] ) ) { + $endpoint_args[ $field_id ]['description'] = $params['description']; + } + + if ( WP_REST_Server::CREATABLE === $method && isset( $params['default'] ) ) { + $endpoint_args[ $field_id ]['default'] = $params['default']; + } + + if ( WP_REST_Server::CREATABLE === $method && ! empty( $params['required'] ) ) { + $endpoint_args[ $field_id ]['required'] = true; + } + + foreach ( array( 'type', 'format', 'enum' ) as $schema_prop ) { + if ( isset( $params[ $schema_prop ] ) ) { + $endpoint_args[ $field_id ][ $schema_prop ] = $params[ $schema_prop ]; + } + } + + // Merge in any options provided by the schema property. + if ( isset( $params['arg_options'] ) ) { + + // Only use required / default from arg_options on CREATABLE endpoints. + if ( WP_REST_Server::CREATABLE !== $method ) { + $params['arg_options'] = array_diff_key( $params['arg_options'], array( 'required' => '', 'default' => '' ) ); + } + + $endpoint_args[ $field_id ] = array_merge( $endpoint_args[ $field_id ], $params['arg_options'] ); + } + } + + return $endpoint_args; + } +} diff --git a/sermons.php b/sermons.php index 77716b2..41752fe 100755 --- a/sermons.php +++ b/sermons.php @@ -85,6 +85,7 @@ private function includes() { '/includes/class-sm-dates.php', // Dates operations '/includes/class-sm-dates-wp.php', // Attach to WP filters '/includes/class-sm-search.php', // Search + '/includes/class-sm-api.php', // API '/includes/sm-deprecated-functions.php', // Deprecated SM functions '/includes/sm-core-functions.php', // Deprecated SM functions '/includes/legacy-php.php', // Old PHP compatibility fixes From 1db42bbe5f3775e96aeb1ca6cafde6866c9839c1 Mon Sep 17 00:00:00 2001 From: Nikola Date: Thu, 21 Sep 2017 15:51:34 +0200 Subject: [PATCH 06/63] API: Update WP_REST_Controller to latest and modify include path --- includes/class-sm-api.php | 2 +- .../vendor/abstract-wp-rest-controller.php | 289 +++++++++++------- 2 files changed, 182 insertions(+), 109 deletions(-) diff --git a/includes/class-sm-api.php b/includes/class-sm-api.php index 6891d89..87c49ce 100644 --- a/includes/class-sm-api.php +++ b/includes/class-sm-api.php @@ -50,7 +50,7 @@ private function rest_api_includes() { include_once 'api/class-sm-rest-sermons-controller.php'; if ( ! class_exists( 'WP_REST_Controller' ) ) { - include_once ABSPATH . 'wp-includes/rest-api/endpoints/class-wp-rest-controller.php'; + include_once 'vendor/abstract-wp-rest-controller.php'; } } diff --git a/includes/vendor/abstract-wp-rest-controller.php b/includes/vendor/abstract-wp-rest-controller.php index 072ba19..bd0ae47 100644 --- a/includes/vendor/abstract-wp-rest-controller.php +++ b/includes/vendor/abstract-wp-rest-controller.php @@ -1,17 +1,13 @@ 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** - * Get a collection of items. + * Retrieves a collection of items. + * + * @access public * * @param WP_REST_Request $request Full data about the request. - * @return WP_Error|WP_REST_Response + * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. */ public function get_items( $request ) { - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** - * Check if a given request has access to get a specific item. + * Checks if a given request has access to get a specific item. + * + * @access public * * @param WP_REST_Request $request Full data about the request. - * @return WP_Error|boolean + * @return WP_Error|bool True if the request has read access for the item, WP_Error object otherwise. */ public function get_item_permissions_check( $request ) { - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** - * Get one item from the collection. + * Retrieves one item from the collection. + * + * @access public * * @param WP_REST_Request $request Full data about the request. - * @return WP_Error|WP_REST_Response + * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. */ public function get_item( $request ) { - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** - * Check if a given request has access to create items. + * Checks if a given request has access to create items. + * + * @access public * * @param WP_REST_Request $request Full data about the request. - * @return WP_Error|boolean + * @return WP_Error|bool True if the request has access to create items, WP_Error object otherwise. */ public function create_item_permissions_check( $request ) { - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** - * Create one item from the collection. + * Creates one item from the collection. + * + * @access public * * @param WP_REST_Request $request Full data about the request. - * @return WP_Error|WP_REST_Response + * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. */ public function create_item( $request ) { - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** - * Check if a given request has access to update a specific item. + * Checks if a given request has access to update a specific item. + * + * @access public * * @param WP_REST_Request $request Full data about the request. - * @return WP_Error|boolean + * @return WP_Error|bool True if the request has access to update the item, WP_Error object otherwise. */ public function update_item_permissions_check( $request ) { - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** - * Update one item from the collection. + * Updates one item from the collection. + * + * @access public * * @param WP_REST_Request $request Full data about the request. - * @return WP_Error|WP_REST_Response + * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. */ public function update_item( $request ) { - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** - * Check if a given request has access to delete a specific item. + * Checks if a given request has access to delete a specific item. + * + * @access public * * @param WP_REST_Request $request Full data about the request. - * @return WP_Error|boolean + * @return WP_Error|bool True if the request has access to delete the item, WP_Error object otherwise. */ public function delete_item_permissions_check( $request ) { - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** - * Delete one item from the collection. + * Deletes one item from the collection. + * + * @access public * * @param WP_REST_Request $request Full data about the request. - * @return WP_Error|WP_REST_Response + * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. */ public function delete_item( $request ) { - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** - * Prepare the item for create or update operation. + * Prepares one item for create or update operation. + * + * @access public * * @param WP_REST_Request $request Request object. - * @return WP_Error|object $prepared_item + * @return WP_Error|object The prepared item, or WP_Error object on failure. */ protected function prepare_item_for_database( $request ) { - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** - * Prepare the item for the REST response. + * Prepares the item for the REST response. * - * @param mixed $item WordPress representation of the item. - * @param WP_REST_Request $request Request object. + * @access public * - * @return WP_Error|WP_REST_Response + * @param mixed $item WordPress representation of the item. + * @param WP_REST_Request $request Request object. + * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. */ public function prepare_item_for_response( $item, $request ) { - return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be over-ridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) ); + return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } /** - * Prepare a response for inserting into a collection. + * Prepares a response for insertion into a collection. * - * @param WP_REST_Response $response Response object. + * @access public * - * @return array|WP_REST_Response + * @param WP_REST_Response $response Response object. + * @return array|mixed Response data, ready for insertion into collection data. */ public function prepare_response_for_collection( $response ) { if ( ! ( $response instanceof WP_REST_Response ) ) { return $response; } - $data = (array) $response->get_data(); + $data = (array) $response->get_data(); $server = rest_get_server(); if ( method_exists( $server, 'get_compact_response_links' ) ) { @@ -181,22 +204,26 @@ public function prepare_response_for_collection( $response ) { } /** - * Filter a response based on the context defined in the schema. + * Filters a response based on the context defined in the schema. * - * @param array $data - * @param string $context - * @return array + * @access public + * + * @param array $data Response data to fiter. + * @param string $context Context defined in the schema. + * @return array Filtered response. */ public function filter_response_by_context( $data, $context ) { $schema = $this->get_item_schema(); + foreach ( $data as $key => $value ) { if ( empty( $schema['properties'][ $key ] ) || empty( $schema['properties'][ $key ]['context'] ) ) { continue; } - if ( ! in_array( $context, $schema['properties'][ $key ]['context'] ) ) { + if ( ! in_array( $context, $schema['properties'][ $key ]['context'], true ) ) { unset( $data[ $key ] ); + continue; } if ( 'object' === $schema['properties'][ $key ]['type'] && ! empty( $schema['properties'][ $key ]['properties'] ) ) { @@ -204,7 +231,8 @@ public function filter_response_by_context( $data, $context ) { if ( empty( $details['context'] ) ) { continue; } - if ( ! in_array( $context, $details['context'] ) ) { + + if ( ! in_array( $context, $details['context'], true ) ) { if ( isset( $data[ $key ][ $attribute ] ) ) { unset( $data[ $key ][ $attribute ] ); } @@ -217,42 +245,46 @@ public function filter_response_by_context( $data, $context ) { } /** - * Get the item's schema, conforming to JSON Schema. + * Retrieves the item's schema, conforming to JSON Schema. + * + * @access public * - * @return array + * @return array Item schema data. */ public function get_item_schema() { return $this->add_additional_fields_schema( array() ); } /** - * Get the item's schema for display / public consumption purposes. + * Retrieves the item's schema for display / public consumption purposes. * - * @return array + * @access public + * + * @return array Public item schema data. */ public function get_public_item_schema() { $schema = $this->get_item_schema(); foreach ( $schema['properties'] as &$property ) { - if ( isset( $property['arg_options'] ) ) { - unset( $property['arg_options'] ); - } + unset( $property['arg_options'] ); } return $schema; } /** - * Get the query params for collections. + * Retrieves the query params for the collections. * - * @return array + * @access public + * + * @return array Query parameters for the collection. */ public function get_collection_params() { return array( 'context' => $this->get_context_param(), 'page' => array( - 'description' => __( 'Current page of the collection.', 'woocommerce' ), + 'description' => __( 'Current page of the collection.' ), 'type' => 'integer', 'default' => 1, 'sanitize_callback' => 'absint', @@ -260,7 +292,7 @@ public function get_collection_params() { 'minimum' => 1, ), 'per_page' => array( - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), + 'description' => __( 'Maximum number of items to be returned in result set.' ), 'type' => 'integer', 'default' => 10, 'minimum' => 1, @@ -269,7 +301,7 @@ public function get_collection_params() { 'validate_callback' => 'rest_validate_request_arg', ), 'search' => array( - 'description' => __( 'Limit results to those matching a string.', 'woocommerce' ), + 'description' => __( 'Limit results to those matching a string.' ), 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'validate_callback' => 'rest_validate_request_arg', @@ -278,43 +310,53 @@ public function get_collection_params() { } /** - * Get the magical context param. + * Retrieves the magical context param. + * + * Ensures consistent descriptions between endpoints, and populates enum from schema. * - * Ensures consistent description between endpoints, and populates enum from schema. + * @access public * - * @param array $args - * @return array + * @param array $args Optional. Additional arguments for context parameter. Default empty array. + * @return array Context parameter details. */ public function get_context_param( $args = array() ) { $param_details = array( - 'description' => __( 'Scope under which the request is made; determines fields present in response.', 'woocommerce' ), + 'description' => __( 'Scope under which the request is made; determines fields present in response.' ), 'type' => 'string', 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg', ); + $schema = $this->get_item_schema(); + if ( empty( $schema['properties'] ) ) { return array_merge( $param_details, $args ); } + $contexts = array(); - foreach ( $schema['properties'] as $key => $attributes ) { + + foreach ( $schema['properties'] as $attributes ) { if ( ! empty( $attributes['context'] ) ) { $contexts = array_merge( $contexts, $attributes['context'] ); } } + if ( ! empty( $contexts ) ) { $param_details['enum'] = array_unique( $contexts ); rsort( $param_details['enum'] ); } + return array_merge( $param_details, $args ); } /** - * Add the values from additional fields to a data object. + * Adds the values from additional fields to a data object. + * + * @access protected * - * @param array $object - * @param WP_REST_Request $request - * @return array modified object with additional fields. + * @param array $object Data object. + * @param WP_REST_Request $request Full details about the request. + * @return array Modified data object with additional fields. */ protected function add_additional_fields_to_object( $object, $request ) { @@ -333,17 +375,18 @@ protected function add_additional_fields_to_object( $object, $request ) { } /** - * Update the values of additional fields added to a data object. + * Updates the values of additional fields added to a data object. + * + * @access protected * - * @param array $object - * @param WP_REST_Request $request + * @param array $object Data Object. + * @param WP_REST_Request $request Full details about the request. + * @return bool|WP_Error True on success, WP_Error object if a field cannot be updated. */ protected function update_additional_fields_for_object( $object, $request ) { - $additional_fields = $this->get_additional_fields(); foreach ( $additional_fields as $field_name => $field_options ) { - if ( ! $field_options['update_callback'] ) { continue; } @@ -353,27 +396,32 @@ protected function update_additional_fields_for_object( $object, $request ) { continue; } - call_user_func( $field_options['update_callback'], $request[ $field_name ], $object, $field_name, $request, $this->get_object_type() ); + $result = call_user_func( $field_options['update_callback'], $request[ $field_name ], $object, $field_name, $request, $this->get_object_type() ); + + if ( is_wp_error( $result ) ) { + return $result; + } } + + return true; } /** - * Add the schema from additional fields to an schema array. + * Adds the schema from additional fields to a schema array. * * The type of object is inferred from the passed schema. * - * @param array $schema Schema array. + * @access protected * - * @return array $schema Schema array. + * @param array $schema Schema array. + * @return array Modified Schema array. */ protected function add_additional_fields_schema( $schema ) { if ( empty( $schema['title'] ) ) { return $schema; } - /** - * Can't use $this->get_object_type otherwise we cause an inf loop. - */ + // Can't use $this->get_object_type otherwise we cause an inf loop. $object_type = $schema['title']; $additional_fields = $this->get_additional_fields( $object_type ); @@ -390,10 +438,13 @@ protected function add_additional_fields_schema( $schema ) { } /** - * Get all the registered additional fields for a given object-type. + * Retrieves all of the registered additional fields for a given object-type. * - * @param string $object_type - * @return array + * @access protected + * + * @param string $object_type Optional. The object type. + * @return array Registered additional fields (if any), empty array if none or if the object type could + * not be inferred. */ protected function get_additional_fields( $object_type = null ) { @@ -415,9 +466,11 @@ protected function get_additional_fields( $object_type = null ) { } /** - * Get the object type this controller is responsible for managing. + * Retrieves the object type this controller is responsible for managing. + * + * @access protected * - * @return string + * @return string Object type for the controller. */ protected function get_object_type() { $schema = $this->get_item_schema(); @@ -430,20 +483,20 @@ protected function get_object_type() { } /** - * Get an array of endpoint arguments from the item schema for the controller. - * - * @param string $method HTTP method of the request. The arguments - * for `CREATABLE` requests are checked for required - * values and may fall-back to a given default, this - * is not done on `EDITABLE` requests. Default is - * WP_REST_Server::CREATABLE. - * @return array $endpoint_args + * Retrieves an array of endpoint arguments from the item schema for the controller. + * + * @access public + * + * @param string $method Optional. HTTP method of the request. The arguments for `CREATABLE` requests are + * checked for required values and may fall-back to a given default, this is not done + * on `EDITABLE` requests. Default WP_REST_Server::CREATABLE. + * @return array Endpoint arguments. */ public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) { - $schema = $this->get_item_schema(); - $schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array(); - $endpoint_args = array(); + $schema = $this->get_item_schema(); + $schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array(); + $endpoint_args = array(); foreach ( $schema_properties as $field_id => $params ) { @@ -469,7 +522,7 @@ public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CRE $endpoint_args[ $field_id ]['required'] = true; } - foreach ( array( 'type', 'format', 'enum' ) as $schema_prop ) { + foreach ( array( 'type', 'format', 'enum', 'items' ) as $schema_prop ) { if ( isset( $params[ $schema_prop ] ) ) { $endpoint_args[ $field_id ][ $schema_prop ] = $params[ $schema_prop ]; } @@ -489,4 +542,24 @@ public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CRE return $endpoint_args; } -} + + /** + * Sanitizes the slug value. + * + * @access public + * + * @internal We can't use sanitize_title() directly, as the second + * parameter is the fallback title, which would end up being set to the + * request object. + * + * @see https://github.com/WP-API/WP-API/issues/1585 + * + * @todo Remove this in favour of https://core.trac.wordpress.org/ticket/34659 + * + * @param string $slug Slug value passed in request. + * @return string Sanitized value for the slug. + */ + public function sanitize_slug( $slug ) { + return sanitize_title( $slug ); + } +} \ No newline at end of file From fb17760154841edda0e5bd6fc3e7f665fc25b949 Mon Sep 17 00:00:00 2001 From: GITNE Date: Thu, 21 Sep 2017 18:30:00 +0200 Subject: [PATCH 07/63] Add README.md symlink for prettier rendering on GitHub --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 120000 README.md diff --git a/README.md b/README.md new file mode 120000 index 0000000..0d79d56 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +readme.txt \ No newline at end of file From 4313608a2e3d39cd3118617212dfdd7fa29d7add Mon Sep 17 00:00:00 2001 From: GITNE Date: Thu, 21 Sep 2017 19:00:00 +0200 Subject: [PATCH 08/63] Codify shortcodes, paths, file names, user input strings, and PHP variable identifiers for consistency and better readability --- readme.txt | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/readme.txt b/readme.txt index 1961167..737875a 100755 --- a/readme.txt +++ b/readme.txt @@ -29,12 +29,12 @@ Sermon Manager is designed to help churches easily publish sermons online. The f = Popular Shortcodes = -* [sermons] - This will list the 10 most recent sermons. -* [sermons per_page="20"] - This will list the 20 most recent sermons. -* [sermon_images] - This will list all sermon series and their associated image in a grid. -* [list_sermons] - This will list all series or speakers in a simple unordered list. -* [latest_series] - This will display information about the latest sermon series, including the image, title (optional), and description (optional). -* [sermon_sort_fields] - Dropdown selections to quickly navigate to all sermons in a series or by a particular speaker. +* `[sermons]` - This will list the 10 most recent sermons. +* `[sermons per_page="20"]` - This will list the 20 most recent sermons. +* `[sermon_images]` - This will list all sermon series and their associated image in a grid. +* `[list_sermons]` - This will list all series or speakers in a simple unordered list. +* `[latest_series]` - This will display information about the latest sermon series, including the image, title (optional), and description (optional). +* `[sermon_sort_fields]` - Dropdown selections to quickly navigate to all sermons in a series or by a particular speaker. For more information on each of these shortcodes please visit [our knowledgebase](https://wpforchurch.com/my/knowledgebase/12/Sermon-Manager). @@ -61,10 +61,10 @@ Note: Any contribution via pull request will have a note with submitter's userna Installation is simple: -1. Just use the "Add New" button in Plugin section of your WordPress blog's Control panel. To find the plugin there, search for 'Sermon Manager' +1. Just use the "Add New" button in Plugin section of your WordPress blog's Control panel. To find the plugin there, search for `Sermon Manager` 2. Activate the plugin 3. Add a sermon through the Dashboard -4. To display the sermons on the frontend of your site, just visit the http://yourdomain.com/sermons if you have permalinks enabled or http://yourdomain.com/?post_type=wpfc_sermon if not. Or you can use the shortcode [sermons] in any page. +4. To display the sermons on the frontend of your site, just visit the http://yourdomain.com/sermons if you have permalinks enabled or http://yourdomain.com/?post_type=wpfc_sermon if not. Or you can use the shortcode `[sermons]` in any page. == Frequently Asked Questions == @@ -121,7 +121,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man = 2.5.0 = * Add media functions in the sermon editor * Add options to filtering shortcode -* Fix filtering shortcode sometimes making 404 on filter +* Fix filtering shortcode sometimes making `404` on filter * Fix PHP warning not dismissible * Tweak sermon audio length field description (thanks @macbookandrew) @@ -213,7 +213,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man = 2.3.1 = * Fix shortcodes compatibility issue -* Fix [sermons] shortcode ordering +* Fix `[sermons]` shortcode ordering = 2.3.0 = * Add an option to change "Preacher" to whatever user wants ("Teacher", "Speaker"...) @@ -324,26 +324,26 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man = 1.9.4 = * Bugfix trailing / removed from podast feed * Bugfix don't include enclosure in podcast if there is no audio file -* Bugfix [list_sermons] order/orderby attributes now work as expected -* Bugfix hide_nav works correctly in the [sermons] shortcode +* Bugfix `[list_sermons]` order/orderby attributes now work as expected +* Bugfix hide_nav works correctly in the `[sermons]` shortcode * Bugfix setting defaults on activation now works correctly = 1.9.3 = * now actions are used to load sermon content in a theme: sermon_single & sermon_excerpt. This makes it easy to override the content by removing the default action and adding your own custom action. -* Bugfix sermon_images shortcode now displays the description correctly +* Bugfix `[sermon_images]` shortcode now displays the description correctly * Added podcast feed for service types = 1.9.2 = * improve setting MP3 duration; allow user to edit duration if not set accurately = 1.9.1 = -* Minor fixes to the [latest_series] shortcode - [updated documentation](http://www.wpforchurch.com/knowledgebase/sermon-manager-shortcodes/) +* Minor fixes to the `[latest_series]` shortcode - [updated documentation](http://www.wpforchurch.com/knowledgebase/sermon-manager-shortcodes/) = 1.9 = * NEW FEATURE: Podcast feeds for every Preacher, Service Type, Series, Bible Book, and Topic. -* NEW FEATURE: New shortcode to display the latest sermon series image [latest_series] (many options including displaying by service type) +* NEW FEATURE: New shortcode to display the latest sermon series image `[latest_series]` (many options including displaying by service type) * NEW FEATURE: Admin columns are now sortable - props to @khornberg -* NEW FEATURE: All media is now uploaded to a custom folder /sermons/ under /uploads. This will allow easier media management and exclusion from backups (if desired) +* NEW FEATURE: All media is now uploaded to a custom folder `/sermons` under `/uploads`. This will allow easier media management and exclusion from backups (if desired) * Remove mediaelement audio player and use the built in mediaelement (now requires WordPress 3.6+) * Remove dependency on wp-pagenavi for shortcode pagination * Resolved issue with media player not displaying with shortcodes @@ -376,7 +376,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man = 1.7 = * Improved many areas of the code; organized files -* Made a new permalink structure possible with a common base slug across all taxonomies, e.g. sermons/preacher or sermons/series. +* Made a new permalink structure possible with a common base slug across all taxonomies, e.g. `sermons/preacher` or `sermons/series`. * Added new template tag for the podcast url * Add series, preacher, topic, and book to post class * Trim taxonomy description in Admin @@ -385,7 +385,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Add template tags to show preacher and series info on individual sermons * Allow service type to be empty * Use date option set in WordPress settings instead of hardcoded format -* Resolve $wpfc_entry_views error with PHP 5.4 +* Resolve `$wpfc_entry_views` error with PHP 5.4 * Cleaned up CSS ids and classes to be compliant code = 1.6 = @@ -402,7 +402,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Fix settings for bib.ly = 1.5.4 = -* Added an action 'wpfc_settings_form' to add fields to the settings page +* Added an action `wpfc_settings_form` to add fields to the settings page * Fixed bug with sermon topic dropdown = 1.5.3 = @@ -425,8 +425,8 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Properly enqueueing all JavaScript and CSS * New template tags for easier theme customization * Added new taxonomy "Book of the Bible" to allow easy sorting of sermons -* Display a grid of images assigned to speakers or series with a new shortcode [sermon-images] -* Display a list of sermon series, preachers, sermon topics, or book of the Bible with a new shortcode [list-sermons] +* Display a grid of images assigned to speakers or series with a new shortcode `[sermon-images]` +* Display a list of sermon series, preachers, sermon topics, or book of the Bible with a new shortcode `[list-sermons]` = 1.3.3 = * Bug fix with menu not showing in some themes @@ -442,7 +442,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Added images to sermon topics * Created new functions to render sermon archive listing and single sermons * Added better sorting fields on archive page -* Added shortcode to insert sort fields - sermon_sort_fields +* Added shortcode to insert sort fields - `[sermon_sort_fields]` = 1.2.1 = * Enhanced shortcode to allow for Ajax pagination @@ -457,7 +457,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Added icons for audio and video attachments = 1.1.3 = -* Theme developers can add support for sermon manager to their theme with `add_theme_support( 'sermon-manager' );` in functions.php. For now, this will disable the loading of the jwplayer javascript +* Theme developers can add support for sermon manager to their theme with `add_theme_support( 'sermon-manager' );` in `functions.php`. For now, this will disable the loading of the jwplayer javascript * Bug fix to load javascript for sermon player and verse popups on single sermon pages only * minor CSS fix to increase font size of popup Bible passages From c1555cd5aa5de6d07bab729cba6843bcd7315eca Mon Sep 17 00:00:00 2001 From: GITNE Date: Thu, 21 Sep 2017 19:30:00 +0200 Subject: [PATCH 09/63] Fix spelling, typos, and letter casing --- readme.txt | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/readme.txt b/readme.txt index 737875a..f73e927 100755 --- a/readme.txt +++ b/readme.txt @@ -36,7 +36,7 @@ Sermon Manager is designed to help churches easily publish sermons online. The f * `[latest_series]` - This will display information about the latest sermon series, including the image, title (optional), and description (optional). * `[sermon_sort_fields]` - Dropdown selections to quickly navigate to all sermons in a series or by a particular speaker. -For more information on each of these shortcodes please visit [our knowledgebase](https://wpforchurch.com/my/knowledgebase/12/Sermon-Manager). +For more information on each of these shortcodes please visit [our knowledge base](https://wpforchurch.com/my/knowledgebase/12/Sermon-Manager). = Expert Support = @@ -108,7 +108,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Change preacher slugs as well when changing preacher label in settings * Fix spelling error (thanks @tythewebguy) * Fix filtering not working on a subpage -* Fix a security concern (GitHub isssue #87) +* Fix a security concern (GitHub issue #87) * Fix preacher image upload button & title not respecting preacher label * Fix wrong dialog title for Sermon Series image picker * Fix archive slug change needs saving of settings two times @@ -329,12 +329,12 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Bugfix setting defaults on activation now works correctly = 1.9.3 = -* now actions are used to load sermon content in a theme: sermon_single & sermon_excerpt. This makes it easy to override the content by removing the default action and adding your own custom action. +* Now actions are used to load sermon content in a theme: sermon_single & sermon_excerpt. This makes it easy to override the content by removing the default action and adding your own custom action. * Bugfix `[sermon_images]` shortcode now displays the description correctly * Added podcast feed for service types = 1.9.2 = -* improve setting MP3 duration; allow user to edit duration if not set accurately +* Improve setting MP3 duration; allow user to edit duration if not set accurately = 1.9.1 = * Minor fixes to the `[latest_series]` shortcode - [updated documentation](http://www.wpforchurch.com/knowledgebase/sermon-manager-shortcodes/) @@ -350,29 +350,29 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man = 1.8.3 = -* require WordPress 3.6+ -* use built in mediaelement player +* Require WordPress 3.6+ +* Use built in mediaelement player = 1.8.1 = -* fixed errors with saving settings for some users (remove dependency on CURL) +* Fixed errors with saving settings for some users (remove dependency on CURL) = 1.8 = -* improved podcasting performance - props @livingos -* cleaned up options page with tabs, added hooks for other plugins to hook into the option page. -* fixed bug causing sermons to display 2x +* Improved podcasting performance - props @livingos +* Cleaned up options page with tabs, added hooks for other plugins to hook into the option page. +* Fixed bug causing sermons to display 2x = 1.7.4 = -* updated the way attachments are displayed. Now they will be available for download even if not attached to the sermon. -* fix sermon-images shortcode +* Updated the way attachments are displayed. Now they will be available for download even if not attached to the sermon. +* Fix sermon-images shortcode = 1.7.3 = -* compatibility with WordPress 3.6 +* Compatibility with WordPress 3.6 = 1.7.2 = -* disable a filter that was causing problems in some themes (added in 1.7) +* Disable a filter that was causing problems in some themes (added in 1.7) = 1.7.1 = -* fix a few bugs introduced in 1.7 +* Fix a few bugs introduced in 1.7 = 1.7 = * Improved many areas of the code; organized files @@ -459,19 +459,19 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man = 1.1.3 = * Theme developers can add support for sermon manager to their theme with `add_theme_support( 'sermon-manager' );` in `functions.php`. For now, this will disable the loading of the jwplayer javascript * Bug fix to load javascript for sermon player and verse popups on single sermon pages only -* minor CSS fix to increase font size of popup Bible passages +* Minor CSS fix to increase font size of popup Bible passages = 1.1.2 = -* bug fixes so everything saved correctly when doing autosave, quick edit, and bulk edit -* minor CSS fix for icon to display with additional files +* Bug fixes so everything saved correctly when doing autosave, quick edit, and bulk edit +* Minor CSS fix for icon to display with additional files = 1.1.1 = -* bug fixes to templating system -* minor CSS fixes +* Bug fixes to templating system +* Minor CSS fixes = 1.1 = * New much improved templating system! -* Bug fixes related to the loading of javascript and CSS +* Bug fixes related to the loading of JavaScript and CSS = 1.0 = * Fixes related to WordPress 3.3; takes advantage of new tinymce editor @@ -486,4 +486,4 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Bug Fixes = 0.6 = -* initial public release +* Initial public release From 2144f6c011e89a132f50f5f4f5e28aaf3efad75a Mon Sep 17 00:00:00 2001 From: GITNE Date: Thu, 21 Sep 2017 19:40:00 +0200 Subject: [PATCH 10/63] Modify section headers to Markdown headers --- readme.txt | 184 ++++++++++++++++++++++++++--------------------------- 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/readme.txt b/readme.txt index f73e927..4794da0 100755 --- a/readme.txt +++ b/readme.txt @@ -1,4 +1,4 @@ -=== Sermon Manager === +# Sermon Manager # Contributors: wpforchurch, nikolam Donate link: http://wpforchurch.com/ Tags: church, sermon, sermons, preaching, podcasting, manage, managing, podcasts, itunes @@ -11,9 +11,9 @@ License URI: https://www.gnu.org/licenses/gpl-2.0.html Add audio and video sermons, manage speakers, series, and more to your church website. -== Description == +## Description ## -= Sermon Manager is the #1 WordPress Sermon Plugin = +### Sermon Manager is the #1 WordPress Sermon Plugin ### Sermon Manager is designed to help churches easily publish sermons online. The features include: @@ -27,7 +27,7 @@ Sermon Manager is designed to help churches easily publish sermons online. The f * Full-featured iTunes podcasting support for all sermons, plus each sermon series, preachers, sermon topics, or book of the Bible! * Quick and professional support -= Popular Shortcodes = +### Popular Shortcodes ### * `[sermons]` - This will list the 10 most recent sermons. * `[sermons per_page="20"]` - This will list the 20 most recent sermons. @@ -38,7 +38,7 @@ Sermon Manager is designed to help churches easily publish sermons online. The f For more information on each of these shortcodes please visit [our knowledge base](https://wpforchurch.com/my/knowledgebase/12/Sermon-Manager). -= Expert Support = +### Expert Support ### The Sermon Manager is available as a FREE download however in order to maintain a free version we offer [premium support packages](https://wpforchurch.com/wordpress-plugins/sermon-manager/#pricing) for those who need any custom assistance. Paid support means you get exclusive access to the Sermon Manager forum as well as support tickets. This is also a way you can donate to the project to help us offer prompt support and a free version of the plugin. @@ -46,18 +46,18 @@ You can access the paid support options via [our website](http://wpforchurch.com Bug fixing and fixing unexpected behavior *is free* and *always will be free*. Just [make an issue on GitHub](https://github.com/WP-for-Church/Sermon-Manager/issues/new) or [create a support thread on WordPress](https://wordpress.org/support/plugin/sermon-manager-for-wordpress#new-post) and we will solve it ASAP. -= Developers = +### Developers ### Would you like to help improve Sermon Manager or report a bug you found? This project is open source on [GitHub](https://github.com/WP-for-Church/Sermon-Manager) Note: Any contribution via pull request will have a note with submitter's username in changelog, example: "(thanks @nikola3244)". -= WP for Church = +### WP for Church ### * [WP for Church](https://wpforchurch.com/) provides plugins and responsive themes for churches using WordPress. * Keep up with the latest product news & tips, sign up to our [newsletter](https://www.wpforchurch.com/blog)! -== Installation == +## Installation ## Installation is simple: @@ -66,45 +66,45 @@ Installation is simple: 3. Add a sermon through the Dashboard 4. To display the sermons on the frontend of your site, just visit the http://yourdomain.com/sermons if you have permalinks enabled or http://yourdomain.com/?post_type=wpfc_sermon if not. Or you can use the shortcode `[sermons]` in any page. -== Frequently Asked Questions == +## Frequently Asked Questions ## -= How do I display sermons on the frontend? = +### How do I display sermons on the frontend? ### Visit the http://yourdomain.com/sermons if you have permalinks enabled or http://yourdomain.com/?post_type=wpfc_sermon if not. Or you can use the shortcode `[sermons]` in any page. -= How do I create a menu link? = +### How do I create a menu link? ### Go to Appearance => Menus. In the "Custom Links" box add "http://yourdomain.com/?post_type=wpfc_sermon" as the url and "Sermons" as the label and click "Add to Menu". -= I wish Sermon Manager could... = +### I wish Sermon Manager could... ### We are open to suggestions to make this a great tool for churches! Submit your feedback at [WP for Church](https://feedback.userreport.com/05ff651b-670e-4eb7-a734-9a201cd22906/) -= More Questions? = +### More Questions? ### Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-manager/ "Sermon Manager homepage") -== Screenshots == +## Screenshots ## 1. Sermon Details 2. Sermon Files -== Changelog == -= 2.6.2 = +## Changelog ## +### 2.6.2 ### * Add more `` elements for more styling options * Fix podcast feed not working -= 2.6.1 = +### 2.6.1 ### * Fix fatal error on old PHP versions * Fix custom preacher slug not working -= 2.6 = +### 2.6 ### * Fix PHP warning regarding sorting * Fix Taxonomy images not working on initial plugin install (and sometimes for existing ones as well - needs plugin re-activation) * Fix space character is being URL encoded twice * Add more filters to the shortcode * Add back Sermon dates -= 2.5.2 = +### 2.5.2 ### * Change preacher slugs as well when changing preacher label in settings * Fix spelling error (thanks @tythewebguy) * Fix filtering not working on a subpage @@ -115,34 +115,34 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Fix taxonomy image errors on first plugin install * Fix copyright symbol not appearing correctly -= 2.5.1 = +### 2.5.1 ### * Fix fatal error on older PHP versions -= 2.5.0 = +### 2.5.0 ### * Add media functions in the sermon editor * Add options to filtering shortcode * Fix filtering shortcode sometimes making `404` on filter * Fix PHP warning not dismissible * Tweak sermon audio length field description (thanks @macbookandrew) -= 2.4.11 = +### 2.4.11 ### * Fix paragraphs in podcast feed description * Fix podcasts not validating with exotic mp3 file names * Fix double URLs appearing in sermon downloads * Fix sermons not appearing in shortcodes -= 2.4.10 = +### 2.4.10 ### * Fix filtering styling being broken -= 2.4.9 = +### 2.4.9 ### * Fix new sermons not appearing * Fix couple PHP warnings * Fix filtering in shortcode -= 2.4.8 = +### 2.4.8 ### * Fix featured image not working -= 2.4.7 = +### 2.4.7 ### * Fix PHP notice in the footer * Fix slashes in RSS feed * Fix podcast cover image not selecting @@ -153,29 +153,29 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Removed all warnings and error related to dates * Replaced old media manager with new one for podcast cover image -= 2.4.6 = +### 2.4.6 ### * Add a setting to define podcast count * Fix a bug that caused WSOD on some hosts * Fix a bug that prevented settings to save on some hosts -= 2.4.5 = +### 2.4.5 ### * Fix error that rendered website unusable on some hosts * Fix double line-breaks in the podcast description not changing into HTML paragraphs * Make new podcast HTML tags option disabled by default -= 2.4.4 = +### 2.4.4 ### * Fix shortcode pagination broken on front page (thanks @antgiant) * Fix new audio player not loading on some old themes * Add an option to show key verse in "Recent Sermons" widget * Add HTML tags display in podcast description (can be disabled in settings) * Improve scripts & styles loading (website performance improvements) -= 2.4.3 = +### 2.4.3 ### * Fix HTML formatting * Fix new player duration always being 0:00 on initial load * Fix Sermon date breaking the website in some special circumstances -= 2.4.2 = +### 2.4.2 ### * Fix Sermon Manager interfering with regular post dates under some circumstances * Fix fatal error when using UpdraftPlus * Fix fatal error for longtime Sermon Manager users (thank you <3) @@ -184,10 +184,10 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Fix scripts and styles not loading when shortcode is used in ordinary posts * Fix new player styles not loading -= 2.4.1 = +### 2.4.1 ### * Fix fatal error for podcasts -= 2.4.0 = +### 2.4.0 ### * Add a setting for Sermon date format * Add a filter for changing sermon image link (thanks @macbookandrew) * Add Polish translation (thanks @GITNE) @@ -196,56 +196,56 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Performance improvements * Miscellaneous bug fixes -= 2.3.4 = +### 2.3.4 ### * Improve backend performance * Fix topics list in backend sometimes being corrupted -= 2.3.3 = +### 2.3.3 ### * Fix a typo in "Sort by Preacher" table column * Fix a PHP warning when a sermon is created with Service Type set to "None" * Fix Sermon Audio removing/uploading in backend not working -= 2.3.2 = +### 2.3.2 ### * Allow displaying of audio and video at the same time * Fix new audio player conflicting with other elements * Fix Bib.ly not showing on sermon archive pages * Fix Bib.ly not loading over HTTPS -= 2.3.1 = +### 2.3.1 ### * Fix shortcodes compatibility issue * Fix `[sermons]` shortcode ordering -= 2.3.0 = +### 2.3.0 ### * Add an option to change "Preacher" to whatever user wants ("Teacher", "Speaker"...) * Fix series image shortcode not working properly * Fix disappeared bible passage * Core improvements -= 2.2.0 = +### 2.2.0 ### * Add `orderby` argument for `[sermons]` shortcode. How to use: https://wpforchurch.com/my/knowledgebase/75/Sermon-Manager-Shortcodes.html * Add an option to switch between the old and the new MP3 player * Fix some cases where PodCast feed is invalid -= 2.1.5 = +### 2.1.5 ### * Fix crash on PHP <5.5 (for real this time) * Fix sermon MP3 file name while downloading -= 2.1.4 = +### 2.1.4 ### * Fix crash on PHP <5.5 -= 2.1.3 = +### 2.1.3 ### * Fix podcast feed date being invalid when used on website with non English language * Fix crashing on older PHP versions -= 2.1.2 = +### 2.1.2 ### * Allow Sermon Manager usage on old PHP versions * Fix shortcode not working -= 2.1.1 = +### 2.1.1 ### * Fix plugin crashing. Add missing files. * Remove old screenshots -= 2.1.0 = +### 2.1.0 ### * Fix book sorting bug * Fix issue where podcast enclosures are sometimes duplicated * Fix sermon topics custom view not loading @@ -259,18 +259,18 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Add warning if user is using PHP version less than 5.6.0 * Simplify shortcodes -= 2.0.8 = +### 2.0.8 ### * Fix another date error * Revert fix for "fatal error with date processing", since it caused issues for some users * Fix video width being too wide * Fix microphone issue -= 2.0.7 = +### 2.0.7 ### * Fixed fatal error with date processing * Fixed some PHP 7 warnings * Added better shortcode book sorting -= 2.0.6 = +### 2.0.6 ### * Fix date warning in the `Date Preached` column * Fix downloads not showing notes and bulletin * Fix taxonomy images not working on new installs @@ -278,32 +278,32 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Fix Yoast SEO XML sitemap not working with SM - Please re-save settings and permalinks * Fix image chooser not opening correctly when user clicks on series/preacher image (browser cache might need to be cleared) -= 2.0.5 = +### 2.0.5 ### * Fix: Sermon Archive shortcode wasn't displaying properly -= 2.0.4 = +### 2.0.4 ### * Fixed error where saving anything in admin caused a php notice * Fixed setting page and notice to re-save settings even after user had saved * Updated sermon archive to show new sermon sorting fields function -= 2.0.3 = +### 2.0.3 ### * Fixed error causing sermons views to not count * Fixed several issues with classes being called improperly -= 2.0.2 = +### 2.0.2 ### * Fixed legacy support and functionality for video embed * Fixed podcast error causing duplicate entries -= 2.0.1 = +### 2.0.1 ### * Fixed backwards compatibility issues * Fixed issue with service type dropdown -= 2.0 = +### 2.0 ### * Massive update to core code with php7 compatibility * Bulletin file upload @@ -311,35 +311,35 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Updated Views * Use YouTube/Vimeo link (with legacy support for old video embeds) -= 1.9.6 = +### 1.9.6 ### * Bugfix podcast title is fixed in WP 4.4 * Multiple non-fatal errors have been fixed -= 1.9.5 = +### 1.9.5 ### * Bugfix podcast title is taken from Settings Page * Bugfix podcast no longer has any missing sermons * Bugfix properly strip html from podcast summary -= 1.9.4 = +### 1.9.4 ### * Bugfix trailing / removed from podast feed * Bugfix don't include enclosure in podcast if there is no audio file * Bugfix `[list_sermons]` order/orderby attributes now work as expected * Bugfix hide_nav works correctly in the `[sermons]` shortcode * Bugfix setting defaults on activation now works correctly -= 1.9.3 = +### 1.9.3 ### * Now actions are used to load sermon content in a theme: sermon_single & sermon_excerpt. This makes it easy to override the content by removing the default action and adding your own custom action. * Bugfix `[sermon_images]` shortcode now displays the description correctly * Added podcast feed for service types -= 1.9.2 = +### 1.9.2 ### * Improve setting MP3 duration; allow user to edit duration if not set accurately -= 1.9.1 = +### 1.9.1 ### * Minor fixes to the `[latest_series]` shortcode - [updated documentation](http://www.wpforchurch.com/knowledgebase/sermon-manager-shortcodes/) -= 1.9 = +### 1.9 ### * NEW FEATURE: Podcast feeds for every Preacher, Service Type, Series, Bible Book, and Topic. * NEW FEATURE: New shortcode to display the latest sermon series image `[latest_series]` (many options including displaying by service type) * NEW FEATURE: Admin columns are now sortable - props to @khornberg @@ -349,32 +349,32 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Resolved issue with media player not displaying with shortcodes -= 1.8.3 = +### 1.8.3 ### * Require WordPress 3.6+ * Use built in mediaelement player -= 1.8.1 = +### 1.8.1 ### * Fixed errors with saving settings for some users (remove dependency on CURL) -= 1.8 = +### 1.8 ### * Improved podcasting performance - props @livingos * Cleaned up options page with tabs, added hooks for other plugins to hook into the option page. * Fixed bug causing sermons to display 2x -= 1.7.4 = +### 1.7.4 ### * Updated the way attachments are displayed. Now they will be available for download even if not attached to the sermon. * Fix sermon-images shortcode -= 1.7.3 = +### 1.7.3 ### * Compatibility with WordPress 3.6 -= 1.7.2 = +### 1.7.2 ### * Disable a filter that was causing problems in some themes (added in 1.7) -= 1.7.1 = +### 1.7.1 ### * Fix a few bugs introduced in 1.7 -= 1.7 = +### 1.7 ### * Improved many areas of the code; organized files * Made a new permalink structure possible with a common base slug across all taxonomies, e.g. `sermons/preacher` or `sermons/series`. * Added new template tag for the podcast url @@ -388,35 +388,35 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Resolve `$wpfc_entry_views` error with PHP 5.4 * Cleaned up CSS ids and classes to be compliant code -= 1.6 = +### 1.6 ### * Improved localization & added French translation * Updated mediaelements.js to the latest version * Change Service Types to a custom taxonomy so you can add/edit as you wish (you'll see an admin notice to refresh your database) -= 1.5.6 = +### 1.5.6 ### * Added comma separator in case of multiple speakers or multiple series * Added speaker name to widget * Added "sort by Book" to sermon sort fields -= 1.5.5 = +### 1.5.5 ### * Fix settings for bib.ly -= 1.5.4 = +### 1.5.4 ### * Added an action `wpfc_settings_form` to add fields to the settings page * Fixed bug with sermon topic dropdown -= 1.5.3 = +### 1.5.3 ### * Properly prefixed the entry views function to prevent conflicts -= 1.5.2 = +### 1.5.2 ### * Only load admin scripts and styles on Sermon pages -= 1.5.1 = +### 1.5.1 ### * Improve CSS for Chrome * Add the option to include the audio player in archive view * Fix display issues on some themes in archive view -= 1.5 = +### 1.5 ### * Improve page navigation styles with shortcode * Improve admin interface & added a "Sermon Notes" field * Fixed the views count for sermons @@ -428,13 +428,13 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Display a grid of images assigned to speakers or series with a new shortcode `[sermon-images]` * Display a list of sermon series, preachers, sermon topics, or book of the Bible with a new shortcode `[list-sermons]` -= 1.3.3 = +### 1.3.3 ### * Bug fix with menu not showing in some themes -= 1.3.1 = +### 1.3.1 ### * Bug fix with Service Type not saving correctly -= 1.3 = +### 1.3 ### * Added a settings page * Now translation ready! * Added styling to the Recent Sermons Widget @@ -444,46 +444,46 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Added better sorting fields on archive page * Added shortcode to insert sort fields - `[sermon_sort_fields]` -= 1.2.1 = +### 1.2.1 ### * Enhanced shortcode to allow for Ajax pagination * Requires a plugin for pagination in shortcode to work: http://wordpress.org/extend/plugins/wp-pagenavi/ -= 1.2 = +### 1.2 ### * Shortcode completely updated with [documentation](http://www.wpforchurch.com/882/sermon-shortcode/) -= 1.1.4 = +### 1.1.4 ### * Now you can add images to sermon series and preachers! * Widget now includes the sermon date * Added icons for audio and video attachments -= 1.1.3 = +### 1.1.3 ### * Theme developers can add support for sermon manager to their theme with `add_theme_support( 'sermon-manager' );` in `functions.php`. For now, this will disable the loading of the jwplayer javascript * Bug fix to load javascript for sermon player and verse popups on single sermon pages only * Minor CSS fix to increase font size of popup Bible passages -= 1.1.2 = +### 1.1.2 ### * Bug fixes so everything saved correctly when doing autosave, quick edit, and bulk edit * Minor CSS fix for icon to display with additional files -= 1.1.1 = +### 1.1.1 ### * Bug fixes to templating system * Minor CSS fixes -= 1.1 = +### 1.1 ### * New much improved templating system! * Bug fixes related to the loading of JavaScript and CSS -= 1.0 = +### 1.0 ### * Fixes related to WordPress 3.3; takes advantage of new tinymce editor -= 0.9 = +### 0.9 ### * Added WYSIWYG editor to the sermon description field -= 0.8 = +### 0.8 ### * Added Widgets -= 0.7 = +### 0.7 ### * Bug Fixes -= 0.6 = +### 0.6 ### * Initial public release From 3427f6b80e2864dccb13a9074831079fd3675a00 Mon Sep 17 00:00:00 2001 From: Nikola Date: Fri, 22 Sep 2017 09:04:23 +0200 Subject: [PATCH 11/63] Maybe fix ordering --- includes/widgets.php | 2 +- readme.txt | 1 + sermons.php | 2 +- views/wpfc-podcast-feed.php | 10 +++++----- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/includes/widgets.php b/includes/widgets.php index 219fc9e..0b0b9ea 100755 --- a/includes/widgets.php +++ b/includes/widgets.php @@ -52,7 +52,7 @@ function widget( $args, $instance ) { 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'meta_key' => 'sermon_date', - 'meta_value' => time(), + 'meta_value_num' => time(), 'meta_compare' => '<=', 'orderby' => 'meta_value_num', ) ); diff --git a/readme.txt b/readme.txt index 763ad4a..bf542b6 100755 --- a/readme.txt +++ b/readme.txt @@ -91,6 +91,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man == Changelog == = 2.7 = * Add WordPress search support to sermons +* Fix sermon ordering = 2.6.2 = * Add more `` elements for more styling options diff --git a/sermons.php b/sermons.php index 41752fe..1a2c83a 100755 --- a/sermons.php +++ b/sermons.php @@ -198,7 +198,7 @@ public static function fix_sermons_ordering( $query ) { is_tax( 'wpfc_bible_book' ) ) { $query->set( 'meta_key', 'sermon_date' ); - $query->set( 'meta_value', time() ); + $query->set( 'meta_value_num', time() ); $query->set( 'meta_compare', '<=' ); $query->set( 'orderby', 'meta_value_num' ); $query->set( 'order', 'DESC' ); diff --git a/views/wpfc-podcast-feed.php b/views/wpfc-podcast-feed.php index 286f090..13db50e 100644 --- a/views/wpfc-podcast-feed.php +++ b/views/wpfc-podcast-feed.php @@ -9,12 +9,12 @@ exit; $args = array( - 'post_type' => 'wpfc_sermon', + 'post_type' => 'wpfc_sermon', 'posts_per_page' => - 1, - 'meta_key' => 'sermon_date', - 'meta_value' => time(), - 'meta_compare' => '<=', - 'orderby' => 'meta_value_num', + 'meta_key' => 'sermon_date', + 'meta_value_num' => time(), + 'meta_compare' => '<=', + 'orderby' => 'meta_value_num', ); $sermon_podcast_query = new WP_Query( $args ); From a0878f7d6fa2572277a80493189dde877d5f2361 Mon Sep 17 00:00:00 2001 From: Nikola Date: Fri, 22 Sep 2017 11:25:44 +0200 Subject: [PATCH 12/63] Fix PHPdoc @return --- includes/shortcodes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/shortcodes.php b/includes/shortcodes.php index 989e792..31c5fee 100755 --- a/includes/shortcodes.php +++ b/includes/shortcodes.php @@ -602,7 +602,7 @@ public function displaySermonSorting( $atts = array() ) { * @type string $atts ['before'] Date to retrieve posts before. Accepts strtotime()-compatible string * * - * @return string|void + * @return string */ function displaySermons( $atts = array() ) { // default options From 9c480cc84626e81f71374bba1e168f5908ce9eae Mon Sep 17 00:00:00 2001 From: Nikola Date: Fri, 22 Sep 2017 12:46:33 +0200 Subject: [PATCH 13/63] Add sermon ordering by sermon_date meta and post_date --- includes/shortcodes.php | 36 +++++++++++++++++++++++++++--------- readme.txt | 1 + sermons.php | 21 +++++++++++++++++---- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/includes/shortcodes.php b/includes/shortcodes.php index 31c5fee..6ca4c32 100755 --- a/includes/shortcodes.php +++ b/includes/shortcodes.php @@ -658,9 +658,6 @@ function displaySermons( $atts = array() ) { 'post_type' => 'wpfc_sermon', 'posts_per_page' => $args['per_page'], 'order' => $args['order'], - 'meta_key' => 'sermon_date', - 'meta_value_num' => time(), - 'meta_compare' => '<=', 'paged' => $my_page, 'year' => $args['year'], 'month' => $args['month'], @@ -668,6 +665,19 @@ function displaySermons( $atts = array() ) { 'day' => $args['day'], 'after' => $args['after'], 'before' => $args['before'], + 'meta_query' => array( + 'relation' => 'OR', + array( //check to see if date has been filled out + 'key' => 'sermon_date', + 'compare' => '<=', + 'value' => time() + ), + array( //if no date has been added show these posts too + 'key' => 'sermon_date', + 'value' => time(), + 'compare' => 'NOT EXISTS' + ) + ), ); // check if it's a valid ordering argument @@ -683,12 +693,7 @@ function displaySermons( $atts = array() ) { $args['orderby'] = 'date'; } - // set the ordering options - if ( $args['orderby'] === 'date' ) { - $query_args['orderby'] = 'meta_value_num'; - } else { - $query_args['orderby'] = $args['orderby']; - } + $query_args['orderby'] = $args['orderby']; // if we should show just specific sermons if ( $args['sermons'] ) { @@ -767,8 +772,17 @@ function displaySermons( $atts = array() ) { unset( $query_args['tax_query']['custom'] ); } + + if ( $query_args['orderby'] === 'date' ) { + add_filter( 'posts_orderby', array( $this, 'orderby' ) ); + } + $listing = new WP_Query( $query_args ); + if ( $query_args['orderby'] === 'date' ) { + remove_filter( 'posts_orderby', array( $this, 'orderby' ) ); + } + if ( $listing->have_posts() ) { ob_start(); ?>
@@ -812,6 +826,10 @@ function displaySermons( $atts = array() ) { return 'No sermons found.'; } } + + public function orderby( $var ) { + return 'GREATEST(UNIX_TIMESTAMP(wp_posts.post_date), wp_postmeta.meta_value+0) DESC'; + } } $WPFC_Shortcodes = new WPFC_Shortcodes; diff --git a/readme.txt b/readme.txt index bf542b6..3d95876 100755 --- a/readme.txt +++ b/readme.txt @@ -92,6 +92,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man = 2.7 = * Add WordPress search support to sermons * Fix sermon ordering +* Fix new sermons not appearing = 2.6.2 = * Add more `` elements for more styling options diff --git a/sermons.php b/sermons.php index 1a2c83a..9737847 100755 --- a/sermons.php +++ b/sermons.php @@ -197,11 +197,24 @@ public static function fix_sermons_ordering( $query ) { is_tax( 'wpfc_sermon_series' ) || is_tax( 'wpfc_bible_book' ) ) { - $query->set( 'meta_key', 'sermon_date' ); - $query->set( 'meta_value_num', time() ); - $query->set( 'meta_compare', '<=' ); - $query->set( 'orderby', 'meta_value_num' ); + $query->set( 'meta_query', array( + 'relation' => 'OR', + array( //check to see if date has been filled out + 'key' => 'sermon_date', + 'compare' => '<=', + 'value' => time() + ), + array( //if no date has been added show these posts too + 'key' => 'sermon_date', + 'value' => time(), + 'compare' => 'NOT EXISTS' + ) + ) ); + $query->set( 'orderby', 'meta_value_num date' ); $query->set( 'order', 'DESC' ); + add_filter( 'posts_orderby', function ( $arg ) { + return 'GREATEST(UNIX_TIMESTAMP(wp_posts.post_date), wp_postmeta.meta_value+0) DESC'; + } ); } } } From 281f25043a0b3d9928890f691ec6b44dde6624c0 Mon Sep 17 00:00:00 2001 From: Nikola Date: Fri, 22 Sep 2017 13:20:51 +0200 Subject: [PATCH 14/63] Fix span styling in widget --- css/sermon.css | 4 ++++ readme.txt | 1 + 2 files changed, 5 insertions(+) diff --git a/css/sermon.css b/css/sermon.css index 99ebae7..630222a 100755 --- a/css/sermon.css +++ b/css/sermon.css @@ -139,6 +139,10 @@ display: block; } +.widget_recent_sermons .meta > span { + display: inline; +} + #sermon-navigation { padding-bottom: 15px; } diff --git a/readme.txt b/readme.txt index a05e5d7..1ef9aaa 100755 --- a/readme.txt +++ b/readme.txt @@ -93,6 +93,7 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man * Add WordPress search support to sermons * Fix sermon ordering * Fix new sermons not appearing +* Fix widget styling ### 2.6.2 ### * Add more `` elements for more styling options From 8a45071ce4af4ffb926c5d56e57862ee4d831cbe Mon Sep 17 00:00:00 2001 From: Nikola Date: Fri, 22 Sep 2017 14:40:40 +0200 Subject: [PATCH 15/63] Post types, taxonomies and permalinks refactoring --- includes/class-sm-dates-wp.php | 3 +- includes/class-sm-dates.php | 1 + includes/class-sm-post-types.php | 256 +++++++++++ includes/sm-cmb-functions.php | 189 ++++++++ includes/sm-core-functions.php | 81 ++++ ...cy-php.php => sm-legacy-php-functions.php} | 0 includes/template-tags.php | 26 +- includes/types-taxonomies.php | 408 ------------------ readme.txt | 2 + sermons.php | 7 +- 10 files changed, 560 insertions(+), 413 deletions(-) create mode 100644 includes/class-sm-post-types.php create mode 100755 includes/sm-cmb-functions.php rename includes/{legacy-php.php => sm-legacy-php-functions.php} (100%) delete mode 100755 includes/types-taxonomies.php diff --git a/includes/class-sm-dates-wp.php b/includes/class-sm-dates-wp.php index 572050d..564a81f 100644 --- a/includes/class-sm-dates-wp.php +++ b/includes/class-sm-dates-wp.php @@ -1,4 +1,6 @@ false, + 'label' => __( 'Preachers', 'sermon-manager' ), + 'labels' => array( + 'name' => __( \SermonManager::getOption( 'preacher_label' ) ? \SermonManager::getOption( 'preacher_label' ) . 's' : 'Preachers', 'sermon-manager' ), + 'singular_name' => __( \SermonManager::getOption( 'preacher_label' ) ?: 'Preacher', 'sermon-manager' ), + 'menu_name' => _x( \SermonManager::getOption( 'preacher_label' ) ? \SermonManager::getOption( 'preacher_label' ) . 's' : 'Preachers', 'Admin menu name', 'sermon-manager' ), + 'search_items' => __( 'Search' . ( \SermonManager::getOption( 'preacher_label' ) ? \SermonManager::getOption( 'preacher_label' ) . 's' : 'preachers' ), 'sermon-manager' ), + 'all_items' => __( 'All ' . ( \SermonManager::getOption( 'preacher_label' ) ? \SermonManager::getOption( 'preacher_label' ) . 's' : 'preachers' ), 'sermon-manager' ), + 'parent_item' => null, // it's not hierarchical + 'parent_item_colon' => null, // it's not hierarchical + 'edit_item' => __( 'Edit ' . ( \SermonManager::getOption( 'preacher_label' ) ?: 'preacher' ), 'sermon-manager' ), + 'update_item' => __( 'Update ' . ( \SermonManager::getOption( 'preacher_label' ) ?: 'preacher' ), 'sermon-manager' ), + 'add_new_item' => __( 'Add new ' . ( \SermonManager::getOption( 'preacher_label' ) ?: 'preacher' ), 'sermon-manager' ), + 'new_item_name' => __( 'New ' . ( \SermonManager::getOption( 'preacher_label' ) ?: 'preacher' ) . ' name', 'sermon-manager' ), + 'not_found' => __( 'No ' . ( \SermonManager::getOption( 'preacher_label' ) ? \SermonManager::getOption( 'preacher_label' ) . 's' : 'preacher' ) . ' found', 'sermon-manager' ), + ), + 'show_ui' => true, + 'query_var' => true, + 'rewrite' => array( 'slug' => $permalinks['wpfc_preacher'], 'with_front' => false ), + ) ) ); + + register_taxonomy( 'wpfc_sermon_series', + apply_filters( 'sm_taxonomy_objects_wpfc_sermon_series', array( 'wpfc_sermon' ) ), + apply_filters( 'sm_taxonomy_args_wpfc_sermon_series', array( + 'hierarchical' => false, + 'label' => __( 'Series', 'sermon-manager' ), + 'labels' => array( + 'name' => __( 'Series', 'sermon-manager' ), + 'singular_name' => __( 'Series', 'sermon-manager' ), + 'menu_name' => _x( 'Series', 'Admin menu name', 'sermon-manager' ), + 'search_items' => __( 'Search series', 'sermon-manager' ), + 'all_items' => __( 'All series', 'sermon-manager' ), + 'parent_item' => null, // it's not hierarchical + 'parent_item_colon' => null, // it's not hierarchical + 'edit_item' => __( 'Edit series', 'sermon-manager' ), + 'update_item' => __( 'Update series', 'sermon-manager' ), + 'add_new_item' => __( 'Add new series', 'sermon-manager' ), + 'new_item_name' => __( 'New series name', 'sermon-manager' ), + 'not_found' => __( 'No series found', 'sermon-manager' ), + ), + 'show_ui' => true, + 'query_var' => true, + 'rewrite' => array( 'slug' => $permalinks['wpfc_sermon_series'], 'with_front' => false ), + ) ) ); + + register_taxonomy( 'wpfc_sermon_topics', + apply_filters( 'sm_taxonomy_objects_wpfc_sermon_topics', array( 'wpfc_sermon' ) ), + apply_filters( 'sm_taxonomy_args_wpfc_sermon_topics', array( + 'hierarchical' => false, + 'label' => __( 'Topics', 'sermon-manager' ), + 'labels' => array( + 'name' => __( 'Topics', 'sermon-manager' ), + 'singular_name' => __( 'Topic', 'sermon-manager' ), + 'menu_name' => _x( 'Topics', 'Admin menu name', 'sermon-manager' ), + 'search_items' => __( 'Search topics', 'sermon-manager' ), + 'all_items' => __( 'All topics', 'sermon-manager' ), + 'parent_item' => null, + 'parent_item_colon' => null, + 'edit_item' => __( 'Edit topic', 'sermon-manager' ), + 'update_item' => __( 'Update topic', 'sermon-manager' ), + 'add_new_item' => __( 'Add new topic', 'sermon-manager' ), + 'new_item_name' => __( 'New topic name', 'sermon-manager' ), + 'not_found' => __( 'No topics found', 'sermon-manager' ), + ), + 'show_ui' => true, + 'query_var' => true, + 'rewrite' => array( 'slug' => $permalinks['wpfc_sermon_topics'], 'with_front' => false ), + ) ) ); + + register_taxonomy( 'wpfc_bible_book', + apply_filters( 'sm_taxonomy_objects_wpfc_bible_book', array( 'wpfc_sermon' ) ), + apply_filters( 'sm_taxonomy_args_wpfc_bible_book', array( + 'hierarchical' => false, + 'label' => __( 'Books', 'sermon-manager' ), + 'labels' => array( + 'name' => __( 'Bible books', 'sermon-manager' ), + 'singular_name' => __( 'Book', 'sermon-manager' ), + 'menu_name' => _x( 'Books', 'Admin menu name', 'sermon-manager' ), + 'search_items' => __( 'Search books', 'sermon-manager' ), + 'all_items' => __( 'All books', 'sermon-manager' ), + 'parent_item' => null, + 'parent_item_colon' => null, + 'edit_item' => __( 'Edit book', 'sermon-manager' ), + 'update_item' => __( 'Update book', 'sermon-manager' ), + 'add_new_item' => __( 'Add new book', 'sermon-manager' ), + 'new_item_name' => __( 'New book name', 'sermon-manager' ), + 'not_found' => __( 'No books found', 'sermon-manager' ), + ), + 'show_ui' => true, + 'query_var' => true, + 'rewrite' => array( 'slug' => $permalinks['wpfc_bible_book'], 'with_front' => false ), + ) ) ); + + register_taxonomy( 'wpfc_service_type', + apply_filters( 'sm_taxonomy_objects_wpfc_service_type', array( 'wpfc_sermon' ) ), + apply_filters( 'sm_taxonomy_args_wpfc_service_type', array( + 'hierarchical' => false, + 'label' => __( 'Service Types', 'sermon-manager' ), + 'labels' => array( + 'name' => __( 'Service Types', 'sermon-manager' ), + 'singular_name' => __( 'Type', 'sermon-manager' ), + 'menu_name' => _x( 'Types', 'Admin menu name', 'sermon-manager' ), + 'search_items' => __( 'Search types', 'sermon-manager' ), + 'all_items' => __( 'All types', 'sermon-manager' ), + 'parent_item' => __( 'Parent type', 'sermon-manager' ), + 'parent_item_colon' => __( 'Parent type:', 'sermon-manager' ), + 'edit_item' => __( 'Edit type', 'sermon-manager' ), + 'update_item' => __( 'Update type', 'sermon-manager' ), + 'add_new_item' => __( 'Add new type', 'sermon-manager' ), + 'new_item_name' => __( 'New type name', 'sermon-manager' ), + 'not_found' => __( 'No types found', 'sermon-manager' ), + ), + 'show_ui' => true, + 'query_var' => true, + 'rewrite' => array( 'slug' => $permalinks['wpfc_service_type'], 'with_front' => false ), + ) ) ); + + do_action( 'sm_after_register_taxonomy' ); + } + + /** + * Register core post types. + */ + public static function register_post_types() { + if ( ! is_blog_installed() || post_type_exists( 'wpfc_sermon' ) ) { + return; + } + + do_action( 'sm_register_post_type' ); + + $permalinks = sm_get_permalink_structure(); + + register_post_type( 'wpfc_sermon', apply_filters( 'sm_register_post_type_wpfc_sermon', array( + 'labels' => array( + 'name' => __( 'Sermons', 'sermon-manager' ), + 'singular_name' => __( 'Sermon', 'sermon-manager' ), + 'all_items' => __( 'All Sermons', 'sermon-manager' ), + 'menu_name' => _x( 'Sermons', 'Admin menu name', 'sermon-manager' ), + 'add_new' => __( 'Add New', 'sermon-manager' ), + 'add_new_item' => __( 'Add new sermon', 'sermon-manager' ), + 'edit' => __( 'Edit', 'sermon-manager' ), + 'edit_item' => __( 'Edit sermon', 'sermon-manager' ), + 'new_item' => __( 'New sermon', 'sermon-manager' ), + 'view' => __( 'View sermon', 'sermon-manager' ), + 'view_item' => __( 'View sermon', 'sermon-manager' ), + 'search_items' => __( 'Search sermon', 'sermon-manager' ), + 'not_found' => __( 'No sermons found', 'sermon-manager' ), + 'not_found_in_trash' => __( 'No sermons found in trash', 'sermon-manager' ), + 'featured_image' => __( 'Sermon image', 'sermon-manager' ), + 'set_featured_image' => __( 'Set sermon image', 'sermon-manager' ), + 'remove_featured_image' => __( 'Remove sermon image', 'sermon-manager' ), + 'use_featured_image' => __( 'Use as sermon image', 'sermon-manager' ), + 'insert_into_item' => __( 'INSERT INTO sermon', 'sermon-manager' ), + 'uploaded_to_this_item' => __( 'Uploaded to this sermon', 'sermon-manager' ), + 'filter_items_list' => __( 'Filter sermon', 'sermon-manager' ), + 'items_list_navigation' => __( 'Sermon navigation', 'sermon-manager' ), + 'items_list' => __( 'Sermon list', 'sermon-manager' ), + ), + 'description' => __( 'This is where you can add new sermons to your website.', 'sermon-manager' ), + 'public' => true, + 'show_ui' => true, + 'capability_type' => 'post', + 'map_meta_cap' => true, + 'publicly_queryable' => true, + 'exclude_from_search' => false, + 'show_in_menu' => true, + 'menu_icon' => SERMON_MANAGER_URL . 'includes/img/sm-icon.svg', + 'hierarchical' => false, + 'rewrite' => array( 'slug' => $permalinks['wpfc_sermon'], 'with_front' => false ), + 'query_var' => true, + 'show_in_nav_menus' => true, + 'show_in_rest' => true, + 'has_archive' => true, + 'supports' => array( + 'title', + 'thumbnail', + 'publicize', + 'wpcom-markdown', + 'comments', + 'entry-views', + ) + ) ) ); + + do_action( 'sm_after_register_post_type' ); + } + + /** + * Flush rewrite rules. + */ + public static function flush_rewrite_rules() { + flush_rewrite_rules(); + } + + /** + * Add Sermon Support to Jetpack Omnisearch. + */ + public static function support_jetpack_omnisearch() { + if ( class_exists( 'Jetpack_Omnisearch_Posts' ) ) { + new Jetpack_Omnisearch_Posts( 'wpfc_sermon' ); + } + } + + /** + * Add sermon support for Jetpack related posts. + * + * @param array $post_types + * + * @return array + */ + public static function rest_api_allowed_post_types( $post_types ) { + $post_types[] = 'wpfc_sermon'; + + return $post_types; + } +} + +SM_Post_Types::init(); diff --git a/includes/sm-cmb-functions.php b/includes/sm-cmb-functions.php new file mode 100755 index 0000000..d21e0a3 --- /dev/null +++ b/includes/sm-cmb-functions.php @@ -0,0 +1,189 @@ +slug; + + wp_set_object_terms( $post_ID, $service_type, 'wpfc_service_type' ); + } + + return $post; + } +} + +/* + * Creation of all meta boxes + */ + +/** + * Gets a number of terms and displays them as options + * + * @param string $taxonomy Taxonomy terms to retrieve. Default is category. + * @param string|array $args Optional. get_terms optional arguments + * + * @return array An array of options that matches the CMB2 options array + */ +function cmb2_get_term_options( $taxonomy = 'category' ) { + + $args['taxonomy'] = $taxonomy; + + // $defaults = array( 'taxonomy' => 'category' ); + + $taxonomy = $args['taxonomy']; + + $args = array( + 'hide_empty' => false + ); + + $terms = (array) get_terms( $taxonomy, $args ); + + // Initate an empty array + $term_options = array(); + if ( ! empty( $terms ) ) { + foreach ( $terms as $term ) { + $term_options[ $term->term_id ] = $term->name; + } + } + + return $term_options; +} + +// sanitize the field +add_filter( 'cmb2_sanitize_text_number', 'sm_cmb2_sanitize_text_number', 10, 2 ); +function sm_cmb2_sanitize_text_number( $null, $new ) { + $new = preg_replace( "/[^0-9]/", "", $new ); + + return $new; +} + +// Define the metabox and field configurations +function wpfc_sermon_metaboxes() { + + $cmb = new_cmb2_box( array( + 'id' => 'wpfc_sermon_details', + 'title' => __( 'Sermon Details', 'sermon-manager' ), + 'object_types' => array( 'wpfc_sermon', ), // Post type + 'context' => 'normal', + 'priority' => 'high', + 'show_names' => true, // Show field names on the left + // 'cmb_styles' => false, // false to disable the CMB stylesheet + // 'closed' => true, // Keep the metabox closed by default + ) ); + + $date_format = 'm/d/Y'; + if ( \SermonManager::getOption( 'date_format' ) !== '' ) { + switch ( \SermonManager::getOption( 'date_format' ) ) { + case '0': + $date_format = 'm/d/Y'; + break; + case '1': + $date_format = 'd/m/Y'; + break; + case '2': + $date_format = 'Y/m/d'; + break; + case '3': + $date_format = 'Y/d/m'; + break; + } + } + + $cmb->add_field( array( + 'name' => __( 'Date Preached', 'sermon-manager' ), + 'desc' => '
(format: ' . $date_format . ')', + 'id' => 'sermon_date', + 'type' => 'text_date_timestamp', + 'date_format' => $date_format, + ) ); + + $cmb->add_field( array( + 'name' => __( 'Service Type', 'sermon-manager' ), + 'desc' => __( 'Select the type of service. Modify service types in Sermons -> Service Types.', 'sermon-manager' ), + 'id' => 'wpfc_service_type', + 'type' => 'select', + 'show_option_none' => true, + 'options' => cmb2_get_term_options( 'wpfc_service_type' ), + ) ); + $cmb->add_field( array( + 'name' => __( 'Main Bible Passage', 'sermon-manager' ), + 'desc' => __( 'Enter the Bible passage with the full book names,e.g. "John 3:16-18".', 'sermon-manager' ), + 'id' => 'bible_passage', + 'type' => 'text', + ) ); + $cmb->add_field( array( + 'name' => __( 'Description', 'sermon-manager' ), + 'desc' => __( 'Type a brief description about this sermon, an outline, or a full manuscript', 'sermon-manager' ), + 'id' => 'sermon_description', + 'type' => 'wysiwyg', + 'options' => array( 'textarea_rows' => 7, 'media_buttons' => true, ), + ) ); + + $cmb2 = new_cmb2_box( array( + 'id' => 'wpfc_sermon_files', + 'title' => __( 'Sermon Files', 'sermon-manager' ), + 'object_types' => array( 'wpfc_sermon', ), // Post type + 'context' => 'normal', + 'priority' => 'high', + 'show_names' => true, // Show field names on the left + // 'cmb_styles' => false, // false to disable the CMB stylesheet + // 'closed' => true, // Keep the metabox closed by default + ) ); + $cmb2->add_field( array( + 'name' => __( 'Location of MP3', 'sermon-manager' ), + 'desc' => __( 'Upload an audio file or enter an URL.', 'sermon-manager' ), + 'id' => 'sermon_audio', + 'type' => 'file', + 'text' => array( + 'add_upload_file_text' => 'Add Sermon Audio' // Change upload button text. Default: "Add or Upload File" + ), + ) ); + $cmb2->add_field( array( + 'name' => __( 'MP3 Duration', 'sermon-manager' ), + 'desc' => __( 'Length in hh:mm:ss format (if left blank, will attempt to calculate automatically when you save)', 'sermon-manager' ), + 'id' => '_wpfc_sermon_duration', + 'type' => 'text', + ) ); + $cmb2->add_field( array( + 'name' => __( 'Video Embed Code', 'sermon-manager' ), + 'desc' => __( 'Paste your embed code for Vimeo, Youtube, or other service here', 'sermon-manager' ), + 'id' => 'sermon_video', + 'type' => 'textarea_code' + ) ); + $cmb2->add_field( apply_filters( 'sm_cmb2_field_sermon_video_link', array( + 'name' => __( 'Video Link', 'sermon-manager' ), + 'desc' => __( 'Paste your link for Vimeo, Youtube, or other service here', 'sermon-manager' ), + 'id' => 'sermon_video_link', + 'type' => 'text' + ) ) + ); + $cmb2->add_field( array( + 'name' => __( 'Sermon Notes', 'sermon-manager' ), + 'desc' => __( 'Upload a pdf file or enter an URL.', 'sermon-manager' ), + 'id' => 'sermon_notes', + 'type' => 'file', + 'text' => array( + 'add_upload_file_text' => 'Add File' // Change upload button text. Default: "Add or Upload File" + ), + ) ); + $cmb2->add_field( array( + 'name' => __( 'Bulletin', 'sermon-manager' ), + 'desc' => __( 'Upload a pdf file or enter an URL.', 'sermon-manager' ), + 'id' => 'sermon_bulletin', + 'type' => 'file', + 'text' => array( + 'add_upload_file_text' => 'Add File' // Change upload button text. Default: "Add or Upload File" + ), + ) ); +} diff --git a/includes/sm-core-functions.php b/includes/sm-core-functions.php index b233e31..0091a59 100644 --- a/includes/sm-core-functions.php +++ b/includes/sm-core-functions.php @@ -93,4 +93,85 @@ function sm_clean( $var ) { } else { return is_scalar( $var ) ? sanitize_text_field( $var ) : $var; } +} + +/** + * Get permalink settings for Sermon Manager independent of the user locale. + * + * @since 2.7 + * + * @return array + */ +function sm_get_permalink_structure() { + if ( did_action( 'admin_init' ) ) { + sm_switch_to_site_locale(); + } + + $permalinks = wp_parse_args( (array) get_option( 'sm_permalinks', array() ), array( + 'wpfc_preacher' => '', + 'wpfc_sermon_series' => '', + 'wpfc_sermon_topics' => '', + 'wpfc_bible_book' => '', + 'wpfc_service_type' => '', + 'wpfc_sermon' => trim( \SermonManager::getOption( 'archive_slug' ) ), + 'use_verbose_page_rules' => false, + ) ); + + // Ensure rewrite slugs are set. + $permalinks['wpfc_preacher'] = untrailingslashit( empty( $permalinks['wpfc_preacher'] ) ? _x( 'preacher', 'slug', 'sermon-manager' ) : $permalinks['wpfc_preacher'] ); + $permalinks['wpfc_sermon_series'] = untrailingslashit( empty( $permalinks['wpfc_sermon_series'] ) ? _x( 'series', 'slug', 'sermon-manager' ) : $permalinks['wpfc_sermon_series'] ); + $permalinks['wpfc_sermon_topics'] = untrailingslashit( empty( $permalinks['wpfc_sermon_topics'] ) ? _x( 'topics', 'slug', 'sermon-manager' ) : $permalinks['wpfc_sermon_topics'] ); + $permalinks['wpfc_bible_book'] = untrailingslashit( empty( $permalinks['wpfc_bible_book'] ) ? _x( 'book', 'slug', 'sermon-manager' ) : $permalinks['wpfc_bible_book'] ); + $permalinks['wpfc_service_type'] = untrailingslashit( empty( $permalinks['wpfc_service_type'] ) ? _x( 'service-type', 'slug', 'sermon-manager' ) : $permalinks['wpfc_service_type'] ); + $permalinks['wpfc_sermon'] = untrailingslashit( empty( $permalinks['wpfc_sermon'] ) ? _x( 'sermons', 'slug', 'sermon-manager' ) : $permalinks['wpfc_sermon'] ); + + if ( \SermonManager::getOption( 'common_base_slug' ) ) { + foreach ( $permalinks as $name => &$permalink ) { + if ( $name === 'wpfc_sermon' ) { + continue; + } + + $permalink = $permalinks['wpfc_sermon'] . '/' . $permalink; + } + } + + if ( did_action( 'admin_init' ) ) { + sm_restore_locale(); + } + + return $permalinks; +} + +/** + * Switch Sermon Manager to site language. + * + * @since 2.7 + */ +function sm_switch_to_site_locale() { + if ( function_exists( 'switch_to_locale' ) ) { + switch_to_locale( get_locale() ); + + // Filter on plugin_locale so load_plugin_textdomain loads the correct locale. + add_filter( 'plugin_locale', 'get_locale' ); + + // Init Sermon Manager locale. + SermonManager::load_translations(); + } +} + +/** + * Switch Sermon Manager language to original. + * + * @since 2.7 + */ +function sm_restore_locale() { + if ( function_exists( 'restore_previous_locale' ) ) { + restore_previous_locale(); + + // Remove filter. + remove_filter( 'plugin_locale', 'get_locale' ); + + // Init Sermon Manager locale. + SermonManager::load_translations(); + } } \ No newline at end of file diff --git a/includes/legacy-php.php b/includes/sm-legacy-php-functions.php similarity index 100% rename from includes/legacy-php.php rename to includes/sm-legacy-php-functions.php diff --git a/includes/template-tags.php b/includes/template-tags.php index f306287..f287cc6 100755 --- a/includes/template-tags.php +++ b/includes/template-tags.php @@ -151,7 +151,9 @@ function render_wpfc_sorting( $args = array() ) { // handle current page. We don't need "page" var in URL if ( is_archive() && get_post_type() === 'wpfc_sermon' ) { - $action = get_site_url() . '/' . generate_wpfc_slug()['slug']; + $permalinks = sm_get_permalink_structure(); + + $action = get_site_url() . '/' . $permalinks['wpfc_sermon']; } else { $action = get_site_url(); } @@ -562,3 +564,25 @@ function wpfc_footer_preacher() { } } } + +/** + * Build '; - } - - return $html; -} diff --git a/readme.txt b/readme.txt index 1ef9aaa..e723ab6 100755 --- a/readme.txt +++ b/readme.txt @@ -91,9 +91,11 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man ## Changelog ## ### 2.7 ### * Add WordPress search support to sermons +* Add Jetpack Publicize and Omnisearch support to sermons * Fix sermon ordering * Fix new sermons not appearing * Fix widget styling +* General performance and compatibility fixes ### 2.6.2 ### * Add more `` elements for more styling options diff --git a/sermons.php b/sermons.php index 9737847..cd28677 100755 --- a/sermons.php +++ b/sermons.php @@ -86,10 +86,11 @@ private function includes() { '/includes/class-sm-dates-wp.php', // Attach to WP filters '/includes/class-sm-search.php', // Search '/includes/class-sm-api.php', // API + '/includes/class-sm-post-types.php', // Register post type, taxonomies, etc '/includes/sm-deprecated-functions.php', // Deprecated SM functions '/includes/sm-core-functions.php', // Deprecated SM functions - '/includes/legacy-php.php', // Old PHP compatibility fixes - '/includes/types-taxonomies.php', // Post Types and Taxonomies + '/includes/sm-legacy-php-functions.php', // Old PHP compatibility fixes + '/includes/sm-cmb-functions.php', // CMB2 Meta Fields functions '/includes/taxonomy-images/taxonomy-images.php', // Images for Custom Taxonomies '/includes/entry-views.php', // Entry Views Tracking '/includes/shortcodes.php', // Shortcodes @@ -238,7 +239,7 @@ public static function get_instance() { * @return void */ public static function load_translations() { - load_plugin_textdomain( 'sermon-manager', false, SERMON_MANAGER_PATH . 'languages' ); + load_plugin_textdomain( 'sermon-manager', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); } /** From 885f8aaa2bb33dce44c8c26bc933a44244a8600d Mon Sep 17 00:00:00 2001 From: Nikola Date: Fri, 22 Sep 2017 18:33:24 +0200 Subject: [PATCH 16/63] Add API --- .../api/class-sm-rest-sermons-controller.php | 36 ---- includes/class-sm-api.php | 162 ++++++++---------- includes/class-sm-post-types.php | 5 + readme.txt | 3 +- sermons.php | 4 +- 5 files changed, 80 insertions(+), 130 deletions(-) delete mode 100644 includes/api/class-sm-rest-sermons-controller.php diff --git a/includes/api/class-sm-rest-sermons-controller.php b/includes/api/class-sm-rest-sermons-controller.php deleted file mode 100644 index 7190c5f..0000000 --- a/includes/api/class-sm-rest-sermons-controller.php +++ /dev/null @@ -1,36 +0,0 @@ -namespace, '/' . $this->rest_base, array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) ); - } -} \ No newline at end of file diff --git a/includes/class-sm-api.php b/includes/class-sm-api.php index 87c49ce..170724b 100644 --- a/includes/class-sm-api.php +++ b/includes/class-sm-api.php @@ -13,116 +13,96 @@ class SM_API { * Init class */ public function __construct() { - // Add query vars - add_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 ); + // Add filters for wpfc_sermon post type + add_action( 'rest_wpfc_sermon_collection_params', array( $this, 'modify_query_params' ) ); - // Register API endpoints - add_action( 'init', array( $this, 'add_endpoint' ), 0 ); + // Add custom data to the response + add_filter( 'rest_prepare_wpfc_sermon', array( $this, 'add_custom_data' ) ); - // Handle sm-api endpoint requests - add_action( 'parse_request', array( $this, 'handle_api_requests' ), 0 ); - - // WP REST API - $this->rest_api_init(); + // Fix ordering + add_filter( 'rest_wpfc_sermon_query', array( $this, 'fix_ordering' ) ); } - /** - * Init WP REST API - */ - private function rest_api_init() { - // REST API was included starting WordPress 4.4 - if ( ! class_exists( 'WP_REST_Server' ) ) { - return; + public function fix_ordering( $args ) { + if ( $args['orderby'] === 'date' ) { + $args['orderby'] = 'meta_value_num date'; + $args['meta_query'] = array( + 'relation' => 'OR', + array( //check to see if date has been filled out + 'key' => 'sermon_date', + 'compare' => '<=', + 'value' => time() + ), + array( //if no date has been added show these posts too + 'key' => 'sermon_date', + 'value' => time(), + 'compare' => 'NOT EXISTS' + ) + ); + + add_filter( 'posts_orderby', function ( $arg ) { + return 'mt1.meta_value+0 DESC, wp_posts.post_date DESC'; + } ); } - $this->rest_api_includes(); - - // Init REST API routes - add_action( 'rest_api_init', array( $this, 'register_rest_routes' ), 10 ); + return $args; } /** - * Include REST API classes. + * Currently, it only replaces "post" string with "sermon", but we can add more query parameters here if needed * - * @since 3.0.0 - */ - private function rest_api_includes() { - include_once 'api/class-sm-rest-sermons-controller.php'; - - if ( ! class_exists( 'WP_REST_Controller' ) ) { - include_once 'vendor/abstract-wp-rest-controller.php'; - } - } - - /** - * Sermon Manager API + * @param array $query_params + * + * @return array Modified query params */ - public static function add_endpoint() { - add_rewrite_endpoint( 'sm-api', EP_ALL ); + public function modify_query_params( $query_params ) { + // Replace "post" to "sermon" + $query_params['slug']['description'] = str_replace( 'post', 'sermon', $query_params['slug']['description'] ); + $query_params['status']['description'] = str_replace( 'post', 'sermon', $query_params['status']['description'] ); + $query_params['after']['description'] = str_replace( 'post', 'sermon', $query_params['after']['description'] ); + $query_params['before']['description'] = str_replace( 'post', 'sermon', $query_params['before']['description'] ); + + return $query_params; } /** - * Add new query vars + * Add custom data to the response, such as audio, passage, etc * - * @param array $vars + * @param WP_REST_Response $response The response object. * - * @return string[] - */ - public function add_query_vars( $vars ) { - $vars[] = 'sm-api'; - - return $vars; - } - - /** - * API request - Trigger any API requests + * @return WP_REST_Response Modified response */ - public function handle_api_requests() { - global $wp; - - if ( ! empty( $_GET['sm-api'] ) ) { - $wp->query_vars['sm-api'] = $_GET['sm-api']; + public function add_custom_data( $response ) { + $data = &$response->data; + + $post_meta = wp_parse_args( get_post_meta( $data['id'] ), array( + 'sermon_audio' => array( '' ), + '_wpfc_sermon_duration' => array( '' ), + 'Views' => array( '' ), + 'bible_passage' => array( '' ), + 'sermon_description' => array( '' ), + 'sermon_video' => array( '' ), + 'sermon_video_link' => array( '' ), + 'sermon_bulletin' => array( '' ), + '_thumbnail_id' => array( '' ), + ) ); + + $data['sermon_audio'] = $post_meta['sermon_audio'][0]; + $data['sermon_audio_duration'] = $post_meta['_wpfc_sermon_duration'][0]; + $data['views'] = $post_meta['Views'][0]; + $data['bible_passage'] = $post_meta['bible_passage'][0]; + $data['sermon_description'] = $post_meta['sermon_description'][0]; + $data['sermon_video_embed'] = $post_meta['sermon_video'][0]; + $data['sermon_video_url'] = $post_meta['sermon_video_link'][0]; + $data['sermon_bulletin'] = $post_meta['sermon_bulletin'][0]; + $data['featured_url'] = wp_get_attachment_url( $post_meta['_thumbnail_id'][0] ); + + if ( SM_Dates::get( 'Y-m-d H:m:s', $data['id'] ) !== false ) { + $data['date'] = mysql_to_rfc3339( SM_Dates::get( 'Y-m-d H:m:s', $data['id'] ) ); + $data['date_gmt'] = mysql_to_rfc3339( SM_Dates::get( 'Y-m-d H:m:s', $data['id'] ) ); } - // sm-api endpoint requests. - if ( ! empty( $wp->query_vars['sm-api'] ) ) { - - // Buffer, we won't want any output here. - ob_start(); - - // No cache headers. - nocache_headers(); - - // Clean the API request. - $api_request = strtolower( sm_clean( $wp->query_vars['sm-api'] ) ); - - // Trigger generic action before request hook. - do_action( 'sm_api_request', $api_request ); - - // Is there actually something hooked into this API request? If not trigger 400 - Bad request. - status_header( has_action( 'sm_api_' . $api_request ) ? 200 : 400 ); - - // Trigger an action which plugins can hook into to fulfill the request. - do_action( 'sm_api_' . $api_request ); - - // Done, clear buffer and exit. - ob_end_clean(); - die( '-1' ); - } - } - - /** - * Register REST API routes - */ - public function register_rest_routes() { - $controllers = array( - 'SM_REST_Sermons_Controller', - ); - - foreach ( $controllers as $controller ) { - $this->$controller = new $controller(); - $this->$controller->register_routes(); - } + return $response; } } diff --git a/includes/class-sm-post-types.php b/includes/class-sm-post-types.php index f1d3fa0..e8f50fb 100644 --- a/includes/class-sm-post-types.php +++ b/includes/class-sm-post-types.php @@ -55,6 +55,7 @@ public static function register_taxonomies() { ), 'show_ui' => true, 'query_var' => true, + 'show_in_rest' => true, 'rewrite' => array( 'slug' => $permalinks['wpfc_preacher'], 'with_front' => false ), ) ) ); @@ -79,6 +80,7 @@ public static function register_taxonomies() { ), 'show_ui' => true, 'query_var' => true, + 'show_in_rest' => true, 'rewrite' => array( 'slug' => $permalinks['wpfc_sermon_series'], 'with_front' => false ), ) ) ); @@ -103,6 +105,7 @@ public static function register_taxonomies() { ), 'show_ui' => true, 'query_var' => true, + 'show_in_rest' => true, 'rewrite' => array( 'slug' => $permalinks['wpfc_sermon_topics'], 'with_front' => false ), ) ) ); @@ -127,6 +130,7 @@ public static function register_taxonomies() { ), 'show_ui' => true, 'query_var' => true, + 'show_in_rest' => true, 'rewrite' => array( 'slug' => $permalinks['wpfc_bible_book'], 'with_front' => false ), ) ) ); @@ -151,6 +155,7 @@ public static function register_taxonomies() { ), 'show_ui' => true, 'query_var' => true, + 'show_in_rest' => true, 'rewrite' => array( 'slug' => $permalinks['wpfc_service_type'], 'with_front' => false ), ) ) ); diff --git a/readme.txt b/readme.txt index e723ab6..01c6328 100755 --- a/readme.txt +++ b/readme.txt @@ -92,7 +92,8 @@ Visit the [plugin homepage](https://wpforchurch.com/wordpress-plugins/sermon-man ### 2.7 ### * Add WordPress search support to sermons * Add Jetpack Publicize and Omnisearch support to sermons -* Fix sermon ordering +* Add REST API support +* Fix sermon ordering // todo: seems like it's not working, check on Monday * Fix new sermons not appearing * Fix widget styling * General performance and compatibility fixes diff --git a/sermons.php b/sermons.php index cd28677..3d8177f 100755 --- a/sermons.php +++ b/sermons.php @@ -191,7 +191,7 @@ private function restore_dates() { * @return void */ public static function fix_sermons_ordering( $query ) { - if ( ! is_admin() && $query->is_main_query() ) { + if ( ! is_admin() && ( $query->is_main_query() ) ) { if ( is_post_type_archive( 'wpfc_sermon' ) || is_tax( 'wpfc_preacher' ) || is_tax( 'wpfc_sermon_topics' ) || @@ -214,7 +214,7 @@ public static function fix_sermons_ordering( $query ) { $query->set( 'orderby', 'meta_value_num date' ); $query->set( 'order', 'DESC' ); add_filter( 'posts_orderby', function ( $arg ) { - return 'GREATEST(UNIX_TIMESTAMP(wp_posts.post_date), wp_postmeta.meta_value+0) DESC'; + return 'mt1.meta_value+0 DESC, wp_posts.post_date DESC'; } ); } } From 1448a80ef1743918f5f82d056010b2c8e44c0442 Mon Sep 17 00:00:00 2001 From: Nikola Date: Fri, 22 Sep 2017 18:34:01 +0200 Subject: [PATCH 17/63] Remove debug line --- includes/options.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/options.php b/includes/options.php index b5271f5..ef427e6 100755 --- a/includes/options.php +++ b/includes/options.php @@ -195,7 +195,6 @@ function wpfc_sermon_options_render_form() {

- '; print_r($sermon_settings); echo ''; ?>